function createXMLHttpRequest(frm) {
	var xmlHttp = null;
	try {
	xmlHttp = new XMLHttpRequest();
//	alert("FireFox, Opera, Safari");
	return xmlHttp;
	}catch (e){
		try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//		alert("Internet Explorer");
		return xmlHttp;
		}catch (e){
			try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			return xmlHttp;
			}catch (e){
				alert("Your Browser not Supporting Ajax");
				return false;
			}
		}
	} 
}



function getModels_Sell_Car(frm) {
var make = document.getElementById("cmake");
if(make.value==""){
document.getElementById("viewmodel").innerHTML = "<span class=\"star\">*</span>&nbsp;<select name=\"cmodel\" id=\"cmodel\" disabled=\"disabled\" style=\"width:170px; height:20px; font-size:13px;\"><option value=\"\">Select Car Model</option></select>";
getstate_city(frm);
return false;
}

var models = "<a\">*</span>&nbsp;<select name=\"cmodel\" id=\"cmodel\" style=\"width:170px; height:20px; font-size:13px;\"><option value=\"\">&nbsp;&nbsp;&nbsp;&nbsp;Loading...</option></select>";
document.getElementById("viewmodel").innerHTML = models;
models = "";
var url = "/ajaxcrmodel?make="+make.value;
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = function gotModels() {
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			var msg = xmlHttp.responseXML.getElementsByTagName("root")[0];
			models = "<span class=\"star\">*</span>&nbsp;<select name=\"cmodel\" id=\"cmodel\" style=\"width:170px; height:20px; font-size:13px;\"><option value=\"\">Select a Model</option>";
			for(i=0; i<msg.childNodes.length; i++){
				models = models + "<option value=\""+msg.getElementsByTagName("model")[i].childNodes[0].nodeValue+"\">"+msg.getElementsByTagName("model")[i].childNodes[0].nodeValue+"</option>";
			}
			models =models + "</select>";
			
				document.getElementById("viewmodel").innerHTML = models;
					getstate_city(frm);

		}
	}

}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}


function getstate_city(frm){

var zip = document.getElementById("txtzip").value;
document.getElementById("selstate").value = "";
document.getElementById("txtcity").value = "";

var url = "/getstatecity?zip="+zip;

	if(zip.length==5){
		if(!isNaN(zip)){
			xmlHttp = createXMLHttpRequest();
			xmlHttp.onreadystatechange = function gotCategories() {
				if(xmlHttp.readyState==4){
	 				if(xmlHttp.status==200){
	 				var msg = xmlHttp.responseXML.getElementsByTagName("statecity")[0];
	 				var state = msg.getElementsByTagName("state")[0].childNodes[0].nodeValue;
	 				var city = msg.getElementsByTagName("city")[0].childNodes[0].nodeValue;
					if(state!="No"){
					
					document.getElementById("selstate").value = state;
					document.getElementById("txtcity").value = city;
					
					document.getElementById("zip_status").innerHTML="<font color=\"#FF9966\" size=\"2\"><b>"+city+"-"+state+"</b></font>";
					}else {
	 						document.getElementById("zip_status").innerHTML="<font color=\"red\" size=\"2\"><b>Enter Valid Zip Code<b></font>";
	 						
	 				}
				}
			}
		}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
		
		}else {
		document.getElementById("zip_status").innerHTML="<font color=\"red\" size=\"2\"><b>Enter Valid Zip Code<b></font>";
		}
	}else {
	document.getElementById("zip_status").innerHTML="";
	}
}

