﻿/********************回到顶部开始************************/
/**
* 滑动回到页面顶部
* @param acceleration 加速度
* @param time 时间间隔 (毫秒)
**/
function BackTop(acceleration, time) {
    acceleration = acceleration || 0.1;
    time = time || 16;

    var x1 = 0;
    var y1 = 0;
    var x2 = 0;
    var y2 = 0;
    var x3 = 0;
    var y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }
    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }
    var x3 = window.scrollX || 0;
    var y3 = window.scrollY || 0;

    // 滚动条到页面顶部的水平距离
    var x = Math.max(x1, Math.max(x2, x3));
    // 滚动条到页面顶部的垂直距离
    var y = Math.max(y1, Math.max(y2, y3));

    // 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
    var speed = 1 + acceleration;
    window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));

    // 如果距离不为零, 继续调用迭代本函数
    if (x > 0 || y > 0) {
        var invokeFunction = "goTop(" + acceleration + ", " + time + ")";
        window.setTimeout(invokeFunction, time);
    }
}
/**
* 立刻回到页面顶部
**/
function GoBackTop() {
    var diffY;
    if (document.documentElement && document.documentElement.scrollTop)
        diffY = document.documentElement.scrollTop;
    else if (document.body)
        diffY = document.body.scrollTop
    else {
    }
    window.scrollBy(0, -diffY);
}

/**
* 是否显示回到顶部按钮
* window.setInterval("goTopisShow('actiTop')", 1);
**/
function IsShowBackTop(actiTop) {
    var diffY;
    if (document.documentElement && document.documentElement.scrollTop)
        diffY = document.documentElement.scrollTop;
    else if (document.body)
        diffY = document.body.scrollTop
    else {
    }
    if (diffY > 600) {
        //$("#actiTop")[0].style.display = 'block';
        $("#" + actiTop).show();
    } else {
        //$("#actiTop")[0].style.display = 'none';
        $("#" + actiTop).hide()
    }
}
/********************回到顶部结束************************/


/********************设置首页和加入收藏夹开始************************/
/**
* 加入收藏夹
**/
function AddFavorites() {
    if (document.all) {
        window.external.addFavorite('http://www.8666.com/', '海绵外语网');
    }
    else if (window.sidebar) {
        window.sidebar.addPanel('海绵外语网', 'http://www.8666.com/', "");
    }
}

/**
* 设置首页
**/
function SetHome() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://www.8666.com/');
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                etscape.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', 'http://www.8666.com/');
    }
}
/********************设置首页和加入收藏夹结束************************/

/********************倒计时开始************************/
/**
* 倒计时
* @param lab 显示位置ID
* @param btn 控制button按钮能否点击，如果没有设置为null
* @param timeSeconds 还剩下多长时间，时间为秒
**/
function Countdown(lab, btn, timeSeconds) {
    var labID = lab;
    var btnID = btn;
    if (btnID != null) {
        //传入的时间为空或小于0
        if (timeSeconds == null || timeSeconds < 0) {
            document.getElementById(btnID).disabled = false;
            clearTimeout(sid);
            return;
        }
        document.getElementById(btnID).disabled = true;
        document.getElementById(labID).innerHTML = SecondToTime(timeSeconds);
        timeSeconds--;
        var sid = setTimeout("Countdown('" + labID + "','" + btnID + "','" + timeSeconds + "')", 1000);
    }
    else {
        //传入的时间为空或小于0
        if (timeSeconds == null || timeSeconds < 0) {
            clearTimeout(sid);
            document.getElementById(labID).innerHTML = "正在上课";
            return;
        }
        document.getElementById(labID).innerHTML = SecondToTime(timeSeconds);
        timeSeconds--;
        var sid = setTimeout("Countdown('" + labID + "',null,'" + timeSeconds + "')", 1000);
    }
}
/**
* 秒转换为日期时分秒
* @param seconds 需要转换的秒数
**/
function SecondToTime(seconds) {
    var hh;
    var mm;
    var ss;
    //得到小时
    hh = seconds / 3600 | 0;
    seconds = parseInt(seconds) - hh * 3600;
    if (parseInt(hh) < 10) {
        hh = "0" + hh;
    }
    //得到分
    mm = seconds / 60 | 0;
    //得到秒
    ss = parseInt(seconds) - mm * 60;
    if (parseInt(mm) < 10) {
        mm = "0" + mm;
    }
    if (ss < 10) {
        ss = "0" + ss;
    }
    if (parseInt(hh) / 24 < 1) {
        return hh + ":" + mm + ":" + ss;
    }
    else {
        var dd = Math.floor(parseInt(hh) / 24);
        hh = parseInt(hh) - dd * 24;
        return "还剩 " + dd + " 天 " + hh + ":" + mm + ":" + ss;
    }
}
/********************倒计时结束************************/

