var isWorking = false;
var http = getHTTPObject();


function show(idLayer) {document.getElementById(idLayer).style.display='block';}
function showInline(idLayer) { document.getElementById(idLayer).style.display='inline'; }
function hide(idLayer) {document.getElementById(idLayer).style.display='none';}

function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}





function goCity()
{
	var obj1 = document.getElementById("frmSrch");
	var blnPass = false;
	
	if(obj1.selRegion.value=="")
	{
		alert("Please select a region.");
		obj1.selRegion.focus();
	}
	else if(obj1.selState.value=="")
	{
		alert("Please select a state/prov/cntry.");
		obj1.selState.focus();
	}
	else if(obj1.selCity.value=="")
	{
		alert("Please select a city.");
		obj1.selCity.focus();
	}
	else
	{
		var strC = obj1.selCity.value.split("~");
		strURL = "/hotels/" + obj1.selRegion.value + "/" + obj1.selState.value + "/" + strC[1] + "/";
		top.location.href=strURL;
	}
}
function goCityV()
{
	var obj1 = document.getElementById("frmSrch");
	var blnPass = false;
	
	if(obj1.selRegion.value=="")
	{
		alert("Please select a region.");
		obj1.selRegion.focus();
	}
	else if(obj1.selState.value=="")
	{
		alert("Please select a state/prov/cntry.");
		obj1.selState.focus();
	}
	else if(obj1.selCity.value=="")
	{
		alert("Please select a city.");
		obj1.selCity.focus();
	}
	else
	{
		var strC = obj1.selCity.value.split("~");
		strURL = "/vacations/" + obj1.selRegion.value + "/" + obj1.selState.value + "/" + strC[1] + "/";
		top.location.href=strURL;
	}
}






function getStates(strRegion,nullrestrict)
{		
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);
		var strNULLrestrict = "";
		if(nullrestrict>0)strNULLrestrict = "&nullrestrict";
		http.open("GET", "/java/ajax/getstates.php?region=" + strRegion + "&w=" + dblW + strNULLrestrict, true);
		http.onreadystatechange = StateHttpResponse;
		isWorking = true;
		http.send(null);
	}
	else
	{
		//alert('still working');
	}
}
function StateHttpResponse()
{
  if(http.readyState == 4)
  {
    if (http.responseText.indexOf('invalid') == -1)
    {
	var xmlDocument = http.responseXML;
	isWorking = false;
	var obj1 = document.getElementById("frmSrch");
	var strStateData = xmlDocument.getElementsByTagName('statesdata').item(0).firstChild.data;
	var strS = strStateData.split("|");
	var scount = strS[1];
	
	obj1.selState.innerHTML = "";
	if(strS[0]=="states")
	{
		document.getElementById("spState").innerHTML = "State";
		obj1.selState.options[obj1.selState.length] = new Option("Select a state","");
	}
	if(strS[0]=="provinces")
	{
		document.getElementById("spState").innerHTML = "Province";
		obj1.selState.options[obj1.selState.length] = new Option("Select a province","");
	}
	else if(strS[0]=="countries")
	{
		document.getElementById("spState").innerHTML = "Country";
		obj1.selState.options[obj1.selState.length] = new Option("Select a country","");
	}
	
	for(w=1;w<=scount;w++)
	{
		strStateData = xmlDocument.getElementsByTagName('statesdata').item(w).firstChild.data;
		strS = strStateData.split("|");
		obj1.selState.options[obj1.selState.length] = new Option(strS[0],strS[1]);
	}
    }
  }

}






