function emailCheck(element) {
	emailStr=element.value;

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		window.alert("Email address seems incorrect.")
		element.focus();
		element.select();
		return false
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		window.alert("The email username doesn't seem to be valid.")
		element.focus();
		element.select();
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				window.alert("Destination email IP address is invalid!")
				element.focus();
				element.select();
				return false
			}
		}
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		window.alert("The email domain name doesn't seem to be valid.")
		element.focus();
		element.select();
		return false
	}

	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>4) {
		// the address must end in a two letter or three letter word.
		window.alert("The email address must end in a three-letter domain, or two letter country.")
		element.focus();
		element.select();
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		var errStr="The email address is missing a hostname!"
		window.alert(errStr)
		element.focus();
		element.select();
		return false
	}
	return true;
}

var openhlp;
var oldplace;
function helpWin(objEvt, sType) {
	openhlp="oHlp"+sType;
	if (oldplace==undefined) {
		oldplace=openhlp;
	}
	if (openhlp!=oldplace) {
		document.getElementById(oldplace).style.display="none";
		oldplace=openhlp;
	}
	document.getElementById(openhlp).style.display="block";

	var intXPos;
	var intYPos;
	var intDivSizeW = document.getElementById(openhlp).offsetWidth;
	var intDivSizeH = document.getElementById(openhlp).offsetHeight;
	var intScreenSizeW = document.body.offsetWidth;
	var intScreenSizeH = document.body.offsetHeight;

	intXPos=intScreenSizeW/2-intDivSizeW/2;
	intYPos=objEvt.clientY;

	document.getElementById(openhlp).style.left=intXPos+"px";
	document.getElementById(openhlp).style.top=intYPos+"px";
	if (document.all) {
		for (i=0; i<document.ENQUIRY.elements.length; i++) {
			oMe=document.ENQUIRY.elements[i];
			if (oMe.tagName=="SELECT") {
				oMe.style.visibility="hidden";
			}
		}
	}
}
function helpWinClose() {
	document.getElementById(openhlp).style.display="none";
	if (document.all) {
		for (i=0; i<document.ENQUIRY.elements.length; i++) {
			oMe=document.ENQUIRY.elements[i];
			if (oMe.tagName=="SELECT") {
				oMe.style.visibility="inherit";
			}
		}
	}	
}
function trim(sTrim, sRep) {
	if (!sRep) {
		sRep = "";
	}
	return sTrim.replace(/^\s+|\s+$/g,sRep);
}
function isNum(iNum, bRequired) {
	if (isNaN(trim(iNum, "#"))) {
		return false;
	}
	if (bRequired) {
		if (trim(iNum) == "") {
			return false;
		}
	}
	return true;
}
function JSTrimEx(sString) {
	// Remove whitespace &crlf from LHS
	bRun=true;
	do {
		c=sString.charCodeAt(0);
		switch (c) {
			case 32:
			case 13:
			case 10:
				sString=sString.substr(1);
				break;
			default:
				bRun=false;
				break;
		}	
	} while ((bRun)&&(sString!=""));
	
	// Remove whitespace &crlf from LHS
	bRun=true;
	do {
		iLen=sString.length;
		c=sString.charCodeAt(iLen-1);
		switch (c) {
			case 32:
			case 13:
			case 10:
				sString=sString.substr(0, iLen-1);
				break;
			default:
				bRun=false;
				break;
		}	
	} while ((bRun)&&(sString!=""));
	
	return sString;
}
function readSelectVal(oSelect) {
	if (!oSelect) return "";
	if (oSelect.options.length<=0) return "";
	if (oSelect.selectedIndex<0) return "";
	
	return JSTrimEx(oSelect.options[oSelect.selectedIndex].value);
}
function parseFloatZ(sVal) {
	fVal=parseFloat(sVal);
	return (isNaN(fVal))? 0 : fVal;
}