﻿// JScript 文件


// *********************************************************************************** //
// 头部控件专用 function 
// --------------
// 功能：设置COOKIE和获取COOKIE

// 传入参数：
//              
// 传出结果：    

// *********************************************************************************** //
function setCookie(name,value)
{
    var Days = 30;   
    var exp = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    //document.cookie = name + "=" + escape(value) +";expires=" + exp.toGMTString();
	document.cookie  =  name  +    "=  "  +  escape(value)  +  ";expires=  "  +  exp.toGMTString()  +    ";path=/  "  ; 
}
function setCookieN(name,value)
{
	document.cookie  =  name  +    "=  "  +  escape(value)  +  ";path=/  "  ; 
}
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]);
    return null;
}

function delCookie()
{
    var ck = document.cookie;
    cs = ck.split(";");
    var exp = new Date();  
    exp.setTime (exp.getTime() - 1);  



    for(i=0;i<cs.length;i++)
    {
        s = cs[i];
        pos = s.indexOf("=");
        if(pos >0)
        {
            name = s.substring(0,pos)
            document.cookie = name + "=" + "; expires=" + exp.toGMTString();
        }
    }
    alert("所有历史纪录都已清除！");
}




// *********************************************************************************** //
// 头部控件专用 function 
// --------------
// 功能：返回对象的位置参数

// 传入参数：
//              
// 传出结果：    

// *********************************************************************************** //
function getObjLeft(obj)
{
	var topnum = 0;
	var parentObj = obj.parentNode;
	while (!isNaN(parentObj.offsetLeft))
	{
		topnum += parentObj.offsetLeft;
		parentObj = parentObj.parentNode;
    }
	return topnum;
}

/*通用函数*/
//获取对象坐标
function getSelectPosition(obj) {
	var objLeft = getObjLeft(obj);
	var objTop = getObjTop(obj);
	return([objLeft,objTop]);
}

function getObjTop(obj)
{
	var topnum = 0;
	var parentObj = obj.parentNode;
	while (!isNaN(parentObj.offsetTop))
	{
		topnum += parentObj.offsetTop;
		parentObj = parentObj.parentNode;
		if(parentObj.id == "pD") break;
	}
	return topnum;
}

// *********************************************************************************** //
// 头部控件专用 function 
// --------------
// 功能：控制下拉菜单

// 传入参数：
//              
// 传出结果：    

// *********************************************************************************** //
function setSelInput(seltype)
{   
    if(document.readyState != "complete")
    {
        return;
    }
    

    var SearchS = getCookie(seltype);
    if(SearchS != null)
    {
        var OptionText = SearchS.split("|");
    }
    else
    {
        SearchS = "";
        var OptionText = SearchS.split("|");
    }
    //下拉菜单主体
    var selectDiv = document.getElementById("imgSel1");
    //外层Div
    if(optionDiv.childNodes.length>0)
    {
        for(var i=optionDiv.childNodes.length-1;i>=0;i--)
        {
            var DelOption = optionDiv.childNodes[i];
            optionDiv.removeChild(DelOption);
        }
    }
    //设置下拉菜单选项的坐标和宽度
    with(optionDiv.style) {
	    //optionDiv.className = "optionDiv";
    }
    //下拉菜单内容
    var OptionUl = optionDiv.appendChild(document.createElement("ul"));
    var Options = new Array();    
    for (var i=0;i<OptionText.length;i++) {
	    Options[i] = OptionUl.appendChild(document.createElement("li"));
    }
    for (i=0;i<Options.length;i++) {
	    Options[i].innerHTML = OptionText[i]+"<i><a href=\"javascript:deloption('" + OptionText[i] + "','" + seltype +   "')\"><img src='../image/delcookie.gif' alt='' border='0'></a></i>";
    }

    /*事件*/
    //禁止选择文本
    selectDiv.onselectstart = function() {return false;}
    optionDiv.onselectstart = function() {return false;}
    document.onclick = function() {
	    optionDiv.style.visibility = "hidden";
    }
    
    for (i=0;i<Options.length;i++) 
    {
	    Options[i].attachEvent("onmouseover",function(){moveWithOptions("highlight","white")});
	    Options[i].attachEvent("onmouseout",function(){moveWithOptions("","")});
	    Options[i].attachEvent("onmouseup",selectedText);
    }
}