function getCities(strRegion,strState,nullrestrict)
{
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);
		var strNULLrestrict = "";
		if(nullrestrict>0)strNULLrestrict = "&nullrestrict";
		http.open("GET", "/java/ajax/getcities.php?region=" + strRegion + "&state=" + strState + "&w=" + dblW + strNULLrestrict, true);
		http.onreadystatechange = CityHttpResponse;
		isWorking = true;
		http.send(null);
	}
	else
	{
		//alert('still working');
	}
}
function CityHttpResponse()
{
  if(http.readyState == 4)
  {
    if (http.responseText.indexOf('invalid') == -1)
    {
	var xmlDocument = http.responseXML;
	isWorking = false;
	var obj1 = document.getElementById("frmSrch");
	var strCityData = xmlDocument.getElementsByTagName('citiesdata').item(0).firstChild.data;
	var strC = strCityData.split("|");
	var ccount = strC[1];
	obj1.selCity.innerHTML = "";
	obj1.selCity.options[obj1.selCity.length] = new Option("Select a city","");
	
	for(w=1;w<=ccount;w++)
	{
		strCityData = xmlDocument.getElementsByTagName('citiesdata').item(w).firstChild.data;
		strC = strCityData.split("|");
		obj1.selCity.options[obj1.selCity.length] = new Option(strC[0],strC[1]);
	}
    }
  }

}



function getStatesV(strRegion,nullrestrict)
{		
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);
		var strNULLrestrict = "";
		if(nullrestrict>0)strNULLrestrict = "&nullrestrict";
		http.open("GET", "/java/ajax/getstates.php?vacay&region=" + strRegion + "&w=" + dblW + strNULLrestrict, true);
		http.onreadystatechange = StateVHttpResponse;
		isWorking = true;
		http.send(null);
	}
	else
	{
		//alert('still working');
	}
}
function StateVHttpResponse()
{
  if(http.readyState == 4)
  {
    if (http.responseText.indexOf('invalid') == -1)
    {
	var xmlDocument = http.responseXML;
	isWorking = false;
	var obj1 = document.getElementById("frmSrch");
	var strStateData = xmlDocument.getElementsByTagName('statesdata').item(0).firstChild.data;
	var strS = strStateData.split("|");
	var scount = strS[1];
	
	obj1.selState.innerHTML = "";
	if(strS[0]=="states")
	{
		document.getElementById("spState").innerHTML = "State";
		obj1.selState.options[obj1.selState.length] = new Option("Select a state","");
	}
	if(strS[0]=="provinces")
	{
		document.getElementById("spState").innerHTML = "Province";
		obj1.selState.options[obj1.selState.length] = new Option("Select a province","");
	}
	else if(strS[0]=="countries")
	{
		document.getElementById("spState").innerHTML = "Country";
		obj1.selState.options[obj1.selState.length] = new Option("Select a country","");
	}
	
	for(w=1;w<=scount;w++)
	{
		strStateData = xmlDocument.getElementsByTagName('statesdata').item(w).firstChild.data;
		strS = strStateData.split("|");
		obj1.selState.options[obj1.selState.length] = new Option(strS[0],strS[1]);
	}
    }
  }

}






function getCitiesV(strRegion,strState,nullrestrict)
{
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);
		var strNULLrestrict = "";
		if(nullrestrict>0)strNULLrestrict = "&nullrestrict";
		http.open("GET", "/java/ajax/getcities.php?vacay&region=" + strRegion + "&state=" + strState + "&w=" + dblW + strNULLrestrict, true);
		http.onreadystatechange = CityVHttpResponse;
		isWorking = true;
		http.send(null);
	}
	else
	{
		//alert('still working');
	}
}
function CityVHttpResponse()
{
  if(http.readyState == 4)
  {
    if (http.responseText.indexOf('invalid') == -1)
    {
	var xmlDocument = http.responseXML;
	isWorking = false;
	var obj1 = document.getElementById("frmSrch");
	var strCityData = xmlDocument.getElementsByTagName('citiesdata').item(0).firstChild.data;
	var strC = strCityData.split("|");
	var ccount = strC[1];
	obj1.selCity.innerHTML = "";
	obj1.selCity.options[obj1.selCity.length] = new Option("Select a city","");
	
	for(w=1;w<=ccount;w++)
	{
		strCityData = xmlDocument.getElementsByTagName('citiesdata').item(w).firstChild.data;
		strC = strCityData.split("|");
		obj1.selCity.options[obj1.selCity.length] = new Option(strC[0],strC[1]);
	}
    }
  }

}




function getHTTPObject()
{

  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 && typeof XMLHttpRequest != 'undefined')
  {
    try
    {
      xmlhttp = new XMLHttpRequest();
	xmlhttp.overrideMimeType("text/xml");
    }
    catch (e)
    {
      xmlhttp = false;
    }
  }

  return xmlhttp;

}

