<!--
/**
 * filename:			getWordLength.js
 * written by:			SIU, Pui-wing
 * date:				07.10.2003
 * arguement:			text_string		[String]	- the text string which need detemine the word length
 * return type:			Integer
 * return description:	the length of the given text
 * description:			It is used to get the length of a word
 **/

function getWordLength(text_string){
	var charCount = 0;
	var charPosition = 0;
	for (charPosition = 0; charPosition < text_string.length; charPosition++){
		// @ The ASCII of English and Numeric is less then 256
		// @ if less than 256, add 1, otherwise, add 2
		(text_string.charCodeAt(charPosition) >= 256) ? charCount += 2 : charCount++;
	}

	return charCount;
}

function isValidEmail(email){
	var emailInfo = email.split("@");

	if (emailInfo.length > 2){									/* @ check at most one @ is exist */
		return false;
	} else if (emailInfo.length < 2){
		return false;
	} else{
		var user = emailInfo[0];
		var domain = emailInfo[1];
		var userFormat = /[\s\/\\\*\+\?\|\(\)\[\]\{\}~!@#$%^&=;\'\"<>:]/;
		var domainFormat = /[\s\/\\\*\+\?\|\(\)\[\]\{\}~!@#$%^&=;\'\"<>:_]/;

		if (user.match(userFormat) != null){					/* @ check username haven't any illegal character */
			return false;
		}

		if (domain.indexOf(".") == -1){							/* @ check at least the format of domain be XXXX.XXX */
			return false;
		}

																/* @ check the top domain at least have 1 char and not more than 4 char */
		if ((domain.substring(domain.lastIndexOf(".") + 1, domain.length).length > 4) || (domain.substring(domain.lastIndexOf(".") + 1, domain.length).length < 2)){
			return false;
		}
																/* @ check the top level domain MUST be English character */
		if (domain.substring(domain.lastIndexOf(".") + 1, domain.length).match(/[^A-Za-z]/) != null){
			return false;
		}

		if (domain.match(domainFormat) != null){				/* @ check the domain havent any illegal character */
			return false;
		}
	}
	return true;
}

function openBrowser(url, name, width, height, feather){
	var isIE	= (document.all ? true : false);				//@ is Internet Explorer
	var isNS	= (document.layer ? true : false);				//@ is Netscape Navigator 4
	var isDOM	= (document.getElementById ? true : false);		//@ is Netscape Navigator 6+ or other
	var browser				= new Object();
	var browser_attribute	= "";

	if (!browser.win || (browser.win && browser.win.closed)){
		browser.url		= url;
		browser.name	= name;
		browser.width	= width;
		browser.height	= height;

		//-- centerized the opened broswer and initial its attribute
		if (isIE || isDOM){
			browser.left	= (screen.width - browser.width) / 2;
			browser.top		= (screen.height - browser.height) / 2;
			browser_attribute = "left=" + browser.left + ",top=" + browser.top + ",resizeable=no,width=" + browser.width + ",height=" + browser.height + "," + feather;
		} else if (isNS){
			browser.left	= window.screenX + ((window.outerWidth - browser.width) / 2);
			browser.top		= window.screenY + ((window.outerHeight - browser.height) / 2);
			browser_attribute = "screenX=" + browser.left + ",screenY=" + browser.top + ",resizeable=no,width=" + browser.width + ",height=" + browser.height + "," + feather;
		}

		//-- open new browser
		browser.win = window.open (browser.url, browser.name, browser_attribute);
	}

	browser.win.focus();
	
	return browser;
}
//-->