
function validate_ajax_email_form(frm) {
	var errFlag = true;

	if(isEmpty(frm.yourname.value) || !is_valid_name(frm.yourname.value)) {
		document.getElementById("ynamn").innerHTML="!";
		
		errFlag = false;
	}
	else {
		document.getElementById("ynamn").innerHTML="";
	}
	
	if(isEmpty(frm.youremail.value) || !is_valid_email(frm.youremail.value)) {
		document.getElementById("yemail").innerHTML="!";
		errFlag = false;
	}
	else {
		document.getElementById("yemail").innerHTML="";
	}

	return errFlag;
}

// Check Form Field Is Empty
function isEmpty(value){
	if (trim(value) == ""){
		return true;
	}
	return false;
}

// Trim White Spaces
function trim(strText) { 
	// this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);
	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);
   return strText;
}

// Check Name
function is_valid_name(name) {
	var name = trim(name);
	var filter  = /[(\*\(\)\[\]\+\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
	return !filter.test(name);
}

// Check Email
function is_valid_email(email) {
	var email = trim(email);
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}
