<!-- Begin
function addDotFormVals() {
  var r = document.forms.dotform;
  addDotFormVal(r, 'dotemail');
  addDotFormVal(r, 'dotname');
  addDotFormVal(r, 'dot_addr');
  addDotFormVal(r, 'dot_city');
  addDotFormVal(r, 'dot_state');
  addDotFormVal(r, 'dot_zip');
  addDotFormVal(r, 'list_id');
  addDotFormVal(r, 'listadd');
  addDotFormVal(r, 'dottext');

  return true;
}


function dotAddr() {
  document.forms.dotform.dotknown[0].checked = true;
  document.getElementById('changemapview').style.display='none';
  document.getElementById('dotblinkmsg').style.display='none';
  if (IE) {
    document.getElementById('dotknowntable').style.display='block';
    document.getElementById('dotknowntable2').style.display='block';
  }
  else {
    document.getElementById('dotknowntable').style.display='table';
    document.getElementById('dotknowntable2').style.display='table-row';
  }
  if (1 || document.mapserv.isplacement.value=='noaddr') {
    document.mapserv.isplacement.value='addr';
  }
}
function dotNoAddr() {
  document.forms.dotform.dotknown[1].checked = true;
  document.getElementById('newdot').style.display="block";
  placeDot();
  document.getElementById('changemapview').style.display='block';
  document.getElementById('dotblinkmsg').style.display='block';
  document.getElementById('dotknowntable').style.display='none';
  document.getElementById('dotknowntable2').style.display='none';
  if (1 || document.mapserv.isplacement.value=='addr') {
    document.mapserv.isplacement.value='noaddr';
  }
}


function toggleEnhance() {
  if (document.getElementById('enhance').style.display=='none') {
    if (IE) {
      document.getElementById('enhance').style.display='block';
    }
    else {
      document.getElementById('enhance').style.display='table-row';
    }
  }
  else {
    document.getElementById('enhance').style.display='none';
    document.forms.dotform.eurl.value = '';
    document.forms.dotform.ephone.value = '';
  }
}

function addDotFormVal(r, n) {
  var s, ok=0;
  if (n=='dottext' || n=='dot_state' || (r && r[n] && r[n].value)) { 
    var drName = document.createElement("input");
    drName.type="hidden";
    if (n=='dottext' && dotHtmlArea) {
      s = dotHtmlArea.getHTML();
      if (s!='' && s!='&nbsp;') { drName.value = s; ok = 1;}
    }
    else if (n=='dot_state') {
      s = get_option_selected(document.forms.dotform.dot_state);
      if (s!='' && s!='--') { drName.value = s; ok = 1;}
    }
    else {
      drName.value=r[n].value;
      ok = 1;
    }
    if (ok) {
      drName.name=n;
      document.getElementById('mapservform').appendChild(drName);
      //    l[n].value = r[n].value; 
    }
  }
}

function verifyPublish() {
	var textvalue = dotHtmlArea.getHTML();
	if (!document.dotform.dotname.value && (!textvalue || textvalue=='&nbsp;')) {
		alert("Please enter a name and description for this dot.");
		return false;
	}
	if (!document.dotform.dotname.value) {
		alert("Please enter a name for this dot.");
		return false;
	}
	if (!textvalue || textvalue=='&nbsp;') {
		alert("Please enter a description for this dot.");
		return false;
	}
	if (!document.dotform.dot_addr.value || 
		!document.dotform.dot_city.value || 
		!document.dotform.dot_zip.value) {
		alert("Please enter an address, \nor select 'Address not known' above.");
		return false;
	}
	document.dotform.dottext.value = textvalue;
	document.dotform.submit();
}

// maps

ballIcons = {};
ballIcons.o  = new google.maps.MarkerImage('/graphics/greenball.png',
					new google.maps.Size(15, 15),
					new google.maps.Point(0,0),
					new google.maps.Point(7,7));
ballIcons.c  = new google.maps.MarkerImage('/graphics/redball.png',
					new google.maps.Size(15, 15),
					new google.maps.Point(0,0),
					new google.maps.Point(7,7));
ballIcons.uw = new google.maps.MarkerImage('/graphics/paleblueball.png',
					new google.maps.Size(10, 10),
					new google.maps.Point(0,0),
					new google.maps.Point(5,5));
