var xmlHttp;

if (window.XMLHttpRequest){
	try{
		xmlHttp = new XMLHttpRequest();
	}catch(e){
		xmlHttp = false;
	}
}else if(window.ActiveXObject){
	try{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlHttp = ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlHttp = false;
		}
	}
}

if(!xmlHttp){
	alert('XMLHttpRequest creation failure!\n');
}	


function CountryCategories(_country,_just_city) {

	this.country = _country;
	this.just_city = _just_city;
	
	this.objF = document.getElementById("federal_id");
	this.objP = document.getElementById("provincial_id");
	this.objM = document.getElementById("municipal_id");
	if(this.just_city == 0) {
		while (this.objF.options.length>1) {
			deleteIndex=this.objF.options.length-1;
			this.objF.options[deleteIndex]=null;
		}
		while (this.objP.options.length>1) {
			deleteIndex=this.objP.options.length-1;
			this.objP.options[deleteIndex]=null;
		}
	}
	while (this.objM.options.length>1) {
		deleteIndex=this.objM.options.length-1;
		this.objM.options[deleteIndex]=null;
	}
	countryCategories_ajaxLoad(this.country, this.objP.value, this.just_city);
}

function countryCategories_ajaxLoad(_country,_pCategory,_just_city) {
	xmlHttp.open("GET", "/includes/code/country_categories.php?country_id="+_country+"&pcategory="+_pCategory+"&just_city="+_just_city,true);
	
	xmlHttp.onreadystatechange=function() {
    	if (xmlHttp.readyState==4){
			var reply = unescape(xmlHttp.responseText.replace(/\+/g," ")); //"
			if (reply.substring(reply.length-2) != "ok"){
				alert("Reply failure!");
			}else{
				eval(reply.substring(0,reply.length-2));
			}    		
    	}
	}
	xmlHttp.send(null)	
}