	// ------------------------------------------------------------------------
	// dreamweaver functions
	// ------------------------------------------------------------------------

	function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);

	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

	function navOver(strImageName){
		if (strImageName)
		{
			MM_nbGroup('over','nav-'+ strImageName,'/images/general_images/leftnavbar/'+ strImageName.replace(/_\d$/, "") +'_1.gif','',1);
		}
	}

	function MM_nbGroup(event, grpName) { //v3.0
	  var i,img,nbArr,args=MM_nbGroup.arguments;
	  if (event == "init" && args.length > 2) {
	    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
	      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
	      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
	      nbArr[nbArr.length] = img;
	      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
	        if (!img.MM_up) img.MM_up = img.src;
	        img.src = img.MM_dn = args[i+1];
	        nbArr[nbArr.length] = img;
	    } }
	  } else if (event == "over") {
	    document.MM_nbOver = nbArr = new Array();
	    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
	      if (!img.MM_up) img.MM_up = img.src;
	      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
	      nbArr[nbArr.length] = img;
	    }
	  } else if (event == "out" ) {
	    for (i=0; i < document.MM_nbOver.length; i++) {
	      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
	  } else if (event == "down") {
	    if ((nbArr = document[grpName]) != null)
	      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
	    document[grpName] = nbArr = new Array();
	    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
	      if (!img.MM_up) img.MM_up = img.src;
	      img.src = img.MM_dn = args[i+1];
	      nbArr[nbArr.length] = img;
	  } }
	}



	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	// ------------------------------------------------------------------------
	// aspboard functions
	// ------------------------------------------------------------------------

	function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}

	function checkFields() {
	missinginfo = "";
	if (document.form.name.value == "") {
	missinginfo += "\n     -  Name";
	}
	if(document.form.subject.value == "") {
	missinginfo += "\n     -  Subject";
	}
	if(document.form.comments.value == "") {
	missinginfo += "\n     -  Comments";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"You failed to correctly fill in your:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
	}

	function openWindow5(url) {
	  popupWin = window.open(url,'new_page','width=420,height=400')
	}

	function popup(pageURL, width, height, targetName)
	{
		targetName = targetName || 'popup';
		var popup = window.open(pageURL, targetName, 'toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,width='+(width ? width : 600)+',height='+(height ? height : 420));
		if (window.focus) { popup.focus() }
		return false;
	}

	function popup2(pageURL, width, height, targetName, center)
	{
		targetName = targetName || 'popup';
		width = width || 600;
		height = height || 420;
		center = center || false;
		var strCenter = 'top=190,left=100,'
		if (center)
		{
			top = (screen.height) ? (screen.height-height)/2 : 0;
			left = (screen.width) ? (screen.width-width)/2 : 0;
			strCenter = 'top='+top+',left='+left+','
		}

		var popup = window.open(pageURL, targetName, strCenter+'toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,width='+ width +',height='+ height);
		return false;
	}

	// ------------------------------------------------------------------------
	// validation functions
	// ------------------------------------------------------------------------

	var whitespace = " \t\n\r";
	var iEmail = "This field must be a valid email address (like me@myisp.com)."
	var mPrefix = "You did not enter a value into the "
	var mSuffix = " field. This is a required field. Please enter it now."
	var iPassNot = "You entered two different passwords, please enter the same password twice to confirm spelling."

	function validateItemCount(myform){
		return( checkValues(myform.count, "Qty", "1234567890") )
	}

	function isEmpty(s){
		return ((s == null) || (s.length == 0))
	}

	function isWhitespace(s){
		var i;
		if (isEmpty(s)) return true;

	    for (i = 0; i < s.length; i++){
			var c = s.charAt(i);
			if (whitespace.indexOf(c) == -1) return false;
		}

		return true;
	}

	function isEmail(s){
		if (isEmpty(s))
			if (isEmail.arguments.length == 1) return false;
			else return (isEmail.arguments[1] == true);

			if (isWhitespace(s)) return false;

			var i = 1;
			var sLength = s.length;
			while ((i < sLength) && (s.charAt(i) != "@")) i++;
				if ((i >= sLength) || (s.charAt(i) != "@")) return false;
				else i += 2;
			while ((i < sLength) && (s.charAt(i) != ".")) i++;
				if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
				else return true;
	}

	function warnEmpty(theField, s){
		theField.focus()
		alert(mPrefix + s + mSuffix)
		return false
	}

	function warnInvalid(theField, s){
		theField.focus()
		theField.select()
		alert(s)
		return false
	}

	function notalike(theField){
		theField.focus()
		theField.select()
		alert(iPassNot)
		return false
	}

	function checkEmail(theField, emptyOK){
		if (checkEmail.arguments.length == 1) emptyOK = false;
			if ((emptyOK == true) && (isEmpty(theField.value))) return true;
			else if (!isEmail(theField.value, false))
				return warnInvalid (theField, iEmail);
		else return true;
	}

	function checkString(theField, s, emptyOK){
		if (checkString.arguments.length == 2) emptyOK = false;
		if ((emptyOK == true) && (isEmpty(theField.value))) return true;
		if (isWhitespace(theField.value))
			return warnEmpty(theField, s);
	    else return true;
	}

	function checkValues(myfield, str, okvalues){
		isOK = true;
		fieldval = myfield.value;
		fieldstr = fieldval.toString()
		for(counter=0; counter < fieldstr.length; counter++){
			if(okvalues.indexOf(fieldstr.charAt(counter))==-1){
				isOK = false;
				break;
			}
		}
		if(isOK) return true;
		else return warnInvalid(myfield, "Please enter a valid value in the "+ str +" field and try again.");
	}

	function checkLength(myfield, str, minlngth, maxlngth){
		// no max or no min if value is set to -1
		fieldstr = myfield.value.toString();
		reallength = fieldstr.length;
		if(reallength < minlngth && minlngth !=-1) return warnInvalid(myfield, "Please enter a valid value in the "+ str +" field and try again.  This field's minimum value is "+ minlngth +" characters.");
		else if(reallength > maxlngth && maxlngth !=-1) return warnInvalid(myfield, "Please enter a valid value in the "+ str +" field and try again.  This field's maximum value is "+ maxlngth +" characters.");
		else return true;
	}


	// ------------------------------------------------------------------------
	// categories.asp functions
	// ------------------------------------------------------------------------


	function mainOnload(){
		this.window.name = "main";
		this.main = this.window;
		MM_preloadImages('/images/bg/basket/nextbtn_f2.gif','/images/bg/basket/nextbtn_f3.gif','/images/bg/basket/previousbtn_f2.gif','/images/bg/basket/previousbtn_f3.gif',
			'/images/general_images/leftnavbar/newgifts_1.gif','/images/general_images/leftnavbar/mensgifts_1.gif','/images/general_images/leftnavbar/womensgifts_1.gif',
			'/images/general_images/leftnavbar/adulttoys_1.gif','/images/general_images/leftnavbar/flowers_1.gif','/images/general_images/leftnavbar/activitygifts_1.gif',
			'/images/general_images/leftnavbar/childrensgifts_1.gif','/images/general_images/leftnavbar/petgifts_1.gif','/images/general_images/leftnavbar/personalisedgifts_1.gif',
			'/images/general_images/leftnavbar/birthdaygifts_1.gif','/images/general_images/leftnavbar/weddinggifts_1.gif','/images/general_images/leftnavbar/weddingsupplies_1.gif',
			'/images/general_images/leftnavbar/anniversarygifts_1.gif','/images/general_images/leftnavbar/retirementgifts_1.gif',
			'/images/general_images/leftnavbar/graduationgifts_1.gif','/images/general_images/leftnavbar/newhomegifts_1.gif','/images/general_images/leftnavbar/christmasgifts_1.gif',
			'/images/general_images/leftnavbar/valentinesgifts_1.gif','/images/general_images/leftnavbar/mothersdaygifts_1.gif','/images/general_images/leftnavbar/fathersdaygifts_1.gif',
			'/images/general_images/leftnavbar/seasonalgifts_1.gif','/images/general_images/leftnavbar/specialoffers_1.gif','/images/general_images/leftnavbar/corporategifts_1.gif',
			'/images/general_images/bluenavbar/fmagNAVbarBLUE_r17_c2.gif','/images/general_images/bluenavbar/spacer.gif','/images/general_images/bluenavbar/fmagNAVbarBLUE_r19_c2.gif',
			'/images/general_images/bluenavbar/fmagNAVbarBLUE_r21_c2.gif','/images/general_images/bluenavbar/fmagNAVbarBLUE_r23_c2.gif',
			'/images/general_images/bluenavbar/fmagNAVbarBLUE_r25_c2.gif','/images/general_images/bluenavbar/fmagNAVbarBLUE_r27_c2.gif','/images/general_images/bluenavbar/spacer.gif');

/*
		isExit = true;
		window.onunload = exitPopup;
*/
		if(document.location.href.indexOf("find-me-a-gift.co.uk/") == document.location.href.length - 21 || document.location.href.indexOf("/index.asp") != -1)
			checkCount();
	}

	function exitPopup(){
/*
		if(isExit)
			var exitPop = window.open("/on-site-exit.html", 'exitPop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=no,width=400,height=475,top=150,left=150,top=-5000,left=5000');
*/
	}


	function categoryOnload(catid){
		mainOnload();

		isExit = true;
		window.onunload = exitPopup;

		switch(catid){
			case 1:
				MM_preloadImages('/buttons/general-nav/gadgetsbtn_f2.gif','/buttons/general-nav/groombtn_f2.gif','/buttons/general-nav/officebtn_f2.gif','/buttons/general-nav/personalbtn_f2.gif');
				break;
			case 2:
				MM_preloadImages('/buttons/general-nav/girlybtn_f2.gif','/buttons/general-nav/personalbtn_f2.gif','/buttons/general-nav/gifts4homebtn_f2.gif','/buttons/general-nav/healthnbeautybtn_f2.gif');
				break;
			case 3:
				MM_preloadImages('/buttons/general-nav/4babiesbtn_f2.gif','/buttons/general-nav/4boysbtn_f2.gif','/buttons/general-nav/4girlsbtn_f2.gif');
				break;
			case 4:
				MM_preloadImages('/buttons/seasonal-nav/seasnav_f2.gif','/buttons/seasonal-nav/seasnav_f2.gif','/buttons/seasonal-nav/seasnav_f2.gif','/buttons/seasonal-nav/seasnav_f2.gif');
				break;
			case 5:
				MM_preloadImages('/buttons/general-nav/salepagebtn_f2.gif','/buttons/general-nav/wedbargsbtn_f2.gif','/buttons/general-nav/weklyspecbtn_f2.gif');
				break;
			case 6:
				MM_preloadImages('/buttons/general-nav/tanbtn_f2.gif', '/buttons/general-nav/4womenbtn_f2.gif', '/buttons/general-nav/healthchkbtn_f2.gif', '/buttons/general-nav/4menbtn_f2.gif');
				break;
			case 7:
				MM_preloadImages('/buttons/wedding-nav/weddnav_f2.gif','/buttons/wedding-nav/weddnav_f2.gif','/buttons/wedding-nav/weddnav_f2.gif','/buttons/wedding-nav/weddnav_f2.gif','/buttons/wedding-nav/weddnav_f2.gif');
				break;
			case 60:
				MM_preloadImages('/images/bg/bgfire/add2bsktblkbtn_f3.gif','/images/bg/basket/nextbtn_f2.gif','/images/bg/basket/nextbtn_f3.gif','/images/bg/basket/previousbtn_f2.gif','/images/bg/basket/previousbtn_f3.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r1_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r3_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r5_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r7_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r9_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r11_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r13_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r15_c1_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r17_c2_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r19_c2_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r21_c2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r23_c2_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r25_c2_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r27_c2_f2.gif','/images/general_images/blacknavbar/fmagNAVbarBLACK_r29_c2_f2.gif');
				break;
		}

//		if(document.location.search.toLowerCase().indexOf("display=2") == -1)
//			toggleVisibility("divBottomText", true);
	}


	function productPopup(pageURL, strOpener){
		var productpop = window.open(pageURL, 'productpop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=no,width=610,height=400,top=100,left=100');

		productpop.name					=	"productpop";
		productpop.opener					=	this.window;
		productpop.opener.name			=	strOpener;
		productpop.opener.productpop	=	productpop;

		return false;
	}


	// ------------------------------------------------------------------------
	//  productinfo.asp functions
	// ------------------------------------------------------------------------

	function miniPopup(pageURL, strOpener){
		if(strOpener == null)
			strOpener = "main";

		if(pageURL.indexOf("http") == -1){
			if(pageURL.indexOf("/") != 0)
				delim = "/";
			else
				delim = "";
			pageURL = delim + pageURL;
		}

		var minipop = window.open(pageURL, 'minipop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=yes,width=500,height=600,top=150,left=150');

		minipop.name				=	"minipop";
		minipop.opener				=	this.window;
		minipop.opener.name		=	strOpener;
		minipop.opener.minipop	=	minipop;

		return false;
	}

	function productOnload(){

		if(window.opener && window.opener.closed ==false){
			self.name	= "productpop";
			productpop	= this.window;
			main			= window.opener.main;
		}
		MM_preloadImages('/images/bg/basket/addtobasket_f3.gif','/images/bg/basket/addtobasket_f2.gif','/images/bg/basket/addtowishlist_f3.gif','/images/bg/basket/addtowishlist_f2.gif','/images/bg/basket/submitrevbut_f3.gif','/images/bg/basket/submitrevbut_f2.gif');
		this.focus();

	}



	// ------------------------------------------------------------------------
	// basket.asp functions
	// ------------------------------------------------------------------------

	function basketOnload(isUnfocus){
		MM_preloadImages('/images/bg/basket/contshopbtn_f3.gif','/images/bg/basket/contshopbtn_f2.gif','/images/bg/basket/updatebsktbtn_f3.gif','/images/bg/basket/updatebsktbtn_f2.gif','/images/bg/basket/checkoutbtn_f3.gif','/images/bg/basket/checkoutbtn_f2.gif','/images/bg/basket/savebsktbtn_f3.gif','/images/bg/basket/savebsktbtn_f2.gif');

		if(window.opener && window.opener.closed ==false){
			self.name	=	"minipop";
			minipop		=	this.window;
		}

		if(isUnfocus){
			//closeProductpop();
			setTimeout("this.window.blur()", 100);

		}else{
			this.window.focus();
		}
	}

	function updateCart(isContinueShopping){
		if(isContinueShopping)
			document.myform.unfocus.value = 1;
		document.myform.submit();
		return false;
	}

	function continueShopping(){
		self.blur();
		if(window.main)
			window.main.focus();
		return false;
	}

	// ------------------------------------------------------------------------
	// customeraccount.asp functions
	// ------------------------------------------------------------------------

	function orderdetailPopup(pageURL){
		var orderdetailPop = window.open(pageURL, 'orderdetailPop', 'toolbars=no,scrollbars=yes,location=no,statusbars=no,menubars=no,resizable=yes,width=500,height=600');
		return false;
	}

	function addressPopup(ival, opener, ischeckout, height, corner){
		if(opener == null)
			opener = "main";
		if(height == null)
			height = 530;
		if(corner == null)
			corner = 150;
		if(ischeckout == null)
			ischeckout = false;

		if(ival != ""){
			pageURL	=	"/customers/address_edit.asp?aid="+ ival;

			if(ischeckout){
				pageURL = (pageURL + "&ischeckout=1");
			}

			var addressPop = window.open(pageURL, 'addressPop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=yes,width=600,height='+height+',top='+corner+',left='+corner);
			addressPop.opener = this.window;
			addressPop.opener.name = opener;
			//document.location.href = pageURL;

		}
		return false;
	}

	function addressListPopup(ischeckout){
		if(opener == null)
			opener = "main";
		if(ischeckout == null)
			ischeckout = false;

		pageURL	=	"/customers/address_list.asp";

		if(ischeckout){
			pageURL = (pageURL + "?ischeckout=1");
		}

		//var addressPop = window.open(pageURL, 'addressPop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=yes,width=600,height=500,top=150,left=150');
		//addressPop.opener = this.window;
		//addressPop.opener.name = opener;
		document.location.href = pageURL;
		return false;
	}

	function emailProcess(f){
		miniPopup("about:blank");
		f.submit();
	}



	// ------------------------------------------------------------------------
	// general functions
	// ------------------------------------------------------------------------


	function closeAndRefresh(){
		if(this.window.opener != null){
			this.window.opener.history.go(0);
			setTimeout("this.window.close()", 2500);
		}
	}

	function closeAndRedirect(win, urlstr){
		alert(urlstr);
		if(this.window.opener != null){
			this.window.opener.document.location.href = urlstr;
			setTimeout("this.window.close()", 2500);
		}
	}

	function checkoutAndClose(){
		mainGoto("/asp/checkout_process.asp?act=add");
	}

	function mainGoto(urlstr){

		window.open(urlstr,"main");
		return false;
	}

	function closeAll(){
		closeMinipop();
		//closeProductpop();
		closeExitpop();
		self.focus();

	}
	function closeMinipop(){
		mp	=	window.open("","minipop","toolbars=no,scrollbars=no,location=no,status=no,menubars=no,resizable=no,width=10,height=10,top=-5000,left=5000");
		if(mp){
			mp.blur();
			mp.close();
		}
	}
	function closeProductpop(){
		return;
	}
	function closeExitpop(){
		ep	=	window.open("","exitPop","toolbars=no,scrollbars=no,location=no,status=no,menubars=no,resizable=no,width=10,height=10,top=-5000,left=5000");
		if(ep){
			ep.blur();
			ep.close();
		}
	}

	function areaMaxlength(field,maxlimit) {
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
	}

	function warnIfErrors(optStr){

		if(optStr == null)
			optStr = "";

		qs = document.location.search.toString();
		if(qs.length > 1 && qs.indexOf("?err=") != -1){
			errfields	=	qs.substring(5);
			errfieldsA	=	errfields.split(",");

			if(optStr != "none")
				alert("It appears that some information has not been entered correctly.\nPlease check the fields marked 'Please complete this field' and try again."+ optStr);
			if(document.forms[0].elements[errfieldsA[0]])
				document.forms[0].elements[errfieldsA[0]].focus();

		}
	}


	function vocalconnect_popup(companyid, zoneid, configid, subject) {
		window.open("http://www.vocalconnect.com/user.vox?CompanyID="+companyid+"&ZoneID="+zoneid+"&ZoneConfigID="+configid+"&Subject="+escape(subject),"_blank","width=580,height=419,directories=0,hotkeys=0,location=0,menubar=0,resizable=0,scrollbars=0,statusbar=0,toolbar=0");
	}

	function toggleVisibility(strTagId, boolShow) {
		obj = getTag(strTagId);

		if(obj && obj.style){
			obj = obj.style;
			if(boolShow === true){
				node	=	obj.display	=	"";
			}else if(boolShow === false){
				node	=	obj.display	=	"none";
			}else{
				if(obj.display == "")
					node	=	obj.display	=	"none";
				else
					node	=	obj.display	=	"";
			}
		}
	}


	function getTag(strTagId){
		var obj;
		if(document.getElementById && document.getElementById(strTagId) != null)
			obj	=	document.getElementById(strTagId);
		else if(document.layers && document.layers[strTagId] != null)
			obj	=	document.layers[strTagId];
		else if(document.all)
			obj	=	document.all[strTagId];
		return obj;
	}






var expDays = 30; // number of days the cookie should last

var page = "/homepage-popup.asp";
var windowprops = "width=400,height=400,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
	var count = GetCookie('count')
	if(count == null) {
		SetCookie('count','1')
		return 1
	}else{
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
	}
}
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
	var count = GetCookie('count');
	if (count == null) {
		count=1;
		SetCookie('count', count, exp);

//		adWin = window.open(page, "adWin", windowprops);

	}else{
		count++;
		SetCookie('count', count, exp);
	}
}

