﻿//发送激活邮件
function SendActiveEmail(obj,CustName, EMail) {
    Ajax.call('/member/reg.aspx?act=sendemailcheck', 'CustName=' + CustName + '&EMail=' + EMail, function(data) {
        if (data.message == '发送成功') {
            $(obj).text('已经发送了一封激活邮件到您的邮箱，请在30分钟内登录并激活您的邮件地址');
        }
        else {
            $(obj).text(data.message);
        }
    }, 'post', 'json', function() {
        $(obj).text('邮件发送中，请稍候....');
    });
}

//设置输入框的提示值
function SetInputTipVal(iptId, tipVal) {
    var oldColor = $(iptId).css('color');
    $(iptId).val(tipVal).css({ color: '#999' }).focus(function () {
        if ($(this).val() == tipVal)
            $(this).val('').css({ color: oldColor });
    }).blur(function () {
        if ($(this).val() == '')
            $(this).val(tipVal).css({ color: '#999' });
    });
}

//刷新验证码
function ReloadCaptcha() {
    $('.captcha').attr('src', '/tools/captcha.aspx?'+Math.random());
}
//倒计时
function countdown(endtime, showid) {
    today = new Date();
    target_time = new Date(endtime);
    timeold = (target_time.getTime() - today.getTime());
    sectimeold = timeold / 1000;
    secondsold = Math.floor(sectimeold);
    msPerDay = 24 * 60 * 60 * 1000;
    e_daysold = timeold / msPerDay;
    daysold = Math.floor(e_daysold);
    e_hrsold = (e_daysold - daysold) * 24;
    hrsold = Math.floor(e_hrsold);
    e_minsold = (e_hrsold - hrsold) * 60;
    minsold = Math.floor(e_minsold);
    e_seconds = (e_minsold - minsold) * 60;
    seconds = Math.floor(e_seconds);
    e_millisecond = (e_seconds - seconds) * 1000;
    millisecond = Math.floor(e_millisecond);
    millisecond10 = Math.floor(millisecond / 10);

    $(showid).html("剩" + daysold + "天" + hrsold + "小时"); //" + minsold + "分" + seconds + "秒"+millisecond10+"毫秒"

    window.setTimeout("countdown('" + endtime + "' ,'" + showid + "')", 100);
}
/*添加到收藏夹*/
function addFavorite(val) {
    if (document.all) {
        window.external.addFavorite(window.location, val);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(val, window.location, "");
    }
}
/*复制url地址*/
function copyUrl() {
    var clipBoardContent = this.location.href;
    window.clipboardData.setData("Text", clipBoardContent);
    alert("复制成功!");
}
/*推荐给朋友*/
var content;
content = "";
content = "给你推荐个好东东：[title]， 赶紧去看看，网址是：";
content += location.href;
function SendToMyFriend(title) {
    content = content.replace("[title]", title);
    window.clipboardData.setData("Text", content);
    alert("已经把信息拷贝到粘贴板里面，请把内容通过即时通讯工具发送给你的好朋友广而告之。");
}
/* *
* 截取小数位数
*/
function advFormatNumber(value, num) // 四舍五入
{
    var a_str = formatNumber(value, num);
    var a_int = parseFloat(a_str);
    if (value.toString().length > a_str.length) {
        var b_str = value.toString().substring(a_str.length, a_str.length + 1);
        var b_int = parseFloat(b_str);
        if (b_int < 5) {
            return a_str;
        }
        else {
            var bonus_str, bonus_int;
            if (num == 0) {
                bonus_int = 1;
            }
            else {
                bonus_str = "0."
                for (var i = 1; i < num; i++)
                    bonus_str += "0";
                bonus_str += "1";
                bonus_int = parseFloat(bonus_str);
            }
            a_str = formatNumber(a_int + bonus_int, num)
        }
    }
    return a_str;
}
/* *
* 截取小数位数
*/
function formatNumber(value, num) // 直接去尾
{
    var a, b, c, i;
    a = value.toString();
    b = a.indexOf('.');
    c = a.length;
    if (num == 0) {
        if (b != -1) {
            a = a.substring(0, b);
        }
    }
    else {
        if (b == -1) {
            a = a + ".";
            for (i = 1; i <= num; i++) {
                a = a + "0";
            }
        }
        else {
            a = a.substring(0, b + num + 1);
            for (i = c; i <= b + num; i++) {
                a = a + "0";
            }
        }
    }
    return a;
}

//--------------------------------------------------------------------------------------------------------------------------------------------



