document.write("<script type='text/javascript' src='/includes/xlib/x_core.js'></script>");
document.write("<script type='text/javascript' src='/includes/xlib/x_event.js'></script>");
document.write("<script type='text/javascript' src='/includes/xlib/lib/xenabledrag.js'></script>");
document.write("<script type='text/javascript' src='/includes/xlib/lib/xfenster.js'></script>");
document.write("<script type='text/javascript' src='/includes/xlib/lib/xaddeventlistener.js'></script>");
document.write("<link rel='stylesheet' type='text/css' href='/includes/xlib/css/xfenster.css'>");

function Show_Window(theSrc, theWidth, theHeight, theTitle, theId, objectId, showMinimize, showMaximize, showClose, oncreate, onminimize, onrestore, onmaximize, onclose, manager)
{
  if (theSrc != null)
  {
    theSrc = "/frameset_builder.aspx?"+theSrc;
  }

  if (showMinimize == null) {showMinimize = true;}
  if (showMaximize == null) {showMaximize = true;}
  if (showClose == null) {showClose = true;}
      
  var winW = document.documentElement.clientWidth || document.body.clientWidth;
  var winH = document.body.clientHeight;
   
  if (theWidth > winW) theWidth = winW;
  if (theHeight > winH - 10) theHeight = winH -10;


  var theLeft = (winW - theWidth) /2;
  if (theLeft < 0)
  {
    theLeft = 0;
  }
  new xFenster(theId, theTitle, theSrc, theLeft, 10, theWidth, theHeight,
               150, null, 0, 1, 1,
               true, true, showMinimize, showMaximize, showClose, false, false,
               null, null, null, null, null, null, null, null,
               'xfCon', 'xfClient', 'xfTBar', 'xfTBarF', 'xfSBar', 'xfSBarF',
               'xfRIco', 'xfNIco', 'xfMIco', 'xfOIco', 'xfCIco',
               'Resize', 'Minimize', 'Maximize', 'Restore', 'Close', objectId, oncreate, onminimize, onrestore, onmaximize, onclose, manager);
}

////////////////////////////////////////////////////////////////////
////////////////////// XWindowsManager Class ///////////////////////
////////////////////////////////////////////////////////////////////

XWindowsManager = function()
{//Start of XWindowsManager Class
  this.lastId = 1;
  this.xwindows = new Object();
  
this.Get_NewId = function()
{
  var newId = 'xwindow_id_'+this.lastId;
  this.lastId = this.lastId + 1;
  return newId;
}

this.oncreateEventHandler = function(sender)
{
  var xwindowId = sender.id;
  sender.manager.xwindows[xwindowId] = sender;
}

this.oncloseEventHandler = function(sender)
{
  var xwindowId = sender.id;
 delete sender.manager.xwindows[xwindowId];
}

this.Get_XWindow_ById = function(xwindowId)
{
  return this.xwindows[xwindowId]; 
}

this.Get_XWindows_List = function()
{
  var theList = new Array();
  for (var xwindowId in this.xwindows) {
      theList.push(this.xwindows[xwindowId]);
  }
  return theList;
}

this.Get_XWindows_Ids = function()
{
  var ids = new Array();
  for (var xwindowId in this.xwindows) {
      ids.push(xwindowId);
  }
  return ids;
}

this.Get_Id_By_IFrame = function(theIFrame)
{
  for (var xwindowId in this.xwindows) {
    var xwindow = this.xwindows[xwindowId];
    if (xwindow.client.contentWindow == theIFrame)
      return xwindowId;
  }  
}

this.Change_MyContainrs_Title = function(me, title)
{
  xwindowId = this.Get_Id_By_IFrame(me);
  this.xwindows[xwindowId].title(title);
}

this.Show_Window = function(theSrc, theWidth, theHeight, theTitle, theId, showMinimize, showMaximize, showClose)
{
  if (showMinimize == null) {showMinimize = true;}
  if (showMaximize == null) {showMaximize = true;}
  if (showClose == null) {showClose = true;}

  var objectId = this.Get_NewId();
  if (theId == null)
    theId = objectId + '_iframe';

  Show_Window(theSrc, theWidth, theHeight, theTitle, theId, 
              objectId, 
              showMinimize, showMaximize, showClose, 
              this.oncreateEventHandler, null, null, null, this.oncloseEventHandler, this);
}


}//End of XWindowsManager Class

xwindowsManager = new XWindowsManager();

