// Version: 3.00
// Last Update: 10.9.2002
// Author: Stanislav Stedry

//-------------------------------------------------------------------------------------------

function docElem(strID)
{
  if (document.all) return(document.all(strID));
  if (document.getElementById) return(document.getElementById(strID));
  return false;
}

//-------------------------------------------------------------------------------------------

function IEBrowserVer()
{
  if (window.navigator.userAgent.indexOf('MSIE') == -1) return 0;
  return eval(window.navigator.userAgent.substr(window.navigator.userAgent.indexOf('MSIE')+5,1))
}

//-------------------------------------------------------------------------------------------

var imgTabArowDown, imgTabArowUp;

function switchTabDashboard(idTab)
{
  if (document.images)
  {
    if (!imgTabArowDown) {imgTabArowDown  = new Image(); imgTabArowDown.src  = "../../images/arowdown.gif"}
    if (!imgTabArowUp) {imgTabArowUp = new Image(); imgTabArowUp.src = "../../images/arowup.gif"}
  }

  if (docElem('idTab'+idTab))
  {
    if (docElem('idTab'+idTab).style.display == 'block')
    {
      docElem('idTab'+idTab).style.display = 'none';
      document.images['img'+idTab].src = imgTabArowDown.src;
      if (document.forms.frmDbrStatus)
        document.forms.frmDbrStatus['MDL_'+idTab].value=1;
    }
    else
    {
      docElem('idTab'+idTab).style.display = 'block';
      document.images['img'+idTab].src = imgTabArowUp.src;
      if (document.forms.frmDbrStatus)
        document.forms.frmDbrStatus['MDL_'+idTab].value=2;
    }
  }
}

//-------------------------------------------------------------------------------------------

function setPage(newAddress){
  if (newAddress != '') window.location.href = newAddress;
}

//-------------------------------------------------------------------------------------------

function setOpener(newAddress){
  if (newAddress != '')
    if (window.opener)
      window.opener.location.href = newAddress;
}

//-------------------------------------------------------------------------------------------

function changeImg(imageName,isOn)
{
  if (document.images)
  {
    if (isOn==true) document.images[imageName].src = eval(imageName + 'on' + '.src');
    else document.images[imageName].src = eval(imageName + 'off' + '.src');
  }
}

//-------------------------------------------------------------------------------------------

function ShowHideItem(id)
{
  if (docElem(id))
  {
    if (docElem(id).style.display == 'none') docElem(id).style.display = 'block';
    else docElem(id).style.display = 'none';
  }
}

//-------------------------------------------------------------------------------------------

function PageMenuClick(n)
{
  for (var i=0; i<PageMenu.length; i++)
  {
    PageMenu[i].className = 'clsPageMenu';
  }
  PageMenu[n].className = 'clsPageMenuSelected';
}

//------------------------------------------------------------------------------------

function TabSelect(n)
{
  if (docElem('TabMenu0') && docElem('TabMenu1'))
  {
    for (var i=0; (docElem('TabMenu'+i) && i<50); i++)
    {
      if(i!=n)
      {
        docElem('TabMenu'+i).className = 'clsTabMenu';
        docElem('TabDiv'+i).style.display = 'none';
      }
    }
    docElem('TabMenu'+n).className = 'clsTabMenuSelected';
    docElem('TabDiv'+n).style.display = 'block';
    document.frmForm.IDTab.value = n;
  }
}

//------------------------------------------------------------------------------------

function setPosWindowModalWidth(wndObj, wndWidth)
{
  mwidth = wndWidth+12;
  mleft = (window.screen.width - mwidth) / 2 + 5;
  wndObj.dialogWidth = mwidth + 'px';
  wndObj.dialogLeft = mleft + 'px';
}

//------------------------------------------------------------------------------------

