﻿///获取标准html控件ID
function $JC(hid)
{
    return document.getElementById(hid);
}


///回车事件
function SubmitKeyOnClick(hid, event)
{
    if(event.keyCode == 13)
    {
        event.returnValue = false;
        document.getElementById(hid).click();
    }
}

//检测字符
function isReg(str)
{ 
    var re = /^[0-9a-z \u4e00-\u9fa5]+$/gi; 
    return re.test(str); 
}

///将字符窜转换为对象
function decode(json)
{ 
    return eval("("+json+")"); 
}

//控制点击样式
function Visited(hid)
{
    var tempCookie = getCookie("LinkButtonName");
    if(tempCookie != null)
    {
        if($JC(tempCookie) != null)
        {
            var tempObj = decode(tempCookie);
            if(hid != tempObj)
            {
                hid.style = "";
            }
        }
    }
    hid.style.color = "#f89500";
    addCookie("LinkButtonName", hid, 1);    
}

//点击展开事件
function ControlBlock(ConID, ImgID, ValCon)
{
    if(ConID.style.display == "none")
    {
        ConID.style.display = "block";
        ImgID.style.background = "url(images/title_1.jpg)";
        window.scrollTo(0,0);   ///滚动条至顶端
    }
    else
    {
        ConID.style.display = "none";
        ImgID.style.background = "url(images/title_2.jpg)";
    }
    CookieBlock(ConID, ValCon);
}

function CookieBlock(ConID, ValCon)
{
    var TempCookie = getCookie("TCookie");
    addCookie("TCookie",ValCon,1);
    if(TempCookie != null)
    {
        ///判断是否存在TempCookie对象,如果存在则把TempCookie转换为对象并使之收缩起来
        if(document.getElementById(TempCookie) != null)
        {
            var TempObj = decode(TempCookie);
            if(ConID != TempObj)
            {
                TempObj.style.display = "none";
                var TempStart = TempCookie.toString().indexOf("Cont");
                var TempGifStr = TempCookie.toString().substring(TempStart + 4);
                var ObjTempGif = decode("Icon" + TempGifStr);
                ObjTempGif.style.background = "url(images/title_2.jpg)";
            }
        }
    }
}

