// JavaScript Document


function CheckForm(){
 var name = document.getElementById('Name:');
 var telephone = document.getElementById('Telephone:');
 var email = document.getElementById('Email:');
 var message = document.getElementById('Message:');
 
 	if(CheckName(name,"Your Name is required")){
		return false;
	}
	
	else if(CheckEmail(email,"Invalid e-mail format")){
		return false;
	}	
	
	else if(CheckTelephone(telephone,"Your Telephone is required")){
		return false;
	}
	
	else if(CheckMessage(message,"Please leave a message")){
		return false;
	}
	
	return true;
}


function CheckName(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function CheckTelephone(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function CheckEmail(elem,msg){
	if(elem.value.length != 0){
	   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(elem.value.match(emailExp)){
		return false;
	 }
		else{
			alert(msg);
			elem.focus();
			return true;
		}
	  }
	else{
		alert("Your e-mail address is required");
		elem.focus();
		return true;
	}
}	

function CheckMessage(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

