// JavaScript Document
//====================================================================================================
//	File Name		:	validate.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.

//
//====================================================================================================

function Form_Submit(frm)
{
	with(frm)
	{	
				
		if(!IsEmpty(txtname,"Please Enter Name."))
		{
			return false;
		}
	
		if(!IsEmpty(txtemail,"Please Enter Email Address."))
		{
			
			return false;
		}
		if(!IsEmail(txtemail,"Please Enter Valid Email Address."))
		{
			return false;
		}
		if(!IsEmpty(txtcomment,"Please Enter Comment."))
		{
			return false;
		}
	frm.submit();
	//return true;
	}
}

function IsEmail(fld,msg)
{
	var regex = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/ ;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}
function ValidString(fld)
{
	//var regex = /^[a-zA-Z]*[0-9]/;
	var regex = new RegExp(/^[a-zA-Z0-9]/);
	if(!regex.test(fld.value))
	{
		alert("Please Enter Valid String.");
		fld.focus();
		return false;
	}
	return true;
}

function IsEmpty(fld,msg)
{
	if((fld.value == "" || fld.value.length == 0) && (msg == ''))
	{
		fld.select();
		return false;
	}
	if(fld.value == "" || fld.value.length == 0)
	{
		alert(msg);
		fld.focus();
		fld.select();
		return false;
	}
	if(!ValidString(fld))
	{
		fld.select();
		return false;
	}
	return true;
	
}