var _dialogPromptID1 = null;
var _blackoutPromptID1 = null;
var JJBackDiv = null;
var JJAnimationID;
var JJTbl, JJH, JJH1, JJW, JJW1, JJI;
var tbl;

function JJAnimation() {
    //debugger;
    if (parseInt(tbl.style.height) < JJH) {
        tbl.style.height = parseInt(parseInt(tbl.style.height) + 10) + 'px';
        tbl.style.top = parseInt(parseInt(tbl.style.top) - 5) + 'px';
    }
    if (parseInt(tbl.style.width) < JJW) {
        tbl.style.width = parseInt(parseInt(tbl.style.width) + 10) + 'px';
        tbl.style.left = parseInt(parseInt(tbl.style.left) - 5) + 'px';
    }

    //            tbl.style.height = parseInt(parseInt(tbl.style.height) + 10) + 'px';
    //            tbl.style.width = parseInt(parseInt(tbl.style.width) + 10) + 'px';
    //            tbl.style.top = parseInt(parseInt(tbl.style.top) - 5) + 'px';
    //            tbl.style.left = parseInt(parseInt(tbl.style.left) - 5) + 'px';
    //            
    if ((parseInt(tbl.style.width) >= JJW) && (parseInt(tbl.style.height) >= JJH)) {
        clearInterval(JJAnimationID);
    }

}
function JJModelPopUp(tblPopUp, tblPopUpMove, btnCancel, ControlToFocus, Isddl) {
    tbl = tblPopUp;
    //tbl.style.width = parseInt(W / 2) + 'px';
    //tbl.style.height = parseInt(H / 2) + 'px';
    //    tbl.style.top = parseInt(parseInt(document.documentElement.scrollTop + (screen.height / 2)) - 100) + 'px';
    //    tbl.style.left = parseInt((document.body.offsetWidth - 150) / 2) + 'px';
    //debugger;
    //    JJH = H;
    //    JJW = W;
    //    JJAnimationID = setInterval("JJAnimation()", 30);
    //debugger;
    btnCancel.onclick = function Test() {
        //debugger;
        if (Isddl) {
            Isddl.selectedIndex = 0;
        }
        document.getElementById('BackDiv').style.display = 'none';
        tblPopUp.style.display = 'none';
        return false;

    }

    if (!tbl) {
        tbl = document.getElementById('IEPromptBox1');
    }
    tbl.style.display = 'inline';
    var tbody = document.getElementsByTagName("body")[0];
    var tDiv = document.createElement('div');
    tDiv.id = 'BackDiv';
    tbody.appendChild(tDiv);
    JJBackDiv = document.getElementById('BackDiv');

    //////tnode = tbl;
    //////tnode.id = 'IEPromptBox1';
    //////tbody.appendChild(tnode);
    //////_dialogPromptID1 = document.getElementById('IEPromptBox1');
    //////tnode = document.createElement('div');
    //////tnode.id = 'promptBlackout1';
    //////tbody.appendChild(tnode);
    //////_blackoutPromptID1 = document.getElementById('promptBlackout1');
    JJBackDiv.style.opacity = '.9';
    JJBackDiv.style.position = 'absolute';
    JJBackDiv.style.top = '0px';
    JJBackDiv.style.left = '0px';
    JJBackDiv.style.backgroundColor = '#f3f3ff';
    JJBackDiv.style.filter = 'alpha(opacity=90)';
    JJBackDiv.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
    JJBackDiv.style.display = 'block';
    JJBackDiv.style.zIndex = '50';
    // assign the styles to the dialog box
    //_dialogPromptID1.style.border = '2px solid blue';
    //_dialogPromptID1.style.backgroundColor = '#DDDDDD';
    tbl.style.position = 'absolute';
    //_dialogPromptID1.style.width = '330px';
    tbl.style.zIndex = '100';
    JJBackDiv.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
    JJBackDiv.style.width = '100%';
    JJBackDiv.style.display = 'block';
    tbl.style.top = parseInt(document.documentElement.scrollTop + (screen.height / 3)) + 'px';
    tbl.style.left = parseInt((document.body.offsetWidth - 315) / 2) + 'px';
    tbl.style.display = 'block';
    tblPopUpMove.style.cursor = 'move';
    //tblPopUpMove.style.backgroundColor = '#ffffff';
    //tblPopUpMove.style.border = '1px solid white';
    if (ControlToFocus) {
        ControlToFocus.focus();
    }
    Drag.init(tblPopUpMove, tbl);
    //tblPopUp.width = 300;
    //tblPopUp.height = 150;
    return false;
}










