 //<![CDATA[

    var map;
    var geocoder;
var theform;

    function load() {
      //map = new GMap2(document.getElementById("map"));
      //map.setCenter(new GLatLng(34, 0), 1);
      try{
      
     
      geocoder = new GClientGeocoder();
      }
      catch(exception)
      {}
      
     
    }

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
      //map.clearOverlays();
      var thisform;
      var mozillaFlag = false;
      var address0; //= "";
      
      if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			thisform = document.Form1;
		}
		else {
			thisform = document.forms["Form1"];
		}
		
      var results = false;
      var loc;
      var XMLHttpRequestObject;
      
      loc = thisform.LeftTopnav1_SetLocation1_address.value
      var reqUrl;
     //reqUrl = '/webrequestor.aspx?contentType=text/xml&url=http://api.local.yahoo.com/MapsService/V1/geocode?appid=seniorsa2z&location=' + loc + '&stamp=' +(new Date()).getTime();
      //showinput(reqUrl);
      reqUrl = '/msexcel/xmlhttp.aspx?url=http://api.local.yahoo.com/MapsService/V1/geocode?appid=seniorsa2z&location=' + loc + '&stamp=' +(new Date()).getTime();
    
      var latitude, longitude, address, city, state, zipcode, country;
      country = ""; 
       state = ""; 
       city = ""; 
       county = ""; 
       city = ""; 
       streetLine = ""; 
       zip = ""; //
      if (!response || response.Status.code != 200 ||!geocoder) {
    // if(!geocoder){
			//var request = GXmlHttp.create();
		
			if (window.XMLHttpRequest) 
				{
					XMLHttpRequestObject = new XMLHttpRequest();
					XMLHttpRequestObject.overrideMimeType("text/xml");
					mozillaFlag = true;
				} 
			else if (window.ActiveXObject) 
				{
					XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
				}
			//alert(XMLHttpRequestObject + ' mFlag = ' + mozillaFlag);
			/// we have the object now run with it...
			if(XMLHttpRequestObject) 
			{
				XMLHttpRequestObject.open("GET", reqUrl, false);
				XMLHttpRequestObject.onreadystatechange = function() {
				
				if  (XMLHttpRequestObject.readyState == 4 
					&& XMLHttpRequestObject.status == 200)
					
				 {
				//if (XMLHttpRequestObject.readyState == 4 
					//&& XMLHttpRequestObject.status == 200) {
					//alert(XMLHttpRequestObject.responseXML);
				 var xmlDocument = XMLHttpRequestObject.responseXML;
					// This doesn't fire
						
				if(mozillaFlag)
					{
					removeWhitespace(xmlDocument);
				}
					/// Parse the XML
					//alert(XMLHttpRequestObject.getAllResponseHeaders());
					//alert(XMLHttpRequestObject.responseXML);
					results = false;
					var result;
					var sLat, sLong, sAddress, sCity, sState, sZip, sCountry;
					result = xmlDocument.getElementsByTagName("Result");
					//alert('xmlDocument' + result.length);
					//alert(result[0]);
					var resultNode;
					resultNode = xmlDocument.documentElement;
					//alert(result[0].attributes.getNamedItem("precision").nodeValue);
					var nodeText = xmlDocument.createTextNode(""); 
					//If xml node is missing we need to insert blankstring to prevents errors
					//var precision = result[0].attributes.getNamedItem("precision").nodeValue;
					var precision;
					try {
						precision = result[0].attributes.getNamedItem("precision").nodeValue;
					}
					 catch(exception) 
					{
						alert('Unable to find the location specified');
						return false;
					}
					
					//alert(precision);
					latitude = xmlDocument.getElementsByTagName("Latitude");
					longitude = xmlDocument.getElementsByTagName("Longitude");
					address = xmlDocument.getElementsByTagName("Address");
					city = xmlDocument.getElementsByTagName("City");
					state = xmlDocument.getElementsByTagName("State");
					zipcode = xmlDocument.getElementsByTagName("Zip");
					country = xmlDocument.getElementsByTagName("Country");  
										
									switch (precision) 
										{ 
										case "country" : 
											//address = "";
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = "";
											sState = "";
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
													break; 
										case "state" :
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = "";
											sState = state[0].firstChild.nodeValue;
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
											break; 
										case "city" :
										
											//address[0].appendChild(nodeText);
											//zipcode[0].appendChild(nodeText);
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
											//sZip = "";
											
											 
											break; 
										case "address" :
											//do nothing all nodes are full 
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = address[0].firstChild.nodeValue;
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = zipcode[0].firstChild.nodeValue;
											sCountry = country[0].firstChild.nodeValue;
											break; 
										case "zip" : 
											//we have all feilds excpet for an address
											
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = zipcode[0].firstChild.nodeValue;
											sCountry = country[0].firstChild.nodeValue;
										
											
											break; 
											} 
								  

						//var warning = (result[0].attributes.getNamedItem("warning"));
						//myhemi = result[0].attributes.getNamedItem("warning").nodeValue;
						//address0 = "";
						//alert(sAddress);
						address0 = "";
						if ((sAddress) && !sAddress == ""){
						//alert((sAddress) + 'saddress');
							address0 = 	address0 + sAddress +', '
						} 
						if ((sCity) && !sCity == ""){
							address0 = 	address0  + sCity + ', '
						} 
						if ((sState) && !sState == ""){
							address0 = 	address0  + sState + ' '
						} 
						if ((sZip) && !sZip == ""){
							address0 = 	address0  + sZip
						} 
						if ((sCountry) && !sCountry == ""){
							address0 = 	address0  + ' ' + sCountry
						} 
						
						lat =  sLat;
						lng = sLong;
						//alert(address0);
						//alert(lng);
						//alert(lat);
						/*var displayText = 'Precision = ' + precision + '<br /> ' ;  
						displayText = displayText + 'Latidue :' + sLat + '<br>' ;
						displayText = displayText + 'Longitude :' + sLong + '<br>' ;
						displayText = displayText + 'Address : ' + sAddress + '<br>' ;
						displayText = displayText + 'City : ' + sCity + '<br>' ;
						displayText = displayText + 'State : ' + sState + '<br>' ;
						displayText = displayText + 'Zipcode : ' + sZip + '<br>' ;
						displayText = displayText + 'Country : ' + sCountry + '<br>';*/
						}
					}
			} // end on ready state function
			//alert('x obj ' + XMLHttpRequestObject);
			XMLHttpRequestObject.send(null);
			
			//alert('a0 before m flass' + (address0));
			if (mozillaFlag) {
				
				//alert('3m test');
				//alert(XMLHttpRequestObject.responseXML);
				//alert(XMLHttpRequestObject.readystate == 4);
				//alert(XMLHttpRequestObject.status == 200);
				var result;
				var xmlDocument = XMLHttpRequestObject.responseXML;
					var sLat, sLong, sAddress, sCity, sState, sZip, sCountry;
					//alert('domtagname' + (xmlDocument.getElementsByTagName));
					result = xmlDocument.getElementsByTagName("Result");
					//alert('xmlDocumentlenmf' + result.length);  
				//if (XMLHttpRequestObject.status == 200) 
				//{
				results = false;
					var result;
					var sLat, sLong, sAddress, sCity, sState, sZip, sCountry;
					result = xmlDocument.getElementsByTagName("Result");
					//alert('xmlDocumentlenmf' + result.length);
					//alert(result[0]);
					var resultNode;
					resultNode = xmlDocument.documentElement;
					//alert(result[0].attributes.getNamedItem("precision").nodeValue);
					var nodeText = xmlDocument.createTextNode(""); 
					//If xml node is missing we need to insert blankstring to prevents errors
					var precision;
					try {
						precision = result[0].attributes.getNamedItem("precision").nodeValue;
					}
					 catch(exception) 
					{
						alert('Unable to find the location specified');
						return false;
					}
					
					//alert(precision);
					latitude = xmlDocument.getElementsByTagName("Latitude");
					longitude = xmlDocument.getElementsByTagName("Longitude");
					address = xmlDocument.getElementsByTagName("Address");
					city = xmlDocument.getElementsByTagName("City");
					state = xmlDocument.getElementsByTagName("State");
					zipcode = xmlDocument.getElementsByTagName("Zip");
					country = xmlDocument.getElementsByTagName("Country");  
										
									switch (precision) 
										{ 
										case "country" : 
											//address = "";
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = "";
											sState = "";
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
													break; 
										case "state" :
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = "";
											sState = state[0].firstChild.nodeValue;
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
											break; 
										case "city" :
										
											//address[0].appendChild(nodeText);
											//zipcode[0].appendChild(nodeText);
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = "";
											sCountry = country[0].firstChild.nodeValue;
											//sZip = "";
											
											 
											break; 
										case "address" :
											//do nothing all nodes are full 
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = address[0].firstChild.nodeValue;
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = zipcode[0].firstChild.nodeValue;
											sCountry = country[0].firstChild.nodeValue;
											break; 
										case "zip" : 
											//we have all feilds excpet for an address
											
											sLat = latitude[0].firstChild.nodeValue;
											sLong = longitude[0].firstChild.nodeValue;
											sAddress = "";
											sCity = city[0].firstChild.nodeValue;
											sState = state[0].firstChild.nodeValue;
											sZip = zipcode[0].firstChild.nodeValue;
											sCountry = country[0].firstChild.nodeValue;
										
											
											break; 
											} 
								  

						//var warning = (result[0].attributes.getNamedItem("warning"));
						//myhemi = result[0].attributes.getNamedItem("warning").nodeValue;
						
						//alert(sAddress);
						address0 = "";
						if (!sAddress == ""){
						//alert((!sAddress) + 'saddress');
							address0 = 	address0  + sAddress +', '
						} 
						if (!sCity == ""){
							address0 = 	address0  + sCity + ', '
						} 
						if (!sState == ""){
							address0 = 	address0  + sState + ' '
						} 
						if (!sZip == ""){
							address0 = 	address0  + sZip
						} 
						if (!sCountry == ""){
							address0 = 	address0  + ' ' + sCountry
						} 
						
						lat =  sLat;
						lng = sLong;
						}  
							//alert('a01' + (address0));
				//}	alert('a02' + (address0));
        //alert("Sorry, we were unable to geocode that address");
        //return;
      
      } 
      else 
     {
           results = true;
		}
      
      

      if (results == true) {
        place = response.Placemark[0];
        //alert(place.Point.coordinates[1] + ' ' + place.Point.coordinates[0]);
     
      // place = response.Placemark[myIndex];
    
        address0 = place.address; 
        lat = place.Point.coordinates[1]; 
        lng = place.Point.coordinates[0]; 



        if (place.AddressDetails && place.AddressDetails.Country) 
        {country = place.AddressDetails.Country.CountryNameCode; 
            if (place.AddressDetails.Country.AdministrativeArea) 
                {
                state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName; 
                        if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea) 
						{
						county = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName; 
                              if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality) 
                                {
                                city = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName; 
                                     if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare) 
                                        {
                                        streetLine = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName; 
                                        } 
                                        if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode) 
                                        { 
                                        zip = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber; 
                                        }    
                                }   
                        } 
                } 
                   
        } 
 }
 	
 if (address0 == "") {
	
 alert("Cound not find this location.  Please try again");
	return;
	}
