function trimString (str) {
	while (str.charAt(0) == ' ') {
		str = str.substring(1);
	}
	while (str.charAt(str.length - 1) == ' ') {
		str = str.substring(0, str.length - 1);
	}
	return str;
}

function emailCheck(type) {
	var email = trimString(document.emailForm.emailAddress.value);

	if (!validEmail(email)) {
		alert('请输入有效的电子邮件地址.');
		return false;
	}
	if (type == 1) {
		document.emailForm.submit();
	}
}

function validEmail(email) {
	var vAtSym    = email.indexOf('@')
	var vPeriod   = email.lastIndexOf('.')
	var vSpace    = email.indexOf(' ')
	var vLength   = email.length - 1   // Array is from 0 to length - 1

	if (vAtSym < 1 ||                     // '@' cannot be in first position
		vPeriod <= vAtSym + 1 ||          // Must be atleast one valid char btwn '@' and '.'
		vPeriod == vLength  ||            // Must be atleast one valid char after '.'
		vSpace  != -1)                    // No empty spaces permitted
	{
		return false;
	}
	return true;
}

function showCustomPopUp(thisUrl, thisName, theseParams) {
	remote = open(thisUrl, thisName, theseParams);
}

//	verisign POP-UP WINDOW
function popUp(url) {
	sealWin = window.open(url, "win", 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function jump(url) {
	if (url != "" && url != null) {
		self.location.href = url;
	}
}

function valEmailForm(emailFormField) {
	if (!validEmail(emailFormField.value)) {
		alert("请输入有效的电子邮件地址.");
		if (!document.layers) {
			//emailFormField.style.backgroundColor = "yellow";
			emailFormField.googleFixColor = "yellow";
			emailFormField.style.color = "#000000";
		}
		emailFormField.focus();
		return false;
	}
	return true;
}
//This code changes the email field back to the intended background color.
//########################################################################
if (window.attachEvent) {
	window.attachEvent("onload", setListeners);
}

function setListeners() {
	var inputList = document.getElementsByTagName("INPUT");
	for (var i = 0;i < inputList.length; i++) {
		inputList[i].attachEvent("onpropertychange", restoreStyles);
		inputList[i].style.backgroundColor = "";
	}
	var selectList = document.getElementsByTagName("SELECT");
	for (var i = 0; i < selectList.length; i++) {
		selectList[i].attachEvent("onpropertychange", restoreStyles);
		selectList[i].style.backgroundColor = "";
	}
}

function restoreStyles() {
	var theElement = event.srcElement;
	var theColor = theElement.googleFixColor;
	if (theColor == undefined || theColor.length == 0) {
		return;
	}
	theColor = theColor.toLowerCase();
	var currentBgColor = theElement.style.backgroundColor;
	if (currentBgColor != undefined && currentBgColor.length > 0) {
		currentBgColor = currentBgColor.toLowerCase();
	}
	if (currentBgColor != theColor) {
		theElement.style.backgroundColor = theColor;
	}
}
//########################################################################