//参数：startDate--开始日期;endDate--结束日期
//方法：分别比较日期、月份、年份的差额，根据差额进行进位，借位的计算
function DateDiff(startDate, endDate, d_type) {
    var sDate = new Date(Date.parse(startDate.replace(/-/g, "/"))); //转化成日期对象
    var eDate = new Date(Date.parse(endDate.replace(/-/g, "/")));

    //获得各自的年、月、日
    var sY = sDate.getFullYear();
    var sM = sDate.getMonth() + 1;
    var sD = sDate.getDate();
    var eY = eDate.getFullYear();
    var eM = eDate.getMonth() + 1;
    var eD = eDate.getDate();


    //var flagD = 0;   //日期标记：
    var flagM = 0;    //月份进/减位标记
    var flagY = 0;    //年份进/减位标记
    var months = 0;   //相隔约数，返回值

    var d = eD - sD;  //日期相差天数
    if (d > 0 && d >= 15)  //如果为正，且大于15天，月份进一
    {
        flagM = 1;
    }
    if (d < 0 && 30 + d < 15)  //如果为负，且相隔天数<15，月份减一
    {
        flagM = -1;
    }

    var m = eM + flagM - sM;   //相隔月数 = 结束月份 + 月份进/减位标记 - 开始月份
    if (m < 0)                    //如果小于0，年数减一，月数为12减去相隔月数
    {
        flagY = -1;
        m = 12 + m
    }

    var y = eY + flagY - sY  //相隔年数 = 结束年份 + 年份进/减位标记 - 开始年份

    if (y >= 0)                 //如果大于等于0，则返回值为年份数*12 + 月份数，否则返回0
        months = y * 12 + m
    
    if (d_type==1)
        return y;

    return months;
}

/*扩展date方法，实现日期格式化*/
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;
};

//--------------------------------------------------------------------------------------------------------------------------------------------


/* *
* 字符格式替换
*/
String.prototype.template = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function(m, i) {
        return args[i];
    });
};

//--------------------------------------------------------------------------------------------------------------------------------------------

/* *
* 鼠标点击其他地方 关闭该控件
*/
$.fn.extend({
    autoHide: function() {
        var thisObj = this;
        var div_hide_ids = arguments;
        function autoHideObj() {
            thisObj.hide();
        }
        $(document).bind("mousedown", function(e) {
            var ids = div_hide_ids;
            var ids_len = ids.length;
            var obj = thisObj;
            var objPos = obj.offset();
            var objHeight = obj.height();
            var objWidth = obj.width();

            var objOther;
            var objPosOther;
            var objHeightOther;
            var objWidthOther;

            e = e || window.event;
            var x = e.pageX || (e.clientX +
         (document.documentElement.scrollLeft
         || document.body.scrollLeft));
            var y = e.pageY || (e.clientY +
         (document.documentElement.scrollTop
         || document.body.scrollTop));
            if ((x > objPos.left && x < objPos.left + objWidth && y > objPos.top && y < objPos.top + objHeight)) {
                return true;
            }
            for (var i = 0; i < ids_len; i++) {
                objOther = $("#" + ids[i]);
                if (objOther.length) {
                    objPosOther = objOther.offset();
                    objHeightOther = objOther.height();
                    objWidthOther = objOther.width();
                    if ((x > objPosOther.left && x < objPosOther.left + objWidthOther && y > objPosOther.top && y < objPosOther.top + objHeightOther)) {
                        return true;
                    }
                }
            }
            autoHideObj();
            return true;
        });
    }
});

//--------------------------------------------------------------------------------------------------------------------------------------------

function showBirthday(val) {
    var birthdayValue;
    if (15 == val.length) { //15位身份证号码
        birthdayValue = val.charAt(6) + val.charAt(7);
        if (parseInt(birthdayValue) < 10) {
            birthdayValue = '20' + birthdayValue;
        }
        else {
            birthdayValue = '19' + birthdayValue;
        }
        birthdayValue = birthdayValue + '-' + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11);
    }
    if (18 == val.length) { //18位身份证号码
        birthdayValue = val.charAt(6) + val.charAt(7) + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11) + '-' + val.charAt(12) + val.charAt(13);
    }

    return birthdayValue;
}

//--------------------------------------------------------------------------------------------------------------------------
//checkbox变单选
$(function() {
    $(".checkbox").click(function() {
        if ($(this).attr("checked") == true) {
            var obj = $(this);
            $(".checkbox").each(function() {
                if (obj != $(this)) {
                    $(this).removeAttr("checked");
                    
                } else {
                    $(".checkbox").attr("checked", true);
                }
            });
            $($(this).attr("value")).show();
        } else {
            $(".checkbox").attr("checked", false);
            $($(this).attr("value")).hide();
        }
    });
});

//--------------------------------------------------------------------------------------------------------------------------------------------

