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;}
}



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;
	this.UPC = '';
	this.HasUpload = false;
	this.inStockMessage = 'In Stock.';
	this.outOfStockMessage = 'NO - On Backorder.';
}

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();
var aModData = new Array();

function AddToItemData(ItemData, ModID, ModName, ModAddDesc, ModTypeName, ModBriefDesc, Price, ItemCode, Onhand, Methods, Backorder, ItemID, ItemConcurrencyID, ItemImage, ModOneTime, UniqueImages, ModImage, ModHasUpload, ItemHasUpload, ItemUPC, ModDesc)
{

	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 sItemUPC = '', bItemUpload = false;
	var ModifierData = new Object();
	
	ModifierData.ID = ModID;
	ModifierData.Name = ModName;
	ModifierData.AddDesc = ModAddDesc;
	ModifierData.IsInventory = ModBriefDesc;
	ModifierData.Price = Price;
    ModifierData.OneTime = false;
    ModifierData.ModImage = '';
    ModifierData.HasUniqueImages = false;
    ModifierData.HasUpload = false;
    ModifierData.Description = '';
	
	switch(arguments.length)
	{
	    case 21: ModifierData.Description = ModDesc;
	    case 20: sItemUPC = ItemUPC;
	    case 19: bItemUpload = ItemHasUpload;
	    case 18: ModifierData.HasUpload = ModHasUpload;
	    case 17: ModifierData.ModImage = ModImage;
	    case 16: ModifierData.HasUniqueImages = UniqueImages;
	    case 15: 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 has an image associated with it
	if(Boolean(UniqueImages)) {
		AddToModifierData(aModData, ModTypeName, ModID);
	}
	
	//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[ItemCode1].HasUpload = bItemUpload;
		ItemData[ItemCode1].UPC = sItemUPC;
		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) +')':'');
		
		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 + Delim + Modifiers[i].HasUpload + '">' + 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 typName = TypeName.replace(re,'');
	typName = typName.replace("'","");
	
	var SelData = '<Select class="comProdDropDown" id="COM'+typName.replace(' ','')+'" 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) +')':'');

		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 + Delim + Modifiers[i].HasUpload + '">' + 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 + Delim + Modifiers[i].HasUpload + '"/>';

	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 onfocus="this.touched = \'true\';if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';" touched="false" maxlength=210 type="text" id="AddDesc' + TypeName + ProductID + '" name="AddDesc' + TypeName + ProductID + '" value="&lt;'+ TypeName +'&gt;"';
		Reg = new RegExp("Email", "gi");
		Between += ' onfocus="if (this.value == \'&lt;'+ TypeName +'&gt;\') this.value=\'\';">&nbsp;';
		    if(Reg.test(TypeName)){
			    Between += '&nbsp;<div style="padding-top:2px;padding-bottom:2px;font-weight:bold;">Please re-type recipient email!</div>&nbsp;<input type="text" maxlength="210" value="<Confirm Email>" id="ConfirmEmail' + TypeName + ProductID + '" onblur="compareEmails(\'AddDesc' + TypeName + ProductID + '\',this);">';
		    }
		}
		document.write('<input type="hidden" name="AddDescNames' + ProductID + '" value="' + TypeName + '"/>');
	}
	var out = '';
		if(AddDesc){
		//alert(AddDescHidden);
		out = '<tr><td valign="top">' + 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 compareEmails(OrigEmail,tag)
{
    var eml = document.getElementById(OrigEmail).value;

	if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(eml)){
		//do nothing
	}else{
		alert('Invalid email address.');
		//tag.focus();
		try { document.getElementById("addtocartBT").disabled = true; } catch(e) {}
		return false;
	}    
	if(tag.value != eml){
		alert('email addresses don\'t match, please check and try again.');
		tag.focus();
        try { document.getElementById("addtocartBT").disabled = true; } catch(e) {}
        tag.style.backgroundColor = "#FEFBB4";	
		return false;
	}
        
    try { document.getElementById("addtocartBT").disabled = false; } catch(e) {}
    tag.style.backgroundColor = "#FFFFFF";	
        	
}

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 GetModifierIDCombosForImages()
{
	var ary = new Array();
	
	GetModifierCombos(aModData, 0, '', ary);
	
	return ary;
}

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;
}

