//<![CDATA[
//***********************
// FULL MODIFIED AND improved by interaxmedia
//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************



//=============================================================================
// Initialization code.
//=============================================================================


var  desktopHeight =728;

var winList = new Array();
var winTmpList = new Array();
var winPersistentList = new Array();
var winTransactionalList = new Array();
var winGlobalList = new Array();
var winCtrl = new Object();





// Determine browser and version.
function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  
  this.isNS = true;
  return;
}

var browser = new Browser();


//=============================================================================
// Window Object
//=============================================================================

function Window(el) {

  var i, mapList, mapName;

  // Get window components.

  this.frame           = el;
  this.titleBar        = winFindByClassName(el, "titleBar");
  this.titleBarText    = winFindByClassName(el, "titleBarText");
  this.titleBarButtons = winFindByClassName(el, "titleBarButtons");
  this.clientArea      = winFindByClassName(el, "clientArea");
  this.makeResizable  = winFindByClassName(el, "makeResizable");
  
  
 
  this.originalX     = 0;
  this.originalY  = 0;
  
  //this.glass  = winFindByClassName(this.clientArea, "winGlass");
  
  this.closed  = winFindByClassName(el, "closed");

  
  this.scrollable  = winFindByClassName(el, "scrollable");
  
  this.transactional  = winFindByClassName(el, "transactional");
  
  this.windowId  = winFindByClassName(el, "windowId");
  if(this.windowId){
  	 this.windowId=this.windowId.innerHTML
  }else{
  	this.windowId="";
  }
  
 this.alwaysOnTop  = winFindByClassName(el, "alwaysOnTop");
  if(this.alwaysOnTop)
  	this.alwaysOnTop = true;
  else
  	this.alwaysOnTop = false;
  
  
  this.clientSeparatorLine      = winFindByClassName(el, "clientSeparatorLine"); 
  
    //Save properties
  this.isResizable=false
  if(this.makeResizable)
  	 this.isResizable=true
  	 

  //indica si por defecto aparece abierta o cerrada a la hora de inicializar
  if(this.closed){
  	 this.closed=true
  }else{
  	this.closed=false;
  }
  
  this.javascript  = winFindByClassName(el, "javascript");
  if(this.javascript){
  	 this.javascript=this.javascript.innerHTML
  }else{
  	this.javascript="";
  }
  
  
    //indica si es scrollable
  if(this.scrollable){
  	 this.scrollable=true
  }else{
  	this.scrollable=false;
  }
  
  if(this.transactional){
  	 this.transactional=true
  }else{
  	this.transactional=false;
  }
  
 this.cookieName  = winFindByClassName(el, "cookieName");
  if(this.cookieName){
  this.cookieName  = this.cookieName.innerHTML;
  }
  
  // Find matching button image map.

  mapName = this.titleBarButtons.useMap.substr(1);
  mapList = document.getElementsByTagName("MAP");
  for (i = 0; i < mapList.length; i++)
    if (mapList[i].name == mapName)
      this.titleBarMap = mapList[i];


 
  // Save colors.

  
  this.activeFrameBackgroundColor  = this.frame.style.backgroundColor;
  this.activeFrameBorderColor      = this.frame.style.borderColor;
 
  this.activeTitleBarColor         = this.titleBar.style.backgroundColor;
  this.inactiveTitleBarColor 	   = this.titleBarText.style.backgroundColor;

  this.activeTitleTextColor        = this.titleBar.style.color;
  this.activeClientAreaBorderColor = this.clientArea.style.borderColor;
  if (browser.isIE)
    this.activeClientAreaScrollbarColor = this.clientArea.style.scrollbarBaseColor;

  // Save images.

  this.activeButtonsImage   = this.titleBarButtons.src;
  this.inactiveButtonsImage = this.titleBarButtons.longDesc;

  // Set flags.

  this.isOpen      = false;
  this.isMinimized = false;
	
  // Set methods.

  this.open       = winOpen;
  this.close      = winClose;
  this.minimize   = winMinimize;
  this.minimize2   = winMinimize2;
  this.restore    = winRestore;
  this.oneButtonMR   =  oneButtonMinimizeRestore;
  this.makeActive = winMakeActive;
  this.saveCookie = __saveCookie;
  this.getWindowPropertiesFromCookie = __getWindowPropertiesFromCookie;
  
  this.originalPos = winOriginalPos;
 // this.fadeOut       = winFadeOut;
 // this.fadeIn      = winFadeIn;

  // Set up event handling.
	
  this.oldX = 0;
  this.oldY = 0;	

 		
  this.frame.parentWindow = this;
  
  if(this.isResizable){
	  this.frame.onmousemove  = winResizeCursorSet;
	  this.frame.onmouseout   = winResizeCursorRestore;
	  this.frame.onmousedown  = winResizeDragStart;
  }

  this.titleBar.parentWindow = this;
  this.titleBar.onmousedown  = winMoveDragStart;

  this.clientArea.parentWindow = this;
  this.clientArea.onclick      = winClientAreaClick;

  for (i = 0; i < this.titleBarMap.childNodes.length; i++)
    if (this.titleBarMap.childNodes[i].tagName == "AREA")
      this.titleBarMap.childNodes[i].parentWindow = this;

  // Calculate the minimum width and height values for resizing
  // and fix any initial display problems.

  var initLt, initWd, w, dw;

  // Save the inital frame width and position, then reposition
  // the window.

  initLt = this.frame.style.left;
  
  initWd = parseInt(this.frame.style.width);
  this.frame.style.left = -this.titleBarText.offsetWidth + "px";

  // For IE, start calculating the value to use when setting
  // the client area width based on the frame width.

  if (browser.isIE) {
    this.titleBarText.style.display = "none";
    w = this.clientArea.offsetWidth;
    this.widthDiff = this.frame.offsetWidth - w;
    this.clientArea.style.width = w + "px";
    dw = this.clientArea.offsetWidth - w;
    w -= dw;     
    this.widthDiff += dw;
    this.titleBarText.style.display = "";
  }

  // Find the difference between the frame's style and offset
  // widths. For IE, adjust the client area/frame width
  // difference accordingly.

  w = this.frame.offsetWidth;
  this.frame.style.width = w + "px";
  dw = this.frame.offsetWidth - w;
  w -= dw;     
  this.frame.style.width = w + "px";
  if (browser.isIE)
    this.widthDiff -= dw;

  // Find the minimum width for resize.

  this.isOpen = true;  // Flag as open so minimize call will work.
  

  this.minimize();

  // Get the minimum width.
  if (browser.isNS && browser.version >= 1.2)
    // For later versions of Gecko.
    this.minimumWidth = this.frame.offsetWidth;
  else
    // For all others.
    this.minimumWidth = this.frame.offsetWidth - dw;

  // Find the frame width at which or below the title bar text will
  // need to be clipped.

  this.titleBarText.style.width = "";
  this.clipTextMinimumWidth = this.frame.offsetWidth - dw;

  // Set the minimum height.

  this.minimumHeight = 1;

  // Restore window. For IE, set client area width.

  this.restore();
  this.isOpen = false;  // Reset flag.
  initWd = Math.max(initWd, this.minimumWidth);
  this.frame.style.width = initWd + "px";
  if (browser.isIE)
    this.clientArea.style.width = (initWd - this.widthDiff) + "px";

  // Clip the title bar text if needed.

  if (this.clipTextMinimumWidth >= this.minimumWidth)
    this.titleBarText.style.width = (winCtrl.minimizedTextWidth + initWd - this.minimumWidth) + "px";

  // Restore the window to its original position.


  this.frame.style.left = initLt;
  
  this.originalX = this.frame.style.left
   this.originalY = this.frame.style.top
  
  
}