function setPosWindowModalHeight(wndObj, wndHeight)
{
  mheight = wndHeight+30;
  mtop = (window.screen.height - mheight) / 2 + 15;
  wndObj.dialogHeight = mheight + 'px';
  wndObj.dialogTop = mtop + 'px';
}

//------------------------------------------------------------------------------------

function setPosWindowModal(wndObj, wndWidth, wndHeight)
{
  setPosWindowModalWidth(wndObj, wndWidth)
  setPosWindowModalHeight(wndObj, wndHeight)
}

//------------------------------------------------------------------------------------

function setPosWindowNormalWidth(wndObj, wndWidth)
{
  mwidth = wndWidth;
  mheight = wndObj.document.body.clientHeight;
  mtop = (window.screen.height - mheight) / 2;
  mleft = (window.screen.width - mwidth) / 2;
  wndObj.resizeTo(mwidth, mheight);
  wndObj.moveTo(mleft, mtop);
}

//------------------------------------------------------------------------------------

function setPosWindowNormalHeight(wndObj, wndHeight)
{
  mwidth = wndObj.document.body.clientWidth;
  mheight = wndHeight;
  mtop = (window.screen.height - mheight) / 2;
  mleft = (window.screen.width - mwidth) / 2;
  wndObj.resizeTo(mwidth, mheight);
  wndObj.moveTo(mleft, mtop);
}

//------------------------------------------------------------------------------------

function setPosWindowNormal(wndObj, wndWidth, wndHeight)
{
  setPosWindowNormalWidth(wndObj, wndWidth)
  setPosWindowNormalHeight(wndObj, wndHeight)
}

//------------------------------------------------------------------------------------

function createPosStrWindowModal(wndWidth,wndHeight)
{
  mwidth = wndWidth+12;
  mheight = wndHeight+30;
  mtop = (window.screen.height - mheight) / 2 + 15;
  mleft = (window.screen.width - mwidth) / 2 + 5;
  return('dialogHeight: ' + mheight + 'px; dialogWidth: ' + mwidth + 'px; dialogTop: ' + mtop + 'px; dialogLeft: ' + mleft + 'px;')
}

//------------------------------------------------------------------------------------

function createPosStrWindowNormal(wndWidth,wndHeight)
{
  mwidth = wndWidth;
  mheight = wndHeight;
  mtop = (window.screen.height - mheight) / 2;
  mleft = (window.screen.width - mwidth) / 2;
  return('height=' + mheight + ',width=' + mwidth + ',top=' + mtop + ',left=' + mleft + ',')
}

//------------------------------------------------------------------------------------

function openWindowModal(wndPath, wndTitle, wndWidth, wndHeight)
{
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndTitle) == 'undefined') wndTitle='';
  if (typeof(wndWidth) == 'undefined') wndWidth=600;
  if (typeof(wndHeight) == 'undefined') wndHeight=500;
  window.showModalDialog('../engine/windowmodal.asp?Title=' + escape(wndTitle) + '&Path=' + escape(wndPath),window,createPosStrWindowModal(wndWidth,wndHeight)+'scroll: no; center: yes; help: no; resizable: yes; status: no;');
}

//------------------------------------------------------------------------------------

function openWindowNormal(wndPath, wndName, wndWidth, wndHeight)
{
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndName) == 'undefined') wndName='';
  if (typeof(wndWidth) == 'undefined') wndWidth=600;
  if (typeof(wndHeight) == 'undefined') wndHeight=500;
  objWnd = window.open('../engine/windownormal.asp?Path=' + escape(wndPath),wndName,createPosStrWindowNormal(wndWidth,wndHeight) + 'scrollbars=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
  objWnd.focus();
}

//------------------------------------------------------------------------------------

function openWindowPrint(wndPath, wndName, wndWidth, wndHeight)
{  
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndName) == 'undefined') wndName='';
  if (typeof(wndWidth) == 'undefined') wndWidth=750;
  if (typeof(wndHeight) == 'undefined') wndHeight=500;
  objWnd = window.open(wndPath,wndName,createPosStrWindowNormal(wndWidth,wndHeight) + 'scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no,resizable=yes');
  objWnd.focus();
}

