//------------------------------------------------  
// zoomto a specific latitude and longitude
function zoomto(thelon,thelat)
{
map.setCenter(new GLatLng( thelat,thelon), 16);
}



//------------------------------------------------  	
// 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) {

if (!response || response.Status.code != 200) {
	alert("Sorry, we were unable to geocode that address");
} else {
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1],
	place.Point.coordinates[0]);
	marker = new GMarker(point);
	map.addOverlay(marker);
	document.getElementById('lat').value = place.Point.coordinates[1]
	document.getElementById('lon').value = place.Point.coordinates[0]
	marker.openInfoWindowHtml(place.address);
	map.setCenter(new GLatLng( place.Point.coordinates[1],place.Point.coordinates[0]), 16);
}
}			


//------------------------------------------------  				
// 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() {
	var address = document.forms["mapform"].searchaddress.value;
	geocoder.getLocations(address, addAddressToMap);
}

//------------------------------------------------  
//validate for numeric text into a field
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
//------------------------------------------------  
//replace characters that cause error when writing 
function ReplaceCharacters(thevariable)
{
	var myvariable = thevariable
	myvariable = myvariable.replace(/ /g,"_");
	myvariable = myvariable.replace(/&/g,"---");
	myvariable = myvariable.replace(/'/g,"\'");
	return myvariable;
}


//------------------------------------------------  
//called from load XML doc
function state_Change()
 
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  textstring =  xmlhttp.responseText;
  
  textstring = String(textstring);
  document.getElementById(globalid).innerHTML=textstring;

  }
  else
  {
  alert("Problem retrieving data:" + xmlhttp.statusText)
  }
  }
}

//------------------------------------------------  
//calls a div tag and expands based on ivalue
function EXPANDDATA(divid,ivalue)
{

if (document.getElementById(divid).innerHTML.length > 0)
  {
  document.getElementById(divid).innerHTML='';
  }
else
  {
  loadXMLDoc(ivalue,divid);
  }
}

function Generate_Random_Number()
{
	var rand = new Array();
	var d = new Date()
	rand[0] = d.getMonth() + 1;
	rand[0] = PadDigits(rand[0],2)
	rand[1] = d.getDate();
	rand[1] = PadDigits(rand[1],2)
	rand[2] = d.getFullYear();
	rand[3] = d.getSeconds();
	rand[3] = PadDigits(rand[3],2)
	rand[4] = d.getMilliseconds();
	rand[4] = PadDigits(rand[4],3)
	rand[5] = Math.floor(Math.random()*101);
	rand[5] = PadDigits(rand[5],3)
	var rnumber = rand.join("");
	return rnumber;
}

 function PadDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    } 
