// JavaScript Document

var xmlHttp

function stringFilter(input) {
	filteredValues = "() ";     // Characters stripped out
	var i;
	var returnString = "";
	for (i = 0; i < input.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = input.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
	}
	return(returnString);
}

function populate_dealers(data) {

	getString = new String();
	
	southwest = new String(data.getSouthWest());
	northeast = new String(data.getNorthEast());
	northeast = stringFilter(northeast);
	southwest = stringFilter(southwest);
	northeast_split = northeast.split(',');
	southwest_split = southwest.split(',');
	
	getString = "?nelat=" + northeast_split[0] + "&nelon=" + northeast_split[1] + "&swlat=" + southwest_split[0] + "&swlon=" + southwest_split[1];

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request")
	return
 	}

	var url="dealers_ajaxlist.php"
	url=url+getString;
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
	
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("dealer_list").innerHTML=xmlHttp.responseText 
 } 
}


function GetXmlHttpObject() {

	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
