function Form()
{
	this.DataToSend="";
	if(arguments.length > 0)
		if(arguments[0].length != 0) this.DataToSend=arguments[0];
	this.URL="";
	if(arguments.length > 1)
		if(arguments[1].length != 0) this.URL=arguments[1];
	this.Method="POST";
	if(arguments.length > 2)
		if(arguments[2].length != 0) this.Method=arguments[2];
	this.ContentType="application/x-www-form-urlencoded";
	if(arguments.length > 3)
		if(arguments[3].length != 0) this.ContentType=arguments[3];
	this.Response="";
	return true;
}
Form.prototype.Post=function()
	{
		var xmlhttp;var result="";
		try
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if(xmlhttp==void(0))
			{
				alert("Microsoft XML is not installed!");
				return;
			}
			with(xmlhttp)
			{
				if(this.Method.toUpperCase()=="POST")
				{
					Open(this.Method,this.URL,false);
					setRequestHeader("Content-type",this.ContentType);
					Send(this.DataToSend);
				}
				else
				{
					Open(this.Method,this.URL + "&" + this.DataToSend,false);
					Send();
				}
				result=responseText;
				this.Response=result;
			}
			delete xmlhttp;
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Form.prototype.Post');
		}
		return result;
	}

function Customer(){}
Customer.Name="";
Customer.GetName=function()
	{
		var tmpHref="";
		var customerStart=0;var customerLength=0; var passwordStart=0;var customerName;
		try
		{
			if(Customer.Name.length==0)
			{
				tmpHref=document.location.href.toUpperCase();
				if (tmpHref.indexOf('?CN=')!=-1)
				{
					customerStart=tmpHref.indexOf('?CN=') + 4;
					passwordStart=tmpHref.indexOf('&PW=') ;
					customerLength=passwordStart-customerStart;
					customerName=tmpHref.substr(customerStart,customerLength);
					var arrCustomerName=customerName.split(",");
					customerName="";
					for (var x=0;x<arrCustomerName.length;x++)
						customerName+=String.fromCharCode(arrCustomerName[x]);	
				}
				else
				{
					customerName=String.fromCharCode(85,110,114,101,97,108,99,105,116,121);
				}		
			}
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Customer.Get');
		}
		Customer.Name=customerName;
		return Customer.Name;
	}
Customer.Password="";
Customer.GetPassword=function()
	{
		var passwordStart=0;var passwordLength=0;var tmpHref="";var password;
		try
		{
			if(Customer.Password.length==0)
			{
				tmpHref=document.location.href.toUpperCase();
				if (tmpHref.indexOf('&PW=')!=-1)
				{
					passwordStart=tmpHref.indexOf('&PW=') + 4;
					passwordLength=tmpHref.length-passwordStart;
					if(tmpHref.indexOf('&',passwordStart)!=-1)
					{
						passwordLength=passwordLength - (tmpHref.length - tmpHref.indexOf('&',passwordStart));
					}
					password=tmpHref.substr(passwordStart,passwordLength);
					var arrPassword=password.split(",");
					var PostFrom;
					password="";
					for (var x=0;x<arrPassword.length;x++)
						password+=String.fromCharCode(arrPassword[x]);	
				}
				else
				{
					password=String.fromCharCode(49,48,50,48,49,57,54,56); 			
				}		
			}
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Customer.Password.Get');
		}
		Customer.Password=password;
		return Customer.Password;
	}

Customer.Name=Customer.GetName();
Customer.Password=Customer.GetPassword();

function PostForm(sXML) 
{
	var xmlhttp;var theURL;var xmlDoc;var theProductName="";var ReturnedXML;var theXML;var theDataToSend;
	var form=new Form();
	try 
	{
		if (arguments.length > 1) 
		{
			form.URL=arguments[1];
		}
		else 
		{
			form.URL="http://" + document.domain + "/xml/default.asp";
			theProductName="<?productname Optimus Parts?>";
			theProductName+="<?customer " + Customer.Name + "?>";
			theProductName+="<?password " + Customer.Password + "?>";
		}
		var theXML=escape(theProductName + sXML);
		form.DataToSend="xml=" + theXML;
		var arg2="";
		if (arguments.length > 2) 
			form.Method=arguments[2].toUpperCase();
		ReturnedXML=form.Post();
		if (ReturnedXML.length==0 && arg2!="GET") 
			alert('No Data was returned by your request; please inform the webmaster.');
		else
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			if (xmlDoc==void(0)) 
			{
				alert('Error creating Microsoft.XMLDOM; please inform the webmaster.')
				return;
			}
			with (xmlDoc) 
			{
				async = false;
				loadXML(ReturnedXML);
			}
			delete form;
			return xmlDoc;
		}
	} 
	catch (e) 
	{
		alert('An Error occurred: ' + e.message + '\nLocation: PostForm');
		alert('You must have XML 3.0 or higher installed to utilize this website.\n\nYou can download this for free from www.microsoft.com/xml/');
		return true;
	}	
}

