   var SavedEnquiry = '';

   function CheckTravelGroup(inputName){
      var GroupElements=new Array();
      var i;
      if(inputName=='Other'){
         GroupElements = document.getElementsByName('Outbound');
         for(i=0;i<GroupElements.length;i++){
            GroupElements[i].checked=false;
         }
         GroupElements = document.getElementsByName('Inbound');
         for(i=0;i<GroupElements.length;i++){
            GroupElements[i].checked=false;
         }
      }
      if(inputName=='Outbound'||inputName=='Inbound'){
         GroupElements=document.getElementsByName('Other');
         for(i=0;i<GroupElements.length;i++){
            GroupElements[i].checked=false;
         }
         GroupElements=document.getElementsByName('Outbound');
         var found=false;
         for(i=0;i<GroupElements.length;i++){
            if(GroupElements[i].checked){
               found=true;
               break;
            }
         }
         if(!found){
            for(i=0;i<GroupElements.length;i++){
               if(!GroupElements[i].disabled){
                  GroupElements[i].checked=true;
                  break;
               }
            }
         }
         GroupElements=document.getElementsByName('Inbound');
         found=false;
         for(i=0;i<GroupElements.length;i++){
            if(GroupElements[i].checked){
               found=true;
               break;
            }
         }
         if(!found){
            for(i=0;i<GroupElements.length;i++){
               if(!GroupElements[i].disabled){
                  GroupElements[i].checked=true;
                  break;
               }
            }
         }
      }
   }

   function CheckAccommodation(inputName){
      var totalAdults=document.getElementById('TotalAdults').value;
      var APR=document.getElementsByName('AdultsPerRoom');
      var accAdults=0;
      var accCode;
      for(var i=0;i<APR.length;i++){
         if(APR[i].id.substr(3,APR[i].id.length-3)==inputName){
            accCode=APR[i].id;
            if(document.getElementById('Accommodation'+accCode)){
               if(document.getElementById('Accommodation'+accCode).value>0){
                  accAdults+=document.getElementById('Accommodation'+accCode).value*APR[i].value;
               }
            }
         }
      }
      if(totalAdults!=accAdults){
         alert('The rooms selected does not match the number of adults');
         return false;
      }
      else{
         return true;
      }
   }

   function ShowSearchingScreen(){
      if((document.getElementById('SearchingLayer')) && (document.getElementById('DefaultLayer'))){
         SavedEnquiry = document.getElementById('DefaultLayer').innerHTML;
         document.getElementById('DefaultLayer').innerHTML = document.getElementById('SearchingLayer').innerHTML;
      }
   }

   function CheckEnquiry(){
      var Continue = true;
      
      if (Continue) {
         if (document.getElementById('SelectEventTypes')) {
            if (document.getElementById('SelectEventTypes').value == '') {
               alert('Please select an event type');
               Continue = false;
            }
         }
      }               
            
      if (Continue) {
         if (document.getElementById('cboFromDate')) {
            if (document.getElementById('cboFromDate').value == '') {
               alert('Please enter a from date');
               Continue = false;
            }
         }
      }
      
      if (Continue) {
         if (document.getElementById('cboToDate')) {
            if (document.getElementById('cboToDate').value == '') {
               alert('Please enter a to date');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('Adults')) {
            if (document.getElementById('Adults').value == '0') {
               alert('Please enter number of adults');
               Continue = false;
            }
         }
      }
                        
      if (Continue) {
         ShowSearchingScreen();
         document.EnquiryForm.submit();
      }
   }
   
   function CheckLogin(){
      var Continue = true;
      var str = '';
      
      if (Continue) {
         if (document.getElementById('LoginEmail')) {
            if (document.getElementById('LoginEmail').value == '') {
               alert('Please enter an email address');
               Continue = false;
            }
         }
      }               
            
      if (Continue) {
         if (document.getElementById('LoginPassword')) {
            if (document.getElementById('LoginPassword').value == '') {
               alert('Please enter a password');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('LoginEmail')) {
            str = document.getElementById('LoginEmail').value
            if ((str.indexOf("@")==-1) || (str.indexOf(".")==-1) || (str.length < 7)){
               alert('Please enter a valid email address');
               Continue = false;
            }
         }
      }   
                        
      if (Continue) {
         document.Login.submit();
      }
   }   

   function CheckPassword(){
      var Continue = true;
      var str = '';
      
      if (Continue) {
         if (document.getElementById('LoginEmail')) {
            if (document.getElementById('LoginEmail').value == '') {
               alert('Please select an email address');
               Continue = false;
            }
         }
      }               

      if (Continue) {
         if (document.getElementById('LoginEmail')) {
            str = document.getElementById('LoginEmail').value
            if ((str.indexOf("@")==-1) || (str.indexOf(".")==-1) || (str.length < 7)){
               alert('Please enter a valid email address');
               Continue = false;
            }
         }
      }      
                     
      if (Continue) {
         document.Login.submit();
      }
   }      

   function CheckPassengers(){
      var Continue = true;
      
      //Loop Through all form elements, validate all passengers
      var str = '';
      var PaxNo = -1;
      var DOB = '';      
      
      if (document.getElementsByName('PaxNo')){
         for(var i=0; i<document.getElementsByName('PaxNo').length; i++) {
            var titles = document.getElementsByName('Title');
            if (Continue) {   
               if (titles[i]) {         
                  if (titles[i].value == '') {
                     alert('Please enter a title for passenger number ' + (i + 1)+ '.');
                     
                     Continue = false;
                  }
               }
            }
            
            var forenames = document.getElementsByName('Forename');
            if (Continue) {
               if (forenames[i]) {               
                  if (forenames[i].value == '') {
                     alert('Please enter a forename for passenger number ' + (i + 1)+ '.');
                     
                     Continue = false;
                  }
               }
            }
            
            var surnames = document.getElementsByName('Surname');
            if (Continue) {      
               if (surnames[i]) {         
                  if (surnames[i].value == '') {
                     alert('Please enter a surname for passenger number ' + (i + 1)+ '.');
                     
                     Continue = false;
                  }
               }
            }
            
            var genders = document.getElementsByName('Gender');
            if (Continue) {      
               if (genders[i]) {         
                  if (genders[i].value == '') {
                     alert('Please select a gender for passenger number ' + (i + 1)+ '.');
                     
                     Continue = false;
                  }
               }
            }
                  
            if (Continue) {
               
               if (document.getElementById('DateOfBirth' + (i))) {
                  
                  var elemDOB = document.getElementsByName('DateOfBirth' + (i));
                  
                  var DOB = '';            
                  var ValidDOB = ''
                  for(var j = 0; j < elemDOB.length; j++)
                     {               
                        if (Continue) {
                           DOB = DOB + elemDOB[j].value + '/'
                        }
                     }
      
                     if (DOB.length == 11) {            
                        DOB = DOB.substring(0, DOB.length-1);
                        //now we have date formatted dd/mm/yyyy
                     } else if (DOB.length == 3) {
                        DOB = '';
                     } else {
                        alert('Invalid date of birth entered for passenger number ' + (i + 1) + '.');
                        
                        Continue = false;
                     }
                     
                     if (Continue) {
                        if (checkDate(DOB)== false && DOB!='') {
                           alert('Invalid date of birth entered for passenger number ' + (i + 1) + '.');
                           Continue = false;
                        }                  
                     }
                     
                     if (Continue){
                        if (calcAge(DOB) < 18 ) {
                           alert('All passengers must be adults. \n\nPlease check date of birth for passenger number ' + (i + 1) + '.');
                           Continue = false;
                        }
                     }
                     
               } 
            }
   
            
         } 
      } else {
         Continue = false;
      }

      if (Continue) {                  
         document.PassengerInput.submit();
      }             
   }                           

   function CheckQuestions(){
      var Continue = true;
      //Loop Through all form elements, all questions must be answered
      var elem = document.getElementById('QuestionsInput').elements;      
      
      for(var i = 0; i < elem.length; i++){         
         if (Continue) {
            if (elem[i].type == 'radio'){
               var radioCheck = document.getElementsByName(elem[i].name);
               
               var validResponse = false;
               for (var j=0; j< radioCheck.length; j++){
                  if (radioCheck[j].checked == true){
                     validResponse = true;
                  }
               }
               
               if (validResponse == false) {
                  alert('Please answer all questions.');
                  Continue = false;
               }
            } else if (elem[i].type == 'text' && elem[i].name.substring(elem[i].name.length-2)!='FT'){
               if (elem[i].value == '') {
                  alert('Please answer all questions.');
                  Continue = false;
               }
            }
         }                                                                           
      } 
      
      if (Continue) {
         document.QuestionsInput.submit();
      }     
   }   

   function CheckPassengerActivity(){
      var Continue = true;
      var PaxAdded = 0;
      var PaxActivity = "";
      //Loop Through all form elements, all questions must be answered
      var elem = document.getElementsByName('PaxActivity');
     
      for(var i = 0; i < elem.length; i++){                 
         if (Continue) {
            PaxActivity = (elem[i].value);
            PaxAdded = 0;
            
            var ActivityElem = document.getElementsByName('PaxActivity' + PaxActivity);
            
            for(var j = 0; j < ActivityElem.length; j++){                 
               if (ActivityElem[j].type == 'checkbox'){
                  if (ActivityElem[j].checked) {
                     PaxAdded ++;
                  }
               }
            }
            
            if (document.getElementById('PaxActivity')) {
               //PaxActivity = document.getElementById('PaxActivity').value;
               //alert(document.getElementById('MaxPaxActivity').value);
               if (document.getElementById('MaxPaxActivity' + PaxActivity)) {            
                  if (parseInt(document.getElementById('MaxPaxActivity' + PaxActivity).value)>PaxAdded){
                     alert(document.getElementById('PaxActivityName' + PaxActivity).value + ":\n\nNot all passenger activities have been assigned.");
                     Continue = false;
                  } 
                  else if (parseInt(document.getElementById('MaxPaxActivity' + PaxActivity).value)<PaxAdded){
                     alert(document.getElementById('PaxActivityName' + PaxActivity).value + ":\n\nYou have assigned too many passengers to the activity.");
                     Continue = false;
                  } 
               }
            }
            else {
               alert("Unable to continue");
               Continue = false;
            }
         }                                                                           
      } 
      

      
      if (Continue) {
          document.PassengerInput.submit();
      }     

   
   }   

   function CheckActivities(){
      var Continue = true;
      
         
      //All fields must be entered
      //Password must e 8 - 10 chars
      if (Continue) {
         document.QuestionsInput.submit();
      }             
   }
      
   function CheckRegistration(){
      var Continue = true;
      var str = '';
      var DOB = '';

      if (Continue) {
         if (document.getElementById('ClientEmail')) {
            if (document.getElementById('ClientEmail').value == '') {
               alert('Please enter an email address');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientEmail')) {
            str = document.getElementById('ClientEmail').value
            if ((str.indexOf("@")==-1) || (str.indexOf(".")==-1) || (str.length < 7)){
               alert('Please enter a valid email address');
               Continue = false;
            }
         }
      }   

      if (Continue) {
         if (document.getElementById('ClientPassword')) {
            if (document.getElementById('ClientPassword').value == '') {
               alert('Please enter a password');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientPassword')) {
            str = document.getElementById('ClientPassword').value
            if ((str.length < 8) || (str.length > 10)){
               alert('Password must be 8 to 10 characters in length.');
               Continue = false;
            }
         }
      }
                  
      if (Continue) {
         if (document.getElementById('ClientTitle')) {
            if (document.getElementById('ClientTitle').value == '') {
               alert('Please select a title');
               Continue = false;
            }
         }
      }   

      if (Continue) {
         if (document.getElementById('ClientForename')) {
            if (document.getElementById('ClientForename').value == '') {
               alert('Please enter forename');
               Continue = false;
            }
         }
      }


      if (Continue) {
         if (document.getElementById('ClientSurname')) {
            if (document.getElementById('ClientSurname').value == '') {
               alert('Please enter surname');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientGender')) {
            if (document.getElementById('ClientGender').value == '') {
               alert('Please select a gender');
               Continue = false;
            }
         }
      }            

      if (Continue) {
         if (document.getElementById('ClientDOB')) {
            var elem = document.getElementsByName('ClientDOB');
            
            var DOB = '';            
            var ValidDOB = ''
            for(var i = 0; i < elem.length; i++)
               {               
                  if (Continue) {
                     DOB = DOB + elem[i].value + '/'
                  }
               }

               if (DOB.length == 11) {            
                  DOB = DOB.substring(0, DOB.length-1);
                  //now we have date formatted dd/mm/yyyy
               } else if (DOB.length == 3) {
                  alert('Please enter date of birth');
                  
                  Continue = false;
               } else {
                  alert('Invalid date of birth entered');
                  
                  Continue = false;
               }
               
               if (Continue) {
                  if (checkDate(DOB)== false) {
                     alert('Invalid date of birth entered');
                     Continue = false;
                  }                  
               }
               
               if (Continue){
                  if (calcAge(DOB) < 18 ) {
                     alert('All passengers must be adults. Please check date of birth');
                     Continue = false;
                  }
               }
         } 
      }

      if (Continue) {
         if (document.getElementById('PassengerInput')){
            var elem = document.getElementById('PassengerInput').elements;
            for(var i = 0; i < elem.length; i++)
            {
               if (Continue) {
                  str = elem[i].name
                  if (str.indexOf("ClientDOB")!=-1) {
                     DOB = DOB + elem[i].value + '/'
                     
                     //if not blank, and have full date validate age
                     if (Continue) {
                        if (DOB.length == 11) {
                           //remove trailing /
                           DOB = DOB.substring(0, DOB.length-1);
                           //now we have date formatted dd/mm/yyyy
                           
                           if (checkDate(DOB)== false) {
                              alert('Invalid date of birth entered');
                              Continue = false;
                           }
         
                           if (Continue){
                              if (calcAge(DOB) < 18 ) {
                                 alert('All passengers must be adults. Please check date of birth');
                                 Continue = false;
                              }
                           }
                           
                           if (Continue == false){
                              
                           }
                        }
                     }
                  }
               }         
            }                                                         
         } 
      }

      if (Continue) {
         if (document.getElementById('Address1')) {
            if (document.getElementById('Address1').value == '') {
               alert('Please enter the first line of your address');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('Town')) {
            if (document.getElementById('Town').value == '') {
               alert('Please enter an address town');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('County')) {
            if (document.getElementById('County').value == '') {
               alert('Please enter an address County');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('Country')) {
            if (document.getElementById('Country').value == '') {
               alert('Please select an  address Country');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientCountry')) {
            if (document.getElementById('ClientCountry').value == '') {
               alert('Please enter an address');
               Continue = false;
            }
         }
      }

/*
      if (Continue) {
         if ((document.getElementById('ClientPostCode1')) && (document.getElementById('ClientPostCode2'))) {
            if ((document.getElementById('ClientPostCode1').value == '') || (document.getElementById('ClientPostCode2').value == '')) {
               alert('Please enter a postcode');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientPostCode1')) {
            str = document.getElementById('ClientPostCode1').value
            if (str.length < 2){
               alert('Invalid postcode entered');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('ClientPostCode2')) {
            str = document.getElementById('ClientPostCode2').value
            if (str.length < 3){
               alert('Invalid postcode entered');
               Continue = false;
            }
         }
      }      

      if (Continue) {
         if ((document.getElementById('ClientPostCode1')) && (document.getElementById('ClientPostCode2'))) {
            str = (document.getElementById('ClientPostCode1').value + document.getElementById('ClientPostCode2').value)
            if (str.length < 5){
               alert('Invalid postcode entered');
               Continue = false;
            }
         }
      }   
*/
                        
      if (Continue) {
         if (document.getElementById('ClientTelephone')) {
            if (document.getElementById('ClientTelephone').value == '') {
               alert('Please enter an telephone number');
               Continue = false;
            }
         }
      }

      /*if (Continue) {
         if (document.getElementById('ClientTelephone')) {
            str = document.getElementById('ClientTelephone').value
            if (str.length != 11){
               alert('Invalid telephone number entered');
               Continue = false;
            }
         }
      } */

      if (Continue) {
         if (document.getElementById('ClientTelephone')) {
            str = document.getElementById('ClientTelephone').value
            if (IsNumeric(str)==false) {
               alert('Invalid telephone number entered');
               Continue = false;
            }
         }
      }
      
      if (Continue) {
        document.PassengerInput.submit();
      }             
   }

   function Payments() {
      if (document.getElementById("Other").checked == true){
         document.getElementById("OtherPayment").disabled = false;
      } else {
         document.getElementById("OtherPayment").disabled = true;
      }
   }   
      
   function CheckPayments(){
      var Continue = true;
      var str = '';
      

            
      if (document.getElementById('Other')) {               
         if (document.getElementById("Other").checked == true){
            var NewPayment = parseFloat(document.getElementById("Other").value);
            var MinPayment = parseFloat(document.getElementById("MinPayment").value);
            var MaxPayment = parseFloat(document.getElementById("MaxPayment").value);
                           
            if (NewPayment < MinPayment) {
               alert('Payment must be at least \u00A3' + MinPayment);
               document.getElementById("Other").value = MinPayment;
               document.getElementById("OtherPayment").value = MinPayment;
               Continue = false;
            }
            
            if (NewPayment > MaxPayment) {
               alert('Payment can not be at more than \u00A3' + MaxPayment);   
               document.getElementById("Other").value = MaxPayment;
               document.getElementById("OtherPayment").value = MaxPayment;
               Continue = false;      
            }
            
         }
      }
      
      if (Continue) {
         if (document.getElementById('PaymentMethod')) {
            if (document.getElementById('PaymentMethod').value == '') {
               alert('Please select a payment method');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('CardNumber')) {
            if (document.getElementById('CardNumber').value == '') {
               alert('Please enter card number');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('CardNumber')) {
            str = document.getElementById('CardNumber').value
            if (str.length != 16){
               alert('Invalid card number entered');
               Continue = false;
            }
         }
      }
      
      if (Continue) {
         if (document.getElementById('CardNumber')) {
            str = document.getElementById('CardNumber').value
            if (IsNumeric(str)==false) {
               alert('Invalid card number entered');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('CardNumber')) {
            str = document.getElementById('CardNumber').value
            if (LuhnCheck(str)==false) {
               alert('Invalid card number entered');
               Continue = false;
            }
         }
      }
                        
      
      if (Continue) {
         if (document.getElementById('CardHolder')) {
            if (document.getElementById('CardHolder').value == '') {
               alert('Please enter card holder');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if ((document.getElementsByName("IssueDate")[0]) && (document.getElementsByName("IssueDate")[0].disabled == false)){
            if (document.getElementsByName("IssueDate")[0].value == '') {
               alert('Please enter an issue date');
               Continue = false;
            }
         }
      }   

      if (Continue) {
         if ((document.getElementsByName("IssueDate")[1]) && (document.getElementsByName("IssueDate")[1].disabled == false)){
            if (document.getElementsByName("IssueDate")[1].value == '') {
               alert('Please enter an issue date');
               Continue = false;
            }
         }
      }   
      
      if (Continue) {
         if ((document.getElementsByName("ExpiryDate")[0]) && (document.getElementsByName("ExpiryDate")[0].disabled == false)){
            if (document.getElementsByName("ExpiryDate")[0].value == '') {
               alert('Please enter an expiry date');
               Continue = false;
            }
         }
      }   

      if (Continue) {
         if ((document.getElementsByName("ExpiryDate")[1]) && (document.getElementsByName("ExpiryDate")[1].disabled == false)){
            if (document.getElementsByName("ExpiryDate")[1].value == '') {
               alert('Please enter an expiry date');
               Continue = false;
            }
         }
      }               

      if (Continue) {
         if ((document.getElementById('IssueNumber')) && (document.getElementById('IssueNumber').disabled == false)) {
            str = document.getElementById('IssueNumber').value
            if (IsNumeric(str)==false) {
               alert('Invalid Issue number entered');
               Continue = false;
            }
         }
      }
                                    
      if (Continue) {
         if (document.getElementById('CVS')) {
            if (document.getElementById('CVS').value == '') {
               alert('Please enter a security number');
               Continue = false;
            }
         }
      }   

      if (Continue) {
         if (document.getElementById('CVS')) {
            str = document.getElementById('CVS').value
            if (str.length < 3){
               alert('Invalid security number entered');
               Continue = false;
            }
         }
      }
      
      if (Continue) {
         if (document.getElementById('CVS')) {
            str = document.getElementById('CVS').value
            if (IsNumeric(str)==false) {
               alert('Invalid security number entered');
               Continue = false;
            }
         }
      }

      if (Continue) {
         if (document.getElementById('AcceptConditions')) {
            if (document.getElementById('AcceptConditions').checked == false) {
               alert('Please confirm you have read and accepted the booking conditions');
               Continue = false;
            }
         }
      }
      
      //Need to validate required fields eg. Issue No, Exp Date not always required
      if (Continue) {
         document.PaymentsInput.submit();
      }             
   }
                           
   function changeDay() {
      foundDate=false;

      if(document.getElementById("cboFromMonthYear")) {
         var DepDate=new Date(document.getElementById("cboFromMonthYear").value.substr(0,4),document.getElementById("cboFromMonthYear").value.substr(4,2)-1,document.getElementById("cboFromDate").value);
         foundDate=true;    
      } else if(document.getElementById("cboFromYear")) {
         var DepDate=new Date(document.getElementById("cboFromYear").value,document.getElementById("cboFromMonth").value-1,document.getElementById("cboFromDate").value);
         foundDate=true;
      }

      if(foundDate) {
         DepartDOWText=weekday[DepDate.getDay()].substr(0,2).toUpperCase();
   
         if(document.getElementById("DepartDOW")) {
            if(document.getElementById("DepartDOW").firstChild.tagName.toLowerCase()=="p") {
               document.getElementById("DepartDOW").firstChild.innerHTML=DepartDOWText;
            }
         }
     
         if(document.getElementById("cboToMonthYear")) {
            var RetDate=new Date(document.getElementById("cboToMonthYear").value.substr(0,4),document.getElementById("cboToMonthYear").value.substr(4,2)-1,document.getElementById("cboToDate").value);
         } else {
            var RetDate=new Date(document.getElementById("cboToYear").value,document.getElementById("cboToMonth").value-1,document.getElementById("cboToDate").value);
         }
       
         ReturnDOWText=weekday[RetDate.getDay()].substr(0,2).toUpperCase();
         
         if(document.getElementById("ReturnDOW")) {
            if(document.getElementById("ReturnDOW").childNodes[0].tagName.toLowerCase()=="p") {
               document.getElementById("ReturnDOW").childNodes[0].innerHTML=ReturnDOWText;
            }
         }
      }
      BuildDays('cboFromMonthYear','cboFromYear','cboFromMonth','cboFromDate');
      BuildDays('cboToMonthYear','cboToYear','cboToMonth','cboToDate');
   }   
   
function calcReturnDate(OutDay,OutMonth,OutYear,InDay,InMonth,InYear, Months) {
   if(document.getElementById(OutMonth).value.length>2) {
      theDate=new Date(document.getElementById(OutMonth).value.substr(0,4),document.getElementById(OutMonth).value.substr(4,2)-1,document.getElementById(OutDay).value); 
   } else {
      theDate=new Date(document.getElementById(OutYear).value,document.getElementById(OutMonth).value-1,document.getElementById(OutDay).value); 
   }
   
   theDate = theDate.addMonths(Months);
   
   theDate.setMilliseconds(theDate.getMilliseconds());
   
   iDay="0"+theDate.getDate()
   iDay=iDay.substr(iDay.length-2, iDay.length)
   
   iMonth="0"+(theDate.getMonth()+1);
   iMonth=iMonth.substr(iMonth.length-2, iMonth.length)
   
   if(document.getElementById(InMonth).value.length>2) {
      document.getElementById(InMonth).value=theDate.getFullYear().toString()+iMonth.toString();
   } else {
      document.getElementById(InMonth).value=iMonth;
      document.getElementById(InYear).value=theDate.getFullYear();
   }
   
   document.getElementById(InDay).value=iDay;
}   

Date.prototype.addMonths = function (n) {
var day = this.getDate();
this.setMonth(this.getMonth() + n);
if (this.getDate() < day) {
this.setDate(1);
this.setDate(this.getDate() - 1);

}
return this;
}

function IsNumeric(inputVal) {
     if (isNaN(parseFloat(inputVal))) {
          return false;
     }else{
        return true;
     }
}

function LuhnCheck(str) {
   var result=true;
   var sum=0; 
   var mul=1; 
   var strLen=str.length;
  
   for (i=0;i<strLen;i++) {
      var digit=str.substring(strLen-i-1,strLen-i);
      var tproduct=parseInt(digit ,10)*mul;

       if (tproduct>=10) {sum+=(tproduct % 10)+1;}
      else {sum+=tproduct;}

      if (mul==1) {mul++;}
      else {mul--;}
  }
  if ((sum%10)!=0) {result=false;}
    
  return result;
}

function calcAge(dateString) 
{
    /*
    dateString format dd/yy/yyyy
    
    compare with todays date to calculate age 
    */
    
   var now = new Date();
    
    var yearNow = now.getFullYear();
    var monthNow = now.getMonth()+1;
    var dateNow = now.getDate();

    var dob = new Date(dateString.substring(6,10),dateString.substring(3,5)-1,dateString.substring(0,2));

    var yearDob = dob.getFullYear();
    var monthDob = dob.getMonth()+1;
    var dateDob = dob.getDate();
            
    var yearAge = yearNow - yearDob;
     
    if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
    else 
    {
        yearAge--;
        var monthAge = 12 + monthNow -monthDob;
    }

    if (dateNow >= dateDob)
        var dateAge = dateNow - dateDob;
    else 
    {
        monthAge--;
        var dateAge = 31 + dateNow - dateDob;

        if (monthAge < 0) 
        {
            monthAge = 11;
            yearAge--; 
        }
    }

    //return yearAge + ' years ' + monthAge + ' months ' + dateAge + ' days';
    return yearAge;
}

function dateParts(lDate) {
   var vdateParts=lDate.split("/");

   if(vdateParts.length>2) {
      if(vdateParts[2].toString().length==2) {
         vdateParts[2]="20"+vdateParts[2];
      }
   }
   return vdateParts;
}

function str2date(str) {
   var vdateParts=dateParts(str);

   if(vdateParts.length>2)
   {
      day=vdateParts[0].toString();
      month=vdateParts[1].valueOf()-1;
      year=vdateParts[2].toString();
      var vDate=new Date(year, month, day);
      return vDate;
   }
}

function checkDate(dateString) 
{
   var checkDateContinue = true;
   var now = new Date();
   
   var vdatePart = dateString.split("/");   
   var DateToCheck = new Date(dateString.substring(6,10),dateString.substring(3,5)-1,dateString.substring(0,2));
    
   var strDateToCheck = (DateToCheck.getDate() + '/' + (DateToCheck.getMonth() + 1) + '/' + DateToCheck.getFullYear());
     var parsedDateToCheck = (parseFloat(vdatePart[0]) + '/' + parseFloat(vdatePart[1]) + '/' + parseFloat(vdatePart[2]));
     
     if (strDateToCheck != parsedDateToCheck) {
         checkDateContinue = false;
     }
      
     if (checkDateContinue) {
      var yearCheck = DateToCheck.getFullYear();
      var monthCheck = DateToCheck.getMonth()+1;
      var dateCheck = DateToCheck.getDate();
       
      var yearNow = now.getFullYear();
      var monthNow = now.getMonth()+1;
      var dateNow = now.getDate();
      var todayString = '';
      var checkString = '';
      
      todayString = yearNow + '' + monthNow + '' + dateNow
      checkString = yearCheck + '' + monthCheck + '' + dateCheck
      dateString = yearCheck + '/' + monthCheck + '/' + dateCheck
       
      if (checkString >= todayString){
         return false;    
      } else {
         return true;  
      }
   } else {
         return false;
   }
}

   function CheckClientEmail(){
      var emailAddress = document.getElementById("ClientEmail").value;
      
      ValidateAjax("ReadCustomers", emailAddress);
      
   }

   function AjaxResponse(AjaxFunction, ValidResponse){
      switch(AjaxFunction) {      
         case "ReadCustomers":                
            if (ValidResponse) {
               var reply = confirm("That email address has previously been registered.\n\nDo you want to login with this email address?");
               if (reply) {
                  window.location = "?em=" + document.getElementById("ClientEmail").value;
               } else {
                  document.getElementById("ClientEmail").value = "";
                  document.getElementById("ClientEmail").focus();
               }
            } else {
               //Do nothing
            }
            break;
      }
   }
      
   function ValidateAjax(AjaxFunction, AjaxParameter){{
      var xmlhttp;
      var ValidResponse = false;
      if (window.XMLHttpRequest){     
         xmlhttp=new XMLHttpRequest();
      } else if (window.ActiveXObject) {     
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      } else {
        alert("Your browser does not support XMLHTTP!");
      }
         
      xmlhttp.onreadystatechange=function() {
         if(xmlhttp.readyState==4) {
              if (xmlhttp.responseText == 'True') {
                 ValidResponse = true;
              } else {
                 ValidResponse = false;
              }              
              AjaxResponse(AjaxFunction, ValidResponse);
          }
      }
         xmlhttp.open("GET","ajax/ajax-validation.asp?ft=" + AjaxFunction + "&fp=" + AjaxParameter,true);
         xmlhttp.send(null);
   }
   
   }
   
   function AlphaNumericsOnly(Obj,UpperCase)
   {
      var newValue='';
      if(Obj!=null) {
         newValue=Obj.value;
         if(newValue!='') {
            if (UpperCase) {
               newValue=newValue.toUpperCase();
            }
            var re=new RegExp('[^0-9A-Za-z]','ig');
            newValue=newValue.replace(re,'');
            Obj.value=newValue;
         }
      }
      if(event && event.keyCode==9) {
         Obj.select();
      }
   }     
         
   
   function NumericsOnly(Obj)
   {
      if ((window.event.keyCode<48 || window.event.keyCode>57) && window.event.keyCode!=46) {
         window.event.keyCode=0;
      }
      
      if(Obj!=null) {
         var y=Obj.value;
         if(y!='') {
            Obj.value=Obj.value;
         }
      }
      
      if(event && event.keyCode==9) {
         document.getElementById(x).select();
      }
   }  
   
   function UpperCase(x) 
   {
      var y=document.getElementById(x).value;
      if(y!='') {
         document.getElementById(x).value=y.toUpperCase();
      }
      if(event && event.keyCode==9) {
         document.getElementById(x).select();
      }
   }   

   var newWin = null;  
   function popUp(strURL, strType, strHeight, strWidth) {  
      if (newWin != null && !newWin.closed)  
         newWin.close();  
         var strOptions="";  
      if (strType=="console")  
         strOptions="resizable,height="+  
         strHeight+",width="+strWidth;  
      if (strType=="fixed")  
         strOptions="status,height="+  
         strHeight+",width="+strWidth;  
      if (strType=="elastic")  
         strOptions="toolbar,menubar,scrollbars,"+  
         "resizable,location,height="+  
         strHeight+",width="+strWidth;  
         newWin = window.open(strURL, 'newWin', strOptions);  
      
      newWin.focus();  
   }
   

   function RequestEvents() {
      http_event_request = false;
     
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_event_request = new XMLHttpRequest();
         if (http_event_request.overrideMimeType) {
            http_event_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_event_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_event_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_event_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
     
      http_event_request.onreadystatechange = EventsContents;      
      
        var selectedType = document.getElementById("SelectEventTypes").value;
        
      http_event_request.open('GET', "/ajax/ajax-functions.asp?ft=ReadEvents&fp=" + selectedType, true);
     
      http_event_request.send(null);
      
   }

   function EventsContents() {
     
      if (http_event_request.readyState == 4) {         
         if (http_event_request.status == 200) {      
     
            if (window.ActiveXObject) { // IE            
               var doc = http_event_request.responseText;
               var xDoc = new ActiveXObject("Microsoft.XMLDOM");   
               xDoc.loadXML(doc);                                                 
            } else {
               var xDoc = http_event_request.responseXML;
            }            
            
            UpdateEvents(xDoc);                        
            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }      
   
   function UpdateEvents(lXML){
      var xValue = lXML.getElementsByTagName("Value");
      var xText = lXML.getElementsByTagName("Text");   
      
      var ComboSelect=document.getElementById("Events") 
      while (ComboSelect.options.length) {                        
         ComboSelect.remove(ComboSelect.length-1);
      }

      for (j=0;j<xValue.length;j++){
         element = document.createElement('OPTION');
         if(xValue[j].childNodes[0]){
            element.value = xValue[j].childNodes[0].nodeValue;
            element.text = xText[j].childNodes[0].nodeValue;
         }

         document.getElementById("Events").options.add(element);
         document.getElementById("Events").selectedIndex = 0;

      }
   }      
