
<!--
var webApplication = "/Blake";

function UpdateQuantitiesTotal(currentBox, totalQuantityId)
{
	if(isNaN(parseInt(currentBox.value, 10)))
		currentBox.value = 0;
		
	var totalQuantity = 0;
	var textBoxes = document.body.getElementsByTagName("INPUT");
	for(i=0; i<textBoxes.length; i++)
	{
		if(textBoxes[i].type == "text" && (!isNaN(parseInt(textBoxes[i].value, 10))))
			totalQuantity = totalQuantity + parseInt(textBoxes[i].value, 10);
	}
	
	document.getElementById(totalQuantityId).innerHTML = totalQuantity;
}

function UpdateQuantityTotal(totalQuantityId)
{
	var totalQuantity = 0;
	var textBoxes = document.body.getElementsByTagName("INPUT");
	for(i=0; i<textBoxes.length; i++)
	{
		if(textBoxes[i].type == "text" && (!isNaN(parseInt(textBoxes[i].value, 10))))
			totalQuantity = totalQuantity + parseInt(textBoxes[i].value, 10);
	}
	
	document.getElementById(totalQuantityId).innerHTML = totalQuantity;
}


function ShowShipAfterCalendar(sourcePage)
{
	ShowPopUp("http://stores.colorworkspromotions.com/blake/Checkout/Calendar.aspx?srcPg=" + sourcePage, "300", "200", true);
}

function ClosePopUp(sourcePage)
{
	window.opener.location = sourcePage;
	window.close();
}

function CloseShipAfterCalendar(sourcePage)
{
	window.opener.location = sourcePage;
	window.close();
}

function ShowSubscriptionCalendar(sourcePage)
{
	ShowPopUp("http://stores.colorworkspromotions.com/blake/SubscriptionCalendar.aspx?srcPg=" + sourcePage, "300", "200", true);
}

function CloseSubscriptionCalendar(sourcePage)
{
	window.opener.location = sourcePage;
	window.close();
}

function ShowPopUp(url, width, height, scroll)
{
	if(scroll == true)
		scroll = "yes";
	if(scroll == false)
		scroll = "no";
		
	window.open(url, null, "status=no," +
							"toolbar=no," +
							"menubar=no," +
							"resizable=yes," +
							"directories=no," +
							"location=no," +
							"scrollbars=" + scroll + "," +
							"width=" + width +
							",height=" + height);
	
}

function ShowPopUpCurrentSize(url, scroll)
{
    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion)>3) 
    {
        if (navigator.appName=="Netscape") 
        {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) 
        {
            winW = document.body.offsetWidth;
            winH = document.body.offsetHeight + 200;
        }
    }
    
    ShowPopUp(url, winW, winH, scroll);
}

function ChangeImage(image, picture)
{
	if(typeof(image) == "string")
		image = document.getElementById(image);

	image.src = picture;
}

function PreloadImages()
{
	var d = document;
	
	if(d.images){
		if(!d.pageImages) d.pageImages = new Array();
		
		var i, j = d.pageImages.length, a = PreloadImages.arguments; 
		
		for(i = 0; i < a.length; i++)
			if (a[i].indexOf("#")!=0){ 
				d.pageImages[j]=new Image; 
				d.pageImages[j++].src = a[i];
			}
	}
}

function GetScreenResolution()
{
	var res = "&res=" + screen.width;
	location = "banner.aspx?action=set" + res;
}

function ResetOrder()
{
	var textBoxes = document.body.getElementsByTagName("INPUT");
	for(i=0; i<textBoxes.length; i++)
	{
		if(textBoxes[i].type == "text" && parseInt(textBoxes[i].value) > 0)
		{
			textBoxes[i].value = "0";
		}
	}
}

function ChangeCategory(category)
{
	var currentLocation = '' + top.location;
	
	top.location = AppendQueryString(FindRootURL(FindRootURL(currentLocation, "subcategory="), "category="), 'category=' + category);
}

