

var windowOpenedSuccessfully = "false";

function focusAndCheck(openedWindow, displayError)
{
	if(!openedWindow||(openedWindow.closed||!openedWindow.focus))
	{
		if (displayError)
		{
			alert("Popup blocking software may be stopping this operation.  Please disable any popup blockers and try again.");
		}
		return false;
	}
	else
	{
		openedWindow.focus();
		return true;
	}
}

function replaceText(inString,oldText,newText)

{
	return (inString.split(oldText).join(newText));
}

function openPopup(inputUrl, inputWidth, inputHeight){

	var popupWindow = "";
	var stringArray = inputUrl.split(".aspx");
	
	var pagePath =  replaceText(stringArray[0],'/en/shoponline/', '');
	
	if (!popupWindow || popupWindow.closed)
	{
		windowOpenedSuccessfully = "false";
		popupWindow = window.open(inputUrl, pagePath, 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=0');
		windowOpenedSuccessfully = focusAndCheck(popupWindow, true);
	}
}

function openPopupGeneric(inputUrl, inputWidth, inputHeight, scrollbars){

	var popupWindow = "";

	if (!popupWindow || popupWindow.closed)
	{
		windowOpenedSuccessfully = "false";
		popupWindow = window.open(inputUrl, "frettePopup", 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=' + scrollbars);
		windowOpenedSuccessfully = focusAndCheck(popupWindow, true);
	}
}

function checkEnter(e, url)
{ 
	var characterCode 

	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	e = event;
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		submitSearchForm(url);
	return false; 
	}
	else{
	return true;
	}
}

function printpage() {
	window.print();  
}

function closeWindow()
{
	window.close();
}

function goToScrollPos(scrollPos)
{
	window.scrollTo(0, scrollPos);
}

function submitShopOnlineSizeDropdown(lineItemIndex)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.getElementById('dropdownSelectType').value = 'size';
	document.getElementById('lastModifiedLineItemIndex').value=lineItemIndex;
	document.shopOnlineForm.action = document.shopOnlineForm.action;
	document.shopOnlineForm.submit()
}

function submitShopOnlineColourNameDropdown(lineItemIndex)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.getElementById('dropdownSelectType').value = 'colourName';
	document.getElementById('lastModifiedLineItemIndex').value = lineItemIndex;
	document.shopOnlineForm.action = document.shopOnlineForm.action;
	document.shopOnlineForm.submit();
}

function submitShopOnlineAddToBag(lineItemIndex)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.getElementById('lineItemIndexAddedToBag').value = lineItemIndex;
	document.getElementById('lastModifiedLineItemIndex').value = lineItemIndex;
	document.shopOnlineForm.action = document.shopOnlineForm.action;
	document.shopOnlineForm.submit();
}

function submitShopOnlineRemoveShoppingBagItem(sourcePath, basketItemId, previousBasketItemId, nextBasketItemId)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.shoppingBagForm.action = sourcePath + '?updateBasket=yes&action=delete&basketItemId='+basketItemId +'&previousBasketItemId='+previousBasketItemId+'&nextBasketItemId='+nextBasketItemId;
	document.shoppingBagForm.submit();
}

function submitShopOnlineUpdateShoppingBag(sourcePath, previousPagePath)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.getElementById('previousPagePath').value = previousPagePath;
	document.shoppingBagForm.action = sourcePath + "?updateBasket=yes";
	document.shoppingBagForm.submit();
}

function submitShopOnlineUpdateShoppingBagAndCheckout(sourcePath)
{
	document.shoppingBagForm.action = sourcePath + "?checkout=yes";
	document.shoppingBagForm.submit();

}

function submitShopOnlineApplyPromotionCode(sourcePath)
{
	document.getElementById('scrollPos').value = f_scrollTop();
	document.shoppingBagForm.action = sourcePath + "?updatebasket=yes";
	document.shoppingBagForm.submit();
}

function submitShopOnlineSubmitOrder(sourcePath)
{
	document.shoppingBagForm.action = sourcePath + "?updatebasket=yes&submit=yes";
	document.shoppingBagForm.submit();
}

var selected_id = null; 
var dom = document.getElementById; 

function swapIt(id, newclass) { 
if (dom) { 
if(selected_id != id) { 

el = document.getElementById(id); 
el.className = newclass; 
el.style.cursor = "hand"; 
el.style.cursor = "pointer";
 
} 
} 
} 

function down (id,oldclass,newclass){ 
if (dom) { 
if(selected_id != null) { 
document.getElementById(selected_id).className = oldclass; 
} 
el.className = newclass; 
selected_id = id; 
} 
} 

function toggleShopOnlineGiftMessageCheckbox(checkboxId, idToToggle, disabledClass, enabledClass)
{	

	if (document.getElementById(checkboxId).checked == true)
		swapIt(idToToggle, enabledClass);
	else
		swapIt(idToToggle, disabledClass);

}

function setElementContent(id,content)
{
	document.getElementById(id).value = content;
}