//=============================================================================
// Window Methods
//=============================================================================

function winOpen() {

  if (this.isOpen)
    return;

  // Restore the window and make it visible.
	
  
  this.makeActive();
  this.isOpen = true;
  if (this.isMinimized)
    this.restore();
     this.frame.style.display=''
  this.frame.style.visibility = "visible";
  
  

}

function winClose() {

 this.minimize();

  this.frame.style.zIndex=0;
  this.frame.style.visibility = "hidden";
  this.isOpen = false;
  
  if(this.transactional){
		
	win_transactional_poolDiv = document.getElementById('win_transactional_pool')
	
	win_containter_Div = document.getElementById('winContainerAdd'+this.windowId)
	
	if(win_containter_Div){
		win_containter_Div.innerHTML="";
		
	 	win_transactional_poolDiv.removeChild(win_containter_Div);
			 
		winTransactionalList[this.windowId]=false;
		winTransactionalList["winFrame"+this.windowId]=false;
	}
			 
  }
  
}

function winMinimize() {
   
  if (!this.isOpen || this.isMinimized)
    return;

  this.makeActive();
	
  // Save current frame and title bar text widths.

  this.restoreFrameWidth = this.frame.style.width;
  this.restoreTextWidth = this.titleBarText.style.width;

  // Disable client area display.

  this.clientArea.style.display = "none";
  this.clientSeparatorLine.style.display = "none";


  // Minimize frame and title bar text widths.
//************MINIMIZA del ancho del textarea
/*
 if (this.minimumWidth)
    this.frame.style.width = this.minimumWidth + "px";
  else
    this.frame.style.width = "";
      //*/
  this.titleBarText.style.width = winCtrl.minimizedTextWidth + "px"; 


  this.isMinimized = true;


}

//************se puede BORRAR
function winMinimize2() {

  if (!this.isOpen || this.isMinimized)
    return;

  this.makeActive();

  // Save current frame and title bar text widths.

  this.restoreFrameWidth = this.frame.style.width;
  this.restoreTextWidth = this.titleBarText.style.width;

  // Disable client area display.

  this.clientArea.style.display = "none";
  this.clientSeparatorLine.style.display = "none";

  // Minimize frame and title bar text widths.

  if (this.minimumWidth)
    this.frame.style.width = this.minimumWidth + "px";
  else
    this.frame.style.width = "";
    
  this.titleBarText.style.width = winCtrl.minimizedTextWidth + "px";

  this.isMinimized = true;
}

function winRestore() {

  if (!this.isOpen || !this.isMinimized)
    return;

  this.makeActive();

  // Enable client area display.

  this.clientArea.style.display = "";
  this.clientSeparatorLine.style.display = "";

  // Restore frame and title bar text widths.

  this.frame.style.width = this.restoreFrameWidth;
  this.titleBarText.style.width = this.restoreTextWidth;

  this.isMinimized = false;
  //check if window pass the desktop dimention
  desktopRestriction(this);
}

