﻿

Array.prototype.objCount = function(c) { return c; }

String.prototype.format = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function(m, i) {
        return args[i];
    });
}


String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }

    return str;
}

function $get() { return document.getElementById(arguments[0]); }

function pagerDelegate(obj, method, mode) {
    var delegate = function() {
        var args = [];
        args.push(mode);
        method.apply(obj, args);
    }

    return delegate;
}


function msg(a) { }





function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function copyUrl() {
    var clipBoardContent = this.location.href;
    window.clipboardData.setData("Text", clipBoardContent);
    alert("复制成功!");
}
function copyUrlText(url) {
    var clipBoardContent = url;

    window.clipboardData.setData("Text", clipBoardContent);
    alert("复制成功!");
}
function toUrlByPagerNum(num, urlparm, pageurl) {

    if (parseInt(num) > 0) {
        window.location.href = pageurl + "?page=" + num + urlparm;

    }
}

function toUrlByParm(urlparm, url) {

    if (urlparm != "" && urlparm != "请输入关键字内容") {
        window.location.href = url + "?keyword=" + encodeURI(urlparm);

    }
}

function Login() {
    var website = window.location.href;
    if (arguments.length > 0)
    { ymPrompt.win({ message: '/simlogin.aspx?refer=' + website, width: 649, height: 418, title: '登录', iframe: true, titleBar: false }) }
    else { ymPrompt.win({ message: '/simlogin.aspx?refer=' + website, width: 649, height: 418, title: '登录', iframe: true }) }


}

function Logout() {
    $.getJSON(
            "/Service/register.ashx", { type: "logout" },
            function(json) {
                $("#loginEx").show();
                $("#loginEx").html("<a href=\"javascript:void(0);\" onclick=\"Login();\">立即登录</a> | <a href=\"javascript:void(0);\" onclick=\"Login();\">注册新用户</a> | <div style=\"width:128px; background: url(/images/sina.png) no-repeat; position:absolute;  height:26px\"><a href=\"javascript:void(0);\" onclick=\"ymPrompt.win({ message: '/sinaweibo.aspx', width: 649, height: 418, title: '登录', iframe: true });\" style=\"color: White;\">&nbsp;&nbsp;&nbsp;用微博帐号登录</a></div>");
                $("#login").hide();
                $("#login_r").hide();
                $("#headmsg").hide();
            });
}


function selectAll(name) {
    $("input[name='" + name + "']").each(function() {
        $(this).attr("checked", true);
    });
}
function deselectAll(name) {
    $("input[name='" + name + "']").each(function() {
        if ($(this).attr("checked"))
            $(this).attr("checked", false);
        else
            $(this).attr("checked", true);
    });
}
function selectedItem(name) {
    var idarr = "";
    var re = /^(\+|-)?\d+$/;
    $("input[name='" + name + "']").each(function() {
        if ($(this).attr("checked")) {
            if (re.test($(this).val()))
                idarr += $(this).val() + ",";
        }
    });
    if (idarr == "") {
        alert("请至少选择一个操作项！");
        return;
    }
    return idarr;
}

function searchPriduct() {
    if ($("#keyword").val() == "") {
        alert("请填写关键字！");
        return false;
    }

    searchform.submit();     
}
