﻿

 function WarnBeforeClear(){
 
    return confirm("This action will clear all the text you have entered. Is this what you want to do?");
    
 
 }


 function ValidateFields()
   {
        var firstName   = document.forms[0]['firstNameTextBox'];
        var lastName   = document.forms[0]['surnameTextBox'];
        var contactPhone = document.forms[0]['workPhoneTextBox'];
        var email = document.forms[0]['emailAddress'];
  
    if(firstName)
    {
        if (firstName && firstName.value.length == 0)
        {
            firstName.style.backgroundColor = "lightyellow";
            firstName.select();
            window.scrollTo(0,450);
            alert("A first name is required");
            return false;
        }
        else  firstName.style.backgroundColor = "white";
       
    }
   
    if(lastName){          
        if (lastName.value.length == 0)
        {
            lastName.style.backgroundColor = "lightyellow";
            lastName.select();
            window.scrollTo(0,450);
            alert("A last name is required");
            return false;
        }
        else  lastName.style.backgroundColor = "white";
    }
    
    
  
    if(email){    
        if (email.value.length == 0)
        {
            email.style.backgroundColor = "lightyellow";
            email.select();
            window.scrollTo(0,450);
            alert("Please enter an email address");
            return false;
        }
        else email.style.backgroundColor = "white";
        
        //validate the email format is correct
        var regexp =  /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

            
        if ( regexp.exec(email.value) == null)
        {
            email.style.backgroundColor = "lightyellow";
            email.select();
            window.scrollTo(0,450);
             alert("Please ensure the email address is valid");
            return false;
        }
        else  email.style.backgroundColor = "white";
        
     }  
     
     
     if(contactPhone){
        if (contactPhone.value.length == 0 && document.forms[0]['homePhoneTextBox'].value.length==0)
        {
            contactPhone.style.backgroundColor = "lightyellow";
            contactPhone.select();
            window.scrollTo(0,450);
            alert("At least one contact phone number is required.");
            return false;
        }
        else  contactPhone.style.backgroundColor = "white";
    }
     
        
     return true;
}