var _dialogPromptID = null;
var _blackoutPromptID = null;
var _JJDivLoading = null;
var _JJDivBody = null;
///////////////////////////////////////////////////////////

function IEprompt(innertxt, def, CallBackFunction) {
    // debugger;
    that = this;

    // Check to see if this is MSIE 7.   This isn't a great general purpose
    // detection system but it works well enough just to find MSIE 7.
    var _isIE7 = (navigator.userAgent.indexOf('MSIE 7') > 0);

    this.wrapupPrompt = function(cancled) {
        // debugger;
        // wrapupPrompt is called when the user enters or cancels the box.
        // It's called only by the IE7 dialog box, not the non IE prompt box
        //////       if (_isIE7) {



        // Make sure we're in IE7 mode and get the text box value
        val = document.getElementById('iepromptfield').value;
        //////           // clear out the dialog box
        //////           _dialogPromptID.style.display = 'none';
        //////           // clear out the screen
        //////           _blackoutPromptID.style.display = 'none';
        //////           // clear out the text field
        //////           document.getElementById('iepromptfield').value = '';
        // if the cancel button was pushed, force value to null.
        if (cancled) { val = '' }
        // call the user's function
        window[CallBackFunction](val);
        //////       }
        return false;
    }

    //if def wasn't actually passed, initialize it to null
    if (def == undefined) { def = ''; }
    //debugger;
    //////   if (_isIE7) {
    // If this is MSIE 7.0 then...
    if (_dialogPromptID == null) {
        // Check to see if we've created the dialog divisions.
        // This block sets up the divisons
        // Get the body tag in the dom
        var tbody = document.getElementsByTagName("body")[0];
        // create a new division
        tnode = document.createElement('div');
        // name it
        tnode.id = 'IEPromptBox';
        // attach the new division to the body tag
        tbody.appendChild(tnode);
        // and save the element reference in a global variable
        _dialogPromptID = document.getElementById('IEPromptBox');
        // Create a new division (blackout)
        tnode = document.createElement('div');
        // name it.
        tnode.id = 'promptBlackout';
        // attach it to body.
        tbody.appendChild(tnode);
        // And get the element reference
        _blackoutPromptID = document.getElementById('promptBlackout');
        // assign the styles to the blackout division.
        _blackoutPromptID.style.opacity = '.9';
        _blackoutPromptID.style.position = 'absolute';
        _blackoutPromptID.style.top = '0px';
        _blackoutPromptID.style.left = '0px';
        _blackoutPromptID.style.backgroundColor = '#ffffff';
        _blackoutPromptID.style.filter = 'alpha(opacity=90)';
        _blackoutPromptID.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
        _blackoutPromptID.style.display = 'block';
        _blackoutPromptID.style.zIndex = '50';
        // assign the styles to the dialog box
        _dialogPromptID.style.border = '2px solid #253958';
        _dialogPromptID.style.backgroundColor = '#DDDDDD';
        _dialogPromptID.style.position = 'absolute';
        _dialogPromptID.style.width = '330px';
        _dialogPromptID.style.zIndex = '100';
    }
    // This is the HTML which makes up the dialog box, it will be inserted into
    // innerHTML later. We insert into a temporary variable because
    // it's very, very slow doing multiple innerHTML injections, it's much
    // more efficient to use a variable and then do one LARGE injection.
    var tmp = '<div id="DivHeader" style="width: 100%; background-color: #253958; color: white; font-family: arial; font-size: 10pt; font-weight: bold; height: 20px">Input Required</div>';
    tmp += '<div style="padding: 10px;font-family: arial;background-color: #eaf1f7;">' + innertxt + '<BR><BR>';
    tmp += '<form action="" onsubmit="return that.wrapupPrompt()">';
    tmp += '<input id="iepromptfield"  name="iepromptdata" type=text size=46 value="' + def + '">';
    tmp += '<br><br><center>';
    tmp += '<input type="submit" value="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;">';
    tmp += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    tmp += '<input type="button" onclick="that.wrapupPrompt(true)" value="&nbsp;Cancel&nbsp;">';
    tmp += '</form></div>';

    // Stretch the blackout division to fill the entire document
    // and make it visible.  Because it has a high z-index it should
    // make all other elements on the page unclickable.
    _blackoutPromptID.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
    _blackoutPromptID.style.width = '100%';
    _blackoutPromptID.style.display = 'block';
    // Insert the tmp HTML string into the dialog box.
    // Then position the dialog box on the screen and make it visible.
    _dialogPromptID.innerHTML = tmp;
    _dialogPromptID.style.top = parseInt(document.documentElement.scrollTop + (screen.height / 3)) + 'px';
    _dialogPromptID.style.left = parseInt((document.body.offsetWidth - 315) / 2) + 'px';
    _dialogPromptID.style.display = 'block';
    // Give the dialog box's input field the focus.
    document.getElementById('iepromptfield').focus();
    document.getElementById('iepromptfield').select();
    document.getElementById("DivHeader").style.cursor = 'move';
    Drag.init(document.getElementById("DivHeader"), _dialogPromptID);


}


