function regionFillSelect(host, selectObj, fk_value, form) {

	this.selectObj  = selectObj;
	
	this.form = form;
	
	// check if object exisits.
	if(typeof selectObj != 'object') return false;

	if (fk_value > 0) {
		
		resetSelectHTML(selectObj);
	
		this.selectObj.options[0] = new Option("Locading...", "");
		this.selectObj.disabled   = true;
		
		if (typeof form.country_id != 'object') form.country_id.disabled=true;
		if (typeof form.state_id   != 'object') form.state_id.disabled=true;
		
		url  = host+'/location_region.php?state_id=' + fk_value;
		
		if(fk_value > 0) loadResultHTML(url,'');
	}
	
}

function fillSelectSearchPage(host, obj, fk_value, form){

	this.selectObj = obj;

	resetSelectHTML(obj);

	// check if object exisits.
	if(typeof obj != 'object') return false;

	if (obj.name == "search_region") {
		url = host + '/location_region.php?state_id=' + fk_value;
		if (fk_value > 0) loadResultHTML(url, '');
	}

}

function resetSelectHTML(obj){
	while (obj.options.length>1) {
		deleteIndex=obj.options.length-1;
		obj.options[deleteIndex]=null;
	}
}

function loadHTMLDoc() {
	
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChangeHTML;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChangeHTML;
			req.open("GET", url, true);
			req.send();
		}
	}
	
}

function processReqChangeHTML() {
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here
			response = req.responseText;
			if(response) {
				loadResultHTML('',response);
				unlockLocationHTML();
			}
		} else {
			alert("There was a problem retrieving the HTML data:\n" + req.statusText);
			unlockLocationHTML();
		}
		unlockLocationHTML();
	}
}

function loadResultHTML(url, result){
	if (result != ''){
		// Response mode
		document.getElementById("div_"+this.selectObj.name).innerHTML = result;
	} else if(url != '') {
		// Input mode
		return (loadHTMLDoc(url));
	}
}

function unlockLocationHTML() {
	if (typeof this.form.country_id != 'object') this.form.country_id.disabled="";
	if (typeof this.form.state_id != 'object')   this.form.state_id.disabled="";
	if (typeof this.form.region_id != 'object')  this.form.region_id.disabled="";
}