    // Validator Object
    var valid = new Object();

    // REGEX Elements

	//Not Blank - added by MD
	// valid.notBlank = /^.+$/;
	
	valid.notBlank = /^[\S]|[\.]+$/;
	

        // matches zip codes
        valid.zipCode = /\d{5}(-\d{4})?/;

        // matches $17.23 or $14,281,545.45 or ...
        valid.Currency = /\$\d{1,3}(,\d{3})*\.\d{2}/;

        // matches 5:04 or 12:34 but not 75:83
        valid.Time = /^([1-9]|1[0-2]):[0-5]\d$/;
        
        
        // is alpha numeric
        valid.AlphaNum = /^([a-zA-Z0-9])+$/;

        //matches email
        valid.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

        // matches phone ###-###-####
        valid.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;

        // International Phone Number
        valid.phoneNumberInternational = /^\d(\d|-){7,20}/;

        // IP Address
        valid.ipAddress = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;

        // Date xx/xx/xxxx
        valid.Date = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

        // State Abbreviation
        valid.State = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;

        // Social Security Number
        valid.SSN = /^\d{3}\-\d{2}\-\d{4}$/;
        



function validateNonTextfield(elem, theName)
{
           if((elem.name == theName) && (elem.disabled == false) && (elem.style.display != "block"))
	   {	
	   	var str = elem.value;
	   	  		   	
	   	if(str.length == 0)
		{
		
	   		var text1 = "A Value must be entered for ";
			var text2 = ". \n\nHit 'OK' and you will be returned to the form\n";
		
	   	 	alert(text1 + elem.getAttribute("description") + text2);
                 	return false;
	   	}
           }
           return true;
}



    
function validateForm(theForm) {

        var elArr = theForm.elements; 

        for(var i = 0; i < elArr.length; i++) 
        {   
        

// For some reason this won't work in the main loops
// It is the validations for non text fields

// for 'onlineOrder'
	// for Share Class
	

	if(theForm.name == "enqForm")
	{
		if(document.enqForm.smartcode.value.length == 0)
		{
			alert("The security code entered is not correct. Please try again");
			theForm.smartcode.select();
			theForm.smartcode.focus();
           		return false;
           	}
        }
		
		
	if(document.getElementById("shelfco"))
	{
           if(validateNonTextfield(elArr[i], "JURState") == false)
           { 		
           	theForm.desired1.select();
           	theForm.desired1.focus();
           	return false;
           }
           
           if(document.onlineOrder.DOSNoShares1.value.length != 0)
           {
                if(validateNonTextfield(elArr[i], "DOSClassShare1") == false)
           	{ 		
                	theForm.DOSNoShares1.select();
                	theForm.DOSNoShares1.focus();
           		return false;
           	}
           }
           if(document.onlineOrder.DOSNoShares2.value.length != 0)
           {
                if(validateNonTextfield(elArr[i], "DOSClassShare2") == false)
           	{ 		
                	theForm.DOSNoShares2.select();
                	theForm.DOSNoShares2.focus();
           		return false;
           	}
           }
           if(document.onlineOrder.DOSNoShares3.value.length != 0)
           {
                if(validateNonTextfield(elArr[i], "DOSClassShare3") == false)
           	{ 		
                	theForm.DOSNoShares3.select();
                	theForm.DOSNoShares3.focus();
           		return false;
           	}
           }

           if(document.onlineOrder.DOSNoShares4.value.length != 0)
           {
                if(validateNonTextfield(elArr[i], "DOSClassShare4") == false)
           	{ 		
                	theForm.DOSNoShares4.select();
                	theForm.DOSNoShares4.focus();
           		return false;
           	}
           }



	  // for DOB
           if(document.onlineOrder.DOSIndType1[0].checked == true)
           {
                if((validateNonTextfield(elArr[i], "DOSBirthDate1day") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate1month") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate1year") == false))
           	   { 		
                	theForm.DOSPostcode1.select();
                	theForm.DOSPostcode1.focus();
           		return false;
           	   }
           }

           if(document.onlineOrder.DOSIndType2[0].checked == true)
           {
                if((validateNonTextfield(elArr[i], "DOSBirthDate2day") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate2month") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate2year") == false))
           	   { 		
                	theForm.DOSPostcode2.select();
                	theForm.DOSPostcode2.focus();
           		return false;
           	   }
           }

           if(document.onlineOrder.DOSIndType3[0].checked == true)
           {
                if((validateNonTextfield(elArr[i], "DOSBirthDate3day") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate3month") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate3year") == false))
           	   { 		
                	theForm.DOSPostcode3.select();
                	theForm.DOSPostcode3.focus();
           		return false;
           	   }
           }

           if(document.onlineOrder.DOSIndType4[0].checked == true)
           {
                if((validateNonTextfield(elArr[i], "DOSBirthDate4day") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate4month") == false) ||
                   (validateNonTextfield(elArr[i], "DOSBirthDate4year") == false))
           	   { 		
                	theForm.DOSPostcode4.select();
                	theForm.DOSPostcode4.focus();
           		return false;
           	   }
           }
           
     	  

         
          
          // Check at least 1 applicant position is checked 
          
          if((document.onlineOrder.DOSDir1.disabled == false) && 
              ( (document.onlineOrder.DOSDir1.checked == false) &&
              	(document.onlineOrder.DOSSec1.checked == false) &&
          	(document.onlineOrder.DOSPO1.checked == false) &&
          	(document.onlineOrder.DOSSH1.checked == false) ))
          {
           
	   	var text1 = "At least one of the applicant positions must be selected for applicant 1\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);

                theForm.DOSDir1.select();
                theForm.DOSDir1.focus();           	
                return false;
          }
          

          
          if((document.onlineOrder.DOSDir2.disabled == false) && 
              ( (document.onlineOrder.DOSDir2.checked == false) &&
              	(document.onlineOrder.DOSSec2.checked == false) &&
          	(document.onlineOrder.DOSPO2.checked == false) &&
          	(document.onlineOrder.DOSSH2.checked == false) ))
          {
           
	   	var text1 = "At least one of the applicant positions must be selected for applicant 2\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);

                theForm.DOSDir2.select();
                theForm.DOSDir2.focus();           	
                return false;
          } 
          
          
          if((document.onlineOrder.DOSDir3.disabled == false) && 
              ( (document.onlineOrder.DOSDir3.checked == false) &&
              	(document.onlineOrder.DOSSec3.checked == false) &&
          	(document.onlineOrder.DOSPO3.checked == false) &&
          	(document.onlineOrder.DOSSH3.checked == false) ))
          {
           
	   	var text1 = "At least one of the applicant positions must be selected for applicant 3\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);

                theForm.DOSDir3.select();
                theForm.DOSDir3.focus();           	
                return false;
          }  
          
                    
          if((document.onlineOrder.DOSDir4.disabled == false) && 
              ( (document.onlineOrder.DOSDir4.checked == false) &&
              	(document.onlineOrder.DOSSec4.checked == false) &&
          	(document.onlineOrder.DOSPO4.checked == false) &&
          	(document.onlineOrder.DOSSH4.checked == false) ))
          {
           
	   	var text1 = "At least one of the applicant positions must be selected for applicant 4\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);

                theForm.DOSDir4.select();
                theForm.DOSDir4.focus();           	
                return false;
          }          
          
          
          
         
 
 
 
            
          


 
           // Check at least 1 applicant is Director
           
           if((document.onlineOrder.DOSDir1.checked == false) &&
               	(document.onlineOrder.DOSDir2.checked == false) &&
           	(document.onlineOrder.DOSDir3.checked == false) &&
           	(document.onlineOrder.DOSDir4.checked == false))
           {
            
 	   	var text1 = "One of the Applicants must hold the position of Director\n";
 		var text2 = "\nHit 'OK' and you will be returned to the form\n";
 		
 	   	alert(text1 + text2);
 
                 theForm.DOSSH1.select();
                 theForm.DOSSH1.focus();           	
                 return false;
           }    



          
          
          
         // At least one applicant must be a shareholder 
          if( 	
          	(document.onlineOrder.DOSSH1.checked == false)  &&
           	(document.onlineOrder.DOSSH2.checked == false)  &&
           	(document.onlineOrder.DOSSH3.checked == false)  &&
           	(document.onlineOrder.DOSSH4.checked == false)  )
          {
           
	   	var text1 = "At least one of the applicants must hold shares. Please select the 'Shareholder' checkbox for at least one applicant.\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);

                theForm.DOSPostcode1.select();
                theForm.DOSPostcode1.focus();           	
                return false;
          }  


           	  
           	  
           // Check at least 1 share requested

           
          if( 	
          	((document.onlineOrder.DOSNoShares1.value==0) || (document.onlineOrder.DOSNoShares1.value==null)) &&
           	((document.onlineOrder.DOSNoShares2.value==0) || (document.onlineOrder.DOSNoShares2.value==null)) &&
           	((document.onlineOrder.DOSNoShares3.value==0) || (document.onlineOrder.DOSNoShares3.value==null)) &&
           	((document.onlineOrder.DOSNoShares4.value==0) || (document.onlineOrder.DOSNoShares4.value==null)) )
          {
           
	   	var text1 = "At least one of the applicants must hold shares. Please allocate shares to at least one of the applicants.\n";
		var text2 = "\nHit 'OK' and you will be returned to the form\n";
		
	   	alert(text1 + text2);
	   	
                theForm.DOSPostcode1.select();
                theForm.DOSPostcode1.focus();           	
                return false;
          }          
          
          
          
          
          
          
          
          
          
          
      }




           with(elArr[i]) 
           { 
///		alert(theForm.name + '.' + elArr[i].name); }}}





              var v = elArr[i].getAttribute("validator");

              if(!v) continue; 
              var thePat = valid[v]; 
              var gotIt = thePat.exec(value); 

// General Checks

              if(! gotIt && (elArr[i].disabled == false) && (elArr[i].style.display != "block"))
              {
 
		if(theForm.name == "forgotid")
		{
             		if(elArr[i].name == "forgotIDEmail")
             		{
              			alert("The email must be entered in a valid format. Please check the entry");
                		theForm.forgotIDEmail.select();
                		theForm.forgotIDEmail.focus(); 
                		return false;
             		}                                 
		} 
		
		if(theForm.name == "enqForm")
		{
             		if(elArr[i].name == "email")
             		{
              			alert("The email must be entered in a valid format. Please check the entry");
                		theForm.email.select();
                		theForm.email.focus(); 
                		return false;
             		}                                 
		} 
              
              
               	if(v == "notBlank")
              	{ 
              		var mess = elArr[i].getAttribute("description");
              		var text = "A Value must be entered for "  +  mess + ". Hit 'OK' and you will be returned to the required field\n";
              		 
             		
              		 alert(text);
              		
                }
              	else if(v == "Date")
              	{              		
              		alert(name + ": not entered in correct Date format dd/mm/yyyy\nHit 'OK' and you will be returned to this field");
                }   
                
              	else if(v == "AlphaNum")
              	{              		
              		var mess = elArr[i].getAttribute("description");
              		var text = "The Value for "  +  mess + " must contain a combination of Letters and/or Numbers only (ie. Characters such as \!, \@, \#, \$, \%, \^, \&, \*, \(, \), \-, \+, \?, \", \', \:, \;, \{, \}, \[, \], \|, \~ etc. are not allowed).\n\nHit 'OK' and you will be returned to the required field.\n";
              		 
               		alert(text);                
                }                                                 
                else 
                {           
                 	alert(name + ": failure to match " + v + " to " + value); 
                }
                
                 
                 elArr[i].select();
                 elArr[i].focus(); 
                 return false;
              }
              
             
              
       if(theForm.name == "onlineOrder")
	{              

  
	   // Number of Members check - Super Deeds
	   
	          if(elArr[i].name == "STNumMEM")
	          {		              	
	              	if((theForm.STtype[0].checked == true) && (theForm.STNumMEM.selectedIndex > theForm.STNumTrustees.selectedIndex))
	              	{
	                 	alert("For Personal Superannuation Trust Deeds, the Number of Members must not exceed the number of Trustees\nTo proceed, alter either the Number of Members or Number of Trustees");
	                   	theForm.MEMFullName1.select();
	                   	theForm.MEMFullName1.focus(); 
	                   	return false;
	                }	                                     
	           }
	           


	// Number of Trustees check - Disc Deeds
	          
	          if(elArr[i].name == "DTNumTrustees")
	          {	           

                	if((theForm.DTtype[1].checked == true) && (theForm.DTNumTrustees.selectedIndex != 0))
           		{
              			alert("For Corporate Discretionary Trust Deeds, there must be only 1 Trustee. Please Alter the number of Trustees to 1");
                		theForm.DTNameTrustee1.select();
                		theForm.DTNameTrustee1.focus(); 
                		return false;
                	}
                  }
                  
                  
            if(elArr[i].name == "agreeterms")
		{	    
		      if(theForm.agreeterms.checked == false)
			{
			     alert("The form cannot be submitted unless you agree to the terms and conditions");
			     	  	return false;
			 }
	     	} 
	           	           
	    }
	    
              	     	     
          }
        }        
        return true;
}