/********************浏览器title闪动显示新消息开始************************/
/**
* 秒转换为日期时分秒
* newMessageRemind.show();显示
* newMessageRemind.clear();清除
**/
var newMessageRemind = {
    _step: 0,
    _title: document.title,
    _timer: null,
    //显示新消息提示
    show: function () {
        var temps = newMessageRemind._title.replace("【　　　】", "").replace("【新消息】", "");
        newMessageRemind._timer = setTimeout(function () {
            newMessageRemind.show();
            //这里写Cookie操作
            newMessageRemind._step++;
            if (newMessageRemind._step == 3) { newMessageRemind._step = 1 };
            if (newMessageRemind._step == 1) { document.title = "【　　　】" + temps;};
            if (newMessageRemind._step == 2) { document.title = "【新消息】" + temps;};
        }, 800);
        return [newMessageRemind._timer, newMessageRemind._title];
    },
    //取消新消息提示
    clear: function () {
        clearTimeout(newMessageRemind._timer);
        document.title = newMessageRemind._title;
        //这里写Cookie操作
    }

};
/********************浏览器title闪动显示新消息结束************************/

/********************浮动层飘动开始************************/
/**
* 浮动广告
* @param divId 需要上下浮动的对象ID(页面只能有一个浮动)
**/
FloatingBoxLastScrollY = 0;
function FloatingBox(divId) {

    var diffY;
    if (document.documentElement && document.documentElement.scrollTop)
        diffY = document.documentElement.scrollTop;
    else if (document.body)
        diffY = document.body.scrollTop
    else {
    }
    percent = .1 * (diffY - FloatingBoxLastScrollY);
    if (percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);

    document.getElementById(divId).style.top = parseInt(document.getElementById(divId).style.top) + percent + "px";
    FloatingBoxLastScrollY = FloatingBoxLastScrollY + percent;
}
/**
* 浮动广告
* @param divId 需要上下浮动的对象ID(页面有两个浮动时调用)
**/
DoubleFloatingBoxLastScrollY = 0;
function DoubleFloatingBox(divId1, divId2) {

    var diffY;
    if (document.documentElement && document.documentElement.scrollTop)
        diffY = document.documentElement.scrollTop;
    else if (document.body)
        diffY = document.body.scrollTop
    else {
    }
    percent = .1 * (diffY - DoubleFloatingBoxLastScrollY);
    if (percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);

    document.getElementById(divId1).style.top = parseInt(document.getElementById(divId1).style.top) + percent + "px";
    document.getElementById(divId2).style.top = parseInt(document.getElementById(divId2).style.top) + percent + "px";

    DoubleFloatingBoxLastScrollY = DoubleFloatingBoxLastScrollY + percent;
}
/**
* 浮动广告
* @param divId 需要无规则浮动的DIV对象
*使用：var itl = setInterval("RandomFloat(objDiv)", 10)
*document.getElementById(objDiv).onmouseover = function () { clearInterval(itl) }
*document.getElementById(objDiv).onmouseout = function () { itl = setInterval("RandomFloat(objDiv)", 10) }
**/
var Floatx = 50, Floaty = 60//设置左右距离
var Floatxin = true, Floatyin = true//设置漂浮左右方向
var Floatstep = 1//设置漂浮速度
function RandomFloat(objDiv) {
    var L = T = 0
    var R = document.body.clientWidth - document.getElementById(objDiv).offsetWidth
    var B = document.body.clientHeight - document.getElementById(objDiv).offsetHeight
    document.getElementById(objDiv).style.left = x + document.body.scrollLeft
    document.getElementById(objDiv).style.top = y + document.body.scrollTop

    Floatx = Floatx + Floatstep * (Floatxin ? 1 : -1)
    if (Floatx < L) { Floatxin = true; Floatx = L }
    if (Floatx > R) { Floatxin = false; Floatx = R }

    Floaty = Floaty + Floatstep * (Floatyin ? 1 : -1)
    if (Floaty < T) { Floatyin = true; Floaty = T }
    if (Floaty > B) { Floatyin = false; Floaty = B }
}
/********************浮动层飘动结束************************/

