<!--

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_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_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 YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

/**************************************************************
 IsEmail: Returns a Boolean if the specified Expression is a
          valid e-mail address. If Expression is null, false
          is returned.

 Parameters:
      Expression = e-mail to validate.

 Returns: Boolean
***************************************************************/
function IsEmail(Expression)
{
	if (Expression == null)
		return (false);

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}

function FSfncCheckCCnum(FormField) {
	// Check credit/Maestro card number is in valid format
	var ccRE=/\W/gi;
	var CCnumber=FormField.value.replace(ccRE, "");
	if (isNaN(CCnumber)) {
		//alert("Credit card number is not numeric.");
		FormField.focus();
		return "Please check the credit card number entered as it should only contain numbers.";
	}
  if ((CCnumber.length!=16) && (CCnumber.length!=18) && (CCnumber.length!=19)) {
		//alert("Incorrect number of digits in credit card number.");
		FormField.focus();
		return "Please check the credit card number entered";
	}
	var cardMath=0;
	for (i=CCnumber.length; i>0; i--) {
		if (i % 2 == 1) {
			var doubled = "" + (parseInt(CCnumber.substring(i - 1, i)) * 2);
			if (doubled.length==2) {doubled = parseInt(doubled.substring(0,1)) + parseInt(doubled.substring(1,2))}
			cardMath += parseInt(doubled);
			}
		else {cardMath += parseInt(CCnumber.substring(i - 1, i))}
		}
	if (cardMath % 10 != 0) {
		//alert("Credit card number is invalid.");
		FormField.focus();
		return "Credit card number is invalid.";
	}
	return "";
}


// my functions
function bmbSetFocus(obj) {
	targetObj = MM_findObj(obj,"")
	targetObj.focus();
}

function bmbGetValue(objTarget) {
	targetObj = MM_findObj(objTarget,"")
	bmbValue = targetObj.value;
	return bmbValue;
}
function bmbSetValue(objTarget, bmbValue) {
	targetObj = MM_findObj(objTarget,"")
	if (targetObj != null) {
		targetObj.value = bmbValue;
	}
}

function bmbSetText(objTarget, bmbValue) {
	targetObj = MM_findObj(objTarget,"")
	targetObj.innerHTML = bmbValue;
}


function confirmDelete() {
	good2go = confirm("Are you sure?");
	if (good2go) {
		return true;
	}
	else {
		return false;
	}
}

function hideIt(obj) {
	targetObj = MM_findObj(obj,"")
	if (targetObj != null) {
		targetObj.style.display = "none";
	}
}

function showIt(obj) {
	targetObj = MM_findObj(obj,"")
  if (targetObj != null) {
  	targetObj.style.display = "";
  }
}

// functions for subscriptions Page2
function subscriptionsIndex_onload() {
	showOrHideDeliveryFields();
}

function showOrHideDeliveryFields() {
	if (bmbGetValue('selDifferentDeliveryDetails') == "Yes") {
		showIt('deliveryDiv');
	}
	if (bmbGetValue('selDifferentDeliveryDetails') == "No") {
		hideIt('deliveryDiv');
	}
}

function selDifferentDeliveryDetails_Changed(obj, value) {
	showOrHideDeliveryFields();
}

function subscriptionsValidateIndex() {
	strErrors = "";
	if (bmbGetValue('selMarketingCode') == "") {
		strErrors = strErrors + "\nPlease enter your answer";
	}	
	if (bmbGetValue('txtForename') == "") {
		strErrors = strErrors + "\nPlease enter your first name";
	}
	if (bmbGetValue('txtSurname') == "") {
		strErrors = strErrors + "\nPlease enter your surname";
	}
	if (bmbGetValue('txtTelephone') == "") {
		strErrors = strErrors + "\nPlease enter your telephone number";
	}	

	
	if (!IsEmail(bmbGetValue('txtEmail'))) {
		strErrors = strErrors + "\nPlease check the email entered";
	}
	else {
		if (bmbGetValue('txtEmail') != bmbGetValue('txtConfirmEmail')) {
			strErrors = strErrors + "\nPlease check that both email addresses match.";
		}
	}
	
	if (strErrors != "") {
		alert("Problems:\n" + strErrors);
		return false;
	}
	else {
		return true;
	}
}

