﻿// alert related begin
function createTag(tag) { return document.createElement(tag); }
/*==半透明透明层==*/
var oWinBg, oAlertWrap, oAlertWrapLeft, winSt, aSelect
var createAlert = function() {
    oWinBg = createTag('div');
    oWinBg.id = 'winBg';
    oWinBg.style.height = (document.body.clientHeight < document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight + 'px';
    document.body.appendChild(oWinBg);
    oWinBg.style.display = 'none';
    //Element.hide(oWinBg);
    /*==提示对话框==*/
    oAlertWrap = createTag('div');
    oAlertWrap.id = 'alertWrap';
    oAlertWrapLeft = (((document.body.clientWidth < document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth) - 400) / 2 + 'px';
    oAlertWrap.style.left = oAlertWrapLeft;
    winSt = function() { return document.documentElement.scrollTop || document.body.scrollTop; }
    oAlertWrap.style.top = winSt() + 200 + 'px';
    oAlertWrap.style.display = 'none';
    //Element.hide(oAlertWrap);
    document.body.appendChild(oAlertWrap);
    aSelect = document.getElementsByTagName('select');
}
var selectHide = function() {
    //if(aSelect){aSelect.each(function(oSelect){Element.hide(oSelect);});}
}
var selectShow = function() {
    //if(aSelect){aSelect.each(function(oSelect){Element.show(oSelect);});}
}

var alertIntervalId = null;
var alertFloat = function() {
    if (oAlertWrap) {
        oAlertWrap.style.left = oAlertWrapLeft;
        clearInterval(alertIntervalId);
        alertIntervalId = setInterval(alertMove, 100);
    }
}
var alertInitSt = 0;
var alertMove = function() {
    var _st = winSt();
    if (alertInitSt != _st) {
        _st = alertInitSt + (_st - alertInitSt) / 2;
        alertInitSt = _st;
        oAlertWrap.style.top = alertInitSt + 200 + 'px';
    } else { clearInterval(alertIntervalId); }
}

window.onresize = alertFloat;
window.onscroll = alertFloat;

//Event.observe(window,'resize',alertFloat,false);
//Event.observe(window,'scroll',alertFloat,false);


if (!window.Element)
    var Element = new Object();

var alertError = function(msg, href) {
    if (!oWinBg) { createAlert(); }
    oAlertWrap.innerHTML = '<h2>Tips</h2><p>' + msg + '</p>';
    var oBtn = createTag('input');
    oBtn.type = 'button';
    oBtn.className = 'btn';
    oBtn.value = 'OK';
    oBtn.onclick = function() {
        oAlertWrap.style.display = "none";
        oWinBg.style.display = "none";
        selectShow();
        if (href) { window.location = href; }
    };
    oAlertWrap.appendChild(oBtn);
    oAlertWrap.className = 'alertError';
    selectHide();
    oWinBg.style.display = "";
    oAlertWrap.style.display = "";
    oBtn.focus();
}
var alertSuccess = function(msg, href) {
    if (!oWinBg) { createAlert(); }
    oAlertWrap.innerHTML = '<h2>Tips</h2><p>' + msg + '</p>';
    var oBtn = createTag('input');
    oBtn.type = 'button';
    oBtn.className = 'btn';
    oBtn.value = 'OK';
    oBtn.onclick = function() {
        oAlertWrap.style.display = "none";
        oWinBg.style.display = "none";
        selectShow();
        if (href) { window.location = href; }
    };
    oAlertWrap.appendChild(oBtn);
    oAlertWrap.className = 'alertSuccess';
    selectHide();
    oWinBg.style.display = "";
    oAlertWrap.style.display = "";
    oBtn.focus();
}
var alertTip = function(msg, href) {
    if (!oWinBg) { createAlert(); }
    oAlertWrap.innerHTML = '<h2>Tips</h2><p>' + msg + '</p>';
    var oBtn = createTag('input');
    oBtn.type = 'button';
    oBtn.className = 'btn';
    oBtn.value = 'OK';
    oBtn.onclick = function() {
        oAlertWrap.style.display = "none";
        oWinBg.style.display = "none";
        selectShow();
        if (href) { window.location = href; }
    };
    oAlertWrap.appendChild(oBtn);
    oAlertWrap.className = 'alertTip';
    selectHide();
    oWinBg.style.display = "";
    oAlertWrap.style.display = "";
    oBtn.focus();
}
var jconfirm = function(msg, controlId) {
    if (!oWinBg) { createAlert(); }
    oAlertWrap.innerHTML = '<h2>Comfirm Tips</h2><p>' + msg + '</p>';
    var oBtn = createTag('input');
    oBtn.type = 'button';
    oBtn.className = 'btn';
    oBtn.value = 'OK';
    oBtn.onclick = function() {
        oAlertWrap.style.display = "none";
        oWinBg.style.display = "none";
        selectShow();
        __doPostBack(controlId, '');
    };
    oAlertWrap.appendChild(oBtn);
    var oBtnCancel = createTag('input');
    oBtnCancel.type = 'button';
    oBtnCancel.className = 'btn';
    oBtnCancel.value = 'Cancel';
    oBtnCancel.onclick = function() {
        oAlertWrap.style.display = "none";
        oWinBg.style.display = "none";
        selectShow();
    };
    oAlertWrap.appendChild(oBtnCancel);
    oAlertWrap.className = 'alertConfirm';
    selectHide();
    oWinBg.style.display = "";
    oAlertWrap.style.display = "";
    oBtn.focus();
    return false;
}
// alert related end
