﻿$.ajax({
    url: "/SysHandler/userLoginState.ashx?id=" + Math.random(),
    //    async: true,
    success: function(t) {
    if (t != "error") {
        document.getElementById("zhuce").style.display = "none";
        document.getElementById("zhuce1").style.display = "none";
            document.getElementById("loginname").innerHTML = t;
        }
    }
});

function login() {
    var name = $("#username").val();
    var pwd = $("#userpass").val();
    $.ajax({
        url: "/SysHandler/Login.ashx?do=login&name=" + name + "&pwd=" + pwd,
        //        async: true,
        success: function(t) {
            if (t == "ok") {
                $.ajax({
                    url: "/SysHandler/userLoginState.ashx?id=" + Math.random(),
                    async: true,
                    success: function(t) {
                        if (t != "error") {
                            document.getElementById("login_last").style.display = "block";
                            document.getElementById("login_forward").style.display = "none";
                            document.getElementById("login_last_info").innerHTML = t;
                        }
                    }
                });
            } else {
                if (confirm("您的用户名或者密码错误！新用户请注册！")) {
                    location.href = "/User/Login.aspx";
                }
            }
        }
    });
}
function exit() {
    $.ajax({
        url: "/SysHandler/Login.ashx?do=exit",
        success: function(t) {
            location.href = location.href;
        }
    });
}



/*去空格*/
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

$(document).ready(function() {
    var i = location.href.indexOf('kw');
    if (i != -1) {
        $("#q").val(decodeURI(request("kw")));
    }
});

function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}
function goUrl(path) {
    var url = path + "?kw=" + encodeURI($("#q").val().trim());
    window.location.href = url;
}


function SearchObj(obj) {
    var finallUrl = window.location + "";
    if (obj == "default") {
        if (finallUrl.indexOf('--') > 0) {
            if ($('#q').val().trim() == "") {
                location.href = "../-----------------------.htm";
            } else {
                location.href = "/" + encodeURI($('#q').val().trim()) + finallUrl.substring(finallUrl.lastIndexOf('/'), finallUrl.length);
            }
        } else {
            location.href = "../" + encodeURI($('#q').val().trim()) + "/-----------------------.htm";
        }

    } else if (obj == "bizinfo") {
        if (finallUrl.indexOf('--') > 0) {
            location.href = finallUrl.substring(0, finallUrl.lastIndexOf('/') + 1) + encodeURI($('#q').val().trim()) + finallUrl.substring(finallUrl.indexOf('-'), finallUrl.length);
        } else {
            location.href = "../ProductAgent/" + encodeURI($('#q').val().trim()) + "---------------------------.htm";
        }
    }
    else if (obj == "company") {
        if (finallUrl.indexOf('--') > 0) {
            location.href = "/CompanySearch/" + encodeURI($('#q').val().trim()) + finallUrl.substring(finallUrl.indexOf('-'), finallUrl.length);
        } else {
            location.href = "/CompanySearch/" + encodeURI($('#q').val().trim()) + "--------------.htm";
        }
    } else if (obj == "exhibition") {
        location.href = "/Web2/Exhibit/ExhibitList.aspx?kw=" + encodeURI($('#q').val().trim());
    }
}


function addCookie() { // 加入收藏夹
    if (document.all) {
        try {
            window.external.addFavorite(location.href, document.title);
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    } else if (window.sidebar) {
        window.sidebar.addPanel($("title").html(), location.href, "");
    }
}

function setHomepage() { // 设置首页
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(location.href);
    } else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert(" 该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', location.url);
    }
}

