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 update_price(b, l, pc)
{
	var additional = 0.00;
	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) {
					additional = document.getElementsByName(packages[p].getAttribute('value') + '.Package_Price')[0].getAttribute('value');
				}
			}
		}
	}

	var size = null;
	var color = null;

	clearTimeout(pulse_events['price']);

	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;
	}

	var p_el = document.getElementById('price');
	p_el.style.visibility = 'visible';
	var f_el = document.getElementById('freeWith');

	var Base_Price = b;
	var Loyalty_Price = l;
	var Point_Cost = pc;

	for(var i in sProduct.Variants)
	{
		if(size == sProduct.Variants[i].Size_Value_Id && color == sProduct.Variants[i].Color_Value_Id)
		{
			Base_Price = sProduct.Variants[i].Base_Price;
			Loyalty_Price = sProduct.Variants[i].Loyalty_Price;
			Point_Cost = sProduct.Variants[i].Point_Cost;
			break;
		}
	}

	if(sLoyalty === true)
	{
		// use <br> instead of <br /> because innerHTML will convert to <br> anyway
		var pricing_copy = '<b>CLUB LAX Price: $' + (Math.round((parseFloat(Loyalty_Price) + parseFloat(additional)) * 100) / 100);
		var Current_Price = Loyalty_Price;
	}
	else
	{
		var priceDecimals = (Math.round((parseFloat(Base_Price) + parseFloat(additional)) * 100) / 100);
		var pricing_copy = 'Price: $' + priceDecimals.toFixed(2);
		var m_el = document.getElementById('membersPay');
		var loyaltyPriceDecimals = (Math.round((parseFloat(Loyalty_Price) + parseFloat(additional)) * 100) / 100);
		var loyalty_copy = '<a href="/goalclub/">Goal Club</a> Members pay $' + loyaltyPriceDecimals.toFixed(2);
		var Current_Price = Base_Price;
	}

	var free_copy = 'Free with ' + Point_Cost + ' Goal Club points';

	if(sProduct.List_Price && sProduct.List_Price > 0.00 && Current_Price && document.getElementById('listPrice'))
	{
		var l_el = document.getElementById('listPrice');
		var list_copy = '<span class="strikeout">$' + sProduct.List_Price + ' List Price.</span> You Save $' + Math.round(sProduct.List_Price - Current_Price);
		if(l_el.innerHTML != list_copy)
		{
			l_el.innerHTML = list_copy;
		}
	}

	if(Base_Price && 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);
	}

	if(sLoyalty === false && Loyalty_Price && m_el.innerHTML != loyalty_copy)
	{
		m_el.innerHTML = loyalty_copy;
	}

	if(Point_Cost && Point_Cost > 0 && f_el.innerHTML != free_copy)
	{
		f_el.innerHTML = free_copy;
	}
}

