window.onerror=function(){return true}

//var body=document.body,agent=navigator.userAgent;
var isIE,isIE4,isIE5,isIE6,isOpr,isMoz;
var glb=new Object(),tmpl=new Object();

var l;
String.prototype.trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g, "")}
String.prototype.inc=function(k1,k2){return k2==null?this.indexOf(k1)>-1?true:false:(k2+this+k2).indexOf(k2+k1+k2)>-1?true:false}
String.prototype._slice="".slice
String.prototype.slice=function(n1,n2){var v,b1=typeof(n1)=="number",b2=typeof(n2)=="number";if(!b1||typeof(n2)=="string"){v=eval("this._slice("+(b1?n1:this.indexOf(n1)+(n2==null?1:0)+(this.indexOf(n1)==-1?this.length:0))+(n2==null?"":(b2?n2:(this.indexOf(n2)==-1?"":","+this.indexOf(n2))))+")")}else{v=isIE5&&n1<0&&n2==null?this._slice(this.length-1):eval("this._slice(n1"+(n2==null?"":","+n2)+")")}return v}
String.prototype.css=function(key,def){var n1,n2,l=this;if(key=="")return "";if((";"+l+";").indexOf(";"+key+";")>-1)return true;n1=(";"+l+":").indexOf(";"+key+":");if(n1==-1)return def==null?"":def;n1+=(key+":").length;n2=(";"+l+";").indexOf(";",n1+1);return l.slice(n1,n2-1)}
String.prototype.qv=function(key){var l=this.replace("?","&")+"&",n1,n2;n1=l.indexOf("&"+key+"=");if(n1==-1)return "";n1=l.indexOf("=",n1)+1;n2=l.indexOf("&",n1);return l.slice(n1,n2)}
String.prototype.toArray=function(key){var l=this,v;if(key==null)key="|";v=key;if(key=="n"){l=l.replace(/\r/g,"");v="\n"};l=l.replace(new RegExp("(\\"+key+")+","g"),v).replace(new RegExp("^[\\"+key+"]*|[\\"+key+"]+$","g"),"");return l==""?new Array():l.split(v)}
Array.prototype.add=function(key){this[this.length]=key}

isOpr=agent.inc("Opera");
isIE=agent.inc("IE")&&!isOpr;
isIE4=agent.inc("IE 4");
isIE5=agent.inc("IE 5")||agent.inc("IE 4");
isIE6=isIE&&!isIE5;
isMoz=agent.inc("Mozilla")&&!isOpr&&!isIE;
if(isIE4){
	document.getElementById=function(key){return document.all[key]}
	document.getElementsByName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].name==key)a[a.length]=ol[i];}return a}
	document.getElementsByTagName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].tagName.toLowerCase()==key)a[a.length]=ol[i];}return a}
}
if(isMoz){
	Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode}return node});
	HTMLElement.prototype.__defineGetter__("children",function(){return this.childNodes});
	HTMLElement.prototype.__defineGetter__("parentElement",function(){return this.parentNode});
}
	var gotourl;
	var gototarget;
	function showLogin(tourl, totarget)// showLogin Box method
	{ 
		if(readCookie() && tourl != ''){ 
			if (tourl == "#") {
				return;
			}
			if (totarget == "blank") {
				//window.open(tourl);
				//window.force(tourl);
				openWindow(tourl);
				//window.alert(tourl);
			}
			else {
				window.location = tourl;
			}
			//window.location = tourl;
		}
		else {
			if (!readCookie()) {
				gotourl = tourl;
				gototarget = totarget;
				screenDark();		
				$('menu-div').style.display = "block";
				var x =(document.body.clientWidth-$('menu-div').offsetWidth)/2;		
				var y =(document.body.clientHeight-$('menu-div').offsetHeight)/2+document.body.scrollTop;
				$('menu-div').style.position = "absolute";
				$('menu-div').style.left = x;
				$('menu-div').style.top = y;	
				$('menu-div').style.zIndex = "1000";
				change_style('select', 'hidden');
				if (tourl != '') {
					$('loginInfo').style.display = "block";
					$('loginInfo').innerHTML = "<font color=red><b>您还没有登录，请先登录</b></font>";
				}
				$('username').focus();
			}
			else {
				if (tourl == "#" || tourl == "") {
					return;
				}
				else {
					if (totarget == "blank") {
						//window.open(tourl);
						//window.force(tourl);
						openWindow(tourl);
						//window.alert(tourl);
					}
					else {
						window.location = tourl;
					}
				}
			}
		}
	}
	