/********************DIV操作方法开始************************/
/**
* 创建DIV
* @param objId D创建IV对象ID
* @param msg div里内容
* @param t 离上方距离
* @param rl 离左还是右边
* @param rlRange 离左(右)边距离
**/
function CreateDiv(objId, msg, t, rl, rlRange) {
    var createDiv = document.createElement("div");
    createDiv.id = objId;
    createDiv.style.cssText = "position:absolute;top:" + t + "px;" + rl + ":" + rlRange + "px;z-index:5000;background:white;border:1px solid #999;";
    createDiv.innerHTML = msg;
    document.body.appendChild(createDiv);
}

/**
* 获取div对象内容
**/
function GetDivObject(divId) {
    if (navigator.appName.indexOf("Explorer") > -1)
        return document.getElementById(divId).innerHTML;
    else
        return document.getElementById(divId).innerHTML;
}
/**
* 隐藏DIV
**/
function NoDisplay(divId) {
    document.getElementById(divId).style.display = "none";
}
/**
* 显示DIV
**/
function ShowDisplay(divId) {
    document.getElementById(divId).style.display = 'block';
}
/**
* 移除DIV
**/
function RemoveDiv(DivId) {
    var div = document.getElementById(DivId);
    div.style.display = "none"; //隐藏而不删除  
    div.parentNode.removeChild(div); //删除
}

/********************DIV操作方法结束************************/
/********************消息提示开始************************/
/**
* 显示浮动弹出div提示信息
* @param divShow 显示位置
* @param message 需要转换的秒数
* @param typeImg 显示图片类型：Success成功，Warn警告，Error错误，Question疑问
* @param url 是否自动跳转页面
**/
function ShowInfoSuccess(divShow, message, typeImg, url) {
    switch (typeImg) {
        case "Success": 

            imgName = "images/Success.gif";
            break;
        case "Warn":
            imgName = "images/Warn.gif";
            break;
        case "Error":
            imgName = "images/Error.gif";
            break;
        case "Question":
            imgName = "images/Question.gif";
            break;
        default:
            imgName = "images/Success.gif";
            break;
    }
    var messgaeLen = message.length;
    var infoHtml;
    if (messgaeLen > 6) {
        infoHtml = "<div class=\"messageBox\" id=\"messageTooltip\"><div class=\"messageBox_L\">" + message + "</div>\
                   <div class=\"messageBox_R\"><img src=\"" + imgName + "\" alt=\"\" width=\"25\"  />\
                   </div><div class=\"cle\"></div></div>";
    }
    else {
        infoHtml = "<div class=\"messageBox\" id=\"messageTooltip\"><div class=\"messageBox_L\">" + message + "</div>\
                    <div class=\"messageBox_R_02\"><img src=\"" + imgName + "\" alt=\"\" width=\"25\"/>\
                    </div><div class=\"cle\"></div></div>"
    }
    $("#" + divShow).html(infoHtml);

    if (url == "back") {
        window.history.back(-1);
    } else if (url != "" && url != null) {
        window.location.href = url;
    }

    //3秒后清除提示
    setTimeout(function () {
        $("#messageTooltip").remove();
    }, 3000);
}

