function newXMLHttpRequest(){

  var xmlreq = false;

  if (window.XMLHttpRequest) {
   
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    try {

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {
     
      try {

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

      }
    }
  }

  return xmlreq;
}
function loadModels(manuID){
	

	document.getElementById("indicatorModel").style.display="block";

	var rto = document.getElementById("rto")

		if(rto.value.trim().length==0){
		alert("Please enter valid city name");
		rto.focus();
		rto.select();
		return false;
	}

	var parameters='manufacturerName='+manuID+"&rto="+rto.value.trim()+"&manuSearchType="+manuSearchType;
	var req = newXMLHttpRequest();
	//document.getElementById(elementid).options.length = 0;
 req.onreadystatechange=function()
 {
    if (req.readyState == 4) {
      if (req.status == 200) {
		addValuesToModelListbox(req.responseText);
		if(document.getElementById("campaignCityVal").value!=""){
		loadCampaignModelName();}
      } else {
        //alert("HTTP error: "+req.status);
      }
    }
  }

	req.open("POST", "getAllModels.do", true); //synchronous

    req.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded");

	req.send(parameters);
}
function loadSearchCity(){
	var rto = document.getElementById("rto").value;
	if(rto.trim().length==0){
		document.getElementById("indicatorRegion").style.display="none";
		alert("Please enter atleast one character");
		rto.focus();
		rto.select();
		return false;
	}
	var cityReq = newXMLHttpRequest();
	 cityReq.onreadystatechange=function()
 {
    if (cityReq.readyState == 4) {
      if (cityReq.status == 200) {
		   
	var xsltfile="privatecar/privateCarSearchCity.xsl";
	
	var xml;	
	if (window.ActiveXObject){
	
	  xml=new ActiveXObject("Microsoft.XMLDOM");
	  xml.async="false";
	  xml.loadXML(cityReq.responseText);
	}
	// code for Mozilla, Firefox, Opera, etc.
	else{
			
	  var parser=new DOMParser();
	  xml=parser.parseFromString(cityReq.responseText,"text/xml");
	}// documentElement always represents the root node
	xsl=loadXMLDoc(xsltfile);
	// code for IE
	if (window.ActiveXObject){
		ex=xml.transformNode(xsl);
		document.getElementById("searchCityGrd").innerHTML=ex;
		}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument){
  		xsltProcessor=new XSLTProcessor();
  		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToFragment(xml,document);
		var y = document.getElementById('searchCityGrd'), child;
		while(child=y.firstChild)
		y.removeChild(child);
		document.getElementById("searchCityGrd").appendChild(resultDocument);
  	}  
		
      } else {
		alert("HTTP error: "+cityReq.status);
      }
    }
  } 
  var parameters="rto="+rto.trim();
 	cityReq.open("POST","getCarSearchCity.do", true);
	cityReq.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded");
	cityReq.send(parameters);
}
function loadXMLDoc(fname)
{
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async=false;
	  xmlDoc.load(fname);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	  {
	  var loadFileXml = new window.XMLHttpRequest();
	  loadFileXml.open("GET",fname,false);
	  loadFileXml.send(null);
	  xmlDoc = loadFileXml.responseXML.documentElement;
	  }
	else
	  {
	  alert('Your browser cannot handle this script');
	  }
	
	return(xmlDoc);
}

function loadManu(){

	document.getElementById("indicatorRegion").style.display="block";
	
	var rto = document.getElementById("rto")
	//alert(rto.value);
		if(rto.value.trim().length==0){
		document.getElementById("indicatorRegion").style.display="none";
		alert("Please enter valid city name");
		rto.focus();
		rto.select();
		return false;
	}

	var parameters="rto="+rto.value.trim()+"&manuSearchType="+manuSearchType;
	var manuReq = newXMLHttpRequest();
	//document.getElementById(elementid).options.length = 0;
 manuReq.onreadystatechange=function()
 {
    if (manuReq.readyState == 4) {
      if (manuReq.status == 200) {
		addValuesToManuListbox(manuReq.responseText);
		if(document.getElementById("campaignCityVal").value!=""){
		loadCampaignManuName();}
      } else {
        alert("HTTP error: "+manuReq.status);
      }
    }
  }

	manuReq.open("POST", "getAllManu.do", true); //synchronous

    manuReq.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded");

	manuReq.send(parameters);
}

