﻿/*
* 函数说明：防163删除确认对话框
* 参数：	服务器端要触发事件的Button的ID，提示消息
* 时间：2008-06-18
*/
var flag = false;
function confirmOperate(ServerControlId, msg) {
    hide();
    Container = document.createElement('div');
    Container.id = 'dvConformOperate';
    Container.style.display = '';
    Container.style.zIndex = '999';
    Container.style.position = 'absolute';
    Container.style.textAlign = 'left';
    Container.style.top = '100px';
    Container.style.left = '50%';
    Container.style.width = "350px";
    Container.style.backgroundColor = "#FFFFFF";
    html = "<table width=\"100%\" border=\"0\" cellspacing=\"0\">";
    html += "        <tr>";
    html += "          <td align=\"center\" class=\"tsbg\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr>";
    html += "              <td width=\"44%\" height=\"25\" align=\"left\" class=\"color02\">提示信息</td>";
    html += "              <td width=\"56%\" align=\"right\" valign=\"top\"><img id=\"imgCloseMsg\" src=\"/images/close002.gif\" style=\"cursor:pointer\" width=\"20\" height=\"23\" border=\"0\" onClick=\"IsConfirm(false,'" + ServerControlId + "')\" /></td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "        <tr>";
    html += "          <td height=\"60\" align=\"center\"><table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr>";
    html += "              <td width=\"14%\" align=\"left\"><img src=\"/images/ts.gif\" alt=\"提示信息\" width=\"36\" height=\"36\" /></td>";
    html += "              <td width=\"86%\" align=\"left\"><span class=\"f09\">" + msg + "</span></td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "        <tr id=\"msgBtns\">";
    html += "          <td align=\"center\" class=\"tdbg\"><table width=\"200\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr align=\"center\">";
    html += "              <td width=\"100\">";
    html += "                <img src=\"/images/btn-023.gif\" id=\"img_confirmMsg\" style=\"cursor:pointer\" width=\"62\" height=\"21\" border=\"0\" onclick=\"IsConfirm(true,'" + ServerControlId + "')\" />";
    html += "                </td>";
    html += "              <td width=\"100\" height=\"28\" >";
    html += "                <img src=\"/images/btn-016.gif\" id=\"img_cancelMsg\" style=\"cursor:pointer\" width=\"62\" height=\"21\" border=\"0\" onclick=\"IsConfirm(false,'" + ServerControlId + "')\" />";
    html += "              </td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "      </table>";

    Container.innerHTML = html;
    document.body.appendChild(Container);
    setCenterDisplay(Container);
    $('#dvConformOperate').draggable({ axis: null, handle: '.tsbg' });
    if (flag) {
        return true;
    }
    else {
        return false;
    }
}


/*
* 函数说明：防163删除确认对话框调用方法
* 参数：	
* 作者：zengxie
* 时间：2008-11-03
*/
function IsConfirm(obj, ControlId) {
    if (obj == true) {
        cancel();
        document.body.removeChild(document.getElementById('dvConformOperate'));
        flag = true;
        document.getElementById(ControlId).click();
    }
    else {
        cancel();
        flag = false;
        document.body.removeChild(document.getElementById('dvConformOperate'));
        return false;
    }
}


/*
* 函数说明：防163确认对话框,点击确定后就跳转
* 参数：	服务器端要触发事件的Button的ID，提示消息
* 作者：曾协
* 时间：2008-11-25
*/
function alertOperateReLoad(msg, Url) {
    hide();
    Container = document.createElement('div');
    Container.id = 'dvConformOperate';
    Container.style.display = 'block';
    Container.style.zIndex = '9999';
    Container.style.position = 'absolute';
    Container.style.marginLeft = '-175px';
    Container.style.textAlign = 'left';
    Container.style.top = '100px';
    Container.style.left = '50%';
    Container.style.width = "350px";
    Container.style.backgroundColor = "#FFFFFF";
    html = "<table width=\"100%\" border=\"0\" cellspacing=\"0\">";
    html += "        <tr>";
    html += "          <td align=\"center\" class=\"tsbg\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr>";
    html += "              <td width=\"44%\" height=\"25\" align=\"left\" class=\"color02\">提示信息</td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "        <tr>";
    html += "          <td height=\"60\" align=\"center\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr>";
    html += "              <td width=\"14%\" align=\"left\"><img src=\"/images/ts.gif\" alt=\"提示信息\" width=\"36\" height=\"36\" /></td>";
    html += "              <td width=\"86%\" align=\"left\"><h3 id=\"tripMsg\">" + msg + "</h3>&nbsp;&nbsp;</td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "        <tr id=\"msgBtns\">";
    html += "          <td align=\"center\" class=\"tdbg\"><table width=\"200\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "            <tr align=\"center\">";
    html += "              <td width=\"100\">";
    html += "                <img src=\"/images/btn-023.gif\" id=\"img_confirmMsg\" style=\"cursor:pointer\" width=\"62\" height=\"21\" border=\"0\" onclick=\"IsReload('" + Url + "')\" />";
    html += "                </td>";
    html += "            </tr>";
    html += "          </table></td>";
    html += "        </tr>";
    html += "      </table>";
    Container.innerHTML = html;
    document.body.appendChild(Container);
}

function isReload(url) {
    window.location.href = url;
}

//
//控制DIV的隐藏与显示
function displayDiv(id, b) {
    b = b ? "" : "none";
    document.getElementById(id).style.display = b;
}