/**
* 添加事件
* @param node		监听对象
* @param type		监听类型（鼠标移动坐标：mousemove）
* @param listener	触发事件
* @return			事件是否添加成功
*/
function addEvent(node, type, listener) {
    if (node.addEventListener) {
        node.addEventListener(type, listener, false);
        return true;
    } else if (node.attachEvent) {
        node['e' + type + listener] = listener;
        node[type + listener] = function () {
            node['e' + type + listener](window.event);
        };
        node.attachEvent('on' + type, node[type + listener]);
        return true;
    }
    return false;
}
/**
* 获取鼠标在页面上的位置
* @param ev	触发的事件
* @return x:鼠标在页面上的横向位置, y:鼠标在页面上的纵向位置
*/
function getMousePoint(ev) {
    // 定义鼠标在视窗中的位置
    var point = {
        x: 0,
        y: 0
    };

    // 如果浏览器支持 pageYOffset, 通过 pageXOffset 和 pageYOffset 获取页面和视窗之间的距离
    if (typeof window.pageYOffset != 'undefined') {
        point.x = window.pageXOffset;
        point.y = window.pageYOffset;
    }
    // 如果浏览器支持 compatMode, 并且指定了 DOCTYPE, 通过 documentElement 获取滚动距离作为页面和视窗间的距离
    // IE 中, 当页面指定 DOCTYPE, compatMode 的值是 CSS1Compat, 否则 compatMode 的值是 BackCompat
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
        point.x = document.documentElement.scrollLeft;
        point.y = document.documentElement.scrollTop;
    }
    // 如果浏览器支持 document.body, 可以通过 document.body 来获取滚动高度
    else if (typeof document.body != 'undefined') {
        point.x = document.body.scrollLeft;
        point.y = document.body.scrollTop;
    }

    // 加上鼠标在视窗中的位置
    point.x += ev.clientX;
    point.y += ev.clientY;

    // 返回鼠标在视窗中的位置
    return point;
}
/**
* 兼容火狐及IE7、IE8的可移动弹出层，完全代替JavaScript的Alert弹出窗口。
* @param title 标题内容
* @param msg 弹出框内容
* @param w 弹出框宽度
* @param h 弹出框高度
**/
function alertMessage(title, msg, w, h) {
    var s = document.getElementsByTagName("select"); //--------------把所有select标签捉住
    for (var j = 0; j < s.length; j++) { s[j].style.display = "none"; } //--------------设为不显示，再进行下面操作
    var titleheight = "20px"; // 提示窗口标题高度
    var bordercolor = "#666699"; // 提示窗口的边框颜色
    var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色
    var titlebgcolor = "#1d5798"; // 提示窗口的标题背景色
    var bgcolor = "#FFFFFF"; // 提示内容的背景色
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var bgObj = document.createElement("div");
    bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:" + iWidth + "px;height:" + Math.max(document.body.clientHeight, iHeight) + "px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
    document.body.appendChild(bgObj);
    var msgObj = document.createElement("div");
    msgObj.style.cssText = "position:absolute;font:11px '宋体';top:" + (iHeight - h) / 2 + "px;left:" + (iWidth - w) / 2 + "px;width:" + w + "px;height:" + h + "px;text-align:center;border:1px solid " + bordercolor + ";background-color:" + bgcolor + ";padding:1px;line-height:22px;z-index:102;";
    document.body.appendChild(msgObj);
    var table = document.createElement("table");
    msgObj.appendChild(table);
    table.style.cssText = "margin:0px;border:0px;padding:0px;";
    table.cellSpacing = 0;
    var tr = table.insertRow(-1);
    var titleBar = tr.insertCell(-1);
    titleBar.style.cssText = "width:100%;height:" + titleheight + "px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:" + titlecolor + ";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
    titleBar.style.paddingLeft = "10px";
    titleBar.innerHTML = title;
    var moveX = 0;
    var moveY = 0;
    var moveTop = 0;
    var moveLeft = 0;
    var moveable = false;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;
    titleBar.onmousedown = function () {
        var evt = getEvent();
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(msgObj.style.top);
        moveLeft = parseInt(msgObj.style.left);
        document.onmousemove = function () {
            if (moveable) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
                if (x > 0 && (x + w < iWidth) && y > 0 && (y + h < iHeight)) {
                    msgObj.style.left = x + "px";
                    msgObj.style.top = y + "px";
                }
            }
        };
        document.onmouseup = function () {
            if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;
                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }
    var closeBtn = tr.insertCell(-1);
    closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
    closeBtn.innerHTML = "<span style='font-size:15pt; color:" + titlecolor + ";'>×</span>";
    closeBtn.onclick = function () {
        for (var j = 0; j < s.length; j++) { s[j].style.display = ""; } //--------------再给select显出来
        document.body.removeChild(bgObj);
        document.body.removeChild(msgObj);
    }
    var msgBox = table.insertRow(-1).insertCell(-1);
    msgBox.style.cssText = "font:10pt '宋体';";
    msgBox.colSpan = 2;
    msgBox.innerHTML = msg;
    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
        return window.event || arguments.callee.caller.arguments[0];
    }
}
/********************消息提示结束************************/

