function changeSection(section_id) 
{
	if (section_id == 'home' || section_id == '**') {
		location.href = '/';
	} else if (section_id == 'brand') {
		location.href = '/channels/features.php?story=vendors';
	} else {
		location.href = '/IWCatSectionView.process?IWAction=Load&Merchant_Id=1&Section_Id=' + section_id + '&Sort=Product_Name';
	}
}

function change_case(form_object){
	form_object.logonUsername.value = form_object.logonUsername.value.toLowerCase();
	return true;
}

function popUp(url){
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function ChangeAddressOption()
{
	if(document.forms[document.forms.length - 1].elements.ShippingAddressOption)
	{
		if(document.forms[document.forms.length - 1].elements.ShippingAddressOption.length)
		{
			document.forms[document.forms.length - 1].elements.ShippingAddressOption[document.forms[document.forms.length - 1].elements.ShippingAddressOption.length - 1].checked = 'true';
		}
	}
}

function ChangePaymentOption(positionVar)
{
	if(document.forms[document.forms.length - 1].elements.PaymentOption)
	{
		if(document.forms[document.forms.length - 1].elements.PaymentOption.length)
		{
			if (positionVar === undefined) {
				document.forms[document.forms.length - 1].elements.PaymentOption[document.forms[document.forms.length - 1].elements.PaymentOption.length-1].checked = 'true';
			} else {
				var pos = positionVar-1;
				document.forms[document.forms.length - 1].elements.PaymentOption[pos].checked = 'true';
			} 
		}
	}
}

function PopulateProvince(Field, State)
{
	opener.document.forms[opener.document.forms.length - 1].elements[Field].value = State;
	self.close();
}

function AnalyzeCreditCard()
{
	switch(document.forms.shipping.CreditCardNumber.value.substr(0,1))
	{
		case '3'	:	document.all.CardType.options[3].selected = true; break;		// AMEX
		case '4'	:	document.all.CardType.options[1].selected = true; break;		// VISA
		case '5'	:	document.all.CardType.options[2].selected = true; break;		// MASTERCARD
		case '6'	:	document.all.CardType.options[4].selected = true; break;		// DISCOVER
		default	:	document.all.CardType.options[0].selected = true; break;		// DEFAULT
	}
}

//Popup Window for Free Shipping Restrictions
function open_freeshipping(){
	window.open('/freeshipping.html', 'FreeShipping', 'height=260,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

//Popup Window for Shipping Source Explanations
function open_whatis_instock(){
	window.open('/WhatIsInStock.html', 'WhatIsInStock', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

function open_whatis_specialorder(){
	window.open('/WhatIsSpecialOrder.html', 'WhatIsSpecialOrder', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

function open_specialorder_deadlines(){
	window.open('/CheckVendorCutoffDate.process', 'WhatIsSpecialOrder', 'height=200,width=480,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

function open_whatis_backorder(){
	window.open('/WhatIsBackOrder.html', 'WhatIsBackOrder', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

function open_whatis_preorder(){
	window.open('/WhatIsPreOrder.html', 'WhatIsPreOrder', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
}

function open_club_status(statusCode){
	switch(statusCode) {
		case 'InStock':
			window.open('/WhatIsClubInStock.html', 'WhatIsClubInStock', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
			break;
		case 'SpecialOrder':
			window.open('/WhatIsClubSpecialOrder.html', 'WhatIsClubSpecialOrder', 'height=315,width=300,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=1');
			break;
	}
}

function EstimateShipping()
{
	var Shipping_Method_Id = document.forms.shipping.Shipping_Method_Id[document.forms.shipping.Shipping_Method_Id.selectedIndex].value;
	var Postal_Code = document.forms.shipping.Postal_Code.value;
	if(Postal_Code == '')
	{
		alert('Please enter your Zipcode in the space provided.');
	} else {
		window.open('ShippingEstimator.process?Shipping_Method_Id=' + Shipping_Method_Id + '&Postal_Code=' + Postal_Code + '&OnlyGC=0', 'ShippingEstimator', 'height=140,width=300,resizable=1,status=0,menubar=0,toolbar=0,scrollbars=0');
	}
}

function copyCatalogSourceCode()
{
	var sourcecode = document.placeOrder2.CatalogSourceCode.value;
	document.placeOrder.CatalogSourceCode.value = sourcecode;
}

function AddBILBtoGearbag(val)
{
	document.forms['GearBag'].elements['BILB'].value = val;
	document.forms['GearBag'].submit();
}

//Customization Code

function showCustomizations(customizations)
{
	var rio = customizations;
	rio = rio.split(",");
	if(rio[8] == "--------"){ rio[8] = "NIKE SWOOSH"; }
	else{ rio[8] += "\t"; }
	rio[8] = rio[8].replace(/-/g, " ");
	rio[5] = rio[5].replace(/-/g, " ");
	switch(rio[2])
	{
		case '117423': rio[2] = 'Material: FULL GRAIN\tZoom Air: NO AIR'; break;
		case '117424': rio[2] = 'Material: FULL GRAIN\tZoom Air: HEEL AIR'; break;
		case '117425': rio[2] = 'Material: FULL GRAIN\tZoom Air: HEEL & FF AIR'; break;
		case '117426': rio[2] = 'Material: MICROFIBER\tZoom Air: NO AIR'; break;
		case '117427': rio[2] = 'Material: MICROFIBER\tZoom Air: HEEL AIR'; break;
		case '117428': rio[2] = 'Material: MICROFIBER\tZoom Air: HEEL & FF AIR'; break;
		case '117429': rio[2] = 'Material: KANGAROO\tZoom Air: NO AIR'; break;
		case '117430': rio[2] = 'Material: KANGAROO\tZoom Air: HEEL AIR'; break;
		case '117431': rio[2] = 'Material: KANGAROO\tZoom Air: HEEL & FF AIR'; break;
	}
	alert("Your Customizations (Size " + rio[4] + ")\n\n" + rio[2] + "\nPrimary iD: " + rio[8] + "\tSecondary iD: " + rio[5] + "\nColor: " + rio[13] + "\t\tOutsole: " + rio[29]);
}

function ShowExplanation(company, teaser, explanation, start_date, end_date)
{
	var teaser = (teaser.length > 0) ? teaser : 'You didn\'t enter a Teaser!';
	var explanation = (explanation.length > 0) ? explanation.replace(/\r\n/g, '<br />') : 'You didn\'t enter an Explanation!';
	var start_date = (start_date.length > 0) ? start_date : '01/01/2069';
	var end_date = (end_date.length > 0) ? end_date : '01/01/2069';

	var dates = start_date + ' - ' + end_date;
	var dynaheight = (74 + ((teaser.length / 28) * 24) + ((explanation.length / 42) * 20));

	if(company == '01')
	{
		var color = '#fff';
		var website = 'SOCCER.COM';
	}

	if(company == '03')
	{
		var color = '#fff';
		var website = 'LACROSSE.COM';
	}

	var output = '';

	output += '<html>\n';
	output += '<head>\n';
	output += '<title>' + teaser + '</title>\n';
	output += '<link rel="stylesheet" type="text/css" href="/stylesheets/OrderProcess/promo_module.css" />\n';
	output += '</head>\n';
	output += '<body bgcolor="' + color + '" leftmargin="0" topmargin="0">\n';
	output += '<div id="promoExp" style="background:' + color + ';">\n';
	output += '<h2>' + teaser + '</h2>\n';
	output += '<p>' + explanation + '</p>\n';
	output += '<h6>Order must be placed on ' + website + ' before ' + end_date + '.</h6>\n';
	output += '</div>\n';
	output += '</table>\n';
	output += '</body>\n';
	output += '</html>\n';

	var explanation_win = window.open('about:blank', 'window', 'directories=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,height=' + dynaheight + ',width=390');
	explanation_win.document.write(output);
}

function detect_position_x(object)
{
	var current_value = 0;
	if(object.offsetParent)
	{
		while(object.offsetParent)
		{
			current_value += object.offsetLeft;
			object = object.offsetParent;
		}
	}
	return current_value;
}

function detect_position_y(object)
{
	var current_value = 0;
	if(object.offsetParent)
	{
		while(object.offsetParent)
		{
			current_value += object.offsetTop;
			object = object.offsetParent;
		}
	}
	return current_value;
}

// BEGIN PRODUCT PAGE SPECIFICS

	function SEI_createWindow (url, name, options) {
		var w = window.open(url, name, options);
		w.focus();
		return false;
	}

	function openVideo()
	{
		window.open('http://videos.soccer.com/movies/diadora/diadora_video.html', 'Video', 'height=375,width=350,resizable=0,status=0,menubar=0,toolbar=0,scrollbars=0');
	}

	function view360(product, winType)
	{
		var pageLoc;
		if(winType == '360') 
			pageLoc	= "/360/"+product+"/"+product+".html";
		if(winType == 'video')
			pageLoc	= "http://videos.soccer.com/prod_vids.php?pc="+product+"&res=lo";
		if(winType == '')
			pageLoc	= "/360/"+product+"/"+product+".html";
			
		window.open(pageLoc,"360","toolbar=0,statusbar=0,menubar=0,width=500,height=400");
	}
	
	function viewVideo(product, winType)
	{
		var pageLoc;
		if(winType == '360') 
			pageLoc	= "/360/"+product+"/"+product+".html";
		if(winType == 'video')
			pageLoc	= "http://videos.soccer.com/prod_vids.php?pc="+product+"&res=lo";
		if(winType == '')
			pageLoc	= "/360/"+product+"/"+product+".html";
			
		window.open(pageLoc,"360","toolbar=0,statusbar=0,menubar=0,width=660,height=410");
	}

	function view360Lax(product, winType)
	{
		var pageLoc;
		if(winType == '360') 
			pageLoc	= "/360/"+product+"/"+product+".html";
		if(winType == 'video')
			pageLoc	= "http://videos.lacrosse.com/prod_vids.php?pc="+product+"&res=lo";
		if(winType == '')
			pageLoc	= "/360/"+product+"/"+product+".html";
			
		window.open(pageLoc,"360","toolbar=0,statusbar=0,menubar=0,width=500,height=400");
	}
	
	function viewVideoLax(product, winType)
	{
		var pageLoc;
		if(winType == '360') 
			pageLoc	= "/360/"+product+"/"+product+".html";
		if(winType == 'video')
			pageLoc	= "http://videos.lacrosse.com/prod_vids.php?pc="+product+"&res=lo";
		if(winType == '')
			pageLoc	= "/360/"+product+"/"+product+".html";
			
		window.open(pageLoc,"360","toolbar=0,statusbar=0,menubar=0,width=660,height=410");
	}

	function dictionaryWindow(DictionaryID)
	{
		var dictionaryLink = "/dictionary/definition.php?dictionaryID=" + DictionaryID;
		window.open(dictionaryLink, 'dictionary_window','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=200,width=220');
	}

	function dictionaryWindowLax(DictionaryID)
	{
		var dictionaryLink = "/dictionary/definitionLax.php?dictionaryID=" + DictionaryID;
		window.open(dictionaryLink, 'dictionary_window','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=200,width=220');
	}

	function display_tab(tab)
	{
		document.getElementById('itemDetails').style.display = 'none';
		document.getElementById('itemReviews').style.display = 'none';

		document.getElementById(tab).style.display = 'block';
	}

function imagePop (url, name, options) {
	var w = window.open(url, name, options);
	w.focus();
	return false;
}

// Function that will swap the display/no display for large callout images

function showCallout(index)
{
	var d, i=0;
	while (d = document.getElementById('display' + (i))) {
		d.style.display = 'none';
		document.getElementById('imageClose' + i).style.display = 'none';
		i++;
	}
	document.getElementById('display' + index).style.display = 'block';
	document.getElementById('imageClose' + index).style.display = 'block';
}


function validateQTY(qty_object)
{
	qty_value = qty_object.value.replace(/\D/g, '');
	if(qty_value == "" || qty_value == 0){ qty_value = 1; }
	qty_object.value = qty_value;

	var error = false;

	if(document.getElementById('size')){
		if(document.getElementById('size').options[document.getElementById('size').selectedIndex].text == 'Choose'){
			error = true;
		}
	}

	if(document.getElementById('color')){
		if(document.getElementById('color').options[document.getElementById('color').selectedIndex].text == 'Choose'){
			error = true;
		}
	}

	if(error){
		alert('You must select a size and/or color to purchase this item.');
	}

	return !error;
}


	function change_case(form_object){
		form_object.logonUsername.value = form_object.logonUsername.value.toLowerCase();
        return true;
	}

function writeDate(){
	ddate = new Date();
	day = ddate.getDay();
	date = ddate.getDate();
	month = ddate.getMonth();
	year = ddate.getYear();
	if(year < 1900){ year = year + 1900; }
	var days = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	document.write(days[day]+", "+months[month]+" "+date+", "+year);
}

// This function was created to apply a Gift Card on the Payment page
function ApplyGiftCard(){
	document.location = "/PlaceOrder.process?GiftCardNumber=" + document.forms.payment.GiftCardNumber.value + "&GCRecipientName=" + document.forms.payment.GCRecipientName.value +"&GiftCardAction=Apply&IWPEProcessFlow.submitted.sequenceID=" + document.forms.payment.sequenceID.value;
	return true;
}

function checkGiftCardBalance()
{
	var GiftCardNumber = document.forms.payment.GiftCardNumber.value;
	var PIN = document.forms.payment.PIN.value;
	if(GiftCardNumber == '')
	{
		alert('Please enter your Gift Card Number in the space provided.');
	} else {
		window.open('GiftCardBalance.process?GiftCardNumber=' + GiftCardNumber + '&PIN=' + PIN, 'GiftCardBalance', 'height=80,width=370,resizable=1,status=0,menubar=0,toolbar=0,scrollbars=0');
	}
}

function toggle_visibility(display_block)
{
	if (document.getElementById(display_block).style.display == "block")
	 {
	 document.getElementById(display_block).style.display="none";
	 }
	else
	{
	 document.getElementById(display_block).style.display = "block";
	}
}

function showZones ()
{
	//window.open('/shipmapholiday.html', 'window', 'top=15,left=15,width=640,height=520,statusbar=0,toolbar=0,resizable=1');
	window.open('/shipmapsmall.html', 'window', 'top=15,left=15,width=640,height=455,statusbar=0,toolbar=0,resizable=1');
}

function nikeGinga() 
{
	window.open('/channels/features/nike_ginga/index.html', 'window', 'top=0,left=15,width=980,height=700,statusbar=0,toolbar=0,resizable=1');
}

/* Customization JavaScript */

function iconPop() {
	window.open('/channels/customize/iconpop.html', 'window', 'top=15,left=15,width=750,height=550,scrollbars=1,statusbar=0,toolbar=0,resizable=0'); 
}

function JerseyStylePop() {
	window.open('/channels/customize/jerseystylepop.html', 'window', 'top=15,left=15,width=750,height=600,scrollbars=0,statusbar=0,toolbar=0,resizable=1'); 
}

function JerseyStyleAuthPop() {
	window.open('/channels/customize/jerseystyleauthpop.html', 'window', 'top=15,left=15,width=380,height=585,scrollbars=0,statusbar=0,toolbar=0,resizable=1'); 
}

function JerseyStyleBasicPop() {
	window.open('/channels/customize/jerseystylebasicpop.html', 'window', 'top=15,left=15,width=380,height=585,scrollbars=0,statusbar=0,toolbar=0,resizable=1'); 
}

/* Cookie Functions */

function setCookie (name, value, days) {
	var expires = '';
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 *60 * 60 * 1000));
		expires = '; expires=' + date.toGMTString();
	}
	document.cookie = name + '=' + value + expires + '; path=/';
}

function getCookie (name) {
	var name = name + '=';
	var cookies = document.cookie.split(';');
	for (var i=0; i < cookies.length; i++) {
		var c = cookies[i];
		while (cookies[i].charAt(0) == ' ') {
			cookies[i] = cookies[i].substring(1, cookies[i].length);
		}
		if (cookies[i].indexOf(name) == 0) {
			return cookies[i].substring(name.length, cookies[i].length);
		}
	}
	return null;
}

function deleteCookie (name) {
	setCookie(name, '', -1);
}

function changeSizeOptInSearch (newValue) {
	var sizeOpt = document.getElementsByName("SizeOpt")
	sizeOpt[newValue].checked = true;
}

/* end Cookie Functions */

/**
 * toggleElement
 *
 * @param element	the element on the page to toggle
 * @param maximize	(optional) force minimize or maximize
 */
function toggleElement(element /*, maximize*/) {

	if (element === null) {
		return;
	}

	var maximize = (element.style.display === 'none');

	/**
	 * If the optional parameter maximize is a boolean, override the
	 * calculated action.
	 */
	if (typeof arguments[1] === 'boolean') {
		maximize = arguments[1];
	}

	/**
	 * Show or hide the element depending on what action is needed (or
	 * was specified).
	 */
	if (maximize) {
		element.style.display = 'block';
	} else {
		element.style.display = 'none';
	}		
}