//oneButtonMinimizeRestore
function oneButtonMinimizeRestore() {

  if (!this.isMinimized)
    this.minimize();
  else
  	this.restore();

}

function winMakeActive() {

 	if(this.frame && !this.alwaysOnTop)
  		this.frame.style.zIndex = ++winCtrl.maxzIndex;
	else
		this.frame.style.zIndex = 8888+winCtrl.maxzIndex;
		
		
  if (winCtrl.active == this)
    return;



  // Inactivate the currently active window.
	   //in case browser not workin

  if (winCtrl.active && winCtrl.active.frame && winCtrl.active!=undefined ) {

    winCtrl.active.frame.style.backgroundColor = winCtrl.inactiveFrameBackgroundColor;
    
    winCtrl.active.frame.style.borderColor        = winCtrl.inactiveFrameBorderColor;
    
     //winCtrl.active.glass.style.visibility = "visible";
    
     // document.getElementById('estatus').innerHTML = 'aqui'+winCtrl.active.frame.id+1;
    /*if(winCtrl.active.inactiveTitleBarColor)
	  	winCtrl.active.titleBar.style.backgroundColor = winCtrl.active.inactiveTitleBarColor
	else
	   winCtrl.active.titleBar.style.backgroundColor = winCtrl.inactiveTitleBarColor;*/
	 /******************* setOpacity**********************/
	 

	  	if(!detectMac())
			 setOpacity(winCtrl.active.titleBar,winCtrl.opacityValue)

    winCtrl.active.titleBar.style.color           = winCtrl.inactiveTitleTextColor;
    winCtrl.active.clientArea.style.borderColor   = winCtrl.inactiveClientAreaBorderColor;
  
    if (browser.isIE)
      winCtrl.active.clientArea.style.scrollbarBaseColor = winCtrl.inactiveClientAreaScrollbarColor;
    if (browser.isNS && browser.version < 6.1)
      winCtrl.active.clientArea.style.overflow = "hidden";
    if (winCtrl.active.inactiveButtonsImage)
      winCtrl.active.titleBarButtons.src = winCtrl.active.inactiveButtonsImage;
 
  }
	
  // Activate this window.
  
 
  this.frame.style.backgroundColor    = this.activeFrameBackgroundColor;
  this.frame.style.borderColor        = this.activeFrameBorderColor;
  this.titleBar.style.backgroundColor = this.activeTitleBarColor;
  this.titleBar.style.color           = this.activeTitleTextColor;
  this.clientArea.style.borderColor   = this.activeClientAreaBorderColor;
  
   //this.glass.style.visibility = 'hidden';
  

  	/*******************Reset setOpacity**********************/
	//setOpacity(this.frame,100)
	if(!detectMac())
		setOpacity(this.titleBar,100)
  
  if (browser.isIE)
    this.clientArea.style.scrollbarBaseColor = this.activeClientAreaScrollbarColor;
  
  if (browser.isNS && browser.version < 6.1)
    this.clientArea.style.overflow = "auto";
    
  if (this.inactiveButtonsImage)
    this.titleBarButtons.src = this.activeButtonsImage;
    
    if(!this.alwaysOnTop)
		this.frame.style.zIndex = ++winCtrl.maxzIndex;
	else
		this.frame.style.zIndex = 8888+winCtrl.maxzIndex;
		
		
	//alert('delay'); if(winCtrl.active)if(winCtrl.active.frame)alert(winCtrl.active.frame.id)
  		winCtrl.active = this;

}

function winOriginalPos(){
this.frame.style.left = this.originalX
this.frame.style.top = this.originalY
}

//=============================================================================
// Event handlers.
//=============================================================================
function winClientAreaClick(event) {
  // Make this window the active one.
  this.parentWindow.makeActive();
}

//-----------------------------------------------------------------------------
// Window dragging.
//-----------------------------------------------------------------------------