(function(jQuery) {
    jQuery.fn.extend({
        Scroll: function(opt, callback) {
            //参数初始化
            if (!opt) var opt = {};
            var _this = this;
            var lineH = 20, //获取行高
                        line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10), //每次滚动的行数，默认为一屏，即父容器高度
                        speed = opt.speed ? parseInt(opt.speed, 10) : 500, //卷动速度，数值越大，速度越慢（毫秒）
                        timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滚动的时间间隔（毫秒）
            if (line == 0) line = 1;
            var upHeight = 0 - line * lineH;
            //滚动函数
            scrollUp = function() {
                _this.animate({
                    marginTop: upHeight
                }, "slow", function() {
                    for (i = 1; i <= line; i++) {
                        _this.find("a:first").appendTo(_this);
                    }
                    _this.css({ marginTop: 0 });
                });
            }
            var timerID
            //鼠标事件绑定
            _this.hover(function() {
                clearInterval(timerID);
            }, function() {
                timerID = setInterval("scrollUp()", timer);
            }).mouseout();
        }
    })
})(jQuery);



//--------------------------------------------------------------------------------------------------------------------------------------------


var Ajax = new Object;
/* *
* 调用此方法发送HTTP请求。
*
* @public
* @param   {string}    url             请求的URL地址
* @param   {mix}       params          发送参数
* @param   {Function}  callback        回调函数
* @param   {string}    ransferMode     请求的方式，有"GET"和"POST"两种
* @param   {string}    responseType    响应类型，有"JSON"、"XML"和"TEXT"三种
* @param   {boolean}   asyn            是否异步请求的方式
* @param   {boolean}   quiet           是否安静模式请求
*/
Ajax.call = function(url, params, callback, transferMode, responseType, beforeSend, asyn, quiet) {
    $.ajax({
        type: transferMode,
        url: url,
        data: params,
        success: callback,
        dataType: responseType.toString().toLowerCase(),
        async: asyn,
        beforeSend: beforeSend,
        cache:false,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus + "："+ errorThrown);
            // 通常 textStatus 和 errorThrown 之中
            // 只有一个会包含信息
            this; // 调用本次AJAX请求时传递的options参数
        }
    });
}


//--------------------------------------------------------------------------------------------------------------------------------------------
/* $Id : utils.js 5052 2007-02-03 10:30:13Z weberliu $ */

var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);

var Utils = new Object();

