(function (){
///
var icb = window.icb = {
//************
user: {
	id:0,
	name:'',
	email:'',
	mobile:'',
	stat:{
		stat:false,
		email:false,
		mobile:false
	}
}, 
init: function(){
	var ustat;
	var stat = this.readcookie('_ustat');
	if(typeof stat == "string"){
		try{
			ustat = eval('('+stat+')'); 
			this.user.id =  ustat.i;
			this.user.name= ustat.n;
			this.user.email=ustat.e;
			this.user.stat.account=ustat.s.u;
			this.user.stat.email=ustat.s.e;
			this.user.stat.mobile=ustat.s.m;
		}catch(e){}
	} 

	if(this.checklogin()){
		this.showuserinfo();
	}else{
		this.initloginwindow();
	}

	this.showdailysentence();
	//this.showadtips();
},

$:	function (id){
		return document.getElementById(id);
},
 
getparam: function(name){
	if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1)
    {
        return false;
    }

    var queryString = location.href.substring(location.href.indexOf("?")+1);

    var parameters = queryString.split("&");
    var pos, paraName, paraValue;
    for(var i=0; i<parameters.length; i++)
    {
        pos = parameters[i].indexOf('=');
        if(pos == -1) { continue; }

        paraName = parameters[i].substring(0, pos);
        paraValue = parameters[i].substring(pos + 1);

        if(paraName == name)
        {
            return unescape(paraValue.replace(/\+/g, " ")); 
        }
    }
    return false;
},

readcookie: function(name){
	var cookieValue = "";
	var search = name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			cookieValue = document.cookie.substring(offset, end);
		}
	}
	return decodeURIComponent(cookieValue);
},

checklogin: function(){ 
	if(this.user.id == 0 || this.user.name == '') return false;
	return true;
},

showloginwindow: function(){ 
	try{
      var w, h;
      if (self.innerHeight) {
    	w = self.innerWidth;
    	h = self.innerHeight;
      }else if(document.documentElement && document.documentElement.clientHeight) {
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
      }else if (document.body){
        w = document.body.clientWidth;
        h = document.body.clientHeight;
      }
      sh = document.body.scrollTop;
      sh = sh ? sh : document.documentElement.scrollTop;
      mh = document.body.scrollHeight;
      mh = mh > h ? mh:h;
      this.$('logWindow').style.display='';
      this.$('logWindow').style.left=(w - 280)/2 +'px';
      this.$('logWindow').style.top=((h - 395)/2+sh) +'px';
      this.$('myhidWin').style.display='';
      this.$('myhidWin').style.height= mh + 'px';
	}catch(e){
      return true;
	}
	return false;
},

closeloginwindow: function(){
	try{
		this.$('logWindow').style.display='none';
		this.$('myhidWin').style.display='none';
	}catch(e){}
},
 
initloginwindow:function(){
	var spector = '&nbsp;|&nbsp;';
	document.write('<div id="myhidWin" style="display:none;position:absolute;z-index:100;background:#000;margin:0px;width:100%;filter:alpha(opacity=5);-moz-opacity:0.05;top:0px;left:0px;" onclick="icb.closeloginwindow();">&nbsp;</div><div id="logWindow" style="display:none;position:absolute;z-index:100;margin-left:10px;background:#ffffff;width:280px;height:395px;"><link href="http://my.iciba.com/css/cn/login.css" rel="stylesheet" rev="stylesheet" type="text/css"><div style="border: 2px solid #e9f3fc;width:280px;"><div style="border:1px solid #C0DDEC;"><div style="float:right;margin:8px 10px;"><a href="javascript:icb.closeloginwindow();"><img border="0" alt="点击关闭" src="http://my.iciba.com/images/tb_close.jpg"/></a></div><div id="login" style="width: 250px;clear: both;"><div class="r" style="clear: both; width: 250px;"><div class="n"><form name="logfrm" id="logfrm" action="http://uc.iciba.com/index.php?module=user&act=login&g=1&returnurl='+encodeURIComponent(window.location.href)+'" method="post" style="margin: 0pt;"><div class="c" style="background:url();"><div><img src="http://my.iciba.com/images/cn/login_07.jpg"></div><div class="c1" style="font-size:12px">用户名：<input id="username" name="username" style="width: 176px;" type="text"></div><div class="c1" style="font-size:12px">密　码：<input name="password" style="width: 176px;" type="password"><input type="hidden" name="do" value="login" /></div><div class="c2"><div style="float: right;"><a href="http://pass.kingsoft.com/ksgweb/jsp/login/passwordmail.jsp" style="font-size:12px;">忘记密码?</a></div><label style="font-size:12px;" for="autologin"><input id="autologin" name="autologin" value="1" style="border: medium none ;height:14px;" type="checkbox">下次自动登录</label></div><div class="c3"><input name="loginsubmit" value="1" src="http://my.iciba.com/images/cn/login_05.jpg" type="image"></div><div class="c4" style="font-size:12px">还没有注册？</div></div><div class="c5" style="text-align: center;"><a href="http://uc.iciba.com/index.php?module=user&act=reg"><img src="http://my.iciba.com/images/cn/login_06.jpg" border="0"></a><br/></div></form></div></div></div><div style="clear:both;line-height:500%;">&nbsp;</div></div></div><div style="clear:both;"></div></div>');
	try{
		this.$('my_nick').innerHTML = '<a href="http://uc.iciba.com/?module=user&act=login&returnurl='+encodeURIComponent(window.location.href)+'" onclick="return icb.showloginwindow();">登录</a>' + spector;
		this.$('my_center').innerHTML = '<a href="http://uc.iciba.com/?module=user&act=reg&returnurl='+encodeURIComponent(window.location.href)+'" target="_blank">注册</a>';
		this.$('my_logout').innerHTML = '';
	}catch(e){}
},


