// JavaScript Document - controls the drop down lists  in the Place Ads form.
 
//**************************** Manage Changes to Country, Province and Region Fields *****************************//
var searchcountryId='';
var searchprovId='';

function getSearchProvs(pCountry) {
	searchcountryId=pCountry;
	var gURL = 'formsGetSearchProvs.php?searchcountry='+searchcountryId;
	document.getElementById("searchregion").value="";
	document.getElementById("searchregion").disabled = true;
	
	//create the Cross-browser XMLHttpRequest object
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}	
		xmlhttp.onreadystatechange=loadSearchProvs;
		xmlhttp.open("GET", gURL, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE 
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
		if (xmlhttp) {
			xmlhttp.onreadystatechange=loadSearchProvs;
			xmlhttp.open('GET', gURL, false);
			xmlhttp.send();
		}
	}

}

// function to handle asynchronus call
function loadSearchProvs() {
	if (xmlhttp.readyState==4) { 
		if (xmlhttp.status==200) { 
			document.getElementById('searchprovstates').innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText.indexOf('disabled')<=0) {
				document.getElementById('searchprovstate').focus();
			}	
		}
	}
}

function getSearchRegions(pProv,pCountry) {
	searchprovId=pProv;
	searchcountryId=pCountry;
	if (pProv=='') {
		var gURL = 'formsGetSearchRegions.php';
	}else{
		var gURL = 'formsGetSearchRegions.php?searchcountry='+searchcountryId+'&searchprovstate='+searchprovId;
	}	
	//create the Cross-browser XMLHttpRequest object
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}	
		xmlhttp.onreadystatechange=loadSearchRegions;
		xmlhttp.open("GET", gURL, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE 
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
		if (xmlhttp) {
			xmlhttp.onreadystatechange=loadSearchRegions;
			xmlhttp.open('GET', gURL, false);
			xmlhttp.send();
		}
	}
}

// function to handle asynchronus call
function loadSearchRegions() {
	if (xmlhttp.readyState==4) { 
		if (xmlhttp.status==200) { 
			document.getElementById('searchregions').innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText.indexOf('disabled')<=0) {
				document.getElementById('searchregion').focus();
			}
		}
	}
}


//**************************** Manage Changes to Make and Model Fields *****************************//

var searchmakeId='';
var searchmodelId='';

function getSearchModels(pMake) {
	searchmakeId=pMake;
	var gURL = 'formsGetSearchModels.php?searchmake='+searchmakeId;
	//create the Cross-browser XMLHttpRequest object
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}	
		xmlhttp.onreadystatechange=loadSearchModels;
		xmlhttp.open("GET", gURL, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE 
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
		if (xmlhttp) {
			xmlhttp.onreadystatechange=loadSearchModels;
			xmlhttp.open('GET', gURL, false);
			xmlhttp.send();
		}
	}
}

// function to handle asynchronus call
function loadSearchModels() {
	if (xmlhttp.readyState==4) { 
		if (xmlhttp.status==200) { 
			document.getElementById('searchmodels').innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText.indexOf('disabled')<=0) {
				document.getElementById('searchmodel').focus();
			}	
		}
	}
}