//-------------------------------------------------------------------------------------------

function openWindowGetModuleModal(wndPath, wndTitle, wndWidth, wndHeight)
{  
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndTitle) == 'undefined') wndTitle='';
  if (typeof(wndWidth) == 'undefined') wndWidth=230;
  if (typeof(wndHeight) == 'undefined') wndHeight=400;
  mwidth = wndWidth+12;
  mheight = wndHeight+30;
  mtop = (window.screen.height - mheight) / 2 + 15;
  mleft = (window.screen.width - mwidth) / 2 + 5 + 270;
  strTemp = 'dialogHeight: ' + mheight + 'px; dialogWidth: ' + mwidth + 'px; dialogTop: ' + mtop + 'px; dialogLeft: ' + mleft + 'px;'
  window.showModalDialog('../engine/windowgetmodule.asp?Title=' + escape(wndTitle) + '&Path=' + escape(wndPath),window,strTemp + 'scroll: no; center: yes; help: no; resizable: yes; status: no;');
}

//-------------------------------------------------------------------------------------------

function openWindowGetModuleModeless(wndPath, wndTitle, wndWidth, wndHeight)
{  
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndTitle) == 'undefined') wndTitle='';
  if (typeof(wndWidth) == 'undefined') wndWidth=230;
  if (typeof(wndHeight) == 'undefined') wndHeight=400;
  mwidth = wndWidth+12;
  mheight = wndHeight+30;
  mtop = (window.screen.height - mheight) / 2 + 15;
  mleft = (window.screen.width - mwidth) / 2 + 5 + 270;
  strTemp = 'dialogHeight: ' + mheight + 'px; dialogWidth: ' + mwidth + 'px; dialogTop: ' + mtop + 'px; dialogLeft: ' + mleft + 'px;'
  window.showModelessDialog('../engine/windowgetmodule.asp?Title=' + escape(wndTitle) + '&Path=' + escape(wndPath),window,strTemp + 'scroll: no; center: yes; help: no; resizable: yes; status: no;');
}

//-------------------------------------------------------------------------------------------

function openWindowGetModule(wndPath, wndTitle, wndWidth, wndHeight)
{  
  openWindowGetModuleModeless(wndPath, wndTitle, wndWidth, wndHeight)
}

//------------------------------------------------------------------------------------

function openWindowDialogOkCancel(idDiv, wndTitle, wndWidth, wndHeight)
{
  if (typeof(idDiv) == 'undefined') idDiv='';
  if (typeof(wndTitle) == 'undefined') wndTitle='';
  if (typeof(wndWidth) == 'undefined') wndWidth=250;
  if (typeof(wndHeight) == 'undefined') wndHeight=150;
  return window.showModalDialog('../engine/windowdialog.asp?Type=OkCancel&Title=' + escape(wndTitle) + '&IDDiv=' + idDiv,window,createPosStrWindowModal(wndWidth,wndHeight)+ 'scroll: no; center: yes; help: no; resizable: yes; status: no;');
}

//------------------------------------------------------------------------------------

function openWindowDialog(idDiv, wndTitle, wndWidth, wndHeight)
{
  if (typeof(idDiv) == 'undefined') idDiv='';
  if (typeof(wndTitle) == 'undefined') wndTitle='';
  if (typeof(wndWidth) == 'undefined') wndWidth=250;
  if (typeof(wndHeight) == 'undefined') wndHeight=150;
  return window.showModalDialog('../engine/windowdialog.asp?Title=' + escape(wndTitle) + '&IDDiv=' + idDiv,window,createPosStrWindowModal(wndWidth,wndHeight)+ 'scroll: no; center: yes; help: no; resizable: yes; status: no;');
}

//-------------------------------------------------------------------------------------------