function winMoveDragStart(event) {

  var target;
  var x, y;

  if (browser.isIE)
    target = window.event.srcElement.tagName;
  if (browser.isNS)
    target = event.target.tagName;

  if (target == "AREA")
    return;

  this.parentWindow.makeActive();

  // Get cursor offset from window frame.

  if (browser.isIE) {
    x = window.event.x;
    y = window.event.y;
  }
  if (browser.isNS) {
    x = event.pageX;
    y = event.pageY;
  }
  
  //AQUI SE COLOCA UN VIDRIO QUE EVITA QUE SE PIERDA EL EVENTO EN UN IFRAME U OTRA VENTANA
  overlay();
  
  if(!detectMac())
  setOpacity(winCtrl.active.frame,winCtrl.opacityDragValue);
  

  /* if(winCtrl.active.clientArea.innerHTML.indexOf("<object")>0 && !winCtrl.active.isMinimized){
  	winCtrl.active.clientArea.style.display='none'
  }*/
  
  winCtrl.xOffset = winCtrl.active.frame.offsetLeft - x;
  winCtrl.yOffset = winCtrl.active.frame.offsetTop  - y;

  winCtrl.active.oldX = winCtrl.active.frame.style.left;
  winCtrl.active.oldY = winCtrl.active.frame.style.top;	
  // Set document to capture mousemove and mouseup events.

  if (browser.isIE) {
    document.onmousemove = winMoveDragGo;
    document.onmouseup   = winMoveDragStop;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", winMoveDragGo,   true);
    document.addEventListener("mouseup",   winMoveDragStop, true);
    event.preventDefault();
  }

  winCtrl.inMoveDrag = true;
}
var oldTarget = null;
function winMoveDragGo(event) {

  var x, y;

  if (!winCtrl.inMoveDrag)
    return;

  // Get cursor position.

  if (browser.isIE) {
    x = window.event.x;
    y = window.event.y;
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    x = event.pageX;
    y = event.pageY;
    event.preventDefault();
  }

  // Move window frame based on offset from cursor.
  

//if(oldTarget!=event.currentTarget) document.getElementById('estatus').innerHTML+='<br>Cambio'+event.currentTarget
//  if( Math.abs(parseInt(winCtrl.active.frame.style.left)-(x + winCtrl.xOffset))<c && Math.abs(parseInt(winCtrl.active.frame.style.top)-(y + winCtrl.yOffset))<c){
//if((x==oldX || oldX==-1) && (y==oldY || oldY==-1)) {
  winCtrl.active.frame.style.left = (x + winCtrl.xOffset) + "px";
  winCtrl.active.frame.style.top  = (y + winCtrl.yOffset) + "px";
  
//  }


}

function winMoveDragStop(event) {

  winCtrl.inMoveDrag = false;
	overlay();
  // Remove mousemove and mouseup event captures on document.

  if (browser.isIE) {
    document.onmousemove = null;
    document.onmouseup   = null;
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", winMoveDragGo,   true);
    document.removeEventListener("mouseup",   winMoveDragStop, true);
  }

   // DesktopRules

  desktopRestriction(winCtrl.active);
  
  
  /* OPACITY RESTORE*/
  setOpacity(winCtrl.active.frame,100);
  
  /*if(winCtrl.active.clientArea.innerHTML.indexOf("iframe")>0 && !winCtrl.active.isMinimized){
  	winCtrl.active.clientArea.style.display=''
  }*/
  /* if(winCtrl.active.clientArea.innerHTML.indexOf("<object")>0 && !winCtrl.active.isMinimized){
  	winCtrl.active.clientArea.style.display=''
  }*/
  winCtrl.active.saveCookie();
  
}

//-----------------------------------------------------------------------------
// Window resizing.
//-----------------------------------------------------------------------------

