	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 checkpostcode(inn,out){
//alert("inside 1");
var postcode = document.getElementById(inn).value;
//alert(postcode);
if(postcode=="Post Code"){
return false;
}

if(postcode!=""){
// alert("inside"+document.getElementById(inn).value);
var xmlHttppost = createXMLHttpRequest();
var url = "/ajaxvalidpostcode.do?postcode="+postcode;
xmlHttppost.open("GET",url,false)
xmlHttppost.send(null);
//alert("after null");
 var msg = xmlHttppost.responseXML.getElementsByTagName("root")[0];
 var status = msg.getElementsByTagName("msg")[0].childNodes[0].nodeValue;
 if(status==0){
     document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/correct.gif\">";                        
    document.getElementById("zipok").value="1";
    document.getElementById("ldistance").style.display="inline";
     var code = msg.getElementsByTagName("msg")[1].childNodes[0].nodeValue;
     document.getElementById(inn).value = code;
   }
 else{
      document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/wrong.gif\">";     
      document.getElementById("zipok").value="0";
      document.getElementById("ldistance").style.display="none";
   }
  // alert("zip ok"+document.getElementById("zipok").value);
}
else{
clearspan(out);
}
}






/*function checkpostcode(inn,out){
var postcode = document.getElementById(inn).value;
if(postcode=="Post Code"){
return false;
}

if(postcode!=""){

var xmlHttppost = createXMLHttpRequest();
var url = "/ajaxvalidpostcode.do?postcode="+postcode;

xmlHttppost.onreadystatechange = function isexisting(){

  if(xmlHttppost.readyState==4){
//  alert("check postode "+postcode);
     if(xmlHttppost.status==200){
     
      var msg = xmlHttppost.responseXML.getElementsByTagName("root")[0];
      var status = msg.getElementsByTagName("msg")[0].childNodes[0].nodeValue;
      
      if(status==0){
        document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/correct.gif\">";        
        
//        document.getElementById("zipok").value=1;
      var code = msg.getElementsByTagName("msg")[1].childNodes[0].nodeValue;
      document.getElementById(inn).value = code;
        }
      else{
        document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/wrong.gif\">";       }
     }
  }
 }

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

}
else{
clearspan(out);
}
}*/

