﻿///*******************************************************************************
//*
//*   AJAXComms.js
//*   Andrew McNerlin
//*   Fluent Technology 2008
//*
//********************************************************************************/


/*******************************************************************************
*
*   HTTP
*
********************************************************************************/
function HTTP() 
{
	var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try 
		{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e) 
		{
   	
			try 
			{
     				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
   			} 
			catch (E) 
			{
    				xmlhttp=false
   			}
  		}
 	@else
  		xmlhttp=false
 	@end @*/

 	if (!xmlhttp) 
	{
  		try 
		{
   			xmlhttp = new XMLHttpRequest();
  		} 
		catch (e) 
		{
   			xmlhttp=false
  		}
 	}
 	return xmlhttp
}	

/*******************************************************************************
*
*   getGeographiesByCoords
*
********************************************************************************/
    
function getGeographiesByCoords(url,dragStartEasting,dragStartNorthing,dragEndEasting,dragEndNorthing)
{
    xmlhttp=new HTTP();
	if (xmlhttp) 
	{
	    //alert(url + '&dSE=' + dragStartEasting + '&dSN=' + dragStartNorthing + '&dEE=' + dragEndEasting + '&dEN=' + dragEndNorthing);
	    //window.open(url + '&dSE=' + dragStartEasting + '&dSN=' + dragStartNorthing + '&dEE=' + dragEndEasting + '&dEN=' + dragEndNorthing);
	    xmlhttp.open("GET", url + '&dSE=' + dragStartEasting + '&dSN=' + dragStartNorthing + '&dEE=' + dragEndEasting + '&dEN=' + dragEndNorthing,true);
		xmlhttp.onreadystatechange=processGeographiesByCoords;
   		xmlhttp.send(null);
	}
	else
	{
		alert('Failed to get list of geographies');
	}
}

/*******************************************************************************
*
*   processGeographiesByCoords
*
********************************************************************************/
function processGeographiesByCoords() 
{
	
	if (xmlhttp.readyState == 4) 
	{
		if (xmlhttp.status == 200) 
		{
			var textResponse = xmlhttp.responseText;
			
			if (textResponse.length>0)
			{
			    document.getElementById('GeographyList').innerHTML = textResponse;
			}
			else
			{
			    document.getElementById('GeographyList').innerHTML = 'No geographies found';
			    return false;
			}
		}
		else
		{
			alert("There was a problem retrieving the geography list XML data:\n" + xmlhttp.statusText);
        	}
    	}
}
