
function ShowPopup(path, title, width, height, top, left)

{

            var leftPosition;

            var topPosition;

            

            height = typeof height != "undefined" ? height : 400;

            width = typeof width != "undefined" ? width : 400;

            

            if(typeof top == "undefined")

                        topPosition = (screen.height) ? (screen.height-height)/2 : 0;

            else

                        topPosition = top;

                        

 

            if(typeof left == "undefined")

                        leftPosition = (screen.width) ? (screen.width-width)/2 : 0;

            else

                        leftPosition = left;

 

            window.open(path, title, "scrollbars=yes,height="+ height +",width="+ width +",status=no,toolbar=no,menubar=no,location=no,resizable=no, top=" + topPosition + ", left=" + leftPosition);

}

function checkCheckBoxes(Form1) 
{

	if(	(!document.getElementById('radNo').checked) && (!document.getElementById('radYes').checked) )
	{
		alert ('You must choose whether your delivery address is the same as your card address');
		return false;
	}

    if (Form1.AgreeTerms.checked == false) 
    {
		alert ('You must click the checkbox to say that you have read and agree with the Terms and Conditions');
		return false;
    } 

    return true;

}


function isValidPostcode(postcode) 
{
	var postcodeRegEx = /(^((([BEGLMNS][1-9]\d?)|(W[2-9])|((A[BL]|B[ABDHLNRST]|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]|F[KY]|G[LUY]|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]|M[EKL]|N[EGNPRW]|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKL-PRSTWY]|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)\d\d?)|(W1[A-HJKSTUW0-9])|(((WC[1-2])|(EC[1-4])|(SW1))[ABEHMNPRVWXY]))(\s*)?([0-9][ABD-HJLNP-UW-Z]{2}))$|^(GIR\s?0AA)$)/i;
	return postcodeRegEx.test(postcode);
}



function ReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function PopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 520,top = 285');");
}


function SetDeliveryCookie(ProductId, name, expires, path, domain, secure)
{	
	var found_it;
	var pc;
	pc = document.getElementById('TextBoxPostcode').value;
	
	for (var i=0; i<document.Form1.DeliveryCheckRadio.length; i++)  { 
		if (document.Form1.DeliveryCheckRadio[i].checked)  {
			found_it = document.Form1.DeliveryCheckRadio[i].value
		} 
	} 
	
	if(found_it == null)
	{
		alert("Please select a delivery address option.");
		return;
	}
	
	if(found_it == "Mainland" && pc == "")
	{
		alert("Please provide your postcode.");
		return;
	}
	
	if(found_it == "Mainland" && pc != "" && !isValidPostcode(pc))
	{
		alert("Please provide a valid postcode.");
		return;
	}
	
	
	document.cookie = name + "=" + escape (found_it) + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
    
    document.cookie = "Postcode=" + pc + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");

	document.location = "AddToBasket.aspx?ProductId="+ ProductId;
}

function AddToBasket(ProductId)
{
	document.location = "AddToBasket.aspx?ProductId="+ ProductId;
}

function PreviewImage(placeHolder)
{	
	var srcElem = window.event.srcElement;
	if(srcElem.value.indexOf(".jpg") > 0)
		placeHolder.src = srcElem.value;
	else
		placeHolder.src = "../Images/Products/NoImageSmall.gif";
}
function ClickButton(e, buttonId)
{ 
	var button = document.getElementById(buttonId); 

	if(navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
		e = window.event;

	// Check for Enter key
	if(e.keyCode == 13)
	{
		// Check to see if button or image.
		if(button.tagName.toUpperCase() == "INPUT" || button.tagName.toUpperCase() == "BUTTON")
			button.click();
		else if(button.tagName.toUpperCase() == "IMG")
			button.onclick();

		return false;
	}
} 
        
		function stopRKey(evt) {
		var evt = (evt) ? evt : ((event) ? event : null);
		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
		}
		document.onkeypress = stopRKey; 
		