function ChangeSubcategory(subcategory)
{
	var currentLocation = '' + top.location;
	
	top.location = AppendQueryString(FindRootURL(currentLocation, "subcategory="), 'subcategory=' + subcategory);
}

function ChangeUDF(field, value)
{
	var currentLocation = '' + top.location;
	
	top.location = AppendQueryString(FindRootURL(currentLocation, field + '='), field + '=' + value);
}

function FindRootURL(currentLocation, search)
{
	var currentSearchIndex = currentLocation.indexOf(search);
	
	if (currentSearchIndex > 0)
	{
		var nextQueryStringIndex = currentLocation.indexOf("&", currentSearchIndex);

		if (nextQueryStringIndex >= 0)
		{
		    if (currentLocation.indexOf("&") < nextQueryStringIndex)
		        currentLocation = currentLocation.substring(0, currentSearchIndex - 1) + currentLocation.substring(nextQueryStringIndex);
		    else
			    currentLocation = currentLocation.substring(0, currentSearchIndex - 1) + '?' + currentLocation.substring(nextQueryStringIndex + 1);
	    }
		else
			currentLocation = currentLocation.substring(0, currentSearchIndex - 1);
			
		if (currentLocation.indexOf("?") == currentLocation.length - 1)
			currentLocation = currentLocation.substring(0, currentLocation.length - 1);
		
		if (currentLocation.indexOf("&") == currentLocation.length - 1)
			currentLocation = currentLocation.substring(0, currentLocation.length - 1);
	}
	
	return currentLocation;
}

function AppendQueryString(URL, append)
{
	if (URL.indexOf("?") > 0)
		return URL + "&" + append;
	else
		return URL + "?" + append;
}

function MaskQueryString(querystring)
{
    return querystring.replace(/\?/g, "%3f").replace(/=/g, "%3d").replace(/&/g, "%26").replace("/", "%2f")
}

function CopyArray(a)
{
	var newArray = new Array(a.length);
	
	for (var i = 0; i < a.length; i++)
		newArray[i] = a[i];
		
	return newArray;	
}

function Composite(dimA, dimB)
{
	this.DimA = dimA;
	this.DimB = dimB;
	this.SKU = undefined;
	this.CompositeName = undefined;
	this.AdditionalPrice = undefined;
	this.QuantityAvailable = undefined;
	this.ImageSource = undefined;
	this.ThumbSource = undefined;
}

function Composite(dimA, dimB, sku, compositeName, additionalPrice, qtyAvailable, imageSrc, thumbSrc)
{
	this.DimA = dimA;
	this.DimB = dimB;
	this.SKU = sku;
	this.CompositeName = compositeName;
	this.AdditionalPrice = additionalPrice;
	this.QuantityAvailable = qtyAvailable;
	this.ImageSource = imageSrc;
	this.ThumbSource = thumbSrc;
}

function DimensionValue(code, description, sequence, additionalPrice, imageSrc, thumbSrc)
{
	this.Code = code;
	this.Description = description;
	this.SortSequence = sequence;
	this.AdditionalPrice = additionalPrice;
	this.ImageSource = imageSrc;
	this.ThumbSource = thumbSrc;
}

function DimensionDefinition(code, label, ddl, sequence, field, position, length)
{
	this.Values = new Array();
	this.DDL = ddl;
	this.Code = code;
	this.Label = label;
	this.SortSequence = sequence;
	this.Field = field;
	this.Position = position;
	this.Length = length;
}

function SizeColor(code, field, position, length)
{
	this.Code = code;
	this.Field = field;
	this.Position = position;
	this.Length = length;
}

function HiddenDDL(item, isDimA)
{
    this.type = "hiddenDDL";
    this.selectedIndex = 0;
    var value = "";
    
    if (isDimA)
        value = item.Composites[0].DimA;
    else
        value = item.Composites[0].DimB;
        
    this.options = new Array();
    this.options[0] = new Option(value, value, true, true);
}

