// !!!!! THIS IS IMPORTANT !!!!!!
// If you edit this file, you should also search for all references to it in the code and
// change the version number in the querystring.  This file is cached by hard-browsers and
// needs to be reloaded by the clients.

var XML_UTIL_INVALIDRESPONSE = 1;

function LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,firstoptionvalue, showOptionAll, showOptionRequest, showOptionAdd)
{    
    document.getElementById(selectid).length = 0;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	//alert("XML: " + xmlurl);
	xmlhttp.open("GET", xmlurl, false);
	xmlhttp.send(null);
	//alert(xmlhttp.status);
	var doc = xmlhttp.responseXML;
	var coll = doc.getElementsByTagName(maintag);
	var elementcount = 0;
	
     AddOption(selectid,firstoptiontext,firstoptionvalue);
     if (showOptionAll) AddOption(selectid,"All","0");
     if (showOptionRequest)
     {
		if (selectid.toLowerCase().indexOf("models") > 0)
			AddOption(selectid,"Request Model","REQ");
		else if (selectid.toLowerCase().indexOf("manufacturers") > 0)
			AddOption(selectid,"Request Manufacturer","REQ");
	}
	if (showOptionAdd)
     {
		if (selectid.toLowerCase().indexOf("models") > 0)
			AddOption(selectid,"Add Model","ADD");
		else if (selectid.toLowerCase().indexOf("manufacturers") > 0)
			AddOption(selectid,"Add Manufacturer","ADD");
	}
     for (i=0;i<coll.length;i++)
	 {
		var coll2 = coll[i].getElementsByTagName(idtag);
		var coll3 = coll[i].getElementsByTagName(texttag);
		AddOption(selectid,coll3[0].childNodes[0].nodeValue,coll2[0].childNodes[0].nodeValue);
		elementcount++;
	 }
	
	return elementcount;
	
}

function LoadBaseModels(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{
     LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,"",false,false, false);
}

function LoadSelectFromXmlForAdvancedSearch(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{
	return LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,"",true,false, false);
}

function LoadSelectFromXml(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{
	return LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,"",false,false, false);
}
function LoadSelectFromXmlReq(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{
	return LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,"",false,true, false);
}
function LoadSelectFromXmlAdd(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{
	return LoadSelectFromXml_Ex(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext,"",false, false, true);
}
function LoadXml(xmlurl,maintag)
{
    	var returnvalue;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	xmlhttp.open("GET", xmlurl, false);
	xmlhttp.send(null);
	if (xmlhttp.responseText.indexOf(maintag) == -1)
	{
	    returnvalue = XML_UTIL_INVALIDRESPONSE;
	}
	else
	{
        var doc = xmlhttp.responseXML;
        returnvalue = doc.getElementsByTagName(maintag);
    }
	return returnvalue;
}
function AddOption(selectid,text,value)
{
	var option1 = document.createElement("OPTION");
	option1.text = text;
	option1.value = value;
	var optionsarray = document.getElementById(selectid).options;
	optionsarray[optionsarray.length] = option1;
}

function LoadSubCategoriesAdvancedSearch(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{              
   var returnval = LoadSelectFromXmlForAdvancedSearch(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
   return returnval;
}
function LoadSubCategories(selectid,xmlurl,maintag,idtag,texttag,firstoptiontext)
{              
   var returnval = LoadSelectFromXml(selectid, xmlurl, maintag, idtag, texttag, firstoptiontext);
   return returnval;
}