function math_round(expression, decimalPlaces, minDecimalPlaces){

	var multiplier = 1;

	if(decimalPlaces != null && decimalPlaces != 0)
		multiplier = Math.pow(10, decimalPlaces);

	strExpression	=	String(expression);

	if(strExpression.indexOf(",") > -1)
		expression	=	strExpression.replace(/,/g, "");

	if(isNaN(parseFloat(expression)))
		expression	=	0;

	var retVal = (Math.round(expression * multiplier) / multiplier);

	if (minDecimalPlaces)
	{
		if (String(retVal).indexOf(".") < 0)
			retVal += ".";
		decPart = String(retVal).replace(/(.*)\./,"");
		if (decPart.length < minDecimalPlaces){
			decPart = padNumber(decPart, minDecimalPlaces, true);
		}
		return String(RegExp.$1 +"."+ decPart);
	}
	else
		return retVal;
}

// FORMAT THE NUMBER TO SHOW 2 DIGITS PAST THE DECIMAL PLACE
//
function priceFormat(n, isSplitThousands){

	var n,nstr;

	n		=	math_round(n,2)+.001;
	nstr	=	String(n);
	nstr	=	nstr.substring(0, nstr.indexOf(".") + 3);
	if(!isSplitThousands)
		return nstr;
	else
		return (splitThousands(nstr, ",", 2));

}

