function ClickCancel(Destination,isTop){
	//if a cancel button is clicked do this.
	//isTop is optional.	
	if (Destination.length > 0 && confirm('Press \'OK\' to Cancel')){								
		if (arguments[1])
			top.location.href = Destination;							
		else
			location.href = Destination;	
	}
}//end of ClickCancel
function jsTrim(inFieldValue){					
	var inFieldLength = inFieldValue.length;					
	var i,startI,endI;
					
	if (inFieldLength > 0){					
		//
		//start from beginning and find the fist non-space
		//
		for(i=0; i < inFieldLength; i++){
							
			if(inFieldValue.charAt(i) != ' '){								
				startI = i;
				i = inFieldLength;
			} 									
		}
		//
		//start from end and find the first non-space
		//
		for(i=inFieldLength-1; i >= 0; i--){
			//alert(inFieldValue.charAt(i))
			if(inFieldValue.charAt(i) != ' '){								
				endI = i+1;
				i = 0;
			}
		}
		//alert('->'+inFieldValue.substring(startI,endI)+'<-');
		return inFieldValue.substring(startI,endI)
	}//end of if()
	else {return '';}
}//end of jsTrim
function NumericCheck(inForm,inElement) {
	var re = /\,|\$|\./gi;
	var formItem,formItem;
	var i,returnNum;	
	
	//
	//verify number is numeric
	//	
	//GET element value
	formItem = (GetVal(inForm, inElement)); 
	//remove all '$' ; '.' ; ','
	formItemre = formItem.replace(re, "");
	//check to see if number is numeric or base 10
	if ( (parseInt(formItemre,10) !=formItemre) && formItemre != "" ) {
		alert(inElement + " must be numeric");
		return false; 
	}	
	
	//
	//Format number to display to customer
	//	
	//remove '$' ; ','
	re = /\,|\$/gi;
	formItemre = formItem.replace(re,"")
	//split upon decimal	
	formItemre = formItemre.split(".");
	//check to see if there are more than one decimal
	if (formItemre.length > 2 ) {
		alert(inElement + " has too many decimal points");
		return false;		
	}
	//set returnNum = nothing
	returnNum = "";
	//build return number to set in textbox
	for(i=0;i<formItemre.length;i++){		
		if (i>0){returnNum = returnNum + '.'}
		returnNum = returnNum + formItemre[i];
	}
	
	//Set the text value
	SetVal(inForm,inElement,returnNum);
	return true;		
}//end of NumericCheck()
function jsTB(inName,inValue,inSize,inMaxLength){
	var T = '';
	var Size = 25;
	var MaxLength = 255;
	if (arguments[2])
	{
		Size = inSize
	}
	if (arguments[3])
	{
		MaxLength = inMaxLength
	}										
	T += '<input type="text" name="'+inName+'" id="'+inName+'" value="'+inValue+'" class="FormElementInput" size="'+Size+'" maxlength="'+MaxLength+'" />';
	return T;
}//end of jsTB
function jsHI(inName,inValue){
	var H;
	var hValue = '';
	if (arguments[1])
	{
		hValue = inValue;
	}
	H = '<input type="hidden" name="'+inName+'" value="'+hValue+'" />'
	return H;
}//end of jsHI
function GetFileExt(inImage){
	var ImageLength = inImage.length;
	var tmpStr = '';
	if (ImageLength > 0){
		for (var i=(ImageLength-3); i<ImageLength; i++){
			tmpStr+= inImage.charAt(i);
		}
		return tmpStr.toLowerCase();
	}else{return false;}
}
function MakeThumbString(inImage){
	var ImageLength = inImage.length;
	var tmpStr = '';
	if (ImageLength > 0){
		for (var i=0; i<ImageLength; i++){
			tmpStr+= inImage.charAt(i);
			if (i == ImageLength-5){
				tmpStr+= '_thumb';
			}
		}
		return tmpStr.toLowerCase();
	}else{return false;}
}

//inventory-modifier bumblefuck functions/objects