function BasePost(postType)
{
	this.PostType=postType;
	this.Item=null;
	this.Items="";
	this.ItemsToEncode="";
}
BasePost.prototype.GetXml=function(innerXml)
	{
		var Xml="<root><" + this.PostType + " action='get'>";
		Xml+="<customername>" + Customer.Name + "</customername>";
		Xml+=innerXml;
		Xml+="</" + this.PostType + "></root>";	
		return Xml;
	}
BasePost.prototype.CreateArray=function(docElm)
	{
		var tmp;
		try
		{
			with (docElm) 
			{
				for (var n=0;n<childNodes.length;n++) 
				{
					var aTmp=new this.Item();
					var elementsToAdd=this.Items.split(",");
					var elementsToAddEncoded=this.ItemsToEncode.split(",");
					for (var a=0;a<childNodes[n].attributes.length;a++) 
					{
						tmp=childNodes[n].attributes[a].name.toLowerCase();
						if(elementsToAdd.Contains(tmp))
							aTmp[tmp]=childNodes[n].attributes[a].nodeTypedValue;
					}
					this.Item.Add(aTmp);
					delete aTmp;
				}
			}
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: BasePost.CreateArray');
		}
	}

function PartTypes()
{
	PartTypes.PostFrom="GetPartTypes";
}
PartTypes.prototype=new BasePost('parttypes');
PartTypes.prototype.constructor=PartTypes;
PartTypes.GetXml=function()
	{
		var innerXml="";
		if (Category.SelectedID!=0) 
			innerXml+="<categoryid>" + Category.SelectedID + "</categoryid>";
		return this.prototype.GetXml(innerXml);
	}
PartTypes.Get=function()
	{
		var oDocElm;var thePost;var xmlDoc;var tmp;
		window.status="Getting Part Types, please wait...";
		try
		{
			Data.PartTypes.Empty();
			this.prototype.Item=PartType;
			this.prototype.Items="id,name,description,imagesrc";
			this.prototype.ItemsToEncode="";			
			thePost=PartTypes.GetXml();	
			xmlDoc=PostForm(thePost);
			oDocElm=xmlDoc.documentElement;
			this.prototype.CreateArray(oDocElm);				
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: PartTypes.Get');
		}
		window.status="Page Load complete, please proceed."
		return true;
	}
	
function Brands()
{
	Brands.PostFrom="GetBrands";
}
Brands.prototype=new BasePost('brands');
Brands.prototype.constructor=Brands;
Brands.GetXml=function()
	{
		var innerXml="";
		if (PartType.SelectedID!=0) 
			innerXml+="<parttypeid>" + PartType.SelectedID + "</parttypeid>";
		return this.prototype.GetXml(innerXml);
	}
Brands.Get=function()
	{
		var oDocElm;var thePost;var xmlDoc;var tmp;
		window.status="Getting Brands, please wait...";
		try
		{
			Data.Brands.Empty();
			this.prototype.Item=Brand;
			this.prototype.Items="id,name,description";
			this.prototype.ItemsToEncode="";			
			thePost=Brands.GetXml();	
			xmlDoc=PostForm(thePost);
			oDocElm=xmlDoc.documentElement;
			this.prototype.CreateArray(oDocElm);				
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Brands.Get');
		}
		window.status="Page Load complete, please proceed."
		return true;
	}

function Models()
{
	Models.PostFrom="GetModels";
}
Models.prototype=new BasePost('models');
Models.prototype.constructor=Models;
Models.GetXml=function()
	{
		var innerXml="";
		if (Brand.SelectedID!=0) 
			innerXml+="<brandid>" + Brand.SelectedID + "</brandid>";
		return this.prototype.GetXml(innerXml);
	}
Models.Get=function()
	{
		var oDocElm;var thePost;var xmlDoc;var tmp;
		window.status="Getting Models, please wait...";
		try
		{
			Data.Models.Empty();
			this.prototype.Item=Model;
			this.prototype.Items="id,name,description,imagesrc";
			this.prototype.ItemsToEncode="";			
			thePost=Models.GetXml();	
			xmlDoc=PostForm(thePost);
			oDocElm=xmlDoc.documentElement;
			this.prototype.CreateArray(oDocElm);				
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Models.Get');
		}
		window.status="Page Load complete, please proceed."
		return true;
	}