//this function replaces the contents of an element with
//the appropriate element to submit an action.
function ReplaceButton(which, action)
{
	var out = span = '';
	
	//alert(action);
	
	switch(which.toLowerCase())
	{
	case 'addtocart':
		out = '<input class="FormButtons COMProdButton" id="addtocartBT" type="button" value="Add to Cart" onclick="' + action + '">';
		span = 'COMCartSpan';
	break;
	case 'goback':
		out = '<input class="FormButtons COMProdButton" type="button" value="Go Back" onclick="' + action + '">'
		span = 'COMBackSpan';
	break;
	case 'search':
		out = '<input class="FormButtons" type="button" value="Search" onclick="' + action + '">'
		span = 'COMSearchSpan';
	break;
	case 'clearcart':
		out = '<input class="FormButtons" type="button" value="Clear Cart" id="Cancel" onclick="' + action + '">';
		span = 'COMClearCSpan';
	break;
	case 'checkout':
		out = '<input class="FormButtons" type="button" value="Check Out" onclick="' + action + '">';
		span = 'COMCheckoutSpan';
	break;
	case 'cshopping':
		out = '<br><br><input class="FormButtons" type="button" value="Continue Shopping" onclick="' + action + '">';
		span = 'COMConShopSpan';
	break;	
	}
	
	GetTag(span).innerHTML = out;
}

function ClearCart(PageID,ShopID)
{
	var confirmed = confirm('Click "OK" to Clear your Cart.');
	
	if(confirmed)
	{
		var outstr = '';
		
		outstr += '<form action="/content/' + PageID + '.htm" method="get" name="CartForm" id="CartForm">';
		outstr += '<input type="hidden" name="ShopID" value="' + ShopID + '">';
		outstr += '<input type="hidden" name="ClearCart" value="TRUE">';
		outstr += '</form>';
		
		document.body.innerHTML += outstr;
		GetTag('CartForm').submit();
	}
}

//////////////////////////////////////////////////////////////////////////////
// added 1/2007 to draw out quick order table to prod script

//// updated 3/13

