//****************************************************************************
//创建人：赖利锋
//创建时间：2007-08-04
//用途：整个网站公用的脚本文件
//****************************************************************************
var isguestlogin=false;//是否为游客登陆
var slinkfriend_data="";

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
 String.prototype.trim  =  function()
{
   return  this.replace(/(^\s*)|(\s*$)/g,  "");
}
/*js容错*/
function killErrors() {
   return true;
}
window.onerror = killErrors;

function menuFix() { 
    var sfEls = document.getElementById("nav").getElementsByTagName("li"); 
	for (var i=0; i<sfEls.length; i++) { 
		sfEls[i].onmouseover=function() { 
				this.className+=(this.className.length>0? " ": "") + "sfhover"; 
			} 
			sfEls[i].onMouseDown=function() { 
				this.className+=(this.className.length>0? " ": "") + "sfhover"; 
			} 
			sfEls[i].onMouseUp=function() { 
				this.className+=(this.className.length>0? " ": "") + "sfhover"; 
			} 
			sfEls[i].onmouseout=function() { 
				this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"),""); 
		} 
	} 
} 
function bookmarkit()
{
	if (document.all)
    {
       window.external.addFavorite('http://www.99sushe.com/','99sushe_大学生交友社区');
    }
    else if (window.sidebar)
    {
       window.sidebar.addPanel('99sushe_大学生交友社区', 'http://www.99sushe.com/', "");
    }
}
//加载方法
function loadHead()
{
   OpenService.BIK.Business.Model.AjaxFactory.GetLoginInfo(loadHead_callback);
}
function loadHead_callback(response)
{
   if(response != null &&　response.value != null)
   {
       if(response.value == "")
       {
           notLogin();
       }
       else
       {
           var infos = response.value.split(",");
           document.getElementById('head_main').href='/main.aspx?userid='+infos[0];
           document.getElementById('hName').innerHTML = infos[1];
           document.getElementById('hBrowseTimes').innerHTML = infos[2];
           document.getElementById('hMessages').innerHTML = infos[3];
           hasLogin();
           if(parseInt(infos[4])==1){
              isguestlogin=true;
              document.getElementById('head_main').href="javascript:void(0);";//head_main
              document.getElementById('head_login').innerHTML="<img src='/img/200708/login_5.jpg' />"+infos[1]+",你现在是游客登陆，请登陆 <label color='#ff0000'><a href='/Regist.aspx'>注册</a></label> 网站体验更多功能！";
              }else{
              isguestlogin=false;
              }
           //alert("isguest:"+isguestlogin);
       }
   }
   else
   {
       notLogin();   
   }
}
//已登录用户
function hasLogin()
{
    document.getElementById('head_login').style.display='block';
}
//未登录用户
function notLogin()
{
    if(window.location.href.toLowerCase().indexOf("regist.aspx") == -1)
    {
			document.getElementById('head_notlogin').style.display='block';
    }
   	if(window.location.href.toLowerCase().indexOf("rmbregist.aspx") >0)
	{
			document.getElementById('head_notlogin').style.display='block';
    }
    else
    {
        if(window.location.href.toLowerCase().indexOf("regist.aspx") > 0)
		{
			document.getElementById('head_notlogin').style.display='block';
			document.getElementById('head_notlogin').innerHTML="99宿舍 - 最in的国际大学生互动社区!";
			document.getElementById('head_notlogin').style.color='white';
			document.getElementById('head_notlogin').style.padding='10px 5px';
			document.getElementById('head_notlogin').style.textIndent='2em';
			document.getElementById('head_notlogin').style.lineHeight='20px';
			document.getElementById('head_notlogin').style.textAlign='left';
		}
    }
}
//返回当前用户的经常联系人集合，用，分开
function getislinkFriend()
{
	OpenService.BIK.Business.Model.AjaxFactory.islinkFriend(getlinkfriend_callback);
	return slinkfriend_data;
}

	//判断上线用户是否经常联系的好友，返回好友id,用，分开
function getlinkfriend_callback(response)
{
	slinkfriend_data=response.value;
}

