﻿var dlgBackGround = null;
var dlgForeGround = null;
var dlgShadow = null;
var dlgCallBackFunctionName=null;
var dlgCallBackParameter=null;
var dlgBodyScroll=null;
var dlgComboBoxes = null;
var dlgComboBoxedVisibility = null;
var _windowHandlersAttached = false;

function showModalMsg(txt, w, h)
{
    showModalDlg("TXT:" + txt, w, h, null, null);
}

function showModalMsgCallback(txt, w, h, callbackFunctionName, callbackParameter)
{
    showModalDlg("TXT:" + txt, w, h, callbackFunctionName, callbackParameter);
}

function showModalDlg(url, w, h, callbackFunctionName, callbackParameter)
{
    if (url.lastIndexOf('?')!=-1)
        url=url+'&';
    else
        url=url+'?';
    h=h.replace("px","");
    w=w.replace("px","");        
    tb_show('dgdfg',url+'placeValuesBeforeTB_=savedValues&TB_iframe=true&height='+h+'&width='+w+'&modal=true',false);
//  var oCanvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0]; 
//  if (dlgBackGround == null)
//  {
//    dlgBackGround = document.createElement("div");    
//    document.body.appendChild(dlgBackGround);
//    dlgBackGround.style.backgroundColor = "gray";
//    dlgBackGround.style.opacity = "0.7";
//    dlgBackGround.style.position = "absolute";
//    dlgBackGround.style.zIndex = "999";
//    dlgBackGround.style.top = "0px";
//    dlgBackGround.style.left = "0px";    
//  }
//  
//  if (dlgShadow == null)
//  {
//    dlgShadow = document.createElement("div");    
//    document.body.appendChild(dlgShadow);
//    dlgShadow.style.backgroundColor = "black";
//    dlgShadow.style.opacity = "0.2";
//    dlgShadow.style.position = "absolute";
//    dlgShadow.style.zIndex = "1000";
//    dlgShadow.style.top = "0px";
//    dlgShadow.style.left = "0px";
//  }

//  dlgBackGround.style.display = "block";
//  
//  if (dlgForeGround == null)
//  {
//    dlgForeGround = document.createElement("div");
//    dlgForeGround.className = "modalForeground";
//    dlgForeGround.style.backgroundColor = "white";
//    document.body.appendChild(dlgForeGround);
//    dlgForeGround.style.position="absolute";
//    dlgForeGround.style.zIndex="1001";
//  }
//  
//  dlgForeGround.style.width = w;
//  dlgForeGround.style.height = h;    
//  dlgForeGround.style.display = "block";  
// 
//  dlgShadow.style.width = w;
//  dlgShadow.style.height = h;
//  dlgShadow.style.display = "block";  
//  
//  modalLayout(); // Set up layout
//  
//  
//  if (url.substring(0, 4) == "TXT:")
//  {    
//    var zX = parseInt(h) - 30;
//    dlgForeGround.innerHTML = "<div style='padding:2px 2px 2px 2px; height:" + zX + "px'>" + url.substring(4) + "</div><div style='text-align:center;'><input type='button' onclick='returnModalValue(-1)' value='OK' /></div>";
//    dlgForeGround.style.border = "solid 1px Black";
//  }
//  else
//    dlgForeGround.innerHTML="<iframe frameborder='no' style='border:solid 1px black' src='"+url+"' width='"+w+"' height='"+h+"'></iframe>";    
//  
//  
  dlgCallBackFunctionName = callbackFunctionName;
  dlgCallBackParameter = callbackParameter;
  //dlgBodyScroll=document.body.scroll;
  //document.body.scroll = "no";  
//  
//  if (navigator.appName == "Microsoft Internet Explorer")
//  {
//    dlgBackGround.style.filter = "alpha(opacity=70)";
//    dlgShadow.style.filter = "alpha(opacity=20)";    
//  
//    // Hide all select-tag
//    var dlgComboBoxes = document.getElementsByTagName("select");
//    dlgComboBoxesVisibility = new Array();
//    for(var i=0; i<dlgComboBoxes.length; i++)
//    {        
//      dlgComboBoxesVisibility[i] = dlgComboBoxes[i].style.visibility;
//      dlgComboBoxes[i].style.visibility = "hidden";
//    }
//  }  
// 
//  if (!_windowHandlersAttached)
//  {
//    $addHandler(window, 'resize', modalLayout);
//    $addHandler(window, 'scroll', modalLayout);
//    _windowHandlersAttached = true;
//  } 
}

function modalLayout()
{
    if (dlgBackGround.style.display == "block")
    {
        var oCanvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0]; 
        var w = parseInt(dlgShadow.style.width);
        var h = parseInt(dlgShadow.style.height);
      
      if (Sys.Browser.agent == Sys.Browser.Opera) oCanvas = document.body;
      
        
        if (navigator.appName == "Microsoft Internet Explorer")
        {
            dlgBackGround.style.top = oCanvas.scrollTop + "px";
            dlgBackGround.style.left = oCanvas.scrollLeft + "px";
            dlgBackGround.style.width = oCanvas.clientWidth + "px";
            dlgBackGround.style.height = oCanvas.clientHeight + "px";
        } 
        else
        {    
            clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
            clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);   
            clientHeight = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight)+'px';
            clientWidth = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth)+'px';
    
            dlgBackGround.style.height = clientHeight;
            dlgBackGround.style.width = clientWidth;
        }

        dlgForeGround.style.top = parseInt(oCanvas.scrollTop) + (parseInt(oCanvas.clientHeight)/2) - (parseInt(h)/2) + 'px';
        dlgForeGround.style.left = parseInt(oCanvas.scrollLeft) + (parseInt(oCanvas.clientWidth)/2) - (parseInt(w)/2) + 'px';    
  
        dlgShadow.style.top = parseInt(oCanvas.scrollTop) + (parseInt(oCanvas.clientHeight)/2) - (parseInt(h)/2) + 15 + 'px';
        dlgShadow.style.left = parseInt(oCanvas.scrollLeft) + (parseInt(oCanvas.clientWidth)/2) - (parseInt(w)/2) + 15 + 'px';
    }
}

function returnModalValue(val)
{ 
    tb_remove();
   // document.body.scroll=dlgBodyScroll;
  //dlgBackGround.style.display = "none";
  //dlgForeGround.style.display = "none";
  //dlgShadow.style.display = "none";

 
//  if (navigator.appName == "Microsoft Internet Explorer")
//  {
//    // Restore "visible" status for all select-tag
//    dlgComboBoxes = document.getElementsByTagName("select"); 
//    for(var i=0; i<dlgComboBoxes.length; i++)      
//      dlgComboBoxes[i].style.visibility = dlgComboBoxesVisibility[i];    
//  }
//    
  if ((val != -1) && (dlgCallBackFunctionName != null)) //eval(dlgCallBackFunctionName+"('"+myEncode(val)+"','"+dlgCallBackParameter+"');");
     dlgCallBackFunctionName(val, dlgCallBackParameter);
   
}