// RETURNS A STRING REPRESENTATION OF A NUMBER PADDED TO APPROPRIATE LENGTH
// IF ORIGINAL LENGTH > DESIREDLENGTH, RETURNS TRUNCATED NUMBER REPRESENTATION
//
function padNumber(num, desiredLength, padBehind, padChar){
	var num = String(num);
	var length = num.length;
	var dLength = desiredLength - length;
	var addStr = '';
	var retVal = '';

	if (!padChar)
		padChar = '0';

	if (dLength <= 0)
	{
		if (padBehind)
			retVal = num.substring(0, desiredLength);
		else
			retVal = num.substring(length - desiredLength);
	}
	else
	{
		for (var i = 0; i < dLength; i ++)
			addStr += padChar;
		if (padBehind)
			retVal = num.concat(addStr);
		else
			retVal = addStr.concat(num);
	}
	return retVal;
}


// RETURN NULL IF THE STRING'S VALUE IS UNDEFINED, EMPTY, OR NULL
//
function testNullString(str, strAltReturn){
	var str	=	String(str);
	var strAltReturn;

	if(strAltReturn == undefined || strAltReturn == null)
		strReturn	=	null;
	else
		strReturn	=	strAltReturn;

	if(str == "undefined" || str == "null" || str == "")
		return strReturn;
	else
		return str;
}