function dorm99AllSearch()
{
	window.location.href='/search/FriendSearch.aspx';
}
//99搜索
function dorm99Search()
{
    var txt = document.getElementById('txtdorm99Search').value.trim();
    if(txt == "")
    {
        alert("请输入搜索内容");
        document.getElementById('txtdorm99Search').focus();
    }
    else
    {
         document.getElementById("btndorm99Search").disabled='disabled';
         var searchtype = document.getElementById("selSearchType");
	     var typevalue = searchtype.options[searchtype.selectedIndex].value;
	     if(typevalue == 1)
	     {
	         window.location.href='/friendlist.aspx?nickname='+txt;
	     }
	     else if(typevalue == 2)
	     {
	         window.location.href='/search/BlogSearchResult.aspx?key='+txt;
	     }
	     else if(typevalue == 3)
	     {
	         window.location.href='/search/albumsearchresult.aspx?key='+txt;
	     }
	     else if(typevalue == 4)
	     {
	         window.location.href='/search/videosearchresult.aspx?key='+txt;
	     }
	     else if(typevalue == 5)
	     {
	         window.location.href='/search/postsearchresult.aspx?key='+txt;
	     }
	     else
	     {
	         window.location.href='/gpsearchresult.aspx?txt='+txt;
	     }
    }
}
//登录
 function hlogin()
{
    if(document.getElementById("htxtUserName").value.trim() == "" || document.getElementById("htxtPasswordLogin").value == "")
	{
		alert("用户名和密码都不能为空");
		document.getElementById("htxtUserName").focus();
	}
	else
	{
		document.getElementById("hLogin").disabled="disabled";
		var ip = "";
		var ip_con = document.getElementById("Left_clientIp");
		if(ip_con != null)
		{
		   ip = ip_con.value;
		}
		OpenService.BIK.Business.Model.AjaxFactory.Login(document.getElementById("htxtUserName").value.trim(),document.getElementById("htxtPasswordLogin").value,ip,window.location.href,login_CallBack);
	}	  
}
//登录回调
function login_CallBack(response)
{    
    if(response != null && response.value != null)
    {
        if(response.value == "-1")
        {
            alert("密码错误，请注意大小写");
            document.getElementById("hLogin").disabled="";
            document.getElementById("htxtUserName").focus();
        }
        else if(response.value == "-2")
        {
            alert("系统找不到指定用户，请检查用户名输入是否有误");
            document.getElementById("hLogin").disabled="";
            document.getElementById("htxtUserName").focus();
        }
        else if(response.value == "0")
        {
            alert("由于网络忙，登录未成功，请重新登录");
            document.getElementById("hLogin").disabled="";
            document.getElementById("htxtUserName").focus();
        }
        else if(response.value == "1")
        {
        	//window.open('http://www.99sushe.com/passport/login.aspx?uid='+document.getElementById("htxtUserName").value+'&ups='+escape(document.getElementById("htxtPasswordLogin").value+'&url='+window.location.href));
            window.location.href = window.location.href.replace("redirect=dorm99","").replace("?&","&").replace("&&","&");
        }
    }
}
//忘记密码
 function hgetpwd()
{
    if(document.getElementById("htxtUserName").value.trim() == "")
	{
		alert("请输入你的注册邮箱");
		document.getElementById("htxtUserName").focus();
	}
	else
	{
		document.getElementById("hpwd").disabled="disabled";
		var res = parseInt(OpenService.BIK.Business.Model.AjaxFactory.GetPassword(document.getElementById("htxtUserName").value.trim()).value);
		if(res==0)
        {
            alert("系统找不到指定用户，请检查注册邮箱输入是否有误!");
        }
        else if(res==1)
        {
            alert("密码已发至您的邮箱，请查收!如果没有收到邮件，请确认你的邮箱没有屏蔽来自dorm99.com的信件");
        }
        else if(res==-1)
        {
            alert("由于网络忙，发信没有成功，请重发!");
        }
        document.getElementById("hpwd").disabled="";
        document.getElementById("htxtUserName").focus();
	}	  
}
//忘记密码回调
function getpwd_callback(response)
{    
    if(response != null && response.value != null)
    {
        if(response.value == "0")
        {
            alert("系统找不到指定用户，请检查注册邮箱输入是否有误!");
        }
        else if(response.value == "1")
        {
            alert("密码已发至您的邮箱，请查收!如果没有收到邮件，请确认你的邮箱没有屏蔽来自dorm99.com的信件");
        }
        else if(response.value == "-1")
        {
            alert("由于网络忙，发信没有成功，请重发!");
        }
    }
    else
    {
        alert("网络传输出现错误，请刷新页面重试");
    }
    document.getElementById("hpwd").disabled="";
    document.getElementById("htxtUserName").focus();
}
//注册
function hregist()
{
    var reurl = "/Regist.aspx";
    reurl = reurl+"?fromUrl="+window.location.href;
	window.location.href = reurl;
}
function onlineAddScore(userid)
{
    OpenService.BIK.Business.Model.AjaxFactory.AddScoreForOnlineTime(userid,15,"在线15分钟");
}