/********************图片轮播切换开始************************/
/**
* 图片轮播切换
**/
var WheelSowPicture = function () {
    var interv = 3000; //切换间隔时间
    var interv2 = 20; //切换速速
    var opac1 = 80; //文字背景的透明度
    var source = "WheelSowFocus" //焦点轮换图片容器的id名称
    //获取对象
    function getTag(tag, obj) { if (obj == null) { return document.getElementsByTagName(tag) } else { return obj.getElementsByTagName(tag) } }
    function getid(id) { return document.getElementById(id) };
    var opac = 0, j = 0, t = 63, num, scton = 0, timer, timer2, timer3; var id = getid(source); id.removeChild(getTag("div", id)[0]); var li = getTag("li", id); var div = document.createElement("div"); var title = document.createElement("div"); var span = document.createElement("span"); var button = document.createElement("div"); button.className = "wheelwow_button"; for (var i = 0; i < li.length; i++) { var a = document.createElement("a"); a.innerHTML = i + 1; a.onclick = function () { clearTimeout(timer); clearTimeout(timer2); clearTimeout(timer3); j = parseInt(this.innerHTML) - 1; scton = 0; t = 63; opac = 0; fadeon(); }; a.className = "wheelwow_b1"; a.onmouseover = function () { this.className = "wheelwow_b2" }; a.onmouseout = function () { this.className = "wheelwow_b1"; sc(j) }; button.appendChild(a); }
    //控制图层透明度
    function alpha(obj, n) { if (document.all) { obj.style.filter = "alpha(opacity=" + n + ")"; } else { obj.style.opacity = (n / 100); } }
    //控制焦点按钮
    function sc(n) { for (var i = 0; i < li.length; i++) { button.childNodes[i].className = "wheelwow_b1" }; button.childNodes[n].className = "wheelwow_b2"; }
    title.className = "wheelwow_num_list"; title.appendChild(span); alpha(title, opac1); id.className = "wheelwow_d1"; div.className = "wheelwow_d2"; id.appendChild(div); id.appendChild(title); id.appendChild(button);
    //渐显
    var fadeon = function () { opac += 5; div.innerHTML = li[j].innerHTML; span.innerHTML = getTag("img", li[j])[0].alt; alpha(div, opac); if (scton == 0) { sc(j); num = -2; scrolltxt(); scton = 1 }; if (opac < 100) { timer = setTimeout(fadeon, interv2) } else { timer2 = setTimeout(fadeout, interv); }; }
    //渐隐
    var fadeout = function () { opac -= 5; div.innerHTML = li[j].innerHTML; alpha(div, opac); if (scton == 0) { num = 2; scrolltxt(); scton = 1 }; if (opac > 0) { timer = setTimeout(fadeout, interv2) } else { if (j < li.length - 1) { j++ } else { j = 0 }; fadeon() }; }
    //滚动文字
    var scrolltxt = function () { t += num; span.style.marginTop = t + "px"; if (num < 0 && t > 3) { timer3 = setTimeout(scrolltxt, interv2) } else if (num > 0 && t < 62) { timer3 = setTimeout(scrolltxt, interv2) } else { scton = 0 } };
    fadeon();
}
/********************图片轮播切换结束************************/

/********************表单验证开始************************/
function LoginSubmit() {
    var hid_DCtype = $("#UserName").val();
    if (hid_DCtype == "") {
        $.ligerDialog.warn('账户名称不能为空');
        return false;
    }
    var hid_Dlan = $("#Password").val();
    if (hid_Dlan == "") {
        $.ligerDialog.warn('密码不能为空');
        return false;
    }
}
/********************表单验证结束************************/

