// JavaScript Document

//Left side trim
function LTrim(txtName)
{
	var re=/\s*((\S+\s*)*)/;
	return txtName.replace(re,'$1');
}
// Right side trim
function RTrim(txtName)
{
	var re=/((\s*\S+)*)\s*/;
	return txtName.replace(re,'$1');
}
// function like as php
function trim(txtName)
{
	return LTrim(RTrim(txtName));
}

function email(str)	//function to check email is valid
// we find @ and . in the emailid as well length>4 and  @ and . have url in b/w
{
	var at=0,dot=0;
	for (var i=0;i<str.length;i++){
		if (str.charAt(i)=="@") at=i;
		if (str.charAt(i)==".") dot=i;
	}
	if ((at!=0) && (dot!=0) && ((dot-at)>0) && (str.length>4))
		return true;
	else {
		alert("invalid email");
		return false; 
	}
}

function chkForm(form)
{
	if(form.full_name.value == ""){
		alert("Full Name field should not be empty!");
		form.full_name.focus();
		return false;
	}
	if(form.email.value == ""){
		alert("Email field should not be empty!");
		form.email.focus();
		return false;
	}
	if(!email(form.email.value)){
		form.email.focus();
		return false;
	}
	if(trim(form.comments.value) == ""){
		alert("Comments field should not be empty!");
		form.comments.focus();
		return false;
	}

	return true;
}