ballIcons.u  = new google.maps.MarkerImage('/graphics/blueball.png',
					new google.maps.Size(12, 12),
					new google.maps.Point(0,0),
					new google.maps.Point(6,6));

var ballIcons10 = {};
ballIcons10.o  = '/graphics/greenball_10.png';
ballIcons10.c  = '/graphics/redball_10.png';
ballIcons10.uw = '/graphics/paleblueball_10.png';
ballIcons10.u  = '/graphics/blueball_10.png';
ballIcons10.dotxy  = '/graphics/icon47_10.png';

var ballZindex = {};
ballZindex.o   = 100;
ballZindex.c   =  90;
ballZindex.uw  =  70;
ballZindex.u   =  30;

ballIcons.dotxy  = new google.maps.MarkerImage('/graphics/icon47_16.png', 
					new google.maps.Size(16, 16));

function clearLocations(numToLeave, allMarkers, dot_id) {

  //x console.log("clearLocations ", numToLeave, allMarkers.length);

  if (numToLeave>=allMarkers.length) {
	return allMarkers;
  }

  //old infoWindow.close();

  //alert("clear locations " + allMarkers.length);

  var allTmp = [];
  var firstSaved = allMarkers.length - numToLeave;
  var dot_id_index = -1;

  //console.log("clearLocations firstSaved ", firstSaved);
  var i;
  for (i=0; i < firstSaved && i<allMarkers.length; i++) {

//	var gid = allMarkers[i].getAttribute("dot_id"); //was using xml node
	var gid = allMarkers[i].dot_id;

	if (dot_id && gid==dot_id) { 
	  dot_id_index = i;
	  //console.log("SKIP save id ", dot_id, " at index ", dot_id_index, allMarkers[i]);
	  continue; 
	}

	if (currentInfoMarker==allMarkers[i]) {
	  infoWindow.close();
	}


	allMarkers[i].setMap(null);

	delete(allDotIds['g' + gid]);

	// remove from left list
	//console.log("removing id=", gid);
	newDiv = document.getElementById("ld_" + gid);
	if (newDiv) { newDiv.parentNode.removeChild(newDiv);  }
  }

  // also save dot that was clicked
  var dot_id_offset = 0;
  if (dot_id && dot_id_index>=0) {	
    allTmp[0] = allMarkers[dot_id_index]; 
    dot_id_offset = 1;
  }

  for (i=firstSaved; firstSaved>=0 && i < allMarkers.length; i++) {
	allTmp[dot_id_offset + i-firstSaved] = allMarkers[i];
  }

  allMarkers = allTmp;

  //alert(allMarkers.length);
  //x console.log("clearLocations nowlef= ", allMarkers.length);

  return allMarkers;
}

function getMarkerHandler(thisMarker) {
    return function() {
		google.maps.event.trigger(thisMarker, 'click');
		return false;
    };
}

function addAddressDot(x, y, address_title) {

	if (allDotIds['star']) { return; }

	var point = new google.maps.LatLng(y,x);
	var address_marker = new google.maps.Marker({
	  map: map,
      icon: ballIcons.dotxy,
      position: point,
	  title: address_title,
	  zIndex: 10
      });

	bindInfoWindow(address_marker, map, infoWindow, address_title);
	allDotIds['star'] = address_marker;


	newDiv = document.createElement("div");
	//var left_html = "<b>" + '<a onclick="google.maps.event.trigger(allDotIds[\'star\'], \'click\'); return false;" href="#">' + address_title + '</a>' + "</b><br/><p/>";
	var left_html = '<a onclick="map.setCenter(new google.maps.LatLng(' + y + ',' + x + ')); google.maps.event.trigger(allDotIds[\'star\'], \'click\'); return false;" href="#">' + address_title + '</a>' + "<br/><p/>";
	var ball10 = ballIcons10.dotxy;

	newDiv.innerHTML = '<img src="' + ball10 + '"> ' + left_html;
		
	var parnode = document.getElementById("leftlist");
	parnode.appendChild(newDiv); 

}