/********************密码强度验证开始************************/
/**
* 密码强度验证
* @param input_field_id 需要验证的TextBox的ID
* @param output_display_id 显示验证结果图片区域DIV的ID
**/
function update_strength(input_field_id, output_display_id) {
    var input_field = document.getElementById(input_field_id);
    var output_display = document.getElementById(output_display_id);

    var input_str = input_field.value;
    var input_length = input_str.length;

    var strength = 0;

    number_re = new RegExp("[0-9]");
    if (number_re.test(input_str)) {
        strength++;
    }

    non_alpha_re = new RegExp("[^A-Za-z0-9]");
    if (non_alpha_re.test(input_str)) {
        strength++;
    }

    upper_alpha_re = new RegExp("[A-Z]");
    if (upper_alpha_re.test(input_str)) {
        strength++;
    }

    if (input_length >= 8) {
        strength++;
    }

    var strength_str;
    if (strength <= 1) {
        strength_str = '<img src="http://f.8666.com/images/icon/Icon_48.gif" />';
    } else if (strength <= 2) {
        strength_str = '<img src="http://f.8666.com/images/icon/Icon_49.gif" />';
    } else {
        strength_str = '<img src="http://f.8666.com/images/icon/Icon_50.gif" />';
    }
    if (input_str.length < 6) {
        strength_str = '<img src="http://f.8666.com/images/icon/Icon_47.gif" />';
    }
    output_display.innerHTML = strength_str; output_display.style.display = "";
}
/********************密码强度验证结束************************/

/********************对话框开始************************/

/********************对话框开始************************/