function screenDark()
{
	if ($('screen')) {
		var screen = $('screen');
	}
	if (!screen) {
		var screen = document.createElement("div");
		document.body.appendChild(screen);
	}
		//screen.style.position="relative";
		screen.id = "screen";
		screen.style.cssText = "position:absolute;top:0px;left:0px;background:#000;";
		screen.style.width = document.body.offsetWidth +"px";
		//screen.style.height = document.body.offsetHeight +"px";
		screen.style.height = document.body.scrollHeight;
		screen.style.zIndex = "100";
		if(document.all){
			screen.style.filter='Alpha(Opacity=45)';
		}else{
			screen.style.MozOpacity='0.45'
		}
}

function closeLog(box)
{
		if ($('loginInfo')) {
			$('loginInfo').style.display = "none";
		}
		if ($('passwd')) {
			$('passwd').value = '';
		}
		$(box).style.display='none';	
		change_style('select', 'visible');
}

var gTimer;
var gTimes = 0;

function checkLogonForm(frm) 
{
	if(frm.username.value.length <= 0){
		alert("请填写用户名");
		frm.username.focus();
		return false;
	}
	if (frm.passwd.value.length <= 0) 	{
		alert("请填写密码");
		frm.passwd.focus();
		return false;
	}
	frm.loginid.value = frm.username.value + frm.maildomain.value;
	gTimer = window.setInterval("getLoginResult()", 500);
	if ($('loginInfo')) {
		$('loginInfo').style.display = "none";
	}
	if ($('notice')) {
		$('notice').style.visibility = "visible";
	}
	if ($('loginForm')) {
  	$('loginForm').style.display = "none";
  }
	//getLoginResult();
	return true;
}

function checkLogonFormHeader(frm)
{
	if(frm.username.value.length <= 0){
		alert("请填写用户名");
		frm.username.focus();
		return false;
	}
	if (frm.passwd.value.length <= 0) 	{
		alert("请填写密码");
		frm.passwd.focus();
		return false;
	}
	frm.loginid.value = frm.username.value + frm.maildomain.value;
	
	gTimer = window.setInterval("getLoginResultHeader()", 500);
	$('loginForm').style.display = "none";
	$('loginInfo').style.display = "block";
	$('notice').innerHTML = "<b><font color=\"#008000\">正在为您登录......</font></b>";
  return true;
	//getLoginResult();
}


function dGetCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function getLoginResult()
{
	gTimes++;
	//超时处理
  if (gTimes >= 10) {
  	if (gTimer) {
  		window.clearInterval(gTimer);
  	}
  	showLoginError("网络超时，请稍后再试");
  	return;
  }
  var loginResult = dGetCookie('loginResult');
  if (loginResult != "") {
  	//dSsetCookie("loginResult", "", -1);
  	if (gTimer) {
  		window.clearInterval(gTimer);
  	}
  	if (loginResult == "ok") {
  			//登录成功
  		showSuccessInfo();
  	}
  	else if (loginResult == 1) {
  		showLoginError("用户名不存在");
  	}
  	else if (loginResult == 2) {
  		showLoginError("用户名或密码错误");
  	}
  	else if (loginResult == 3) {
  		showLoginError("您还没有激活，请先<a href='http://club.sohu.com/reg_step1_auth.php?back="+window.location.href+"' target=_top>激活您的社区账户</a>");
  	}
  	else if (loginResult == 4) {
  		showLoginError("您已经被网管禁止登陆");
  	}
  	else {
  		showLoginError("系统忙，请稍后再试");
  	}
  }
}

