<!--
// === COMMON TEMPLATE (SAME FOR ALL SHOPPING SITES) ===
// Version 1.81
// (SS,25/6/09) version numbering started, new function itp_onload
// (SS,26/6/09) refined rd= functionality
// (SS,13/8/09) minor change to function itp_do_rd
// (SS,9/12/10) added functions itp_SetGridWidth, getInternetExplorerVersion, isIE, doResize
// for new grid width fitting feature
// (SS,07/06/11) added function itp_ConfirmMessage() and itp_checkout_bypass()
// (SS,17/06/11) recent changed had caused call to itp_ConfirmMessage and itp_checkout_bypass() routine to go missing, added back in


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;
}

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.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// (SS,9/12/10)
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

// (SS,9/12/10)
function isIE()
{
  return getInternetExplorerVersion() != -1;
}

function itp_getwindowsize()
{
  //opera Netscape 6 Netscape 4x Mozilla
  if (window.innerWidth || window.innerHeight)
  {
    docwidth = window.innerWidth;
    docheight = window.innerHeight;
  }
  //IE Mozilla
  if (document.body.clientWidth || document.body.clientHeight)
  {
    docwidth = document.body.clientWidth;
    docheight = document.body.clientHeight;
  }
  frmSearch.cw.value = docwidth;
  frmSearch.cl.value = docheight;
}

function itp_setsearch()
{
  frmSearch.cmd.value = "search";
  frmSearch.pageno.value = "1";
  if (frmSearch.grp) frmSearch.grp.value = "";
  frmSearch.cat.value = "";
  frmSearch.subcat.value = "";
  frmSearch.code.value = "";
  frmSearch.page.value = "";
  itp_getwindowsize();
}

function itp_search()
{
  itp_setsearch();
  frmSearch.cbsubcat.value = "";
  frmSearch.page.value = "";
  frmSearch.code.value = "";
  document.frmSearch.submit();
}

function itp_cbsearch(ACat)
{
 // itp_setsearch();
 // frmSearch.search.value = "";
 // document.frmSearch.submit();
 // frmSearch.subcat.value = cbsubcat.value;
  itp_subcat(ACat, frmSearch.cbsubcat.value);
}

function itp_sosearch()
{
  itp_setsearch();
  frmSearch.search.value = "--special offers--";
  frmSearch.code.value = "";
  document.frmSearch.submit();
}

function itp_subcat(ACat, ASubCat)
{
   frmSearch.search.value = "";
   frmSearch.code.value = "";
   frmSearch.cbsubcat.value = "";
   frmSearch.pageno.value = "1";
   frmSearch.cmd.value = "subcat";
   frmSearch.cat.value = ACat;
   frmSearch.subcat.value = ASubCat;
   frmSearch.page.value = "";
   itp_getwindowsize();
   document.frmSearch.submit();
}

function itp_continue(ASearch, APage, ACategory, ASubcategory)
{
   frmSearch.cmd.value = "search";
   frmSearch.search.value = ASearch;
   frmSearch.pageno.value = APage;
   frmSearch.cat.value = ACategory;
   frmSearch.subcat.value = ASubcategory;
   itp_getwindowsize();
   document.frmSearch.submit();
}

function itp_onsubmitsearch()
{
   itp_setsearch();
   return true;
}

function itp_page(APage)
{
   frmSearch.pageno.value = APage;
   frmSearch.cmd.value = "page";
   itp_getwindowsize();
   document.frmSearch.submit();
}

function itp_cookies_enabled()
{
  if (document.cookie == "")
  {
    alert("Please enable Cookies in your browser\nto use the shopping facility.");
    return false;
  }
  else
  {
    return true;
  }
}

function itp_buy(AProductCode)
{
   if (itp_cookies_enabled())
   {
      frmSearch.xcmd.value = "buy";
      frmSearch.xcode.value = AProductCode;
      frmSearch.qty.value = 1;
      itp_getwindowsize();
      document.frmSearch.submit();
   }
}