/********************常用方法开始************************/
/**
* 时间对象的格式化;
    var testDate = new Date();
    var testStr = testDate.format("YYYY年MM月dd日hh小时mm分ss秒");
    alert(testStr);
*/
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;
}
/**
* 比较两个日期的大小（日期格式为yyyy-MM-dd）
*/
function TimeCompare(a, b) {
    var arr = a.split("-");
    var starttime = new Date(arr[0], arr[1], arr[2]);
    var starttimes = starttime.getTime();
    var arrs = b.split("-");
    var endtime = new Date(arrs[0], arrs[1], arrs[2]);
    var endtimes = endtime.getTime();
    if (starttimes > endtimes)//开始大于结束
    {
        return false;
    }
    else {
        return true;
    }
}
/*
检查输入结束日期是否在今天之后，结束如期格式：yy-MM-dd
结束如期>=起始日期
输入：
startDate：起始日期，字符串
endDate：结束如期，字符串
返回：
如果通过验证返回true,否则返回false
*/
function checkEndDate(edate) {
    var today = getNowFormatDate();
    var startDate = new Date(today.replace("-", ",")).getTime();
    var endDate = new Date(edate.replace("-", ",")).getTime();
    if (startDate > endDate) {
        return false;
    }
    return true;
}
/**
* 获得系统当前时间（日期格式为yyyy-MM-dd）
*/
function getNowFormatDate() {
    var day = new Date();
    var Year = 0;
    var Month = 0;
    var Day = 0;
    var CurrentDate = "";
    //初始化时间  
    Year = day.getFullYear();
    Month = day.getMonth() + 1;
    Day = day.getDate();
    CurrentDate += Year + "-";
    if (Month >= 10) {
        CurrentDate += Month + "-";
    } else {
        CurrentDate += "0" + Month + "-";
    }
    if (Day >= 10) {
        CurrentDate += Day;
    } else {
        CurrentDate += "0" + Day;
    }
    return CurrentDate;
}
/**
* 在数组中寻找子串
* var a=new Array('aa1321321','b4323424b','cc345345','dd4654','dd4654','b4323424b');
* document.getElementById('t2').value=a.indexOf('cc345345');
*/
Array.prototype.indexOf = function (substr, start) {
    var ta, rt, d = '\0';
    if (start != null) { ta = this.slice(start); rt = start; } else { ta = this; rt = 0; }
    var str = d + ta.join(d) + d, t = str.indexOf(d + substr + d);
    if (t == -1) return -1; rt += str.slice(0, t).replace(/[^\0]/g, '').length;
    return rt;
}
/**
* 在数组中寻找子串
* var a=new Array('aa1321321','b4323424b','cc345345','dd4654','dd4654','b4323424b');
* document.getElementById('t3').value=a.lastIndexOf('dd4654')
*/
Array.prototype.lastIndexOf = function (substr, start) {
    var ta, rt, d = '\0';
    if (start != null) { ta = this.slice(start); rt = start; } else { ta = this; rt = 0; }
    ta = ta.reverse(); var str = d + ta.join(d) + d, t = str.indexOf(d + substr + d);
    if (t == -1) return -1; rt += str.slice(t).replace(/[^\0]/g, '').length - 2;
    return rt;
}
/**
* 正则替换数组中
* var a=new Array('aa1321321','b4323424b','cc345345','dd4654','dd4654','b4323424b');
* document.getElementById('t4').value=a.replace(/\d/g,'*');
*/
Array.prototype.replace = function (reg, rpby) {
    var ta = this.slice(0), d = '\0';
    var str = ta.join(d); str = str.replace(reg, rpby);
    return str.split(d);
}
/**
* 在数组中查找字符数量
* var a=new Array('aa1321321','b4323424b','cc345345','dd4654','dd4654','b4323424b');
* document.getElementById('t5').value=a.search(/dd4654/);
*/
Array.prototype.search = function (reg) {
    var ta = this.slice(0), d = '\0', str = d + ta.join(d) + d, regstr = reg.toString();
    reg = new RegExp(regstr.replace(/\/((.|\n)+)\/.*/g, '\\0$1\\0'), regstr.slice(regstr.lastIndexOf('/') + 1));
    t = str.search(reg); if (t == -1) return -1; return str.slice(0, t).replace(/[^\0]/g, '').length;
}
/**
*数组重合性冲突判断
*使用：
    var test = new ArrayConflict("vistordata");
    var arr = [["2|3", "1|4"], ["5|6", "7|8"]];
    var arrdate =
    [
	    ["2011-09-01|2012-11-11","2011-09-01|2012-11-11"],
        ["2012-04-05|2012-07-07","2012-04-05|2012-07-07","2012-04-05|2012-07-07","2012-04-05|2012-07-07","2012-04-05|2012-07-07"],
	    ["2012-04-05|2012-07-07","2012-04-05|2012-07-07","2012-04-05|2012-07-07"]
    ];
    //判断数字是否冲突
    window.alert(test.JudgeConflict(arr,false));
    window.alert(test.GetConflict(arr, false));
    //判断日期是否冲突
    window.alert(test.JudgeConflict(arrdate, true));
    window.alert(test.GetConflict(arrdate, true));
*/
function ArrayConflict() {
    var self = this;
    var trim = function (str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

    var init = function () {
    }
    init();

    //数字比较函数1。（用于第一级）
    var StringSort1 = function (a, b) {
        return a - b;
    }
    //数字比较函数2。（用于第二级）
    var StringSort2 = function (a, b) {
        return a.toString().split("|")[0] - b.toString().split("|")[0];
    }

    //日期比较函数1。需要先将字符串转化为日期类型。（用于第一级）
    var StringDateSort1 = function (a, b) {
        var ta = new Date(a.toString());
        var tb = new Date(b.toString());
        return ta - tb;
    }
    //日期比较函数2。需要先将字符串转化为日期类型。（用于第二级）
    var StringDateSort2 = function (a, b) {
        var ta = new Date(a.toString().split("|")[0]);
        var tb = new Date(b.toString().split("|")[0]);
        return ta - tb;
    }

    //返回是否有冲突（true or false）
    this.JudgeConflict = function (arr, ifDate) {
        var a = arr.join(",").split(",").sort(ifDate ? StringDateSort2 : StringSort2); //第二级排序最终二维数组
        var arr2 = a.join("|").split("|"); //第二级排序最终一维数组
        var arr1 = arr2.concat([]).sort(ifDate ? StringDateSort1 : StringSort1); //第一级排序最终一维数组
        return arr1.toString() != arr2.toString();
    }

    //返回冲突的序号数组
    this.GetConflict = function (arr, ifDate) {
        var a = arr.join(",").split(",").sort(ifDate ? StringDateSort2 : StringSort2); //第二级排序最终二维数组
        var arr2 = a.join("|").split("|"); //第二级排序最终一维数组
        var arr1 = arr2.concat([]).sort(ifDate ? StringDateSort1 : StringSort1); //第一级排序最终一维数组
        var l = arr1.length; //获取长度
        var arrC = []; //冲突数组
        for (var i = 0; i < l; i++) {
            if (arr1[i] != arr2[i]) {
                //如果不对应，说明此处冲突，将其加入到冲突数组;
                var c = Math.round(i % 2 == 0 ? (i / 2) : (i - 1) / 2);
                arrC = arrC.concat(a[c]);
            }
        }

        arrC = arrC.concat("");
        arrC = [""].concat(arrC);

        var arrR = []; //结果数组，记录有冲突的原始索引
        var L = arr.length;
        for (var i = 0; i < L; i++) {
            var l = arr[i].length;
            for (var j = 0; j < l; j++) {
                if (arrC.toString().indexOf("," + arr[i][j].toString() + ",") >= 0)
                    arrR = arrR.concat(i + "|" + j);
            }
        }
        return arrR;
    }
    //返回有冲突的数组序号
    this.GetConArrayflict = function (arr, ifDate) {
        var a = arr.join(",").split(",").sort(ifDate ? StringDateSort2 : StringSort2); //第二级排序最终二维数组
        var arr2 = a.join("|").split("|"); //第二级排序最终一维数组
        var arr1 = arr2.concat([]).sort(ifDate ? StringDateSort1 : StringSort1); //第一级排序最终一维数组
        var l = arr1.length; //获取长度
        var arrC = []; //冲突数组
        for (var i = 0; i < l; i++) {
            if (arr1[i] != arr2[i]) {
                //如果不对应，说明此处冲突，将其加入到冲突数组;
                var c = Math.round(i % 2 == 0 ? (i / 2) : (i - 1) / 2);
                arrC = arrC.concat(a[c]);
            }
        }

        arrC = arrC.concat("");
        arrC = [""].concat(arrC);

        var arrR = []; //结果数组，记录有冲突的原始索引
        var L = arr.length;
        for (var i = 0; i < L; i++) {
            var l = arr[i].length;
            for (var j = 0; j < l; j++) {
                if (arrC.toString().indexOf("," + arr[i][j].toString() + ",") >= 0) {
                    arrR = arrR.concat(i);
                }
            }
        }
        
        return arrR.ArrayHeavy();
    }
    //快速判断是否冲突
    //循环对照判断最终数组，根据序号组成冲突的新二维数组
    //循环初始数组，返回序号二维数组
}
/**
*数组重合性冲突判断
*使用：
var b = [2,2,3,4,3,5,7]; 
var c =b.ArrayHeavy();
*/
Array.prototype.ArrayHeavy = function () {
    var temp = {}, len = this.length;
    for (var i = 0; i < len; i++) {
        if (typeof temp[this[i]] == "undefined") {
            temp[this[i]] = 1;
        }
    }
    this.length = 0;
    len = 0;
    for (var i in temp) {
        this[len++] = i;
    }
    return this;
}
/**
*关闭浏览器窗口
*/
function CloseWindow() {
    if (confirm("您确定要关闭本页吗？")) {
        self.opener = null;
        self.open('', '_self');
        self.close();
    }
}
/**
*获取当前url参数
*/
function getUrlArgs(strName) {
    var strHref = document.location.toString();
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1); //==========获取到右边的参数部分
    var arrTmp = strRight.split("&"); //=============以&分割成数组

    for (var i = 0; i < arrTmp.length; i++) //===========循环数组
    {
        var dIntPos = arrTmp[i].indexOf("=");
        var paraName = arrTmp[i].substr(0, dIntPos);
        var paraData = arrTmp[i].substr(dIntPos + 1);
        if (paraName.toUpperCase() == strName.toUpperCase()) {
            return paraData;
        }
    }
    return "";
}
/********************常用方法结束************************/

/********************Cookies开始************************/
/**
*获取cookie
*/
function getCookie(cookieName) {
    var cookieString = document.cookie;
    var start = cookieString.indexOf(cookieName + '=');
    if (start == -1)
        return null;
    start += cookieName.length + 1;
    var end = cookieString.indexOf(';', start);
    if (end == -1) return unescape(cookieString.substring(start));
    return unescape(cookieString.substring(start, end));
}
/**
*设置cookie
*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
}
/**
*删除cookie
*/
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
/*******************Cookies结束************************/

