﻿var winlisttime=1500;
var winlistInterval;
var winlistOpentime=200;
var winlistOpenInterval;
var winlistpanel;
var winlistTopOffset = 28;
var winlistLeftOffset = -3;
var ShowCloseIcon = true;
var Autoarrangevar="Autoarrange";

function GetWindowlistAnchor()
{
    var hrefs = document.getElementsByTagName("a");
    
    for (i=0; i < hrefs.length; i++)
    {
        var a = hrefs[i];
        var text = a.innerHTML;
        var l = text.length;
        var p = text.indexOf("Windowselect24.ICO");
       if ( p < 0 )
       {
            p = text.indexOf("Windowselect.ICO");
       } 
        
        if ( p > (-1) ) 
        {
            var img = a.firstChild;

            ntext = text.substring(0,l-1);
            ntext += " " + "onMouseover=" + "windowlist(2,this);" + ">";      
            a.innerHTML = ntext;
        
            break;
        }
    } 
}

function windowlist(pTyp,pObj)
{
    if ( !winlistpanel ) winlistpanel=document.getElementById("WinListPanel");
    if (pTyp==0)
   {
         if (winlistOpenInterval) window.clearTimeout(winlistOpenInterval);
         winlistInterval = window.setTimeout("HideWinList();", winlisttime);   
   } 
   else if (pTyp==1)
   {
        if (pObj.src)
        {
            pObj.src="../Images/Icons/WindowselectOver.ICO";
            pObj.parentNode.style.backgroundImage="url(../images/Design8/HGMENUIMAGEHOVER.png)";
            pTyp=2;
        }            
   }
   
   if (pTyp>0)
   {
        if (winlistInterval) window.clearTimeout(winlistInterval);
        setTimeout("ShowWinList("+pTyp+");",10);
   }
}

function windowlistpn(pTyp)
{
    if(pTyp==0)
         winlistInterval = window.setTimeout("HideWinList();", winlisttime);   
    else
        window.clearTimeout(winlistInterval);
}

function getListRow(pIndex,pText,pBildSufix,pClose)
{
    var retval="<tr><td ";
    if(!pClose) retval=retval+"  ";
    retval=retval+" onclick='winfocus("+pIndex+");' nowrap class='m1DynamicMenuItemStyle'  style='height:18px;' onmouseover='setListOver(this,1);' onmouseout='setListOver(this,0);'><table cellspacing='0' cellpaddig='0' style='display:inline;'><tr><td><img src='../Images/Icons/Windowaktiv"+pBildSufix+".ICO'  border=0><img src='../Images/clear.gif' width='10px' height='16px' border=0></td><td nowrap valign=top>"+pText+"&nbsp</td></tr></table></td>";
    if(pClose) retval=retval+"<td style='height:18px;width:18px;' onclick='winclose("+pIndex+");'><img src='../Images/Icons/WindowsClose.ICO' border=0 align=right></a></td>";
    retval=retval+"</tr>";
    return retval;
}

function setListOver(pObj,pParam)
{
    if(pParam==1)
        pObj.className="m1DynamicHoverStyle";
   else 
        pObj.className="m1DynamicMenuItemStyle";
}


