function _openwin(page){
 window.open(page, 'helpWindow', 'location=no,scrollbars=yes,toolbar=no,width=300,height=400');
}

function updQuant(i){
	var f="prodform"+i;
	var e="quant"+i;
	p=document.getElementById(f);
	q=document.getElementById(e);
	p.quant.value=q.value;
	p.submit();
}

function frmsubmit(func,postcost) {
	document.basket.func.value = func;
	document.basket.postcost.value = postcost;
	document.basket.submit();
}

function _opensecwin(url){
secwin=window.open(url, 'securewin', 'location=yes,scrollbars,width=786,height=600');
 secwin.window.focus();
}

function _openemailpagewin(){
	epagewin=window.open('emailpage.php', 'epwin', 'location=no,scrollbars,status=no,width=500,height=350');
	epagewin.window.focus();
}

function launchcalculator(prod_id,formid,quantid){
calcwin=window.open('calculator.php?id='+prod_id+'&form='+formid+'&quant='+quantid, 'calcwin', 'location=no,scrollbars=yes,toolbar=no,status=no,resizable=no,width=345,height=460');
 calcwin.window.focus();
}

function validateForm(){
 if(document.sp_form.email.value==""){
	alert("Please type in your email address");
	document.sp_form.email.focus();
	document.sp_form.email.style.backgroundColor='ffff00';
	return false;
}else if(document.sp_form.email.value!=document.sp_form.email2.value){
	alert("Your two entered email addresses do not match.");
	document.sp_form.email.focus();
	document.sp_form.email.style.backgroundColor='ffff00';
	return false;
 } else if (!valid_email(document.sp_form.email.value)){
		alert("You must enter a valid e-mail address");
		document.sp_form.email.focus();
		document.sp_form.email.style.backgroundColor='ffff00';
		return (false);
 }else{
	return true;
 }
}

function valid_email(addr) {
	if (matchit(addr)==null){
		//alert("This is not a genuine e-mail address.");
		return (false);
	} else {
		return (true);
	}
}

function matchit(email){
	var result= email.match(/(^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$)/gi);
	return result;
}

function selectHandler() {
	if (document.spasearchform.county.value=="general") {
		document.spasearchform.region.disabled=0	
	} else {
		document.spasearchform.region.disabled=1	
	}
	if (document.spasearchform.region.value=="general") {
		document.spasearchform.county.disabled=0	
	} else {
		document.spasearchform.county.disabled=1	
	}
}

function showMessageDiv(message, objectWidth, objectHeight) {
	container = document.getElementById("messageDivContainer");
	messageContent2  = document.getElementById("messageContent");
	if(container){
		container.className = "messagePopup displayBlock";		
		container.style.visibility = "hidden";
		container.width = objectWidth - 12;
		container.height = objectHeight;
		document.getElementById("messageDivHeader").width = objectWidth;
		document.getElementById("messagePopupCloseIcon").style.marginLeft = (objectWidth - 12) + "px";
		
		var iSiteBodyWidth = document.getElementById("mainbody").offsetWidth;
		var iPopupWidth = container.width;
		var iLeftPos = (iSiteBodyWidth / 2) - (iPopupWidth / 2);
		var iTopPos = 130;
		if(typeof(window.innerWidth) == "number"){
			var iBrowserWidth = window.innerWidth;
		}else{
			var iBrowserWidth = document.documentElement.clientWidth;
		}
		var iWhitespaceWidth = (iBrowserWidth - iSiteBodyWidth) / 2;
		
		iLeftPos = iLeftPos + iWhitespaceWidth - 200;
		container.style.left = iLeftPos + "px";
		container.style.top = iTopPos + "px";
		
		messageContent2.innerHTML=""+message;
		
		container.style.visibility = "visible";			
	}
}
function closeMessagePopup(){
	var oPopupDiv = document.getElementById("messageDivContainer");
	if(oPopupDiv){
		oPopupDiv.className = "messagePopup displayNone";
		//document.getElementById("siteBodyContainer").className = "siteBody content";
	}
}
function showElemisDiscountDiv(objectWidth, objectHeight) {
	container = document.getElementById("elemisDiscountDivContainer");
	
	if(container){
		container.className = "elemisDiscountPopup displayBlock";
		container.style.visibility = "hidden";
		container.width = objectWidth - 12;
		container.height = objectHeight;
		document.getElementById("elemisDiscountDivHeader").width = objectWidth;
		document.getElementById("elemisDiscountPopupCloseIcon").style.marginLeft = (objectWidth - 12) + "px";
		
		var iSiteBodyWidth = document.getElementById("mainbody").offsetWidth;
		var iPopupWidth = container.width;
		var iLeftPos = (iSiteBodyWidth / 2) - (iPopupWidth / 2);
		var iTopPos = 130;
		if(typeof(window.innerWidth) == "number"){
			var iBrowserWidth = window.innerWidth;
		}else{
			var iBrowserWidth = document.documentElement.clientWidth;
		}
		var iWhitespaceWidth = (iBrowserWidth - iSiteBodyWidth) / 2;
		
		iLeftPos = iLeftPos + iWhitespaceWidth - 100;
		container.style.left = iLeftPos + "px";
		container.style.top = iTopPos + "px";
			
		container.style.visibility = "visible";			
	}
}
function closeElemisDiscountPopup(){
	var oPopupDiv = document.getElementById("elemisDiscountDivContainer");
	if(oPopupDiv){
		oPopupDiv.className = "elemisDiscountPopup displayNone";
		//document.getElementById("siteBodyContainer").className = "siteBody content";
	}
}
function showGiftCardVisual(){
	var oGiftCardVisual = document.getElementById("divGiftCardVisual");
	if(oGiftCardVisual){
		if(oGiftCardVisual.style.display == "block"){
			oGiftCardVisual.style.display = "none";
		}else{
			oGiftCardVisual.style.display = "block";
		}
	}
}
function showGiftWrapVisual(){
	var oGiftWrapVisual = document.getElementById("divGiftWrapVisual");
	if(oGiftWrapVisual){
		if(oGiftWrapVisual.style.display == "block"){
			oGiftWrapVisual.style.display = "none";
		}else{
			oGiftWrapVisual.style.display = "block";
		}
	}
}