/*
ET.js 版本 v2
*/
window.ETool = new Object(); //全局变量ETool
ETool.build = function (fullNS) {
    var nsArr = fullNS.split(".");
    var sEval = "";
    var sNS = "";
    for (var i = 0; i < nsArr.length; i++) {
        if (i != 0) sNS += ".";
        sNS += nsArr[i];
        // 依次创建构造命名空间对象（假如不存在的话）的语句
        sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = {};"
    }
    if (sEval != "") eval(sEval);
};  //end
//ETool.bulid()构造命名空间对象，目的是减少重复率
//ETool.build("ET.Kas");    //调用举例
/*2011.11重构 内容来自base.js
	var etshop = {
		base: "http://localhost:8080",
		currencySign: "￥",// 货币符号
		currencyUnit: "元",// 货币单位
		priceScale: "2",// 商品价格精确位数
		priceRoundType: "roundHalfUp",// 商品价格精确方式
		orderScale: "2",// 订单金额精确位数
		orderRoundType: "roundHalfUp"// 订单金额精确方式
	};
	// 浮点数加法运算
	function floatAdd(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 floatSub(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);
	}
	
	// 浮点数乘法运算
	function floatMul(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 floatDiv(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 (r1 / r2) * pow(10, t2 - t1);
		}
	}
	
	// 设置数值精度
	function setScale(value, scale, roundingMode) {
		if (roundingMode.toLowerCase() == "roundhalfup") {
			return (Math.round(value * Math.pow(10, scale)) / Math.pow(10, scale)).toFixed(scale);
		} else if (roundingMode.toLowerCase() == "roundup") {
			return (Math.ceil(value * Math.pow(10, scale)) / Math.pow(10, scale)).toFixed(scale);
		} else {
			return (Math.floor(value * Math.pow(10, scale)) / Math.pow(10, scale)).toFixed(scale);
		}
	}
	
	// 格式化商品价格货币
	function priceCurrencyFormat(price) {
		price = setScale(price, etshop.priceScale, etshop.priceRoundType);
		return etshop.currencySign + price;
	}
	
	// 格式化商品价格货币（包含货币单位）
	function priceUnitCurrencyFormat(price) {
		price = setScale(price, etshop.priceScale, etshop.priceRoundType);
		return etshop.currencySign + price + etshop.currencyUnit;
	}
	
	// 格式化订单金额货币
	function orderCurrencyFormat(price) {
		price = setScale(price, etshop.orderScale, etshop.orderRoundType);
		return etshop.currencySign + price;
	}
	
	// 格式化订单金额货币（包含货币单位）
	function orderUnitCurrencyFormat(price) {
		price = setScale(price, etshop.orderScale, etshop.orderRoundType);
		return etshop.currencySign + price + etshop.currencyUnit;
	}
2011.11重构 内容来自base.js end*/





