// JavaScript Document

var xmlHttp5;

function loadCities(countryId,who)

{

	xmlHttp5=GetXmlHttpObject()

	if (xmlHttp5==null)

  	{

  		alert ("Browser does not support HTTP Request")

  		return

  	} 

	if(who == "member")

		var url = "system/includes/loadCities.php";

	else if(who == "admin")

		var url = "../includes/loadCities.php";

	url += "?cid="+countryId; ///pass the country Id

	url += "&sid="+Math.random();

	xmlHttp5.onreadystatechange=stateChanged 

	xmlHttp5.open("GET",url,true)

	xmlHttp5.send(null)

}



function stateChanged() 

{ 

	if (xmlHttp5.readyState==3 || xmlHttp5.readyState=="process")

 	{ 

		document.getElementById("spanDeliveryCity").innerHTML = "Loading...";

	}

	if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete")

 	{ 

 		//document.getElementById("citiesarea").innerHTML=xmlHttp.responseText 

		var res = xmlHttp5.responseText;  ///  result is stored in the variable res

		//alert(res);

		var cities = res.split("**");

		document.getElementById("spanDeliveryCity").innerHTML = "";

		document.getElementById("cities").style.display= "block";

		removeAllOptions(document.getElementById("cities"));

		if(cities.length > 1)

		{

			for(var i=0;i<cities.length-1;i+=2)

			{

				addOption(document.getElementById("cities"),cities[i],cities[i+1]);

			}

			addOption(document.getElementById("cities"),0,"Other Cities");

		}

		else

		{

			addOption(document.getElementById("cities"),-1,"Select");

			addOption(document.getElementById("cities"),0,"Other Cities");

		}

 	} 

}

function addOption(selectbox,value,text)  ///  Add the resulting cities to the list box

{

	var optn = document.createElement("OPTION");

	optn.text = text;

	optn.value = value;

	selectbox.options.add(optn);

}

function removeAllOptions(selectbox)

{

	var i;

	for(i=selectbox.options.length-1;i>=0;i--)

	{

		selectbox.remove(i);

	}

}



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;

}

