function emailCheck (emailStr, warning) {



/* This pattern checks user@domain format, and is used to separate the username

   from the domain. */

var emailPat=/^(.+)@(.+)$/

/* We don't want to allow the following characters ( ) < > @ , ; : \ " . [ ]    */

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

/* Range of characters allowed in a username or domainname.  It really states which chars aren't allowed. */

var validChars="\[^\\s" + specialChars + "\]"

/* If the "user" is a quoted string, anything goes.*/

var quotedUser="(\"[^\"]*\")"

/* If the domain is an IP addresses, rather than symbolic names.  

   E.g. joe@[123.124.233.4] is a legale-mail address. 

   NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

/* An atom (basically a series of non-special characters.) */

var atom=validChars + '+'

/* One word in the typical username. E.g. john.doe@somewhere.com, john and doe are words.

   Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")"

// Structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

/* Structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")



/* Is supplied address is valid. */

var matchArray=emailStr.match(emailPat)

if (matchArray==null) {

	warning += "\n     - The e-mail address seems incorrect (check @ and .'s)"

	return warning

}

var user=matchArray[1]

var domain=matchArray[2]



// See if "user" is valid 

if (user.match(userPat)==null) {

    warning +="\n     - The e-mail username doesn't seem to be valid."

    return warning

}



/* If an IP address, make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {

    // this is an IP address

	  for (var i=1;i<=4;i++) {

	    if (IPArray[i]>255) {

	        warning +="\n     - The e-mail destination IP address is invalid!"

		return warning

	    }

    }

    return warning;

}



// Domain is symbolic name

var domainArray=domain.match(domainPat)

if (domainArray==null) {

	warning +="\n     - The e-mail domain name doesn't seem to be valid."

    return warning

}



/* Check that the domain ends in a three-letter word (like com, edu, gov) 

   or a two-letter word, representing country (uk, nl), 

   and that there's a hostname preceding the domain or country. */



/* Break up the domain to get a count of how many atoms it consists of. */

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 || 

    domArr[domArr.length-1].length>3) {

   warning +="\n     - The e-mail address must end in a three-letter domain, or two letter country."

   return warning

}



// Make sure there's a host name preceding the domain.

if (len<2) {

   warning +="\n     - The e-mail address is missing a hostname."

   return warning

}

return warning;

}



/***********************************************************************/

function chkForm()

{

	if(alltrim(document.getElementById('inq_name').value)=='')

	{

		

		alert('Please enter a name');

		document.getElementById('inq_name').focus();

		return false;

	}

	

	if(alltrim(document.getElementById('inq_org').value)=='')

	{

		alert('Please enter the name of organization');

		document.getElementById('inq_org').focus();

		return false;

	}

	

	if(isNaN(document.getElementById('inq_phone').value))

	{

	alert('Please enter a numeric value');

	return false;

	}

	warning='';

	warning = emailCheck(document.getElementById('inq_email').value, warning);

	

	if(warning !='')

	{

		alert(warning);

		return false;

	

	}

	

	document.getElementById('mode').value='sendmail';

	document.getElementById('inquiry').method='POST';

	document.getElementById('inquiry').action='contactForm.php';

	document.getElementById('inquiry').submit();

}

function clrfrm()

{

	document.getElementById('inq_name').value='';

	document.getElementById('inq_title').value='';

	document.getElementById('inq_org').value='';

	document.getElementById('inq_address').value='';

	document.getElementById('inq_phone').value='';

    document.getElementById('inq_email').value='';

	document.getElementById('inq_prjplan').value='';

	document.getElementById('inq_more_info').value='';

}