Array.prototype.Empty=function() 
	{
		try
		{
			this.splice(0,this.length);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Array.prototype.Empty');
		}
		return true;
	}
Array.prototype.Contains=function(lookFor)
	{
		var result=false;
		for(var x=0;x<this.length;x++)
		{
			if(this[x]==lookFor)
			{
				result=true;
				break;
			}
		}
		return result;
	}

function Data(){}
Data.Categories=new Array();
Data.PartTypes=new Array();
Data.Brands=new Array();
Data.Models=new Array();
Data.Items=new Array();

function Choice()
{
	this.id=0;
	this.name='';
	this.description='';
}
Choice.prototype.SelectedID=0;
Choice.prototype.SelectedText="";
Choice.prototype.Add=function(obj,data)
	{
		try
		{
			obj.Data[obj.Data.length]=data;
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Choice.prototype.Add');
		}
		return true;	
	}
Choice.prototype.Reset=function()
	{
		Status.Reset();
		Data.Items.Empty();
		UI.Middle.Clear();
		divSPI.innerHTML="";
	}
Choice.prototype.Empty=function(obj)
	{
		try
		{
			obj.SelectedID=0;
			obj.SelectedText="";
			for (var x=obj.Select.options.length;x>0;x--)
				obj.Select.options.remove(1);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Choice.prototype.Empty');
		}
		return true;
	}
Choice.prototype.Fill=function(obj)
	{
		var array=obj.Data;
		var select=obj.Select;
		for (var x=0;x<array.length;x++) 
		{
			var tmpElm=document.createElement("OPTION");
			tmpElm.text=array[x].name;
			tmpElm.value=array[x].id.toString();
			select.options.add(tmpElm);
			delete tmpElm;
		}
	}

function ImageChoice()
{
	this.imagesrc='';
}
ImageChoice.prototype = new Choice();
ImageChoice.prototype.constructor=ImageChoice;
ImageChoice.prototype.Empty=function(obj)
	{
		try
		{
			var z=new Choice();
			obj.PicDiv.innerHTML="";
			z.Empty(obj);
			delete z;
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: ImageChoice.prototype.Empty');
		}
	}
ImageChoice.prototype.ImageSwap=function(obj)
	{
		window.event.cancelBubble=true;
		var id=obj.SelectedID;
		var txt=obj.SelectedText;
		var theArr=obj.Data;
		var theDiv=obj.PicDiv;
		var theImgSrc="";
		try
		{
			if (id==0 || isNaN(id)) 
			{
				theDiv.innerHTML="";
				return true;
			}
			window.status="Loading graphic, please wait...";
			for(x=0;x<theArr.length;x++) 
			{
				if (theArr[x].id==id) 
				{
					var theArrElm=theArr[x];var theHTML;
					if (theArrElm.imagesrc.length>0) 
					{
						theImgSrc=Config.GraphicPathPrefix + theArrElm.imagesrc;
						theHTML="<img src=\"" + theImgSrc + "\"/>";
						theDiv.innerHTML=theHTML;
					}
					else if (txt.length>0) theHTML="No picture for...<br>" + txt;
					else theHTML="";
					theDiv.innerHTML=theHTML;
					delete theHTML;
				}
			}
			delete theArr;delete theDiv;
			window.status="Page Load complete, please proceed."
		}
		catch (e)
		{
			if (theImgSrc.toUpperCase().indexOf("PICTURE FAILED",0)==-1) return true;
			else alert('An Error occurred: ' + e.message + '\nLocation: ImageChoice.prototype.ImageSwap');
		}
		return true;	
	}

function Category(id,name,description,imagesrc) 
{
	try
	{		
		this.id=parseInt(id);
		this.name=name;
		this.description=description;
		this.imagesrc=imagesrc;
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: Category');
	}
	return true;
}
Category.prototype = new ImageChoice();
Category.prototype.constructor=Category;
Category.Data=Data.Categories;
Category.Add=function(item)
	{	
		try
		{
			this.prototype.Add(this,item);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Category.Add');
		}
		return true;
	}
Category.Empty=function()
	{
		this.prototype.Empty(this);
		return true;
	}
Category.Reset=function()
	{
		try
		{
			this.prototype.Reset();
			PartNumber.Empty();
			Category.ImageSwap();
			PartType.ImageSwap();
			Model.ImageSwap();
			PartType.Empty();
			Brand.Empty();
			Model.Empty();
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Category.Reset');
		}
		return true;
	}
Category.Fill=function()
	{
		Category.Empty();
		this.prototype.Fill(this);
	}
