

var errorcolor = "#FFD600"; //this is the error hightlight color of fields
var normalcolor = "#ffffff"  // this is the normal background of fields

function radio_button_checker( objValue )
{   // set var radio_choice to false
    var radio_choice = false;
    // Loop from zero to the one minus the number of radio button selections
    for( counter = 0; counter < objValue.length; counter++ )
    {   // If a radio button has been selected it will return true
        // (If not it will return false)
        if( objValue[counter].checked )
        {   radio_choice = true;
        }
    }
    if( !radio_choice )
    {   // If there were no selections made display an alert box
        return( false );
    }
    return( true );
}

function validatePersonForm()
{
//setting the out to false will exit the loop.
var out = true;
while (out) {  

  var alertMessage = "Registration Error! \n\nPlease enter your: \n";
    var isAlert = false;

  
    // The following makes sure a field is NOT EMPTY  (validateNotEmpty) Repeat As necessary
    if( !validateNotEmpty( document.registrationForm.firstName.value ) )
    {   
		alertMessage += "First Name \n";
        document.registrationForm.firstName.style.background = errorcolor
        isAlert = true;
    } else { document.registrationForm.firstName.style.background = normalcolor; }

    if( !validateNotEmpty( document.registrationForm.lastName.value ) )
    {   
		alertMessage += "Last Name \n";
        document.registrationForm.lastName.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.lastName.style.background = normalcolor; }

    if( !validateNotEmpty( document.registrationForm.address1.value ) )
    {   
		alertMessage += "Address 1 \n";
        document.registrationForm.address1.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.address1.style.background = normalcolor; }

    if( !validateNotEmpty( document.registrationForm.city.value ) ) 
    {   
		alertMessage += "City \n";
        document.registrationForm.city.style.background = errorcolor;
        isAlert = true;
    } else { //document.registrationForm.city.style.background = normalcolor; 
		if (!validateCity()) {break;}	
}


    if( !validateNotEmpty( document.registrationForm.zipcode.value ) )
    {   
		alertMessage += "Zip \n";
        document.registrationForm.zipcode.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.zipcode.style.background = normalcolor; }

    // The following Validates Emails are in correct Syntax
    if( !validateEmail( document.registrationForm.email.value ) )
    {  
		alertMessage += "Email \n";
        document.registrationForm.email.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.email.style.background = normalcolor; }

   

    if( !validateNotEmpty( document.registrationForm.password.value ) )
    {   
		alertMessage += "password \n";
        document.registrationForm.password.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.password.style.background = normalcolor; }
    

    

 if( !isDate( document.registrationForm.dateOfBirth.value ) )
    {   
		alertMessage += "date of birth \n";
        document.registrationForm.dateOfBirth.style.background = errorcolor;
        isAlert = true;
    } else { document.registrationForm.dateOfBirth.style.background = normalcolor; }
    
	
	
    if( isAlert )
    {   alert( alertMessage );
	out = false;
    }
    else { 
		if(IsUnderage(document.registrationForm))
		{
		//alert("is under age");
		out = false;
		}
		else{
	 	out = false;
	 	document.registrationForm.submit();
		}
    }
  }
}


function validateUploadForm()
{
//setting the out to false will exit the loop.
var out = true;
while (out) {  
  var alertMessage = "Upload Error! \n\nPlease enter your: \n";
    var isAlert = false;
	
	if( !validateNotEmpty( document.photoUploadForm.uploadEntryFile.value ) )
    {  
		alertMessage += "Photo \n";
        document.photoUploadForm.uploadEntryFile.style.background = errorcolor;
        isAlert = true;
    } else { document.photoUploadForm.uploadEntryFile.style.background = normalcolor; }

	if( !validateNotEmpty( document.photoUploadForm.title.value ) )
    {   
		alertMessage += "Title \n";
        document.photoUploadForm.title.style.background = errorcolor;
        isAlert = true;
    } else { document.photoUploadForm.title.style.background = normalcolor; }

	if( !validateNotEmpty( document.photoUploadForm.text.value ) )
    {  
		alertMessage += "Message \n";
        document.photoUploadForm.text.style.background = errorcolor;
        isAlert = true;
    } else { document.photoUploadForm.text.style.background = normalcolor; }

	if( isAlert )
    {   alert( alertMessage );
		out = false;
    }
    else { 
	 	out = false;
	 	document.photoUploadForm.submit();
    }
	
}
	
}

function validateCity () {
    var alertMessage = "Registration Error! \n\n";
    //var isAlert = false;
    if( !isNaN( document.registrationForm.city.value ) )
    {   alertMessage += "City cannot have numeric values \n";
        document.registrationForm.city.style.background = errorcolor;
      //  isAlert = true;
	alert( alertMessage );
	return false;
    } else { document.registrationForm.city.style.background = normalcolor;
	     return true; }

    //if( isAlert )
    //{   alert( alertMessage );
    //}
    //else {   
	//validatePhone();
    //}
}







