
function checkFormOne(){
    /*
    Form one id=screen1
    */
    if (!checkSurname()){
       document.getElementById('surname').focus();
        return false;
        }
        
    if (!checkFirstname()){
        document.getElementById('firstname').focus();
        return false;
        }  
        
    if (!checkTel()){
        document.getElementById('tel').focus();
        return false;
        }  
    if (!checkEmail()){
        document.getElementById('email').focus();
        return false;
        }  
        
    if (!checkAddress()){
        document.getElementById('address').focus();
        return false;
        } 
        
    if (!checkGender()){
        return false;
        }
        
    if (!checkExecutor()){
        document.getElementById('executorAS').focus();
        return false;
        } 
     if (!checkMaritalStatus()){
        document.getElementById('m0').focus();
        return false;
        }
        return true;
    }
    
    /*form 3 , id="screen3"*/
    
function checkFormThree(){
    /*
    Form three id=screen3
    */
    if (!checkChildren()){
        return false;
        }
    if (!checkBen()){
        return false;
        }
        
     return true;
    }
    
    
function checkFormFive(){
     if (!checkTrustee()){
        return false;
        }
        
    if (!checkGuardian()){
        return false;
        }
        
    return true;

    }
    
    
    
function checkSurname(){
    var name =  document.getElementById('surname').value;
    if(checkBlank(name)){
        document.getElementById('surnameString').style.color = "#ff0000";
        return false;
    }else{
        document.getElementById('surnameString').style.color = "#666666";
         return true;
        }
   
    }
    
function checkFirstname(){
    var name =  document.getElementById('firstname').value;
    if(checkBlank(name)){
        document.getElementById('firstnameString').style.color = "#ff0000";
        return false;
    }else{
        document.getElementById('firstnameString').style.color = "#666666";
         return true;
        }
   
    }    
    
function checkTel(){
    var name =  document.getElementById('tel').value;
    if(checkBlank(name)){
        document.getElementById('telString').style.color = "#ff0000";
        return false;
       
    }else if (name.match(/^[+]\d{11}/) && name.length == 12){
        document.getElementById('telString').style.color = "#666666";
        return true;
    
        
    }else{
    
	 document.getElementById('telString').style.color = "#ff0000";
        alert("Please enter a valid Telephone Number \n" +
              "with your county's code \n i.e +27123456789");

        }
    }  

function checkEmail(){
    var email = document.getElementById('email').value;
    if (checkBlank(email)){
         document.getElementById('emailString').style.color = "#ff0000";
        return false;
        }
    var atIndex = email.indexOf("@");
    if (atIndex == -1){
        alert("Please enter a valid email address with a @ !");
        return false;
        }
    if (email.indexOf(".", atIndex) == -1){
        alert("Please enter a valid domain after @");
        return false;
        }
    document.getElementById('emailString').style.color = "#666666";
    return true;
    }
    
function checkAddress(){
    var name =  document.getElementById('address').value;
    if(checkBlank(name)){
        document.getElementById('addressString').style.color = "#ff0000";
        return false;
    }else{
         document.getElementById('addressString').style.color = "#666666";
         return true;
        }
    }  

function checkGender(){
    if (document.getElementById('male').checked){
        document.getElementById('genderString').style.color = "#666666";
        return true;
        }
    if (document.getElementById('female').checked){
        document.getElementById('genderString').style.color = "#666666";
        return true;
        }
    document.getElementById('genderString').style.color = "#ff0000";
    return false;
    }
    
function checkExecutor(){
    var count = 0;
    
    if (document.getElementById('g1').checked){
        count++;
    }
    
    if (document.getElementById('g2').checked){
        count++;
        var name =  document.getElementById('executor').value;
        if(checkBlank(name)){
            document.getElementById('g2String').style.color = "#ff0000";
            alert("Please enter full name of Executor:");
        return false;
        }
    }
    
    if(count > 0){
        document.getElementById('g2String').style.color = "#666666"; 
        document.getElementById('check1').style.color = "#666666"; 
        document.getElementById('check2').style.color = "#666666"; 
        
        return true;
    }else{
         document.getElementById('check1').style.color = "#ff0000";
         document.getElementById('check2').style.color = "#ff0000";
        alert("Please select a senior partner");
        } 
}


function checkMaritalStatus(){
    var count = 0;
    
    if (document.getElementById('m0').checked){
        document.getElementById('maritalStatusString').style.color = "#666666";
        count++;
        return true;
    }
   
    if (document.getElementById('m1').checked){
        document.getElementById('maritalStatusString').style.color = "#666666";
        count++;
        return true;
    }
    if (document.getElementById('m2').checked){
        document.getElementById('maritalStatusString').style.color = "#666666";
        count++;
        return true;
    }
    
    if (document.getElementById('m3').checked){
        document.getElementById('maritalStatusString').style.color = "#666666";
        count++;
        return true;
    }
    
        document.getElementById('maritalStatusString').style.color = "#ff0000";
        return false;
     
    
    }    
     
     /*Form 3 id="screen3"*/
