// this JavaScript code was written by Andy Lammers 
// AndyL0440@hotmail.com
// This script will do some cool stuff


	
function xmlhttpPost_city(strURL) 
{
	//
	
	//alert("hello");
	
    var req = false;
    req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) 
	{
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
        		//updatepage_tru(req.responseXML);
				updatepage_tru(req.responseText);
			}
		}
		try
		{
			req.open("POST", strURL, true);
			req.send(getquerystring_tru());
		}catch(e)
		{
			alert("exception" + e);
		}
	}
}

function getquerystring_tru() 
{
	
    var word = "sendStr";
   // var qstr = 'method=' + escape("youtube.videos.list_featured") + "&dev_id=" + escape("cYBapzXrXtw");
	var qstr ="";
	 // NOTE: no '?' before querystring
    return qstr;
}

function updatepage_tru(textObj)
{
	//alert(textObj);
	var columIDs = new Array("lat","long");
	var a1 = new Array();
	var a2 = new Array();
	a1 = textObj.split("\n");
	for(var i=0; i<a1.length; i++)
	{
		a2[i] = new Array();
		a2[i] = a1[i].split(",");
	}
	//alert(a2[0]);
	drawGeoData(a2);
	
 /*
	a1[0] = new Array();
	var ii = 0
	for(var i=0; i<nodes.childNodes.length; i++)
	{
		var newChildNodes = nodes.childNodes[i];
		if(newChildNodes.nodeName == "state")
		{
			a1[ii] = new Array();
			//if(i<5)
			//{
				//alert(getChild_tru(newChildNodes, "name").firstChild.nodeValue );
			//}
			a1[ii][0] = getChild_tru(newChildNodes, "name").firstChild.nodeValue;
			a1[ii][1] = getChild_tru(newChildNodes, "stateCode").firstChild.nodeValue;
			a1[ii][2] = getChild_tru(newChildNodes, "latitude").firstChild.nodeValue;
			a1[ii][3] = getChild_tru(newChildNodes, "longitude").firstChild.nodeValue;
			//a1[ii][0] = newChildNodes.getAttribute("lat");
			//a1[ii][1] = newChildNodes.getAttribute("long");
			ii++;
		}	
	}
	
	
	getSomeTruData(a1);
	*/
	
}



function getChild_tru(nodeObj, childName)
{
	var returnNode = null;
	for (var j = 0; j<nodeObj.childNodes.length; j++)
	{
		if(nodeObj.childNodes[j].nodeName.toUpperCase()==childName.toUpperCase())
		{
			returnNode = nodeObj.childNodes[j];
		}
	}
	if(returnNode!=null)
	{
		return returnNode;
	}else
	{
		//text1.text="none";
		return null;
	}
	return;
}
function getrssNode_tru(nodes)
{
	if(nodes.nextSibling.nodeName=="rss")
	{
		return nodes.nextSibling;
	}else
	{
		return nodes.nextSibling.nextSibling;
	}
	/*
	if(nodes.nextSibling.nodeName=="rss")
	{
		alert(nodes.nextSibling.nodeName);
		return nodes.nextSibling;
		
	}else
	{
		getrssNode(nodes.nextSibling);
	}
	*/
	
}




		  var delay = 100;
		  
		  var geo = new GClientGeocoder(); 
	
		  // ====== Array for decoding the failure codes ======
		  var reasons=[];
		  reasons[G_GEO_SUCCESS]            = "Success";
		  reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
		  reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
		  reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
		  reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
		  reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
		  reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
		  reasons[403]                      = "Error 403: Probably an incorrect error caused by a bug in the handling of invalid JSON.";
		  
		  // ====== Geocoding ======
		  var geoPoints = new Array();
		  
		  function getAddress(search, next, index_p) 
		  {
			  
			 
			  
			  geo.getLocations(search, function (result)
			  { 
				// If that was successful
				if (result.Status.code == G_GEO_SUCCESS) 
				{
				  // Lets assume that the first marker is the one we want
				  var p = result.Placemark[0].Point.coordinates;
				  var lat=p[1];
				  var lng=p[0];
				  // Display the results in XML format
				  var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" lat="' +lat+ '" lng="' +lng+ '"&gt;<br>';
				  
				  var index = search;
				   
				  geoPoints.push([lat, lng, index]);
				  document.getElementById("message").innerHTML += xml;
				}
				else {
				  // === if we were sending the requests to fast, try this one again and increase the delay
				  if (result.Status.code == G_GEO_TOO_MANY_QUERIES) {
					nextAddress--;
					delay++;
					var xml = '&nbsp;&nbsp;&lt;marker delay="' + delay + '" error="' +result.Status.code+ '"&gt;<br>';
					
				  } else {
					var reason="Code "+result.Status.code;
					if (reasons[result.Status.code]) {
					  reason = reasons[result.Status.code]
					} 
					var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" error="' +reason+ '"&gt;<br>';
					document.getElementById("message").innerHTML += xml;
				  }   
				}
				next();
			  }
			);
			
			
		  }
	
	
	
		  // ======= An array of locations that we want to Geocode ========
		  var addresses = [
					/*
					"1060 West Addison Street, Chicago, IL",
					"99, rue de Rivoli, Paris 75001",
					*/
					
					"ILLINOIS,CHICAGO",
					"GEORGIA,ATLANTA",
					"NEW YORK,NEW YORK"
					/*
					"London, UK",
					"1600 Pennsylvania Avenue, Washington, DC",
					"A totally bogus address"
					*/
					
		  ];
	
		  // ======= Global variable to remind us what to do next
		  var nextAddress = 0;
	
		  // ======= Function to call the next Geocode operation when the reply comes back
	
			  function theNext() 
			  {
					if (nextAddress < addresses.length) 
					{
					  setTimeout('getAddress("'+addresses[nextAddress]+'",theNext, ' + nextAddress + ')', delay);
					  nextAddress++;
					} else {
					  document.getElementById("message").innerHTML += "&lt;/markers&gt;";
					  createGeoOverlay(geoPoints);
					}
			  }
			  
			  
	 
    // display a warning if the browser was not compatible
  