// FORMAT INPUT NUMBER USING SEPARATOR TO MARK THOUSANDS
//
function splitThousands(input, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives){
	var retVal = numberFormat(input, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives);
	return testNullString(retVal, "");
}
function numberFormat(origInput, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives) {

	if(origInput){

		var decSeparator ="."
		var strSeparator	=	",";
		if (origInput.indexOf(decSeparator) < 0 && numDigitsAfterDecimal)
			origInput += '.';

		var input		=	testNullString(origInput, "0");
		var intPart		=	numDigitsAfterDecimal ? origInput.replace(/\.\d*$/, "").replace(/\D/g, "") : Math.abs(math_round(origInput));
		var decimalPart	=	numDigitsAfterDecimal ? origInput.replace(/^.*\./, "").replace(/\D/g, "") : "";//make it a number like 0.232
		var output		=	"";

		if(!math_round(intPart)){
			if(!incLeadingDig)
				intPart = "";
			else
				intPart = "0";
		}else{

			intPart = String(intPart);

			for(var counter = intPart.length; counter > 0; counter--){
				output = ((counter != 1 && counter != intPart.length + 1 && (intPart.length - counter + 1) % 3 == 0) ? strSeparator : "" ) + intPart.charAt(counter - 1) + output;
			}
		}

		if (numDigitsAfterDecimal){
			if(math_round(decimalPart))
				decimalPart = math_round(decimalPart * Math.pow(10, numDigitsAfterDecimal - String(decimalPart).length));
			else
				decimalPart = String(Math.pow(10, numDigitsAfterDecimal)).substring(1);

			output += decSeparator + decimalPart;
		}

		//handle how negative numbers are displayed
		if (testNullString(origInput,"").search(/^-/) != -1 && output){
			if(parenForNegatives)
				output = "("+(output.replace(/-/,""))+")";
			else
				output = "-"+output;//add negative sign back if necessary
		}

		return output;
	}
	return;
}