//显示登录后信息
showuserinfo:function(){
	var spector = '&nbsp;|&nbsp;';
	try{
	var spacename='我的空间';
	if(/^sl/.test(window.location.hostname)){
		spacename = '我的E社会';
	}
	this.$('my_nick').innerHTML = this.user.name + spector;
	this.$('my_center').innerHTML = '<a href="http://e.iciba.com/space.php?do=home" id="mh" class="my_centers" target="_blank">' + spacename + '</a> <span id="my_span"></span>' + spector;
	this.$('my_logout').innerHTML = '<a href="http://uc.iciba.com/?module=user&act=login&do=logout&g=1&returnurl='+encodeURIComponent(window.location.href)+'" target="_top">退出</a>';
	}catch(e){}
	document.write("<scr"+"ipt  language=javascript  src='http://uc.iciba.com/index.php?module=message&act=chknew'></scr"+"ipt>");
}, 

showdailysentence:function(){
	if(this.$('spdbox')){
	   try{
		   document.write('<scri'+'pt src="http://www.iciba.com/spdshow.php" charset="utf-8" type="text/javascript" language="javascript"></sc'+'ript>');
	   }catch(e){}
	}
},

showadtips:function(){
	var dt = new Date(); 
	if( dt.getSeconds() % 2 == 0 &&  !/^(www|editor|love|newdict|old)/.test(window.location.hostname)){ 
		try{ document.write('<scri'+'pt src="http://my.iciba.com/script/showtip.js" charset="utf-8" type="text/javascript" language="javascript"></sc'+'ript>');}catch(e){}    
	}
},
ajax: {
	xmlHttp:null,
	init:function(){
		if(window.ActiveXObject) { 
		   this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	   } else if(window.XMLHttpRequest) { 
		   this.xmlHttp = new XMLHttpRequest(); 
	   }
	},

	get: function(s){ 
		s.method = "GET";
		this.send(s);
	},

	post:function(s){
		s.method = "POST";
		this.send(s);
	},
	
	send: function(s){
		document.domain = "iciba.com";
		if(!s.method) s.method = "GET";
		if(!s.dataType) s.dataType = "text";
		if(!s.async) s.async = true;
		if(!s.sucess) s.sucess = function(){
		}

		if(!s.error) s.error = function(){
		}

		if(!s.loading) s.loding = function(){
		}

		if(s.data){ 
			if(s.url.indexOf("?")>=0){
				s.url += "&" + s.data;
			}else{
				s.url += "?" + s.data;
			}
		}

		this.init();
		this.xmlHttp.open(s.method,s.url,s.async); 
		this.xmlHttp.onreadystatechange = function(){
			if(this.readyState == 1){
				s.loading();
			}  

			if(this.readyState == 4){
				if(this.status == 200){
					s.success(this.responseText);
				}
			}
		};
		
		this.xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); 
		this.xmlHttp.send(null);
	}
}

}; 

icb.init();
//*************** 
})(); 
