// JavaScript Document
function formValidatorContact(){
	// Make quick references to our fields

	var fname= document.getElementById('fname');	
	var email= document.getElementById('email');
	var phone= document.getElementById('phone');	
	var title= document.getElementById('title');
	var msg= document.getElementById('msg');
		
	//check empty for data input 		
	if(isEmpty(fname, "Please input your first name")){
		return false;
	}		

	if(isEmpty(email, "Please input your email")){
		return false;
	}	
	if(!emailValidator(email, "Please check your email")){
		return false;		
	}	

	if(isEmpty(title, "Please input your title")){
		return false;
	}	

	if(isEmpty(msg, "Please input your message")){
		return false;
	}	

	document.form1.submit();
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == ""){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
