
var errorcolor = "#FFD600"; //this is the error hightlight color of fields
var normalcolor = "#ffffff"  // this is the normal background of fields




function validatePersonForm()
{
//setting the out to false will exit the loop.
//alert("here");
var out = true;
while (out) {  

  var alertMessage = "Profile Update Error! \n\nPlease enter your: \n";
    var isAlert = false;

  //alert("firstName="+document.command.firstName.value );
    // The following makes sure a field is NOT EMPTY  (validateNotEmpty) Repeat As necessary
    if( !validateNotEmpty( document.command.firstName.value ) )
    {   
		alertMessage += "First Name \n";
        document.command.firstName.style.background = errorcolor
        isAlert = true;
    } else { document.command.firstName.style.background = normalcolor; }
 //alert("lastName="+document.command.lastName.value );
    if( !validateNotEmpty( document.command.lastName.value ) )
    {   
		alertMessage += "Last Name \n";
        document.command.lastName.style.background = errorcolor;
        isAlert = true;
    } else { document.command.lastName.style.background = normalcolor; }
//alert("address1="+document.command.address1.value );
    if( !validateNotEmpty( document.command.address1.value ) )
    {   
		alertMessage += "Address 1 \n";
        document.command.address1.style.background = errorcolor;
        isAlert = true;
    } else { document.command.address1.style.background = normalcolor; }

	 //alert("city=="+document.command.city.value );
    if( !validateNotEmpty( document.command.city.value ) ) 
    {   
		alertMessage += "City \n";
        document.command.city.style.background = errorcolor;
        isAlert = true;
    } else { document.command.city.style.background = normalcolor; 	}

 //alert("state=="+document.command.state.value );
    if( !validateNotEmpty( document.command.state.value ) )
    {   
		alertMessage += "State\n";
        document.command.state.style.background = errorcolor;
        isAlert = true;
    } else { document.command.state.style.background = normalcolor; }
//alert("zipcode=="+document.command.zipcode.value );
    if( !validateNotEmpty( document.command.zipcode.value ) )
    {   
		alertMessage += "Zip \n";
        document.command.zipcode.style.background = errorcolor;
        isAlert = true;
    } else { document.command.zipcode.style.background = normalcolor; }

    // The following Validates Emails are in correct Syntax
	//alert("email=="+document.command.email.value );
    if( !validateEmail( document.command.email.value ) )
    {  
		alertMessage += "Email \n";
        document.command.email.style.background = errorcolor;
        isAlert = true;
    } else { 
		document.command.email.style.background = normalcolor; 
		
	}
	//alert(document.command.emailConfirm.value);
    if( !validateNotEmpty( document.command.emailConfirm.value ) || document.command.emailConfirm.value != document.command.email.value )
    {   
		alertMessage += "Email confirmation\n";
        document.command.emailConfirm.style.background = errorcolor;
        isAlert = true;
    } else { document.command.emailConfirm.style.background = normalcolor; }

	//alert(document.command.areaCode.value);
	
	  if( !validateNotEmpty( document.command.areaCode.value ) )
    {  
		alertMessage += "Phone Number: area code \n";
        document.command.areaCode.style.background = errorcolor;
        isAlert = true;
    } else { document.command.areaCode.style.background = normalcolor; }

     if( !validateNotEmpty( document.command.first3Digits.value ) )
    {  
		alertMessage += "Phone Number: first 3 digits \n";
        document.command.first3Digits.style.background = errorcolor;
        isAlert = true;
    } else { document.command.first3Digits.style.background = normalcolor; }


     if( !validateNotEmpty( document.command.last4Digits.value ) )
    {  
		alertMessage += "Phone Number: last 4 digits \n";
        document.command.last4Digits.style.background = errorcolor;
        isAlert = true;
    } else { document.command.last4Digits.style.background = normalcolor; }
	
	 if( validateNotEmpty( document.command.areaCode.value ) && validateNotEmpty( document.command.first3Digits.value ) && validateNotEmpty( document.command.last4Digits.value )){
	 
	 	document.command.phoneNumber.value=document.command.areaCode.value+"-"+document.command.first3Digits.value+document.command.last4Digits.value
	 }
	
	// Makes sure the Date of Birth Fields arent empty
    if( !validateNotEmpty( document.command.dobMonth.value ) )
    {  
		alertMessage += "Birth date: Month \n";
        document.command.dobMonth.style.background = errorcolor;
        isAlert = true;
    } else { document.command.dobMonth.style.background = normalcolor; }

    if( !validateNotEmpty( document.command.dobDay.value ) )
    {   
		alertMessage += "Birth date: Day \n";
        document.command.dobDay.style.background = errorcolor;
        isAlert = true;
    } else { document.command.dobDay.style.background = normalcolor; }

    if( !validateNotEmpty( document.command.dobYear.value ) )
    {   
		alertMessage += "Birth date: Year \n";
        document.command.dobYear.style.background = errorcolor;
        isAlert = true;
    } else { document.command.dobYear.style.background = normalcolor; }

	 if( validateNotEmpty( document.command.dobMonth.value )  && validateNotEmpty( document.command.dobDay.value ) &&  validateNotEmpty( document.command.dobYear.value ))
    {
		document.command.birthDate.value = document.command.dobMonth.value + "/" + document.command.dobDay.value + "/" + document.command.dobYear.value;
		
	}
	
	
	
	
	
	if( !validateNotEmpty( document.command.gender.value ) )
    {   
		alertMessage += "Gender \n";
        document.command.gender.style.background = errorcolor;
        isAlert = true;
    } else { 
		document.command.gender.style.background = normalcolor; 
		
	}
	
		
	if( !validateNotEmpty( document.command.personId.value ) )
	{
		if( !validateNotEmpty( document.command.username.value ) )
    	{   
			alertMessage += "Username \n";
        	document.command.username.style.background = errorcolor;
        	isAlert = true;
    	} else { 
			document.command.username.style.background = normalcolor; 
		}
	}
	
    if( !validateNotEmpty( document.command.password.value ) )
    {   
		alertMessage += "Password \n";
        document.command.password.style.background = errorcolor;
        isAlert = true;
    } else { 
		document.command.password.style.background = normalcolor; 
		
	}
	
    if( !validateNotEmpty( document.command.passwordConfirm.value ) || document.command.passwordConfirm.value != document.command.password.value )
    {  
		alertMessage += "Password Confirm\n";
        document.command.passwordConfirm.style.background = errorcolor;
        isAlert = true;
    } else { document.command.passwordConfirm.style.background = normalcolor; }
 
	
	
    if( isAlert )
    {   alert( alertMessage );
	out = false;
    }
    else { 
		if(IsUnderage(document.command))
		{
		//alert("is under age");
		out = false;
		}
		else{
	 	out = false;
	 	document.command.submit();
		}
    }
  }
}