function InventoryEntry(){
	this.Modifiers=new String();
	this.QtyOnHand=0;
	this.AllowBackorder=false;
	this.ItemCode= new String();
	this.ItemPrice = 0;
	this.aryMod = new Array();
	this.ItemID = 0;
	this.ItemConcurrencyID = 0;
	this.Image = null;
}

InventoryEntry.prototype.AddModifier = function(ID){
	this.aryMod.push(ID);
	this.aryMod.sort();
	this.Modifiers = this.aryMod.join(',');
}

InventoryEntry.prototype.isAvailable = function(Qty, Name){
	if (this.AllowBackorder) return true;
	
	if (parseInt(this.QtyOnHand) >= parseInt(Qty)) return true;
	alert(Name + ', as selected, is only available in quantities of ' + this.QtyOnHand.toString() + ' or less.');
	return false;
}

Array.prototype.push = function(value){
	this[this.length] = value;
}

//array of atts in form of NonInvAtts['a<modid>'] = true (if modid is a noninvatt)
var NonInvAtts = new Array();

function AddToItemData(ItemData, ModID, ModName, ModAddDesc, ModTypeName, ModBriefDesc, Price, ItemCode, Onhand, Methods, Backorder, ItemID, ItemConcurrencyID, ItemImage, ModOneTime){

	if(ItemData['Modifiers'] == null){
		ItemData['Modifiers'] = new Array();
	}
	
	if(ItemData['Modifiers'][ModTypeName] == null){
		ItemData['Modifiers'][ModTypeName] = new Array();
		ItemData['Modifiers'][ItemData['Modifiers'].length] = ModTypeName;
	}
	
	var ModifierData = new Object();
	
	ModifierData.ID = ModID;
	ModifierData.Name = ModName;
	ModifierData.AddDesc = ModAddDesc;
	ModifierData.IsInventory = ModBriefDesc;
	ModifierData.Price = Price;
	if (typeof ModOneTime != 'undefined') ModifierData.OneTime = ModOneTime
	
	//only add modifier data if not already added
	if(ItemData['Modifiers'][ModTypeName]['a' + ModName.toString()] == null){
		ItemData['Modifiers'][ModTypeName].push(ModifierData);
		ItemData['Modifiers'][ModTypeName]['a' + ModName.toString()] = true;
	}
	
	//this modifier is not associated with an item.
	if (ItemCode == null){
		NonInvAtts['a' + ModID] = true;
		return false;
	}
	NonInvAtts['a' + ModID] = false;
	
	//add to item definition
	var ItemCode1 = 'item' + ItemCode.toString();
	if (ItemData[ItemCode1] == null){
		ItemData[ItemCode1] = new InventoryEntry();
		ItemData[ItemCode1].QtyOnHand = Onhand;
		ItemData[ItemCode1].AllowBackorder = Backorder;
		ItemData[ItemCode1].ItemCode = ItemCode;
		ItemData[ItemCode1].ItemPrice = Price;
		ItemData[ItemCode1].ItemID = ItemID;
		ItemData[ItemCode1].Image = ItemImage;
		ItemData[ItemCode1].ItemConcurrencyID = ItemConcurrencyID;
		ItemData[ItemData.length] = ItemCode1;
	}
	
	ItemData[ItemCode1].AddModifier(ModID);
	ItemData[ItemCode1].ItemPrice += Price;
	
	return true;
}

function GetModString(ProductID){
	var x;
	var Mods = new Array();
	var str;
	var Props = GetTags('ProductProp' + ProductID.toString());

	for(x = 0; x < Props.length;x++){
		str = Props[x].value;
			str = str.split(String.fromCharCode(28));
			
			if (NonInvAtts['a' + str[1]] == false){
			if (str[3]=='false' || str[3] == '0'){
				Mods.push(str[1]);
			}}

	}
	
	Mods.sort();
	return Mods.join(',');
}