// functions for page3
function subscriptionsPage2_onload() {
	showOrHidePaymentFields();
}

function selPaymentMethod_Changed(obj, value) {
	showOrHidePaymentFields();
}

function showOrHidePaymentFields() {
	//alert("Running showOrHidePaymentFields().");
	switch (bmbGetValue('selPaymentMethod')) {
		case "Visa/Visa_Delta":
			//alert("Visa/Visa_Delta");
			showIt('creditCard');
      hideIt('visaElectron');
      hideIt('mastercard');
			hideIt('directDebit');
			hideIt('maestroCard');
			break

    case "Visa/Visa_Delta/Visa_Connect":
      //alert("Visa/Visa_Delta");
      showIt('creditCard');
      hideIt('visaElectron');
      hideIt('mastercard');
      hideIt('directDebit');
      hideIt('maestroCard');
      break


    case "Visa_Electron":
      //alert("Visa_Electron");
      showIt('visaElectron');
      hideIt('creditCard');
      hideIt('mastercard');
      hideIt('directDebit');
      hideIt('maestroCard');
      break
		
		case "MasterCard":
			//alert("MasterCard");
      hideIt('creditCard');
      hideIt('visaElectron');
      showIt('mastercard');
      hideIt('directDebit');
      hideIt('maestroCard');
			break

    case "Maestro":
      //alert("Maestro");
      hideIt('creditCard');
      hideIt('visaElectron');
      hideIt('mastercard');
      hideIt('directDebit');
      showIt('maestroCard');
      break

		case "Direct_Debit":
			//alert("Direct_Debit");
      hideIt('creditCard');
      hideIt('visaElectron');
      hideIt('mastercard');
      showIt('directDebit');
      hideIt('maestroCard');
			break
		
		default:
			//alert("Nothing Selected");
      hideIt('creditCard');
      hideIt('visaElectron');
      hideIt('mastercard');
      hideIt('directDebit');
      hideIt('maestroCard');
	}
}

function subscriptionsValidatePage2() {
	switch (bmbGetValue('selPaymentMethod')) {
		case "Visa/Visa_Delta":
			//alert("Visa/Visa_Delta");
			return validateCreditCardPayment();
			break

    case "Visa/Visa_Delta/Visa_Connect":
      //alert("Visa/Visa_Delta");
      return validateCreditCardPayment();
      break

    case "Visa_Electron":
      //alert("Visa_Electron");
      return validateVisaElectronPayment();
      break
		
		case "MasterCard":
			//alert("MasterCard");
      return validateMasterCardPayment();
			break

		case "Maestro":
			//alert("MasterCard");
			return validateMaestroCardPayment();
			break

		case "Direct_Debit":
			//alert("Direct_Debit");
			//strBank = (bmbGetValue('txtBankName');
			
			var answer = confirm("\nPlease confirm if the details are correct:\nBankname: " + (bmbGetValue('txtBankName')) + "\nSortcode: " + (bmbGetValue('txtSortCode')) + "\nAccount Number: " + (bmbGetValue('txtAccountNumber')) + "\nAccount Holder: " + (bmbGetValue('txtAccountHolderName')))
																							
			 
			 if (answer)
			 return validateDirectDebitPayment();
			 else
			 //return validateDirectDebitPaymentAuth();
			 //alert("Unfortunately it isn't possible to accept your direct debit request as you need to be able to soley authorise direct debits on this account. Please select another payment option.");
			 alert("Please amend the details and click Submit Information again.");
			 return false;
			 break
		
		
		
		default:
			alert("Nothing Selected");
			return false;
	}
}

function validateCreditCardPayment() {
	strErrors = "";
	
	if (bmbGetValue('txtCardNumber') == "") {
		strErrors = strErrors + "\nPlease enter the card number";
	}
	else {
		strErrors = strErrors + FSfncCheckCCnum(MM_findObj('txtCardNumber',""));
	}


	if (compareDates(pageDateForExpiryDate,'NNN-yyyy',bmbGetValue('selExpiry_Month') + "-" + bmbGetValue('selExpiry_Year'),'NNN-yyyy') != "0") {
		strErrors = strErrors + "\nPlease check your card expiry date, this needs to be in the future.";
	}

	if (bmbGetValue('txtCvsNumber') == "") {
		strErrors = strErrors + "\nPlease enter the 3 digit card security code.";
	}	


	if (strErrors != "") {
		alert("Problems:\n" + strErrors);
		return false;
	}
	else {
		return true;
	}
}

