var gIEVersion = "";	//浏览器名字
var gVersionNum = 0;	//浏览器版本号
function fCheck(){
	var bOk = false;
	var s = "";
	var fm = document.form;
	s = fm.style.value;
	
	fm.user.value = fTrim(fm.user.value); //Trim the input value.
	if(!fCheckCookie()){
		return false;
	}
	if( fm.user.value =="") {
		window.alert("\请输入您的用户名 ?");
		fm.user.focus();
		return false;
	}	

	if( fm.pass.value.length =="") {
		window.alert("\请输入您的密码 ?");
		fm.pass.focus();
		return false;
	}
	var remUser = fm.remUser.checked?true:false;
	if( remUser){
		fm.autocomplete="on";
	}else{
		fm.autocomplete="off";
	}	

	var url = "http://entry.126.com/cgi/login?hid=10010102&";
	if( fm.secure.checked )
		url += "verifycookie=1&";
	fm.action = url + "language=0&style=" + s ;
	var ati = fm.user.value.indexOf( "@"); 
	if( ati != -1 )
		fm.user.value = fm.user.value.substring(0, ati);
	visitordata.setVals( [fm.user.value,fm.style.value,fm.secure.checked?1:0 ], remUser );
	visitordata.store();
	return true;
}

function fTrim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
/*
function fInitStyle()
{
	var html ="";
	switch( gVersionNum )
	{
		case 0:	break;
		case 6: 
		case 5.5: html += '<option value="1"> 随心DIY</option><option value="2">商　　务</option>';
		default: break;
	}
	html ='<select name="style"><option value="-1" selected>默　　认</option><option value="0">简　　约</option>' + html+ "</select>";
	document.write( html );
}
*/
function fGetIEVersion()
{
	var IEAppName   = window.navigator.appName;						//得到当前浏览器的名.		
	var IEversion	= window.navigator.appVersion;					//得到当前浏览器的版本说明
	if(IEAppName.indexOf("Microsoft")<0){
		gIEVersion = IEAppName;
		return 0;
	}
	var isOpera = window.navigator.userAgent.indexOf("Opera") > -1;
	if(isOpera){
		gIEVersion = "Opera";
		return 0;
	}

	var k=IEversion.indexOf("MSIE");					//查找IE的版本号
	if(k>=0){
		k+=4;
		var j=IEversion.indexOf(";",k);
		if(j<0){
			j=IEversion.length-1;
		}	
		IEversion	=IEversion.substring(k,j)*1;				//得到IE的版本号，并且数字化
		gIEVersion = "MSIE: "+IEversion;
		if(IEversion >= 6){										//如果版本号6.0以上，		
			return 6;
		}else if( IEversion >= 5.5 && IEversion < 6 ){
			return 5.5;
		}else if( IEversion >= 5 && IEversion <5.5){
			return 5;
		}
		else{
			return 0;
		}
	}else{
		gIEVersion =  window.navigator.appVersion;
		return 0;
	}
}
gVersionNum = fGetIEVersion();

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;
	var cookie = "NETEASE_SSN=" + document.getElementsByName("user")[0].value + ";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;
	}
}
document.domain = "126.com";
var visitordata = new Cookie( document, "nts_mail_user", document.domain);
visitordata.load();

//*** For Login UserName.
function fInitUser()
{
	var fm = window.document.form;
	var name = "";
	if( visitordata.data != null)
	{	
		name = visitordata.data[0][0];
		fm.remUser.checked = true;
		fm.autocomplete="on";
	}else{
		fm.autocomplete="off";
	}

	fm.user.focus();
	if( name != ""){
		fm.user.focus();
		fm.user.value = name;
	}	
}

function attention()
{
	window.open("http://mail.126.com/126s.htm","attention","width=500,height=400,top="+ (window.screen.height/2-200) +",left="+ (window.screen.width/2-250) +", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
function exitad()
{
	var frames = ["<iframe src=http://mail.163.com/"," width=468 height=320 frameborder=no border=0 marginwidth=0 marginheight=0 scrolling=no hspace=0 vspace=0></iframe>"];
	id =  Math.floor(Math.random() * 2 + 1);
	if(id==1) {
		document.write(frames[0] + "virus468320.htm" + frames[1]);}
	else if(id==2){
		document.write(frames[0] + "vip468320.htm" + frames[1]);
	} else {
		document.write(frames[0] + "eaw468320.htm" + frames[1]);
	}
}
function fCheckCookie(){
	var secure = document.getElementsByName("secure");
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="testcookie";
		cookieEnabled=(document.cookie=="testcookie")? true : false;
		document.cookie="";
	}
	if(secure.length>0){
		if(secure[0].checked && !cookieEnabled){
			window.alert("您好，您的浏览器设置禁止使用cookie。您登录邮箱时选中了“增强安全性”选项，该选项要求浏览器启用cookie设置。\n\n您可以选择以下的其中一个方法登录邮箱：\n1：设置您的浏览器，启用cookie设置，再重新登录。\n2：或者登录时取消选中“增强安全性”选项，但是您的登录安全性将会降低。");
			return false;
		}
	}
	return true;
}