function GetInventoryEntry(ItemData, ProductID){
	
	var strMod = GetModString(ProductID);
	var x;
	for(x = 0; x < ItemData.length;x++){
		if (ItemData[ItemData[x]].Modifiers == strMod){
			return ItemData[ItemData[x]];
		}
	}
	
	return null;
}

function GetInventoryEntryByModString(ItemData, strMod){
	
	var x;
	for(x = 0; x < ItemData.length;x++){
		if (ItemData[ItemData[x]].Modifiers == strMod){
			return ItemData[ItemData[x]];
		}
	}
	
	return null;
}

function MultiItemDatas(){
	this.ItemDatas = new Array();
}

MultiItemDatas.prototype.AddToItemDatas = function(ProductID, ModID, ModName, ModAddDesc, ModTypeName, ModBriefDesc, Price, ItemCode, Onhand, Methods, Backorder, BasePrice){
	//if(this.ItemDatas == null) this.ItemDatas = new Array();
	
	if (this.ItemDatas[ProductID.toString()] == null){
		this.ItemDatas[ProductID.toString()] = new Array();
		this.ItemDatas[ProductID.toString()]['BasePrice']=BasePrice;
		this.ItemDatas[this.ItemDatas.length] = ProductID.toString();
	}
	
	var ItemData;
	ItemData = this.ItemDatas[ProductID.toString()];
	
	AddToItemData(ItemData, ModID, ModName, ModAddDesc, ModTypeName, ModBriefDesc, Price, ItemCode, Onhand, Methods, Backorder);
}

function DisplayProductDetail(ProductID, ItemData, onChange, Between, Spacer){
	
	//var ItemData = ItemDatas.ItemData[ProductID.toString()];
	
	var Modifiers = ItemData['Modifiers'];
	var out = '<table border=0 cellspacing=0 cellpadding=0>';
	var i;
	if (Modifiers != null){
		for(i=0;i<Modifiers.length;i++){
			//alert('drawing modifiers of type: ' + Modifiers[i] + ' out of ' + Modifiers.length);
			//DrawModifierSelect(ProductID, Modifiers[Modifiers[i]], Modifiers[i], onChange, Between, Spacer);
			out += GetModifierSelectRow(ProductID, Modifiers[Modifiers[i]], Modifiers[i], onChange, Between, Spacer);
	
		}
	}
	out += '</table>';
	GetTag('ProductModifiers' + ProductID.toString()).innerHTML = out;
	//alert(document.getElementById('ProductModifiers' + ProductID.toString()).innerHTML);
}


function DrawModifierSelect(ProductID, Modifiers, TypeName, onChange, Between, Spacer){
	
	var Div =GetTag('ProductModifiers' + ProductID.toString());
	var AddDescLabel;
	var AddDescHidden;
	var Opt;
	var Delim = String.fromCharCode(28);
	
	//var Sel = document.createElement("select");
	var re = /,/gi;
	
	var SelData = '<Select name="' + 'ProductProp' + ProductID.toString() + '" ';
	var AddDescHidden = '';
	var AddDesc = false;
	var OptionsString = new String();
	for(var i = 0; i < Modifiers.length;i++){
		
		Opt = new String();
		Opt = Modifiers[i].Name.toString() + (Modifiers[i].Price?' (' + (Modifiers[i].Price>0?'+':'') + formatCurrency(Modifiers[i].Price) +')':'');
		if(Modifiers[i].OneTime != 'undefined')
		{
			OptionsString += '<option value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + Delim + Modifiers[i].OneTime + '">' + Opt + '</option>';
		}
		else
		{
			OptionsString += '<option value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + '">' + Opt + '</option>';
		}
		if(Modifiers[i].AddDesc) AddDesc = true;
		if((AddDesc == true) && (AddDescHidden == ''))
		{
			AddDescLabel = Opt + ': ';
			AddDescHidden = '<input type="hidden" name="' + 'ProductProp' + ProductID.toString() + '" value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + '">';
		}
	}

	SelData += 'onchange="' + onChange + '" ';
	
	SelData += 'onkeyup="' + onChange + '" ';
	
	SelData += 'onmouseup="' + onChange + '" ';
	
	SelData += 'attType="Select" >';
	
	if(Between == null) Between='';
	if(Spacer == null) Spacer='&nbsp;';
	
	if (AddDesc){
		var Reg = new RegExp("Message", "gi");
		if(Reg.test(TypeName)){
		Between = '&nbsp;<TextArea rows=3 cols=35 onBlur="CheckTextArea(this, 210)" name="AddDesc' + TypeName + ProductID + '" onfocus="if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';">&lt;'+ TypeName +'&gt;</textarea>&nbsp;' + Between;
		}else{
		Between = ((Modifiers.length > 1)?'<br>':'&nbsp;') + '<input maxlength=210 type="text" name="AddDesc' + TypeName + ProductID + '" value="&lt;'+ TypeName +'&gt;" onfocus="if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';">&nbsp;' + Between;
		}
		document.write('<input type="hidden" name="AddDescNames' + ProductID + '" value="' + TypeName + '"');
	}
	
		if(AddDesc){
		//alert(AddDescHidden);
		Div.innerHTML+= Spacer.toString() + AddDescHidden + AddDescLabel + Between;
		}else{
		Div.innerHTML+= (jsTrim(TypeName).replace(' ', '&nbsp;') + ':') + Spacer.toString() + SelData + OptionsString + '</SELECT>' + Between;
		}
}

