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_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}


function MM_findObj(n, d) { 
  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_validateForm() { 
if (form.btnContinueOrder == true)
{
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  }
}

function getEl(id) {
	// Helper to reduce typing
	return document.getElementById(id);
}

function checkPromotionCode(src, arg) {
	var i = getEl("txtPromotionCode").value.length;
	if (i != 0) {
		arg.IsValid = (i >= 10 && i <=15);
	} else {
		arg.IsValid = true;
	}
}

function checkHouseNumberOrName(src, arg){
	arg.IsValid = (getEl("txtHouseNumber").value.length != 0 || getEl("txtHouseName").value.length != 0);
}

function checkClubcardNumber(src, arg){
	arg.IsValid = (getEl("txtClubcardNumber").value.length >= 16 || getEl("txtClubcardNumber").value.length == 0);
}

function checkCreditCard(src, arg){
	arg.IsValid = (getEl("txtCardNumber").value.length == 16 || getEl("txtCardNumber").value.length == 18 || getEl("txtCardNumber").value.length == 19);
}

function checkSortCode(src, arg) {
	var sSortCode = getEl("txtSortCode1").value + getEl("txtSortCode2").value + getEl("txtSortCode3").value;
	arg.IsValid = (sSortCode.length == 6);
}

function checkSecurityCode(src, arg) {
	var sSortCode = getEl("Checkout:CardPaymentDetailsTemplate_SecurityCode").value;
	arg.IsValid = (sSortCode.length > 2);
}

function checkEmails(src, arg) {
	if (getEl("txtEmail").value.length != 0 && getEl("txtEmailConfirm").value.length != 0) {
		arg.IsValid = getEl("txtEmail").value == getEl("txtEmailConfirm").value;
	} else {
		arg.IsValid = true;
	}
}

function popup(url, windowName, width, height, top, left) {
	remote = window.open(url, windowName, "resizable=yes,toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,copyhistory=0,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",screeny=" + top + ",screenx=" + left);
	return false;
}

function checkTandC(src, arg)
{
	arg.IsValid = getEl("chkTerms").checked;
}

function checkEnter(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var src = evt ? (evt.target ? evt.target : evt.srcElement) : event.srcElement;

	if (evt) {
		var kc = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
		if (kc == 13) {
			switch (src.id.toLowerCase()) {			
				case "quicksearch_quicksearchaccessoriesid_txttextsearch" :
					getEl("QuickSearch_quicksearchAccessoriesID_btnTextSearch").click();	
					break;	
				case "quicksearch_quicksearchreconid_txttextsearch" :
				    getEl('QuickSearch_quicksearchReconID_btnTextSearch').click();
				    break;
				case "quicksearch_quicksearchathomeid_txttextsearch" :
				    getEl('QuickSearch_quicksearchAtHomeID_btnTextSearch').click();
				    break;			    
			}
		}		
	}
	if(window.event.keyCode == 13)
	{
		return false;
	}	
	return true;
}

function cleartextbox(textbox){
    textbox.value='';       
}

$(document).ready(function() {

//this solves the problem for the flash banner not loading because of the page was in a directory.
var path = document.location.pathname;
var dir = path.substring(path.indexOf('/', 1), path.lastIndexOf('/'));
var root = '';

//for every directory the page is in it will add a '../' to the root variable
//variable which will then be concatenated to the flash source variable

for (var i = 0; i < dir.length; i++)
{
 if (dir[i] == '/')
 root += '../';
}

	$('#flashPeel').flash(
	{
        src: (root + 'media/FlashPeel_v6.swf?V3'),
        width: 184,
        height: 94,
        wmode: 'transparent'
    });
    $('#top_banner').flash(
	{
        src: (root + 'media/top_banner.swf?V3'),
        width: 490,
        height: 80,
        wmode: 'transparent'
    });
    
        
    $('.shop-menu ul ul .selected').parent().find('ul').show();
    // accessories navigation
	//$('.shop-menu>ul>li:nth-child(1)>ul').accordion({ autoHeight:false, active: '.selected' });
    // business navigation
	//$('.shop-menu>ul>li:nth-child(4)>ul').accordion({ autoHeight:false, active: '.selected' });
	
	$('#countDown').flash(
        { src: base + 'xmas_09/countdown.swf?v=v2',
          width: 170,
          height: 110 },
        { version: 8 }
    );
    
    $('#flashPeeler').flash(
        { src: base + 'xmas_09/pre-calendar_peel.swf',
          width: 170,
          height: 98 },
        { version: 8 }
    );
    
	$("a#donate").bind("click", function() {
		$("#donate_form").submit();
		return false;
	});
	
		$("a.imagePop").fancybox({
		'overlayShow'			: false,
		'centerOnScroll'		: false,
		'hideOnContentClick'	: true,
		'autoScale'             : true,
		'hideOnOverlayClick'	: true,
		'overlayOpacity'		: 0.1,
		'frameWidth'  			: 600,
		'frameHeight'			: 600,
		'zoomSpeedIn'			: 200,
		'zoomSpeedOut'			: 500,
		'titlePosition'		    : 'inside',	
		'transitionIn'	        : 'none',
		'transitionOut'	        : 'none',
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack',
		'onStart'               : function() {
		    if (typeof(onFancyBoxStart) == 'function')
		    {
		        return onFancyBoxStart();
		    }
		}
		});	
		
});


