﻿///获取标准html控件ID
function $(hid)
{
    return document.getElementById(hid);
}

///回车事件
function SubmitKeyOnClick(hid)
{
    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($(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("; ");
    for(var i = 0;i < arrStr.length;i ++)
    {
        var temp = arrStr[i].split("=");
        if(temp[0] == objName)
        {
            return unescape(temp[1]);
        }
        else
        {
            return null;
        }
    }
}
  
//为了删除指定名称的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.style.display == "none")
    {
        hid.style.display = "block";
    }
    else
    {
        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($("TabCon" + j) != null)
                {
                    $("TabCon" + j).style.display = "none";
                    $("mdTab" + j).className = "mdCl";
                }
            }
            $("TabCon" + i).style.display = "block";
            $("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";
    }
}