function QuoteEncode(stringToEncode)
{
	var evalChar="";
	var evalCode=0;
	var encodeString=" in.";
	var returnString="";
	stringToEncode=stringToEncode.toString();
	var len=stringToEncode.length;
	for(var x=0;x<len;x++)
	{	
		evalChar=stringToEncode.substring(x,x+1);
		evalCode=evalChar.charCodeAt(0);
		if (evalCode != 34)
			returnString+=evalChar;
		else
			returnString+=encodeString;
	}
	stringToEncode=returnString;
	returnString="";
	encodeString="and";
	len=stringToEncode.length;
	for(var x=0;x<len;x++)
	{	
		evalChar=stringToEncode.substring(x,x+1);
		evalCode=evalChar.charCodeAt(0);
		if (evalCode != 38)
			returnString+=evalChar;
		else
			returnString+=encodeString;
	}
	return returnString;
}


function GetItems() 
{
	var oDocElm;var thePost;var xmlDoc;var tmp;
	window.status="Getting Items, please wait...";
	try
	{
		Data.Items.Empty();
		thePost="<root><items action='get'>";
		if (PartType.SelectedID!=0 && !isNaN(PartType.SelectedID)) 
			thePost+="<parttypeid>" + PartType.SelectedID + "</parttypeid>";
		if (Brand.SelectedID!=0 && !isNaN(Brand.SelectedID))
			thePost+="<brandid>" + Brand.SelectedID + "</brandid>";
		if (Model.SelectedID!=0 && !isNaN(Model.SelectedID)) 
			thePost+="<modelid>" + Model.SelectedID + "</modelid>";
		thePost+="<customername>" + Customer.Name + "</customername>";
		thePost+="</items></root>";
		PostFrom="GetItems";
		xmlDoc=PostForm(thePost);	
		oDocElm=xmlDoc.documentElement;
		with (oDocElm) 
		{
			for (var n=0;n<childNodes.length;n++) 
			{
				var aI=new Item("","0","0","","0","","","0");
				for (var cn=0;cn<childNodes[n].childNodes.length;cn++) 
				{
					tmp=childNodes[n].childNodes[cn].nodeName.toLowerCase();
					if (tmp!=void(0) && tmp!="" &&
							(
							tmp=="itemid" || 
							tmp=="retailprice" ||
							tmp=="imagesrc" ||
							tmp=="brand" ||
							tmp=="manufacturerid" ||
							tmp=="relateditemsfile"
							)
						)
						aI[tmp]=childNodes[n].childNodes[cn].nodeTypedValue;
					else if (tmp!=void(0) && tmp!="" &&
								(
								tmp=="description" ||
								tmp=="dimensiona" || 
								tmp=="dimensionb" 
								)
						)
						aI[tmp]=QuoteEncode(childNodes[n].childNodes[cn].nodeTypedValue);
				}
				delete aI;
			}
		}
		delete thePost;delete oDocElm;delete xmlDoc;delete tmp;
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: GetItems');
	}
	window.status="Page Load complete, please proceed."
	return true;
}			
function GetAltItems() 
{
	var oDocElm;var thePost;var xmlDoc;var tmp;
	window.status="Getting Items, please wait...";
	try
	{
		Data.Items.Empty();
		thePost="<root><altitems action='get'>";
		thePost+="<itemid>" + PartNumber.SelectedID + "</itemid>";
		thePost+="<customername>" + Customer.Name + "</customername>";
		thePost+="</altitems></root>";
		PostFrom="GetAltItems";
		xmlDoc=PostForm(thePost);	
		oDocElm=xmlDoc.documentElement;
		with (oDocElm) 
		{
			for (var n=0;n<childNodes.length;n++) 
			{
				var aI=new Item("","0","0","","0","","","0");
				for (var cn=0;cn<childNodes[n].childNodes.length;cn++) 
				{
					tmp=childNodes[n].childNodes[cn].nodeName.toLowerCase();
					if (tmp=="itemid" || 
						tmp=="retailprice" ||
						tmp=="imagesrc" ||
						tmp=="brand" ||
						tmp=="manufacturerid" ||
						tmp=="relateditemsfile")
						aI[tmp]=childNodes[n].childNodes[cn].nodeTypedValue;
					else if (tmp=="dimensiona" || 
						tmp=="dimensionb" ||
						tmp=="description")
						aI[tmp]=QuoteEncode(childNodes[n].childNodes[cn].nodeTypedValue);						
					}
				delete aI;
			}
		}
		delete thePost;delete oDocElm;delete xmlDoc;delete tmp;
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: GetAltItems');
	}
	window.status="Page Load complete, please proceed."
	return true;
}