function searchSwitch(formName,onOffArray,hiddenElementArray){
		/* this funciton is to set the hidden variables used to change the view options
		and set the classes for the search results modfication buttons on the search results and category pages.
		A few implied items are.
		  1. The form of formName has a hidden value of hiddenElement and hiddenElement'_prev'
			2. onOffArray is a 1x3 arrar where the first element is the 'on' class name and second element is the 'off' class name.  Third Element is the ID of html object to be turned on.
				onOffArray[0] = 'range1';  /on
				onOffArray[1] = 'range6';  /off
				onOffArray[2] = 'price20'; /id of newly pushed button
			3. hiddenElementArray is a 1x3 array with the name of the hidden form element used in the search results and the value.  Third element is the name of the hidden input which houses the current selected button
			  hiddenElementArray[0] = "pageCount"; // Search param field name also the name of hidden form field name
				hiddenElementArray[1] = 20; // Value of the above param
				hiddenElementArray[2] = 'currPageCountID';  // Name of Hidden form field housing the name of current button that is on. current

		*/
		var prevHighlightedButton;

		eval("prevHighlightedButton = document."+formName+"."+hiddenElementArray[2]+".value");
		document.getElementById(prevHighlightedButton).className = onOffArray[1];
		eval("document."+formName+"."+hiddenElementArray[0]+ ".value="+hiddenElementArray[1]);
		eval("document."+formName+"."+hiddenElementArray[2]+".value='"+onOffArray[2]+"'");
		document.getElementById(onOffArray[2]).className= onOffArray[0];

	//	return false;
	}

/* Modal Popup V2 */
//	select all the a tag with name equal to modal
//	Note this is a duplicate of the function in the checkout
function showPopupDialog(id) {
	//Cancel the link behavior
	//e.preventDefault();

	//Get the A tag
	//var id = $j(this).attr('href');

	//Get the screen height and width
	var maskHeight = $j(document).height();
	var maskWidth = $j(window).width();

	//Set height and width to mask to fill up the whole screen
	$j('#mask').css({'width':maskWidth,'height':maskHeight});

	$j('#boxes').show();

	//transition effect
	$j('#mask').fadeIn(500);
	$j('#mask').fadeTo(500,0.8);

	//Get the window height and width
	var winH = $j(window).height();
	var winW = $j(window).width();

	//Set the popup window to center
	$j(id).css('top',  Math.min(100, winH/2-$j(id).height()/2));
	$j(id).css('left', winW/2-$j(id).width()/2);

	//transition effect
	$j(id).fadeIn(1000);
}

function hidePopupDialog() {
	//Cancel the link behavior
	//e.preventDefault();

	$j('.window').fadeOut();
	$j('#mask').fadeOut('slow', function() { $j('#boxes').hide(); });
}


/* #################################################### Scrolling User Comments #################################################### */

var nextBox, scrollTimer, scrollBoxHeight;

function scrollText()
{
	var box;

	if (nextBox == 2)
		box = $j("#scrollInnerBox1");
	else
		box = $j("#scrollInnerBox2");

	var scrollPos = box.scrollTop();
	box.scrollTop(scrollPos+1);
	if (box.scrollTop() == scrollPos) // if at bottom
	{
		clearInterval(scrollTimer);
		setTimeout("scrollBox()",5000);
	}
}

