function Product (basenumber, list_price, pgc) {
	this.Basenumber = basenumber;
	this.List_Price = list_price;
	this.PGC = pgc;
}

function Variant (Size_Value, Color_Value, Color_Code, I, S, B, BD, Special_Handling, Kickback, PreOrder_Flag, Expected_Date) {
	this.I = I;
	this.Size_Value = Size_Value;
	this.Color_Value = Color_Value;
	this.Color_Code = Color_Code;
	this.S = S;
	this.B = B;
	this.BD = BD;
	this.Special_Handling = Special_Handling;
	this.Kickback = Kickback;
	this.P = PreOrder_Flag;
	this.Expected_Date = Expected_Date;

	this.setPricing = function (Base_Price, Loyalty_Price, Point_Cost) {
		this.Base_Price = Base_Price;
		this.Loyalty_Price = Loyalty_Price;
		this.Point_Cost = Point_Cost;
	}
}

/**
 * Size specific functions.
 */
function validate_size_menu()
{
	var size = null;
	var size_array = new Array();

	if(document.getElementById('size'))
	{
		var s_el = document.getElementById('size');
		size = (s_el.options[s_el.selectedIndex].value == '') ? null : s_el.options[s_el.selectedIndex].value;
	}

	s_el.length = 0;
	s_el.options[0] = new Option('Choose', '');

	for(var i in sProduct.Variants)
	{
		if(sProduct.Variants[i].I >= 1 || sProduct.Variants[i].B >= 1 || sProduct.Variants[i].S >= 1)
		{
			if(size_in_menu(s_el, sProduct.Variants[i].Size_Value_Id) === false){
				s_el.options[s_el.options.length] = new Option(sProduct.Variants[i].Size_Value, sProduct.Variants[i].Size_Value_Id);
			}
		}
	}
	// Sorting function call
	sortSelect(document.getElementById('size'));
}

function size_in_menu(size_object, size)
{
	for(var i=0; i < size_object.options.length; i++)
	{
		if(size_object.options[i].value == size){
			return true;
		}
	}
	return false;
}

// size drop-down sort function - ascending (case-insensitive)
function sortFuncAsc(record1, record2) {
     var value1 	= record1.optText.toLowerCase();
     var value2 	= record2.optText.toLowerCase();

	 // This keeps choose at the top
     if(value1 === 'choose') return(-1);
     if(value2 === 'choose') return(1);
     
     // Lets handle letter sizes i.e s, m, l
     // basically converting the sizes into a numeric that
     // evaluates to the order we would like them to appear
     var sizeText	= new Array('yxs', 'ys', 'ym', 'yl', 'yxl', 'xs', 's', 'm', 'l', 'xl', 'xxl', 'xxxl', '3xl');
     var tempValue1	= new String(value1);
     var tempValue2	= new String(value2);
     var matchLetters	= new RegExp(/[a-z]+/);
     
     var resultSizeVal1	= tempValue1.match(matchLetters);
     var resultSizeVal2	= tempValue2.match(matchLetters);
     
     if(resultSizeVal1) {
     	for( var abc = 0; abc <= sizeText.length; abc++)
     		if(value1 == sizeText[abc]) value1 = abc; 
     }
	 if(resultSizeVal2) {
     	for( var abc = 0; abc <= sizeText.length; abc++)
     		if(value2 == sizeText[abc]) value2 = abc; 
     }

	 // get the length of each value for padding purposes
     var len_value1 	= value1.length;
     var len_value2 	= value2.length;
	 // this makes sure the numbers actually compare correctly
	 // since jscript isnt recognizing them as actual numbers
	 // basically padding the string so that the digits line up
     if(len_value1 < len_value2) {
     	for( var x = len_value1; x < len_value2; x++) 
     		value1 = ' ' + value1;
     }
     if(len_value2 < len_value1) {
     	for( var x = len_value2; x < len_value1; x++)
     		value2 = ' ' + value2;
     }

	 // makes sure that half sizes line up with the matching
	 // whole size
	 var tempValue1a	= new String(value1);
	 var tempValue2a	= new String(value2);
	 var matchHalf	= new RegExp(/\.5/);
	 var resultHalfVal1	= tempValue1a.match(matchHalf);	
	 var resultHalfVal2	= tempValue2a.match(matchHalf);	
 
	if(resultHalfVal1) {
     	value1 = '  ' + value1.replace(/\.5/, '');
     	// need to see if value 2 is a half size too
     	if(tempValue2a.match(/\.5/)) value2 = '  ' + value2.replace(/\.5/, '');
     	if(value1 >= value2) return(1);
     	if(value1 <  value2) return(-1);
     }
     
     if(resultHalfVal2) {
     	value2 = '  ' + value2.replace(/\.5/, '');
     	// need to see if value 1 is a half size too
    	if(tempValue1a.match(/\.5/)) value1 = '  ' + value1.replace(/\.5/, '');
      	if(value2 >= value1) return(-1);
     	if(value2 <  value1) return(1);
     }
    
    // if we make it here, just flat out compare them
    if (value1 > value2) return(1);
    if (value1 < value2) return(-1);
    return(0);
}

