function fLoginFormSubmit()
{
	var fm = window.document.login163;
	var user = fm.username;
	user.value = fTrim( user.value); //Trim the input value.

	if( user.value =="") {
		window.alert("\请输入您的用户名 ?");
		user.focus();
		event.returnValue = false;
		return false;
	}	

	if( fm.password.value.length =="") {
		window.alert("\请输入您的密码 ?");
		fm.password.focus();
		event.returnValue = false;
		return false;
	}

	var ati = user.value.indexOf( "@"); 
	if( ati != -1 ){
		user.value = user.value.substring(0, ati);	
	}
	var secure = fm.remUser.checked?true:false;
	var url = "http://reg.163.com/login.jsp?url=http://fm163.163.com/coremail/fcg/ntesdoor2?";
	url += "verifycookie%3D1%26";
	if( secure){
		user.autocomplete="on";
	}else{
		user.autocomplete="off";
	}	
	fGetVersion(fm);
	fm.action = url + "language%3D-1%26style%3D" + fm.style.value;
	visitordata.setVals( [fm.username.value,fm.style.value,fm.secure.checked?1:0 ], fm.remUser.checked?true:false );
	visitordata.store();
	return true;
}
function fGetVersion(fm)
{
	try{
		var userAgent = window.navigator.userAgent;
		var AppName = "";
		var Version = "";
		if(userAgent.indexOf("MSIE")>-1){
			AppName   = "msie";	
			Version	= userAgent.replace(/.+MSIE/gi,"").replace(/;.+/gi,"") - 0;	
		}else if(userAgent.toUpperCase().indexOf("FIREFOX")>-1){
			AppName = "firefox";
			Version = userAgent.replace(/.+Firefox\//gi,"").replace(/\(.*\)/g,"") - 0;
		}else if(userAgent.toUpperCase().indexOf("NETSCAPE")>-1){
			AppName = "netscape";
			Version = userAgent.replace(/.+NETSCAPE\//gi,"").replace(/\(.*\)/g,"") - 0;
		}
		if((AppName == "msie" && Version < 5) || (AppName == "firefox" && Version <1) || (AppName == "netscape" && Version<7.2) || userAgent.indexOf("macintosh") != -1 || userAgent.indexOf("konqueror") != -1 || userAgent.indexOf("safari") != -1 || userAgent.indexOf("camino") != -1){
			fm.style.value = "34";
		}
	}catch(e){}
}
function Cookie( document, name, domain )
{
	this.$document = document;
	this.$name = name;
	this.$expiration = new Date(2099,12,31);
	this.$domain = domain;
	this.data = null;
}
Cookie.prototype.store = function()
{
	var cookieval = "";
	if( this.data != null)
	{
		for( var i=0; i<this.data.length;i++)
		{
			cookieval += this.data[i].join(":") + "&";
		}
	}
	if( cookieval != "" && cookieval.charAt( cookieval.length-1) == "&" )
		cookieval = cookieval.substring( 0,cookieval.length-1);
	var cookie = this.$name + "=" + cookieval + ";expires=" + this.$expiration.toGMTString() + ";domain=" + this.$domain;
	window.document.cookie = cookie;
}
Cookie.prototype.load = function()
{
	var allcookies = this.$document.cookie;
	if( allcookies == "") return false;
	var start = allcookies.indexOf( this.$name + "=" );
	if( start == -1) return false;
	start += this.$name.length +1;
	var end = allcookies.indexOf( ";", start );
	if( end == -1) end = allcookies.length;
	var cookieval= allcookies.substring( start, end );
	var a = cookieval.split("&");
	for( var i=0;i<a.length; i++)
		a[i] = a[i].split(':');
	//用户名:风格:安全
	this.data = a;
	return true;
}
Cookie.prototype.setVals = function( a, flag )
{
	if( this.data == null)
	{
		if( flag )
		{	
			this.data = [];
			this.data[0] = a;
		}
	}
	else
	{
		this.data[0][0] = a[0];
		if( flag)
			return;
		else
			this.data = null;
	}
}
function fInitUserName()
{
	var fm = window.document.login163;
	var name = "";
	if( visitordata.data != null)
	{	
		name = visitordata.data[0][0];
		fm.remUser.checked = true;
		fm.username.autocomplete="on";
		//fm.secure.checked = (visitordata.data[0][3]==1);
	}else{
		fm.username.autocomplete="off";
	}
	fm.username.focus();
	if( name != ""){
		fm.username.focus();
		fm.username.value = name;
	}
}
function fTrim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
var visitordata = new Cookie( document, "nts_mail_user", document.domain);
visitordata.load();


