
/* JavaScript functions for validating form */

function validData(contestEntry){
	
	var error_string = "";
	
	//check the entry
	if((document.contestEntry.songName.value=='')||
	(document.contestEntry.songName.value.length <=1)){
		error_string += "Title of our Mystery Song!\n";
		document.getElementById("songLbl").style.color="#990000";
	}else{
		document.getElementById("songLbl").style.color="#000";
	}

	if((document.contestEntry.artistName.value=='')||
	(document.contestEntry.artistName.value.length <=1)){
		error_string += "Name of our Mystery Artist!\n";
		document.getElementById("artistLbl").style.color="#990000";
	}else{
		document.getElementById("artistLbl").style.color="#000";
	}


		
	// check the name fields
	if ((document.contestEntry.first_name.value == '')|| (document.contestEntry.first_name.value.length <=1)){
		error_string += "Your first name.\n";
		document.getElementById("first").style.color="#990000";
			
	}else{	
		document.getElementById("first").style.color="#000";
	}
	
	if ((document.contestEntry.last_name.value == '')|| (document.contestEntry.last_name.value.length <=1)){
		error_string += "Your last name.\n";
		document.getElementById("last").style.color="#990000";
			
	}else{	
		document.getElementById("last").style.color="#000";
	}
	
	if ((document.contestEntry.address1.value == '')|| (document.contestEntry.address1.value.length <=1)){
		error_string += "Address.\n";
		document.getElementById("addr").style.color="#990000";
	}else{	
		document.getElementById("addr").style.color="#000";
	}

	//check city field
	if ((document.contestEntry.city.value =='')||(document.contestEntry.city.value.length <=1)){
		error_string += "City.\n";
		document.getElementById("cty").style.color="#990000";
	}else{	
		document.getElementById("cty").style.color="#000";
	}
	
	
		//check phone
	if (checkPhone(document.contestEntry.phone.value) == true){
		error_string += "Phone Number.\n";
		document.getElementById("phoneNum").style.color="#990000";	
	}else{	
		document.getElementById("phoneNum").style.color="#000";
	} 

	//check email
	if (checkEmail(document.contestEntry.email.value) == true){
		error_string += "E-Mail Address.\n";
		document.getElementById("eml").style.color="#990000";	
	}else{	
		document.getElementById("eml").style.color="#000";
	} 
	
		//check checkbox
	if (document.contestEntry.readRules.checked==false){
		error_string +="Please check the box to certify that you have read and understand the rules.\n";
		document.getElementById("rulesLbl").style.color="#990000";
	}else{
		document.getElementById("rulesLbl").style.color="#000";
	}
		
		
	if(error_string ==""){

		return true;
	}
	
	else{
		error_string = "The following items were not filled in correctly: \n\n" +error_string +"\nThank you\n\n";
		alert(error_string);
		return false;
	}
}	
	
	
function checkPhone(numString){
	
	var regex=/^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;	
	var regexA=/^\(?\d{3}\)?-?\s*\d{3}\s*?-?\d{4}$/;
	
	
	if((!(regexA.test(numString))) && (!(regex.test(numString))) ){
		return true;
	}
	
	if(numString == ''){
		return true;
	}
	
}


function checkEmail(addy){
	
	var regex=/^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	if (!(regex.test(document.contestEntry.email.value)))
	{
		return true;
	}

}