function sortSelect(selectToSort) {
    // copy options into an array
    var myOptions = [];
    for (var loop=0; loop<selectToSort.options.length; loop++) {
		myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
    }

    myOptions.sort(sortFuncAsc);

    // copy sorted options from array back to select box
    selectToSort.options.length = 0;
    for (var loop=0; loop<myOptions.length; loop++) {
        var optObj = document.createElement('option');
        optObj.text = myOptions[loop].optText;
        optObj.value = myOptions[loop].optValue;
		selectToSort.options[selectToSort.options.length] = new Option(optObj.text, optObj.value);
    }
}
// End Size Sort functions

/**
 * Color specific functions
 */
function update_image(basenumber)
{
	if (update_image_customization()) { return true; }

	var color = null;
	var color_code = null;
	var i = 0;
	var j = 0;
	var q = 0;

	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
	}

	if(c_el)
	{
		if(color)
		{
			for(i in sProduct.Variants)
			{
				if(color == sProduct.Variants[i].Color_Value_Id)
				{
					color_code = sProduct.Variants[i].Color_Code;
					break;
				}
			}
		}
		else
		{
			for(i in sProduct.Variants)
			{
				if(q <= sProduct.Variants[i].I)
				{
					q = sProduct.Variants[i].I;
					color_code = sProduct.Variants[i].Color_Code;
				}
			}
		}

		if(document.images.ProductImage.src != 'http://' + window.location.host + '/Images/Catalog/ProductImages/300/' + basenumber + '.' + color_code + '.JPG')
		{
			document.images.ProductImage.src = '/Images/Catalog/ProductImages/300/' + basenumber + '.' + color_code + '.JPG';
		}
	}
}

function update_image_giftcard(basenumber)
{
	var color = null;
	var color_code = null;
	var i = 0;
	var j = 0;
	var q = 0;

	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = document.getElementById('color').value
	}

	if(c_el)
	{
		if(color)
		{
			for(i in sProduct.Variants)
			{
				if(color == sProduct.Variants[i].Color_Value_Id)
				{
					color_code = sProduct.Variants[i].Color_Code;
					break;
				}
			}
		}
		else
		{
			for(i in sProduct.Variants)
			{
				if(q <= sProduct.Variants[i].I)
				{
					q = sProduct.Variants[i].I;
					color_code = sProduct.Variants[i].Color_Code;
				}
			}
		}

		if(document.images.ProductImage.src != 'http://' + window.location.host + '/Images/Catalog/ProductImages/300/' + basenumber + '.' + color_code + '.JPG')
		{
			document.images.ProductImage.src = '/Images/Catalog/ProductImages/300/' + basenumber + '.' + color_code + '.JPG';
		}
	}
}