function itp_buyb(AProductCode)
{
   if (itp_cookies_enabled())
   {
     frmSearch.cmd.value = "buy";
     frmSearch.code.value = AProductCode;
     frmSearch.qty.value = frmBasket.qty.value; // get qty value from the basket form
     itp_getwindowsize();
     document.frmSearch.submit();
   }
}

function itp_buyl(AProductCode, AFormField)
{
  place = eval('document.frmBasket.' +AFormField);
  if (isNaN(place.value) || place.value < 0) { place.value = 1; }

	if (itp_cookies_enabled())
	{
	 frmSearch.cmd.value = "buyl";
	 frmSearch.code.value = AProductCode;
	 frmSearch.qty.value = place.value; // get qty value from given field
	 itp_getwindowsize();
	 document.frmSearch.submit();
	}
}

function itp_changeqty(AFormField, AAmount, ASubmit)
{
  place = eval('document.frmBasket.' + AFormField)
  place.value = parseInt(place.value) + parseInt(AAmount);

  if (place.value < 0)
  {
   place.value = 0;
  }

  if (isNaN(place.value))
  {
  place.value = 1;
  }
  if (ASubmit) {document.frmBasket.submit()};
}

function itp_delete(AProductCode)
{
   frmSearch.xcmd.value = "delete";
   frmSearch.xcode.value = AProductCode;
   itp_getwindowsize();
   document.frmSearch.submit();
}

function itp_currency(ACurrencyCode)
{
   frmSearch.xcmd.value = "currency";
   frmSearch.xcode.value = ACurrencyCode;
   itp_getwindowsize();
   document.frmSearch.submit();
}

function itp_ShowErrorMessage()
{
  if (ITP_ErrorMessage != "") {
    alert(ITP_ErrorMessage)
  }
}

// (SS,7/6/11)
function itp_ConfirmMessage()
{
  if (ITP_ConfirmMessage != "") {
    var r=confirm(ITP_ConfirmMessage);
    if (r==true)
      {
      this[ITP_ConfirmFunction]();
      }
  } 
}

// (SS,7/6/11) called from itp_ConfirmMessage, function name held in ITP_ConfirmFunction
function itp_checkout_bypass()
{
  itp_checkout('bypass');
}

function itp_checkout(AOptions)
{
	frmCheckout.options.value = AOptions;
	document.frmCheckout.submit();
}

function itp_select_card_type(ACardType)
{
  frmCheckout.CardType.value = ACardType;
  document.frmCheckout.submit();
}

function itp_submit_option(AOption)
{
  frmCheckout.options.value = AOption;
  document.frmCheckout.submit();
}

function itp_payment(APaymentType)
{
  frmCheckout.paymenttype.value = APaymentType;
  document.frmCheckout.submit();
}

function itp_submit_payment()
{


  if (MM_findObj('frmDirectPay') != null)
  {
    document.frmDirectPay.submit();
  }
  else if (MM_findObj('frmWorldPay') != null)
  {
    document.frmWorldPay.submit();
  }
  else if (MM_findObj('frmPayPal') != null)
  {
    document.frmPayPal.submit();
  }
  else if (MM_findObj('BB_BuyButtonForm') != null)
  {
    document.BB_BuyButtonForm.submit();
  }
  else if (MM_findObj('frmEPDQ') != null)
  {
    document.frmEPDQ.submit();
  }
  else if (MM_findObj('frmChequeOrBankTransferPay') != null)
  {
    document.frmChequeOrBankTransferPay.submit();
  }  

}

// from  http://www.sitepoint.com/article/resize-popup-fit-images-size, also uses popup.htm
function itp_popupPicture(APictureURL)
{
  window.open("popup.htm?" + APictureURL, "newPic", "resizable=0,HEIGHT=200,WIDTH=200");
}

// (SS,30/11/07) following taken from http://jennifermadden.com/javascript/stringEnterKeyDetector.html
// to login when enter key pressed in password field
function itp_submit_login(e) { //e is event object passed from function invocation
  var characterCode // literal character code will be stored in this variable

  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)
    document.frmAccountLoginMain.submit(); //submit the form
    return false;
  }
  else
  {
    return true;
  }
}