Category.Changed=function(elm) 
	{
		try
		{
			with(elm)
			{
				Category.SelectedID=parseInt(options[options.selectedIndex].value);
				Category.SelectedText=options[options.selectedIndex].text;
			}
			Category.Reset();
			Category.ImageSwap();
			if (Category.SelectedID!=0) PartType.Fill();
			//alert("Category.SelectedID=" + Category.SelectedID + ":PartType.SelectedID=" + PartType.SelectedID + ":Brand.SelectedID=" + Brand.SelectedID + ":Model.SelectedID=" + Model.SelectedID);
		}
		catch (e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Category.Changed');
		}	
		return true;		
	}	
Category.ImageSwap=function()
	{
		try
		{
			this.prototype.ImageSwap(this);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Category.ImageSwap');
		}
		return true;
	}

function PartType() 
{
	try
	{
		this.id=parseInt(0);
		this.name="";
		this.description="";
		this.imagesrc="";
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: PartType');
	}
	return true;
}
PartType.prototype = new ImageChoice();
PartType.prototype.constructor=PartType;	
PartType.Data=Data.PartTypes;
PartType.Add=function(item)
	{	
		try
		{
			this.prototype.Add(this,item);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: PartType.Add');
		}
		return true;
	}
PartType.Empty=function()
	{
		this.prototype.Empty(this);
		return true;
	}
PartType.Reset=function()
	{
		try
		{
			this.prototype.Reset();
			Model.ImageSwap();
			PartNumber.Empty();
			Brand.Empty();
			Model.Empty();
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: PartType.Reset');
		}
		return true;
	}
PartType.Fill=function()
	{
		PartTypes.Get();
		PartType.Empty();
		this.prototype.Fill(this);
	}
PartType.Changed=function(elm) 
	{
		try
		{
			with(elm)
			{
				PartType.SelectedID=parseInt(options[options.selectedIndex].value);
				PartType.SelectedText=options[options.selectedIndex].text;
			}
			PartType.Reset();
			PartType.ImageSwap();
			if (PartType.SelectedID!=0) Brand.Fill();
			//alert("Category.SelectedID=" + Category.SelectedID + ":PartType.SelectedID=" + PartType.SelectedID + ":Brand.SelectedID=" + Brand.SelectedID + ":Model.SelectedID=" + Model.SelectedID);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: PartTypeChanged');
		}
		return true;
	}
PartType.ImageSwap=function()
	{
		try
		{
			this.prototype.ImageSwap(this);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: PartType.ImageSwap');
		}
		return true;
	}

function Brand()
{
	try
	{
		this.id=parseInt(0);
		this.name="";
		this.description="";
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: Brand');
	}
	return true;
}
Brand.prototype = new Choice();
Brand.prototype.constructor=Brand;
Brand.Data=Data.Brands;
Brand.Add=function(item)
	{	
		try
		{
			this.prototype.Add(this,item);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Brand.Add');
		}
		return true;
	}
Brand.Empty=function()
	{
		this.prototype.Empty(this);
		return true;
	}
Brand.Reset=function()
	{
		try
		{
			this.prototype.Reset();
			Model.ImageSwap();
			PartNumber.Empty();
			Model.Empty();
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Brand.Reset');
		}
		return true;
	}
Brand.Fill=function()
	{
		Brands.Get();
		Brand.Empty();
		this.prototype.Fill(this);
	}
Brand.Changed=function(elm) 
	{
		try
		{
			with(elm)
			{
				Brand.SelectedID=parseInt(options[options.selectedIndex].value);
				Brand.SelectedText=options[options.selectedIndex].text;
			}
			Brand.Reset();
			if (Brand.SelectedID!=0) Model.Fill();
			//alert("Category.SelectedID=" + Category.SelectedID + ":PartType.SelectedID=" + PartType.SelectedID + ":Brand.SelectedID=" + Brand.SelectedID + ":Model.SelectedID=" + Model.SelectedID);
			
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: BrandChanged');
		}
		return true;
	}
	
function Model()
{
	try
	{
		this.id=parseInt(0);
		this.name="";
		this.description="";
		this.imagesrc="";
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: Model');
	}
	return true;
}
Model.prototype = new ImageChoice();
Model.prototype.constructor=Model;
Model.Data=Data.Models;
Model.Add=function(item)
	{	
		try
		{
			this.prototype.Add(this,item);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Model.Add');
		}
		return true;
	}
Model.Empty=function()
	{
		this.prototype.Empty(this);
		return true;
	}
Model.Reset=function()
	{
		try
		{
			this.prototype.Reset();
			PartNumber.Empty();
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Model.Reset');
		}
		return true;
	}
Model.Fill=function()
	{
		Models.Get();
		Model.Empty();
		this.prototype.Fill(this);
	}
Model.Changed=function(elm) 
	{
		try
		{
			with(elm)
			{
				Model.SelectedID=parseInt(options[options.selectedIndex].value);
				Model.SelectedText=options[options.selectedIndex].text;
			}
			Model.Reset();
			Model.ImageSwap();
			//alert("Category.SelectedID=" + Category.SelectedID + ":PartType.SelectedID=" + PartType.SelectedID + ":Brand.SelectedID=" + Brand.SelectedID + ":Model.SelectedID=" + Model.SelectedID);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Model.Changed');
		}
		return true;
	}