function validate_color_menu()
{
	var color = null;
	var color_array = new Array();

	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
	}

	c_el.length = 0;
	c_el.options[0] = new Option('Choose', '');

	for(var i in sProduct.Variants)
	{
		if(sProduct.Variants[i].I >= 1 || sProduct.Variants[i].B >= 1 || sProduct.Variants[i].S >= 1)
		{
			c_el.options[c_el.options.length] = new Option(sProduct.Variants[i].Color_Value, sProduct.Variants[i].Color_Value_Id);
		}
	}
}
// End Color specific functions

function update_image_customization()
{
	var packages = document.getElementsByName('Package_Name');

	if (document.getElementsByName('Customize').length >= 1) {
		if (document.getElementsByName('Customize')[0].checked == true) {
			for (var p=0; p < packages.length; p++) {
				if (packages[p].checked == true) {
					if (packages[p].getAttribute('value').substring(0, 3).toUpperCase() == 'CS.') {
						/* CLUBSTORE Package */
						var values = document.getElementsByName(packages[p].getAttribute('value') + '.LOGO');
						for (var m=0; m < values.length; m++) {
							if (values[m].getAttribute('type') == 'radio') {
								if (values[m].checked == true) {
									packageImageUpdateFunctions[packages[p].getAttribute('value')](document.getElementsByName(packages[p].getAttribute('value') + '.LOGO')[m].value);
									return true;
								}
							}
						}
					} else if (packages[p].getAttribute('value').toUpperCase() == 'HERO' || packages[p].getAttribute('value').toUpperCase() == 'DLHERO') {
						/* REPLICA/HERO Package */
						var values = document.getElementsByName(packages[p].getAttribute('value') + '.AUTHENTICBACKNAME');
						for (var m=0; m < values.length; m++) {
							if (values[m].getAttribute('type') == 'radio') {
//								if (values[m].checked == true) {
//									packageImageUpdateFunctions[packages[p].getAttribute('value')](document.getElementsByName(packages[p].getAttribute('value') + '.Name')[m].value);
//									return true;
//								}
							} else if (values[m].getAttribute('type') == 'text') {
								/* not done for shoes yet */
								packageImageUpdateFunctions[packages[p].getAttribute('value')](document.getElementById(packages[p].getAttribute('value') + '.AUTHENTICBACKNAME').value, document.getElementById(packages[p].getAttribute('value') + '.AUTHENTICBACKNUMBER').value);
								return true;
							}
						}
					}
				}
			}
		}
	}
	return false;
}

/**
 * Tier Pricing specific functions
 */
function open_tierpricing_matrix()
{
	if(document.getElementById('matrix'))
		document.getElementById('matrix').style.display = 'none';
	document.getElementById('tierPricing').style.display = 'block';
}
// End Tier Pricing specific functions


/**
 * Sizes AND Colors exist
 */
function open_availability_matrix()
{
	if(document.getElementById('tierPricing'))
		document.getElementById('tierPricing').style.display = 'none';
	document.getElementById('matrix').style.display = 'block';
}

function update_color_menu()
{
	var size = null;
	var color = null;

	if(document.getElementById('size'))
	{
		var s_el = document.getElementById('size');
		size = (s_el.options[s_el.selectedIndex].value == '') ? null : s_el.options[s_el.selectedIndex].value;
	}

	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
	}

	c_el.length = 0;
	c_el.options[0] = new Option('Choose', '');

	if(size == null){
		return;
	}

	for(var i in sProduct.Variants)
	{
		if(size == sProduct.Variants[i].Size_Value_Id && (sProduct.Variants[i].I >= 1 || sProduct.Variants[i].B >= 1 || sProduct.Variants[i].S >= 1))
		{
			c_el.options[c_el.options.length] = new Option(sProduct.Variants[i].Color_Value, sProduct.Variants[i].Color_Value_Id);
		}
	}
}

/**
 * Sizes OR Colors Exist
 */
