//function changes background color of object to red so user knows what field generated error
function changeRed(f,o){


if(f == 'ID'){
		object_path = "document.getElementById('" + o + "')";
		eval(object_path).style.backgroundColor = '#FF6A6A';
	}
	else{
		object_path = 'document.' + f + '.' + o;
		eval(object_path).style.backgroundColor = '#FF6A6A';	
	}
}

//function that checks to make sure email address is present, does not
//contain illegal characters, and is also valid. returns the var error.
function checkEmail(x,f,o){
	var error='';
	
	if(x == ''){
		error = "You must fill in your email address.\n\n";
		
		changeRed(f,o);
	}
		
		
	var emailFilter=/^.+@.+\..{2,3}$/;
	
	if(!(emailFilter.test(x))){ 
		error = "The email you input was not valid.\n\n";
		
		changeRed(f,o);
	}
	else{
		//tests for illegal characters
		var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/
		if(x.match(illegalChars)){
			error = "The email you input contains illegal characters.\n\n";
			
			changeRed(f,o);
		}
	}
	
	return error;
}

//function that checks to make sure phone number is present, is 10 digits
function checkPhone(x,f,o){
	var error='';
	
	if(x == ''){
		error = "You must fill in your phone number.\n\n";
		
		changeRed(f,o);
	}
	
	var phNum = x.replace(/[\(\)\.\-\ ]/g, ''); 
	if(isNaN(parseInt(phNum))){
		error = "The phone number contains illegal characters.\n\n";
		
		changeRed(f,o);
	}
	//if(x.length != 10){
	//	error = "The length of this phone # is incorrect. Please input a 10 digit #.\n\n";
	//}
	
	return error;
}

//function that will check for a valid selection from a drop down list
function checkSelect(x,f,o){
	var error='';
	if(x =="*"){
		error = "There is a drop down that has not had an option selected.\n\n";
		
		changeRed(f,o);
	}
	
	return error;
}

//function that will check if a radio button is selected
function checkRadio(x){
	var error='';
	if(!checkvalue){
		error = "Please check a radio button.\n\n";
		
		
	}
	
	return error;
}

//function that will check a checkbox
function checkCheckbox(x,f,o){
	var error = '';
	
	if(!x.checked){
		error = "A checkbox was left blank.\n\n";
		
		changeRed(f,o);
	}
	
	return error;
	
}

//function that checks if input is empty
function checkEmpty(x,f,o){
	var error = '';
	
	if(x == '' || x.match(/^s+$/)){
		error = "A required field was left blank.\n\n";
		
		changeRed(f,o);
	}
	
	return error;
	
}

//function that checks if input is empty and a .gif or .jpg
function checkPic(x,f,o){
	var error = '';
	
	if(x == '' || x.match(/^s+$/)){
		error = "A required field was left blank.\n\n";
		
		changeRed(f,o);
	}
	else{
		tempLength = x.length;
		
		if(x.substring(tempLength-4,tempLength) != '.gif' && x.substring(tempLength-4,tempLength) != '.jpg' && x.substring(tempLength - 4,tempLength) != 'jpeg'){
			error += "The image you have provided is in an improper format. Please use .gif, .jpg or .jpeg.\n";
			
			changeRed(f,o);
		}
	}
	
	return error;
	
}

function checkNumber(x,f,o){
	var error = '';
	
	if(isNaN(x)){
		error = 'You can only use numbers in this field.\n\n';
		
		changeRed(f,o);
	}
	
	return error;
}