function openCalendar(obj)
{
  var datum;
  if (obj.value=='') datum='';
  else datum=obj.value;
  result=showModalDialog('../engine/calendar.asp',datum,'dialogHeight: 204px; dialogWidth: 240px; center: yes; help: no; resizable: no; status: no;');
  if (result != null) obj.value=result;
}

//-------------------------------------------------------------------------------------------

function openWindowImg(wndPath, wndName, wndTitle)
{
  if (typeof(wndPath) == 'undefined') wndPath='';
  if (typeof(wndName) == 'undefined') wndName='';
  if (typeof(wndTitle) == 'undefined') wndTitle='&nbsp;';
  var newWin
  newWin = window.open('',wndName,createPosStrWindowNormal(100,100) + 'status=no,toolbar=no,menubar=no,location=no,resizable=yes');
  newWin.focus();
  newWin.document.open("text/html", "replace");
  newWin.document.write('<html><head><title>' + wndTitle + '</title></head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0"><table border="0" cellPadding="0" cellSpacing="0" width="100%" height="100%"><tr><td align="center" valign="middle"><img src="' + wndPath + '" border="0" onLoad="window.resizeTo(this.width+14, this.height+36);window.moveTo((screen.availWidth-(this.width+14))/2,(screen.availHeight-(this.height+14))/2);if (document.body) if (document.body.clientWidth) { window.resizeTo((this.width+14+this.width-document.body.clientWidth), (this.height+36+this.height-document.body.clientHeight)) }"></td></tr></table></body></html>');
  newWin.document.close();
  return newWin
}

//=================================== Start Editor ==========================================

function editorInit(which,readonly)
{
  if (!readonly) {window.frames['ifrm'+which].document.designMode="On"}
  window.frames['ifrm'+which].document.open()
  window.frames['ifrm'+which].document.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1250\"><style>BODY {FONT-FAMILY: Arial; FONT-SIZE: 8pt;} P {FONT-FAMILY: Arial; FONT-SIZE: 8pt;}</style></head><body></body></html>")
  window.frames['ifrm'+which].document.close()
}

//-------------------------------------------------------------------------------------------

function editorLoadData(which)
{
  window.frames['ifrm'+which].document.body.innerHTML = document.frmForm[which].value;
}

//-------------------------------------------------------------------------------------------

function editorSaveData(which)
{
  if (document.frmForm['edFormat'+which])
  {
    if (document.frmForm['edFormat'+which].value=="HTML")
      document.frmForm[which].value = "" + window.frames['ifrm'+which].document.body.innerText + "";
    else
      document.frmForm[which].value = "" + window.frames['ifrm'+which].document.body.innerHTML + "";
  }
}

//-------------------------------------------------------------------------------------------

function editorSwapMode(which)
{
  if (document.frmForm['edFormat'+which].value=="HTML")
  {
    window.frames['ifrm'+which].document.body.innerText = window.frames['ifrm'+which].document.body.innerHTML
    window.frames['ifrm'+which].document.body.style.fontFamily = "monospace"
  }
  else
  {
    window.frames['ifrm'+which].document.body.innerHTML = window.frames['ifrm'+which].document.body.innerText
    window.frames['ifrm'+which].document.body.style.fontFamily = ""
  }
  window.frames['ifrm'+which].focus()
}

//-------------------------------------------------------------------------------------------

function editorDoFormat(which, command)
{
  window.frames['ifrm'+which].focus()
  if (document.frmForm['edFormat'+which].value=="TEXT")
  {
    var edit = window.frames['ifrm'+which].document.selection.createRange()
    if (arguments[2]==null)
      if (command=='InsertBreak')
        edit.pasteHTML("<BR>")
      else
        edit.execCommand(command)
    else
      edit.execCommand(command, true, arguments[2])
    edit.select()
    editorSaveData(which)
  }
}

//==================================== End Editor ===========================================