function validateVisaElectronPayment() {
  strErrors = "";
  
  if (bmbGetValue('txtVisaElectronCardNumber') == "") {
    strErrors = strErrors + "\nPlease enter the card number.";
  }
  else {
    strErrors = strErrors + FSfncCheckCCnum(MM_findObj('txtVisaElectronCardNumber',""));
  }


  if (compareDates(pageDateForExpiryDate,'NNN-yyyy',bmbGetValue('selVisaElectronExpiry_Month') + "-" + bmbGetValue('selVisaElectronExpiry_Year'),'NNN-yyyy') != "0") {
    strErrors = strErrors + "\nPlease check your card expiry date, this needs to be in the future.";
  }

  if (bmbGetValue('txtVisaElectronCvsNumber') == "") {
    strErrors = strErrors + "\nPlease enter the 3 digit card security code.";
  } 


  if (strErrors != "") {
    alert("Problems:\n" + strErrors);
    return false;
  }
  else {
    return true;
  }
}

function validateMasterCardPayment() {
  strErrors = "";
  
  if (bmbGetValue('txtMasterCardCardNumber') == "") {
    strErrors = strErrors + "\nPlease enter the card number.";
  }
  else {
    strErrors = strErrors + FSfncCheckCCnum(MM_findObj('txtMasterCardCardNumber',""));
  }


  if (compareDates(pageDateForExpiryDate,'NNN-yyyy',bmbGetValue('selMasterCardExpiry_Month') + "-" + bmbGetValue('selMasterCardExpiry_Year'),'NNN-yyyy') != "0") {
    strErrors = strErrors + "\nPlease check your card expiry date, this needs to be in the future.";
  }

  if (bmbGetValue('txtMasterCardCvsNumber') == "") {
    strErrors = strErrors + "\nPlease enter the 3 digit card security code.";
  } 


  if (strErrors != "") {
    alert("Problems:\n" + strErrors);
    return false;
  }
  else {
    return true;
  }
}

function validateMaestroCardPayment() {
	strErrors = "";
	
	if (bmbGetValue('txtMaestroCardNumber') == "") {
		strErrors = strErrors + "\nPlease enter the card number.";
	}
	else {
		strErrors = strErrors + FSfncCheckCCnum(MM_findObj('txtMaestroCardNumber',""));
	}

	if (compareDates(bmbGetValue('selMaestroValidFrom_Month') + "-" + bmbGetValue('selMaestroValidFrom_Year'),'NNN-yyyy', pageDateForExpiryDate,'NNN-yyyy') != "0") {
		strErrors = strErrors + "\nPlease check your card valid from date, this shouldn’t be in the future.";
	}

	if (bmbGetValue('txtMaestroCardIssueNumber') == "") {
		strErrors = strErrors + "\nPlease enter the card issue number";
	}	

	if (compareDates(pageDateForExpiryDate,'NNN-yyyy',bmbGetValue('selMaestroExpiry_Month') + "-" + bmbGetValue('selMaestroExpiry_Year'),'NNN-yyyy') != "0") {
		strErrors = strErrors + "\nEXPIRY DATE must be in the future.";
	}

	if (bmbGetValue('txtMaestroCvsNumber') == "") {
		strErrors = strErrors + "\nPlease check your card expiry date, this needs to be in the future.";
	}	


	if (strErrors != "") {
		alert("Problems:\n" + strErrors);
		return false;
	}
	else {
		return true;
	}
}

