// JavaScript Document
var isWorking = false;
var http = getHTTPObject();
var strHotelStarVote = new Array();
var strHotelVotedOn = new Array();

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 visible(idLayer) {document.getElementById(idLayer).style.visibility='invisible';}
function invisible(idLayer) {document.getElementById(idLayer).style.visibility='hidden';}

function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}






function getStates(strRegion)
{
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);

		http.open("GET", "/java/ajax/getstates.php?region=" + strRegion + "&w=" + dblW, 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("frmSrchBox");
	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)
{
	if (!isWorking && http)
	{
		var dblW = Math.floor(Math.random()*10);
		http.open("GET", "/java/ajax/getcities.php?region=" + strRegion + "&state=" + strState + "&w=" + dblW, 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("frmSrchBox");
	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 starVote(starX,starHID)
{
	if(!strHotelVotedOn[starHID])
	{
		if (!isWorking && http)
		{
			var dblW = Math.floor(Math.random()*10);

			http.open("GET", "/java/ajax/starvote.php?starx=" + starX + "&starhid=" + starHID + "&w=" + dblW, true);
			http.onreadystatechange = HttpResponse;
			isWorking = true;
			http.send(null);
		}
		else
		{
			//alert('still working');
		}
	}
}
function HttpResponse()
{
  if(http.readyState == 4)
  {
    if (http.responseText.indexOf('invalid') == -1)
    {
	var xmlDocument = http.responseXML;
	isWorking = false;
	strStarVoteData = xmlDocument.getElementsByTagName('starvotedata').item(0).firstChild.data;
	var strSVD = strStarVoteData.split("|");
	if(strSVD[0]==0)
	{
		//voted!!
		strHotelStarVote[strSVD[2]] = strSVD[1];
		strHotelVotedOn[strSVD[2]] = true;
		document.getElementById("spVisVote" + strSVD[2]).innerHTML = "You gave it " + strSVD[1] + " stars.";
	}
	else if(strSVD[0]==10)
	{
		//already voted..
		strHotelVotedOn[strSVD[2]] = true;
		document.getElementById("spVisVote" + strSVD[2]).innerHTML = "You already gave this hotel " + strSVD[1] + " stars.";
	}
	else if(strSVD[0]==-1)
	{
		//no params or no write
	}
	
    }
  }

}

function starVoteMouseOn(starX,starHID)
{
	if(!strHotelVotedOn[starHID])
	{
		starsOff(starHID);
		for(x=1;x<=5;x++)
		{
			if(x<=starX)
				starbt = "on";
			else
				starbt = "off";

			document.getElementById(x + "imgVoteStar" + starHID).src = "/images/icons/stars-bt/star-" + starbt + ".gif";

		}
		document.getElementById("spVisVote" + starHID).innerHTML = "Give it " + starX + " stars.";
	}
}


function starVoteMouseOff(starX,starHID)
{
	if(!strHotelVotedOn[starHID])
	{
		starsOff(starHID);
		for(x=1;x<=5;x++)
		{
			if(x<=strHotelStarVote[starHID])
				starbt = "on";
			else
				starbt = "off";

			document.getElementById(x + "imgVoteStar" + starHID).src = "/images/icons/stars-bt/star-" + starbt + ".gif";

		}
		if(strHotelStarVote[starHID]>0)
			document.getElementById("spVisVote" + starHID).innerHTML = "Rated " + strHotelStarVote[starHID] + " stars.";
		else
			document.getElementById("spVisVote" + starHID).innerHTML = "Not yet rated.";
	}
}

function starsOff(starHID)
{
	for(x=1;x<=5;x++)
	{
		document.getElementById(x + "imgVoteStar" + starHID).src = "/images/icons/stars-bt/star-off.gif";
	
	}
}



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;

}