//添加cookie
function addCookie(objName,objValue,objHours)
{
    var str = objName + "=" + escape(objValue);
    if(objHours > 0)
    {
        //为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours*3600*1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
    //alert("添加cookie成功");
}
  
//获取指定名称的cookie的值
function getCookie(objName)
{
    var arrStr = document.cookie.split("; ");
    var temp = null;
    for(var i = 0;i < arrStr.length;i ++)
    {
        var arrTemp = arrStr[i].split("=");
        for(var j = 0; j < arrTemp.length; j++)
        {
            if(arrTemp[j] == objName)
            {
                return unescape(arrTemp[j+1]);
                break;
            }
        }
    }
    return temp;
}
  
//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
function delCookie(name)
{
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}

//读取所有保存的cookie字符串
function allCookie()
{
    var str = document.cookie;
    if(str == "")
    {
        str = "没有保存任何cookie";
    }
    alert(str);
}

function $value(m,n)
{
    return document.forms[m].elements[n].value;
}

function add_()
{
    var cookie_name = $value("myform","cookie_name");
    var cookie_value = $value("myform","cookie_value");
    var cookie_expireHours = $value("myform","cookie_expiresHours");
    addCookie(cookie_name,cookie_value,cookie_expireHours);
}

function get_()
{
    var cookie_name = $value("myform","cookie_name");
    var cookie_value = getCookie(cookie_name);
    alert(cookie_value);
}

function del_()
{
    var cookie_name = $value("myform","cookie_name");
    delCookie(cookie_name);
    alert("删除成功");
}

//控制菜单展开隐藏
function cbd(hid)
{
    if(hid != undefined)
    {
        if($JC(hid).style.display == "none")
        {
            $JC(hid).style.display = "block";
        }
        else
        {
            $JC(hid).style.display = "none";
        }
    }
}

//控制按钮菜单的显示隐藏
var mdNum = 5;
function setTabSyn(i)
{
	selectTabSyn(i);
}
function selectTabSyn(i)
{
    switch(i)
    {
        case i:
            for(j = 1; j <= mdNum; j++)
            {
                if($JC("TabCon" + j) != null)
                {
                    $JC("TabCon" + j).style.display = "none";
                    $JC("mdTab" + j).className = "mdCl";
                }
            }
            $JC("TabCon" + i).style.display = "block";
            $JC("mdTab" + i).className = "mdCl2";
            break;
	    default:
	        break;
    }
}

//控制类别展开隐藏
function pLc(pLi, hid)
{
    if(hid.style.display == "none")
    {
        pLi.className = "minus";
        hid.style.display = "block";
    }
    else
    {
        pLi.className = "plus";
        hid.style.display = "none";
    }
}

//登录
function LoginModer()
{
    tb_show("User Login","/WinModer/Login.aspx?&width=600&height=225&modal=true","thickbox");//调用thickbox之必需
}

function doLogin(inAccount, inPwd, inDays)
{
    if($("#"+inAccount).val() == "" || $("#"+inAccount).val() == "UserName")
    {
        alert("Please enter username!");
        $("#"+inAccount).focus();
        return false;
    }
    if($("#"+inPwd).val() == "" || $("#"+inPwd).val() == "Password")
    {
        alert("Please enter password!");
        $("#"+inPwd).focus();
        return false;
    }
    $.post("/jAjax/Logining.ashx",{Account:$("#"+inAccount).val(), Pwd:$("#"+inPwd).val(), Days:inDays},function(res){
        var arrRes = res.split("|");
        if(arrRes[0] == "succeed")
        {
            tb_show("Login","/WinModer/MsgInfo.aspx?&width=600&height=210&modal=true&State=" + arrRes[1] + "&Msg="+arrRes[2],"thickbox");
        }
        else
        {
            tb_show("User Login","/WinModer/Login.aspx?&width=600&height=225&modal=true&erty=1","thickbox");//调用thickbox之必需
        }
    });
}

function CheckComment()
{
    if($("#txtTitle").length > 0)
    {
        if($("#txtTitle").val() == "")
        {
            alert("Please enter the title.");
            $("#txtTitle").focus();
            return false;
        }
    }
    
    if($("#EditorContent").length > 0)
    {
        if($("#EditorContent").val().length > 20)
        {
            alert("The length of content should be less than 250 characters!");
            return false;
        }
    }
    
    if($("#header1_Loginer").length > 0)
    {
        AddLoginUrl();
        LoginModer();
        return false;
    }
}

function CheckLogined()
{
    if($("#header1_Loginer").length > 0)
    {
        AddLoginUrl();
        LoginModer();
        return false;
    }
}

function AddLoginUrl()
{
    addCookie("PreLoginUrl", document.URL, 10);
}

function GetPreLoginUrl()
{
    getCookie("PreLoginUrl");
}

function GoPreLoginUrl()
{
    var url = getCookie("PreLoginUrl");
    if(url != null && url != undefined)
    {
        window.location.href = getCookie("PreLoginUrl");
    }
}

//修正网页表情的路径
function CheckImg()
{
    $("img[src^='emote/']").attr("src","/forums/"+$("img[src^='emote/']").attr("src"));
    //alert($("img[src^='emote/']").attr("src"));
}

function doAgree(Rid)
{
    $.get("/jAjax/doAgree.ashx",{id:Rid},
    function(data)
    {
        if(data == "true")
        {
            $("#spAgree" + Rid).html(Number($("#spAgree" + Rid).html()) + 1);
            $("#aAgree" + Rid).addClass("up_comment_no");
        }
    });
}

function doDisAgree(Rid)
{
    $.get("/jAjax/doDisAgree.ashx",{id:Rid},
    function(data)
    {
        if(data == "true")
        {
            $("#spDisAgree" + Rid).html(Number($("#spDisAgree" + Rid).html()) + 1);
            $("#aDisAgree" + Rid).addClass("down_comment_no");
        }
    });
}


function SelectedAll()
{
    ck = document.getElementsByTagName("INPUT")
    var cbChoiceAll = document.getElementById("cbChoiceAll");
    if(cbChoiceAll.checked)
    {
        for(i=0;i<ck.length;i++)
        {
            if(ck[i].type=="checkbox")
            {
                ck[i].checked = true;
            }
        }
    }
    else
    {
        for(i=0;i<ck.length;i++)
        {
            if(ck[i].type=="checkbox")
            {
                ck[i].checked = false;
            }
        }
    }
}



function SelectPage(selfObj, att, TagsId, HeadAtt, cssName){
	var tag = document.getElementById(TagsId).getElementsByTagName("a");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	//$("#"+TagsId+" [class="+cssName+"]").removeClass(cssName);
	//$("#"+TagsId+" li [class="+cssName+"]").removeClass(cssName);  //有li的标签
	selfObj.className = cssName;
	if(att != "0")
	    $("#item > a:first").addClass("news_tab");
	    selfObj.className = cssName;
	for(i=0; i<taglength; i++){
	    document.getElementById(HeadAtt + i).style.display = "none";
	    //$(HeadAtt + i).css("display", "none");
	}
	document.getElementById(HeadAtt + att).style.display = "block";
	//$(HeadAtt + att).css("display", "block");
}


function SelectPageLi(selfObj, att, TagsId, HeadAtt, cssName){
	var tag = document.getElementById(TagsId).getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	//$("#"+TagsId+" [class="+cssName+"]").removeClass(cssName);
	//$("#"+TagsId+" li [class="+cssName+"]").removeClass(cssName);  //有li的标签
	selfObj.className = cssName;
	for(i=0; i<taglength; i++){
	    document.getElementById(HeadAtt + i).style.display = "none";
	}
	document.getElementById(HeadAtt + att).style.display = "block";
}