function CompareSizeColor(a, b)
{
	if (a.Field > b.Field)
		return -1;
	
	if (a.Field < b.Field)
		return 1;
		
	if (a.Field == b.Field && a.Position == b.Position)
		return 0;
	
	if (a.Position < b.Position)
		return -1;
	
	if (a.Position > b.Position)
		return 1;
	
	return 0;
}

SizeColor.prototype.Compare = CompareSizeColor;

function DimensionItem()
{
	this.DimensionDefinitions = new Array();
	this.Composites = new Array();
}

function ChangeSelectedImage(item, image, dimensionIndex)
{
	if (image)
	{
		//First try to set the composite image...If we can't then we'll use the last changed dimension definition
		var composite = GenerateComposite(item);
		
		for (var i = 0; i < item.Composites.length; i++)
			if (composite.DimA == item.Composites[i].DimA && composite.DimB == item.Composites[i].DimB)
				composite = item.Composites[i];
		
		if (composite != null && composite.ImageSource != null && composite.ImageSource != '' && composite.ImageSource != '&nbsp;')
		{
			image.src = composite.ImageSource;
		}
		else
		{
			for (var i = 0; i < item.DimensionDefinitions[dimensionIndex].Values.length; i++)
				if (item.DimensionDefinitions[dimensionIndex].DDL.options[item.DimensionDefinitions[dimensionIndex].DDL.selectedIndex].value == item.DimensionDefinitions[dimensionIndex].Values[i].Code)
					if (item.DimensionDefinitions[dimensionIndex].Values[i].ImageSource != null && item.DimensionDefinitions[dimensionIndex].Values[i].ImageSource != '' && item.DimensionDefinitions[dimensionIndex].Values[i].ImageSource != '&nbsp;')
					{
						image.src = item.DimensionDefinitions[dimensionIndex].Values[i].ImageSource;
					}
		}
	}
}

function ChangeSelectedDimension(item, dimensionIndex, code)
{
	for (var i = 0; i < item.DimensionDefinitions[dimensionIndex].DDL.options.length; i++)
		item.DimensionDefinitions[dimensionIndex].DDL.options[i].selected = (item.DimensionDefinitions[dimensionIndex].DDL.options[i].value == code);
}

function LoadDefaultDimensionDefinitions(item, dimensionIndex)
{
	var selectedValue = item.DimensionDefinitions[dimensionIndex].DDL.options[item.DimensionDefinitions[dimensionIndex].DDL.selectedIndex].value;
	
	//Load all available options for the dimension index
	item.DimensionDefinitions[dimensionIndex].DDL.options.length = 0;
	
	for (var i = 0; i < item.DimensionDefinitions[dimensionIndex].Values.length; i++)
	{
		item.DimensionDefinitions[dimensionIndex].DDL.options[i] = new Option(item.DimensionDefinitions[dimensionIndex].Values[i].Description, item.DimensionDefinitions[dimensionIndex].Values[i].Code, false, (selectedValue == item.DimensionDefinitions[dimensionIndex].Values[i].Code));
	}
}