////////////////////////////////////////////////////////////////////
/////////////////////// WindowArranger Class ////////////////////////
////////////////////////////////////////////////////////////////////
WindowArranger = function ()
{
	
this.isShown = false;
this.lastSelectedIndex = -1;

this.initial = function()
{
  var theDiv = document.createElement('div');
  theDiv.setAttribute('id','grayDiv');
  theDiv.style.display = 'none';
  theDiv.style.position = 'absolute';
  theDiv.style.overflow = 'hidden';
  theDiv.style.filter = 'alpha(opacity=30)';
  theDiv.style.opacity = '0.3';
  theDiv.style.backgroundColor = 'black';
  theDiv.style.zIndex = '200';
  document.body.appendChild(theDiv);
  
  theDiv = document.createElement('div');
  theDiv.setAttribute('id','chooseWindowDiv');
  theDiv.style.display = 'none';
  theDiv.style.position = 'absolute';
  theDiv.style.backgroundColor = 'white';
  theDiv.style.border = '2px solid';
  theDiv.style.width = '400px';
  theDiv.style.height = '300px';
  theDiv.style.zIndex = '201';
  var selectStyle = 'style="width:380;height:250;position:relative;margin:10px 10px 10px 5px"';
  theDiv.innerHTML = '<select size="10" id="windowsSelect" class="input" '+selectStyle+'></select>';
  document.body.appendChild(theDiv);
  
	xAddEventListener(document,'keydown',this.keydown_Listener,false);
	xAddEventListener(document,'keyup',this.keyup_Listener,false);  
}

this.showModal = function()
{
	var grayDiv = document.getElementById('grayDiv');
	grayDiv.style.width = document.documentElement.clientWidth || document.body.clientWidth;
  if (navigator.appName.indexOf("Microsoft")!=-1)
		grayDiv.style.height = document.body.scrollHeight;
	else
		grayDiv.style.height = document.documentElement.clientHeight;
	grayDiv.style.top = 0;
	grayDiv.style.left = 0;
	grayDiv.style.display = 'block';
	
  var winW = document.documentElement.clientWidth || document.body.clientWidth;
  var winH = document.body.clientHeight;
	
	var chooseWindowDiv = document.getElementById('chooseWindowDiv');
	chooseWindowDiv.style.display = 'block';
	var cwdWidth = chooseWindowDiv.offsetWidth;
	var cwdHeight = chooseWindowDiv.offsetHeight;
	var theLeft = (winW - cwdWidth) / 2;
	var theTop = (winH - cwdHeight) / 2 + document.body.scrollTop;
	chooseWindowDiv.style.left = theLeft;
	chooseWindowDiv.style.top = theTop;
}

this.hideModal = function()
{
	var grayDiv = document.getElementById('grayDiv');
	grayDiv.style.display = 'none';
	var chooseWindowDiv = document.getElementById('chooseWindowDiv');
	chooseWindowDiv.style.display = 'none';
}

this.showWindow= function()
{
	var xwindows = xwindowsManager.Get_XWindows_List();
	if (xwindows.length < 1)
	{
		alert('No window to select');
		return;
	}
	
	var xwindows = xwindowsManager.Get_XWindows_List();
	var windowsSelect = document.getElementById('windowsSelect');
	windowsSelect.options.length = 0;
	for (var i=0; i<xwindows.length; i++) {
		var xwindow = xwindows[i];
		var theOption = new Option(xwindow.title(),xwindow.id);
		windowsSelect.options.add(theOption);
	}
	this.lastSelectedIndex = -1;
	
	this.showModal();
	this.isShown = true;
}
this.hideWindow = function()
{
	this.hideModal();
	this.isShown = false;
	if (this.lastSelectedIndex != -1)
	{
		var windowsSelect = document.getElementById('windowsSelect');
		var xwindowId = windowsSelect.value;
		var xwindow = xwindowsManager.Get_XWindow_ById(xwindowId);
		if (xwindow != null)
			xwindow.focus();
			if (xwindow.minimized)
			 xwindow.restore();
	}
}

this.selectNextWindow = function()
{
	this.lastSelectedIndex++;
	var windowsSelect = document.getElementById('windowsSelect');
	if (this.lastSelectedIndex >= windowsSelect.options.length)
		this.lastSelectedIndex = 0;
	windowsSelect.options[this.lastSelectedIndex].selected = true;
}

this.minimize_all = function()
{
	var xwindows = xwindowsManager.Get_XWindows_List();
	for (var i=0; i<xwindows.length; i++) {
		var xwindow = xwindows[i];
		xwindow.minimize();
	}
}
this.restore_all = function()
{
	var xwindows = xwindowsManager.Get_XWindows_List();
	for (var i=0; i<xwindows.length; i++) {
		var xwindow = xwindows[i];
		xwindow.restore();
	}
}

this.keydown_Listener = function(e)
{ 
  var evt = e || window.event;
  
  var keynum = evt.keyCode || evt.which;
  keychar = String.fromCharCode(keynum);

  if (keynum == 27)
  {
    try
    {
      xFenster.focused.destroy();   
    }
    catch(e){}
  }
  
  if ((keychar=='0') && (evt.ctrlKey ))
  {
    window.focus();
  	if (! windowArranger.isShown)
  		windowArranger.showWindow();
  	else
  	{
  		windowArranger.selectNextWindow();
  	}
  }
  
  if ((keychar=='M') && (evt.ctrlKey ) && (evt.shiftKey ))
  {
    windowArranger.minimize_all();
  }
  if ((keychar=='M') && (evt.ctrlKey ) && (evt.altKey ))
  {
    windowArranger.restore_all();
  }
}

this.keyup_Listener = function(e)
{
  var evt = e || window.event;
  var keynum = 0;
  if(window.event)
    keynum = evt.keyCode;
  else
    keynum = evt.which;

  if ((keynum==17) && (windowArranger.isShown))
		windowArranger.hideWindow();
}

}

var windowArranger = new WindowArranger();
function initial_windowArranger()
{
  windowArranger.initial();
}
if (window.addEventListener)
  window.addEventListener('load',initial_windowArranger,false);
else if (window.attachEvent)
  window.attachEvent('onload',initial_windowArranger);