function addValuesToModelListbox(modelStr){
	document.getElementById("modelName").options.length = 0;
	if (window.ActiveXObject)
	  {
	  doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(modelStr);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  doc=parser.parseFromString(modelStr,"text/xml");
	  }// documentElement always represents the root node

	var masterdoc=doc.documentElement;


	var optionlist=doc.getElementsByTagName("model");	
	var select_box=document.getElementById("modelName");	
	var option_node=document.createElement('option');
	
	option_node.value="select";
	option_node.text="Select Model";
    try
	{
		select_box.add(option_node,null); // standards compliant
	}
	catch(ex)
	{
	  //alert(ex);
	select_box.add(option_node); // IE only
	}
	for(var i=0; i<optionlist.length; i++){
	
		var option_node=document.createElement('option');

		var modelVal=masterdoc.getElementsByTagName("model")[i].childNodes[0].childNodes[0].nodeValue;
		option_node.value=modelVal;
		option_node.text=modelVal;
 //alert("option_node.value="+option_node.value+"option_node.text="+option_node.text);
		   try
			{
			select_box.add(option_node,null); // standards compliant
			}
		  catch(ex)
			{
			  //alert(ex);
			select_box.add(option_node); // IE only
			}
	}
	document.getElementById("modelName").disabled=false;
	document.getElementById("indicatorModel").style.display="none";
}

function addValuesToManuListbox(manuStr){
	//alert("manuStr"+manuStr);
	document.getElementById("manufacturerName").options.length = 0;
	if (window.ActiveXObject)
	  {
	  doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(manuStr);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  doc=parser.parseFromString(manuStr,"text/xml");
	  }// documentElement always represents the root node
	var masterdoc=doc.documentElement;

	var manuOptionlist=doc.getElementsByTagName("manu");
	var select_box=document.getElementById("manufacturerName");
	var option_node=document.createElement('option');
	option_node.value="select";
	option_node.text="Select Manufacturer";
    try
	{
		select_box.add(option_node,null); // standards compliant
	}
	catch(ex)
	{
	select_box.add(option_node); // IE only
	}
	for(var i=0; i<manuOptionlist.length; i++){
	 //alert(manuOptionlist.length);
		var option_node=document.createElement('option');
		var manuNameVal=masterdoc.getElementsByTagName("manu")[i].childNodes[0].childNodes[0].nodeValue;
		option_node.value=manuNameVal;
		option_node.text=manuNameVal;
		//alert(option_node.text);
 
		   try
			{
			select_box.add(option_node,null); // standards compliant
			}
		  catch(ex)
			{
			  //alert(ex);
			select_box.add(option_node); // IE only
			}
	}
	document.getElementById("modelName").options.length = 0;
	var optionlist=doc.getElementsByTagName("model");
	var select_box=document.getElementById("modelName");
	var option_node=document.createElement('option');
	option_node.value="select";
	option_node.text="Select Model";
    try
	{
		select_box.add(option_node,null); // standards compliant
	}
	catch(ex)
	{
	  //alert(ex);
	select_box.add(option_node); // IE only
	}
	if(manuOptionlist.length==0){
		document.getElementById("indicatorRegion").style.display="none";
		document.getElementById("manufacturerName").disabled=true;
		alert("Please select a city name from the list");
		return false;
	}else{
		document.getElementById("manufacturerName").disabled=false;
	}
	document.getElementById("modelName").disabled=true;
	document.getElementById("cityValue").value=document.getElementById("rto").value;
	document.getElementById("indicatorRegion").style.display="none";
}


String.prototype.trim = function() {
// Strip leading and trailing white-space
return this.replace(/^\s*|\s*$/g, "");
}

function loadCC(modelID){
	
	//document.getElementById("indicatorModel").style.display="block";

	var rto = document.getElementById("rto")
	var manufacturerName = document.getElementById("manufacturerName")	

		if(rto.value.trim().length==0){
		alert("Please enter valid city name");
		rto.focus();
		rto.select();
		return false;
	}

	var parameters='modelName='+modelID+"&rto="+rto.value.trim()+"&manufacturerName="+manufacturerName.value.trim()+"&manuSearchType="+manuSearchType;
	var req = newXMLHttpRequest();
	//document.getElementById(elementid).options.length = 0;
 req.onreadystatechange=function()
 {
    if (req.readyState == 4) {
      if (req.status == 200) {
		addValuesToCCVal(req.responseText);
		//if(document.getElementById("campaignCityVal").value!=""){
		//loadCampaignModelName();}
      } else {
        //alert("HTTP error: "+req.status);
      }
    }
  }

	req.open("POST", "getCarCC.do", true); //synchronous

    req.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded");

	req.send(parameters);
}


function addValuesToCCVal(ccStr){
	document.getElementById("CCrange").length = 0;
	if (window.ActiveXObject)
	  {
	  doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(ccStr);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  doc=parser.parseFromString(ccStr,"text/xml");
	  }// documentElement always represents the root node
	
	var masterdoc=doc.documentElement;


	var optionlist=doc.getElementsByTagName("ccValue");		
	var select_box=document.getElementById("CCrange");	
	var option_node=document.createElement('option');
	
	for(var i=0; i<optionlist.length; i++){
	
		var option_node=document.createElement('option');

		var ccVal=masterdoc.getElementsByTagName("ccValue")[i].childNodes[0].childNodes[0].nodeValue;
		option_node.value=ccVal;
		option_node.text=ccVal; 
		   
	}
	
	document.getElementById("CCrange").value=option_node.value;	
	vehiclecchide.innerHTML=option_node.value;
	//document.getElementById("indicatorModel").style.display="none";
}