function deloption(opt,seltype)
{
    var SearchS = getCookie(seltype);
    if(SearchS != null)
    {
        var reg;    
        if(SearchS.lastIndexOf(opt) == 0)
        {
            reg = new RegExp(opt + "\\|");
        }
        else
        {
            reg = new RegExp( "\\|" + opt);
        }    
        SearchS = SearchS.replace(reg,"");
        setCookie(seltype,SearchS);
        setSelInput(seltype);
    }
}

function SelOptions() {
	event.cancelBubble = true;
	if(optionDiv.innerHTML=="") InitTopicTop();
    optionDiv.style.visibility = optionDiv.style.visibility=="visible"?"hidden":"visible";
}
//移动Option时的动态效果

function moveWithOptions(bg,color) {
	with(event.srcElement) {
		style.backgroundColor = bg;
		style.color = color;
	}
}
function selectedText() {
	with(event.srcElement) {
		document.getElementById("inputSel").value = innerText;
	}
}

function beginSearch(ResponseSearchPath,seaType)
{
    var SearchText;
    if(document.getElementById("inputSel").value != "")
        SearchText = document.getElementById("inputSel").value.trim();
    if( SearchText == null || SearchText == "")
    {
        return;
    }
    
    //如果不是汉字，且长度小于1
    if(SearchText.length < 2)
    {
        re = /[^\u4E00-\u9FA5]/g ;
        if(re.test(SearchText))
        {
            alert("无效的关键词");
            return;
        }
    }
    
    var moto = "><!#%'/;'\"$^*";
    moto = moto.split("");
    for(var i=0;i<moto.length;i++ )
    {
        if(SearchText.indexOf(moto[i]) > 0)
        {
            alert("无效的关键词");
            return;
        }
     }
    
//    var seaType = "";    
//    for(i=0;i<document.getElementsByName("sType").length;i++)
//    {
//        if(document.getElementsByName("sType")[i].checked)
//        {
//            seaType = document.getElementsByName("sType")[i].value;
//        }
//    }
//    seaType = document.getElementById("sel_seachType").value;     //by ms 换成下拉列表 
    setCookieN('newSearchType',seaType);
    
        
    if(seaType == "Forum" && SearchText.length > 15)
    {
        alert("搜索主题吧名字的关键字长度必须小于15个字符");
        return;
    }
        
    var SearchS = getCookie("SearchText");

    document.cookie  =  "newSearchWord=  "  +  escape(SearchText)  +  ";path=/  "  ;
    
    if(SearchS == null || SearchS.trim == "")
    {
        setCookie("SearchText",SearchText);
    }
    else if(SearchS.indexOf(SearchText) == -1)
    {
        var SearchSS 
        SearchSS = SearchS.split("|");
        if(SearchSS.length > 11)
        {
            SearchS = SearchSS[SearchSS.length-11];
            for(var i = SearchSS.length-10;i<SearchSS.length;i++)
            {
                SearchS = SearchS + "|" + SearchSS[i];
            }
        }
        
        setCookie("SearchText",SearchS+"|" + SearchText);
    }
    document.cookie  =  "newSearchSUri=  "  +  escape(document.location.href)  +  ";path=/  ";
    document.location = ResponseSearchPath + "?seaType="+escape(seaType)+"&seaValue="+escape(SearchText);
    
}

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//根据属性设置选择显示初始的页头
function InitTopicTop()
{      
    var seaValue = getCookie("newSearchWord");
    if(seaValue != null && seaValue != "")
    {
        document.getElementById("inputSel").value = seaValue;
    }    
   
    setSelInput("SearchText");           
}

//创建我的主题吧
function CreateNewForum(ForumCreateNewPath)
{
    var SearchText = "";
    
    if(document.getElementById("inputSel").value != "")
        SearchText = document.getElementById("inputSel").value.trim();
    
    
    document.location = ForumCreateNewPath + "?ForName=" + escape(SearchText);
    
}


