function reloadForm(){
	document.getElementById('consumer').checked=false;	
	document.getElementById('professional').checked=false;	
	document.getElementById('yes').checked=false;		
}

function preloadValues(course_type, course_option, course_date, course_location){
		if(course_type == 'consumer'){
			document.getElementById('consumer').checked=true;	
			document.getElementById("consumer_options").style.display="block";
			document.getElementById("class").selectedIndex = course_option;
		}
		
		if(course_type == 'professional'){
			document.getElementById('professional').checked=true;	
			document.getElementById("professional_options").style.display="block";	
			document.getElementById("workshop").selectedIndex = course_option;
		}
		
		if(course_date != ""){
			document.getElementById("course_calendar").style.display="block";
			document.getElementById("course_date").value = course_date;	
		}
		
		if(course_location != ""){
			document.getElementById("location").selectedIndex = course_location;	
		}
		
		
}

function checkForm(){
	
	clearErrors();
	var inputs =  document.getElementsByTagName('input');
	var pass = true;
	
	for(var i=0; i<inputs.length; i++){
	
		if(inputs[i].id == "first_name" || inputs[i].id == "last_name" || inputs[i].id  == "phone_number" || inputs[i].id  == "email_address"){
				if(inputs[i].value == ""){
				pass = showError(inputs[i].id + "_Error");}
		}
		
		if(inputs[i].id  == "email_address" ){
			if(!checkEmail(inputs[i].value)){
				pass = showError(inputs[i].id + "_Error");
				
			}
		}
		
		if(inputs[i].value != "" && inputs[i].id == "phone_number" ){
			if(!checkPhone(inputs[i].value)){
				pass = showError(inputs[i].id + "_Error");
				
			}
		}
		
		
			
	}
	
	
	return pass;


}

function openClasses(){
	document.getElementById("consumer_options").style.display="block";	
	document.getElementById("course_calendar").style.display="block";	
	document.getElementById("professional_options").style.display="none";	
}

function openWorkshops(){
	document.getElementById("professional_options").style.display="block";	
	document.getElementById("course_calendar").style.display="block";	
	document.getElementById("consumer_options").style.display="none";	
}

function openCredits(){
	document.getElementById("credit_options").style.display="block";	
}

function closeCredits(){
	document.getElementById("credit_options").style.display="none";	
}

function isNumeric(string){
			var validChars = "0123456789.-";
			var currentChar;
			for (var i = 0; i < string.length; i++){
      			currentChar = string.charAt(i);
      			if (validChars.indexOf(currentChar) == -1){
         			return false;
         		}
      		}
			return true;
	}
	
function isNotNumeric(string){
			var invalidChars = "0123456789";
			var currentChar;
			for (var i = 0; i < string.length; i++){
      			currentChar = string.charAt(i);
      			if (invalidChars.indexOf(currentChar) != -1){
         			return false;
         		}
      		}
			return true;
	}
	
function showError(error_id){
		
		document.getElementById(error_id).style.display = "inline";
		return false;
	}
	
function checkEmail(string){
		var atSign=string.indexOf("@");
			var dot=string.lastIndexOf(".");
			if (atSign<1||dot-atSign<2){
				return false;
			}else{
				return true;
			}
	}
	
function checkPhone(string){
		var validChars = "0123456789";
		var currentChar;
		for (var i = 0; i < string.length; i++){
      			currentChar = string.charAt(i);
      			if (validChars.indexOf(currentChar) == -1){
         			string = string.replace(currentChar, "");
					i--;
         		}
      		}	
			var len = string.length;
		if(string.length != 10){
			return false;	
		}else{
			return true;
		}
	}

function clearErrors(){
	var spans = document.getElementsByTagName('span');
	
	for(var i=0; i< spans.length; i++){
		if(spans[i].className == "error"){
			spans[i].style.display = "none";	
		}
	}
	
}