﻿//回车自动提交
jQuery(function () {
    var bt = jQuery(".keypress").attr("bt");
    jQuery(".keypress input").keypress(function (event) {
        var key_code = event.keyCode;
        if (key_code == 13) {
            jQuery("." + bt).click();
        }
    });
});

function href(v) {
    location.href = v;
}

function isNotANumber(inputData) {
    //isNaN(inputData)不能判断空串或一个空格
    //如果是一个空串或是一个空格，而isNaN是做为数字0进行处理的，而parseInt与parseFloat是返回一个错误消息，这个isNaN检查不严密而导致的。
    if (parseFloat(inputData).toString() == "NaN") {
        //alert("请输入数字……");注掉，放到调用时，由调用者弹出提示。
        return false;
    } else {
        return true;
    }
}

jQuery(function () {
    //纯数字验证开始
    jQuery(".yan1").bind("keyup", function () {
        this.value = this.value.replace(/\D/g, '');
    });
    jQuery(".yan1").bind("afterpaste", function () {
        this.value = this.value.replace(/\D/g, '')
    });
    jQuery(".yan1").bind("blur", function () {
        this.value = this.value.replace(/\D/g, '')
    });
    //纯数字验证结束
    //数字+小数点 验证开始
    jQuery(".yan2").bind("keyup", function () {
        if (isNaN(this.value)) {
            document.execCommand('undo');
        }
    });
    jQuery(".yan2").bind("afterpaste", function () {
        if (isNaN(this.value)) {
            document.execCommand('undo');
        }
    });
    jQuery(".yan2").bind("blur", function () {
        if (isNaN(this.value)) {
            this.value = "";
        }
    });
    //数字+小数点 验证结束
    //中文 验证开始
    jQuery(".yan3").bind("keyup", function () {
        this.value = this.value.replace(/[ -~]/g, '');
    });
    jQuery(".yan3").bind("afterpaste", function () {
        this.value = this.value.replace(/[ -~]/g, '');
    });
    jQuery(".yan3").bind("blur", function () {
        this.value = this.value.replace(/[ -~]/g, '');
    });
    //中文 验证结束

    //大于0的小数 验证开始
    jQuery(".yan4").bind("keyup", function () {
        this.value = this.value.replace(/\D/g, '');
        if (this.value <= 0) {
            this.value = 1;
        }
    });
    jQuery(".yan4").bind("afterpaste", function () {
        this.value = this.value.replace(/\D/g, '');
        if (this.value <= 0) {
            this.value = 1;
        }
    });
    jQuery(".yan4").bind("blur", function () {
        this.value = this.value.replace(/\D/g, '');
        if (this.value <= 0) {
            this.value = 1;
        }
    });
    //大于0的小数 验证结束
});

// <a href="javascript:void(0)" onclick="SetHome(this,window.location)">设为首页</a>
// <a href="javascript:void(0)" onclick="shoucang(document.title,window.location)">加入收藏</a>

function btdis(vs) {
    setTimeout(function () {
        $(vs).attr("disabled", "disabled").css("pointer-events", "none");;
    }, 10);
}
function btdis_clear(vs) {
    setTimeout(function () {
        $(vs).removeAttr("disabled").css("pointer-events", "auto");;
    }, 10);
}

