var xmlHttp;

var imgMap = 'imgMap';
var aImgMap = 'aImgMap';

function getLocation(id, type){
xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	if(id != "")
	{
		var selectedItem = G(id).options[G(id).selectedIndex].value;
		
		var url = "locations.asp";
		url = url + "?id=" + selectedItem;
		url = url + "&type=" + type;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(url);
		xmlHttp.onreadystatechange = function stateChanged(){
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					var response = xmlHttp.responseText;
					parseImages(response);
				}
			}	
		}
	}
}

function parseImages(input){
	var selectCounty = G(imgMap);
	var arImage = input.split("|");
	
	var SmallImageURL = arImage[0];
	var BigImageURL = arImage[1];
	var AddressInfo = arImage[2];
	
	G(imgMap).src = SmallImageURL;
	G(aImgMap).href = BigImageURL;
	G("divAddress").innerHTML = AddressInfo;
}

function fillCounties(id, type, element){
xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	if(id != "")
	{
		var url = "locations.asp";
		url = url + "?id=" + id;
		url = url + "&type=" + type;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(url);
		xmlHttp.onreadystatechange = function stateChanged(){
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					var response = xmlHttp.responseText;
					//alert(response);
					parseCountyFill(response, element);
				}
			}	
		}
	}
}

function parseCountyFill(input, element){
	var selectCounty = G(element);
	selectCounty.options.length = 0;
	var arCounty = input.split(",");
	
	for(i=0; i<arCounty.length; i++){
		if(arCounty[i] != ""){
			var tempArrayIdName = arCounty[i].split("|");
			var CountyName = tempArrayIdName[1];
			var CountyId = tempArrayIdName[0];
			selectCounty.options[i] = new Option(CountyName, CountyId);
		}
	}
}

function G(id){
	return document.getElementById(id);	
}


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; */

     var xmlHttp = null;
     
        if(window.XMLHttpRequest){
            xmlHttp = new XMLHttpRequest();
        } 
        else if(window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        return xmlHttp;
        //return false;

}