//得到一个元素的屏幕的坐标
function getStation(o) {
    var to = new Object();
    to.left = to.right = to.top = to.bottom = 0;
    var twidth = o.offsetWidth;
    var theight = o.offsetHeight;
    while (o && o.tagName != 'BODY' && o.tagName != 'HTML') {//用循环得到对象的坐标
        to.left += o.offsetLeft;
        to.top += o.offsetTop;
        o = o.parentElement;
    }
    to.right = to.left + twidth;
    to.bottom = to.top + theight;
    return to;
}

//得到一个元素的X轴的绝对坐标
function getLeft(e) {
    var offset = e.offsetLeft;
    if (e.offsetParent != null) offset += getLeft(e.offsetParent);
    return offset;
}

//得到一个元素的Y轴的绝对坐标
function getTop(e) {
    var offset = e.offsetTop;
    if (e.offsetParent != null) offset += getTop(e.offsetParent);
    return offset;
}
//设置一个元素在屏幕中心显示
function setCenterDisplay(objdiv) {
    if (objdiv != null) {
        objdiv.style.display = "";
        var styleWidth = objdiv.style.width.substring(0, objdiv.style.width.length - 2);
        var clientHeight = objdiv.clientHeight;
        var objLeft = parseInt(document.documentElement.scrollLeft + (document.documentElement.clientWidth - styleWidth) / 2) + 'px';
        var relTop = (document.documentElement.clientHeight - clientHeight) / 2 > 0 ? (document.documentElement.clientHeight - clientHeight) / 2 : 0;
        var objTop = (parseInt(document.documentElement.scrollTop + relTop) - 20) + 'px';
        objdiv.style.top = objTop;
        objdiv.style.left = objLeft;
        checkAndResetStyleTopN(objdiv);
    }
}
//设置一个元素在屏幕中心显示-----辅助方法
function checkAndResetStyleTopN(obj) {
    var clientHeight = obj.firstChild.clientHeight;
    var bodyScrollHeight = document.body.scrollHeight;
    var styleTop = parseInt(obj.style.top.substring(0, obj.style.top.length - 2));
    if (clientHeight + styleTop > bodyScrollHeight) {
        //        obj.style.top = (bodyScrollHeight - clientHeight) + 'px';
    }
}

//显示操作成功后的提示，自动转向到href
function showOperateResult(msg, href) {
    hide();
    document.getElementById("spSeconds").style.display = "block";
    document.getElementById("msgBtns").style.display = "none";
    document.getElementById("imgCloseMsg").style.display = "none";
    document.getElementById("Layer12").style.display = "block";
    document.getElementById("tripMsg").innerHTML = msg;
    $(document).ready(function () {
        setCenterDisplay(document.getElementById("Layer12")); cancel();
        window.setTimeout("window.location.href='" + href + "';", 1000);
    });
}


function DoubleAnimation(target, targetProperty, from, to, Duration) {
    this.Begin = function anonymous() {
        target[targetProperty] = from;
        var starttime = new Date();
        setTimeout(StoryBoard(), 1);
        function StoryBoard() {
            return function () {
                var now = new Date();
                var d = now.getTime() - starttime.getTime();
                target[targetProperty] = Math.round(from + (to - from) * d / Duration);
                if (d < Duration) setTimeout(StoryBoard(), 10);
            }
        }
    }
    this.setTo = function (val) { to = val; }
    this.setFrom = function (val) { from = val; }
}

var Container;
var p = 0;
var pb1;
var backToUrl;
function ProgressBar(ID, msg) {
    Container.style.display = "";
    var html = "<div id=\"" + ID + "\" style=\"position:absolute;top:10%;width:100; left: 108px;\">";
    html += " <image src=\"/images/emptypb.jpg\" style=\"position: absolute;left: 84px; top: 137px;\" />";
    html += " <div id=\"" + ID + "pb\" style=\"position: absolute; left: 86px; top: 137px;z-index:5;overflow:hidden;width:130;\" > ";
    html += " <img src=\"../images/iconfullpb.jpg\"/> ";
    html += " <div id=\"" + ID + "highlight\" style=\"background:#ffffff;left: -500px; position: absolute; top: -1px;width:100;height:20;filter:Alpha(Opacity=75,FinishOpacity=0,Style=2)\"></div>        </div> ";
    html += " <div style=\"position:absolute;top:118px;width:180px;text-align:-moz-center;*text-align:center; left: 148px;\">" + msg + "</div>   </div>";

    Container.innerHTML = html;
    var story = new DoubleAnimation(document.getElementById(ID + "highlight").style, "left", -100, 324, 2000)
    var stophandle = setInterval(story.Begin, 2000);
    this.set = function (percentage) {
        document.getElementById(ID + "pb").style.width = Math.round(percentage * 329 / 100);
    }
}


function loading(ID, msg, url) {
    if (Container == undefined) {

        hide();

        Container = document.createElement('div');
        Container.id = 'globalLoadDiv';
        Container.style.display = '';
        Container.style.zIndex = '9999';
        Container.style.position = 'absolute';
        Container.style.marginLeft = '-175px';
        Container.style.textAlign = 'left';
        Container.style.top = '100px';
        Container.style.left = '30%';
        Container.style.width = "350px";

        document.body.appendChild(Container);

        pb1 = new ProgressBar(ID, msg, url);
        backToUrl = url;
    }

    pb1.set(p += 1);
    if (p < 100) {
        setTimeout(loading, 1.5);
    }
    else {
        cancel();
        document.body.removeChild(Container);
        document.getElementById("aspnetform").action = backToUrl;
        window.setTimeout("window.location.href='" + backToUrl + "';", 100);
    }
}




//显示消息框
function showTip(b, msg) {
    if (b) {
        hide();
        setCenterDisplay(document.getElementById("Layer12"));
    }
    else {
        cancel();
    }
    displayDiv("Layer12", b);
    $("#tripMsg").html(msg);
}

