// BASED ON DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
// For full source code, documentation, and terms of usage,
// Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm

function openImageBox(title, imageURL) {
	var img = new Image(); 
	img.title = title;
	img.src = imageURL;
	img.onload = doIt;
}

function doIt() {
	// 'this' refers to the image object since it is called by its event handler
	width = this.width + 20;
	height = this.height + 40;
	// correction for body margin for IE
    if (oBrowser.isIE) {
    	width = width + 10;
    	height = height + 20;
    }
	openPopupBox('dummy1234',this.title,width,height,'cx_popupboxtopbar',this.src);
}

function openPopupBox(id, title, width, height, skinClass, pageURL) {      
      var x = new CX_PopupDiv();
      boxdiv = document.createElement('div');
      boxdiv.setAttribute('id', 'dwindow');
      boxdiv.style.display = 'none';
      boxdiv.style.position = 'absolute';
      boxdiv.style.width = width + 'px';
      boxdiv.style.height = height + 'px';
      boxdiv.style.backgroundColor = 'white';
      boxdiv.style.border= '1px solid';
      boxdiv.style.cursor = 'pointer';
      boxdiv.style.left = '0px';
      boxdiv.style.zIndex = '+1000';
    
      boxdiv.onSelectStart = 'return false';
      
      var html = '<table width="100%" height="100%" cellpadding="0" cellspacing="1">' +
           '			  <tr>' +
           '				<td valign="top" class="' + skinClass + '">' +
           '        			<div class="' + skinClass + '" onmousedown="dragStart(event,\'dwindow\')">' +
           '						<table cellpadding="0" cellspacing="0">' +
           '							<tr>' +
           '						      <td align="left" width="100%" >' +
           '								&nbsp;<span class="cx_popupboxtitle">' + title + '</span>' +
           '							  </td>' +
           '							  <td align="right" valign="center">' +
           '	        				    <img class="cx_popupboxcontrolimage" src="/engine/popup/images/max.gif" id="maxname" onClick="maximize()">' +
           '							  </td>' +
           '							  <td valign="center">' +
           '        				        <img id="close" class="cx_popupboxcontrolimage" src="/engine/popup/images/close.gif" onClick="CX_POPUP_closeit()">' +
           '							  </td>' +
           '							</tr>' +
           '						</table>' +
           '        			</div>' +
           '				</td>' +
           '			  </tr>' +
           '			  <tr valign="top">' +
           '				<td height="100%">' +
           '			<div id="dwindowcontent" style="height:100%;">' +
           '				<iframe name="cframe" id="cframe" src="about:blank" border="0" width=100% height=100%></iframe>' +
           '			</div>' +
           '			   </td>' +
           '			  </tr>' +
           '			</table>';

    	  boxdiv.innerHTML = html;
     	  document.body.appendChild(boxdiv);
    	  x._loadwindow(pageURL,width,height);
//    	  return false;
}

var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
var threshold=0;

function CX_PopupDiv() {
    this._iecompattest = CX_POPUP_iecompattest;
    this._loadwindow = CX_POPUP_loadwindow;
}

function CX_POPUP_iecompattest(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function CX_POPUP_loadwindow(url,width,height){
    if (!ie5&&!ns6)
        alert('Popup boxes are not allowed on this platform. Please contact your helpdesk');
    else{
        document.getElementById("dwindow").style.display=''
        document.getElementById("dwindow").style.width=initialwidth=width+"px"
        document.getElementById("dwindow").style.height=initialheight=height+"px"
        document.getElementById("dwindow").style.left="30px"
        document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : CX_POPUP_iecompattest().scrollTop*1+30+"px"
        document.getElementById("cframe").src=url
    }
}

function maximize(){
    if (minrestore==0){
    minrestore=1 //maximize window
    document.getElementById("maxname").setAttribute("src","/engine/popup/images/restore.gif")
    document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : CX_POPUP_iecompattest().clientWidth+"px"
    document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : CX_POPUP_iecompattest().clientHeight+"px"
    }
    else{
    minrestore=0 //restore window
    document.getElementById("maxname").setAttribute("src","/engine/popup/images/max.gif")
    document.getElementById("dwindow").style.width=initialwidth
    document.getElementById("dwindow").style.height=initialheight
    }
    document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : CX_POPUP_iecompattest().scrollLeft+"px"
    document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : CX_POPUP_iecompattest().scrollTop+"px"
}

function CX_POPUP_closeit(){
    document.getElementById("dwindow").style.display="none"
}

function closePopupBox() {
    CX_POPUP_closeit();
}

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id) {
    dragObj.elNode = document.getElementById(id);
  } else {
    if (oBrowser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (oBrowser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (oBrowser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (oBrowser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.
  // dragObj.elNode.style.zIndex = ++dragObj.zIndex;
  // Capture mousemove and mouseup events on the page.

  if (oBrowser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (oBrowser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;
  document.getElementById("dwindowcontent").style.display="none";

  // Get cursor position with respect to the page.

  if (oBrowser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (oBrowser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (oBrowser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (oBrowser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  document.getElementById("dwindowcontent").style.display='';

  if (oBrowser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (oBrowser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