var RequiredFields = new Array();

function GetModifierSelectRow(ProductID, Modifiers, TypeName, onChange){
	var AddDescLabel;
	var AddDescHidden;
	var Opt;
	var Delim = String.fromCharCode(28);
	
	//var Sel = document.createElement("select");
	var re = /,/gi;
	
	var SelData = '<Select name="' + 'ProductProp' + ProductID.toString() + '" ';
	var Hidden = '<input type="hidden" name="ProductProp' + ProductID.toString() + '" value="';
	var AddDescHidden = '';
	var AddDesc = false;
	var OptionsString = new String();
	for(var i = 0; i < Modifiers.length;i++){
		
		Opt = new String();
		Opt = Modifiers[i].Name.toString() + (Modifiers[i].Price?' (+'+ formatCurrency(Modifiers[i].Price) +')':'');
		if(typeof Modifiers[i].OneTime != 'undefined')
		{
			OptionsString += '<option value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + Delim + Modifiers[i].OneTime + '">' + Opt + '</option>';
			Hidden += Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + Delim + Modifiers[i].OneTime + '"/>';
		}
		else
		{
			OptionsString += '<option value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + '">' + Opt + '</option>';
			Hidden += Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + '"/>';		
		}
	if(Modifiers[i].AddDesc) AddDesc = true;
		if((AddDesc == true) && (AddDescHidden == ''))
		{
			AddDescLabel = Opt + ': ';
			if(typeof Modifiers[i].OneTime != 'undefined')
			{
				AddDescHidden = '<input type="hidden" name="' + 'ProductProp' + ProductID.toString() + '" value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + Delim + Modifiers[i].OneTime + '">';
			}
			else
			{
				AddDescHidden = '<input type="hidden" name="' + 'ProductProp' + ProductID.toString() + '" value="' + Modifiers[i].Name.toString().replace(re, '') + Delim + Modifiers[i].ID  + Delim + Modifiers[i].Price + Delim + Modifiers[i].AddDesc + Delim + TypeName + '">';
			}
		}
	}

	SelData += 'onchange="' + onChange + '" ';
	
	SelData += 'onkeyup="' + onChange + '" ';
	
	SelData += 'onmouseup="' + onChange + '" ';
	
	SelData += 'attType="Select" >';
	
	var Between='';
	var Spacer='&nbsp;';
	if (AddDesc){
		RequiredFields[RequiredFields.length] = 'AddDesc' + TypeName + ProductID;
		var Reg = new RegExp("Message", "gi");
		if(Reg.test(TypeName)){
		Between = '</td><td>&nbsp;</td></tr><tr><td colspan=2><TextArea touched="false" rows=3 style="width:100%;" onBlur="CheckTextArea(this, 210)" id="AddDesc' + TypeName + ProductID + '" name="AddDesc' + TypeName + ProductID + '" onfocus="this.touched = \'true\'; if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';">&lt;'+ TypeName +'&gt;</textarea>&nbsp;' + Between;
		}else{
		Between = ((Modifiers.length > 1)?'<br>':'&nbsp;') + '<input touched="false" maxlength=210 type="text" id="AddDesc' + TypeName + ProductID + '" name="AddDesc' + TypeName + ProductID + '" value="&lt;'+ TypeName +'&gt;"';
		Reg = new RegExp("Email", "gi");
		if(Reg.test(TypeName)){
			Between += ' onBlur="stCheckEmail(this);" ';
		}
		Between += ' onfocus="this.touched=\'true\'; if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';">&nbsp;';
		}
		document.write('<input type="hidden" name="AddDescNames' + ProductID + '" value="' + TypeName + '"');
	}
	var out = '';
		if(AddDesc){
		//alert(AddDescHidden);
		out = '<tr><td>' + AddDescHidden + AddDescLabel + '</td><td>' + Between + '</td></tr>';
		}
		if(Modifiers.length == 1){
			if(out.length > 0) {return out;}else{
		    return '<tr><td valign="top">' + (jsTrim(TypeName).replace(' ', '&nbsp;') + ':') + '&nbsp;</td><td>&nbsp;' + Opt + Between+ Hidden +'</td></tr>';
			}
		}else{
			return '<tr><td valign="top">' + (jsTrim(TypeName).replace(' ', '&nbsp;') + ':') + '&nbsp;</td><td>' + SelData + OptionsString + '</SELECT>' + Between+ '</td></tr>';
		}
		
}