//在线加钱
function onlineaddcashtime(userid)
{
	return OpenService.BIK.Business.Model.AjaxFactory.addcashtime(userid).value;
}
//在线查询
function getcashtime(userid)
{
	return OpenService.BIK.Business.Model.AjaxFactory.getcashtime(userid).value;
}

function inviteOnlineChat(targetid,targetname)
{
    document.frames['dorm99_online_frame'].inviteOnlineChat(targetid,targetname);
}
//这里是从default.js中移入
/////////////////////////////////////////////////////////////////////////////////
////	控件值限制（比如限制300字）长度，并显示剩余字数
////    ctlDetail:文字输入的控件对象，比如待输入文字的文本框
////    maxLength:字数上限值，比如300
////    ctlLeftWords:显示“剩余字数”的控件，通常可用文本框
////    输入框使用方法：onPropertyChange = LimitWords('txtBody',1000)
///////////////////////////////////////////////////////////////////////////////
function LimitWords(ctlDetail,maxLength,ctlLeftWords)
{
    var leftWord=document.getElementById(ctlLeftWords);
    var checkedBox=document.getElementById(ctlDetail);
    if(checkedBox != null)
    {
        if(checkedBox.value.length>maxLength)
        {
             checkedBox.value=checkedBox.value.substring(0,maxLength)
        }
        else if(leftWord !=null)
        {
             leftWord.value=maxLength-checkedBox.value.length;
        }
    }
}

//获取页面上的参数
function QueryString(queryStringName)
{
	var returnValue="";
	var URLString=new String(document.location);
	var serachLocation=-1;
	var queryStringLength=queryStringName.length;
	do
	{
		serachLocation=URLString.indexOf(queryStringName+"\=");
		if (serachLocation!=-1)
		{
			if ((URLString.charAt(serachLocation-1)=='?') || (URLString.charAt(serachLocation-1)=='&'))
			{
				URLString=URLString.substr(serachLocation);
				break;
			}
			URLString=URLString.substr(serachLocation+queryStringLength+1);
		}
			
	}
	while (serachLocation!=-1)
	if (serachLocation!=-1)
	{
		var seperatorLocation=URLString.indexOf("&");
		if (seperatorLocation==-1)
		{
			returnValue=URLString.substr(queryStringLength+1);
		}
		else
		{
			returnValue=URLString.substring(queryStringLength+1,seperatorLocation);
		} 
	}
	return returnValue;
}
//自动适应图片大小，mypic为图片对象，xw和xl为图片的最大宽度和最大高度，此方法放在图片的onload事件中
function fitimg(mypic,xw,xl){ 
    var width = mypic.width; 
    var height = mypic.height; 
    var bili = width/height;  
    var a=xw/width; 
    var b=xl/height; 
    if(a<1||b<1) 
    { 
        if(a<b) 
        { 
            mypic.width=xw; 
            mypic.height=xw/bili; 
        } 
        else
        {
            mypic.width=xl*bili; 
            mypic.height=xl; 
        }
    } 
} 
//游客登陆
function guestlogin(){
	OpenService.BIK.Business.Model.AjaxFactory.guest_login(window.location.href,login_CallBack);
	}
function initifguestlogin(){
    alert(isguestlogin);
}
//99新闻滚动效果
var move;
function move_news()   
{  
  if(roll_news_2.offsetTop-roll_news.scrollTop <= 0)   
  {
     roll_news.scrollTop = roll_news.scrollTop - roll_news_1.offsetHeight;   
  }
  else   
  {   
     roll_news.scrollTop++;
  }   
}
function start_move_news()
{
	if(document.getElementById("roll_news_2")!=null)
	{
		if(roll_news_2.innerHTML == "")
		{
			roll_news_2.innerHTML=roll_news_1.innerHTML;
		}
		move = setInterval(move_news,100);
	}
}
function stop_move_news()
{
   clearInterval(move);
}
if(document.getElementById("roll_news"))
{
   addLoadEvent(start_move_news);
}
this.location.onload=start_move_news();