function getLoginResultHeader()
{
	gTimes++;
	//超时处理
  if (gTimes >= 10) {
  	if (gTimer) {
  		window.clearInterval(gTimer);
  	}
  	showLoginErrorHeader("网络超时，请稍后再试");
  	return;
  }
  var loginResult = dGetCookie('loginResult');
  if (loginResult != "") {
  	//dSsetCookie("loginResult", "", -1);
  	if (gTimer) {
  		window.clearInterval(gTimer);
  	}
  	if (loginResult == "ok") {
  			//登录成功
  		showSuccessInfoHeader();
  	}
  	else if (loginResult == 1) {
  		showLoginErrorHeader("用户名不存在");
  	}
  	else if (loginResult == 2) {
  		showLoginErrorHeader("用户名或密码错误");
  	}
  	else {
  		showLoginErrorHeader("系统忙，请稍后再试");
  	}
  }
  //else window.alert('space');
  //window.alert('space');
}

function showLoginError(str)
{
	//window.alert(str);
	$('notice').style.visibility = "hidden";
  $('loginForm').style.display = "block";
  $('loginInfo').style.display = "block";
  $('loginInfo').innerHTML = "<font color=red><b>"+str+"</b></font>";
}

function showLoginErrorHeader(str)
{
	//window.alert(str);
  $('loginForm').style.display = "block";
  $('loginInfo').style.display = "block";
  $('notice').innerHTML = "<font color=red><b>"+str+"</b></font>";
}

function showSuccessInfo()
{
	$('notice').style.visibility = "hidden";
  $('loginInfo').style.display = "block";
  $('loginInfo').innerHTML = "<font color=green><b>登录成功</b></font>";
  window.setTimeout('closedialog()', 1000);
  change_button();
  if (gotourl != "" && gotourl != "huitie") {
  	if (gototarget == "blank") {
  		//window.open(gotourl);
  		//window.location.reload();
  		//window.force(tourl);
  		openWindow(gotourl);
  	}
  	else {
  		window.location = gotourl;
  	}
  }
  else if (gotourl == "huitie") {
  	document.data_form.submit();
  }
}

function showSuccessInfoHeader()
{
	var logouturl = "http://passport.sohu.com/logout.jsp?ru=http://club.sohu.com/logout.php?go="+window.location.href;
	$('welcomeinfo').innerHTML = dGetCookie('cn_Cookie')+' 你好&nbsp;<a href="'+logouturl+'">[退出]</a>';
  $('loginInfo').style.display = "block";
  $('notice').innerHTML = "<font color=green><b>登录成功</b></font>";
  $('menu-div').style.display = "none";
  
  //window.setTimeout('closedialog()', 1000);
  //change_button();
}

function change_style(c_tagname, c_property)
{
	var obj = document.getElementsByTagName(c_tagname);
	for (var i=0; i<obj.length; i++)
	{
		if (obj[i].id != 'maildomain') {
			obj[i].style.visibility = c_property;
		}
	}
}

function closedialog()
{
	closeLog('menu-div');
  closeLog('screen');
}

function change_button()
{
	//$('larea').style.display = "block";
	//$('ularea').style.display = "none";
	if($('ularea')) {
		$('ularea').innerHTML = larea;
	}
	if ($('ularea1')) {
		$('ularea1').innerHTML = larea;
	}
}


function openWindow(openurl)
{
	if ($('tmpform')) {
		removeElement($('tmpform'));
	}
	if(!$('tmpform')) {
		var tmpform = document.createElement("form");
		document.body.appendChild(tmpform);
		tmpform.id = "tmpform";
		tmpform.method = "post";
		tmpform.target = "_blank";
		//openurl = openurl.replace("@", "%40");
		tmpform.action = openurl;
		tmpform.submit();
	}
}

function removeElement(el)
{   
 	var p = el.parentNode;   
  p.removeChild(el);   
}

function UrlEncode(str)
{ 
  var ret=""; 
  var strSpecial="!\"#$%&()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    tt += chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
}