// JavaScript Document




// Validation
function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 

function emailvalidation(entered, alertbox)
{
with (entered)
{
/*apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}*/

if (!value.match("^[a-zA-Z0-9]+[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+[a-zA-Z0-9]$"))
{
	alert(alertbox);
	
	return false;
}
else
	return true;

}
} 

function phonevalidation(entered, alertbox)
{
	
	with (entered)
	{
	/*apos=value.indexOf("@"); 
	dotpos=value.lastIndexOf(".");
	lastpos=value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
	{if (alertbox) {alert(alertbox);} return false;}
	else {return true;}*/
	
	if (!value.match("^[-]?[0-9]+[\.]?[0-9]+$"))//regular expression for js digit
	{
		alert(alertbox);
		
		return false;
	}
	else
		return true;
	
	}
} 



function formvalidation(thisform)
{

with (thisform)
{
if (emptyvalidation(name,"Error ! Please type in your name !")==false) {name.focus(); return false;}
if (emptyvalidation(address,"Error ! Please type in your address!")==false) {address.focus(); return false;}
if (phonevalidation(phone,"Error ! Please type digit!")==false) {phone.select();phone.focus(); return false;}
if (emailvalidation(email,"Error ! Please type in your Email Address!")==false) {email.select();email.focus(); return false;}
if (emptyvalidation(comments,"Error ! Please provide your comments !")==false) {comments.focus(); return false;}
if (emptyvalidation(code_check,"Error ! Please provide the code as in the image !")==false) {code_check.focus(); return false;}
{
	document.contact.submit();
}
}
}