function checkChildren(){
    if (document.getElementById('childrenYes').checked){
        for (var kidcount=1;kidcount <= document.getElementById('numChildren').value; kidcount++){
            var name =  document.getElementById("childrenText" + kidcount).value;
            if(checkBlank(name)){
                document.getElementById('childrenStringName' + kidcount).style.color = "#ff0000";
                return false;
            }else{
                document.getElementById('childrenStringName' + kidcount).style.color = "#666666";
                var name = document.getElementById("childrenIDText" + kidcount).value;
                if(checkBlank(name)){
                    document.getElementById("childrenID" + kidcount).style.color = "#ff0000";
                    return false;
                }else if (name.match(/^\d{2}[-]\d{2}[-]\d{2}/)){
                    document.getElementById('childrenID' + kidcount).style.color = "#666666";
                    return true;  
                }else if (name.match(/^\d{13}/) && name.length == 13){
                    document.getElementById('childrenID' + kidcount).style.color = "#666666";
                    return true;    
                    
                }else{
                    
                    alert("CHILDREN: - Please Enter a Numeric Number for the Identity number and it must be a 13 Digit number\n"+
                    "Or enter the date of birth in this format DD-MM-YY");
                    return false;
                    }
                }
            }
       
        }
        return true;    
    }


function checkBen(){
    if (document.getElementById('bensNo').checked){
        for (var kidcount=1;kidcount <= document.getElementById('numbens').value; kidcount++){
            var name =  document.getElementById("benText" + kidcount).value;
            if(checkBlank(name)){
                document.getElementById('benStringName' + kidcount).style.color = "#ff0000";
                return false;
            }else{
                document.getElementById('benStringName' + kidcount).style.color = "#666666";
                var name = document.getElementById("benIDText" + kidcount).value;
                if(checkBlank(name)){
                    document.getElementById("benID" + kidcount).style.color = "#ff0000";
                    return false;
                }else if (name.match(/^\d{2}[-]\d{2}[-]\d{2}/)){
                    document.getElementById('benID' + kidcount).style.color = "#666666";
                    return true;  
                }else if (name.match(/^\d{13}/) && name.length == 13){
                    document.getElementById('benID' + kidcount).style.color = "#666666";
                    return true;    
                    
                }else{
                    
                    alert("BENEFICIARIES: - Please Enter a Numeric Number for the Identity number and it must be a 13 Digit number\n"+
                    "Or enter the date of birth in this format DD-MM-YY");
                    return false;
                    }
                }
            }
       
        }
        return true;    
    }
        
    //Form 4. Screen 4    
   //Its in the actual html, calculateBequest()
   
   
   //Form 5
   
function checkTrustee(){
    
   
    
    if (document.getElementById('t1').checked && !document.getElementById('trusteeCheck').checked){
    
       return true;    
    }
    
    if(!document.getElementById('t1').checked && !document.getElementById('trusteeCheck').checked){
        document.getElementById('trust1').style.color = "#ff0000";
        return false;   
        }else {
        document.getElementById('trust1').style.color = "#666666";
        }
    
    if(document.getElementById('trusteeCheck').checked){
        for(var kidcount=1;kidcount <= document.getElementById('numTrustee').value; kidcount++){
            var name =  document.getElementById("trusteename" + kidcount).value;
            if(checkBlank(name)){
                document.getElementById("trusteenameText" + kidcount).style.color = "#ff0000";
                document.getElementById('red').style.color = "#ff0000";
                return false;
            }else{
                 document.getElementById("trusteenameText" + kidcount).style.color = "#666666";
                 document.getElementById('red').style.color = "#666666";
                
                }
            }
        return true;    
        } 
    }  
    
function checkGuardian(){

    if (document.getElementById('guardianNo').checked){
        return true;
    }
    if(document.getElementById('guardianYes').checked){
    for( var kidcount=1;kidcount <= document.getElementById('numGuard').value; kidcount++){
        var name =  document.getElementById("guardiansList" +kidcount).value;
        if(checkBlank(name)){
            document.getElementById("guardnameText" + kidcount).style.color = "#ff0000";
            document.getElementById('red2').style.color = "#ff0000";
            return false;
        }else{
             document.getElementById("guardnameText" + kidcount).style.color = "#666666";
             document.getElementById('red2').style.color = "#666666";
            
            }
        }
        return true;
    }
         
}  


   

function checkBlank(string){
    if (string.length == 0)
        return true;
    for (var i =0; i <= string.length-1; i++)
        if (string.charAt(i) != " ")
        return false;
    return true;
        }
    

