// (c) Windmill - (r) gbl 20100513 1625 //

// layer control

function formScheme() {
   if (document.gblForm.authorisation.checked == false) {
      alert("You need to confirm you are 16 or over.");
      document.gblForm.authorisation.focus();
   }
   else {
      document.gblForm.submit();
   }
}

function formOne() {
   var str=document.gblForm.email.value;
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

   var sixteen = dobSet();

   if (document.gblForm.authorisation.checked == false) {
      alert("You need to check this box to authorise the transaction.");
      document.gblForm.authorisation.focus();
   }
   else if (!document.gblForm.name.value) {
      alert("Please enter your name");
      document.gblForm.name.focus();
   }
   else if (!document.gblForm.address1.value && !document.gblForm.address2.value && !document.gblForm.address3.value && !document.gblForm.address4.value) {
      alert("Please enter your address.");
      document.gblForm.address1.focus();
   }
   else if (!document.gblForm.postcode.value) {
      alert("Please enter your postcode.");
      document.gblForm.postcode.focus();
   }
   else if (!document.gblForm.email.value) {
      alert("Please enter your email address.");
      document.gblForm.email.focus();
   }
   else if (!filter.test(str)) {
      alert("Please enter a valid, working email address.");
      document.gblForm.email.focus();
   }
   else if (!document.gblForm.telephone.value) {
      alert("Please enter your daytime telephone number.");
      document.gblForm.telephone.focus();
   }

   else if (document.gblForm.dob_year.value+document.gblForm.dob_month.value+document.gblForm.dob_day.value > sixteen) {
      alert("You must be over sixteen to join the Gold Bond.");
      document.gblForm.dob_day.focus();
   }

   else {
      if (document.gblForm.same_address[0].checked) {
         makeNone('card_address');
      }
      else if (document.gblForm.same_address[1].checked) {
         makeBlock('card_address');
      }
      makeNone('form_one');
      makeBlock('form_two');
   }
}

function formTwo(gblForm) {
   if (document.gblForm.authorisation.checked == false) {
      alert("You need to check this box to authorise the transaction.");
      document.gblForm.authorisation.focus();
   }
   else if (!document.gblForm.cardholder.value) {
      alert("Please enter your name as it appears on your card.");
      document.gblForm.cardholder.focus();
   }
   else if (!document.gblForm.cardnumber.value) {
      alert("Please enter the long number from the middle of your card.");
      document.gblForm.cardnumber.focus();
   }
   else if (document.gblForm.expiry_mm.selectedIndex == 0 || document.gblForm.expiry_mm.selectedIndex == 1) {
      alert("Please enter the expiry date from your card (mm yyyy).");
      document.gblForm.expiry_mm.focus();
   }
   else if (document.gblForm.expiry_yyyy.selectedIndex == 0 || document.gblForm.expiry_yyyy.selectedIndex == 1) {
      alert("Please enter the expiry date from your card (mm yyyy).");
      document.gblForm.expiry_yyyy.focus();
   }
   else if (!document.gblForm.security.value) {
      alert("Please enter the three digit security code from the reverse of your card.");
      document.gblForm.security.focus();
   }
   else if (document.gblForm.same_address[1].checked) {
      if (!document.gblForm.card_address1.value && !document.gblForm.card_address2.value && !document.gblForm.card_address3.value && !document.gblForm.card_address4.value) {
         alert("Please enter your card's billing address.");
         document.gblForm.card_address1.focus();
      }
      else if (!document.gblForm.card_postcode.value) {
         alert("Please enter your postcode.");
         document.gblForm.card_postcode.focus();
      }
      else {
         document.gblForm.submit();
      }
   }

   else {
      document.gblForm.submit();
   }
}

