// JScript File
var ajax = new sack();
var gTimer

function whenStatusLoading(){
	var e = document.getElementById('CustomAddressGeolocateStatus'); 
	//e.style.display='';
	e.innerHTML = "<p>Searching...</p>";
}

function whenStatusLoaded(){
	var e = document.getElementById('CustomAddressGeolocateStatus'); 
	e.innerHTML = "<p>Loading...</p>";
}

function whenStatusInteractive(){
	var e = document.getElementById('CustomAddressGeolocateStatus'); 
	e.innerHTML = "<p>Processing Data...</p>";
}

function whenStatusCompleted(){
	var e = document.getElementById('CustomAddressGeolocateStatus'); 
	if(this.response=='')
		e.innerHTML = 'Please try another address.';
	else{
		//e.innerHTML = 'Address Verified';

		var arrLatLong = this.response.split(",")

		if (document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLatitude') != null){
			document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLatitude').value = arrLatLong[0];
			document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLongitude').value = arrLatLong[1];
			e.innerHTML = 'Location Verified, Please Click <i>Filter Events</i> [' + arrLatLong[2] + ']';
		}
		else{
			e.innerHTML = 'Location Verified [' + arrLatLong[2] + ']';
		}
	}

	//document.getElementById('txtStatus').innerHTML = trim(document.getElementById('statustxt').value);
	//doDisplayStatus();
}

function doCommitQuery(){

	//alert(document.getElementById('setstatus').innerHTML);
	//var statustxt = document.getElementById('statustxt').value;
	sQry = trim(document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioAddress').value);

	ajax = new sack();
	ajax.setVar("a", sQry); // recomended method of setting data to be parsed.
	ajax.requestFile = "/ajax/geo.aspx";
	ajax.method = "POST";
	ajax.element = 'CustomAddressGeolocateStatus';
	ajax.onLoading = whenStatusLoading;
	ajax.onLoaded = whenStatusLoaded; 
	ajax.onInteractive = whenStatusInteractive;
	ajax.onCompletion = whenStatusCompleted;
	ajax.runAJAX();
}

function doAQuery(sQry){
	clearTimeout(gTimer);
	gTimer = setTimeout("doCommitQuery()",500);
}


function whenCGStatusLoading(){
	var e = document.getElementById('ClassAddressLookupResult'); 
	//e.style.display='';
	e.innerHTML = "<p>Searching...</p>";
}

function whenCGStatusLoaded(){
	var e = document.getElementById('ClassAddressLookupResult'); 
	e.innerHTML = "<p>Loading...</p>";
}

function whenCGStatusInteractive(){
	var e = document.getElementById('ClassAddressLookupResult'); 
	e.innerHTML = "<p>Processing Data...</p>";
}

function whenCGStatusCompleted(){
	var e = document.getElementById('ClassAddressLookupResult'); 
	if(this.response=='')
		e.innerHTML = 'Please try another address.';
	else{
		//e.innerHTML = 'Address Verified';

		var arrLatLong = this.response.split(",")

		if (document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLatitude') != null){
			document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLatitude').value = arrLatLong[0];
			document.getElementById('ctl00_ContentPlaceHolder1_CustomStudioLongitude').value = arrLatLong[1];
			e.innerHTML = 'Location Verified, Please Click <i>Filter Events</i> [' + arrLatLong[2] + ']';
		}
		else{
			e.innerHTML = 'Location Verified [' + arrLatLong[2] + ']';
		}
	}
}

function doCommitCGQuery(){
	sQry = trim(document.getElementById('ctl00_ContentPlaceHolder1_ClassAddress').value);

	ajax = new sack();
	ajax.setVar("a", sQry); // recomended method of setting data to be parsed.
	ajax.requestFile = "/ajax/geo.aspx";
	ajax.method = "POST";
	ajax.element = 'ClassAddressLookupResult';
	ajax.onLoading = whenCGStatusLoading;
	ajax.onLoaded = whenCGStatusLoaded; 
	ajax.onInteractive = whenCGStatusInteractive;
	ajax.onCompletion = whenCGStatusCompleted;
	ajax.runAJAX();
}

function doCGQuery(sQry){
	clearTimeout(gTimer);
	gTimer = setTimeout("doCommitCGQuery()",500);
}

function checkStatusEnter(event, oStatus){
	var iASCIIKey = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if(iASCIIKey == 13){
		return false;
	}
}

function right(sTheString, iDigits){
    if (iDigits <= 0)
       return "";
    else if (iDigits > String(sTheString).length)
       return sTheString;
    else {
       var iLen = String(sTheString).length;
       return String(sTheString).substring(iLen, iLen - iDigits);
    }
}

function trim(sTheString) {
	return sTheString.replace(/^\s+|\s+$/g,"");
}