var errorcolor="#F3FD7F"; //this is the error hightlight color of fields
var normalcolor="#ffffff"  // this is the normal background of fields

function checkParentalConsentTerms() {
	if (document.termsForm.terms.checked) {
		window.location="/life/sports/parental_consent_form.pdf";
	} else { alert("You must agree to ChannelOne.com's terms.\n\nPlease check this box to agree."); }
}

function validateform(formname) {  
  	var alertMessage = "Please enter the following: \n\n";
	var isAlert = false;

    // The following makes sure a field is NOT EMPTY  (validateNotEmpty) Repeat As necessary


    // Makes sure the Date of dob Fields arent empty
    if(!validateNotEmpty (formname.dobMonth.value)){
    	alertMessage += "Month of birth \n";
    	formname.dobMonth.style.background=errorcolor;
    	isAlert = true;	
    }
    if(!validateNotEmpty (formname.dobDay.value)){
    	alertMessage += "Day of birth \n";
    	formname.dobDay.style.background=errorcolor;
    	isAlert = true;	
    }
    if(!validateNotEmpty (formname.dobYear.value)){
    	alertMessage += "Year of birth \n\n";
    	formname.dobYear.style.background=errorcolor;
    	isAlert = true;	
    }	


    if(!validateNotEmpty (formname.firstName.value)){
    	alertMessage += "First Name \n";
    	formname.firstName.style.background=errorcolor
    	isAlert = true;	
    }
    
     if(!validateNotEmpty (formname.lastName.value)){
    	alertMessage += "Last Name \n";
    	formname.lastName.style.background=errorcolor;
    	isAlert = true;	
    }
    
    // The following Validates Emails are in correct Syntax
    if(!validateNotEmpty (formname.email.value)){
    	alertMessage += "Email \n";
    	formname.email.style.background=errorcolor;
	   	isAlert = true;	
	}else{	
		if(!validateEmail(formname.email.value)){
	    	alertMessage += "Email: Improper syntax \n";
	    	formname.email.style.background=errorcolor;
		   	isAlert = true;	
	   }	
    }

 
    if(!validateNotEmpty (formname.address1.value)){
    	alertMessage += "Address \n";
    	formname.address1.style.background=errorcolor;
    	isAlert = true;	
    }
	
	if(!validateNotEmpty (formname.city.value)){
    	alertMessage += "City \n";
    	formname.city.style.background=errorcolor;
    	isAlert = true;	
    }
    
    if(!validateNotEmpty (formname.state.value)){
    	alertMessage += "State \n";
    	formname.state.style.background=errorcolor;
    	isAlert = true;	
    }

	
    if(!validateNotEmpty (formname.zip.value)){
    	alertMessage += "Zip \n";
    	formname.zip.style.background=errorcolor;
    	isAlert = true;	
    }

 
    if(!validateNotEmpty (formname.phone.value)){
    	alertMessage += "Phone \n";
    	formname.phone.style.background=errorcolor;
    	isAlert = true;	
    }

    if(!validateNotEmpty (formname.optionalTextarea1.value)){
    	alertMessage += "School Name \n";
    	formname.optionalTextarea1.style.background=errorcolor;
    	isAlert = true;	
    }
		
    if(!validateNotEmpty (formname.optionalTextarea2.value)){
    	alertMessage += "School Address \n";
    	formname.optionalTextarea2.style.background=errorcolor;
    	isAlert = true;	
    }

/*
    if(!validateNotEmpty (formname.optionalTextarea3.value)){
    	alertMessage += "School Address2 \n";
    	formname.optionalTextarea3.style.background=errorcolor;
    	isAlert = true;	
    }
*/
    if(!validateNotEmpty (formname.optionalTextarea4.value)){
    	alertMessage += "School Phone \n";
    	formname.optionalTextarea4.style.background=errorcolor;
    	isAlert = true;	
    }

    if(!validateNotEmpty (formname.optionalText5.value)){
    	alertMessage += "Date of the play \n";
    	formname.optionalText5.style.background=errorcolor;
    	isAlert = true;	
    }

    if(!validateNotEmpty (formname.optionalTextarea5.value)){
    	alertMessage += "Description of the play \n";
    	formname.optionalTextarea5.style.background=errorcolor;
    	isAlert = true;	
    }else {
		var MAX_DESC_CHAR = 10000;
		var num_charaters = document.ch1_form.optionalTextarea5.value.length;
		if(num_charaters > MAX_DESC_CHAR) {
			alertMessage += "Oops! Your feedback is too long. The total number of characters including space in your feedback is " + num_charaters + ". The maximum we are able to accept is " + MAX_DESC_CHAR + ". \n";
	       	isAlert = true;		
		}	
	}

	
	if(isAlert) {
		alert(alertMessage);
		return false;
    } else { //  *** This takes the THREE DOB fields (MONTH,DAY,YEAR) and puts them into one field (DOB) for Coppa validation
	   	var dob = formname.dobMonth.value+ "/" + formname.dobDay.value +"/"+ formname.dobYear.value;
	   	formname.dob.value=dob;
		removeCarriageReturn();
//    	alert (dob);
		return true;	
    }

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	removeCarriageReturn
//	Replace the cariage return with <br/> tag
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function removeCarriageReturn() {
	var textAreaStr = escape(document.ch1_form.optionalTextarea5.value);
	document.ch1_form.optionalTextarea5.value = textAreaStr.replace("%0A", "<br/>","g");
	return null;
}

