﻿// JScript File
var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
var ActiveWindow=null;
var offsetx;
var offsetY;
var tempx;
var tempy;
var nextZIndex=10;
function OpenDivIFrameWindow(ID, width, height, Link,e)
{
    var WindowId = 'Window_' + ID;
    var WindowMenuId = WindowId + '_menu';
    var WindowContentId = WindowId + '_content';
    var WindowsPlace = document.getElementById("AddIframeHere");

    if(document.getElementById('Window_'+ID)==null)
    {
        if(WindowsPlace!=null)
        {
            height+=60;
            width+=30;
            //var _x=ie5? event.clientX-width/2 : e.clientX-width/2;
            var _x=ie5? event.clientX : e.clientX;
            var _y=ie5? event.clientY : e.clientY;
            
            // added by edi to handle the master page menu
            //if (document.getElementById("content") != null) {
            //    var verticalOffset = findPosY(document.getElementById("content"));
            //    _y -= verticalOffset;
            //    if (_y < 0) { _y = 0; }
            //}
            
            var DivText=WindowsPlace.innerHTML;
            
            DivText+='<div id="'+WindowId+'" style="z-index:'+nextZIndex+'; background-color:#EBEBEB; border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid; position:absolute; Left:'+_x+'px; Top:'+_y+'px; width:'+width+'px; height:'+height+'px;" onmousedown="SetNewZIndex( \''+WindowId+'\',event);"  >';
            DivText+='<div id="'+WindowMenuId+'" align="right" style=" cursor:pointer;  background-color:#cacacb; border-bottom: gray 1px solid; width:'+width+'px; height:20px" onmousedown="Drag(\''+WindowId+'\',event)" onmouseup="StopDrag(\''+WindowId+'\',event)" >';
            DivText+='<div style="text-align: center; border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid; background-color: gray; width:20px;height:20px" onClick="CloseWindow(\''+WindowId+'\');" >X</div>'
            DivText+='</div>';
            var iFraneHeight=height-22;
            DivText+='<iframe id="'+WindowContentId+'" frameborder ="0" style="overflow: none; width:'+width+'px; height:'+iFraneHeight+'px;" src="'+Link+'">';
            DivText+='</iframe>';
            DivText+='</div>';            
            WindowsPlace.innerHTML=DivText;        
            nextZIndex++;    
        }
    }
    else
    {
        // added by edi to reset the position
        height+=60;
        width+=30;
        //var _x=ie5? event.clientX-width/2 : e.clientX-width/2;
        var _x=ie5? event.clientX : e.clientX;
        var _y=ie5? event.clientY : e.clientY;
        
        // added by edi to handle the master page menu
        //if (document.getElementById("content") != null) {
        //    var verticalOffset = findPosY(document.getElementById("content"));
        //    _y -= verticalOffset;
        //    if (_y < 0) { _y = 0; }
        //}
        
        document.getElementById(WindowId).style.left = _x + 'px';
        document.getElementById(WindowId).style.top = _y + 'px';
        // end added by edi to reset the position

        document.getElementById("Window_"+ID).style.display="block";
        document.getElementById("Window_"+ID).style.zIndex=nextZIndex;    
        nextZIndex++;
          
    }
    
}
function SetNewZIndex(WindowID,e)
{
     
    if(WindowID!=null)
    {
        document.getElementById(WindowID).style.zIndex =nextZIndex;
        nextZIndex++;
    }
}
function CloseWindow(WindowID)
{
    document.getElementById(WindowID).style.display="none";
}
function Drag(WindowID, e)
{

    ActiveWindow=document.getElementById(WindowID);   
    if(ActiveWindow!=null)
    {
    
        ActiveWindow.style.zIndex =200;
        offsetx=ie5? event.clientX : e.clientX
        offsety=ie5? event.clientY : e.clientY
        tempx=parseInt(ActiveWindow.style.left)
        tempy=parseInt(ActiveWindow.style.top)
        dragapproved=true
        var WindowsPlace=  document.getElementsByTagName("body")[0];
        WindowsPlace.onmousemove=DragDrop;
       //alert(e.button);
    }
    return false;
}
function DragDrop(e)
{
   // ActiveWindow=document.getElementById(WindowID);   
   
     if(ActiveWindow!=null)
     {
        if (ie5&&dragapproved&&event.button==1)
        {
              ActiveWindow.style.pixelLeft=tempx+event.clientX-offsetx;
              ActiveWindow.style.pixelTop=tempy+event.clientY-offsety;
        }
        else if (ns6&&dragapproved&&ActiveWindow&&e.button==0)
        {
             
              var _x=tempx+e.clientX-offsetx;
              var _y=tempy+e.clientY-offsety;
              ActiveWindow.style.left=_x+'px';
              ActiveWindow.style.top=_y+'px';
     
        }  
        else
          StopDrag(ActiveWindow.id,e)
     }
     return false;
}
function StopDrag(WindowID,e)
{
    ActiveWindow=document.getElementById(WindowID);   
    if(ActiveWindow!=null)
    {
       
        dragapproved=false;
        var WindowsPlace=  document.getElementsByTagName("body")[0];
        WindowsPlace.onmousemove=null;
        ActiveWindow.style.display=""; 
        ActiveWindow=null;
       
    }
   return false;
}