// 设置为主页 
function SetHome(obj) {
    var vrl = window.location;
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            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', vrl);
        } else {
            alert("您的浏览器不支持，请按照下面步骤操作：1.打开浏览器设置。2.点击设置网页。3.输入：" + vrl + "点击确定。");
        }
    }
}
// 加入收藏 兼容360和IE6 
function shoucang() {
    var sTitle = document.title;
    var sURL = window.location;
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

jQuery(function () {
    jQuery("input[type='text'],input[type='password'],input[type='tel'],input[type='number'],textarea").focus(function () {
        jQuery(".fixed").hide();
    });
    jQuery("input[type='text'],input[type='password'],input[type='tel'],input[type='number'],textarea").blur(function () {
        jQuery(".fixed").show();
    });
});

jQuery(function () {
    jQuery(".dheight").height(jQuery(document).height());
});

function tx(pos) {
    $(".tx_right").hide().removeClass("animated fadeInRight");
    $(".tx_bottom").hide().removeClass("animated fadeInDown");
    $(".tx_top").hide().removeClass("animated fadeInUp");
    $(".tx_left").hide().removeClass("animated fadeInLeft");
    $(".tx_flip").hide().removeClass("animated flip");
    $(".tx_wu").hide();

    var mycars = new Array(
        "shake",
        "flash",
        "swing",
        "bounce",
        "tada",
        "wobble",
        "pulse",
        "flip",
        "flipInX",
        "flipOutX",
        "flipInY",
        "flipOutY",
        "fadeIn",
        "fadeInUp",
        "fadeInDown",
        "fadeInLeft",
        "fadeInRight",
        "fadeInUpBig",
        "fadeInDownBig",
        "fadeInLeftBig",
        "fadeInRightBig",
        "fadeOut",
        "fadeOutUp",
        "fadeOutDown",
        "fadeOutLeft",
        "fadeOutRight",
        "fadeOutUpBig",
        "fadeOutDownBig",
        "fadeOutLeftBig",
        "fadeOutRightBig",
        "slideInDown",
        "slideInLeft",
        "slideInRight",
        "slideOutUp",
        "slideOutLeft",
        "slideOutRight",
        "bounceIn",
        "bounceInDown",
        "bounceInUp",
        "bounceInLeft",
        "bounceInRight",
        "bounceOut",
        "bounceOutDown",
        "bounceOutUp",
        "bounceOutLeft",
        "bounceOutRight",
        "rotateIn",
        "rotateInDownLeft",
        "rotateInDownRight",
        "rotateInUpLeft",
        "rotateInUpRight",
        "rotateOut",
        "rotateOutDownLeft",
        "rotateOutDownRight",
        "rotateOutUpLeft",
        "rotateOutUpRight",
        "lightSpeedIn",
        "lightSpeedOut",
        "hinge",
        "rollIn",
        "rollOut"
    );
    for (var mycars_i = 0; mycars_i < mycars.length; mycars_i++) {
        var dq_de_zhi = mycars[mycars_i];
        $(".tx_" + dq_de_zhi).hide().removeClass("animated " + dq_de_zhi + "");
    }

    setTimeout(function () {
        jindu(pos, ".tx_right", "animated fadeInRight");
        jindu(pos, ".tx_bottom", "animated fadeInDown");
        jindu(pos, ".tx_top", "animated fadeInUp");
        jindu(pos, ".tx_left", "animated fadeInLeft");
        jindu(pos, ".tx_flip", "animated flip");
        jindu(pos, ".tx_wu", "");

        for (var mycars_i = 0; mycars_i < mycars.length; mycars_i++) {
            var dq_de_zhi = mycars[mycars_i];
            jindu(pos, ".tx_" + dq_de_zhi + "", "animated " + dq_de_zhi + "");
        }
    });
}

function jindu(pos, s1, s2) {
    $(".myHtmlAreaClass").eq(pos).find(s1).each(function () {
        var dq_this = $(this);
        var miao = dq_this.attr("miao");
        if (typeof (miao) != "undefined" && typeof (miao) != "") {
            setTimeout(function () {
                dq_this.show().addClass(s2);
            }, miao);
        } else {
            dq_this.show().addClass(s2);
        }
    });
}

function chkEmail(strEmail) {
    if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(strEmail)) {
        return false;
    }
    else {
        return true;
    }
}

$(function () {
    $(".placeholder").each(function () {
        var valuea = $(this).val();

        $(this).bind("focus", function () {
            if (this.value == valuea) { this.value = ''; }
        });
        $(this).bind("blur", function () {
            if (this.value == '') { this.value = valuea; }
        });
    });
});

function wx_fx() {
    jQuery(function () {
        jQuery.post("/ajax/signature.aspx?appid=" + escape(_appid) + "&timestamp=" + escape(_timestamp) + "&nonceStr=" + escape(_nonceStr) + "&url=" + escape(_url) + "&cache=" + Math.random(), function (data) {
            _signature = data;
            jQuery.getScript("/js/jweixin-1.0.0.js");
            jQuery.getScript("/js/wx_fx.js?sj=" + nyrsfm);
        });
    });
}

$(function () {
    $("input[type=date]").each(function () {
        if ($(this).val().length > 0) {
            $(this).addClass("full");
        }
        else {
            $(this).removeClass("full");
        }
    });
    $("input[type=date]").on("input", function () {
        if ($(this).val().length > 0) {
            $(this).addClass("full");
        }
        else {
            $(this).removeClass("full");
        }
    });
});

//除法 //防止丢失精度
function acc_chu(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""))
        r2 = Number(arg2.toString().replace(".", ""))
        return accMul((r1 / r2), pow(10, t2 - t1));
    }
}
//乘法  //防止丢失精度
function acc_cheng(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//加法    //防止丢失精度
function acc_jia(arg1, arg2) {
    var r1, r2, m;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2))
    return (arg1 * m + arg2 * m) / m
}
//减法    //防止丢失精度
function acc_jian(arg1, arg2) {
    var r1, r2, m, n;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2));
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

//设置cookie
function setCookie(name, value, iDay) {  //传值为名，值，过期时间
    if (iDay) { //如果有过期时间的话则执行这个条件

        var oDate = new Date(); //获取当且的事件戳

        oDate.setDate(oDate.getDate() + iDay); //设置过期事件

        document.cookie = name + "=" + value + "; path=/; expires=" + oDate;//设置cookie

    } else {//如果有过期时间的话则执行这个条件 设置cookie
        document.cookie = name + "=" + value + "; path=/"; //名，值以及根目录
    }

}

//获取cookie值
function getCookie(name) {

    var arr1 = document.cookie.split("; ");  //获取cookie值并且用”； “来进行切割成数组

    for (var i = 0; i < arr1.length; i++) {  //循环本数组

        var arr2 = arr1[i].split("="); //再次利用split（）方法进行切割为二维数组

        if (arr2[0] == name) {  //循环二维数组，当第一个值为你所传的值则返回本数组的第二个值

            return arr2[1];

        }

    }

    return " ";

}

//删除cookie 
function removeCookie(name) {
    setCookie(name, "1234", -1);  //再次调用setCookie,关键是把过期时间设置为负值
}

//获取URL 字段
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}