﻿var sAttrClass = (window.clientInformation) ? "className" : "class";
var $ = function(id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};
function Round(f) {
    return Math.round(f * 100) / 100;
}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5 & version < 7) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                j = j - 1
            }
        }
    }
}
var CheckInput = function() {
    this.isPass = true;
    var focusObj = null;
    var checkList = new Array();

    this.beginCheck = function() {
        this.isPass = true;
        focusObj = null;
        for (var i = 0; i < checkList.length; i++) {
            $("#" + checkList[i]).removeClass("inpError");
        }
    }
    this.endCheck = function() {
        if (focusObj != null) {
            focusObj.focus();
        }
        return this.isPass;
    }
    this.checkObject = function(CheckValue, obj, objID, message) {
        if (CheckValue) {
            var flag = false;
            for (var i = 0; i < checkList.length; i++) {
                if (checkList[i] == objID) {
                    flag = true;
                }
            }
            if (!flag) checkList.push(objID);
            obj.addClass("inpError");
            obj.attr("title", message);
            if (focusObj == null) {
                focusObj = obj;
                obj.focus();
            }
            this.isPass = false;
            return false;
        }
        this.isPass = this.isPass && true;
        return true;
    }
    this.setTitle = function(objID, title) {
        var obj = $("#" + objID);
        obj.attr("title", title);
    }
    this.checkSelectEqual = function(objID, equalValue, message) {
        var obj = $("#" + objID);
        return this.checkObject((obj.val() == equalValue), obj, objID, message);
    }
    this.checkTextEmpty = function(objID, message) {
        var obj = $("#" + objID);
        return this.checkObject((obj.val() == "" || obj.val().length <= 0), obj, objID, message);
    }
    this.checkTextMail = function(objID, message) {
        var obj = $("#" + objID);
        return this.checkObject(!this.IsMain(obj.val()), obj, objID, message);
    }
    this.isEqual = function(sourceID, ObjectID) {
        return this.isEqual(sourceID, ObjectID, "");
    }
    this.isEqual = function(sourceID, ObjectID, message) {
        var source = $("#" + sourceID);
        var obj = $("#" + ObjectID);
        var flag = (source.val() == obj.val());
        if (message != "") {
            this.checkObject(!flag, source, sourceID, message);
            this.checkObject(!flag, obj, ObjectID, message);
        }
        return flag;
    }
    this.checkTextNumber = function(objID, message) {

    }
    this.checkLeastLength = function(objID, len, message) {
        //检查长度是否太短
        var obj = $("#" + objID);
        return this.checkObject((obj.val().length < len), obj, objID, message);
    }
    this.TextBoxOnlyInputNumber = function(objID) {
        var obj = $("#" + objID);
        obj.keyup(function() {//先把非数字的都替换掉，除了数字和.
            obj.val(obj.val().replace(/[^\d.]/g, ""));
            //必须保证第一个为数字而不是.
            obj.val(obj.val().replace(/^\./g, ""));
            //保证只有出现一个.而没有多个.
            obj.val(obj.val().replace(/\.{2,}/g, "."));
            //保证.只出现一次，而不能出现两次以上
            obj.val(obj.val().replace(".", "$#$").replace(/\./g, "").replace("$#$", "."));
        });
    }
    this.CheckByReg = function(str, reg) {
        return reg.test(str);
    }
    this.IsTextEmpty = function(objID) {
        var obj = $("#" + objID);
        return (obj.val() == "" || obj.val().length <= 0);
    }
    this.IsMain = function(mail) {
        return this.CheckByReg(mail, /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/);
    }
}
function Browser() {
    var ua, s, i;
    this.isIE = false;
    this.isNS = false;
    this.isOP = false;
    this.isSF = false;
    ua = navigator.userAgent.toLowerCase();
    s = "opera";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isOP = true;
        return;
    }
    s = "msie";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isIE = true;
        return;
    }
    s = "netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        return;
    }
    s = "gecko";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        return;
    }
    s = "safari";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isSF = true;
        return;
    }
}

var browser = new Browser();

window.attachEvent("onload", correctPNG);

/*
* URL 参数拼接函数
* @url 网址
* @params 参数数组
*/
function getUrl(url, params) {
    if (params) {
        var str = "?";
        for (var k in params) {
            if (str.length > 1) {
                str += "&";
            }
            str += k + "=" + params[k];
        }
        url += str;
    }
    return url;
}

