﻿//JScript Document
//By Collection
//*****************************************************************************************************

// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue) {
    var date = new Date();
    date.setTime(date.getTime() + 360*1000*60*2 ) //两小时秒
    document.cookie = sName + "=" + escape(sValue) + ";path=/; expires=" + date.toGMTString();
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    // a cookie with the requested name does not exist
    return null;
}

// Delete the cookie with the specified name.
function DelCookie(sName) {
    document.cookie = sName + "=Exit; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


///查询QueryString
//parm 参数名
function QueryString(parm) {
    var url = document.location.href.split("?");
    if (url.length > 1) {
        url = url[1].split("&");
        for (i = 0; i < url.length; i++) {
            obj = url[i].split("=");
            if (obj.length > 1 && obj[0] == parm) {
                return obj[1];
            }
        }
    }
    return null;
}

//设置QueryString
//sParm 参数名
//sValue 要设置的值
//返回设置后的URL
function setQueryString(sParm, sValue) {
    var url = document.location.href.split("?");
    if (url.length > 1) {
        var parms = url[1].split("&");
        var arr = new Array();
        for (i = 0; i < parms.length; i++) {
            var s = parms[i].split("=");
            var parm = {};
            if (s.length > 0) {
                parm.name = s[0];
                parm.value = s[1];
            }
            if (parm.name == sParm) {
                parm.value = sValue;
            }
            arr[i] = parm;
        }

        url[0] += "?";
        for (j = 0; j < arr.length; j++) {
            url[0] += arr[j].name + "=" + arr[j].value + "&";
        }
        url = url[0] = url[0].substring(0, url[0].lastIndexOf("&"));
    }
    return url;
}



function addFavorite() {
    var aUrls = document.URL.split("/");
    var vDomainName = "http://" + aUrls[2] + "/";
    var description = document.title;
    try {//IE 
        window.external.AddFavorite(vDomainName, description);
    } catch (e) {//FF 
        window.sidebar.addPanel(description, vDomainName, "");
    }
}

function setHomePage() {
    var aUrls = document.URL.split("/");
    var vDomainName = "http://" + aUrls[2] + "/";
    try {//IE 
        this.style.behavior = "url(#default#homepage)";
        this.setHomePage(vDomainName);
    } catch (e) {//other 
        if (window.netscape) {//ff 
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为’true’");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vDomainName);
        }
    }
}

function keyCode(e) {
    var ff = (document.layers) ? true : false;
    var ie = (document.all) ? true : false;
    if (ff)
        return e.which;
    else if (ie)
        return e.keyCode;
}

function mousePosition(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}

function ChangeCity(c){
    var date = new Date();
    date.setTime(date.getTime() + 1000*60*60*24*15 ) //Half a mounth
    document.cookie = "City=" + escape(c) + ";path=/;expires=" + date.toGMTString();
    window.document.location = "default.aspx";
}