function ChangeShowMyForum(Pid,obj)
{
    document.getElementById("MyOwnerForumList").style.display = "none";
    document.getElementById("MyGroupForumList").style.display = "none";
    document.getElementById("MyBorwseForumList").style.display = "none";
    document.getElementById("UserAttenforum").style.display = "none";
    document.getElementById("CustomerForumList").style.display = "none";
    if(document.getElementById("divCustomerForumListObj")!=null)
        document.getElementById("divCustomerForumListObj").style.display = "none";
    if(Pid=="CustomerForumList")
        getAllForum(Pid,obj);
    else
        document.getElementById(Pid).style.display = "";
}
// JScript 文件
function getControlXYT(e) {
	var t = [e.offsetLeft,e.offsetTop];
	if(e=e.offsetParent){
		var r = getControlXYT(e);
		t[0] += r[0];
		t[1] += r[1];
	}
	return t;
}
function getAllForum(Pid,obj)
{
    var divObj = document.getElementById("divCustomerForumListObj");
    if(divObj==null) 
    {
        divObj = document.createElement("DIV");
        divObj.setAttribute("id","divCustomerForumListObj");
        divObj.setAttribute("className","custom");
        document.body.appendChild(divObj);
        divObj.style.position= "absolute";
        //divObj.style.backgroundColor="#f9f9f9";
	    //divObj.style.border="1px solid #ccc";

//        if(document.getElementById(Pid).innerHTML!="") 
 //       {
//                document.getElementById("CustomerForumList").style.display = "";
//                return;
//        }
        AsyServerData('../AjaxRequest.bolaa','Method=CustomerForum',ShowUserForum);
    }
        var t = getControlXYT(obj);
        divObj.style.left=t[0];
        divObj.style.top = t[1]+15;
        divObj.style.display = "";

    
    
}
var UserDelDisForums=",";
var UserAddDisForums=",";
function ShowUserForum(str)
{
   if(str=="") return;

   var strHtml="<ul>";
   var arrForum = str.split("|");
    for (j=0;j<arrForum.length;j++)
    {
        var tdArr = arrForum[j].split(",");
        strHtml+="<li><input type=\"checkbox\" name='ckCustF' id='UF"+j+"' "+(tdArr[2]=="1" ? " checked " : "") +" value=\""+tdArr[0]+","+tdArr[2]+"\" /><a href='../Forum/ForumView.lbo?ForumId="+tdArr[0]+"'>"+tdArr[1]+"</a></li>";
    }
    strHtml+=" <li><input type=\"checkbox\" onclick=\"checkAll(this,'ckCustF')\" id='ckAll' /><label for='ckAll'>全选</label></li>"
    strHtml+="</ul><div><span><a href='javascript:window.returnValue;' onclick='updateUserForums()'></a></span><b><a href='javascript:window.returnValue;' onclick='cancelUpdateUserForums()'>取消</a></b></div>";
    document.getElementById("divCustomerForumListObj").innerHTML=strHtml;

}
function cancelUpdateUserForums()
{
   ChangeShowMyForum("UserAttenforum");
}

//选择所有function checkAll(obj,name)
{
    var ck = obj.checked;
    var objs =  document.getElementsByName(name);
    if(objs)
        if(objs.length)
          for(var i=0;i<objs.length;i++)
          {
            objs[i].checked = ck;
          }
}
function AddCusForums()
{
    var objs =  document.getElementsByName("ckCustF");
    if(objs)
        if(objs.length)
          for(var i=0;i<objs.length;i++)
          {
            var vArr = objs[i].value.split(",");
            if(objs[i].checked && vArr[1]==0)
                 UserAddDisForums+=vArr[0]+",";
            else if(objs[i].checked==false && vArr[1]==1)
                UserDelDisForums+=vArr[0]+","
          }
}
function updateUserForums()
{
   AddCusForums();
   AsyServerData('../AjaxRequest.bolaa','Method=updateUserForums&UserDelDisForums=' + UserDelDisForums+'&UserAddDisForums='+UserAddDisForums,function(str){window.location = window.location;});
}
function GetRandomForumId(str)
{
    document.getElementById("txtRandom").value = str;
    setTimeout('CheckForum("true")', 1);
}

function CheckForumId()
{
    var ForumId = document.getElementById("txtRandom").value;
    var p = /^[\d]+$/;
    if(!p.test(ForumId))
    {
        alert("请输入吧Id");
        return;
    }
    AsyServerData('../AjaxRequest.bolaa','Method=CheckForumId&ForumId=' + ForumId,CheckForum);
}

function CheckForum(str)
{
    if(str == "true")
    {
        document.location = FPath + document.getElementById("txtRandom").value+"&idtype='disp'";
    }
    else
    {
        alert("您输入的吧Id不存在!");
    }
}