function scrollBox()
{
	var box1 = $j("#scrollInnerBox1");
	var box2 = $j("#scrollInnerBox2");
	var boxes = $j("#scrollInnerBox1,#scrollInnerBox2");
	var enclosingBox = $j("#scrollBox");
	var winHeight = jQuery(window).height();
	var winTop = jQuery(window).scrollTop();
	var scrollerTop = enclosingBox.offset().top;

	if (scrollerTop < winTop+winHeight && winTop < scrollerTop + scrollBoxHeight) // no point hitting the database if its not in view
	{
		if (nextBox == 2)
		{
			box2.load('/asp/ajax_user_comment.asp?i='+Math.random());
			boxes.animate({top:'-='+scrollBoxHeight},500,function(){box1.css("top",scrollBoxHeight+"px");box1.html("");});
			nextBox = 1;
		}
		else
		{
			box1.load('/asp/ajax_user_comment.asp?i='+Math.random());
			boxes.animate({top:'-='+scrollBoxHeight},500,function(){box2.css("top",scrollBoxHeight+"px");box2.html("");});
			nextBox = 2;
		}
	}

	setTimeout("startTextScroll()",5000);
}

function startTextScroll()
{
	scrollTimer = setInterval("scrollText()",100);
}

var nextDayDeliveryByHour				= 9;

/* #################################################### Inline Basket #################################################### */

var basketTimer					= setTimeout("", 0);
var basketShown					= true;
var basketTimerRunning			= false;
var basketAnimationRunning		= false;
var basketItems					= {};							//Placeholder variable to hold the baskets content
var basketLastAddedItem			= 0;

var deliveryByTimer				= setTimeout("", 0);
var bankHolidays				= "";
var showB49delivery				= false;


jQuery(document).ready(function() {
	//NOTE: The binding of clicks is also done in site_media/js/productinfo.js

	//Get any inline 'Buy' Buttons
	jQuery('.a2b-inline').each(function() {
		jQuery(this).click(function (event) {
			event.preventDefault();								//Stop the href click

			var linkObj = new Object();							//Get the url variables
			jQuery(this).attr('href').replace(
				new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
				function( jQuery0, jQuery1, jQuery2, jQuery3 ){
					linkObj[ jQuery1 ] = jQuery3;
				}
			);

			addToInlineBasket(linkObj);							//Post the product to the add to basket
		});
	});

	//Add the hover function to the header and the inline basket
	jQuery("#side-basket-header, #inline-basket").hover(function() {
		if (isEmpty(basketItems))
			loadInlineBasket(0);
		else
			maximizeInlineBasket();
	},function() {
		startCloseTimer(1000);
	});
});

//Adds a product to the basket using Ajax (uses the existing cart process page)
function addToInlineBasket(postData) {
	jQuery.ajax({
		url: "/asp/cart_process.asp?ajax=true",
		data: postData,
		type: "POST",
		cache: false,
		success: function(data){
			minimizeInlineBasket();								//Make sure the basket is closed before reloading it (the highlighting animation wont work otherwise)
			//Focus on the Inline Basket if its not fully on screen
			var windowOffset	= window.pageXOffset;
			var windowWidth		= jQuery(window).width();
			var pageWidth		= jQuery("#page-holder").width();
			window.scrollTo(((windowOffset+windowWidth > pageWidth) ? windowOffset : pageWidth-windowWidth),((window.pageYOffset < 200) ? window.pageYOffset : 140));

			loadInlineBasket(postData.id);						//Load the inline basket
		},
		error: function(data1, data2) {
			alert("There has been a problem adding this item to your basket.");
		}
	});
};

