//info
/*
 * 0 (uninitialized)
 * 1 (loading)
 * 2 (loaded)
 * 3 (interactive)
 * 4 (complete) 
 */

//utility

function jaxify(http_request,mode) {
	
	if (http_request.readyState != 4) return null;
	if (http_request.status != 200) {
		window.status = 'request failed: '+http_request.status;
	  	return false;
	}
	
		var requestReturn = http_request.responseText;
		//alert (requestReturn);
		
		//parse received CSV Object for latitude/longitude data		
		dataArray = requestReturn.split(',');
		
		searchLong = dataArray[3];
		searchLat = dataArray[2];
		searchZoom = 13;
		
		//execute local map centering function with new lat/long and zoom
		gMap.setCenter( new GLatLng( searchLat, searchLong ), searchZoom );	
	
}

function makeRequest(url) {

	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	  http_request = new XMLHttpRequest();
	  if (http_request.overrideMimeType) {
		  http_request.overrideMimeType('text/xml');
		  // See note below about this line
	  }
	} else if (window.ActiveXObject) { // IE
	  try {
		  http_request = new ActiveXObject("Msxml2.XMLHTTP");
		  
	  } catch (e) {
		  try {
			  http_request = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (e) {}
	  }
	}
	
	if (!http_request) {
	  window.status = 'failed creating asynchronous request.';
	  return false;
	}

	http_request.onreadystatechange = function() { jaxify(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);

}


function file_get_contents( url ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Legaev Andrey
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // *     example 1: file_get_contents('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
 	alert("in file get contents");
    var req = null;
    try { 
    		req = new ActiveXObject("Msxml2.XMLHTTP"); 
    	} catch (e) 
    	{
    		alert("step0");
        	try 
        	{ 
        		req = new ActiveXObject("Microsoft.XMLHTTP"); 
        	} catch (e) 
        		{
       	 			alert("step1");
            		try { req = new XMLHttpRequest(); } catch(e) {
            		alert("step2");
            	}
        }
    }
   // alert("step 3");
    if (req == null) throw new Error('XMLHttpRequest not supported');
 	alert("step 4");
    req.open("GET", url, false);
   // req.open("GET", url);
   // alert("after open");
    req.send(null);
   // alert("after send :"+req.responseText);
 
    return req.responseText;
}

function getLatLong(id) {
//alert("in the getLatLong() method");
	//format the geocoder URL passing in the received address/zip data	
	//var url = 'http://staging3.translink.org/geocode.jsp'+'?q='+document.getElementById(id).value+'&output=csv&key=ABQIAAAAyEAK9U_lzLdnKHRo49V64xSsIZP_uzhp-jsnhqBfk9kGVd7grxQDue9mxb67VnAAKndaCCn_Mwhcow';
	
	var url = 'getTranslink/geocode.jsp'+'?q='+document.getElementById(id).value+'&output=csv&key=ABQIAAAAov9xvMTWGMuGPAV-U4P_CRTF4Qt8E04B9nz3BzN6YHcIRmrzdxQ3W7SowrmZF3xfBJO94twP7XjYfg';
	
	//staging4.translink.org code: ABQIAAAAyEAK9U_lzLdnKHRo49V64xSsIZP_uzhp-jsnhqBfk9kGVd7grxQDue9mxb67VnAAKndaCCn_Mwhcow
	//staging3.translink.org code: ABQIAAAAyEAK9U_lzLdnKHRo49V64xS3nGX5y8zWQ6fQj3QreL66xH1n0RSTKANuk1r8RCCIbE-AWgXrxyTn9g
	// given by swirl translink.org API code: ABQIAAAA_tLc-kJhtAOi2PxE9btPKBTZXGjdPFBwlKhO6EaT_rOTFQvqzBSK2A2sDyNrCTNUxKx-w5f2jWttpQ
     //http://www.translink.org : ABQIAAAAov9xvMTWGMuGPAV-U4P_CRTF4Qt8E04B9nz3BzN6YHcIRmrzdxQ3W7SowrmZF3xfBJO94twP7XjYfg
     //http://translink.org :     ABQIAAAAyEAK9U_lzLdnKHRo49V64xQmFNc8FzfReXYBhWXMfgvx3KXitBShVaKpkhA7N1srK72l_MMv8VMX1A	
	// swirlclient.com API code: ABQIAAAAXZ1OMLWrd8xzNA-TSJv-gBTZXGjdPFBwlKhO6EaT_rOTFQvqzBQXapXWvTt0fAQGci9QQK6PQZ8TKA
	
	//window.open (url);
	
	var gMapsResponse = null;	
	if(document.getElementById(id)!=null)
		makeRequest(url);	
	return true;
	
}







