﻿/*
通用窗口加载时事件
*/
function allPageOnload() {
    //设置关键字
    setSkw(window.location.search);

    if (document.getElementById("__service_panel") != null)
        document.getElementById("__service_panel").style.display = "none";

}


//分类导航
function menuFix() {
    if (document.getElementById("nav") != null) {
        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 ? " " : "") + "show";
            }
            sfEls[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp("( ?|^)show\\b"), "");
            }
        }
    }
}

function setViewItem() {
    //隐藏已查看产品
    if (getCookie('VGoods') == '') {
        if (document.getElementById("viewItem") != null)
            document.getElementById("viewItem").className = 'hide';
    }
}

/************************************/

/*
显示分类
*/

function showCat() {
    var li = document.getElementById("catLi");
    li.className += (li.className.length > 0 ? ' ' : '') + 'show';
    var container = document.getElementById("container");

    var allCat = document.getElementById("allCat");

    //判断IE版本
    var browser = navigator.appName
    var b_version = navigator.appVersion
    var version = b_version.split(";");
    var trim_Version = version[1].replace(/[ ]/g, "");
    if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
        allCat.style.left = container.offsetLeft - 1 + "px";
    }
    else {
        allCat.style.left = container.offsetLeft + "px";
    }
    allCat.style.display = "block";
}
function hideCat(li) {
    var li = document.getElementById("catLi");
    li.className = li.className.replace(new RegExp('( ?|^)show\\b'), '');
    var allCat = document.getElementById("allCat");
    allCat.style.display = "none";
}
/************************************/

