var nonce = Math.floor(Math.random()*100);
var http = getHTTPObject();
var modelurl = "/js/modelli.asp?nonce="+nonce+"&id=";

function modelHttpResponse(){
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      var xmlDocument = http.responseXML;
      document.signupfrm.modelli.options.length=0;
      document.signupfrm.modelli.options.length=xmlDocument.getElementsByTagName('record').length+1;
     	document.signupfrm.modelli.options[0].value='0';
     	document.signupfrm.modelli.options[0].text='Altro...';

      for(i=0;i< xmlDocument.getElementsByTagName('record').length;i++)
      {
      	var record=xmlDocument.getElementsByTagName('record').item(i);
      	document.signupfrm.modelli.options[i+1].value=record.getElementsByTagName('bid').item(0).firstChild.data;
      	document.signupfrm.modelli.options[i+1].text=record.getElementsByTagName('Mname').item(0).firstChild.data;
      }
      isWorking = false;      
      window.status="Done";
   }
    else
    {
    document.signupfrm.modelli.options.length=1;
    document.signupfrm.modelli.options[0].value="0";
    document.signupfrm.modelli.options[0].text="Choose";
    }
}else{
    		window.status="provider not exists";
    }
}

var isWorking = false;

function updateModel() {
  if (http){
	  	var marca = document.signupfrm.marca.value;
	    http.open("GET", modelurl + escape(marca), true);
	    http.onreadystatechange = modelHttpResponse;
	    isWorking = true;    
	    http.send(null);
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/  
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
