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 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;
 
		   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){
	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++){
	
		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;
 
		   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, "");
}