/**
 * Would take out the update_price(x,y,z) function from here and placed it in the ProductAttributes.tem for LAX and SOCCER
 */
 function update_price(b, l, pc)
{
	var additional = 0.00;
	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) {
					additional = document.getElementsByName(packages[p].getAttribute('value') + '.Package_Price')[0].getAttribute('value');
				}
			}
		}
	}

	var size = null;
	var color = null;

	clearTimeout(pulse_events['price']);

	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;
	}

	var p_el = document.getElementById('price');
	p_el.style.visibility = 'visible';
	var f_el = document.getElementById('freeWith');

	var Base_Price = b;
	var Loyalty_Price = l;
	var Point_Cost = pc;

	for(var i in sProduct.Variants)
	{
		if(size == sProduct.Variants[i].Size_Value_Id && color == sProduct.Variants[i].Color_Value_Id)
		{
			Base_Price = sProduct.Variants[i].Base_Price;
			Loyalty_Price = sProduct.Variants[i].Loyalty_Price;
			Point_Cost = sProduct.Variants[i].Point_Cost;
			break;
		}
	}

	if(sLoyalty === true)
	{
		// use <br> instead of <br /> because innerHTML will convert to <br> anyway
		var pricing_copy = 'Goal Club<br>Price: $' + (Math.round((parseFloat(Loyalty_Price) + parseFloat(additional)) * 100) / 100);
		var Current_Price = Loyalty_Price;
	}
	else
	{
		var priceDecimals = (Math.round((parseFloat(Base_Price) + parseFloat(additional)) * 100) / 100);
		var pricing_copy = 'Price: $' + priceDecimals.toFixed(2);
		var m_el = document.getElementById('membersPay');
		var loyaltyPriceDecimals = (Math.round((parseFloat(Loyalty_Price) + parseFloat(additional)) * 100) / 100);
		var loyalty_copy = '<b><a href="/goalclub/">Goal Club</a> Members pay $' + loyaltyPriceDecimals.toFixed(2) + '</b>';
		var Current_Price = Base_Price;
	}

	var free_copy = 'Free with ' + Point_Cost + ' Goal Club points';

	if(sProduct.List_Price && sProduct.List_Price > 0.00 && Current_Price && document.getElementById('listPrice'))
	{
		var l_el = document.getElementById('listPrice');
		var list_copy = '<span class="strikeout">$' + sProduct.List_Price + ' List Price.</span> You Save $' + Math.round(sProduct.List_Price - Current_Price);
		if(l_el.innerHTML != list_copy)
		{
			l_el.innerHTML = list_copy;
		}
	}

	if(Base_Price && 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);
	}

	if(sLoyalty === false && Loyalty_Price && m_el.innerHTML != loyalty_copy)
	{
		m_el.innerHTML = loyalty_copy;
	}

	if(Point_Cost && Point_Cost > 0 && f_el.innerHTML != free_copy)
	{
		f_el.innerHTML = free_copy;
	}
}
 
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 giftCardRecipientName	= document.getElementById('giftcard_recipientname').value;
		var giftCardSenderName		= document.getElementById('giftcard_sendername').value ;
		var giftCardRecipientEmail	= document.getElementById('giftcard_recipientemail').value;
		var giftCardGreeting		= document.getElementById('giftcard_greeting').value;

		giftCardRecipientName		= giftCardRecipientName.replace(/'/, "\\'");
		giftCardRecipientName		= giftCardRecipientName.replace(/"/, "\\\"");
		giftCardSenderName			= giftCardSenderName.replace(/'/, "\\'");
		giftCardSenderName			= giftCardSenderName.replace(/"/, "\\\"");
		giftCardRecipientEmail		= giftCardRecipientEmail.replace(/'/, "\\'");
		giftCardRecipientEmail		= giftCardRecipientEmail.replace(/"/, "\\\"");
		giftCardGreeting			= giftCardGreeting.replace(/'/, "\\");
		giftCardGreeting			= giftCardGreeting.replace(/"/, "\\\"");

		document.getElementById('Customization_Value').value = GiftCard_Amount + '|' + giftCardRecipientName + '|' + giftCardSenderName + '|' + giftCardRecipientEmail + '|' + giftCardGreeting;
		//document.getElementById('Customization_Value').value = GiftCard_Amount + '|' + document.getElementById('giftcard_recipientname').value + '|' + document.getElementById('giftcard_sendername').value + '|' + document.getElementById('giftcard_recipientemail').value + '|' + document.getElementById('giftcard_greeting').value;
		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 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 check_GiftCardRecipientEmail() {
	// If they selected delivery by email so we need to check for email address
	if(document.getElementById('sizeValue').value == '3755' && document.getElementById('giftcard_recipientemail').value == '') {
		alert("You have selected to have this \ngift card delivered by email. Please \nprovide an email address for the recipient.");
		document.getElementById('giftcard_recipientemail').focus();
		return false;
	} else {
		return true;
	}
}

function check_GiftCardRecipientSenderNames() {
	var giftCardRecipientName	= document.getElementById('giftcard_recipientname').value;
	var giftCardSenderName		= document.getElementById('giftcard_sendername').value ;
	
	// If they selected delivery by email so we need to check for email address
	if(giftCardRecipientName === "" || giftCardSenderName === ""){
		alert("You must enter both recipient and sender names");
		document.getElementById('giftcard_recipientname').focus();
		return false;
	} else {
		return true;
	}
}

function validate_GiftCardForm()
{
	if(!check_GiftCardRecipientEmail())
		return false;
	if(!update_GiftCardPrice())
		return false;
	if(!check_GiftCardRecipientSenderNames())
		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);
	}
}