function	partialValidate(theForm) {

 
// End of stuff for messagebox    
   

        var elArr = theForm.elements; 

        for(var i = 0; i < elArr.length; i++) 
        {      
           with(elArr[i]) 
           { 
              var v = elArr[i].getAttribute("validator"); 
              if(!v) continue; 
              var thePat = valid[v]; 
              var gotIt = thePat.exec(value); 

// General Checks
              
	     	                   
// Acceptence check             
	     if(elArr[i].name == "agreeterms")
	     {	    
	     
	     	  if(theForm.agreeterms.checked == false)
	     	  {
	     	  	alert("The form cannot be submitted unless you agree to the terms and conditions");
	     	  	return false;
	     	  }
	     }   
          }
        }
       
	
	
		alert("The End");
	     	return false;	
	
	
	
	
	// theForm.ispdf.value = "false"; 
	theForm.incomplete.value = "true";       
	theForm.submit();       
        return true;
        
}


function pdfForm(theForm) 
{

	if(validateForm(theForm))
	{
		theForm.ispdf.value = "true"; 
		theForm.submit();
        	return true;
        }
}





function validateClientId( s2 ) 
{
 
    if(s2.value.length >= 9)
    {
    		alert("The Client ID '" + s2.value + "' is longer than 8 characters.\n\nPlease choose a Client ID of 8 characters or fewer.");
  	        s2.select();
  	        s2.focus(); 
                return false;
    }
  
  return true;
}
 