function winResizeCursorSet(event) {

  var target;
  var xOff, yOff;

  if (this.parentWindow.isMinimized || winCtrl.inResizeDrag)
    return;

  // If not on window frame, restore cursor and exit.

  if (browser.isIE)
    target = window.event.srcElement;
  if (browser.isNS)
    target = event.target;
  if (target != this.parentWindow.frame)
    return;

  // Find resize direction.

  if (browser.isIE) {
    xOff = window.event.offsetX;
    yOff = window.event.offsetY;
  }
  if (browser.isNS) {
    xOff = event.layerX;
    yOff = event.layerY;
  }
  winCtrl.resizeDirection = ""
  if (yOff <= winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "n";
  else if (yOff >= this.parentWindow.frame.offsetHeight - winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "s";
  if (xOff <= winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "w";
  else if (xOff >= this.parentWindow.frame.offsetWidth - winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "e";

  // If not on window edge, restore cursor and exit.

  if (winCtrl.resizeDirection == "") {
    this.onmouseout(event);
    return;
  }

  // Change cursor.

  if (browser.isIE)
    document.body.style.cursor = winCtrl.resizeDirection + "-resize";
  if (browser.isNS)
    this.parentWindow.frame.style.cursor = winCtrl.resizeDirection + "-resize";
}

function winResizeCursorRestore(event) {

  if (winCtrl.inResizeDrag)
    return;

  // Restore cursor.

  if (browser.isIE)
    document.body.style.cursor = "";
  if (browser.isNS)
    this.parentWindow.frame.style.cursor = "";
}

function winResizeDragStart(event) {

  var target;

  // Make sure the event is on the window frame.

  if (browser.isIE)
    target = window.event.srcElement;
  if (browser.isNS)
    target = event.target;
  if (target != this.parentWindow.frame)
    return;

  this.parentWindow.makeActive();

  if (this.parentWindow.isMinimized)
    return;

  // Save cursor position.

  if (browser.isIE) {
    winCtrl.xPosition = window.event.x;
    winCtrl.yPosition = window.event.y;
  }
  if (browser.isNS) {
    winCtrl.xPosition = event.pageX;
    winCtrl.yPosition = event.pageY;
  }

  // Save window frame position and current window size.

  winCtrl.oldLeft   = parseInt(this.parentWindow.frame.style.left,  10);
  winCtrl.oldTop    = parseInt(this.parentWindow.frame.style.top,   10);
  winCtrl.oldWidth  = parseInt(this.parentWindow.frame.style.width, 10);
  winCtrl.oldHeight = parseInt(this.parentWindow.clientArea.style.height, 10);

  // Set document to capture mousemove and mouseup events.

  if (browser.isIE) {
    document.onmousemove = winResizeDragGo;
    document.onmouseup   = winResizeDragStop;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", winResizeDragGo,   true);
    document.addEventListener("mouseup"  , winResizeDragStop, true);
    event.preventDefault();
  }

  winCtrl.inResizeDrag = true;
}

function winResizeDragGo(event) {

 var north, south, east, west;
 var dx, dy;
 var w, h;

  if (!winCtrl.inResizeDrag)
    return;

  // Set direction flags based on original resize direction.

  north = false;
  south = false;
  east  = false;
  west  = false;
  if (winCtrl.resizeDirection.charAt(0) == "n")
    north = true;
  if (winCtrl.resizeDirection.charAt(0) == "s")
    south = true;
  if (winCtrl.resizeDirection.charAt(0) == "e" || winCtrl.resizeDirection.charAt(1) == "e")
    east = true;
  if (winCtrl.resizeDirection.charAt(0) == "w" || winCtrl.resizeDirection.charAt(1) == "w")
    west = true;

  // Find change in cursor position.

  if (browser.isIE) {
    dx = window.event.x - winCtrl.xPosition;
    dy = window.event.y - winCtrl.yPosition;
  }
  if (browser.isNS) {
    dx = event.pageX - winCtrl.xPosition;
    dy = event.pageY - winCtrl.yPosition;
  }

  // If resizing north or west, reverse corresponding amount.

  if (west)
    dx = -dx;
  if (north)
    dy = -dy;

  // Check new size.

  w = winCtrl.oldWidth  + dx;
  h = winCtrl.oldHeight + dy;
  if (w <= winCtrl.active.minimumWidth) {
    w = winCtrl.active.minimumWidth;
    dx = w - winCtrl.oldWidth;
  }
  if (h <= winCtrl.active.minimumHeight) {
    h = winCtrl.active.minimumHeight;
    dy = h - winCtrl.oldHeight;
  }

  // Resize the window. For IE, keep client area and frame widths in synch.

  if (east || west) {
    winCtrl.active.frame.style.width = w + "px";
    if (browser.isIE)
      winCtrl.active.clientArea.style.width = (w - winCtrl.active.widthDiff) + "px";
  }
  if (north || south)
    winCtrl.active.clientArea.style.height = h + "px";

  // Clip the title bar text, if necessary.

  if (east || west) {
    if (w < winCtrl.active.clipTextMinimumWidth)
      winCtrl.active.titleBarText.style.width = (winCtrl.minimizedTextWidth + w - winCtrl.active.minimumWidth) + "px";
    else
      winCtrl.active.titleBarText.style.width = "";
  }

  // For a north or west resize, move the window.

  if (west)
    winCtrl.active.frame.style.left = (winCtrl.oldLeft - dx) + "px";
  if (north)
    winCtrl.active.frame.style.top  = (winCtrl.oldTop  - dy) + "px";


  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function winResizeDragStop(event) {

  winCtrl.inResizeDrag = false;

  // Remove mousemove and mouseup event captures on document.

  if (browser.isIE) {
    document.onmousemove = null;
    document.onmouseup   = null;
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", winResizeDragGo,   true);
    document.removeEventListener("mouseup"  , winResizeDragStop, true);
  }
   winCtrl.active.saveCookie();
}

//=============================================================================
// Utility functions.
//=============================================================================

function winFindByClassName(el, className) {

  var i, tmp;

  if (el.className == className)
    return el;

  // Search for a descendant element assigned the given class.

  for (i = 0; i < el.childNodes.length; i++) {
    tmp = winFindByClassName(el.childNodes[i], className);
    if (tmp != null)
      return tmp;
  }

  return null;
}


function winFindElementsByClassName(el, className) {
  var i, tmp;
  // Search for a descendant element assigned the given class.
  elementos = new Array();
  z=0;
  if(el)
  for (i = 0; i < el.childNodes.length; i++) {
       tmp = winFindByClassName(el.childNodes[i], className);
    if (tmp != null && tmp!=undefined && tmp)
      elementos[z++] = tmp;
  }
  return elementos;
}


function __saveCookie()
{
	if(!this.cookieName)return;
	var cookieValue="";
	cookieValue='frameWidth:'+this.frame.style.width;
	cookieValue+=',frameHeight:'+this.frame.style.height;
	cookieValue+=',clientAreaWidth:'+this.clientArea.style.width;
	cookieValue+=',clientAreaHeight:'+this.clientArea.style.height;
	cookieValue+=',textWidth:'+this.titleBarText.style.width;
	cookieValue+=',xPos:'+this.frame.style.left;
	cookieValue+=',yPos:'+this.frame.style.top;
	cookieValue+=',zIndex:'+this.frame.style.zIndex;
	if(this.isMinimized)
		cookieValue+=',state:minimized';
	else
		cookieValue+=',state:notminimized';
		
	Set_Cookie(this.cookieName,cookieValue,500);	
}

function __getWindowPropertiesFromCookie()
	{
	if(!this.cookieName)return;	
	var cookieValue=Get_Cookie(this.cookieName);
	var propertyArray=getAssociativeArrayFromString(cookieValue);
	if(!propertyArray)return;
	//if(propertyArray.frameWidth)this.frame.style.width = propertyArray.frameWidth;
	//if(propertyArray.frameHeight)this.frame.style.height = propertyArray.frameHeight;
	//if(propertyArray.clientAreaWidth)this.clientArea.style.width = propertyArray.clientAreaWidth;
	//if(propertyArray.clientAreaHeight)this.clientArea.style.height = propertyArray.clientAreaHeight;
	//if(propertyArray.textWidth)this.titleBarText.style.width = propertyArray.textWidth;
	if(propertyArray.xPos)this.frame.style.left=propertyArray.xPos;
	if(propertyArray.yPos)this.frame.style.top=propertyArray.yPos;
	if(propertyArray.zIndex)this.frame.style.zIndex=propertyArray.zIndex;
	if(propertyArray.state){
		if(propertyArray.state=='minimized')
				this.minimize()
	}
	
	// */
}


function setOpacity(elemento,valor){



   	ie5=(document.getElementById && document.all);
	ns6=(document.getElementById && !document.all);

	if(elemento && elemento.id ){
	
		if(ie5){ 
		    elemento.style.filter="alpha(opacity="+valor+")";
			elemento.filters.alpha.opacity = valor;
	    }
	   
	    
	    if(ns6){
		    if(valor==100)
		   	 	elemento.style.opacity = 1 ;
		    else
		    	elemento.style.opacity = "."+valor ;
		    
		    elemento.style.MozOpacity = 0 + '%';
			elemento.style.MozOpacity = valor+ '%';
	    }
    }
     
    
}


function desktopRestriction(elemento){

  if(document.documentElement.clientHeight){
		desktopHeight=document.documentElement.clientHeight
   }else if(document.body.clientHeight){
  		desktopHeight=document.body.clientHeight
   }
desktopHeight-=22



	if(!elemento.isMinimized){
	  if( (parseInt(elemento.frame.style.top ) + (parseInt(elemento.clientArea.style.height ) + 20) ) >= desktopHeight  ){
	 	elemento.frame.style.top = (desktopHeight - (parseInt(elemento.clientArea.style.height ) +20 )  ) +"px"
	  }
	}else{
	  if( ( parseInt(elemento.frame.style.top ) + 12 ) >= (desktopHeight ) ){
	 	elemento.frame.style.top = (desktopHeight -14) +"px"
	  }	
	}
	
 
   if( parseInt(elemento.frame.style.top )<=128 ){
  	elemento.frame.style.top=132+"px"
  }
 


  if(document.documentElement.clientWidth){
	if(  (parseInt(elemento.frame.style.left) + parseInt(elemento.frame.style.width) ) > document.documentElement.clientWidth ){
		elemento.frame.style.left= (document.documentElement.clientWidth - parseInt(elemento.frame.style.width) )- 7 +"px"
	}
  }else if(document.body.clientWidth){
	if(  (parseInt(elemento.frame.style.left) +  parseInt(elemento.frame.style.width)) > document.body.clientWidth ){
		elemento.frame.style.left= (document.body.clientWidth - parseInt(elemento.frame.style.width)  )- 7 + "px"
	}
  }

  //Horizontal rules 
  if( parseInt(elemento.frame.style.left) <0 ){
   elemento.frame.style.left=5+"px"
  }

}


/**
*
*	These cookie functions are downloaded from 
*	http:
*	www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
*/
function Get_Cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
	expires=expires*60*60*24*1000;
	var today=new Date();
	var expires_date=new Date( today.getTime()+(expires));
	
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}

function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

    /**
     *
    * Returns an associative array from a comma delimited string
    * @param String propertyString-commaseparated string(example: "id:myid,title:My title,contentUrl:includes/tab.inc")
     *
     *	@return Associative array of keys+property value(example: key: id, value:myId)
    *@public
     */	
	function getAssociativeArrayFromString(propertyString)
	{
	if(!propertyString)return;
	var retArray=new Array();
	var items=propertyString.split(/,/g);
	for(var no=0;no<items.length;no++){
		var tokens=items[no].split(/:/);	
		retArray[tokens[0]]=tokens[1];		
	}	
	return retArray;	
	}

/*
function winFadeOut(){
	elFadeOut(this.frame,100)
}
function winFadeIn(){
	elFadeIn(this.frame,0)
}

function elFadeOut(elementId,cant){
	elemento = document.getElementById(elementId);
	
	setOpacity(elemento,cant);
	
	if(cant<=0){
		clearTimeout(timeout)
		return false;
	}
	timeout=setTimeout("elFadeOut('"+elemento.id+"',"+cant-20+")",20)
	setTimeout("clearInterval("+timeout+")",200);
}

function elFadeIn(id,cant){
	
	elemento = document.getElementById(id);
	
	setOpacity(elemento,cant);
	
	if(cant>=100){
		clearTimeout(timeout)
		return false;
	}
	
	timeout=setTimeout("elFadeIn('"+elemento.id+"',"+cant+20+")",20)
	setTimeout("clearInterval("+timeout+")",200);
}
*/
/***TRANSITION FIN**/

  winCtrl.maxzIndex                        =   50;
  winCtrl.resizeCornerSize                 =  16;
  winCtrl.minimizedTextWidth               = 100;
  winCtrl.inactiveFrameBackgroundColor     = "#FFFFFF";
  winCtrl.inactiveFrameBorderColor         = "#f0f0f0 #505050 #404040 #e0e0e0";
  winCtrl.inactiveTitleBarColor            = "#808080";
  winCtrl.inactiveTitleTextColor           = "#c0c0c0";
  winCtrl.inactiveClientAreaBorderColor    = "#404040 #e0e0e0 #f0f0f0 #505050";
  winCtrl.inactiveClientAreaScrollbarColor = "";
  winCtrl.inMoveDrag                       = false;
  winCtrl.inResizeDrag                     = false;
  winCtrl.opacityValue =50;
  winCtrl.opacityDragValue = 40;
  
function winInit() {
  var elList;

 
  // Initialize windows and build list.
  elList = document.getElementsByTagName("DIV");
  for (var i = 0; i < elList.length; i++)
    if (elList[i].className == "window"){
      winList[elList[i].id] = new Window(elList[i]);
       winList[elList[i].id].open();
       winList[elList[i].id].getWindowPropertiesFromCookie();
    }
}


function  restoreWindows(){

 elList = document.getElementsByTagName("DIV");
  for (var i = 0; i < elList.length; i++)
    if (elList[i].className == "window"){
     // winList[elList[i].id] = new Window(elList[i]);
      winList[elList[i].id].open();
     
    }

}

function closeWindowsByElement(windowsGroup){

	myWindowsDiv = document.getElementById(windowsGroup); 
	myTmpWindowsArray= winFindElementsByClassName(myWindowsDiv, "window");

	windowDivGroup=null
	
	if(windowsGroup == 'tmp_windows'){
		windowDivList =	winTmpList;
	}	
	if(windowsGroup == 'persistent_windows'){
		windowDivList =	winPersistentList;
	}
	
	if(windowsGroup == 'win_transactional_pool'){
		windowDivList =	winTransactionalList;
	}

	if(windowsGroup == 'global_windows'){
		windowDivList =	winGlobalList;
	}
	

	for (var i = 0; i < myTmpWindowsArray.length; i++){
	  if (myTmpWindowsArray[i].className == "window"){
	    	   windowDivList[myTmpWindowsArray[i].id].close();
	   }
	}
	
	myWindowsDiv.innerHTML="";

}


function winInitTransactional(id,windowsGroup){
  windowsGroupDiv =	document.getElementById(windowsGroup)
  var tmpWindows;
 

  tmpWindows = winFindElementsByClassName(windowsGroupDiv,"window");
  //inicializar primero el custom scroll
  if(fleXenv)
  	fleXenv.globalInit();
  for (var i = 0; i < tmpWindows.length; i++){
	    if (tmpWindows[i].className == "window"){
	     
	       winTransactionalList[id] = new Window(tmpWindows[i]);
			
           winTransactionalList[id].open();  
           winTransactionalList[id].getWindowPropertiesFromCookie();
           
           winTransactionalList[tmpWindows[i].id] = winTransactionalList[id]

	    }
  }
  
}
function winInitByElement(windowsGroup,opened) {

  windowsGroupDiv =	document.getElementById(windowsGroup)
	
  var tmpWindows;
  // Initialize window control object.
 
  // Initialize windows and build list.
  
  	if(windowsGroup == 'tmp_windows'){
		windowDivList =	winTmpList;
	}
	
	if(windowsGroup == 'persistent_windows'){
		windowDivList =	winPersistentList;
	}
  
  	if(windowsGroup == 'win_transactional_pool'){
		windowDivList =	winTransactionalList;
	}

	if(windowsGroup == 'global_windows'){
		windowDivList =	winGlobalList;
	}

  tmpWindows = winFindElementsByClassName(windowsGroupDiv,"window");
  //inicializar primero el custom scroll
  if(fleXenv)
 	 fleXenv.globalInit();
 	 
  for (var i = 0; i < tmpWindows.length; i++){
    if (tmpWindows[i].className == "window"){
     
      windowDivList[tmpWindows[i].id] = new Window(tmpWindows[i]);
      
  		 windowDivList[tmpWindows[i].id].close() ;
  		
      //el default es open
      if(!windowDivList[tmpWindows[i].id].closed && opened){

	           windowDivList[tmpWindows[i].id].open();  
	            windowDivList[tmpWindows[i].id].getWindowPropertiesFromCookie();
      }else{
     	//if(windowDivList[tmpWindows[i].id].clientArea.innerHTML.indexOf("iframe")>0 ){
       	windowDivList[tmpWindows[i].id].frame.style.zIndex =0;
       	windowDivList[tmpWindows[i].id].frame.style.display='none'
     	//}
      }

      /*if(windowDivList[tmpWindows[i].id].scrollable){
       	CSBfleXcroll('scroll'+tmpWindows[i].id)
      }*/
      
      if(windowDivList[tmpWindows[i].id].javascript){
     	//alert("bf eval init");
      	eval('init'+tmpWindows[i].id+'();')
      }
      
    }
  }
    if(windowsGroup=='tmp_windows')
		winTmpList = windowDivList ;
		
	if(windowsGroup == 'persistent_windows'){
		winPersistentList = windowDivList ;
	}
	
	if(windowsGroup == 'win_transactional_pool'){
		winTransactionalList = windowDivList;
	}
	
 	if(windowsGroup == 'global_windows'){
		winGlobalList = windowDivList;
	}
}


function  restoreWindowsByElement(windowsGroup){

	windowsGroupDiv =	document.getElementById(windowsGroup)

  	if(windowsGroup=='tmp_windows')
		windowDivList =	winTmpList;
		
	if(windowsGroup == 'persistent_windows'){
		windowDivList =	winPersistentList;
	}
	
	if(windowsGroup == 'win_transactional_pool'){
		windowDivList =	winTransactionalList;
	}

	if(windowsGroup == 'global_windows'){
		windowDivList =	winGlobalList;
	}
 elList =  winFindElementsByClassName(windowsGroupDiv,"window");
  for (var i = 0; i < elList.length; i++)
    if (elList[i].className == "window"){
     
      windowDivList[elList[i].id].originalPos();
     
      if(!windowDivList[elList[i].id].closed){
      	windowDivList[elList[i].id].open();
      }

     
    }

}


function openTmpWindows(id){
	if(winTmpList['winFrame'+id]){
		winTmpList['winFrame'+id].open();
		
	}
	return false;
}

function openPersistentWindows(id){
	if(winPersistentList['winFrame'+id]){
		winPersistentList['winFrame'+id].open();
		
	}
	return false;
}

function openTransactionalWindows(id){
	if(winTransactionalList['winFrame'+id]){
		winTransactionalList['winFrame'+id].open();
		
	}
	return false;
}

function openGlobalWindows(id){
	if(winGlobalList['winFrame'+id]){
		winGlobalList['winFrame'+id].open();
		
	}
	return false;
}

//workaround para mover las ventanas y que suprimir los eventos onmouseover de los demas elementos excepto la ventana
function overlay() {
	el = document.getElementById("overlay");
	el.style.height=screen.height;
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

 function detectMac() {
	  var userAgent = navigator.userAgent.toLowerCase();
	  if (userAgent.indexOf('mac') != -1) {
	    return true;
	  }
 }
 
 
 
 /*organizar ventanas*/
 
 
 
function  cascadeWindowsByElement(windowsGroup,base){
	windowsGroupDiv =	document.getElementById(windowsGroup)
  	if(windowsGroup=='tmp_windows')
		windowDivList =	winTmpList;
	if(windowsGroup == 'persistent_windows'){
		windowDivList =	winPersistentList;
	}
	if(windowsGroup == 'win_transactional_pool'){
		windowDivList =	winTransactionalList;
	}
	if(windowsGroup == 'global_windows'){
		windowDivList =	winGlobalList;
	}
 elList =  winFindElementsByClassName(windowsGroupDiv,"window");
 
  x=15+base;
  
  y=10+130+base;
 
  for (var i = 0; i < elList.length; i++)
    if (elList[i].className == "window" ){
      if( windowDivList[elList[i].id].isOpen){
      	  windowDivList[elList[i].id].frame.style.left=x +"px" 
      	  x+=25;   	
     	  windowDivList[elList[i].id].frame.style.top=y +"px"
     	   y+=35; 
      		windowDivList[elList[i].id].makeActive();
      }
    }
}

  
function  squareWindowsByElement(windowsGroup,base){

	windowsGroupDiv =	document.getElementById(windowsGroup)
  	if(windowsGroup=='tmp_windows')
		windowDivList =	winTmpList;
	if(windowsGroup == 'persistent_windows'){
		windowDivList =	winPersistentList;
	}
	if(windowsGroup == 'win_transactional_pool'){
		windowDivList =	winTransactionalList;
	}
	if(windowsGroup == 'global_windows'){
		windowDivList =	winGlobalList;
	}
	
 elList =  winFindElementsByClassName(windowsGroupDiv,"window");
 		
  x=15+base;y=10+base;
 
  
  base_width=0;
  base_height=0;
  
  prev_width=0;
 
  z=0;
  for (var i = 0; i < elList.length;i++){

		if (elList[i].className == "window"  && windowDivList[elList[i].id].isOpen ){

				if(z%3==0){
					y=y+128
					base_height;
					prev_width = 0;
					base_height= parseInt(windowDivList[elList[i].id].frame.style.height) +10
				}
		
			 
			  
			  	  windowDivList[elList[i].id].frame.style.left= x + prev_width +  "px" 
			  	     //	 alert(prev_width)
			 	  windowDivList[elList[i].id].frame.style.top=y + "px"
			 	    
			  		windowDivList[elList[i].id].makeActive();
			  		
			  	  prev_width = prev_width +  parseInt(windowDivList[elList[i].id].frame.style.width) +20;
	  			 
			  
			 z++;
		}
	 	
   }
}

function restore(){
 	restoreWindowsByElement('persistent_windows')
 		restoreWindowsByElement('tmp_windows')
 			
}
function cascade(){
 	cascadeWindowsByElement('persistent_windows',0)
 		cascadeWindowsByElement('tmp_windows',20)
 			cascadeWindowsByElement('win_transactional_pool',40)
}
function square(){
 	squareWindowsByElement('persistent_windows',0)
 		squareWindowsByElement('tmp_windows',20)
 			squareWindowsByElement('win_transactional_pool',40)
}
  
 
//window.onload = winInit;  // run initialization code after page loads.

//]]>