function stCheckEmail(tag){

	var eml = tag.value;
	
	if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(eml)){
		//do nothing
	}else{
		alert('Invalid email address.');
		tag.focus();
		return false;
	}

	if(prompt("Please confirm the recipient's email address.", "re-enter email here") != eml){
		alert('email addresses don\'t match, please check and try again.');
		tag.focus();
		return false;
	}



}

function CheckTextArea(tag, max){
	if (tag.value.length > max){
		tag.focus();
		alert("This field must be " + max + " characters or less in length.");
		
	}
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

var ResizeTimeout = new Array();
var ResizeImg1 = new Array();
var ResizeMaxW = new Array();
var ResizeMaxH = new Array();

function ResizeToFitBounds(Img1, MaxW, MaxH){
	
	ResizeImg1.push(Img1);
	ResizeMaxW.push(MaxW);
	ResizeMaxH.push(MaxH);
	
	ResizeTimeout.push(setInterval('ResizeToFitBoundsDelayed('+ ResizeTimeout.length.toString() +')', '600'));
}

function ResizeToFitBoundsDelayed(Idx){
	//alert(Idx);
	
	
	var Img1 = ResizeImg1[Idx];
	var MaxW = ResizeMaxW[Idx];
	var MaxH = ResizeMaxH[Idx];
	
	
	var Img = new Object();
	Img.src = Img1.src;
	var imgAspect = Img1.width / Img1.height;
	var newAspect = MaxW / MaxH;
	
	//alert(imgAspect.toString() + ' to ' + newAspect.toString());
	//return true;
	//image is proportional
	if(imgAspect == newAspect){
		Img.width = MaxW;
		Img.height = MaxH;
	}

	if (imgAspect > newAspect){
		//bound by width
		Img.height = (MaxW * Img1.height) / Img1.width;
		Img.width = MaxW;
	}else{
		//bound by height
		Img.width = (MaxH * Img1.width) / Img1.height;
		Img.height = MaxH;
	}
	
	if (isNaN(Img.width)|| isNaN(Img.height)){
	
	}else{
	Img1.width = Img.width;
	Img1.height = Img.height;
	clearInterval(ResizeTimeout[Idx]);
	//alert('cleared ' + Img.width.toString() + ' x ' + Img.height.toString());
	}
}

function AddToModifierData(ModifierData, TypeID, ModifierID){
	if(ModifierData['type:' + TypeID.toString()] == null){
		ModifierData.push('type:' + TypeID.toString()) ;
		ModifierData['type:' + TypeID.toString()] = new Array();
	}

	ModifierData['type:' + TypeID.toString()].push(ModifierID);
}

function GetModifierCombos(ModifierData, TypeIndex, Prepend, aryOut){
	if (ModifierData[ModifierData[TypeIndex]] == null) return false;
	if(aryOut == null) aryOut = new Array();

	if(TypeIndex == ModifierData.length - 1){
		for(var x = 0;x<ModifierData[ModifierData[TypeIndex]].length;x++){
			//alert(Prepend + ModifierData[ModifierData[TypeIndex]][x].toString());
			if(aryOut['dat' + Prepend + ModifierData[ModifierData[TypeIndex]][x].toString()] == null){
				aryOut['dat' + Prepend + ModifierData[ModifierData[TypeIndex]][x].toString()] = true;
				aryOut.push(Prepend + ModifierData[ModifierData[TypeIndex]][x].toString());
			}
		}
	}else{
		for(var x = 0;x<ModifierData[ModifierData[TypeIndex]].length;x++){
			GetModifierCombos(ModifierData, TypeIndex + 1, Prepend + ModifierData[ModifierData[TypeIndex]][x].toString() + ',', aryOut);
		}
	}
}

function SortString(strText){
var ar;
	ar = strText.split(",");
	ar.sort();
	
	return ar.join(",");
}

//this was added in for adding list items.  currently booleans will not work correctly, so boolean datatypes are not allowed
function COMttSelect(tag, aryTypes, selectedID, formName, tagName, aryDisplay)
{
	//!!
	//!tag CANNOT EQUAL tagName!
	//!!
	try
	{
		var strSelect = '<select name=\"' + tagName + '\" id=\"' + tagName + '\">';
		tag = GetTag(tag);

		var SEL = document.createElement('select');
		var OPT = null;

		SEL.id = tagName;
		SEL.name = tagName;
		if(arguments[5])
		{
			for(var i = 0; i < aryDisplay.length; i++)
			{
				if(aryDisplay[i][0].toString().toLowerCase() != 'boolean')
				{
					OPT = document.createElement('option');
					OPT.value = aryDisplay[i][1];
					OPT.appendChild(document.createTextNode(aryDisplay[i][0]));
					SEL.appendChild(OPT);
          			}
			}
		}
		for(var i = 0; i < aryTypes.length; i++)
		{
			if(aryTypes[i][0].toString().toLowerCase() != 'boolean')
			{
				OPT = document.createElement('option');
				OPT.value = aryTypes[i][1];
				OPT.appendChild(document.createTextNode(aryTypes[i][0]));

				if(aryTypes[i][1] == selectedID)
				{
					OPT.selected = true;
				}

				SEL.appendChild(OPT);
			}
		}
	}
	catch(er){}
	tag.appendChild(SEL);
	return SEL;
}

function QtyPriceBreak(Qty, IsPercent, Delta){
	this.Qty = Qty;
	this.IsPercent = IsPercent;
	this.Delta = Delta;
}

function QtyPriceStruct(){
	this.Breaks = new Array();
	this.Qtys = new Array();
}

QtyPriceStruct.prototype.addBreak = function(Qty, isPercent, Delta){
	this.Breaks[this.Breaks.length] = new QtyPriceBreak(Qty, isPercent, Delta);
	if(this.Qtys[Qty] == null){
		this.Qtys[Qty] = this.Breaks[this.Breaks.length - 1];
	}else{
		if(this.Qtys[Qty].Delta < Delta)
			this.Qtys[Qty] = this.Breaks[this.Breaks.length];
	}
	
}

QtyPriceStruct.prototype.toString = function(BasePrice){
	
	var out = '';
	var isEven = true;
	var sClass;
	this.Breaks.sort(sortQtyPriceBreaks);
	
	try{
		if(this.Qtys.length > 0)
		{
			out += '<table width="95%" border=0 cellpadding=3 cellspacing=0 class="TableWithBorder"><tbody class="Primary">';
			out += '<tr><td align=center colspan=2 class="SecondaryBoldText">Price Breaks</td></tr>';
			out += '<tr><td class="Primary">Min. Qty</td><td class="Primary">Discount Price</td></tr>';
			for(var i=0; i<this.Breaks.length; i++){
				window.status += 'a' + this.Breaks.length;
				sClass = (isEven?'GridRowEven':'GridRowOdd')
				out += '<tr><td class="' + sClass + '">' + this.Breaks[i].Qty + '</td><td class="' + sClass + '">' + this.Breaks[i].toString(BasePrice) + '</td></tr>';
				isEven = !isEven;
			}
			out += '</tbody></table>';
		}
	}
	catch(e){}
	return out;
}

QtyPriceStruct.prototype.getBreak = function(Qty){
	if(this.Breaks.length == 0) return null;
	var i = 0;
	//if(Qty == 1000) throw 'holla!';
	while((i < this.Breaks.length) && (this.Breaks[i].Qty <= Qty)){
		i++;
	}
	if(i == this.Breaks.length && this.Breaks[i-1].Qty <= Qty) return this.Qtys[this.Breaks[i-1].Qty];
	if ((i == 0)|| i == this.Breaks.length) return null; //no discount found
	i--;
	//alert(this.Breaks[i].Qty);
	return this.Qtys[this.Breaks[i].Qty];
}

QtyPriceBreak.prototype.toString = function(BasePrice){
	if (BasePrice){
		
	}else{
		BasePrice = 0;
	}
	var tmpStr = "$";
	
	if(!this.IsPercent) {
		
		tmpStr += (BasePrice - this.Delta).toFixed(2);
		tmpStr += " ea.";
	} else {
		tmpStr += (BasePrice - (BasePrice * (this.Delta * .01))).toFixed(2);
		tmpStr += " (" + this.Delta + "% off)";
	}
	
	return tmpStr;
}

QtyPriceBreak.prototype.getDiscountedPrice = function(Price){
	if(this.IsPercent){
		return Price - (Price * (this.Delta * .01));
	}else{
		return Price - this.Delta;
	}
}

function sortQtyPriceBreaks(a,b)
{
	if(parseInt(a.Qty) > parseInt(b.Qty)) return 1;
	else if(parseInt(a.Qty) < parseInt(b.Qty)) return -1;
	else return 0;
}

function DisplayPreview(src, w, h, AC){
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

if(src == "../vlimages/pixel.gif"){
alert("No Media Selected for this Image");
return false;
}

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = false;

if(AC != null){AutoClose = AC;}

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+w+',height='+h+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=' + w + ',height=' + h + ',left='+PositionX+',top='+PositionY;
var prvWin = null;
if (AutoClose) {if(prvWin != null) {prvWin.close();}}
if (isNN){prvWin=window.open('about:blank','',optNN);}
if (isIE){prvWin=window.open('about:blank','',optIE);}
with (prvWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(' + w + ',' + h + ');');
writeln('width=' + w + ';');
writeln('height=' + h + ' + 20;');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=' + w + ';');writeln('window.innerHeight=' + h + ';}}');
writeln('function doTitle(){document.title="Preview Window";}');writeln('</sc'+'ript>');
writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
writeln('<EMBED name="George" src='+src+' border=0 width=' + w + ' height=' + h + '><div align="right"><a href="javascript: window.close();" STYLE="font-size:12;color:#555555;">close window</a></div></body></html>');
close();		
}


}

function SelectOption(SelectID, OptionValue)
{
    var sel = GetTag(SelectID);

    for(var i = 0; i < sel.options.length;i++)
	    if (sel.options[i].value == OptionValue)
		    sel.options[i].selected = true;
	    else
		    sel.options[i].selected = false;
}
