
function GetLength(){
//On selection of TPI, check length text field and get dets if not empty
if (parseFloat(document.drop_list.length.value)>0){
	ShowDets();
}}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}
//Function to return the XML Http object
function getXMLHTTP() 
{ 
  var xmlhttp=false;	
  try {
  	xmlhttp=new XMLHttpRequest();
  }
  catch(e) {		
  	try {			
  		xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
  	}
  	catch(e){
  		try {
  			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch(e1){
  			xmlhttp=false;
  		}
  	}
  }
  return xmlhttp;
}

function FillMakeList()
{		
  var strURL="Makes.php?sid="+Math.random();
  var req = getXMLHTTP();

  if (req) {
  	req.onreadystatechange = function() {
    	if (req.readyState == 4) {
    		// only if "OK"
    		if (req.status == 200) {						
    			document.getElementById('smake').innerHTML=req.responseText;						
    		} else {
    			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    		}
    	}
    }			
  	req.open("GET", strURL, true);
  	req.send(null);
  }
  // Move focus to lookup box
  document.bslength.lu.focus();
}

function GetModels()
{		
  var strURL="Models.php?Make="+document.bslength.selMake.value+"sid="+Math.random();
  var req = getXMLHTTP();

  if (req) {
  	req.onreadystatechange = function() {
    	if (req.readyState == 4) {
    		// only if "OK"
    		if (req.status == 200) {						
    			document.getElementById('model').innerHTML=req.responseText;						
    		} else {
    			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    		}
    	}
    }			
  	req.open("GET", strURL, true);
  	req.send(null);
  }
}

function ShowDets()
{		
  var strURL="ModelDets.php?Make="+document.bslength.selMake.value+"&Model="+document.bslength.model.options[document.bslength.model.selectedIndex].text+"&sid="+Math.random();
  var req = getXMLHTTP();

  if (req) {
  	req.onreadystatechange = function() {
    	if (req.readyState == 4) {
    		// only if "OK"
    		if (req.status == 200) {						
    			document.getElementById('detsdiv').innerHTML=req.responseText;						
    		} else {
    			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    		}
    	}
    }			
  	req.open("GET", strURL, true);
  	req.send(null);
  }
}

function filtery(pattern,list){
	pattern=new RegExp('^'+pattern,"i");
	i=0;
	sel=0;
	while(i<list.options.length){
		if(pattern.test(list.options[i].text)){sel=i;break;}
		i++;
	}
	list.options.selectedIndex=sel;
}

function DoNothing(){
	if(document.bslength.selMake.selectedIndex!=0){
		GetModels();
	}
	return false;
}