function JJBeginLoad() {

    //debugger;
    var tbody = document.getElementsByTagName("body")[0];
    tnode = document.createElement('div');
    tnode.id = 'JJDivLoading';
    tbody.appendChild(tnode);
    _JJDivLoading = document.getElementById('JJDivLoading');
    tnode = document.createElement('div');
    tnode.id = 'JJDivBody';
    tbody.appendChild(tnode);
    _JJDivBody = document.getElementById('JJDivBody');
    ////        //_JJDivBody.style.opacity = '.9';
    _JJDivBody.style.position = 'absolute';
    _JJDivBody.style.top = '0px';
    _JJDivBody.style.left = '0px';
    _JJDivBody.style.backgroundColor = 'transparent';
    ////        //_JJDivBody.style.filter = 'alpha(opacity=90)';
    _JJDivBody.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
    ////       // _JJDivBody.style.display = 'block';
    _JJDivBody.style.zIndex = '150';
    //        _JJDivLoading.style.border = '2px solid blue';
    //        _dialogPromptID.style.backgroundColor = 'transparent';
    _JJDivLoading.style.position = 'absolute';
    //        _dialogPromptID.style.width = '330px';
    _JJDivLoading.style.zIndex = '200';
    var URL;
    //URL = "http://" + window.location.host + "/images/progress-indicator.gif";
    URL = "http://" + window.location.host + "/eDeskServices/images/progress-indicator.gif";
    var tmp = '<img src=' + URL + ' alt="Please Wait.!!"  />';
    //tmp += '<BR/>Please Wait...';
    _JJDivBody.style.height = (document.body.offsetHeight < screen.height) ? screen.height + 'px' : document.body.offsetHeight + 20 + 'px';
    _JJDivBody.style.width = '100%';
    _JJDivBody.style.display = 'block';
    _JJDivBody.style.cursor = 'wait';
    _JJDivLoading.style.cursor = 'wait';

    _JJDivLoading.innerHTML = tmp;
    _JJDivLoading.style.top = parseInt(document.documentElement.scrollTop + (screen.height / 3)) + 'px';
    _JJDivLoading.style.left = parseInt((document.body.offsetWidth - 130) / 2) + 'px';
    _JJDivLoading.style.display = 'block';
    _JJDivLoading.style.fontFamily = 'Arial';
    _JJDivLoading.style.fontWeight = 'bold';
    _JJDivLoading.style.color = 'red';



}

function JJEndLoad() {
    //debugger;
    document.getElementById('JJDivLoading').style.display = 'none';
    document.getElementById('JJDivBody').style.display = 'none';
    document.getElementById('JJDivBody').style.cursor = 'auto';
    document.getElementById('JJDivLoading').style.cursor = 'auto';

}


var Drag = {

    obj: null,

    init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
        o.onmousedown = Drag.start;

        o.hmode = bSwapHorzRef ? false : true;
        o.vmode = bSwapVertRef ? false : true;

        o.root = oRoot && oRoot != null ? oRoot : o;

        if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
        if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX = typeof minX != 'undefined' ? minX : null;
        o.minY = typeof minY != 'undefined' ? minY : null;
        o.maxX = typeof maxX != 'undefined' ? maxX : null;
        o.maxY = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart = new Function();
        o.root.onDragEnd = new Function();
        o.root.onDrag = new Function();
    },

    start: function(e) {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        o.root.onDragStart(x, y);

        o.lastMouseX = e.clientX;
        o.lastMouseY = e.clientY;

        if (o.hmode) {
            if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
            if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
            if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove = Drag.drag;
        document.onmouseup = Drag.end;

        return false;
    },

    drag: function(e) {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey = e.clientY;
        var ex = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper) nx = o.xMapper(y)
        else if (o.yMapper) ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX = ex;
        Drag.obj.lastMouseY = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end: function() {
        document.onmousemove = null;
        document.onmouseup = null;
        Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE: function(e) {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};