function update_availability()
{
	var size = null;
	var color = null;

	var availability = null;
	var a_el = document.getElementById('availability');

	clearTimeout(pulse_events['availability']);

	if(document.getElementById('size'))
	{
		var s_el = document.getElementById('size');
		size = (s_el.options[s_el.selectedIndex].value == '') ? null : s_el.options[s_el.selectedIndex].value;
	}

	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
	}

		availability = ''

		for(var i in sProduct.Variants)
		{
			if(size == sProduct.Variants[i].Size_Value_Id && color == sProduct.Variants[i].Color_Value_Id)
			{
				if(sProduct.Variants[i].I >= 1){
					availability = '<a onclick="open_whatis_instock(); return false;" href="javascript:void();">In Stock</a>';
					if(document.getElementById('specialorder')){ document.getElementById('specialorder').style.display = 'none'; }
				}
				else if(sProduct.Variants[i].S >= 1){
					availability = '<a onclick="open_whatis_specialorder(); return false;" href="javascript:void();">Special Order</a>';
					if(document.getElementById('specialorder')){ document.getElementById('specialorder').style.display = 'block'; }
				}
				else if((sProduct.Variants[i].B >= 1) && (sProduct.Variants[i].P == 0)){
					availability = '<a onclick="open_whatis_backorder(); return false;" href="javascript:void();">Backorder</a>';
					if (sProduct.Variants[i].Expected_Date != '') {
						availability += ' - Expected in ' + sProduct.Variants[i].Expected_Date;
					}
					if(document.getElementById('specialorder')){ document.getElementById('specialorder').style.display = 'none'; }
				}
				else if((sProduct.Variants[i].B >= 1) && (sProduct.Variants[i].P == 1)){
					availability = '<a onclick="open_whatis_preorder(); return false;" href="javascript:void();">Pre-order</a>';
					if (sProduct.Variants[i].Expected_Date != '') {
						availability += ' - Expected in ' + sProduct.Variants[i].Expected_Date;
					}
					if(document.getElementById('specialorder')){ document.getElementById('specialorder').style.display = 'none'; }
				}
			}
		}

	if(a_el.innerHTML.toLowerCase() != availability.toLowerCase())
	{
		a_el.style.visibility = 'hidden';
		a_el.innerHTML = availability;
		if(availability == '<br><br>' || availability.indexOf('Check Availability') >= 1)
			a_el.style.visibility = 'visible';
		else
			pulse_events['availability'] = setTimeout('pulse_value(\'availability\', true, 3);', 500);
	}
}

function set_GiftCardModifierVectorLength() {
	// Variable to hold Vector Length Value
	var vecLen = "";
	// Get Current Card Type Radio Button value
	var cardType = $("#sizeValue").val();
	if (cardType == "3755")
		vecLen = "4";
	else
		vecLen = "3";
	// Set hidden form field to new vector length value
	$("#giftcard_vector_length").val(vecLen);
	// Return value of vecLen
	return vecLen;
}


function set_GiftCardModifierOtherHiddens() {
	// Get Updated Vector Length Value for loop
	var vecLength = $("#giftcard_vector_length").val();
	var textNameId = "";
	var textNameVal = "";
	var userValuesId = "";
	var nameNumCombsId = "#name_number_coms";
	var nameNumCombsVal = "";
	
	// Set hidden name / value pairs
	for (var i=0; i < vecLength; i++) {
		textNameId = "#t" + i;
		userValuesId = "#u_v" + i;
		
		textNameVal = $(textNameId).val();
		if (textNameVal != "") {
			nameNumCombsVal += textNameVal;
				if (i < vecLength-1)
					nameNumCombsVal += ":";
		}
		
		$(userValuesId).val(textNameVal);
	}
	
	$(nameNumCombsId).val(nameNumCombsVal);
	var testing = 'nameNumCombsVal: ' + $(nameNumCombsId).val();

	return true;
}