/**
*添加收藏
**/
function favorite(URL, title) {
    try {
        window.external.addFavorite(URL, title);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(title, URL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
/************************************/

/**
*设置欢迎语句
**/
function SetWText(sessionId) {
    var LoginSessionID = getCookie("SSC_SessionID");
    var CurrentSessionID = sessionId;

    if (LoginSessionID == CurrentSessionID) {
        var cookieValue = getCookie("SSC_Uid");
    }

    var WTextSpan = document.getElementById("WText");
    if (cookieValue != null && cookieValue != "") {
        var uname = getCookie("SSC_UserName");
        if (uname)
            WTextSpan.innerHTML = uname + ", Welcome to Grandmade！ <a href='/cleansession.aspx' style=' text-decoration:none;'>Log out</a>"
        else {
            WTextSpan.innerHTML = " Welcome to Grandmade！ <a href='/cleansession.aspx' style=' text-decoration:none;'>Log out</a>"
        }
        document.getElementById("hSignin").style.display = "none";
    }
    else {
        WTextSpan.innerHTML = " Not a Member yet ? <a href='/Register.aspx'>Join Us !</a>";
    }
}

/************************************/

/*
已看产品
*/
function hasViewGoods() {
    if (getCookie("VGoods") != "")
        return true;
    else
        return false;
}


/************************************/


/*
用途：cookie操作
输入：cookie名字
返回：
*/
function getCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        var c = document.cookie;
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}

function setCookie(cookieName, cookieValue, DayValue) {
    var expire = "";
    var day_value = 1;
    if (DayValue != null) {
        day_value = DayValue;
    }
    expire = new Date((new Date()).getTime() + day_value * 86400000);
    expire = "; expires=" + expire.toGMTString();
    document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/" + expire;
}

function delCookie(cookieName) {
    var expire = "";
    expire = new Date((new Date()).getTime() - 1);
    expire = "; expires=" + expire.toGMTString();
    document.cookie = cookieName + "=" + escape("") + ";path=/" + expire;
}
/************************************/

/**
*搜索,设置关键字
**/
function search() {
    var obj = document.getElementById("txtSearch");
    //if (obj.value == "关键字")
    //    obj.value = "";
    var catSelect = document.getElementById("selCat");
    var currenSelect = catSelect.options[catSelect.selectedIndex];

    if (currenSelect.value == "0")
        window.location.href = '/list.aspx?kw=' + encodeURI(obj.value);
    else {
        window.location.href = '/list_1_' + currenSelect.value + '_0_0_0-10000_' + encodeURI(obj.value) + '_.aspx';
    }
}

function footsearch() {
    var obj = document.getElementById("txtFootSearch");
    //if (obj.value == "关键字")
    //    obj.value = "";
    var catSelect = document.getElementById("selFootCat");
    var currenSelect = catSelect.options[catSelect.selectedIndex];

    if (currenSelect.value == "0")
        window.location.href = '/list.aspx?kw=' + encodeURI(obj.value);
    else {
        window.location.href = '/list_1_' + currenSelect.value + '_0_0_0-10000_' + encodeURI(obj.value) + '_.aspx';
    }
}

function setSkw(url) {
    var kw = getQuery("kw", url);

    if (kw != null && kw != "") {
        var obj = document.getElementById("txtSearch");
        obj.value = kw;
        obj = document.getElementById("txtFootSearch");
        obj.value = kw;
        
        var cid = getQuery("ParTypeID", url);
        var catSelect = document.getElementById("selCat");
        //下拉列表
        for (j = 0; j < catSelect.options.length; j++) {
            if (catSelect.options[j].value == cid) {
                catSelect.options[j].selected = true;
            }
        }
        catSelect = document.getElementById("selFootCat");
        //下拉列表
        for (j = 0; j < catSelect.options.length; j++) {
            if (catSelect.options[j].value == cid) {
                catSelect.options[j].selected = true;
            }
        }


    } else {
        kw = Q("kw");
        if (kw != null && kw != "") {
            var obj = document.getElementById("txtSearch");
            obj.value = kw;
            obj = document.getElementById("selFootCat");
            obj.value = kw;
        }
    }

    return;

}

/**
*获取参数，若只有一个参数会出错。
**/
function getQuery(name, UrlStr) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var url = decodeURI(UrlStr);
    var r = url.match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

/**
*直接获取参数，可处理一个参数的情况。
**/
function Q() {
    var Url = top.window.location.href;
    var u, g, StrBack = '';
    if (arguments[arguments.length - 1] == "#")
        u = Url.split("#");
    else
        u = Url.split("?");
    if (u.length == 1) g = '';
    else g = u[1];
    if (g != '') {
        gg = g.split("&");
        var MaxI = gg.length;
        str = arguments[0] + "=";
        for (i = 0; i < MaxI; i++) {
            if (gg[i].indexOf(str) == 0) {
                StrBack = gg[i].replace(str, "");
                break;
            }
        }
    }
    return StrBack;
}


/************************************/

/**
*修改Url参数值
**/
function changeURLPar(destiny, par, par_value) {
    var pattern = par + '=([^&]*)';
    var replaceText = par + '=' + par_value;

    if (destiny.match(pattern)) {
        var tmp = '/\\' + par + '=[^&]*/';
        tmp = destiny.replace(eval(tmp), replaceText);
        return (tmp);
    }
    else {
        if (destiny.match('[\?]')) {
            return destiny + '&' + replaceText;
        }
        else {
            return destiny + '?' + replaceText;
        }
    }

    return destiny + '\n' + par + '\n' + par_value;
}
/************************************/

var BigInter;
var SmallInter;



/**
*元素高度收缩
**/

/**
*-id:目标对象ID
*-maxHeight:最大高度
*-numInter:每次移动像素
**/
function toMaxHeight(id, maxHeight, numInter) {
    //间隔时间
    var InterTime = 1;

    clearInterval(SmallInter);
    clearInterval(BigInter);
    BigInter = setInterval(function() { MaxHeight(id, maxHeight, numInter); }, InterTime);
}

/**
*-id:目标对象ID
*-maxHeight:最大高度
*-numInter:每次移动像素
**/
function MaxHeight(id, maxHeight, numInter) {
    //目标对象
    var o = document.getElementById(id);
    //初始数值
    var i = parseInt(o.clientHeight);

    if (parseInt(o.clientHeight) < maxHeight) {
        i = parseInt(o.clientHeight);
        i += numInter;
        o.style.height = i + "px";
    } else {
        clearInterval(BigInter);
    }
}



/**
*-id:目标对象ID
*-minHeight:最小高度
*-numInter:每次移动像素
**/
function toMinHeight(id, minHeight, numInter) {
    //间隔时间
    var InterTime = 1;

    clearInterval(SmallInter);
    clearInterval(BigInter);
    SmallInter = setInterval(function() { MinHeight(id, minHeight, numInter); }, InterTime);
}

/**
*-id:目标对象ID
*-minHeight:最小高度
*-numInter:每次移动像素
**/
function MinHeight(id, minHeight, numInter) {
    //目标对象
    var o = document.getElementById(id);
    //初始数值
    var i = parseInt(o.clientHeight);

    if (parseInt(o.clientHeight) > minHeight) {
        i = parseInt(o.clientHeight);
        i -= numInter;
        if (i < 0)
            i = 0;
        o.style.height = i + "px";

    } else {
        clearInterval(SmallInter);
    }
}

/**
*元素宽度收缩
**/

/**
*-id:目标对象ID
*-maxWidth:最大宽度
*-numInter:每次移动像素
**/
function toMaxWidth(id, maxWidth, numInter) {
    //间隔时间
    var InterTime = 1;

    clearInterval(SmallInter);
    clearInterval(BigInter);
    BigInter = setInterval(function() { MaxWidth(id, maxWidth, numInter); }, InterTime);
}

/**
*-id:目标对象ID
*-maxHeight:最大宽度
*-numInter:每次移动像素
**/
function MaxWidth(id, maxWidth, numInter) {
    //目标对象
    var o = document.getElementById(id);
    //初始数值
    var i = parseInt(o.clientWidth);

    if (parseInt(o.clientWidth) < maxWidth) {
        i = parseInt(o.clientWidth);
        i += numInter;
        o.style.width = i + "px";
    } else {
        clearInterval(BigInter);
    }
}



/**
*-id:目标对象ID
*-minWidth:最小宽度
*-numInter:每次移动像素
**/
function toMinWidth(id, minWidth, numInter) {
    //间隔时间
    var InterTime = 1;

    clearInterval(SmallInter);
    clearInterval(BigInter);
    SmallInter = setInterval(function() { MinWidth(id, minWidth, numInter); }, InterTime);
}

/**
*-id:目标对象ID
*-minWidth:最小宽度
*-numInter:每次移动像素
**/
function MinWidth(id, minWidth, numInter) {
    //目标对象
    var o = document.getElementById(id);
    //初始数值
    var i = parseInt(o.clientWidth);

    if (parseInt(o.clientWidth) > minWidth) {
        i = parseInt(o.clientWidth);
        i -= numInter;
        if (i < 0)
            i = 0;
        o.style.width = i + "px";

    } else {
        clearInterval(SmallInter);
    }
}

/************************************/

/*
用途：加载中
输入：加载文字
返回：
*/
function Loading(text) {
    LoaddingShow("<div style=\"background:url(/templets/common/images/loading.gif) no-repeat 4px 0;\">" + text + "</div>");
}
function cLoading() {
    LoaddingClose();
}
/************************************/