//Gets the contents of the current users basket and update the mini and inline basket
function loadInlineBasket(productId) {
	jQuery.ajax({
		url: "/asp/ajax_basket_details.asp?id="+productId,		//ProductId is so we can return which element in the list we should highlight as 'New'
		type: "GET",
		cache: false,
		dataType: "json",
		success: function(data){
			var freeShipMin		= parseFloat(data.freeShipping);
			var basketTotal		= parseFloat(data.totalcost);
			var strCheckout		= testNullString(data.dev,"https://www.find-me-a-gift.co.uk/secure");
			bankHolidays		= data.bankHolidays;
			showB49delivery		= eval(data.showB49delivery);
			jQuery("#basket-panel .basket-price").html(data.total);								//Update the total number of items
			jQuery("#basket-panel .basket-total-price").html("&pound;"+basketTotal);				//Update the total cost

			basketItems			= eval("("+data.items+")");									//Save all the items into our global basketItems object
			if (productId > 0)
				basketLastAddedItem	= data.highlightItem;									//Save the last added item into our global variable

			if (typeof basketItems == "string") {
				//Load the empty inline basket into the place holder
				var inlineBasket	= "	<div id=\"basket-container\">"+
										"		<img onclick=\"javascript:minimizeInlineBasket();\" src=\"/site_media/images/buttons/exit.png\" width=\"24\" height=\"24\" id=\"inline-close\" alt=\"Close\" title=\"Close\">"+
										"		<div class=\"basket-empty\">"+
										"			Your Basket is Empty</span>"+
										"		</div>"+
										"		<div class=\"clear\"> </div>"+
										"</div>";

				jQuery("#inline-basket").html(inlineBasket);
				maximizeInlineBasket();							//Start the opening animation
				startCloseTimer(1000);							//Start the close timer (short delay)

			} else {
				//Load the inline basket into the place holder
				//	Note: there are no items in it at this time
				var inlineBasket	= "	<div id=\"basket-container\">"+
										"		<img onclick=\"javascript:minimizeInlineBasket();\" src=\"/site_media/images/buttons/exit.png\" width=\"24\" height=\"24\" id=\"inline-close\" alt=\"Close\" title=\"Close\">"+
										"		<ul id=\"inline-basket-products\" class=\"jcarousel jcarousel-skin-inline\"></ul>"+
										"		<div id=\"below-basket\">"+
										"			<div id=\"email-basket\"><a href=\"javascript:emailBasket();\">Email Basket</a></div>"+
										"			<div id=\"basket-totals\">"+
										"				TOTAL:<span id=\"tc\">&pound;"+data.totalcost+"</span>"+
										"			</div>"+
										"			<div id=\"delivery\">"+((freeShipMin > basketTotal) ? "Just <b>&pound;"+priceFormat(freeShipMin-basketTotal)+"</b> more for FREE UK DELIVERY" : "<span class=\"color-orange\">Order qualifies for FREE UK DELIVERY</span>")+"</div>"+
										"			<div id=\"basket-buttons\">"+
										"				<a href=\""+strCheckout+"/checkout/init_checkout.asp?act=add&gco=0\"><img src=\"/site_media/images/view_basket/btn_checkout_inline.png\" width=\"117\" height=\"28\" alt=\"Checkout\" title=\"Checkout\" style=\"float:right\"></a>"+
										"				<a href=\"/basket.asp?bt=mbvb\"><img src=\"/site_media/images/view_basket/btn_edit_inline.png\" width=\"117\" height=\"28\" alt=\"Edit Basket\" title=\"Edit Basket\"></a>"+
										"			</div>"+
										"		</div>"+
										((showB49delivery) ? "		<div id=\"delivery-by\">"+getDeliveryByTime()+"</div>" : "")+
										"		<div class=\"clear\"> </div>"+
										"</div>";

				jQuery("#inline-basket").html(inlineBasket);
				maximizeInlineBasket();							//Start the opening animation
				startCloseTimer(3000);							//Start the close timer (long delay)

				//Intiate jcarousel
				jQuery('#inline-basket-products').jcarousel({
					vertical: true,								//Vertical Scrolling
					scroll: 1,									//Scroll one at a time
					start: ((basketLastAddedItem > 3) ? basketLastAddedItem : 1),	//Make sure the item we just added is visible
					initCallback: loadCarouselItems,			//Once loaded - Add the items into it
					itemFallbackDimension: '82px'
				});

				jQuery('.jcarousel-item').hover(function() {			//Add hover effect to all the items (Can't be done with a .live() call)
					jQuery(this).addClass("hoverHighlight");
				}, function() {
					jQuery(this).removeClass("hoverHighlight");
				});

				jQuery('.removeItem').each(function() {					//Disable onclick for a product if the remove from basket button is clicked
					jQuery(this).click(function (event) {
						jQuery(this).parent("div").attr('onclick','').unbind('click');
					});
				});
			}

		},
		error: function(data1, data2) {
			window.location = "/basket.asp?bt=a2b"				//If it falls over goto basket to display items!
		}
	});

};

//Is my object Empty?
function isEmpty(ob){
		for(var i in ob){ return false;}
	return true;
};

//Add all the basket items into the carousel
function loadCarouselItems(carousel, state) {
	var i = 0;
	//Add all the items into the array from our global basketItems object
	jQuery.each(basketItems, function(key, val) {
		carousel.add(i+1, getItemHTML(val));					//Carousel Array starts at position 1
		i ++;
	});
	carousel.size(i);

	//If we don't have 3 items we need to change the height of the carousel
	if (i < 3) {
		jQuery(".jcarousel-skin-inline .jcarousel-container-vertical").css({'height':(i*110)+'px'});
		jQuery(".jcarousel-skin-inline .jcarousel-clip-vertical").css({'height':(i*110-10)+'px'});
	}
};


//Format the item data into the inline basket style
function getItemHTML(item) {
	return "			<div id=\"item_"+item.pos+"\" class=\"basket-product"+((item.url != "") ? " clickable\" onclick=\"window.location='"+item.url+"'\"" : "\"")+" title=\"View "+item.title+"\">"+
					"				<img src=\"/site_media/images/buttons/exit_sml.png\" width=\"24\" height=\"24\" alt=\"Remove From Basket\" title=\"Remove From Basket\" class=\"clickable removeItem\" onclick=\"removeFromBasket('"+item.id_str+"');\" />"+
					"				<img src=\""+item.image+"\" width=\"80\" height=\"80\" alt=\"\" title=\"\" />"+
					"				<div class=\"price\" style=\"font-weight:bold;\"><b>&pound;"+item.price+"</b></div>"+
					"				<div class=\"title\">"+item.title+"</div>"+
					((item.personalize) ? "				<div class=\"personalize\">"+item.personalize+"</div>":"")+
					"				<div>Qty: "+item.qty+"</div>"+
					"				<div class=\"clear\"> </div>"+
					"			</div>";
};


//Timer which closes and then hides the inline basket
function startCloseTimer(delay) {
	if (basketShown) {						//This extra check is required because the on mouse out event is fired after the close button is clicked
		basketTimerRunning			= true;
		clearTimeout(basketTimer);			//This ensures that any previous basket timer doesn't run
		basketTimer					= setTimeout(function(){
											basketTimerRunning				= false;
											basketAnimationRunning			= true;
											jQuery("#inline-basket").animate({opacity:0},1500,function() {
												basketAnimationRunning		= false;
												minimizeInlineBasket();					//Once faded out return to its 'closed' state
											});
										}, delay);
	}
};


//Set to the default 'closed' state for the inline basket
function minimizeInlineBasket() {
	basketShown					= false;
	basketTimerRunning			= false;
	basketAnimationRunning		= false;
	clearTimeout(basketTimer);
	//Reset opacity to 1 and size of 0 so next time we show it that we expand it from top right corner
	//	Note: Set display:none otherwise it reappears at the side of the scereen after the animation completes!!!!
	jQuery("#inline-basket").stop(true).css({width:'0px',height:'0px',display:'none',opacity:1});
};