function update_GiftCard_color_menu() {
    var size = null;
	
	var gcForm = document.OrderByVariantSimple;
	var gcFormLen = gcForm.elements.length;
	var gcRadioLen = 0;
	
	for (var i = 0; i < gcFormLen; i++) {
		if (gcForm.elements[i].name == "AttributeValueId" && gcForm.elements[i].type == "radio") {
			gcRadioLen++;
			if (gcForm.elements[i].checked == true)
				size = gcForm.elements[i].value;
		}
	}

    if (document.getElementById('color')) {
      var c_el = document.getElementById('color');
      color = (c_el.options[c_el.selectedIndex].value == '') ? null: c_el.options[c_el.selectedIndex].value;
      c_el.length = 0;
    	c_el.options[0] = new Option('Choose', '');
    } else if (document.getElementById('selectedsinglecolor')) {
    	var c_el = document.getElementById('selectedsinglecolor');
      color = (c_el.value == '') ? null: c_el.value;
    }

    if (size == null) {
		alert("Please select a style.");
        return false;
    }

    for (var i in sProduct.Variants) {
        if (size == sProduct.Variants[i].Size_Value_Id && (sProduct.Variants[i].I >= 1 || sProduct.Variants[i].B >= 1 || sProduct.Variants[i].S >= 1)) {
            c_el.options[c_el.options.length] = new Option(sProduct.Variants[i].Color_Value, sProduct.Variants[i].Color_Value_Id);
        }
    }
}


