//fill cities
function TcreateRequestObject() {
	var TtmpXmlHttpObject;

	//depending on what the browser supports, use the right way to create the XMLHttpRequest object
	if (window.XMLHttpRequest) {
		// Mozilla, Safari would use this method ...
		TtmpXmlHttpObject = new XMLHttpRequest();

	} else if (window.ActiveXObject) {
		// IE would use this method ...
		TtmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return TtmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
var Thttp = TcreateRequestObject();


function TmakePostRequest(page_name,obj1) {
	//make a connection to the server ... specifying that you intend to make a GET request
	//to the server. Specifiy the page name and the URL parameters to send
	//Send the proper header information along with the request
	var Tparams = prepare_param(obj1);

	Thttp.open('POST', page_name ,true);

	Thttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	Thttp.setRequestHeader("Content-length", Tparams.length);
	Thttp.setRequestHeader("Connection", "close");


	//assign a handler for the response
	Thttp.onreadystatechange = TprocessResponse;

	//actually send the request to the server
	Thttp.send(Tparams);
}


function TmakePostRequest_1(page_name,obj1,obj2) {
	//make a connection to the server ... specifying that you intend to make a GET request
	//to the server. Specifiy the page name and the URL parameters to send
	//Send the proper header information along with the request
	var Tparams = prepare_param(obj1,obj2);

	Thttp.open('POST', page_name ,true);

	Thttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	Thttp.setRequestHeader("Content-length", Tparams.length);
	Thttp.setRequestHeader("Connection", "close");


	//assign a handler for the response
	Thttp.onreadystatechange = TprocessResponse;

	//actually send the request to the server
	Thttp.send(Tparams);
}

function TprocessResponse() {
	//check if the response has been received from the server

	if(Thttp.readyState == 4){

		//read and assign the response from the server
		var response = Thttp.responseText;

		//do additional parsing of the response, if needed

		//in this case simply assign the response to the contents of the <div> on the page.
		document.getElementById('cities').innerHTML =  response;
		var sPath = window.location.pathname;
		//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		if (sPage == 'register.php'){
			$('#city_name').attr('class','selreg5');
			$('#city_name').css('width','139px');
		}


		//document.getElementById('loading').innerHTML="";

		document.getElementById('city_name').selectedIndex=document.getElementById('city').value;


		//If the server returned an error message like a 404 error, that message would be shown within the div tag!!.
		//So it may be worth doing some basic error before setting the contents of the <div>

	}

	else {
		//document.getElementById('loading').innerHTML="<img src='images/loader.gif'>";

	}


}



function prepare_param(obj1,obj2)
{
	var index_1=obj1.selectedIndex // returns the index of the selected option, ie: 0,1,2...
	var value_1=obj1.value //returns the value of the selected option
	var selected_index_country=obj1.options[obj1.selectedIndex].value // returns the text nested in the selected option

	if(obj2!=null){
		var index=obj2.selectedIndex // returns the index of the selected option, ie: 0,1,2...
		var value=obj2.value //returns the value of the selected option
		var selected_index_city=obj2.options[obj2.selectedIndex].text // returns the text nested in the selected option

		var  par='country=' + selected_index_country + '&' +'city='+selected_index_city;
	}

	else
	{
		var  par='country=' + selected_index_country ;
	}
	//alert(par);
	return par;
}
