function validateAsEmail (emailStr)
{
	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 + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) 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) {
					return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		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 to four letter word.
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		return false
	}

	return true;
}


function setLabel(target, text)
{
	target.onclick = function ()
	{
		if (target.value == text) {
			target.value = ''
		}
	}

	target.onkeydown = function ()
	{
		if (target.value == text) {
			target.value = ''
		}
	}

	target.onblur = function ()
	{
		if (target.value.length == 0) {
			target.value = text
		}
	}

	if (target.value.length == 0) {
		target.value = text
	}
}


function setFocus(elementId)
{
	var el = document.getElementById(elementId);
	if (typeof(el) != 'undefined') {
		var isMozilla = (typeof(el.setAttribute) == 'function');
		if (isMozilla) {
			el.setAttribute('autocomplete', 'off');
		}
		el.focus();
		if (isMozilla) {
			el.setAttribute('autocomplete', 'on');
		}
	}
}


var WindowObjectReference;
function windowCentered(strUrl, strWindowName, intWindowWidth, intWindowHeight, strWindowExtraSettings)
{
	var intWindowLeft = parseInt(screen.width - intWindowWidth) / 2;
	var intWindowTop = parseInt(screen.height - intWindowHeight) / 2;
	var strExtraSettings = 'width=' + intWindowWidth + ',height=' + intWindowHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop + ',scrollbars=1,resizable=1';

	if (typeof(strWindowExtraSettings) != 'undefined') {
		strExtraSettings += ',' + strWindowExtraSettings;
	}

	WindowObjectReference = window.open(strUrl,strWindowName,strExtraSettings)

	if ((typeof(WindowObjectReference) != 'null') && typeof(WindowObjectReference.focus) == 'function') {
		WindowObjectReference.focus();
	}

	return false;
}