function gotMtReply(myCallbackData, response, status) {

  if (status!=200) { return; }
  var xml = parseXml(response);
  var markers = xml.documentElement.getElementsByTagName("marker");

  // show alert for too many/few results.
  if (document.getElementById('search_nodot')) {
    document.getElementById('search_nodot').style.display="none";
    document.getElementById('search_manydot').style.display="none";
  }
  if (myCallbackData.myurl_opts.srch != '') {
    if  (markers.length<=0) {
      document.getElementById('search_nodot').style.display="block";
      document.getElementById('search_nodot_key').innerHTML=myCallbackData.myurl_opts.srch;
    } else if (markers.length>=90) {
      document.getElementById('search_manydot').style.display="block";
    }
  }

    
  var parnode = document.getElementById("leftlist");

  allMarkers = clearLocations(300, allMarkers, myCallbackData.dot_id);
  var prevLen = allMarkers.length;
  var dotcount = 0;

  if (markers.length<=0) {
	if(response.length>200) { alert('No results. Xml server error'); }
	else if (prevLen<=0) {
		document.getElementById('leftlist_noresults').style.display='block';
	}
  }
  else {
	if (document.getElementById('leftlist_noresults')) {
	  document.getElementById('leftlist_noresults').style.display='none';
	}
  }


  //x console.log("prevlen ", allMarkers.length);
  //x console.log("received ", markers.length, "results");
  for (var i = 0; i < markers.length; i++) {

    var markerType = markers[i].getAttribute("type");

    if (markerType=='n') {
		var ngid = markers[i].getAttribute("gid");
		  
		if (allDotIds['n' + ngid]) {
			continue;
		}
		allDotIdIndex = 'n' + ngid;
		//allDotIds['n' + ngid] = 1;
		
		
		var name = markers[i].getAttribute("name");
		var ntext = markers[i].getAttribute("ntext");
		
		var ball = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal4/icon8.png',
					    new google.maps.Size(32, 32));
		
		//var shadow = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal4/icon8s.png',
		//			    new google.maps.Size(32, 32));
		
		var myZindex = 200;
		var point = new google.maps.LatLng(
						parseFloat(markers[i].getAttribute("lat")),
						parseFloat(markers[i].getAttribute("lon")));
		
		var html = "<b>" + '<a href="/view_notes.php">' + name + '</a>' + "</b><br/><p/>";
		html += ntext;

    }
    else {
		
		var valid = markers[i].getAttribute("valid");
		var gid = markers[i].getAttribute("dot_id");

		//console.log(i, "index ", allDotIdIndex, "valid", valid);
		
		if (valid==3) { continue; } // intermediate
		
		if (allDotIds['g' + gid]) {
			//console.log("SKIPPED", i, "index ", allDotIdIndex, "valid", valid);
		  continue;
		}
		allDotIdIndex = 'g' + gid;
		//allDotIds['g' + gid] = 1;
		
		//console.log(i, "index ", allDotIdIndex, "valid", valid);
		var name = markers[i].getAttribute("name");
		var street = markers[i].getAttribute("street");
		var city = markers[i].getAttribute("city");
		var mt_url = markers[i].getAttribute("mt_url");
		var doturl = markers[i].getAttribute("doturl");
		var thumbtype = markers[i].getAttribute("thumbtype");
		//var address = markers[i].getAttribute("address");
		var ntext = markers[i].getAttribute("ntext");
		//var type = markers[i].getAttribute("type");
		var type='bar';
		
		var isopen = markers[i].getAttribute("isopen");
		
		var ball = ballIcons[isopen] || ballIcons.u;
		var ball10 = ballIcons10[isopen] || ballIcons10.u;
		var myZindex = ballZindex[isopen] || ballZindex.u;
		
		var point = new google.maps.LatLng(
							parseFloat(markers[i].getAttribute("lat")),
							parseFloat(markers[i].getAttribute("lon")));
		
		var ballhtml = '<img src="' + ball10 + '"> ';
		var html = "";
		if (isopen!='c' && isopen!='o') { html += ballhtml; }

		if (myCallbackData.target != '') {
			html += "<b>" + '<a target="' + myCallbackData.target + '" href="' + mt_url + '">' + name + '</a>' + "</b><br/><p/>";
		} else {
			html += "<b>" + '<a href="' + mt_url + '">' + name + '</a>' + "</b><br/><p/>";
		}
		
		if ((! myCallbackData.target)  && doturl!='' && doturl.indexOf('thumb://')!=0) {

		  if (myCallbackData.target != '') {
			  html += '<a target="' + myCallbackData.target + '" href="' + mt_url + '">';
		  } else {
			  html += '<a href="' + mt_url + '">';
		  }
		  if (! ntext.match(/<i>/) ) {
			 html += ("<img style=\"float: left; border: 1px transparent; margin: 2px 10px 0 0;\" src=\"/thumb.php?sz=s&url=" + doturl + "\" onload=\"if (this.widt\h>30) {this.style.border=\'1px solid #777\';} this.alt=\'Thumbnails by Thumbshots.org\';\">");
		  } else {
			 html += ("<center><img style=\"border: 1px transparent;\" src=\"/thumb.php?url=" + doturl + "\" onload=\"if (this.width>30) {this.style.border=\'1px solid #777\';} this.alt=\'Thumbnails by Thumbshots.org\';\"><\/center>");
		  }
		} else if (doturl.indexOf('thumb://')==0) {
		  if (thumbtype==100) {
			 html += ("<center><img src=\"" + doturl.substring(8) + "\" width=120 border=1 ><\/center>");
		  } else {
			 html += ("<center><img src=\"" + doturl.substring(8) + "\" width=78 border=1 ><\/center>");
		  }
		}
		html += "</a>";
		
		var tiny_hours = markers[i].getAttribute("thours");

		if (isopen=='c' || isopen=='o') {
			html += ballhtml + tiny_hours + '<br>';
		}
		html += ntext + "<br/><p/>";
		
		html += '<a href="' + mt_url + '">' + "More info</a><br/>\n";
		//var icon = customIcons[type] || {};
	}

	var myTitle = name + " - " + street + ", " + city;

	var myClickable = true;
	if (myCallbackData.preview) {
	  myClickable = true;
	}

	var marker = new google.maps.Marker({
	  map: map,
		   icon: ball,
		   //shadow: shadow,
		   position: point,
		   title: myTitle,
		   clickable: myClickable,
		   zIndex: myZindex
		   });

	if (valid==1 || valid==2) {
		marker.dot_id = gid;
		allMarkers.push(marker);
		dotcount++;

		//console.log("set " + allDotIdIndex + " = to " + marker);
		allDotIds[allDotIdIndex] = marker;

		if (1 || !myCallbackData.preview) {
		  bindInfoWindow(marker, map, infoWindow, html);
		}
	}
	
	// left side display (not intermediates)
	if (markerType!='n' && valid!=3) {
		newDiv = document.createElement("div");
		newDiv.id = "ld_" + gid;

		var left_html = '<a title="' + myTitle + '" onclick="google.maps.event.trigger(allDotIds[\'' + allDotIdIndex + '\'], \'click\'); return false;" href="' + mt_url + '">' + name + '</a>' + "<br/><p/>";
		
		//var ball10 = ballIcons10[isopen] || ballIcons10.u;
		newDiv.innerHTML = '<img src="' + ball10 + '"> ' + (prevLen+dotcount) + ". " + left_html;
		
		if (parnode) { parnode.appendChild(newDiv); }

		//document.getElementById('leftdot'+i).onclick=getMarkerHandler(marker);
	}


  }
  //x console.log("pushed ", dotcount);


    // remove ajax spinner after a bit.
    setTimeout(function(){ 
	if (document.getElementById('maploading')) { 
	  document.getElementById('maploading').style.visibility="hidden";
	} 
    }, 500);
    // alert(allMarkers.length);

    if (firstTime) {
		firstTime = 0;
	    showFirstPopups();
    	//google.maps.event.trigger(allMarkers[3], 'click');
	    //showDotInfoId(1105545);
	}
}

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
				  if (currentInfoMarker != marker) {
				    currentInfoMarker = marker;
				    infoWindow.setContent(html);
				    infoWindow.open(map, marker);
				  }
				});
  google.maps.event.addListener(infoWindow, 'closeclick', function() {
				  currentInfoMarker = null;
				});
}

function parseXml(str) {
  if (window.ActiveXObject) {
    var doc = new ActiveXObject('Microsoft.XMLDOM');
    doc.loadXML(str);
    return doc;
  } else if (window.DOMParser) {
    return (new DOMParser).parseFromString(str, 'text/xml');
  }
}

// End --->

