﻿var geocoder = null;
function initialize() 
{
//alert("initialized fired");
  if (GBrowserIsCompatible()) {
    geocoder = new GClientGeocoder();
 //   alert("initialized completed"); 
  }
}
function geoSubmit(address)
{
//alert("geo Fired");

//alert("address: " + address);
	if (geocoder)
    {
        geocoder.getLatLng(address, function(point) {
            if (!point) {
               // alert("error: " + address);
                document.getElementById("ctl00_mainPage_geocodes").value = "err";
                document.getElementById("ctl00_mainPage_txtZip").focus()
                document.getElementById("ctl00_mainPage_rfvZip").innerHTML = "* Invalid Address.";
                document.getElementById("ctl00_mainPage_submitClicked").value = "False";

                return geocoder;
            }
            else {
              //  alert("found location");
                document.getElementById("ctl00_mainPage_geocodes").value = point;
                document.getElementById("ctl00_mainPage_btnSubmit").disabled = false;
                //WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$mainPage$btnSubmit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false));
                document.getElementById("ctl00_mainPage_submitClicked").value = "True";
                __doPostBack("ctl00_mainPage_btnSubmit", "");
                
            }
        }
	    );
	}

}
function geoFullAddressSubmit()
{
    var street;
    var city;
    var zip;
    var address;

    street = document.getElementById("ctl00_mainPage_txtStreet").value
    city = document.getElementById("ctl00_mainPage_txtCity").value
    zip = document.getElementById("ctl00_mainPage_txtZip").value
    address = street + ", " + city + ", " + zip;
    geoSubmit(address);
}
function geoWorldAddressSubmit()
{
    var street;
    var city;
    var country;
    var zip;
    var address;

    street = document.getElementById("ctl00_mainPage_txtStreet").value
    city = document.getElementById("ctl00_mainPage_txtCity").value
    country=document.getElementById("ctl00_mainpage_ddlCountry").value
    zip = document.getElementById("ctl00_mainPage_txtZip").value
    address = street + ", " + city + ", " + country + "," + zip;
    geoSubmit(address);
}
function geoZipSubmit()
{
//alert("zip submit");
    if (document.getElementById("ctl00_mainPage_txtZip"))
    {
  //  alert("zip box found");
        var address = document.getElementById("ctl00_mainPage_txtZip").value;
    //alert("zip txt found");
    }
    else
    {
    //alert("no zip found, using nowhere");
        address = "99901";
    }
    geoSubmit(address);  
}
function clickSearch()
{
    if (document.getElementById("ctl00_radSearch_0").checked)
    {
        geoSearch();
    }
    if (document.getElementById("ctl00_radSearch_1").checked)
    {
        geoSearch();
    }
    if (document.getElementById("ctl00_radSearch_2").checked)
    {
        geoSearch();
    }
}
function geoSearch()
{
//alert("GEO FIRED");
    if (geocoder)
    {
//alert("FOUND GEO");
        var address;
        address = document.getElementById("ctl00_txtSearch").value;
  //      alert("ADDY: " + address);
        geocoder.getLatLng(address, function(point){
		        if (!point) 
		        {
    //                alert("NO FIND ADDY");
			        document.getElementById("ctl00_geoSearchCoordinates").value = "err";
                }
		        else 
		        {
    		        document.getElementById("ctl00_geoSearchCoordinates").value = point;	    
		        }
//alert("ALMOST GOING TO POST BACK");
                document.getElementById("ctl00_geoSearchClicked").value = "True";
                __doPostBack("ctl00_geoSearchClicked","");
	        }
        );
    }
}

/*
function getGeo(address)
{

}


function fireGeo(box)
{
    if (box.value.length > 4)
    {
        getGeo(box.value);
    }
    else 
    {
        document.getElementById("ctl00_mainPage_btnSubmit").disabled = true;
    }
}
	*/