Model.ImageSwap=function()
	{
		try
		{
			this.prototype.ImageSwap(this);
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Model.ImageSwap');
		}
		return true;
	}

function Catalog(){}
Catalog.Selected=function(elm)
    {
        var url;
        with(elm)
		{
		    url=options[options.selectedIndex].value;
		    if(url.length > 0) 
		        window.open(url);
		}
    }

function PartNumber(){}
PartNumber.prototype = new Choice();
PartNumber.prototype.constructor=PartNumber;
PartNumber.Reset=function()
	{
		this.prototype.Reset();
		Category.ImageSwap();
		PartType.ImageSwap();
		Model.ImageSwap();
		Category.Fill();
		PartType.Empty();
		Brand.Empty();
		Model.Empty();
	}
PartNumber.Empty=function()	
	{
		UI.PartNumber.value="";
	}
	
function Item()
{
	try
	{
		this.itemid="";
		this.dimensiona="";
		this.dimensionb="";
		this.description="";
		this.retailprice="";
		this.imagesrc="";
		this.brand="";
		this.manufacturerid="";
		this.relateditemsfile="";
		Data.Items[Data.Items.length]=this;
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: Item');
	}
	return true;
}
Item.prototype = new ImageChoice();
Item.prototype.constructor=Item;

function Search(){}
Search.prototype = new Choice();
Search.prototype.constructor=Search;
Search.Reset=function()
	{
		try
		{
			this.prototype.Reset();
			divSPI.innerHTML="";
			PartNumber.SelectedID=UI.PartNumber.value;
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Search.Reset');
		}
		return true;
		
	}
Search.Clicked=function(frm) 
{
	try
	{
		var theFrm=frm;
		window.status="SEARCHING, please wait..."
		document.body.style.cursor="wait";
		Search.Reset();
		if ((Category.SelectedID==0 || PartType.SelectedID==0) && (PartNumber.SelectedID.length==0 || PartNumber.SelectedID==0)) 
		{
			window.status="Criteria requirements not met.";
			alert("You MUST specify either a (Category and Part Type) or a Part Number!\n\nTry again.");	
			if (Category.SelectedID==0) theFrm.cboCategory.focus();
			else if (PartType.SelectedID==0) theFrm.cboPartType.focus();
			else if (PartNumber.SelectedID.length==0) theFrm.txtPartNumber.focus();
			else if (PartNumber.SelectedID==0) 
			{
				theFrm.txtPartNumber.value="";
				theFrm.txtPartNumber.focus();
			}
			document.body.style.cursor="default";
			return false;
		}
		if (PartNumber.SelectedID.length>0 && PartNumber.SelectedID!=0) 
		{
			var ToReplace;
			ToReplace=new RegExp("\\*","g");
			var ReplaceWith="%";
			PartNumber.SelectedID=PartNumber.SelectedID.replace(ToReplace,ReplaceWith)
			delete ToReplace;
			void GetAltItems();
		} 
		else GetItems();
		Config.SortType="itemid";
		UI.Middle.Show();
		delete thePartType;delete theFrm;
		document.body.style.cursor="default";
	}
	catch(e)
	{
		alert('An Error occurred: ' + e.message + '\nLocation: Search.Clicked');
		document.body.style.cursor="";		
	}
	return true;		
}	
	
	
function Status(){}
Status.Reset=function()
	{
		try
		{
			window.status="";
			window.defaultStatus="";
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: Status.Reset()');
		}
	}
	
function UI(){}
UI.TD=function(width,align,innerText)//,colspan,bgcolor,extra
	{
		try
		{
			var result="<TD";
			if(width.length > 0)
				result+=" Width='" + width + "'";
			if(align.length > 0)
			{
				result+=" Align='" 
				switch(align.substring(0,1).toUpperCase())
				{
					case "R":
						result+="Right";break;
					case "L":
						result+="Left";break;
					case "B":
						result+="Bottom";break;
					case "T":
						result+="Top";break;
					case "M":
						result+="Middle";break;
					default:
						result+="Center";break;
				}
				result+="'";
			}
			if(arguments.length > 3)
				if(arguments[3].length > 0) result+=" ColSpan='" + arguments[3] + "'";
			if(arguments.length > 4)
				if(arguments[4].length > 0) result+=" bgColor='" + arguments[4] + "'";
			if(arguments.length > 5)
				if(arguments[5].length > 0) result+=" " + arguments[5];
			result+=">" + innerText + "</TD>";
			return result;	
		}
		catch(e)
		{
			alert('An Error occurred: ' + e.message + '\nLocation: UI.TD()');
		}
	}