function SetShowUserInfo()
{
    var ShowUserInfo = getCookie("ShowUserInfo");
    if(ShowUserInfo != "none") 
    {
        ShowUserInfo = "none";
        document.getElementById("Show_myinfo_Pic").src = "../image/quickchoo_arrow_down.gif";
    }
    else
    {
        ShowUserInfo = "";
        document.getElementById("Show_myinfo_Pic").src = "../image/quickchoo_arrow_up.gif";        
    }
    setCookie("ShowUserInfo",ShowUserInfo);
    document.getElementById("Show_myinfo").style.display = ShowUserInfo;
}
//字符串替换函数
function   replace(expression,find,replacewith)   
{   
    var   blnFlag;   
    if(expression=="")   
        blnFlag=false;   
    else   
    {   
        var   loc=expression.indexOf(find);   
        var   findLen=find.length;   
        var   replaceWithLen=replacewith.length;   

        if(loc!=-1)   
            blnFlag = true;   
        else   
            blnFlag =false;   

        while(blnFlag)   
        {   
            expression   =   expression.substr(0,loc)+replacewith+expression.substr(loc+findLen);   
            loc   =   expression.indexOf(find,loc+replaceWithLen);   
            if(loc   ==   -1)  blnFlag   =   false;   
        }   
    }   
    return   expression;   
} 
function glUpDownDisply(glDisobj,glPicobj)
{
if(glDisobj.style.display=="")
{
glDisobj.style.display="none"
glPicobj.src="../image/addmyrss_arrow_down.gif"
}
else
{
glDisobj.style.display=""
glPicobj.src="../image/addmyrss_arrow_up.gif";
}
}

var signEdidorDiv;

function ShowSignEditorPanel() {
    if (!signEdidorDiv)
    {
        var oMySignTitle = document.getElementById("mySignTitle");

        signEdidorDiv                       = document.createElement("div");
        signEdidorDiv.className             = 'utext';
        //signEdidorDiv.style.backgroundColor = 'white';
        //signEdidorDiv.style.left            = getObjLeft(oMySignTitle);
        //signEdidorDiv.style.top             = getObjTop(oMySignTitle);
        //signEdidorDiv.style.position	    = 'absolute';
        //signEdidorDiv.width                 = 200;
        //signEdidorDiv.height                = 30;
        oMySignTitle.parentNode.insertBefore(signEdidorDiv, document.getElementById('mySignContent'));
        //oMySignTitle.parentNode.appendChild(signEdidorDiv);
        //document.body.appendChild(signEdidorDiv);
    }
    
    signEdidorDiv.style.display = 'block';
    signEdidorDiv.style.visibility = 'visible';
    
    var mySignValue = document.getElementById("mySignContent").innerHTML;
    signEdidorDiv.innerHTML = "<div><input type='image' value='确定' onclick='javascript:UpdateSign();return false;' src='../img/utext_ok_btn.gif' /> <br /> <input type='image' value='取消' src='../img/utext_cancel_btn.gif' onclick='javascript:signEdidorDiv.style.display =\"none\";return false;' /></div><textarea type='text' id='signEditorInput'>" + mySignValue + "</textarea>"
}

function UpdateSign() {
    var signEditorInputValue = document.getElementById('signEditorInput').value;
    
    AsyServerData('../AjaxRequest.bolaa', 'Method=UpdateUserAdage&UserAdage=' + escape(signEditorInputValue), UpdateSignComplete);
    signEdidorDiv.style.display = 'none';
}

function UpdateSignComplete(retValue) {
    document.getElementById("mySignContent").innerHTML = retValue;
}
function TopBannerStyle360()
{
    var topbanner = arguments[0] || "div_topic_top_guest";
    var topbannerheight= arguments[1] || 25;
    var topbannertimer;

    function topbannermove(){	//topbanner移动函数
	    if(topbannerheight<=3)
	    {
		    topbanner.style.marginTop="0";
		    window.clearInterval(topbannertimer);
	    }else{
		    topbanner.style.marginTop="-"+(topbannerheight-=3)+"px";
	    }
    }
    function topbannershow(){	
        if((topbanner=document.getElementById("div_topic_top_guest"))!=null)
        {
            topbanner.style.display="";
            topbanner.style.marginTop="-"+topbannerheight+"px";
	        topbannertimer = window.setInterval(topbannermove,25);	//topbanner开始移入
        }
    }
    if(document.all)
    {
        window.attachEvent('onload',topbannershow);
    }
    else{
        window.addEventListener('load',topbannershow,false);
    }
}