function getInnerText(elt) {
    var _innerText = elt.innerText;
    if (_innerText == undefined) {
        _innerText = elt.innerHTML.replace(/<[^>]+>/g, "");
    }
    return _innerText;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function DIVDialog(hdivOverlayLayerID,unUseShareOverlay) {

    this.hdivOverlayLayer = hdivOverlayLayerID;
    this.Show = function () {
            document.getElementById("hdivOverlay").style.display = "block";
            document.getElementById(this.hdivOverlayLayer).style.display = "block";

        var parentDIV = document.getElementById(this.hdivOverlayLayer).parentNode;
        parentDIV.style.display = "block";

        if (broswerVersion < 7) {
            var ps = getPageSize();
            parentDIV.style.height = document.getElementById("hdivOverlay").style.height = ps[1];
            parentDIV.style.width = document.getElementById("hdivOverlay").style.width = ps[0];
        }
    }
    this.Close = function() {
        document.getElementById("hdivOverlay").style.display = "none";
        document.getElementById(this.hdivOverlayLayer).style.display = "none";
        document.getElementById(this.hdivOverlayLayer).parentNode.style.display = "none";
    }

}
function ShowMaxImage(img, maxImgID) {
    $(maxImgID).src = "http://" + window.location.host + "/CommonPage/getFile.aspx?fid=" + img.FileID + "&rnd=" + Math.random(); ;
}
function goBack() {
    history.go(-1);
}


var Request =
    {
        QueryString: function(item) {
            var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
            return svalue ? svalue[1] : svalue;
        }
    }


function CheckAll(panelID, flag) {
    var panel = document.getElementById(panelID);
    if (!panel) return;
    var chkList = panel.getElementsByTagName("input");

    for (var i = 0; i < chkList.length; i++) {
        if (chkList[i].type == 'checkbox') {
            chkList[i].checked = flag;
        }
    }
}
function MD5(value, bit) {
    var sMessage = value;
    function RotateLeft(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); }
    function AddUnsigned(lX, lY) {
        var lX4, lY4, lX8, lY8, lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
        if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        if (lX4 | lY4) {
            if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
        } else return (lResult ^ lX8 ^ lY8);
    }
    function F(x, y, z) { return (x & y) | ((~x) & z); }
    function G(x, y, z) { return (x & z) | (y & (~z)); }
    function H(x, y, z) { return (x ^ y ^ z); }
    function I(x, y, z) { return (y ^ (x | (~z))); }
    function FF(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    }
    function GG(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    }
    function HH(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    }
    function II(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    }
    function ConvertToWordArray(sMessage) {
        var lWordCount;
        var lMessageLength = sMessage.length;
        var lNumberOfWords_temp1 = lMessageLength + 8;
        var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
        var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
        var lWordArray = Array(lNumberOfWords - 1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while (lByteCount < lMessageLength) {
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount) << lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount - (lByteCount % 4)) / 4;
        lBytePosition = (lByteCount % 4) * 8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
        lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
        lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
        return lWordArray;
    }
    function WordToHex(lValue) {
        var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
        for (lCount = 0; lCount <= 3; lCount++) {
            lByte = (lValue >>> (lCount * 8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
        }
        return WordToHexValue;
    }
    var x = Array();
    var k, AA, BB, CC, DD, a, b, c, d
    var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
    var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
    var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
    var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
    // Steps 1 and 2. Append padding bits and length and convert to words 
    x = ConvertToWordArray(sMessage);
    // Step 3. Initialise 
    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
    // Step 4. Process the message in 16-word blocks 
    for (k = 0; k < x.length; k += 16) {
        AA = a; BB = b; CC = c; DD = d;
        a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
        d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
        c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
        b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
        a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
        d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
        c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
        b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
        a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
        d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
        c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
        b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
        a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
        d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
        c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
        b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
        a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
        d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
        c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
        b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
        a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
        d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
        c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
        b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
        a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
        d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
        c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
        b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
        a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
        d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
        c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
        b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
        a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
        d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
        c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
        b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
        a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
        d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
        c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
        b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
        a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
        d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
        c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
        b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
        a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
        d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
        c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
        b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
        a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
        d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
        c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
        b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
        a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
        d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
        c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
        b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
        a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
        d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
        c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
        b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
        a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
        d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
        c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
        b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
        a = AddUnsigned(a, AA); b = AddUnsigned(b, BB); c = AddUnsigned(c, CC); d = AddUnsigned(d, DD);
    }
    if (bit == 32) {
        return WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
    }
    else {
        return WordToHex(b) + WordToHex(c);
    }
}

var timerID = null;
var timerRunning = false;
var startTime = (new Date()).getTime();
function showtime(_tagname, _auctionDate) {
    now = new Date();
    var Temp;
    var ts = parseInt((startTime - now.getTime()) / 1000) + _auctionDate;
    var dateLeft = 0;
    var hourLeft = 0;
    var minuteLeft = 0;
    var secondLeft = 0;

    if (ts < 0) {
        ts = 0;
        CurHour = 0;
        CurMinute = 0;
        CurSecond = 0;
    } else {
        dateLeft = parseInt(ts / 86400);
        ts = ts - dateLeft * 86400;
        hourLeft = parseInt(ts / 3600);
        ts = ts - hourLeft * 3600;
        minuteLeft = parseInt(ts / 60);
        secondLeft = ts - minuteLeft * 60;
    }
    if (hourLeft < 10) hourLeft = '0' + hourLeft;
    if (minuteLeft < 10) minuteLeft = '0' + minuteLeft;
    if (secondLeft < 10) secondLeft = '0' + secondLeft;
    if (dateLeft > 0)
        dateLeft = dateLeft + "天";
    else
        dateLeft = "";
    if (hourLeft > 0)
        hourLeft = hourLeft + "小时";
    else {
        if (dateLeft != "")
            hourLeft = "00小时";
        else
            hourLeft = "";
    }
    if (minuteLeft > 0)
        minuteLeft = minuteLeft + "分钟";
    else {
        if (dateLeft != "" || hourLeft != "")
            minuteLeft = "00分钟";
        else
            minuteLeft = "";
    }
    if (secondLeft > 0)
        secondLeft = secondLeft + "秒";
    else {
        if (dateLeft != "" || hourLeft != "" || minuteLeft != "")
            secondLeft = "00秒";
        else
            secondLeft = "";
    }
    //	if (dateLeft == '') {
    Temp = dateLeft + hourLeft + minuteLeft + secondLeft;
    //   	}else {
    //  		Temp=dateLeft+hourLeft;
    //   	}
    if (_auctionDate <= 0 || dateLeft <= 0 && hourLeft <= 0 && minuteLeft <= 0 && secondLeft <= 0) {
        Temp = "已结束";
        stopclock();
    }

    document.getElementById(_tagname).innerHTML = Temp;
    timerID = setTimeout("showtime('" + _tagname + "'," + _auctionDate + ")", 1000);
    timerRunning = true;
}
function stopclock() {
    if (timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}


function GetRemainTime(theTime) {
    var aDate = 24 * 60 * 60;
    var anHour = 60 * 60;
    var aMinute = 60;
    var iSeconds;
    var str = "";
    var now = new Date().getTime();
    var iTime = theTime - parseInt(now / 1000);
    if (iTime > 0) {
        str = "剩余 ";
        if (iTime > aDate) {
            str += parseInt(iTime / aDate) + "天";
            return str;
        }
        if (iTime > anHour) {
            str += parseInt(iTime / anHour) + "小时";
            return str;
        }
        if (iTime > aMinute * 10) {
            str += parseInt(iTime / aMinute) + "分钟";
            return str;
        }
        if (iTime > aMinute) {

            iSeconds = iTime - parseInt((iTime / aMinute)) * aMinute;
            if (iSeconds > 0)
                str += parseInt(iTime / aMinute) + "分钟" + iSeconds + " 秒";
            else
                str += parseInt(iTime / aMinute) + "分钟";
            return str;
        }
        if (iTime > 0) {

            str += iTime + "秒";
            return str;
        }
    }
    else
        if (iTime <= 0) {
        str = "已过期";
        return str;
    }

}
function DisplayRemainTime(theTime) {
    document.write(GetRemainTime(theTime));
    return;
}

//Function Name	: WebForm_Validate
//  Description	: 验证表单
//	     Author : FireTiger
//   Input Para	: validationGroup - 验证组
// Return Value	: 验证是否通过
function WebForm_Validate(validationGroup) {
    var validationResult = true;
    if (typeof (Page_ClientValidate) == "function") {
        validationResult = Page_ClientValidate(validationGroup);
    }

    return validationResult;
}

//Function Name	: ReplaceCharacters
//  Description	: 批量替换函数
//	     Author : wfang
//   Input Para	: conversionString - 要操作的字符串
//              : inChar           - 要替换的字符串
//              : outChar          - 将被替换的新的字符串
// Return Value	: 无
function ReplaceCharacters(conversionString, inChar, outChar) {
    var convertedString = conversionString.split(inChar);
    convertedString = convertedString.join(outChar);
    return convertedString;
}
function EncryptText(objID) {

    var obj = document.getElementById(objID);
    obj.value = MD5(obj.value, 32);
}

function T(n) {
    document.getElementById("ArticleCnt").style.fontSize = n + "px";
}

//验证特殊字符
function ValidateSpecialCharacter(str) {
    vkeyWords = /^[^`~!$%^&()+=|\\\][\]\{\}:;'\,<>]*$/;
    if (!vkeyWords.test(str)) {
        return false;
    }
    return true;
}

function ValidateLogin(obj1, obj2) {
    return true;
}

var I_FILE_MAX = 3;
var iAttachArray = new Array();
iAttachArray[0] = 1;
for (var i = 1; i < I_FILE_MAX; i++) iAttachArray[i] = 0;

function GetFileButtonIndex() {
    for (var i = 0; i < I_FILE_MAX && iAttachArray[i] == 1; i++);
    return i;
}

function DeleteTR(TableName, oRow, iButtonIndex) {
    var oTable = document.getElementById(TableName);
    oTable.deleteRow(oRow.rowIndex);
    iAttachArray[iButtonIndex] = 0;
}

function AddFileTableRow(TableID) {
    var iFileButtonIndex = GetFileButtonIndex();
    if (iFileButtonIndex >= I_FILE_MAX) {
        alert('您最多只能上传' + I_FILE_MAX + '张问题截图!');
        return;
    }
    var oTable = document.getElementById(TableID);
    var oRow = oTable.insertRow(oTable.rows.length);
    var aCells = oRow.cells;
    var sFileButtonName = "BugPic" + iFileButtonIndex;
    var Cell_1 = oRow.insertCell(aCells.length);
    Cell_1.innerHTML = "<td> <input type='file' name='" + sFileButtonName + "' id='" + sFileButtonName + "'  style='width:308px;'> </td>";
    aCells = oRow.cells;
    Cell_1 = oRow.insertCell(aCells.length);

    Cell_1.innerHTML = "<td>&nbsp;&nbsp;<a style='cursor:hand;text-decoration:underline;' onclick=\"DeleteTR('" + TableID + "',this.parentElement.parentElement, " + iFileButtonIndex + ")\">删除</a></td>";

    iAttachArray[iFileButtonIndex] = 1;
    return true;
}

function AppendSmilies(objTextID, Smilies) {

    var objText = $(objTextID);
    var str = Smilies.alt;
    (str == 'back') ? objText.value = objText.value.substring(0, objText.value.length - 1) : objText.value += str
}
function ReplySubject(objTextID, text) {

    var objText = $(objTextID);
    objText.value = "回复：" + text;
}
function ExcerptSubject(objTextID, text) {

    var objText = $(objTextID);
    objText.value = "引用：" + text;
}
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[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);
        }
    }
}
function SetRanCode(sTxtID) {
    var txt = $(sTxtID);
    if (txt && txt.value == "") {
        txt.value = "0000";
    }
}
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

var tips = new Array("输入搜索关键字，空格隔开");

function doFocus() {
    var obj = document.getElementById("condition");
    if (obj.value == tips[0]) {
        obj.value = "";
    }
    obj.style.color = "#000000";
}

function doBlur() {
    var obj = document.getElementById("condition");
    if (obj.value == "") {
        obj.style.color = "#888888";
    }
    else {
        obj.style.color = "#000000";
    }
}
function jsGetAge(strBirthday) {
    var returnAge;
    var strBirthdayArr = strBirthday.split(".");
    var birthYear = strBirthdayArr[0];
    var birthMonth = strBirthdayArr[1];
    var birthDay = strBirthdayArr[2];

    d = new Date();
    var nowYear = d.getYear();
    var nowMonth = d.getMonth() + 1;
    var nowDay = d.getDate();

    if (nowYear == birthYear) {
        returnAge = 0; //同年 则为0岁
    }
    else {
        var ageDiff = nowYear - birthYear; //年之差
        if (ageDiff > 0) {
            if (nowMonth == birthMonth) {
                var dayDiff = nowDay - birthDay; //日之差
                if (dayDiff < 0) {
                    returnAge = ageDiff - 1;
                }
                else {
                    returnAge = ageDiff;
                }
            }
            else {
                var monthDiff = nowMonth - birthMonth; //月之差
                if (monthDiff < 0) {
                    returnAge = ageDiff - 1;
                }
                else {
                    returnAge = ageDiff;
                }
            }
        }
        else {
            returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
        }
    }

    return returnAge; //返回周岁年龄

}


function isChinaIDCard(StrNo, dateBorn) {

    StrNo = StrNo.toString()

    var aCity = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古",
        21: "辽宁", 22: "吉林", 23: "黑龙江 ",
        31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东",
        41: "河南", 42: "湖北 ", 43: "湖南", 44: "广东", 45: "广西", 46: "海南",
        50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏 ",
        61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "***",
        71: "台湾", 81: "香港", 82: "澳门", 91: "国外 "
    };

    if (aCity[parseInt(StrNo.substr(0, 2))] == null) {
        alert("非法地区");
        return false;
    }

    if (StrNo.length == 18) {
        var a, b, c
        if (!isInteger(StrNo.substr(0, 17))) { return false }
        a = parseInt(StrNo.substr(0, 1)) * 7 + parseInt(StrNo.substr(1, 1)) * 9 + parseInt(StrNo.substr(2, 1)) * 10;
        a = a + parseInt(StrNo.substr(3, 1)) * 5 + parseInt(StrNo.substr(4, 1)) * 8 + parseInt(StrNo.substr(5, 1)) * 4;
        a = a + parseInt(StrNo.substr(6, 1)) * 2 + parseInt(StrNo.substr(7, 1)) * 1 + parseInt(StrNo.substr(8, 1)) * 6;
        a = a + parseInt(StrNo.substr(9, 1)) * 3 + parseInt(StrNo.substr(10, 1)) * 7 + parseInt(StrNo.substr(11, 1)) * 9;
        a = a + parseInt(StrNo.substr(12, 1)) * 10 + parseInt(StrNo.substr(13, 1)) * 5 + parseInt(StrNo.substr(14, 1)) * 8;
        a = a + parseInt(StrNo.substr(15, 1)) * 4 + parseInt(StrNo.substr(16, 1)) * 2;
        b = a % 11;

        if (b == 2)   //最后一位为校验位  
        {
            c = StrNo.substr(17, 1).toUpperCase();   //转为大写X  
        }
        else {
            c = parseInt(StrNo.substr(17, 1));
        }

        switch (b) {
            case 0: if (c != 1) { alert("身份证好号码校验位错:最后一位应该为:1"); return false; } break;
            case 1: if (c != 0) { alert("身份证好号码校验位错:最后一位应该为:0"); return false; } break;
            case 2: if (c != "X") { alert("身份证好号码校验位错:最后一位应该为:X"); return false; } break;
            case 3: if (c != 9) { alert("身份证好号码校验位错:最后一位应该为:9"); return false; } break;
            case 4: if (c != 8) { alert("身份证好号码校验位错:最后一位应该为:8"); return false; } break;
            case 5: if (c != 7) { alert("身份证好号码校验位错:最后一位应该为:7"); return false; } break;
            case 6: if (c != 6) { alert("身份证好号码校验位错:最后一位应该为:6"); return false; } break;
            case 7: if (c != 5) { alert("身份证好号码校验位错:最后一位应该为:5"); return false; } break;
            case 8: if (c != 4) { alert("身份证好号码校验位错:最后一位应该为:4"); return false; } break;
            case 9: if (c != 3) { alert("身份证好号码校验位错:最后一位应该为:3"); return false; } break;
            case 10: if (c != 2) { alert("身份证好号码校验位错:最后一位应该为:2"); return false }
        }
    }
    else   //15位身份证号  
    {
        if (!isInteger(StrNo)) { alert("身份证号码错误,前15位不能含有英文字母！"); return false }
    }

    switch (StrNo.length) {
        case 15:
            if (isValidDate("19" + StrNo.substr(6, 2), StrNo.substr(8, 2), StrNo.substr(10, 2), dateBorn))
            { return true; }
            else
            { return false; }
        case 18:
            if (isValidDate(StrNo.substr(6, 4), StrNo.substr(10, 2), StrNo.substr(12, 2), dateBorn))
            { return true; }
            else
            { return false; }
    }
    alert("输入的身份证号码必须为15位或者18位！");
    return false
}

function isValidDate(iY, iM, iD, dateBorn) {
    var a = new Date(iY, iM - 1, iD);
    var y = a.getFullYear();
    var m = a.getMonth() + 1;
    var d = a.getDate();

    if (a.toString() != dateBorn.toString() || Number(y) != Number(iY) || Number(m) != Number(iM) || Number(d) != Number(iD)) {
        window.alert('身份证号码内日期错误！');
        return false;
    }
    return true
}

function isInteger(str) {
    if (/[^\d]+$/.test(str)) {
        return false;
    }
    return true;
}


function IDUpdate(StrNo) {

    if (!isChinaIDCard(StrNo)) { return false }
    if (StrNo.length == 15) {
        var a, b, c
        StrNo = StrNo.substr(0, 6) + "19" + StrNo.substr(6, 9)
        a = parseInt(StrNo.substr(0, 1)) * 7 + parseInt(StrNo.substr(1, 1)) * 9 + parseInt(StrNo.substr(2, 1)) * 10;
        a = a + parseInt(StrNo.substr(3, 1)) * 5 + parseInt(StrNo.substr(4, 1)) * 8 + parseInt(StrNo.substr(5, 1)) * 4;
        a = a + parseInt(StrNo.substr(6, 1)) * 2 + parseInt(StrNo.substr(7, 1)) * 1 + parseInt(StrNo.substr(8, 1)) * 6;
        a = a + parseInt(StrNo.substr(9, 1)) * 3 + parseInt(StrNo.substr(10, 1)) * 7 + parseInt(StrNo.substr(11, 1)) * 9;
        a = a + parseInt(StrNo.substr(12, 1)) * 10 + parseInt(StrNo.substr(13, 1)) * 5 + parseInt(StrNo.substr(14, 1)) * 8;
        a = a + parseInt(StrNo.substr(15, 1)) * 4 + parseInt(StrNo.substr(16, 1)) * 2;
        b = a % 11;

        switch (b) {
            case 0: { StrNo = StrNo + "1"; } break;
            case 1: { StrNo = StrNo + "0"; } break;
            case 2: { StrNo = StrNo + "X"; } break;
            case 3: { StrNo = StrNo + "9"; } break;
            case 4: { StrNo = StrNo + "8"; } break;
            case 5: { StrNo = StrNo + "7"; } break;
            case 6: { StrNo = StrNo + "6"; } break;
            case 7: { StrNo = StrNo + "5"; } break;
            case 8: { StrNo = StrNo + "4"; } break;
            case 9: { StrNo = StrNo + "3"; } break;
            case 10: { StrNo = StrNo + "3"; }
        }
    }
    return StrNo;
}

function dateRegexp(_sText) {
    var sYear = _sText.substring(0, 4);
    var sMonth = _sText.substring(4, 6);
    var sDay = _sText.substring(6, 8);
    var regexp = /^[12]\d{3}(1[12]|0[1-9])(0[1-9]|1\d|2\d|3[01])$/;
    var largeMonth = "01,03,05,07,08,10,12";
    var smallMonth = "02,04,06,09,11";

    if (regexp.test(_sText)) {//进行正则表达式验证
        var iYear = parseInt(sYear); //将年份转化成整数类型

        if (iYear % 100 != 0 && iYear % 4 == 0 || iYear % 400 == 0) {//进行闰年判断,闰年<=29,非闰年<=28
            if (sMonth == "02") {
                return sDay <= 29 ? true : false;
            } else {
                //进行大月和小月的判断
                if (largeMonth.indexOf(sMonth) >= 0) {
                    return sDay <= 31 ? true : false;
                }
                if (smallMonth.indexOf(sMonth) >= 0) {
                    return sDay <= 30 ? true : false;
                }
            }
        } else {
            if (sMonth == "02") {
                return sDay <= 28 ? true : false;
            } else {
                //进行大月和小月的判断
                if (largeMonth.indexOf(sMonth) >= 0) {
                    return sDay <= 31 ? true : false;
                }
                if (smallMonth.indexOf(sMonth) >= 0) {
                    return sDay <= 30 ? true : false;
                }
            }
        }
    }
}

function change_Bounty(rbtnNoID,rbtnAmountID, rbtnRateID,  txtAmountID, txtRateID, chkOnFID) {

    rbtnNo = $(rbtnNoID);
    rbtnRate = $(rbtnRateID);
    rbtnAmount = $(rbtnAmountID);
    txtRate = $(txtRateID);
    txtAmount = $(txtAmountID);
    chkOnF = $(chkOnFID);
    if (!(rbtnNo && rbtnRate && rbtnAmount && txtRate && txtAmount && chkOnF)) return;

    if (rbtnNo.checked) {
        txtRate.disabled = true;
        txtAmount.disabled = true;
        chkOnF.disabled = true;
        chkOnF.checked = false;
    }
    else if (rbtnRate.checked) {
        txtRate.disabled = false;
        txtAmount.disabled = true;
        chkOnF.disabled = false;
    }
    else if (rbtnAmount.checked) {
        txtRate.disabled = true;
        txtAmount.disabled = false;
        chkOnF.disabled = false;
    }
}
function change_Vouch(rbtnNoID,rbtnAmountID, rbtnRateID,  txtAmountID, txtRateID) {

    rbtnNo = $(rbtnNoID);
    rbtnRate = $(rbtnRateID);
    rbtnAmount = $(rbtnAmountID);
    txtRate = $(txtRateID);
    txtAmount = $(txtAmountID);
    if (!(rbtnNo && rbtnRate && rbtnAmount && txtRate && txtAmount)) return;

    if (rbtnNo.checked) {
        txtRate.disabled = true;
        txtAmount.disabled = true;
    }
    else if (rbtnRate.checked) {
        txtRate.disabled = false;
        txtAmount.disabled = true;
    }
    else if (rbtnAmount.checked) {
        txtRate.disabled = true;
        txtAmount.disabled = false;
    }
}

function CancelPubllishCheck(from,NoBountyID,NoVouchID,txtBountyAmountID, txtBountyRateID, chkBountyOnFID,txtVouchAmountID, txtVouchRateID)
{
    rbtnNoBounty = $(NoBountyID);
    rbtnNoVouch = $(NoVouchID);
    txtBountyAmount = $(txtBountyAmountID);
    txtBountyRate = $(txtBountyRateID);
    chkBountyOnF = $(chkBountyOnFID);
    txtVouchAmount = $(txtVouchAmountID);
    txtVouchRate = $(txtVouchRateID);
    
    if(from=="Bounty" && rbtnNoVouch && rbtnNoBounty && txtVouchAmount && txtVouchRate)
    {
        rbtnNoVouch.checked=true;
        txtVouchAmount.disabled = true;
        txtVouchRate.disabled = true;
    }
    else if(from=="Vouch" && rbtnNoVouch && rbtnNoBounty && txtBountyAmount && txtBountyRate && chkBountyOnF)
    {
        rbtnNoBounty.checked=true;
        txtBountyAmount.disabled = true;
        txtBountyRate.disabled = true;
        chkBountyOnF.disabled = true;
        chkBountyOnF.checked = false;

    }
}
function clearNoNum(obj)
{
		//先把非数字的都替换掉，除了数字和.
		obj.value = obj.value.replace(/[^\d.]/g,"");
		//必须保证第一个为数字而不是.
		obj.value = obj.value.replace(/^\./g,"");
		//保证只有出现一个.而没有多个.
		obj.value = obj.value.replace(/\.{2,}/g,".");
		//保证.只出现一次，而不能出现两次以上
		obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");

}
function enabledControl(flag,controlID)
{
    var ids=controlID.split(",");
    var obj;
    if(ids.length>0)
    {
        for(var i=0;i<ids.length;i++)
        {
            obj=$(ids[i]);
            if(obj)
            {
                obj.disabled=!flag;
             }
        }
    }
}

