// JavaScript Document

function formValidator(){
	// Make quick references to our fields
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	var service_type = document.getElementById('service_type');
    var comment = document.getElementById('comments');

if(isEmpty(name, "Please enter your name")){
if(emailValidator(email, "Please enter a valid email address")){
		if(isEmpty(phone, "Please enter your Phone no.")){
			if(isNumeric(phone, "Please enter valid Phone no.")){
			if(isEmpty(service_type, "Please select the type of service")){
              if(isEmpty(comment, "Please enter your comment")){
							return true;
						}
					}
				}
			}
          }
      }
	return false;
	
}
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;
	}
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function search_data(){

var search_data = document.getElementById('txt_search').value;

window.location = "search_result.php?search_data="+search_data;

}
