/**
 * 获取url参数
 * @param key
 */
window.location.getParam = function (key) {
    var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURIComponent(r[2]);
    }
    return null;
}
/**
 * 打开新标签
 * @param url
 */
window.location.open = function (url) {
    $("body").append($("<a id='wb-open' href='" + url + "' target='_blank' style='dispaly:none;'></a>"))
    document.getElementById("wb-open").click();
    $("#wb-open").remove();
}
/**
 * 日期格式化
 */
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
            RegExp.$1.length == 1 ? o[k] :
                ("00" + o[k]).substr(("" + o[k]).length));
    return format;
};
/**
 * 数组移除
 */
Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
/**
 * 数组替换
 */
Array.prototype.replace = function (val, obj) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1, obj);
    }
};
/**
 * 数组位置调整
 */
Array.prototype.exchange = function (val1, val2) {
    if (val1 < 0 || val2 < 0 || val2 >= this.length || val1 >= this.length) {
        return;
    }
    var o1 = this[val1];
    var o2 = this[val2];
    this.splice(val1, 1, o2);
    this.splice(val2, 1, o1);
};