function maximizeInlineBasket() {
	//Clear the timer and stop any animation
	basketShown					= true;
	clearTimeout(basketTimer);
	jQuery('#inline-basket').stop(true);

	//If the animation is running then restore to fully displayed state
	if (basketAnimationRunning) {
		jQuery('#inline-basket').css({width:'272px',height:'640px',opacity:1,display:'block'});
		higlightInlineItem();

	//If the timer is not running (therefore it must be fully closed) then animate displaying it
	} else if (!basketTimerRunning) {
		basketAnimationRunning	= true;
		jQuery('#inline-basket').animate({width:'272px',height:'640px'},500, function() {
			basketAnimationRunning		= false;
			higlightInlineItem();
		});
	} else {
		higlightInlineItem();
	}

	if (showB49delivery)
		updateDeliveryByTime();			//If before 9 delivery available run the timer
};

//Highlight the newest added item to the basket
function higlightInlineItem() {
	if (basketLastAddedItem > 0) {

		jQuery(".jcarousel-item").stop(true);								//Stop the previous animation
		jQuery(".jcarousel-item-"+basketLastAddedItem)						//Highlight the item we just added
			.css({'background-color':'white'})							//As the element has no current background colour add one (causes error in some browsers)
			.animate( { backgroundColor: 'highlight' }, 500)			//Fade to orange
			.animate( { backgroundColor: 'highlight' }, 400)			//Fade to orange (acts as a pause command)
			.animate( { backgroundColor: 'white' }, 800, function() {	//Fade back to white
				jQuery(this).css({'background-color':''});					//Remove background colour (so hover effect works again)
		});
	}
	basketLastAddedItem			= 0;
}

function removeFromBasket(productIdentifier) {
	jQuery.ajax({
		url: "/asp/cart_process.asp?ajax=true",
		data: "act=del&id="+productIdentifier,
		type: "POST",
		cache: false,
		success: function(data){
			basketLastAddedItem	= 0;
			loadInlineBasket(0);								//Load the inline basket
		},
		error: function(data1, data2) {
			alert("There has been a problem deleting this item from your basket.");
		}
	});
}


function updateDeliveryByTime() {
	var strDeliveryByTime		= getDeliveryByTime();
	jQuery("#delivery-by").html(strDeliveryByTime+"<br />choose UK next day delivery before 9am at checkout.");
	jQuery("#delivery-by-time").html(strDeliveryByTime+" and choose UK Next working day before 9am delivery at checkout.");

	//If the timer is not running then start the time out
	if (deliveryByTimer == undefined) {
		if (jQuery('#delivery-by').length > 0 || jQuery('#delivery-by-time').length > 0) {
			deliveryByTimer			= setInterval(function(){
											updateDeliveryByTime();
										}, (10*1000));		//reload timer every 10 seconds
		}
	}
}

function getDeliveryByTime() {
	var monthList				= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var oneDay					= (24*60*60*1000);		//24 hours in miliseconds

	//var dtToday = new Date(Date.parse("Oct 28, 2011 16:05:00"));
	var dtToday = new Date();
	var dtDeliverBy = new Date(dtToday.getTime() + oneDay);
	var dtOrderBy = new Date(dtToday.getTime());
	dtDeliverBy = checkDates(dtDeliverBy);

	//If its after 4pm add an extra day
	if (dtToday.getHours() >= nextDayDeliveryByHour) {
		dtDeliverBy = checkDates(new Date(dtDeliverBy.getTime() + oneDay));
		dtOrderBy = new Date(dtOrderBy.getTime() + oneDay);
	}

	dtOrderBy.setHours(nextDayDeliveryByHour);
	dtOrderBy.setMinutes(0);
	dtOrderBy					= checkDates(dtOrderBy);

	var dateDiff				= (dtOrderBy - dtToday)/(1000*60);					//In minutes
	var daysDiff				= Math.floor(dateDiff/(24*60));
	var hoursDiff				= Math.floor((dateDiff % (24*60))/60);
	var minutesDiff				= dateDiff % 60;

	return "<b>Want delivery on "+dtDeliverBy.getDate()+" "+monthList[dtDeliverBy.getMonth()]+" before 9am?</b><br />"+
			"Order in the next <b>"+((daysDiff>0) ? daysDiff+" day"+((daysDiff==1) ? "" : "s")+", " : "")+hoursDiff+" hour"+((hoursDiff==1) ? "" : "s")+" and "+minutesDiff+" minute"+((minutesDiff==1) ? "" : "s")+"</b>";
}

function checkDates(dateToCheck) {
//For some reason this function in asp will swap the date to UTC format after the second loop through!! (fortunatly its not causing any issues as at this point we don't care about the time
	var year					= dateToCheck.getYear();
	var month					= dateToCheck.getMonth() + 1;
	var date					= dateToCheck.getDate();

	var key						= "|"+ (year +"-"+ padNumber(month, 2) +"-"+ padNumber(date, 2)) +"|";

	if (String(bankHolidays).indexOf(key) > -1 || dateToCheck.getDay() == 0 || dateToCheck.getDay() == 6)
		return checkDates(new Date(dateToCheck.getTime() + (24*3600000)));

	return dateToCheck;
}


function emailBasket() {
			showPopupDialog('#dialog');
			//openDialog('#popupLayer');
			jQuery('#dialog').load('/modules/email_basket.asp');
			jQuery('#mask').bind('click', function() {
				hidePopupDialog();
			});
}

