// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
var GID="0";
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
 
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// read a file from the server
function process(id1)
{
  
  // only continue if xmlHttp isn't void
  if (xmlHttp)
  {
    // try to connect to the server
    try
    {
      // initiate reading a file from the server
      xmlHttp.open("GET", "phptest.php?id="+id1, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    // display the error in case of failure
    catch (e)
    {
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}


// function called when the state of the HTTP request changes
function handleRequestStateChange() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
    handleServerResponse();
	/*  try
      {
        // do something with the response from the server
        handleServerResponse();
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }*/
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
 
    }
  }
}

// handles the response received from the server
function handleServerResponse()
{
  // read the message from the server
  var xmlResponse = xmlHttp.responseXML;
  // catching potential errors with IE and Opera
  if (!xmlResponse || !xmlResponse.documentElement)
    throw("Invalid XML structure:\n" + xmlHttp.responseText);
  // catching potential errors with Firefox
  var rootNodeName = xmlResponse.documentElement.nodeName;
  if (rootNodeName == "parsererror") throw("Invalid XML structure");
  // obtain the XML's document element
  xmlRoot = xmlResponse.documentElement;  
  // obtain arrays with book titles and ISBNs 
  
  wminame = xmlRoot.getElementsByTagName("wminame");
  wmicode = xmlRoot.getElementsByTagName("wmicode");
  wmierror= xmlRoot.getElementsByTagName("wmierror");
  wmiyear= xmlRoot.getElementsByTagName("wmiyear");
 
 
  wminamevalue=wminame.item(0).firstChild.data;
  wmierrorvalue=wmierror.item(0).firstChild.data;
  
  wmiyearvalue=wmiyear.item(0).firstChild.data; 
  
  
  
  myDiv2 = document.getElementById("make");
  myDiv2.value = wminamevalue;
  
  /*myDiv21 = document.getElementById("idmake");
  myDiv21.innerHTML = wminamevalue;*/
  
  myDiv3 = document.getElementById("error");
  myDiv3.innerHTML = wmierrorvalue;
  
  myDiv4 = document.getElementById("god");
  myDiv4.value = wmiyearvalue;
  
}

function allprocess()
{


	str=document.getElementById('vinnumber').value;

    process(str);
}

function test()
{
	
	my=new Date();
	m=my.getMonth();
	
	if (m<9)
	{ 
      m=m+1;
	  m='/0'+m;
	}
	else
	{m=m+1; m='/'+m;};
		
	document.getElementById('daten').value=my.getFullYear()+(m+'/')+my.getDate()
	
}

function test1()
{
	if (document.getElementById('resale').checked)
	{
		document.getElementById('resale').value='YES';
		document.getElementById('resalenumber').value='';
		document.getElementById('resalenumber').disabled='';
	}
	else
	{
		document.getElementById('resale').value='NO';
		document.getElementById('resalenumber').value='NO';
		document.getElementById('resalenumber').disabled='disabled';
	};
	
};

function setSelect(invalue, field) {
if (field == 'make') {
var string1 = document.form1.make;
}
else if(field == 'state') {
var string1 = document.form1.state;
}
else if (field == 'colors') {
var string1 = document.form1.colors;
}
else if (field == 'typeofloss') {
var string1 = document.form1.typeofloss;
}
else if (field == 'damagetype') {
var string1 = document.form1.damagetype;
}
else if (field == 'damageboolean') {
var string1 = document.form1.damageboolean;
}
else if (field == 'duration') {
var string1 = document.form1.duration;
}
else if (field == 'typeofpickup') {
var string1 = document.form1.typeofpickup;
}
else if (field == 'city') {
var string1 = document.form1.city;
}
else if (field == 'vehicletype') {
var string1 = document.form1.vehicletype;
}
else if (field == 'keys1') {
var string1 = document.form1.keys1;
}
else if (field == 'fuel') {
var string1 = document.form1.fuel;
}
else if (field == 'color') {
var string1 = document.form1.color;
}
else if (field == 'startyear') {
var string1 = document.form1.startyear;
}
else if (field == 'endyear') {
var string1 = document.form1.endyear;
}
else if (field == 'orderby') {
var string1 = document.form1.orderby;
}
else if (field == 'distance') {
var string1 = document.form1.distance;
}
for (var i = 0; i < string1.options.length; i++) {
if (string1.options[i].value == invalue) {
string1.options[i].selected = true;
break;
}
}
};

function setSelect2(invalue, field) {
if (field == 'make') {
var string1 = document.form1.make;
}
else if (field == 'colors') {
var string1 = document.form1.colors;
}
else if (field == 'typeofloss') {
var string1 = document.form1.typeofloss;
}
else if (field == 'damagetype') {
var string1 = document.form1.damagetype;
}
else if (field == 'damageboolean') {
var string1 = document.form1.damageboolean;
}
else if (field == 'duration') {
var string1 = document.form1.duration;
}
else if (field == 'typeofpickup') {
var string1 = document.form1.typeofpickup;
}
else if (field == 'vehicletype') {
var string1 = document.form1.vehicletype;
}
else if (field == 'startyear') {
var string1 = document.form1.startyear;
}
else if (field == 'endyear') {
var string1 = document.form1.endyear;
}

for (var i = 0; i < string1.options.length; i++) {
if (string1.options[i].value == invalue) {
string1.options[i].selected = true;
break;
}
}
};