Utils.htmlEncode = function(text) {
    return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

Utils.trim = function(text) {
    return text.replace(/^\s*|\s*$/g, "");
}

Utils.isEmpty = function(val) {
    switch (typeof (val)) {
        case 'string':
            return Utils.trim(val).length == 0 ? true : false;
            break;
        case 'number':
            return val == 0;
            break;
        case 'object':
            return val == null;
            break;
        case 'array':
            return val.length == 0;
            break;
        default:
            return true;
    }
}

Utils.isNumber = function(val) {
    var reg = /^[\d|\.|,]+$/;
    return reg.test(val);
}

Utils.isInt = function(val) {
    if (val == "") {
        return false;
    }
    var reg = /\D+/;
    return !reg.test(val);
}

Utils.isNum = function(val) {
    if (val == "") {
        return false;
    }
    var reg = /^[0-9]/;
    return !reg.test(val);
}

Utils.isEmail = function(email) {
    var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;

    return reg1.test(email);
}

Utils.isUserName = function(val) {
    var re = /^[0-9a-z][\w-.]*[0-9a-z]$/i;
    if (re.test(val)) { return true; } else { return false; }
}

Utils.isTel = function(tel) {
    var reg = /^[\d|\-|\s|\_]+$/; //只允许使用数字-空格等

    return reg.test(tel);
}

Utils.isMobile = function(mobile) {
    if (/^13\d{9}$/g.test(mobile) || (/^15[0,1,2,3,4,5,6,7,8,9]\d{8}$/g.test(mobile)) || (/^18[0,1,2,3,4,5,6,7,8,9]\d{8}$/g.test(mobile)))
        return true;
    else
        return false;
}

Utils.isIDCard = function(idcard) {
    var re = /^(\d{14}|\d{17})(\d|[xX])$/;

    if (re.test(idcard)) {
        return true;
    }
    else {
        return false;
    }
}

Utils.fixEvent = function(e) {
    var evt = (typeof e == "undefined") ? window.event : e;
    return evt;
}

Utils.srcElement = function(e) {
    if (typeof e == "undefined") e = window.event;
    var src = document.all ? e.srcElement : e.target;

    return src;
}

Utils.isTime = function(val) {
    var reg = /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;

    return reg.test(val);
}








//--------------------------------------------------------------------------------------------------------------------------------------------

//+---------------------------------------------------   
//| 字符串转成日期类型    
//| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd   
//+---------------------------------------------------   
function StringToDate(DateStr) {

    var converted = Date.parse(DateStr);
    var myDate = new Date(converted);
    if (isNaN(myDate)) {
        //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';   
        var arys = DateStr.split('-');
        myDate = new Date(arys[0], --arys[1], arys[2]);
    }
    return myDate;
}





/**
* 时间对象的格式化;
*/
Date.prototype.Format = function(format) {
    /*
    * eg:format="YYYY-MM-dd hh:mm:ss";
    */
    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;
}


//time类型相加
Date.prototype.add = function(milliseconds) {
    var m = this.getTime() + milliseconds;
    return new Date(m);
};

//秒类型相加
Date.prototype.addSeconds = function(second) {
    return this.add(second * 1000);
};

//分钟类型相加
Date.prototype.addMinutes = function(minute) {
    return this.addSeconds(minute * 60);
};
//小时类型相加
Date.prototype.addHours = function(hour) {
    return this.addMinutes(60 * hour);
};

//天数相加
Date.prototype.addDays = function(day) {
    return this.addHours(day * 24);
};
//是否闰年
Date.isLeepYear = function(year) {
    return (year % 4 == 0 && year % 100 != 0)
};

//计算当月 天数
Date.daysInMonth = function(year, month) {
    if (month == 2) {
        if (year % 4 == 0 && year % 100 != 0)
            return 29;
        else
            return 28;
    }
    else if ((month <= 7 && month % 2 == 1) || (month > 7 && month % 2 == 0))
        return 31;
    else
        return 30;
};

//月类型相加法 1个月(判断是否跨年)
Date.prototype.addMonth = function() {
    var m = this.getMonth();
    if (m == 11) return new Date(this.getFullYear() + 1, 1, this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds());

    var daysInNextMonth = Date.daysInMonth(this.getFullYear(), this.getMonth() + 1);
    var day = this.getDate();
    if (day > daysInNextMonth) {
        day = daysInNextMonth;
    }
    return new Date(this.getFullYear(), this.getMonth() + 1, day, this.getHours(), this.getMinutes(), this.getSeconds());
};

//月类型减法 1个月(判断是否跨年)
Date.prototype.subMonth = function() {
    var m = this.getMonth();
    if (m == 0) return new Date(this.getFullYear() - 1, 12, this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds());

    var day = this.getDate();
    var daysInPreviousMonth = Date.daysInMonth(this.getFullYear(), this.getMonth());
    if (day > daysInPreviousMonth) {
        day = daysInPreviousMonth;
    }
    return new Date(this.getFullYear(), this.getMonth() - 1, day, this.getHours(), this.getMinutes(), this.getSeconds());
};

//月类型相加 多个月
Date.prototype.addMonths = function(addMonth) {
    var result = false;
    if (addMonth > 0) {
        while (addMonth > 0) {
            result = this.addMonth();
            addMonth--;
        }
    } else if (addMonth < 0) {
        while (addMonth < 0) {
            result = this.subMonth();
            addMonth++;
        }
    } else {
        result = this;
    }
    return result;
};

//年份加法
Date.prototype.addYears = function(year) {
    return new Date(this.getFullYear() + year, this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds());
};

//转换.net输出的时间
function NDT(dt) {
    return new Date(dt - 8 * 60 * 60 * 1000);
}


/**
* --------------------------------------------------------------------
* jQuery-Plugin "pngFix"
* Version: 1.1, 11.09.2007
* by Andreas Eberhard, andreas.eberhard@gmail.com
*                      http://jquery.andreaseberhard.de/
*
* Copyright (c) 2007 Andreas Eberhard
* Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
*/
eval(function(p, a, c, k, e, r) { e = function(c) { return (c < 62 ? '' : e(parseInt(c / 62))) + ((c = c % 62) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if ('0'.replace(0, e) == 0) { while (c--) r[e(c)] = k[c]; k = [function(e) { return r[e] || e } ]; e = function() { return '([237-9n-zA-Z]|1\\w)' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'<y \'+g+h+i+j;b+=\'9="W:X;white-space:pre-line;Y:Z-10;I:transparent;\'+k+d;b+=\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;\';b+=\'J:K:L.t.M(n=\\\'\'+3(2).7(\'n\')+\'\\\', N=\\\'O\\\');\';b+=l+\'"></y>\';p(a!=\'\'){b=\'<y 9="W:X;Y:Z-10;\'+a+d+\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;">\'+b+\'</y>\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);', [], 68, '||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'), 0, {}))