function checkexisting(idemail,display){

var emailid=document.getElementById(idemail).value;

//alert(emailid);
if(emailid!=""){
var xmlHttpemail = createXMLHttpRequest();
var url="/ajaxismail.do?mailid="+emailid;
var notexistid ="&nbsp;<img src=\"/images/correct.gif\">";
var existid = "&nbsp;<b><font color=\"#FF0000\">ID already exist</font></b>";
if(idemail=="lostemailid"){
notexistid="&nbsp;<b><font color=\"#FF0000\">Entered Login ID not exist</font></b>";
existid="";
}

xmlHttpemail.onreadystatechange = function isexistingemailid(){
//  alert("inside function");
  if(xmlHttpemail.readyState==4){
       if(xmlHttpemail.status==200){
      var msg = xmlHttpemail.responseXML.getElementsByTagName("root")[0];
      var status= msg.getElementsByTagName("msg")[0].childNodes[0].nodeValue;
  //    alert(status);
      if(status==1){
         document.getElementById(display).innerHTML = existid;
         document.getElementById("emailok").value=2;
        }
        else if(status==0){
         document.getElementById(display).innerHTML = notexistid;
        document.getElementById("emailok").value=1;
        }
      else{
      //  alert(document.getElementById(display));
        document.getElementById(display).innerHTML = "&nbsp;<img src=\"/images/wrong.gif\"><b><font color=\"#FF0000\">Invalid ID</font></b>";
    //     alert(document.getElementById(display));
        document.getElementById("emailok").value=0;
        //alert("after email ok");
         
        }
       
     }
  }

         

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

}
else{
clearspan("exist");
}
}

function clearspan(spanname){
document.getElementById(spanname).innerHTML=" ";
}


/*function validatemailidandzipcode(inn,out){
alert("inside validatemailidandzipcode");
  var postcode = document.getElementById(inn).value;
  var emailid=document.getElementById("emailid").value;
  if(postcode=="Post Code"){ 
    return false;
   }
 var xmlHttpval = createXMLHttpRequest();
  var url = "/validateajax.do?postcode="+postcode+"&mailid="+emailid;
  xmlHttpval.onreadystatechange = function isexisting(){
   if(xmlHttpval.readyState==4){
     if(xmlHttpval.status==200){
     
      var msg = xmlHttpval.responseXML.getElementsByTagName("root")[0];
        alert(msg.getElementsByTagName("model")[0]);
      var postcodestatus = msg.getElementsByTagName("msg")[0].childNodes[0].nodeValue;
        alert("postcodestatus"+postcodestatus);
      var emailstatus = msg.getElementsByTagName("msg")[1].childNodes[0].nodeValue;
      
      if(!postcode==""){
      alert("postcodestatus "+postcodestatus);
      if(postcodestatus==0){
        document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/correct.gif\">";        
        //document.getElementById("zipok").value=1;
        }
      else{
        document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/wrong.gif\">";       }
     }
     }
     if(!emailid==""){
     if(emailstatus==0){
        alert("inside");
        document.getElementById(out).innerHTML = "&nbsp;<img src=\"/images/correct.gif\">";        
        //document.getElementById("zipok").value=1;
        }
      else{
        document.getElementById("exist").innerHTML = "&nbsp;<img src=\"/images/wrong.gif\"><b><font color=\"#FF0000\">Invalid ID</font></b>";
     }
    } 
  }
 }

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

}*/




function getModels_Sell_Car(frm,updte,abbrv) {
//alert("inside model");
var make = document.getElementById(abbrv+"make");
var mod = document.getElementById("modelval");
//to set the make value to the previously selected



  if(make.selectedIndex=="0"){
    document.getElementById(updte).innerHTML = "<select name=\""+abbrv+"model\" id=\""+abbrv+"model\" style=\"width:120px; height:20px; font-size:13px;\"><option value=\"all\">Select Model</option></select>";
    
   if(abbrv=="lbuy"){
    document.getElementById(updte).innerHTML = "<select name=\""+abbrv+"model\" id=\""+abbrv+"model\" style=\"width:120px; height:20px; font-size:13px;\"><option value=\"all\">Any Model</option></select>";    			
    //document.getElementById("zip").value="Post Code";
    document.getElementById("Price").value="<=Price";
    document.getElementById("Miles Driven").value="<=Miles Driven";
    document.getElementById("postcodeexist").innerHTML ="&nbsp;";
    document.getElementById("ldistance").style.display="none";
    
    }
    return false;
  }

var models = "<select name=\""+abbrv+"model\" id=\""+abbrv+"model\" style=\"width:120px; height:20px; font-size:13px;\"><option value=\"all\">Loading...</option></select>";
document.getElementById(updte).innerHTML = models;
models = "";
var url = "/ajaxcrmodel.do?make="+make.value;

xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = function gotModels() {
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			var msg = xmlHttp.responseXML.getElementsByTagName("root")[0];
			//alert(msg.childNodes.length);
            if(abbrv=="lsellused")
    			models = "<select name=\""+abbrv+"model\" id=\""+abbrv+"model\" style=\"width:120px; height:20px; font-size:13px;\" onchange=\"isOtherStyle('sellusedviewmodel','othersellmodel','lsellusedmodel');\"><option value=\"all\">Select a Model</option>";
			else
			   models = "<select name=\""+abbrv+"model\" id=\""+abbrv+"model\" style=\"width:120px; height:20px; font-size:13px;\" \"><option value=\"all\">Select a Model</option>";
          // alert(models);
			for(i=0; i<msg.childNodes.length; i++){
			var model =msg.getElementsByTagName("model")[i].childNodes[0].nodeValue;
			
			  if(mod==null||mod.value!=model)
				models = models + "<option value=\""+model+"\">"+model+"</option>";				
			  else
			  	models = models + "<option selected=\"selected\" value=\""+model+"\">"+model+"</option>";
			}

			if(abbrv=="lsellused")
			models = models + "<option value=\"oth\">Other</option>";				
			
			models =models + "</select>";

				document.getElementById(updte).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="";
	}
}


function UploadProgressBar(){
	var url ="/FileUploadProgress";
		xmlHttp = createXMLHttpRequest();
		document.getElementById("uploadbar").innerHTML="<img src=\"/images/upload_progress.gif\"/>";
		
		xmlHttp.onreadystatechange = function ShowProgBar() {
				if(xmlHttp.readyState==4){
	 				if(xmlHttp.status==200){
	                var msg = xmlHttp.responseText;
	                	if(msg=="WIP"){
							window.setTimeout("UploadProgressBar();", 10000);	                	
	                	}else {
	                		document.getElementById("uploadbar").innerHTML="<img src=\"/images/uploaded_progress.gif\"/>";
	                	}
	 					
	 				}
	 			}
		}
		
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
}



function ajaxpage(url,containerid){
//alert(url);
if(url!="null"){
if(url=="user"||url=="car"||url=="image"||url=="newcar"){
url="/showposting.do?info="+url;
}
else if(url=="sendpassword"){
document.getElementById(containerid).innerHTML="<img src='/images/ajax-loader.gif'/>"
var  emailid = document.getElementById("lostemailid").value
url="sendpassword.do?info="+url+"&emailid="+emailid;
//alert(url);
}

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

//alert("after getting http request");
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}

//if (bustcachevar) //if bust caching of external page
//bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
//alert(url);
page_request.open('GET', url, true)
page_request.send(null)
}
//alert("ajax out");
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}





