function AddCart(code,name) {
	window.open('/order.aspx?code=' + code + '&name=' + escape(name) +  '&normal=true','addtocart','height=375,width=451,border=0,resizable=yes,scrollbars=no,toolbar=no');
}


function tellFriend(productCode) {
	window.open('/send.aspx?code=' + productCode,'mailafriend','height=500,width=450,border=0,resizable=yes,scrollbars=yes,toolbar=no');
}

function OnSearchKeyPress() {
	if (event.keyCode==13)
	{   
		if (event.srcElement.InnerHtml != "") 
		{  
			return false;
			DoSearch('txtsearch'); 
		} 
	}
}

function DoSearch(inputControlId) {   
	var keywordsText = '';  
	var inputControl = document.getElementById(inputControlId);  

	if (inputControl == null)
	{
		return;
	}

	keywordsText = inputControl.value;  

	if ((keywordsText == null) || (keywordsText.length == 0)) 
	{
	    return; 
	}
  
	var newHref = '';  
	newHref = '/en/search.aspx?txtsearch=' + cleanInput(keywordsText) + '&tb=a';  
		
	window.location.href = newHref;
		
	return;
}

function getconfirm() { 
	if (confirm("Are you sure you wish to remove this item from your order?")==true) {
		return true;
	}
	else {
		return false;
	}
}

function CheckQuickOrder() {
	var txtQuickOrder = document._ctl1.txtQuickOrder;
	
	if (txtQuickOrder.value.length < 1) {
		txtQuickOrder.focus();
		return false;
	}
	return true;
}

function linkFromPopup(page) {
	if (window.opener) {
		popredirect(page);
	}
	else {
		document.location.href = page;
	}
}

function popredirect(myHref) {
	if (window.opener != null) {
		window.opener.location.href=myHref;
		window.close();
	}
	else {
		window.location.href=myHref;
	}
}

function showhelp(input) {
	window.open('/prompts.aspx?s=' + input,'HelpPage','width=420,height=350,scrollbars=yes, resizable=no');
}

function showoffer(input)
{
	window.open('/offers.aspx?n=' + input,'offers','width=420,height=280,scrollbars=yes, resizable=no');
}

function cleanInput(input) {
invalidstring = new Array('&&', '**', '&*', '*&', '<', '>', '{', '}');

for (count=0; count < invalidstring.length; count++)
	{
      		if (input.indexOf(invalidstring[count]) > -1)
		{
		var regExp = new RegExp(invalidstring[count],'gi');
		input = input.replace(regExp,'');
      		}
    	}
return input;
}

function checkSearch() {
	var searchBox = cleanInput(document.quicksearch.txtsearch.value);
	if (searchBox.length == 0) {
		return false;
	}
	else {
		document.quicksearch.txtsearch.value = searchBox;
		return true;
	}
}

function sanForm() {
	var controlIndex;
	var element;
	var numberOfControls = document.aspNetForm.length;
	for (controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
	{
		element = document.aspNetForm[controlIndex];
		if (element.type == "text") {
			element.value = cleanInput(element.value);
		}
	}
}

function setCookie(sName, sValue, sExpire) {
    var sCookie = sName + "=" + escape(sValue) +"; path=/";	// construct the cookie
    	if (sExpire)
    	{
    	sCookie += "; expires=" + sExpire.toGMTString();	// add expiry date if present
	}
document.cookie = sCookie;					// store the cookie
return null;
}

function getCookie(sName) {
    var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
    var sNextcrumb;
    for (var i=0; i < sCookiecrumbs.length; i++) {
	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
	if (sNextcrumb[0] == sName) {		// if name matches
		return unescape(sNextcrumb[1]); 		// return value
	}
    }
return null;
}

function clearForm() {
	document.aspNetForm.ddlInvoiceSalutation.options[0].selected = true;
	document.aspNetForm.txtInvoiceFirstName.value = '';
	document.aspNetForm.txtInvoiceLastName.value = '';
	document.aspNetForm.txtInvoiceStreet.value = '';
	document.aspNetForm.txtInvoiceAddress2.value = '';
	document.aspNetForm.txtInvoiceCity.value = '';
	document.aspNetForm.txtInvoiceCounty.value = '';
	document.aspNetForm.txtInvoicePostCode.value = '';
	document.aspNetForm.ddlInvoiceCountry.options[41].selected = true;
	document.aspNetForm.txtInvoiceTelephone.value = '';
	document.aspNetForm.txtInvoiceEmail.value = '';

	document.aspNetForm.ddlRentOptOut.options[0].selected = true;
	document.aspNetForm.ddlMailingOptOut.options[0].selected = true;
	document.aspNetForm.ddlEmailOptOut.options[0].selected = true;
}

function selectCard(cardType) {
	document.aspNetForm.ddlCreditCards[cardType].selected = true;
	if (cardType == 2) {
		showSwitchDetails();
	}
	else {
		hideSwitchDetails();
	}
}

function showSwitchDetails() {
	document.getElementById("issueNumber").style.visibility="visible";
}

function hideSwitchDetails() {
	document.getElementById("issueNumber").style.visibility="hidden";
}

function placeOnHold(code) {
	window.location.href = '/en/content/on-hold.aspx?code=' + code;
}

function renderPaging() {
	var pagefile = document.location.href;
	var pageid = '';
	var fileExt = '.aspx'; // last chars

	pageid = pagefile.substr(pagefile.indexOf(fileExt)-2,2).replace('-','');

	if (document.getElementById('prop' + pageid) != null) {
		document.getElementById('prop' + pageid).className = "slct";
	}
	if (document.getElementById('base' + pageid) != null) {
		document.getElementById('base' + pageid).className = "slct";
	}
}