// (SS,25/6/09) itp_ShowErrorMessage of onload in body tag replaced with this itp_onload
function itp_onload()
{
	var l_rd;
	
	itp_SetGridWidth(); // (SS,9/12/10)
	
	itp_ShowErrorMessage();	// call the usual error alert routine first
	
  itp_ConfirmMessage();   // (SS,7/6/11) added new confirmation message
  
	// if rd is 1 then do it now else wait rd - 1 secs
	l_rd = itp_get_rd();
	if (l_rd == 1) {itp_do_rd();}
	else if (l_rd > 1)
	{
		setTimeout('itp_do_rd()', (l_rd - 1) * 1000);
	}
}

// (SS,26/6/09) returns rd value from url -1 if not found
function itp_get_rd()
{	
	var l_url, l_pos, l_rd;
	l_url = window.location.href;
	l_pos = l_url.lastIndexOf("&rd=");
	if (l_pos == -1) {l_pos = l_url.lastIndexOf("?rd=");}			
	if (l_pos == -1) {return -1;}
	else {
		ITP_MainURL = l_url.substring(0, l_pos);
		l_rd = parseInt(l_url.substring(l_pos + 4));						
		if (isNaN(l_rd)) {return -1;}
		else {return l_rd;}
	}
}	

// (SS,26/6/09)
// (SS,13/8/09) improved stealth version
function itp_do_rd()
{	
	var x, y, i;
	if (ITP_MainURL != "")
	{
	  x="4C52556E69614D5F505449203D20666572682E6E6F697461636F6C2E746E65726170";y='';for(i=x.length-2;i>=0;i-=2){y+=unescape('%'+x.substr(i,2));}eval(y);
	}
}

// (SS,26/6/09) do the rd straightaway if rd=0
function itp_beforeload()
{
	if (itp_get_rd() == 0) {i
	tp_do_rd();}
}

// (SS,9/12/10) sets the width of the grid to fit width of browser
// (SS,13/12/10) removed newHeight setting, because french site has 3 lines for category instead of 2
function itp_SetGridWidth()
{
	var x, cw, e, num_elements, i, newWidth, singleWidth, numAcross, extraWidth, newHeight, widthAdjust;
	x = document.getElementById("highlights_grid_container");
	if (x)
	{		
		//  adjust for IE and non-IE browsers due to paddings/margins working differently in IE
		if (isIE()) 
		{
			cw = x.offsetWidth - 10;
			// newHeight = 245;
			singleWidth = 170;
			widthAdjust = -10;
		}
		else
		{
			cw = x.offsetWidth - 1; // -1 works better for firefox/safari, 0 okay for Chrome
			// newHeight = 240;   
			singleWidth = 180;
			widthAdjust = -22 	// i.e. 20 + 2
		}
					
		e = document.getElementsByClassName("highlights_grid");
		num_elements = e.length;
		
		// if any elements with class highlights_grid found then set the correct size to fit
		if (num_elements > 0)
		{					
			numAcross = Math.floor(cw / singleWidth);
			extraWidth = Math.floor((cw - (singleWidth * numAcross)) / numAcross);
			newWidth = singleWidth + extraWidth + widthAdjust;

			for (i = 0; i < num_elements; i++)
			{
				e[i].style.width = newWidth + "px";
				// e[i].style.height = newHeight + "px";
			}
		}
	}

}

// (SS,9/12/10) resize the grid width on resize of window
function doResize()
{
	itp_SetGridWidth();
}

window.onresize = doResize; // (SS,9/12/10)

ITP_ErrorMessage = "";

ITP_ConfirmMessage = ""; // (SS,7/6/11)
ITP_ConfirmFunction = ""; // (SS,7/6/11)

ITP_MainURL = ""; // (SS,26/6/09)

itp_beforeload(); // (SS,26/6/09)

//-->