else {
//if (geocoder) {
		//GDownloadUrl("/maps/setsessionlocation.aspx?address=" + address0 + "&latitude=" + lat + "&longitude=" + lng, function(data, responseCode) { // alert(data);
		//});
		//}
		//else {
		//alert(getCookie('location'));
		var XMLHttpRequestObject;
 			if (window.XMLHttpRequest) 
				{
					XMLHttpRequestObject = new XMLHttpRequest();
					XMLHttpRequestObject.overrideMimeType("text/xml");
					mozillaFlag = true;
				} 
			else if (window.ActiveXObject) 
				{
					XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
				}
				var now = new Date();
			var setlocationurl = "/maps/setsessionlocation.aspx?address=" + address0 + "&latitude=" + lat + "&longitude=" + lng + "&ts="+ now
			alert(setlocationurl);
			deleteCookie('location');
			//alert(XMLHttpRequestObject + ' mFlag = ' + mozillaFlag);
			/// we have the object now run with it...
			if(XMLHttpRequestObject) 
			{
				XMLHttpRequestObject.open("GET", setlocationurl, false);
				XMLHttpRequestObject.onreadystatechange = function() {if  (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){} }
				
				}
				 XMLHttpRequestObject.send(null);
			//}
			address0 = XMLHttpRequestObject.responseText
				// alert(XMLHttpRequestObject.responseText);
 //alert(address0 + ' before insert');
 thisform.LeftTopnav1_SetLocation1_address.value = ""; 
        document.getElementById('LeftTopnav1_SetLocation1_mylocationlab').innerHTML = "Current Location: <br />" + address0 + '<br> Change Location'//+ place.Point.coordinates[1] + ' ' + place.Point.coordinates[0];
		//alert(document.getElementById('LeftTopnav1_SetLocation1_mylocationlab').innerHTML)
		//thisform.LeftTopnav1_SetLocation1_address.value = "Current Location: <br />" + address0 + '<br> Change Location'
		//alert(getCookie('location'));
		//deleteCookie('location');
		//alert(getCookie('location'));
		//setCookie('location', address0);
		//alert(getCookie('location'))
		//setCookie('longitude', lng);
		//setCookie('latitude', lat);
			 //place.Point.coordinates[1] + '||' + place.Point.coordinates[0]);
       // point = new GLatLng(place.Point.coordinates[1],
                           // place.Point.coordinates[0]);
        //marker = new GMarker(point);
        //map.addOverlay(marker);
        //marker.openInfoWindowHtml(place.address + '<br>' +
        //  '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
     
    }
}
    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation(address) {
     //var address = document.forms[0].q.value;
     var thisaddress = address;
     //alert(thisaddress);
      //alert(address);
      try {
      if (geocoder) {
      geocoder.getLocations(thisaddress, addAddressToMap);
      }
     
      }
      catch(exception) 
      {
		
		}
		if (!geocoder) {
		addAddressToMap(null);
		}
    }

   // findLocation() is used to enter the sample addresses into the form.
   function findLocation(address) {
   
      //document.forms[0].address.value = address;
      showLocation(address);
    }
   function showthisformaddress(thisform) {
   theform = thisform;
   
   load();
   findLocation(thisform.LeftTopnav1_SetLocation1_address.value);
   
	//alert(thisform.LeftTopnav1_SetLocation1_address.value);	
	}
		//else {
			//theform = document.forms["Form1"];
			//alert(document.forms["Form1"].elements["LeftTopnav1:SetLocation1:address"]);
   
		//}
   function removeWhitespace(xml)
      {
        var loopIndex;

        for (loopIndex = 0; loopIndex < xml.childNodes.length;
          loopIndex++) {

          var currentNode = xml.childNodes[loopIndex];

          if (currentNode.nodeType == 1) {
            removeWhitespace(currentNode);
          }

          if (((/^\s+$/.test(currentNode.nodeValue))) &&
            (currentNode.nodeType == 3)) {
              xml.removeChild(xml.childNodes[loopIndex--]);
          }
        }     
      }
     

    //]]>