//控制左边导航菜单的显示和隐藏
function showMenu(menuID, obj) {
    var menu = document.getElementById(menuID);
    var target = obj;
    target.blur();
    if (menu.style.display != "block") {
        menu.style.display = "block";
        target.style.backgroundImage = "url(../images/min.gif)";
    } else {
        menu.style.display = "none";
        target.style.backgroundImage = "url(../images/max.gif)";
    }
}

//控制对象显示和隐藏
function showObj(objID, action) {
    var obj = document.getElementById(objID);
    action = (action == "show") ? "block" : "none";
    obj.style.display = action;
}
//全选checkbox和全不选
function checkAll(obj) {
    var check = document.getElementsByName("idList[]");
    for (i = 0; i < check.length; i++) {
        check[i].checked = obj.checked;
    }
}
//设置表单中GD选项的状态
function setGDState(bool) {
    var obj = document.getElementById("noGD");
    if (bool === true) {
        obj.checked = false;
    }
    obj.disabled = bool;
}
//设置单选的check值
function setRadioCheck(name, checkValue) {
    var radio = document.getElementsByName(name);
    for (i = 0; i < radio.length; i++) {
        if (radio[i].value == checkValue) {
            radio[i].checked = true;
            return;
        }
    }
}
//图片显示
function showImage(id) {
    var feature = "dialogWidth:750px;dialogHeight:500px;help:no;status:no;";
    window.showModalDialog("showImage.php?id=" + id, null, feature);
}
//图片选择
function selectPic(path) {
    var Composition = opener.document.getElementById("Composition");
    if (typeof (path) !== "undefined") {
        Composition.document.execCommand("InsertImage", false, path);
    } else {
        Composition.focus();
    }
    window.close();
}
//缩略图选择
function selectThumb(path) {
	//更改文章缩略图的图片
    var selectedThumb = opener.document.getElementById("selectedThumb");
    var imgName = opener.document.getElementById("imgName");
    selectedThumb.src = path;
    imgName.value = path;
    window.close();
}
function Setcookie(name, value) {  //设置名称为name,值为value的Cookie  
    var argc = Setcookie.arguments.length;
    var argv = Setcookie.arguments;
    document.cookie = name + "=" + value + ";path=/";
}
function Deletecookie(name) {  //删除名称为name的Cookie  
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}  
  //清除COOKIE  
function Clearcookie() {
    var temp = document.cookie.split(";");
    var loop3;
    var ts;
    for (loop3 = 0; loop3 < temp.length; loop3++) {
        ts = temp[loop3].split("=")[0];
        if ((ts.indexOf("mycat")) !== -1) {
            Deletecookie(ts);
        }
    }
}
function getCookieVal(offset) {       //取得项名称为offset的cookie值  
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr === -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie(name) {  //取得名称为name的cookie值  
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) === arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i === 0) {
            break;
        }
    }
    return null;
}
function setCookie1(menuID) {
    var menu = document.getElementById(menuID);
    if (menu.style.display != "none") {
        menu.style.display = "none";
    }
}
function initCookie() {
    var sortId = GetCookie("sort");
    if (sortId !== null && sortId !== "") {
        if (sortId.indexOf(",") == -1) {
            var menu = document.getElementById(sortId);
            if (menu.style.display != "block") {
                menu.style.display = "block";
            }
        } else {
            var sortVal = sortId.split(",");
            for (var i = 0; i < sortVal.length; i++) {
                menu = document.getElementById(sortVal[i]);
                if (menu.style.display != "block") {
                    menu.style.display = "block";
                }
            }
        }
    }
}
function newShowMenu(menuID, obj) {
    var sortId = GetCookie("sort");
    if (sortId === null || sortId === "") {
        Setcookie("sort", menuID);
        sortId = menuID;
    } else {
        if (sortId.indexOf(menuID) != -1) {
            var begin = sortId.indexOf(menuID);
            var end = begin + menuID.length;
            var subSortId1 = sortId.substring(0, begin - 1);
            if (begin === 0) {
                subSortId1 = "";
            }
            if (end == sortId.length) {
                sortId = subSortId1;
            } else {
                var subSortId2 = sortId.substring(end + 1, sortId.length);
                sortId = subSortId1 + subSortId2;
            }
            setCookie1(menuID);
            Setcookie("sort", sortId);
        } else {
            Setcookie("sort", sortId + "," + menuID);
            sortId = sortId + "," + menuID;
        }
    }
    initCookie();
}
function newShowMenu2(menuID, obj) {
    var sortId = GetCookie("sort");
    Setcookie("sort", menuID);
    showMenu(menuID, obj);
    if (sortId !== menuID) {
        if (sortId !== null || sortId !== "") {
            setCookie1(sortId);
        }
    }
    var currentid = menuID.substring(4);
    var path = null;
    var currenturl=location.pathname;
    if (currenturl.indexOf('list2') < 0) {
        path = "/product/list/";
    } else {
        path = "/product/list2/";
    }
   window.location.href="http://"+location.host + path + "/" + currentid + ".html";    
}	