var QuickOptions = new Array();

    function DrawModifierQuickTable(ProductID, ItemData, onChange, Between, Spacer,prodINFO,imageClick)
    {
        var Modifiers = ItemData['Modifiers'];
        var aDimension1;
        var aDimension2;
        var tempDim;
        
        var outDiv = '';
        var comma;
        var re = /,/gi;	
        var Delim = String.fromCharCode(28);
        var TypeName;
        var cTypeName;
        
	    //get all dimensions (modifier Type names: size, color, etc...)
	    switch(Modifiers.length){
    	
	    //0 dimensions - easy
	    case 0:
	    outDiv += '<table class="TableWithBorder"><tr>';
			        outDiv += '<td align=center><input type="textbox" style="width:25px;" value="0" id="Qtyprod_0" name="Qtyprod_0"';
	        outDiv += 'onclick='+onChange+' onkeyup='+onChange+' onchange='+onChange+' />';
	        outDiv += '<input type="hidden" id="ProductItemprod_0" name="ProductItemprod_0" value="'+prodINFO[0]+'" />';
	        outDiv += '<input type="hidden" id="PartNoprod_0" name="PartNoprod_'+0+'" value="'+prodINFO[1]+'" />';
	        outDiv += '<input type="hidden" id="ProductTaxableprod_0" name="ProductTaxableprod_0" value="'+prodINFO[2]+'" />';
	        outDiv += '<input type="hidden" id="ProductWeightprod_0" name="ProductWeightprod_0" value="'+prodINFO[3]+'" />';
            outDiv += '<input type="hidden" id="ProductDescriptionprod_0" name="ProductDescriptionprod_0" value="'+prodINFO[4]+'" />';					    
            outDiv += '<input type="hidden" id="ProductBasePriceprod_0" name="ProductBasePriceprod_0" value="'+prodINFO[5]+'" />';
            outDiv += '<input type="hidden" id="ProductPageIDprod_0" name="ProductPageIDprod_0" value="'+prodINFO[6]+'" />';					                            
            outDiv += '<input type="hidden" id="ProductIDprod_0" name="ProductIDprod_0" value="'+ProductID+'" />';
            outDiv += '<input type="hidden" id="ProductItemID_0" name="ItemID" value="_0" />';						                            
            outDiv += '<input type="hidden" id="AddProd_0" name="AddProd_0" value="TRUE" />';
	        outDiv += '</td>';
	    outDiv += '</tr></table>';
	    AddToQuickOrderProduct('Qtyprod-0-'+ProductID,0,'','',0,0,0)
	    break;	
    	
	    //1 dimension - not as easy
	    case 1:
	    var d1Count = 0;
	        aDimension1 = Modifiers[Modifiers[0]];
		    outDiv += '<table class="MultiOrderTable" >';

		    for(var i = 0; i < aDimension1.length; i++){
		        if (Modifiers[0] == 'Color')
		        {outDiv += '<tr><td class="SecondaryBoldText"><a class="imgColorLinks" href="javascript:changeAttrImage(\''+ProductID+'_'+aDimension1[i].ID+'\');" title="View Image">' + aDimension1[i].Name + '</a></td>';}
		        else
		        {outDiv += '<tr><td class="SecondaryBoldText">' + aDimension1[i].Name + '</td>';}
					    outDiv += '<td align=center><input type="textbox" style="width:25px;" value="0" id="Qtyprod_'+d1Count+'" name="Qtyprod_'+d1Count+'"';
					    outDiv += 'onclick='+onChange+' onkeyup='+onChange+' onchange='+onChange+' />';
					    outDiv += '<input type="hidden" id="ProductItemprod_'+d1Count+'" name="ProductItemprod_'+d1Count+'" value="'+prodINFO[0]+'" />';
					    outDiv += '<input type="hidden" id="PartNoprod_'+d1Count+'" name="PartNoprod_'+d1Count+'" value="'+prodINFO[1]+'" />';
					    outDiv += '<input type="hidden" id="ProductTaxableprod_'+d1Count+'" name="ProductTaxableprod_'+d1Count+'" value="'+prodINFO[2]+'" />';
					    outDiv += '<input type="hidden" id="ProductWeightprod_'+d1Count+'" name="ProductWeightprod_'+d1Count+'" value="'+prodINFO[3]+'" />';
                        outDiv += '<input type="hidden" id="ProductDescriptionprod_'+d1Count+'" name="ProductDescriptionprod_'+d1Count+'" value=\''+prodINFO[4]+'\' />';					    
                        outDiv += '<input type="hidden" id="ProductBasePriceprod_'+d1Count+'" name="ProductBasePriceprod_'+d1Count+'" value="'+prodINFO[5]+'" />';
                        outDiv += '<input type="hidden" id="ProductPageIDprod_'+d1Count+'" name="ProductPageIDprod_'+d1Count+'" value="'+prodINFO[6]+'" />';					                            
                        outDiv += '<input type="hidden" id="ProductIDprod_'+d1Count+'" name="ProductIDprod_'+d1Count+'" value="'+ProductID+'" />';
                        outDiv += '<input type="hidden" id="ProductItemID_'+d1Count+'" name="ItemID" value="_'+d1Count+'" />';						                            
                        outDiv += '<input type="hidden" id="AddProd_'+d1Count+'" name="AddProd_'+d1Count+'" value="TRUE" />';
                        outDiv += '<input type="hidden" id="ProductPropprod_'+d1Count+'" name="ProductPropprod_'+d1Count+'" value="'+aDimension1[i].Name.toString().replace(re, '') + Delim + aDimension1[i].ID  + Delim + aDimension1[i].Price + Delim + aDimension1[i].AddDesc + Delim + TypeName + Delim + aDimension1[i].OneTime + Delim + aDimension1[i].HasUpload + '" />';
					    outDiv += '</td>';
			    outDiv += '</tr>';	
			    AddToQuickOrderProduct('Qtyprod-'+i+'-'+ProductID,0,aDimension1[i].Name,aDimension1[i].Price,'',aDimension1[i].ID,0,aDimension1[i].Price)
			    d1Count = d1Count + 1;		    
		    }
		    outDiv += '</table>';
	    break;	
    	
    	
	    //2 dimensions - this sucks
	    case 2:
		    var d1Count = 0;
		    var d2Count = 0;
		    //color dimension should be down side for view images link to be seen
		    for(var i = 0; i < 2; i++){
		            if (Modifiers[i] == 'Color')
		            {
		                aDimension2 = Modifiers[Modifiers[i]];
		                cTypeName = 'Color';
		            }
		            else
		            {
		                aDimension1 = Modifiers[Modifiers[i]];
		                TypeName = Modifiers[i];
		            }
		        
		       // }
		    }
    		
    		outDiv += '<div>Click on a Color Name to View That Color\'s Image</div><BR>';
		    outDiv += '<table class="MultiOrderTable" cellpadding=2 cellspacing=2 width="100%"><tr><td class="SecondaryBoldText">&nbsp;</td>';
		    for(var i = 0; i < aDimension1.length; i++){
			    outDiv += '<td class="SecondaryBoldText" width="40px">' + aDimension1[i].Name + '</td>';
		    }
		    outDiv += '</tr>';
    		
    		
		    for(var i = 0; i < aDimension2.length; i++){
			    outDiv += '<tr>';
			    if (aDimension2[i].Price != 0 || aDimension2[i].Price != "")
			    { outDiv += '<td class="SecondaryBoldText"><a class="imgColorLinks" href="javascript:changeAttrImage(\''+ProductID+'_'+aDimension2[i].ID+'\');" title="View Image">' + aDimension2[i].Name + '</a>(Add '+formatCurrency(aDimension2[i].Price)+')</td>'; }
			    else {outDiv += '<td class="SecondaryBoldText"><a class="imgColorLinks" href="javascript:changeAttrImage(\''+ProductID+'_'+aDimension2[i].ID+'\');" title="View Image">' + aDimension2[i].Name + '</a></td>'; }
				    for(y = 0; y < aDimension1.length; y++){
				        d1Count = QuickOptions.length;
				        d2Count = d1Count + 1;
				        var drivetipTEXT;
				        drivetipTEXT = "";
				        var totalMarkup;
				        totalMarkup = 0;
				            if (aDimension2[i].Name != "")
				            { drivetipTEXT = aDimension2[i].Name + '<br>';   }
				            if (aDimension1[y].Name != "")
				            { drivetipTEXT = drivetipTEXT + aDimension1[y].Name + '<br>';   }				            
				            if (aDimension2[i].Price != 0 || aDimension2[i].Price != "" )
				            {
                                totalMarkup = aDimension2[i].Price;    				        
				            }
				            
				            if (aDimension1[y].Price != 0 || aDimension1[y].Price != "" )
				            {
                                totalMarkup = aDimension1[y].Price;    				        
				            }
				            
				            if (totalMarkup != 0) { drivetipTEXT = drivetipTEXT + 'Add Additional ' + formatCurrency(totalMarkup) + '<BR>'; }
				        if (drivetipTEXT != "")    
					    { outDiv += '<td align=center width="40px"><input type="textbox" onblur="hideddrivetip();" onFocus="ddrivetip(\''+drivetipTEXT+'\',\'yellow\', 120, this);" style="width:25px;" value="0" id="Qtyprod_'+d1Count+'" name="Qtyprod_'+d1Count+'"'; }
					    else { outDiv += '<td align=center width="40px"><input type="textbox" value="0" id="Qtyprod_'+d1Count+'" name="Qtyprod_'+d1Count+'"'; }
					    outDiv += 'onclick='+onChange+' onkeyup='+onChange+' onchange='+onChange+' />';
					    outDiv += '<input type="hidden" id="ProductItemprod_'+d1Count+'" name="ProductItemprod_'+d1Count+'" value="'+prodINFO[0]+'" />';
					    outDiv += '<input type="hidden" id="PartNoprod_'+d1Count+'" name="PartNoprod_'+d1Count+'" value="'+prodINFO[1]+'" />';
					    outDiv += '<input type="hidden" id="ProductTaxableprod_'+d1Count+'" name="ProductTaxableprod_'+d1Count+'" value="'+prodINFO[2]+'" />';
					    outDiv += '<input type="hidden" id="ProductWeightprod_'+d1Count+'" name="ProductWeightprod_'+d1Count+'" value="'+prodINFO[3]+'" />';
                        outDiv += '<input type="hidden" id="ProductDescriptionprod_'+d1Count+'" name="ProductDescriptionprod_'+d1Count+'" value="'+prodINFO[4]+'" />';					    
                        outDiv += '<input type="hidden" id="ProductBasePriceprod_'+d1Count+'" name="ProductBasePriceprod_'+d1Count+'" value="'+prodINFO[5]+'" />';
                        outDiv += '<input type="hidden" id="ProductPageIDprod_'+d1Count+'" name="ProductPageIDprod_'+d1Count+'" value="'+prodINFO[6]+'" />';					                            
                        outDiv += '<input type="hidden" id="ProductIDprod_'+d1Count+'" name="ProductIDprod_'+d1Count+'" value="'+ProductID+'" />';
                        outDiv += '<input type="hidden" id="ProductItemID_'+d1Count+'" name="ItemID" value="_'+d1Count+'" />';						                            
                        outDiv += '<input type="hidden" id="AddProd_'+d1Count+'" name="AddProd_'+d1Count+'" value="TRUE" />';
                        outDiv += '<input type="hidden" id="ProductPropprod_'+d1Count+'" name="ProductPropprod_'+d1Count+'" value="'+aDimension1[y].Name.toString().replace(re, '') + Delim + aDimension1[y].ID  + Delim + aDimension1[y].Price + Delim + aDimension1[y].AddDesc + Delim + TypeName + Delim + aDimension1[y].OneTime + Delim + aDimension1[y].HasUpload + '" />';                        
                        outDiv += '<input type="hidden" id="ProductPropprod_'+d1Count+'" name="ProductPropprod_'+d1Count+'" value="'+aDimension2[i].Name.toString().replace(re, '') + Delim + aDimension2[i].ID  + Delim + aDimension2[i].Price + Delim + aDimension2[i].AddDesc + Delim + cTypeName + Delim + aDimension2[i].OneTime + Delim + aDimension2[i].HasUpload + '" />';                                                
					    outDiv += '</td>';
					    AddToQuickOrderProduct('Qtyprod'+y+'-'+i+'-'+ProductID,0,aDimension2[i].Name,aDimension2[i].Price,aDimension1[y].Name,aDimension2[i].ID,aDimension1[y].ID,aDimension1[y].Price)
					} // end for y
			    outDiv += '</tr>';
			 } //end for i
			    //outDiv += '<td class="SecondaryBoldText">' + g_ModifierNames['lookup' + ItemModifiers[i]] + '</td>';
		    //}
    		
    	
		    //throw 'what?';
	    break;
    	
	    default:
	    alert('This script was not designed to work with products containing more than 2 dimensions of attributes.');
	    break;	        
    }// end switch
    
    GetTag('ProductModifiers' + ProductID).innerHTML = outDiv;
    
    }


function AddToQuickOrderProduct(ModID,CurQuant,Mod1Name,Mod1Price,Mod2Name,Mod1ID,Mod2ID,Price)
{

    var QuickProd = new Object();
	
	QuickProd.Qtyprod = ModID;
	QuickProd.Quant = CurQuant;
	QuickProd.Mod1 = Mod1Name;
	QuickProd.Mod2 = Mod2Name;
	QuickProd.Mod1ID = Mod1ID;
	QuickProd.Mod2ID = Mod2ID;
	QuickProd.Price = Price;
	QuickProd.Mod1Price = Mod1Price;
    //QuickProd.OneTime = false;
    //QuickProd.ModImage = '';
    //QuickProd.HasUniqueImages = false;
    //QuickProd.HasUpload = false;
    //QuickProd.Description = '';
    
    QuickOptions.push(QuickProd);
    //ModifierData['type:' + TypeID.toString()].push(ModifierID);

}

//////////////////////////////////////////////////////////////////////////////
