﻿// JScript File
 
var h='hidden';
var b='block';
var p='px';
var v='visible';
var n='none';
var ab='absolute';
var n='none';

var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';

function ModalDialogRemoveWatch()
 {
    ModalDialog.value = '';
    ModalDialog.eventhandler = '';
 }
        
 function showModalBox(divName, width, height, Title, EventHandler)
 {   
    var obol=$('ol'); 
    var obbxd = $('mbd');
    var obbx=$('mbox');    
    var top = posTop() + ((pageHeight() - height) / 2) - 12;
    var left = posLeft() + ((pageWidth() - width) / 2) - 12;
    
    ModalDialog.eventhandler = EventHandler;
    
   	setVisibility(h);

    obbxd.innerHTML = $(divName).innerHTML;

    obol.style.height=pageHeight()+p;
    obol.style.width=pageWidth()+p;
    obol.style.top=posTop()+p;
    obol.style.left=posLeft()+p;
    obol.style.display=b;

    obbx.style.top = (top < 0 ? 0 : top) + p;
    obbx.style.left = (left < 0 ? 0 : left) + p;
    obbx.style.width = width + p;
    //obbx.style.height = height + p;


    obbx.style.display=b;

    return false;
 }
 
 function showModalInfo(divName, width, height) {
    showModalBox(divName, width, height, "", null);
 }
 
 function showProgressDialog() {
    showModalInfo('progressDialog', 270, 80);
 }
 
 function CloseForm() {
    var Response = arguments[0];
    var ShowProgressDialog = arguments[1];
    var nextFunction = null;
    var eventHandler = ModalDialog.eventhandler;
    var obbxd;
    
    ModalDialog.value = Response; 
    hideModalBox();
    
    eval(eventHandler); 
    obbxd = $('mbd');
    obbxd.innerHTML = "";
    
    ModalDialogRemoveWatch();  
    
    if (ShowProgressDialog == true) {
        showProgressDialog(); 
    } else if (nextFunction != null) {
        eval(nextFunction);
    }
 }

function pageWidth() 
{
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() 
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight : null;
}
function posLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}
function posTop() 
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
function $(x){
    return document.getElementById(x);
}
function scrollFix()
{
    var obol=$('ol');
    obol.style.top=posTop()+'px';
    obol.style.left=posLeft()+'px';
}

function sizeFix()
{
    var obol=$('ol');
    obol.style.height=pageHeight()+'px';
    obol.style.width=pageWidth()+'px';
}
function handleKeyPress(e)
{
    ky=e?e.which:event.keyCode;
    if (ky==88||ky==120) hideModalBox();
    return false;
}

function setVisibility(h)
{
	if(isInternetExplorer() && IEVersion() < 7) {
	    tag=document.getElementsByTagName('select');
	    for(i=tag.length-1;i>=0;i--)
	    {
	        var className;        
	        if (tag[i].form != null && tag[i].form.parentElement) className = tag[i].form.parentElement.className;       
	        else if (tag[i].parentElement.parentElement) className = tag[i].parentElement.parentElement.className;
	        if (className != "dialog" && className != "internalDialogContent") {
	        	try { tag[i].style.visibility=h; }
	        	catch (err) { }
	        }
	    }
	    
	    tag=document.getElementsByTagName('iframe');
	    for(i=tag.length-1;i>=0;i--) {
	        if (tag[i].name.indexOf('nitobi') == -1) { // hack to make sure background iframes aren't made visible when the dialog is closed.
	        	try { tag[i].style.visibility=h; }
	        	catch (err) { }
	        }
	    }
	      
	    tag=document.getElementsByTagName('object');
	    for(i=tag.length-1;i>=0;i--) {
	        var className;        
	        if (tag[i].parentElement.parentElement) className = tag[i].parentElement.parentElement.className;
	        else if (tag[i].form.parentElement) className = tag[i].form.parentElement.className;        
	        if (className != "dialog" && className != "internalDialogContent") {
	        	try { tag[i].style.visibility=h; }
	        	catch (err) { }
	        }
	    }
	    
	    /* 
	    tag=document.getElementsByTagName('button');
	    for(i=tag.length-1;i>=0;i--) {
	        if (tag[i].form.parentElement.className != "dialog" && tag[i].form.parentElement.className != "internalDialogContent")
	            tag[i].style.visibility=h;
	    }
	   
	    tag=document.getElementsByTagName('input');
	    for(i=tag.length-1;i>=0;i--) { 
	        if (tag[i].type == "submit" || tag[i].type == "button") {       
	            if (typeof(tag[i].form) == "undefined" || (tag[i].form.parentElement.className != "dialog" && tag[i].form.parentElement.className != "internalDialogContent"))
	                tag[i].style.visibility=h;
	        }
	    }
	    */
    }
}

function hideModalBox()
{
    $('ol').style.display=n;
    $('mbox').style.display=n;
    setVisibility(v);
    document.onkeypress='';
}

function initializeModalBox()
{
    var obody, frag, obol, obbx, obl, obbxd;
    
    obody = document.getElementsByTagName('body')[0];
    frag = document.createDocumentFragment();
    obol = document.createElement('div');
    
    obol.setAttribute('id', 'ol');
    obol.style.display=n;
    obol.style.position=ab;
    obol.style.top=0;
    obol.style.left=0;
    obol.style.zIndex=998;
    obol.style.width='100%';
    frag.appendChild(obol);
    
    obbx = document.createElement('div');
    obbx.setAttribute('id', 'mbox');
    obbx.style.display=n;
    obbx.style.position=ab;
    obbx.style.zIndex=999;
    
    obl = document.createElement('span');
    obbx.appendChild(obl);
    
    obbxd = document.createElement('div');
    obbxd.setAttribute('id', 'mbd');
    obl.appendChild(obbxd);
    frag.insertBefore(obbx, obol.nextSibling);
    obody.insertBefore(frag, obody.firstChild);
    
    window.onscroll = scrollFix; 
    window.onresize = sizeFix;
}