function validateDirectDebitPayment() {
	strErrors = "";

	if (bmbGetValue('chkDD') == "N") {
		strErrors = strErrors + "\nPlease confirm you are the only person required to authorise direct debits on this account and that you are the account holder. If you are not please  ring 0871 277 8709 to order your subscription by Direct Debit or select a different payment method.";
	}

	if (bmbGetValue('txtBankName') == "") {
		strErrors = strErrors + "\nPlease enter the bank name";
	}
	
	if (bmbGetValue('txtBankName') == "Bank Name") { //this is needed to flag the default setting
		strErrors = strErrors + "\nPlease enter the bank name";
	}

  if (bmbGetValue('txtAccountNumber').length > 8 || !isInteger(bmbGetValue('txtAccountNumber'))) {
		strErrors = strErrors + "\nPlease re-enter the account number, this field must only contain numbers to a maximum of 8 digits.";
	}
  
	//if (bmbGetValue('txtSortCode').length < 6 || !isInteger(bmbGetValue('txtSortCode'))) {
  if (bmbGetValue('txtSortCode').replace(/-/gi, "").length < 6 || !isInteger(bmbGetValue('txtSortCode').replace(/-/gi, ""))) {
		strErrors = strErrors + "\nPlease re-enter the sort code, this field must only contain numbers and be exactly 6 digits.";
	}

//.replace(/-/gi, "")
	
	if (bmbGetValue('txtAccountHolderName') == "") {
		strErrors = strErrors + "\nPlease enter the account holder’s name";
	}	
	
	if (bmbGetValue('txtAccountHolderName') == "Acc Holders Name") { //this is needed to flag the default setting
		strErrors = strErrors + "\nPlease enter the account holder’s name";
	}	

	if (strErrors != "") {
		alert("Problems:\n" + strErrors);
		return false;
	}
	else {
		return true;
	}
}

// ================================
// functions for cartCheckout pages
// ================================

// ===== index.asp functions =====

// a 'wrapper' to subscriptionsIndex_onload()
function cartCheckoutIndex_onload() {
	subscriptionsIndex_onload();
}

// a 'wrapper' to subscriptionsValidateIndex()
function cartCheckoutIndex_validate() {
	return subscriptionsValidateIndex()
}

// ===== page2.asp functions =====

// a 'wrapper' to subscriptionsPage2_onload()
function cartCheckoutPage2_onload() {
	subscriptionsPage2_onload()
}

// a 'wrapper' to subscriptionsValidatePage2()
function cartCheckoutPage2_validate() {
	return subscriptionsValidatePage2()
}


// ================================
// functions for backIssues pages
// ================================

// ===== page2.asp functions =====

// a 'wrapper' to subscriptionsIndex_onload()
function backIssuesPage2_onload() {
	subscriptionsIndex_onload();
}

// a 'wrapper' to subscriptionsValidateIndex()
function backIssuesPage2_validate() {
	return subscriptionsValidateIndex()
}

// ===== page3.asp functions =====

// a 'wrapper' to subscriptionsPage2_onload()
function backIssuesPage3_onload() {
	subscriptionsPage2_onload()
}

// a 'wrapper' to subscriptionsValidatePage2()
function backIssuesPage3_validate() {
	return subscriptionsValidatePage2()
}

















function sortCode_keyup(operand) {
//  alert("Value: " + operand);

  if (operand.charAt(operand.length) == "-") {
    bmbSetValue("txtSortCode", operand.substr(0,operand.length-1))
  }

  if (operand.length == 2 || operand.length == 5) {
    bmbSetValue("txtSortCode", operand + "-")
  }

  if (operand.length > 8) {
    bmbSetValue("txtSortCode", operand.substr(0,8))
  }
  return true
}


function haveOrderedSomething() {

  flgGoodToGo = false
  
  if (bmbGetValue('selQuantity1') > 0) {
    flgGoodToGo = true
  }
  if (bmbGetValue('selQuantity2') > 0) {
    flgGoodToGo = true
  }
  if (bmbGetValue('selQuantity3') > 0) {
    flgGoodToGo = true
  }
  if (bmbGetValue('selQuantity4') > 0) {
    flgGoodToGo = true
  }
  if (bmbGetValue('selQuantity5') > 0) {
    flgGoodToGo = true
  }

  if (flgGoodToGo) {
    return true;
  }
  else {
    alert('You must select something!');
    return false;
  }

  

}

//-->