/*
$.ET.xxx();

常用静态型 工具类方法  v0.5.4
“静态型”这些方法调用次数为“1”次，不返回this，即$.ET.funA();$.ET.funB();
“动态型”这些方法调用次数不限，即$().funA().funA().funA();
*/
(function ($) {
    $.extend({ ET: {} });
    var tools = {
        alert: function (a) {
            /*
            a.msg   提示内容
            a.delay     延时关闭
            a.left      指定位置 必须成对出现
            a.top
            a.w	 a.h
            a.css     class名 不带点
            a.type
            a.ok,a.okCallback
            a.cancel,a.cancelCallback
            */
            if (typeof (a) == "object") {
                var cid = "alert" + this.random(5);
                var $cid = "div." + cid;
                var strTitle = "";
                if (a.title != null) strTitle = "<div class='title'>" + a.title + "</div>";
                if (a.type == null) a.type = "warn";
                $("<div>"
                	+ "<div class='ETalert'><div class='r0'>"
                		+ "<div class='bg_top'><div class='r'></div></div>"
                		+ "<div class='abody'>"
                			+ "<div class='" + a.type + "'></div>"
                			+ "<div class='msg'>"
                				+ strTitle
                				+ "<div>" + a.msg + "</div>"
                			+ "</div>"
                            +"<div style='clear:both;'></div>"
                		+ "</div>"
                		+ "<div class='bg_foot'><div class='r'></div></div>"
                	+ "</div></div>"
                + "</div>")
                    .attr('class', cid + " ETalertBorder")
                    .css("position", "absolute")
                    .css("z-index", this.maxzindex())
                    .appendTo("body");
                if (a.css != "undefined")
                    $($cid + " .ETalert").addClass(a.css);
                if (a.w != null)
                    $($cid + " .ETalert").css("width", a.w);
                if (a.h != null)
                    $($cid + " .ETalert").css("height", a.h);
                $($cid + " .ETalert .msg").css("width", $($cid + " .abody").outerWidth() - 65 - 20);
                $($cid + " .ETalert .bg_foot").before("<div class='btns'></div>");
                if (a.ok != null) {
                    $("<span class='btn ok'><input class='r' name='' type='button' value='" + a.ok + "'/></span>").appendTo($cid + " .btns");
                    $($cid + " .btns .ok").click(function () {
                        thisOkCallBack();
                    });
                }
                if (a.cancel != null) {
                    $("<span class='btn cancel'><input class='r' name='' type='button' value='" + a.cancel + "'/></span>").appendTo($cid + " .btns");
                    $($cid + " .btns .cancel").click(function () {
                        thisCancelCallBack();
                    });
                }
                if (a.left && a.top) {
                    $($cid).css("left", a.left).css("top", a.top);
                } else {
                    this.center($cid);
                }
                if ($.browser.msie && $.browser.version == "6.0") {
                    $("<iframe class=\"ifrie" + cid + "\"></iframe>")
                        .css("position", "absolute")
                        .css("z-index", this.maxzindex() - 1)
                        .appendTo("body")
                        .css("width", $($cid + " .ETalert").width())
                        .css("height", $($cid + " .ETalert").height());
                    this.center('.ifrie' + cid);
                }
                if (a.delay == null) {
                    if (a.ok != null || a.cancel != null) a.delay = -1;
                }
                a.delay = a.delay || 1500;
                if (a.delay > 0) {
                    var oTime = parseInt(a.delay / 1000);
                    if (a.cancel != null) {
                        var oVal = $($cid + " .cancel input").val();
                        window.setInterval(function () {
                            oTime--;
                            $($cid + " .cancel input").val(oVal + "(" + oTime + ")");
                        }, 1000);

                        window.setTimeout(function () {
                            thisCancelCallBack();
                            $($cid).fadeOut(1000).remove();
                        }, a.delay);
                    } else {
                        var oVal = $($cid + " .ok input").val();
                        window.setInterval(function () {
                            oTime--;
                            $($cid + " .ok input").val(oVal + "(" + oTime + ")");
                        }, 1000);

                        window.setTimeout(function () {
                            thisOkCallBack();
                            $($cid).fadeOut(1000).remove();
                        }, a.delay);
                    }
                }

            } else if (typeof (a) == "undefined") {
                alert("请提供参数查看!");
            } else if (typeof (a) == "string") {
                alert(a);
            }

            //functions
            function thisOkCallBack() {
                if ($.isFunction(a.okCallback)) {
                    if (a.okCallback.apply() != false) {
                        $($cid).fadeOut(1000).remove();
                        return true;
                    }
                } else {
                    $($cid).fadeOut(1000).remove();
                    return true;
                }
            }
            function thisCancelCallBack() {
                if ($.isFunction(a.cancelCallback)) {
                    if (a.cancelCallback.apply() != false) {
                        $($cid).fadeOut(1000).remove();
                        return false;
                    }
                } else {
                    $($cid).fadeOut(1000).remove();
                    return false;
                }
            }
        }, //alert() end
        center: function (obj) {
            var h = 0, w = 0;
            if ($(document).height() <= $(window).height()) {
                h = ($(window).height() - $(obj).outerHeight()) / 2;
            } else {
                h = $(document).scrollTop() + ($(window).height() / 2) - ($(obj).outerHeight() / 2);
            }
            w = ($(window).width() - $(obj).width()) / 2;
            $(obj).css("top", h).css("left", w);
        }, //center() end 
        hello: function () { alert('hello'); },
        random: function (a) {
            if (typeof (a) == "undefined") { a = 4; }
            var n = "9";
            for (var i = 1; i < a; i++) { n = n + "9"; }
            return Math.floor(Math.random() * n);
        },
        gotop: function (o) {
            if (typeof (o) != "object") { alert("参数应该是用{}传递的对象！"); return; }
            $(o.id).css("position", "absolute")
                    .css("display", "none")
                    .css("z-index", this.maxzindex() + 1);
            var top = o.top || 0;
            $(window).bind("scroll resize", function () {
                if (o.where == "right" && o.width) {
                    $(o.id).css("left", $(document).width() - ($(document).width() - o.width) / 2);
                }
                $(o.id + " span").html($(document).scrollTop() + "|" + top); //投产不需要此行
                var docTop = parseInt($(document).scrollTop());
                if (docTop < parseInt(top)) { $(o.id).hide(); } else { $(o.id).show() }
                $(o.id).animate({ top: (parseInt(top) + parseInt(docTop)) + "px" }, { duration: 600, queue: false });
            });
        },
        maxzindex: function (str) {
            var n = 0;
            if (arguments.length == 0) str = "div";
            $(str).each(function () {
                var z = $(this).css("z-index");
                if (z != "auto" && parseInt(z) > n)
                    n = z;
            });
            if (n == "auto") n = 0;
            return n;
        },
        alignheight: function () {
            var currentTallest = 0;
            var length = arguments.length;
            var tmp_obj, tmp_height;
            for (i = 0; i < length; i++) {
                currentTallest = Math.max(currentTallest, $(arguments[i]).outerHeight());
            }

            for (i = 0; i < length; i++) {
                tmp_obj = $(arguments[i]);
                tmp_obj.css({ 'height': currentTallest - (tmp_obj.outerHeight() - tmp_obj.height()) });
            }
        },
        md5: function (a) {
            var hex_chr = "0123456789abcdef";
            function rhex(num) {
                str = "";
                for (j = 0; j <= 3; j++)
                    str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * 8)) & 0x0F);
                return str;
            }
            function str2blks_MD5(str) {
                nblk = ((str.length + 8) >> 6) + 1;
                blks = new Array(nblk * 16);
                for (i = 0; i < nblk * 16; i++) blks[i] = 0;
                for (i = 0; i < str.length; i++)
                    blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
                blks[i >> 2] |= 0x80 << ((i % 4) * 8);
                blks[nblk * 16 - 2] = str.length * 8;
                return blks;
            }
            function add(x, y) {
                var lsw = (x & 0xFFFF) + (y & 0xFFFF);
                var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
                return (msw << 16) | (lsw & 0xFFFF);
            }
            function rol(num, cnt) {
                return (num << cnt) | (num >>> (32 - cnt));
            }
            function cmn(q, a, b, x, s, t) {
                return add(rol(add(add(a, q), add(x, t)), s), b);
            }
            function ff(a, b, c, d, x, s, t) {
                return cmn((b & c) | ((~b) & d), a, b, x, s, t);
            }
            function gg(a, b, c, d, x, s, t) {
                return cmn((b & d) | (c & (~d)), a, b, x, s, t);
            }
            function hh(a, b, c, d, x, s, t) {
                return cmn(b ^ c ^ d, a, b, x, s, t);
            }
            function ii(a, b, c, d, x, s, t) {
                return cmn(c ^ (b | (~d)), a, b, x, s, t);
            }
            function MD5(str) {
                x = str2blks_MD5(str);
                var a = 1732584193;
                var b = -271733879;
                var c = -1732584194;
                var d = 271733878;
                for (i = 0; i < x.length; i += 16) {
                    var olda = a;
                    var oldb = b;
                    var oldc = c;
                    var oldd = d;
                    a = ff(a, b, c, d, x[i + 0], 7, -680876936);
                    d = ff(d, a, b, c, x[i + 1], 12, -389564586);
                    c = ff(c, d, a, b, x[i + 2], 17, 606105819);
                    b = ff(b, c, d, a, x[i + 3], 22, -1044525330);
                    a = ff(a, b, c, d, x[i + 4], 7, -176418897);
                    d = ff(d, a, b, c, x[i + 5], 12, 1200080426);
                    c = ff(c, d, a, b, x[i + 6], 17, -1473231341);
                    b = ff(b, c, d, a, x[i + 7], 22, -45705983);
                    a = ff(a, b, c, d, x[i + 8], 7, 1770035416);
                    d = ff(d, a, b, c, x[i + 9], 12, -1958414417);
                    c = ff(c, d, a, b, x[i + 10], 17, -42063);
                    b = ff(b, c, d, a, x[i + 11], 22, -1990404162);
                    a = ff(a, b, c, d, x[i + 12], 7, 1804603682);
                    d = ff(d, a, b, c, x[i + 13], 12, -40341101);
                    c = ff(c, d, a, b, x[i + 14], 17, -1502002290);
                    b = ff(b, c, d, a, x[i + 15], 22, 1236535329);
                    a = gg(a, b, c, d, x[i + 1], 5, -165796510);
                    d = gg(d, a, b, c, x[i + 6], 9, -1069501632);
                    c = gg(c, d, a, b, x[i + 11], 14, 643717713);
                    b = gg(b, c, d, a, x[i + 0], 20, -373897302);
                    a = gg(a, b, c, d, x[i + 5], 5, -701558691);
                    d = gg(d, a, b, c, x[i + 10], 9, 38016083);
                    c = gg(c, d, a, b, x[i + 15], 14, -660478335);
                    b = gg(b, c, d, a, x[i + 4], 20, -405537848);
                    a = gg(a, b, c, d, x[i + 9], 5, 568446438);
                    d = gg(d, a, b, c, x[i + 14], 9, -1019803690);
                    c = gg(c, d, a, b, x[i + 3], 14, -187363961);
                    b = gg(b, c, d, a, x[i + 8], 20, 1163531501);
                    a = gg(a, b, c, d, x[i + 13], 5, -1444681467);
                    d = gg(d, a, b, c, x[i + 2], 9, -51403784);
                    c = gg(c, d, a, b, x[i + 7], 14, 1735328473);
                    b = gg(b, c, d, a, x[i + 12], 20, -1926607734);
                    a = hh(a, b, c, d, x[i + 5], 4, -378558);
                    d = hh(d, a, b, c, x[i + 8], 11, -2022574463);
                    c = hh(c, d, a, b, x[i + 11], 16, 1839030562);
                    b = hh(b, c, d, a, x[i + 14], 23, -35309556);
                    a = hh(a, b, c, d, x[i + 1], 4, -1530992060);
                    d = hh(d, a, b, c, x[i + 4], 11, 1272893353);
                    c = hh(c, d, a, b, x[i + 7], 16, -155497632);
                    b = hh(b, c, d, a, x[i + 10], 23, -1094730640);
                    a = hh(a, b, c, d, x[i + 13], 4, 681279174);
                    d = hh(d, a, b, c, x[i + 0], 11, -358537222);
                    c = hh(c, d, a, b, x[i + 3], 16, -722521979);
                    b = hh(b, c, d, a, x[i + 6], 23, 76029189);
                    a = hh(a, b, c, d, x[i + 9], 4, -640364487);
                    d = hh(d, a, b, c, x[i + 12], 11, -421815835);
                    c = hh(c, d, a, b, x[i + 15], 16, 530742520);
                    b = hh(b, c, d, a, x[i + 2], 23, -995338651);
                    a = ii(a, b, c, d, x[i + 0], 6, -198630844);
                    d = ii(d, a, b, c, x[i + 7], 10, 1126891415);
                    c = ii(c, d, a, b, x[i + 14], 15, -1416354905);
                    b = ii(b, c, d, a, x[i + 5], 21, -57434055);
                    a = ii(a, b, c, d, x[i + 12], 6, 1700485571);
                    d = ii(d, a, b, c, x[i + 3], 10, -1894986606);
                    c = ii(c, d, a, b, x[i + 10], 15, -1051523);
                    b = ii(b, c, d, a, x[i + 1], 21, -2054922799);
                    a = ii(a, b, c, d, x[i + 8], 6, 1873313359);
                    d = ii(d, a, b, c, x[i + 15], 10, -30611744);
                    c = ii(c, d, a, b, x[i + 6], 15, -1560198380);
                    b = ii(b, c, d, a, x[i + 13], 21, 1309151649);
                    a = ii(a, b, c, d, x[i + 4], 6, -145523070);
                    d = ii(d, a, b, c, x[i + 11], 10, -1120210379);
                    c = ii(c, d, a, b, x[i + 2], 15, 718787259);
                    b = ii(b, c, d, a, x[i + 9], 21, -343485551);
                    a = add(a, olda);
                    b = add(b, oldb);
                    c = add(c, oldc);
                    d = add(d, oldd);
                }
                return rhex(a) + rhex(b) + rhex(c) + rhex(d);
            }
            return MD5(a);
        }
    };
    $.fn.extend($.ET, tools);
})(jQuery);


