	var error_msg;
	var missing = new Array();
	var gray = null;
	var error_ctr = null;
	var error_txt = null;
	var fields = null;
	var email_pattern = new RegExp("^[A-Za-z_]{1}[A-Za-z0-9_]*@[A-Za-z0-9_]{1,}\.[A-Za-z0-9_]{2,}$");
	var bday_pattern = new RegExp("^[0-9]{2}/[0-9]{2}/[0-9]{4}$");
	
	window.onload = init;
	
	function init(){
		
		gray = document.getElementById("gray_screen");
		error_ctr = document.getElementById("error_ctr");
		error_txt =  error_ctr.getElementsByTagName("span")[0];
		var submission_form = document.getElementById("submission_form");
		fields = submission_form.getElementsByTagName("input");
		Custom.init();
		
		//alert("start");
	}
	
	function checkSubmission(f){
		error_msg = "";
		error_txt.innerHTML = "";
		missing = new Array();
		for(i=0; i<fields.length; i++){
			checkField(fields[i]);
		}
		if(error_msg==""){
			return true; 
		}else{
			error_handler();
			return false;
		}
	}
	
	function checkEmpty(f,m){
		if(f.value==""){
			error_msg += m + "\n";
			missing.push([f,m]);
		}
	}
	
	function checkSize(f,m,n){
		if(f.value.length < n){
			error_msg += m + "\n";
			missing.push([f,m]);
		}
	}
	
	function checkEmail(f,m){
		if(!email_pattern.test(f.value)){
			error_msg += m + "\n";
			missing.push([f,m]);
		}
	}
	
	function checkDate(f,m){
		if(!bday_pattern.test(f.value)){
			error_msg += m + "\n";
			missing.push([f,m]);
		}
	}
	
	function checkTrue(f,m){
		if(!f.checked){
			error_msg += m + "\n";
			missing.push([f,m]);
		}
	}
	
	function error_handler(){
		if(error_msg!=""){
			var error_ctr = document.getElementById("error_ctr");
			error_txt = error_ctr.getElementsByTagName("span")[0];
			for(i=0;i<fields.length;i++){
				fields[i].style.border = "none";
			}
			for(i=0; i<missing.length; i++){
				error_txt.innerHTML += "<div class=\"error_msg\">" + missing[i][1] + "</div>";
				missing[i][0].style.border = "1px solid red";
			}
			showErrors(error_ctr);
			//return false;
		}
	}
	
	function showErrors(e){
		error_ctr.style.display = "block";
		gray.style.height = getWinHeight();
		//alert(getWinHeight());
		gray.style.display = "block";
	}
	

	function getWinHeight(){
			var y = 0;
			if (window.scrollHeight)
			{
					y = window.scrollHeight;
			}
			else if (document.documentElement && document.documentElement.clientHeight)
			{
					y = document.documentElement.clientHeight;
			}
			else if (document.body)
			{
					y = document.body.clientHeight;
			}
			
			
			return document.body.scrollHeight +"px";
	}
	
	function hideErrors(){
		error_ctr.style.display = "none";
		gray.style.display = "none";
	}
	
	function checkField(f){
			//alert(f.name);
			switch(f.name){
				
				case 'yt_username':
					checkSize(f, "Please enter a valid YouTube username",2);
					break;
					
				case 'fn':
					checkSize(f, "Please enter a valid first name",2);
					break;
					
				case 'ln':
					checkSize(f, "Please enter a valid last name",2);
					break;
					
				case 'yt_link':
					checkEmpty(f, "Please enter a YouTube video link");
					break;
					
				case 'code_country':
					checkSize(f, "Please enter valid zip code or country",4);
					break;
					
				case 'e_add':
					checkEmail(f, "Please enter valid email address");
					break;
					
				case 'operator':
					checkSize(f, "Please enter your league operator",2);
					break;
					
				case 'of_age':
					checkTrue(f, "You must certify that you are 18 or older to participate.");
					break;
					
				case 'rules':
					checkTrue(f, "You must read and agree to the <a href='rules.html'>OFFICIAL RULES</a> and <a href='submission.html'>SUBMISSION AGREEMENT</a>.");
					break;
					
				default:
					break;
			}	
	}