function ShowWinList(pTyp)
{  
    try
   {
        winlistInterval = window.setTimeout("HideWinList();", winlisttime);   
        
        var winlistbild=document.getElementById("winlistbild");
        if(winlistbild)
        {
            var bildpos=findPos(winlistbild);
            winlistpanel.style.top = bildpos[1] + winlistTopOffset + "px";
            winlistpanel.style.left = bildpos[0] + winlistLeftOffset + "px";
        }
        else
        {
            winlistpanel.style.top=MouseY+"px";
            winlistpanel.style.left=MouseX+"px";
        }

        var dieListe="";
        if(fmMain)
        { 
             var thiswin="01";
             if(fmMain.document.title==this.document.title) thiswin="";
             dieListe=dieListe+"<table cellspacing='0' cellpaddig='0' class='m1DynamicMenuStyle' >";
             dieListe=dieListe+getListRow(-1,fmMain.document.title,thiswin,false);
             if(fmMain.mainwinarray.length>0)
             {
                 for(i=0;i<fmMain.mainwinarray.length;i++)
                     if(fmMain.mainwinarray[i])
                         if(!fmMain.mainwinarray[i].closed) 
                         {
                             thiswin="01";
                             if(fmMain.mainwinarray[i].document.title==this.document.title) thiswin="";
                             dieListe=dieListe+getListRow(i,fmMain.mainwinarray[i].document.title,thiswin,ShowCloseIcon);
                         } 
                 dieListe=dieListe+"<tr><td onclick='autoarrange();' nowrap class='m1DynamicMenuItemStyle'  style='height:18px;' onmouseover='setListOver(this,1);' onmouseout='setListOver(this,0);'><table cellspacing='0' cellpaddig='0' style='display:inline;'><tr><td><img src='../Images/Icons/Windowarrange.ICO'  border=0><img src='../Images/clear.gif' width='10px' height='16px' border=0></td><td nowrap valign=top>"+Autoarrangevar+"&nbsp</td></tr></table></td></tr>";
             }
             dieListe=dieListe+"</table>";
         }
         winlistpanel.innerHTML=dieListe;
         if(pTyp==2)winlistpanel.style.visibility="visible";
         else
             winlistOpenInterval = window.setTimeout("if(document)document.getElementById('WinListPanel').style.visibility='visible'", winlistOpentime);   
            
         
    }
    catch(e)
    { 
         winlistpanel.style.visibility="hidden";
         winlistpanel.innerHTML="";
    } 
    
}

function winfocus(pNum)
{
    HideWinList();
    if(fmMain)
    if(pNum>=0)
    {  
         if(fmMain.mainwinarray.length>pNum)
            if(fmMain.mainwinarray[pNum])
               if(!fmMain.mainwinarray[pNum].closed)
                 fmMain.mainwinarray[pNum].focus();
    }
    else
        fmMain.focus();  
}
function winclose(pNum)
{
    HideWinList();
    if(pNum>=0)
    {  
        if(fmMain)
          if(fmMain.mainwinarray.length>pNum)
            if(fmMain.mainwinarray[pNum])
                fmMain.mainwinarray[pNum].close();
    }
    else if(pNum==-1)
        if(fmMain)fmMain.close();  
    ShowWinList(2);
}

function arrcheck()
{
    if(fmMain)
    {
        if(fmMain.mainwinarray.length>0)
        {  
            var ind=0;
            while(ind<fmMain.mainwinarray.length)
            {
                if(fmMain.mainwinarray[ind])
                    if(fmMain.mainwinarray[ind].closed)
                        {fmMain.mainwinarray.splice(ind,1);ind--;}
                ind++;
            }
        }
    }
}


function autoarrange() {
    var docostopabstand = false;
    HideWinList();
    if(fmMain)
    {
        fmMain.focus();  
        if(fmMain.mainwinarray.length>0)
        {  
            arrcheck();
            var ind;
            for(ind=0;ind<fmMain.mainwinarray.length;ind++)
                if(fmMain.mainwinarray[ind])
                {
                    if(!fmMain.mainwinarray[ind].closed)
                    {
                       var mx=WINDOW_LEFT+(ind-1)*5;
                       var my = WINDOW_TOP + (ind - 1) * 25;
                       my += COS_MENU_HEIGHT;
                       if (docostopabstand) my += COS_TOP_ABSTAND;
                       if (fmMain.mainwinarray[ind].name.indexOf('fmCTSelectWizard') >= 0) docostopabstand = true;
                       if (mx != 0 && my != 0)
                        fmMain.mainwinarray[ind].moveTo(mx, my);
                       fmMain.mainwinarray[ind].focus();
                   }
                }
        }
    }
}



function HideWinList()
{
     if(winlistpanel)winlistpanel.style.visibility="";
}