function CheckDimensions(item, dimensionIndex)
{
	var selectedValues = new Array(item.DimensionDefinitions.length);
	
	for (var i = 0; i < item.DimensionDefinitions.length; i++)
		selectedValues[i] = item.DimensionDefinitions[i].DDL.options[item.DimensionDefinitions[i].DDL.selectedIndex].value;
	
	if (item.DimensionDefinitions[dimensionIndex].DDL.options.length < item.DimensionDefinitions[dimensionIndex].Values.length)	
		LoadDefaultDimensionDefinitions(item, dimensionIndex);
	
	for (var i = 0; i < item.DimensionDefinitions.length; i++)
	{
		if (i != dimensionIndex)
		{
			//Create our size / color arrays
			var sizes = new Array();
			var colors = new Array();
			var options = new Array();
			
			//Go through each of other lists and see what's available in this list based on what's selected in the others
			for (var j = 0; j < item.DimensionDefinitions.length; j++)
			{
				if (j != i)
				{
					var def = item.DimensionDefinitions[j];
					
					if (def.DDL.options.selectedIndex >= 0)
					{
						var sc = new SizeColor(def.DDL.options[def.DDL.options.selectedIndex].value, def.Field, def.Position, def.Length);
						
						if (sc.Field.toUpperCase() == "S")
							sizes[sizes.length] = sc;
						else
							colors[colors.length] = sc;
					}
					else
					{
						//Nothing defined for this combination.  Give a message and reload everything here.
						alert('This combination is not available.  Please choose another combination.');
						
						//Load all available options for the dimension index
						item.DimensionDefinitions[j].DDL.options.length = 0;
						
						for (var k = 0; k < item.DimensionDefinitions[j].Values.length; k++)
						{
							item.DimensionDefinitions[j].DDL.options[k] = new Option(item.DimensionDefinitions[j].Values[k].Description, item.DimensionDefinitions[j].Values[k].Code, false, (selectedValues[j] == item.DimensionDefinitions[j].Values[k].Code));
						}
						
						CheckDimensions(item, j);
						return;
					}
				}
			}
			
			for (var j = 0; j < item.DimensionDefinitions[i].Values.length; j++)
			{
				var currentSizes = CopyArray(sizes);
				var currentColors = CopyArray(colors);
				
				var def = item.DimensionDefinitions[i];
				var sc = new SizeColor(def.Values[j].Code, def.Field, def.Position, def.Length);
				
				if (sc.Field.toUpperCase() == "S")
					currentSizes[currentSizes.length] = sc;
				else
					currentColors[currentColors.length] = sc;
					
				var currentSizeCode = GetDimensionCode(currentSizes);
				var currentColorCode = GetDimensionCode(currentColors);
				
				for (var k = 0; k < item.Composites.length; k++)
				{
					var currentComposite = item.Composites[k];
					
					if (currentComposite.DimA == currentSizeCode && currentComposite.DimB == currentColorCode)
					{
						options[options.length] = new Option(item.DimensionDefinitions[i].Values[j].Description, item.DimensionDefinitions[i].Values[j].Code, false, (selectedValues[i] == item.DimensionDefinitions[i].Values[j].Code))
					}
				}
			}
			
			item.DimensionDefinitions[i].DDL.options.length = 0;
			
			for (var j = 0; j < options.length; j++)
			{
				item.DimensionDefinitions[i].DDL.options[j] = options[j];
			}
		}
	}
}

function GetDimensionCode(dimensionCodes)
{
	var dimensionCode = "";
	
	dimensionCodes.sort(CompareSizeColor);
	
	for (var i = 0; i < dimensionCodes.length; i++)
	{
		var currentCode = dimensionCodes[i].Code;
		
		while (currentCode.length < dimensionCodes[i].Length)
		{
			currentCode = currentCode.concat(" ");
		}
		
		dimensionCode = dimensionCode.concat(currentCode);
	}
	
	while (dimensionCode.length < 4)
	{
		dimensionCode = dimensionCode.concat(" ");
	}
	
	return dimensionCode;
}

function GenerateComposite(item)
{
	var sizes = new Array();
	var colors = new Array();
	
	
	for (var i = 0; i < item.DimensionDefinitions.length; i++)
	{
		var def = item.DimensionDefinitions[i];		
		var sc;
		
		if (def.DDL.type == "hiddenDDL")
		{
		    sc = new SizeColor(def.DDL.options[0].value, def.Field, def.Position, def.Length);
		}
		else
		{
		    sc = new SizeColor(def.DDL.options[def.DDL.options.selectedIndex].value, def.Field, def.Position, def.Length);
		}
		
		if (sc.Field.toUpperCase() == "S")
			sizes[sizes.length] = sc;
		else
			colors[colors.length] = sc;
	}
	
	var sizeCode = GetDimensionCode(sizes);
	var colorCode = GetDimensionCode(colors);
	
	return new Composite(sizeCode, colorCode);
}


//-->
