// 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 formvalidation(thisform)
{

with (thisform)
{
if (emptyvalidation(name,"Error ! Please type in your name !")==false) {name.focus(); return false;}
if (emailvalidation(email,"Error ! Please type in your Email Address!")==false) {email.focus(); return false;}
//if (emptyvalidation(address,"Error ! Please type in your address!")==false) {address.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();
}
}
}

<!--email validator -->
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
