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 zhelpWin(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 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";
}
function helpWinClose() {
	document.getElementById(openhlp).style.display="none";
}
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;
}

function isDate(dd, mm, yyyy) {
	dtMyDate = new Date(yyyy, mm-1, dd);
	return  dtMyDate.getDate() == dd && dtMyDate.getMonth() + 1 == mm && dtMyDate.getFullYear() == yyyy;
}
function CheckCover(sFN, bVerbose)
{
	var bBCov=(document.forms[sFN].COVER_BUILDINGS_COVERREQ.selectedIndex==0);
	var oBAD=document.forms[sFN].COVER_BUILDINGS_ACCDAMAGE;
	var oBSum=document.forms[sFN].COVER_BUILDINGS_SUM_INSURED;
	var oBLib=document.forms[sFN].COVER_PROPERTYLI_REQ;
	var oBExc=document.forms[sFN].COVER_BUILDINGS_EXCESSINC;
	
	var bCCov=(document.forms[sFN].COVER_CONTENTS_COVERREQ.selectedIndex==0);
	var oCAD=document.forms[sFN].COVER_CONTENTS_ACCDAMAGE;
 var bCAD=(oCAD.selectedIndex==0);
	var oCSum=document.forms[sFN].COVER_CONTENTS_SUM_INSURED;
	var oCLib=document.forms[sFN].COVER_PUBLICLI_REQ;
	
	if (bBCov) {
		// Buildings cover selected
		oBAD.disabled = false;
		oBSum.disabled = false;
		oBSum.setAttribute("required", "1");
		if (oBLib) {
			oBLib.disabled=false;
		}
		if (oBExc) {
			oBExc.disabled=false;
		}
	} else	{
		// No Buildings cover selected
		oBAD.selectedIndex = 1;
		oBAD.disabled = true;
		oBSum.value = "0";
		oBSum.disabled = true;
		oBSum.setAttribute("required", "0");
		if (oBLib) {
			oBLib.selectedIndex=0;
			oBLib.disabled=true;
		}
		if (oBExc) {
			oBExc.selectedIndex=0;
			oBExc.disabled=true;
		}
		// Contents only must have AD
		if (bCCov&&(!bCAD)) {
			if (bVerbose) {
				window.alert("Contents insurance must include the accidental damage extension if taken without buildings cover.");
			}
			oCAD.selectedIndex=0;
		}
	}
	if (bCCov) {
		// Contents cover selected
		oCAD.disabled = false;
		oCSum.disabled = false;
		oCSum.setAttribute("required", "1");
		if (oCLib) {
			oCLib.disabled=false;
		}
	} else	{
		// No Contents cover selected
		oCAD.selectedIndex = 1;
		oCAD.disabled = true;
		oCSum.value = "0";
		oCSum.disabled = true;
		oCSum.setAttribute("required", "0");
		if (oCLib) {
			oCLib.selectedIndex=0;
			oCLib.disabled=true;
		}
	}
}
function readSelectText(oSelect) {
	if (!oSelect) return "";
	if (oSelect.options.length <= 0) return "";
	if (oSelect.selectedIndex < 0) return "";
	
	return oSelect.options[oSelect.selectedIndex].text;
}