/*
$().etxxxx();
常用动态型   公用类方法
*/

(function () {
    //通用提示 by kas  ver 0.5
    $.fn.etip = $.fn.etipshow = function (op) {
        if ($.ET === undefined) { alert('need $.ET tools!'); return; }
        var opts = $.extend({}, $.fn.etip.defaults, op);
        var o = op || opts;
        o.of = o.of || opts.of;
        o.msg = o.msg || opts.msg;
        o.msg = o.etip || opts.msg; //兼容etipshow
        o.w = o.w || opts.w;
        o.h = o.h || opts.h;
        o.where = o.where || opts.where;
        o.delay = o.delay || opts.delay;
        o.css = o.css || opts.css;
        var ETID = "et" + $.ET.random(5);
        /*	需要的样式
        .etTips .arrow{background: url("../images/etips.gif") no-repeat;position: absolute;z-index: 1;overflow: hidden; width:9px; height:6px;}
        .etTips .detail{background-color: #f8f8f8; border: 1px solid #ec139c;color:#444;line-height:18px;position: absolute;text-align: center;}
        .etTips .close{background: url("../images/etips.gif") no-repeat scroll 0px -40px transparent;cursor: pointer;height: 6px;position: absolute;right: 3px;top: 3px;width: 7px;z-index: 1;}        */
        $("<div class='etTips' style='height:" + o.h + "px;width:" + o.w + "px;'>"
        	+ "<div class='arrow'></div>"
        	+ "<div class='detail'>"
        		+ "<div class='close'></div>"
        		+ "<div class='msg'>" + o.msg + "</div>"
        	+ "</div>"
        + "</div>")
        .addClass(ETID)
        .css("position", "absolute")
        .css("display", "none")
        .css("z-index", $.ET.maxzindex() + 1)
        .appendTo("body");
        ETID = "." + ETID;

        $(ETID + " .detail").css({ padding: "10px 5px" });
        //纠正内框
        $(ETID + " .detail").css({ height: o.h - 20 + "px", width: o.w - 10 + "px" });
        if (o.css != "") $(ETID + " .msg").addClass(o.css);
        //兼容参考对象
        var obj = o.of == null ? $(this) : o.of instanceof $ ? o.of : $(o.of).length > 0 ? $(o.of) : $(this);

        var x = 0, y = 0;
        if (o.where == "right") {
            x = obj.offset().left + obj.width() + 9 + 4;
            y = obj.offset().top + (obj.height() / 2 - $(ETID).outerHeight() / 2);
            $(ETID + " .arrow").css({ left: "-5px", top: (($(ETID).outerHeight() - 9) / 2) + "px", width: "6px", height: "9px", "background-position": "0px 0px" });
        }
        if (o.where == "left") {
            x = obj.offset().left - ($(ETID).width() + 9 + 4);
            y = obj.offset().top + (obj.height() / 2 - $(ETID).outerHeight() / 2);
            $(ETID + " .arrow").css({ "left": $(ETID).outerWidth() + 1 + "px", "top": (($(ETID).height() - 9) / 2) + "px", "width": "6px", "height": "9px", "background-position": "0px -10px" });
        }
        if (o.where == "top") {
            x = obj.offset().left + (obj.width() / 2 - $(ETID).width() / 2);
            y = obj.offset().top - ($(ETID).height() + 9 + 4);
            $(ETID + " .arrow").css({ "left": (($(ETID).width() - 9) / 2) + "px", "top": $(ETID).height() + 1 + "px", "width": "9px", "height": "6px", "background-position": "0px -20px" });
        }
        if (o.where == "bottom") {
            x = obj.offset().left + (obj.width() / 2 - $(ETID).width() / 2);
            y = obj.offset().top + obj.height() + 9 + 4;
            $(ETID + " .arrow").css({ left: (($(ETID).width() - 9) / 2) + "px", top: "-5px", "background-position": "0px -30px" });
        }
        $(ETID).css({ "left": x, "top": y }).fadeIn();
        if (o.delay > 0)
            setTimeout(function () { $(ETID).fadeOut().remove(); }, o.delay);
        $(ETID + " .close").click(function () { $(ETID).fadeOut().remove(); });
        return this;
    };
    $.fn.etip.defaults = {
        of: null,
        msg: "",
        w: "140",
        h: "60",
        where: "bottom",
        delay: 0,
        css: ""
    };
})();

(function ($) {
    //文本框提示处理 v0.2
    $.fn.etvaluetip = function (op) {
        var opts = $.extend({}, $.fn.etvaluetip.defaults, op);
        var o = op || opts;
        o.css = o.css || opts.css;
        return this.each(function () {
            if (o.css != "")
                $(this).addClass(o.css);
            $(this).click(function () {
                if ($(this).attr("valuetip") === undefined || $(this).val() == $(this).attr("valuetip")) {
                    $(this).attr("valuetip", $(this).val());
                    $(this).val("");
                    $(this).removeClass(o.css);
                }
            }).focusout(function () {
                if ($(this).val() == "") {
                    $(this).val($(this).attr("valuetip"));
                    $(this).addClass(o.css);
                }
            });
        });
    };
    $.fn.etvaluetip.defaults = {
        css: ""
    };
})(jQuery);