function update_GiftCardPrice()
{
	clearTimeout(pulse_events['price']);
	var GiftCard_Amount = document.getElementById('giftcard_amnt').value;

	var p_el = document.getElementById('price');
	p_el.style.visibility = 'visible';

	// ending decimal
	if(GiftCard_Amount.charAt(GiftCard_Amount.length-1) == "."){
		GiftCard_Amount += "00";
		document.getElementById('giftcard_amnt').value = GiftCard_Amount;
	}

	// dollar sign
	if(GiftCard_Amount.charAt(0) == "$"){
		GiftCard_Amount = GiftCard_Amount.substring(1,GiftCard_Amount.length);
		document.getElementById('giftcard_amnt').value = GiftCard_Amount;
	}

	if(GiftCard_Amount >= 5)
	{
		var pricing_copy = 'Price: $' + round_decimals(GiftCard_Amount, 2);
		var Current_Price = round_decimals(GiftCard_Amount, 2);
		document.getElementById('giftcard_amnt').value = round_decimals(GiftCard_Amount, 2);

		if(p_el.innerHTML != pricing_copy)
		{
			p_el.style.visibility = 'hidden';
			p_el.innerHTML = pricing_copy;
			pulse_events['price'] = setTimeout('pulse_value(\'price\', true, 3);', 500);
		}

		var giftCardToName				= document.getElementById('t0').value;
		var giftCardFromName			= document.getElementById('t1').value ;
		var giftCardMessage				= document.getElementById('t2').value;
		var giftCardToEmail				= document.getElementById('t3').value;

		giftCardToName					= giftCardToName.replace(/'/, "\\'");
		giftCardToName					= giftCardToName.replace(/"/, "\\\"");
		giftCardFromName				= giftCardFromName.replace(/'/, "\\'");
		giftCardFromName				= giftCardFromName.replace(/"/, "\\\"");
		giftCardMessage					= giftCardMessage.replace(/'/, "\\");
		giftCardMessage					= giftCardMessage.replace(/"/, "\\\"");
		giftCardToEmail						= giftCardToEmail.replace(/'/, "\\'");
		giftCardToEmail						= giftCardToEmail.replace(/"/, "\\\"");
		
		return true;
	} else {
		alert("Gift Cards may be purchased \nfor a minimum amount of $5.00");
		document.getElementById('giftcard_amnt').value = "5.00";
		document.getElementById('giftcard_amnt').focus();
		return false;
	}
}

function check_GiftCardToEmail() {
    // If they selected delivery by email so we need to check for email address
	var emailAddress = $("#t3").val();
    if (document.getElementById("sizeValue").value == "3755") { 
		if (emailAddress == "") {
			alert("You have selected to have this gift card delivered by email.\nPlease provide an email address for the recipient.");
			document.getElementById("t3").focus();
			return false;
		} 
		else if (!isValidEmailAddress(emailAddress)) {
			alert("The email address entered, " + emailAddress + ", is not valid.");
			document.getElementById("t3").focus();
			return false;
		} else {
			return true;
		}
    } else {
        return true;
    }
}

function check_GiftCardToFromNames() {
	var giftCardToName = $("#t0").val();		//document.getElementById('t0').value;
	var giftCardFromName = $("#t1").val();	//document.getElementById('t1').value;
	var replacement = "";
	
	// Replace colons with spaces
	replacement = replace_GiftCardColorCharacters(giftCardToName);
	$("#t0").val(replacement);
	
	replacement = replace_GiftCardColorCharacters(giftCardFromName);
	$("#t1").val(replacement);

	// If they selected delivery by email so we need to check for email address
	if (giftCardToName == "" || giftCardToName == " "){
		alert("You must enter both To and From names.");
		document.getElementById('t0').focus();
		return false;
	}
	else if (giftCardFromName == "" || giftCardFromName == " "){
		alert("You must enter both To and From names.");
		document.getElementById('t1').focus();
		return false;
	} else {
		return true;
	}
}

function check_GiftCardColor() {
	var cardColor = $("#color").val();
	if (cardColor == "") {
		alert("Please select a style.");
		$("#color").focus();
		return false;
	} else {
		return true;
	}
}

function check_GiftCardMessage() {
	var cardMessage = $("#t2").val();
	var replacement = "";
	
	// Replace colons with spaces
	replacement = replace_GiftCardColorCharacters(cardMessage);
	$("#t2").val(replacement);
	return true;
}

// ***********************************************************************************

function update_GiftCardPrice()
{
	clearTimeout(pulse_events['price']);
	var GiftCard_Amount = document.getElementById('giftcard_amnt').value;

	var p_el = document.getElementById('price');
	p_el.style.visibility = 'visible';

	// ending decimal
	if(GiftCard_Amount.charAt(GiftCard_Amount.length-1) == "."){
		GiftCard_Amount += "00";
		document.getElementById('giftcard_amnt').value = GiftCard_Amount;
	}

	// dollar sign
	if(GiftCard_Amount.charAt(0) == "$"){
		GiftCard_Amount = GiftCard_Amount.substring(1,GiftCard_Amount.length);
		document.getElementById('giftcard_amnt').value = GiftCard_Amount;
	}

	if(GiftCard_Amount >= 5)
	{
		var pricing_copy = 'Price: $' + round_decimals(GiftCard_Amount, 2);
		var Current_Price = round_decimals(GiftCard_Amount, 2);
		document.getElementById('giftcard_amnt').value = round_decimals(GiftCard_Amount, 2);

		if(p_el.innerHTML != pricing_copy)
		{
			p_el.style.visibility = 'hidden';
			p_el.innerHTML = pricing_copy;
			pulse_events['price'] = setTimeout('pulse_value(\'price\', true, 3);', 500);
		}

		var giftCardToName				= document.getElementById('t0').value;
		var giftCardFromName			= document.getElementById('t1').value ;
		var giftCardMessage				= document.getElementById('t2').value;
		var giftCardToEmail				= document.getElementById('t3').value;

		giftCardToName					= giftCardToName.replace(/'/, "\\'");
		giftCardToName					= giftCardToName.replace(/"/, "\\\"");
		giftCardFromName				= giftCardFromName.replace(/'/, "\\'");
		giftCardFromName				= giftCardFromName.replace(/"/, "\\\"");
		giftCardMessage					= giftCardMessage.replace(/'/, "\\");
		giftCardMessage					= giftCardMessage.replace(/"/, "\\\"");
		giftCardToEmail						= giftCardToEmail.replace(/'/, "\\'");
		giftCardToEmail						= giftCardToEmail.replace(/"/, "\\\"");
		
		return true;
	} else {
		alert("Gift Cards may be purchased \nfor a minimum amount of $5.00");
		document.getElementById('giftcard_amnt').value = "5.00";
		document.getElementById('giftcard_amnt').focus();
		return false;
	}
}

function check_GiftCardToEmail() {
    // If they selected delivery by email so we need to check for email address
	var emailAddress = $("#t3").val();
    if (document.getElementById("sizeValue").value == "3755") { 
		if (emailAddress == "") {
			alert("You have selected to have this gift card delivered by email.\nPlease provide an email address for the recipient.");
			document.getElementById("t3").focus();
			return false;
		} 
		else if (!isValidEmailAddress(emailAddress)) {
			alert("The email address entered, " + emailAddress + ", is not valid.");
			document.getElementById("t3").focus();
			return false;
		} else {
			return true;
		}
    } else {
        return true;
    }
}

function check_GiftCardToFromNames() {
	var giftCardToName = $("#t0").val();		//document.getElementById('t0').value;
	var giftCardFromName = $("#t1").val();	//document.getElementById('t1').value;
	var replacement = "";
	
	// Replace colons with spaces
	replacement = replace_GiftCardColorCharacters(giftCardToName);
	$("#t0").val(replacement);
	
	replacement = replace_GiftCardColorCharacters(giftCardFromName);
	$("#t1").val(replacement);

	// If they selected delivery by email so we need to check for email address
	if (giftCardToName == "" || giftCardToName == " "){
		alert("You must enter both To and From names.");
		document.getElementById('t0').focus();
		return false;
	}
	else if (giftCardFromName == "" || giftCardFromName == " "){
		alert("You must enter both To and From names.");
		document.getElementById('t1').focus();
		return false;
	} else {
		return true;
	}
}

function check_GiftCardColor() {
	var cardColor = $("#color").val();
	if (cardColor == "") {
		alert("Please select a style.");
		$("#color").focus();
		return false;
	} else {
		return true;
	}
}

function check_GiftCardMessage() {
	var cardMessage = $("#t2").val();
	var replacement = "";
	
	// Replace colons with spaces
	replacement = replace_GiftCardColorCharacters(cardMessage);
	$("#t2").val(replacement);
	return true;
}

function replace_GiftCardColorCharacters(str) {
	var newStr  = '';
	var substr  = '';
	begin = false;
	// retain whitespace characters if they are between other characters
	for (var i = 0; i < str.length; i++) {
		// copy non-whitespace characters
		if (str.charAt(i) != ' ' && str.charCodeAt(i) != 9) {
			// if the temporary string contains some whitespace characters, copy them first
			if (substr != '') {
				newStr += substr;
				substr = '';
			}
			newStr += str.charAt(i);
			if (begin == false) begin = true;
		}
		// hold whitespace characters in a temporary string if they follow a non-whitespace character
		else if (begin == true) substr += str.charAt(i);
	}
	var tempStr = newStr.replace(/:/g,"");
	return tempStr;
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
 
function pad_with_zeros(rounded_value, decimal_places) {
 
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    } else {
        decimal_part_length = value_string.length - decimal_location - 1
    }

    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++){
            value_string += "0"
        }
	}
    return value_string
}

function validate_GiftCardForm()
{
	if(!update_GiftCardPrice())
		return false;
	// if(!check_GiftCardColor())
	//	return false;
	if(!check_GiftCardToFromNames())
		return false;
	if(!check_GiftCardToEmail())
		return false;
	if(!set_GiftCardModifierVectorLength())
		return false;
	if(!check_GiftCardMessage())
		return false;
	if(!set_GiftCardModifierOtherHiddens())
		return false;

	return true;
}

function CharacterCounter(element_name, max)
{
	element = document.forms['OrderByVariantSimple'].elements[element_name];

	if(element.value.indexOf('\r\n') >= 0)
	{
		element.value = element.value.replace(/\r\n/g, '<br />');
	}

	if(element.value.length > max)
	{
		element.value = element.value.substring(0, max);
	}
	else
	{
		document.getElementById(element_name + 'Counter').innerHTML = (max - element.value.length) + ' characters available';
	}
}

var pulse_events = new Array();

function pulse_value(object, visible, repeat)
{
	if(repeat > 0)
	{
		if(visible)
			document.getElementById(object).style.visibility = 'visible';
		else
			document.getElementById(object).style.visibility = 'hidden';
		pulse_events[object] = setTimeout('pulse_value(\'' + object + '\', ' + !visible + ', ' + (--repeat) + ');', 500);
	}
}
