// Roshan's Ajax dropdown code with php

// This notice must stay intact for legal use

// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com

// If you have any problem contact me at http://roshanbh.com.np

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 getYear(mountid)
{
   // var strURL="findyears.php?mount="+mountid;
   // provider.submit("http://www.ronstoyshop.com/curtfeed.php?event=yearxml&mount="+mountid);
   var strURL="/curtfeed-live.php?event=years&mount="+mountid;
   // document.write(strURL);
   var req = getXMLHTTP();
   if (req)
   {
     document.getElementById('yeardiv').innerHTML = '<img src="/loading.gif" alt="loading -  please wait..." width="128" height="15" />';
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
	 // only if "OK"
	 if (req.status == 200)
         {
	      document.getElementById('yeardiv').innerHTML=req.responseText;
	 } else {
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);
	 }
       }

      }
   req.open("GET", strURL, true);
   req.send(null);
   }
   getMake('','-- Select Year --');
}



function getMake(mountid, yearid)
{
   // var strURL="findmakes.php?mount="+mountId;
   var strURL="/curtfeed-live.php?event=make&mount="+mountid+"&year="+yearid;
   var req = getXMLHTTP();
   if (req)
   {
      if (yearid != '-- Select Year --') {
     document.getElementById('makediv').innerHTML = '<img src="/loading.gif" alt="loading -  please wait..." width="128" height="15" />'; }
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
	 // only if "OK"
	 if (req.status == 200)
         {
	    document.getElementById('makediv').innerHTML=req.responseText;
	 } else {
   	   alert("There was a problem while using make XMLHTTP:\n" + req.statusText);
	 }
       }
      }
   req.open("GET", strURL, true);
   req.send(null);
   }
   getModel('','','-- Select Make --');
   // getStyle('','','','-- Select Model --');
   // getHitch('','','','','-- Select Style --');
   // reset  getModel, getStyle
}



function getModel(mountid, yearid, makeid)
{
   // var strURL="findmodels.php?mount="+mountId;
   var strURL="/curtfeed-live.php?event=model&mount="+mountid+"&year="+yearid+"&make="+makeid;
   var req = getXMLHTTP();
   if (req)
   {
     if (makeid != '-- Select Make --') {
     document.getElementById('modeldiv').innerHTML = '<img src="/loading.gif" alt="loading -  please wait..." width="128" height="15" />'; }
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
	 // only if "OK"
	 if (req.status == 200)
         {
	    document.getElementById('modeldiv').innerHTML=req.responseText;
	 } else {
   	   alert("There was a problem while using model XMLHTTP:\n" + req.statusText);
	 }
       }
      }
   req.open("GET", strURL, true);
   req.send(null);
   }
   getBodyStyle('','','','-- Select Model --');
}



function getBodyStyle(mountid, yearid, makeid, modelid)
{
   // var strURL="findstyles.php?mount="+mountId;
   var strURL="/curtfeed-live.php?event=style&mount="+mountid+"&year="+yearid+"&make="+makeid+"&model="+modelid;
   var req = getXMLHTTP();
   if (req)
   {
     if (modelid != '-- Select Model --') {
     document.getElementById('stylediv').innerHTML = '<img src="/loading.gif" alt="loading -  please wait..." width="128" height="15" />'; }
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
	 // only if "OK"
	 if (req.status == 200)
         {
	    document.getElementById('stylediv').innerHTML=req.responseText;
	 } else {
   	   alert("There was a problem while using style XMLHTTP:\n" + req.statusText);
	 }
       }
      }
   req.open("GET", strURL, true);
   req.send(null);
   }
  getHitch('','','','','-- Select Style --');
}



function getHitch(mountid, yearid, makeid, modelid, styleid)
{
   // var strURL="findstyles.php?mount="+mountId;
   var strURL="/curtfeed-live.php?event=hitch-live-feed&mount="+mountid+"&year="+yearid+"&make="+makeid+"&model="+modelid+"&bodystyle="+styleid;
   var req = getXMLHTTP();
   if (req)
   {
     if (styleid != '-- Select Style --') 
	 {
     document.getElementById('resultsdiv').innerHTML = '<img src="/loading.gif" alt="loading -  please wait..." width="128" height="15" />'; 
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
	 // only if "OK"
	 if (req.status == 200)
         {
	    document.getElementById('resultsdiv').innerHTML=req.responseText;
		// document.getElementById('resultsdiv').innerHTML='xxxxxxxxxxxxxxxxxxxx';
	 } else {
   	   alert("There was a problem while using style XMLHTTP:\n" + req.statusText);
	 }
       }
      }
   req.open("GET", strURL, true);
   req.send(null);
   }
   }
   // reset partnumbers
}

