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


function addOption(selectbox, value, text)
{

	var optn = document.createElement("OPTION");
	//optn.text = text;
	optn.value = value;

	//optn.appendChild(document.createTextNode(text));

	//selectbox.options.add(optn);


	optn.innerHTML = '<span>' + text +'</span>';
	selectbox.appendChild( optn );


}


function getXMLHTTP() { //fuction to return the xml http object

		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 getModel(manId) {
		
		


		var strURL="ajaxprocessing.php?manufacturer="+manId;
		var req = getXMLHTTP();
		//window.setTimeout('showLoadingImage()', 0)

		if (req) {

			req.onreadystatechange = function() { 

				if (req.readyState == 4) {

					// only if "OK" 

					if (req.status == 200) {

						xmlDoc=req.responseXML;

						removeAllOptions(document.drop_list.Modeld);
						removeAllOptions(document.drop_list.Trim);
						removeAllOptions(document.drop_list.parts);
						
						var numItems= xmlDoc.getElementsByTagName("modelname").length;
						//document.getElementById('items').innerHTML = numItems;

						for (var i = 0; i < xmlDoc.getElementsByTagName("modelname").length; i++){

							mvalue = xmlDoc.getElementsByTagName("modelvalue")[i].childNodes[0].nodeValue;
							mname = xmlDoc.getElementsByTagName("modelname")[i].childNodes[0].nodeValue;
							
							mname = mname.toUpperCase();
							
							var opt = document.createElement("option");

							document.getElementById("Modeld").options.add(opt);
							
							opt.text = mname;
        					opt.value = mvalue;


						}
						
						//document.getElementById('itemsFound').innerHTML = xmlDoc.getElementsByTagName("modelname").length;

											

					} else {

						alert("0000 There was a problem while using XMLHTTP:\n" + req.statusText);

					}



				}				

			}			

			req.open("GET", strURL, true);
			req.send(null);

		}		

	}
	
	
	function getTrim(modId) {		

		
		var strURL="ajaxprocessing1.php?model="+modId;
		var req = getXMLHTTP();


		if (req) {

			
			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					// only if "OK"

					if (req.status == 200) {						

						xmlDoc=req.responseXML;
						removeAllOptions(document.drop_list.parts);
						removeAllOptions(document.drop_list.Trim);
						
						var numItems= xmlDoc.getElementsByTagName("modelname").length;
						//document.getElementById('items').innerHTML = numItems;

						for (var i = 0; i < xmlDoc.getElementsByTagName("modelname").length; i++){

							mvalue = xmlDoc.getElementsByTagName("modelvalue")[i].childNodes[0].nodeValue;
							mname = xmlDoc.getElementsByTagName("modelname")[i].childNodes[0].nodeValue;
							mname = mname.toUpperCase();

							var opt = document.createElement("option");

							document.getElementById("Trim").options.add(opt);
							
							opt.text = mname;
        					opt.value = mvalue;

						}

						//document.getElementById('itemsFound').innerHTML = xmlDoc.getElementsByTagName("modelname").length;				

					} else {

						alert("0001 There was a problem while using XMLHTTP:\n" + req.statusText);

					}

				}				

			}			

			req.open("GET", strURL, true);
			req.send(null);

		}		

	}
	
	function getParts(trimID) {		

		

		var strURL="ajaxprocessing2.php?trim="+trimID;
		var req = getXMLHTTP();

		

		if (req) {

			

			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					// only if "OK"

					if (req.status == 200) {						

						xmlDoc=req.responseXML;
						removeAllOptions(document.drop_list.parts);

						var numItems= xmlDoc.getElementsByTagName("modelname").length;
						//document.getElementById('items').innerHTML = numItems;
						
						for (var i = 0; i < xmlDoc.getElementsByTagName("modelname").length; i++){

							if(i==0){
								addOption(document.drop_list.parts, '0','All Parts');	
							}

							mvalue = xmlDoc.getElementsByTagName("modelvalue")[i].childNodes[0].nodeValue;
							mname = xmlDoc.getElementsByTagName("modelname")[i].childNodes[0].nodeValue;
							mname = mname.toUpperCase();

							var opt = document.createElement("option");

							document.getElementById("parts").options.add(opt);
							
							opt.text = mname;
        					opt.value = mvalue;

						}
						
						//document.getElementById('itemsFound').innerHTML = xmlDoc.getElementsByTagName("modelname").length;

					

					} else {

						alert("0001 There was a problem while using XMLHTTP:\n" + req.statusText);

					}

				}				

			}			

			req.open("GET", strURL, true);
			req.send(null);

		}		

	}

