// ----------------------------------------------------------------------------
// General purpose POPUP window (LAYER/DIV) support
// ----------------------------------------------------------------------------
// *                                                                          *
// *                           Copyright 2002                                 *
// *                        CHECCO SERVICES, INC.                             *
// *                         All Rights Reserved.                             *
// *                                                                          *
// *     This software contains proprietary and confidential information      *
// *     belonging to CHECCO SERVICES, INC., and may not be decompiled,       *
// *     disassembled, disclosed, reproduced or copied without the prior      *
// *     written consent of CHECCO SERVICES, INC..                            *
// *                                                                          *
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Reference Guide
// ----------------------------------------------------------------------------
// Static Objects:
//	PopupClass
// Properties:
//	.master_Alignment
//	.imageBG 
//	.menuCloseDelay 
//	.shownArray 
//	.zNormal
//	.zTopMost
// Methods:
//	.existLayer	
//	.visibleLayer	
//	.moveLayer	
//	.showLayer	
//	.popBoxOnce	
//	.startLayer
//	.startLayerInline
//	.endLayer	
//	.startWindow	
//	.endWindow	
// ----------------------------------------------------------------------------
// Instance Objects:
// Properties:
// Methods:
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Example Usage
// ----------------------------------------------------------------------------
// <script language="JavaScript">
// </script>
// ----------------------------------------------------------------

// ----------------------------------------------------------------------------
// Change History
// ----------------------------------------------------------------------------
// Modified:  John C. Checco
// History:  2002-08-23
// 	- added support for jsRegistry 
// 	- created static class

jsRegistry.add('inline-popup','browser-type','browser-util');

// ----------------------------------------------------------------------------------------------
// POPUP WINDOW SUPPORT
// ----------------------------------------------------------------------------------------------
var PopupClass = new Object();
// -------------------------------------------
PopupClass.forceDIV	=false;
PopupClass.master_Alignment = new String();
PopupClass.imageBG 		= new Image(10,10);
PopupClass.menuCloseDelay 	= 500;
PopupClass.shownArray 	= new Array();
// -------------------------------------------
PopupClass.zNormal	=10;
PopupClass.zTopMost	=99;
// -------------------------------------------
PopupClass.existLayer	=PopupClass_existLayer	;
PopupClass.visibleLayer	=PopupClass_visibleLayer;
PopupClass.moveLayer	=PopupClass_moveLayer	;
PopupClass.showLayer	=PopupClass_showLayer	;
PopupClass.popBoxOnce	=PopupClass_popBoxOnce	;
PopupClass.startLayer	=PopupClass_startLayer	;
PopupClass.endLayer	=PopupClass_endLayer	;
PopupClass.startWindow	=PopupClass_startWindow	;
PopupClass.endWindow	=PopupClass_endWindow	;
PopupClass.startLayerInline=PopupClass_startLayerInline	;
PopupClass.endLayerInline=PopupClass_endLayerInline	;

// functions go here
// -------------------------------------------
function PopupClass_existLayer(layerName)
{
   return BrowserUtil.findLayer(layerName);
}

function PopupClass_visibleLayer(layerName)
{
	var rc = false;
	var pL = BrowserUtil.findLayer(layerName);
	if (pL) {
		if (BrowserType.is_nav4) {
			rc = pL.visibility;
		} 
		else {
			rc = pL.style.visibility;
		}
	}
	//BrowserUtil.alert("visibleLayer(" + layerName + ")=" + rc);
	rc = rc.toLowerCase();
	return rc == "visible" || rc == "show";
}

function PopupClass_moveLayer(layerName,leftPos,topPos,force) 
{
	//BrowserUtil.alert("moveLayer(" + layerName + ")=" + leftPos + "," + topPos);
	var pL = BrowserUtil.findLayer(layerName);
	if (pL) {
		if (BrowserType.is_dom) {
			if ( pL.style.left == 0 || force ) {
				pL.style.left = leftPos + "px";
				pL.style.top = topPos + "px";
			}
		}
		else if (BrowserType.is_nav4) {
		  pL.moveTo(leftPos,topPos);
		} 
		else {
                  if ( pL.style.pixelLeft == 0 || force ) {
				pL.style.pixelLeft = leftPos;
				pL.style.pixelTop = topPos;
			}
		}
	}
	//pL.scrollIntoView(topPos);
}

function PopupClass_showLayer(layerName,on) 
{
	var pL = BrowserUtil.findLayer(layerName);
	if (pL) {
		if (BrowserType.is_nav4) 
		{
			pL.visibility =  (on ? "show" : "hide");
		} 
		else {
			pL.style.visibility = (on ? "visible" : "hidden");
			//pL.style.display = (on ? "block" : "none");
		}
		// update globals
		if ( on ) {
      			PopupClass.shownArray[layerName] = true;
		}
		else {
      			PopupClass.shownArray[layerName] = false;
		}
	} 
}

function PopupClass_popBoxOnce(layerName,posX,posY,force)
{
   if ( !PopupClass.shownArray[layerName] || force )
   { 
      PopupClass.moveLayer(layerName,posX,posY,true);
      PopupClass.showLayer(layerName,true);
   }
   return PopupClass.shownArray[layerName];
}

function PopupClass_startLayer(layerName,zPos,leftPos,topPos,imageURL,jsEventStr)
{
  var bgOpt = "";
  var posStr = "";
  var idStr = "ID='" + layerName + "' NAME='" + layerName + "' ";
  if ( !zPos ) zPos = PopupClass.zNormal;
  var hide = false;
  var visStr = "";
  if ( zPos < 0 ) {
     zPos = Math.abs(zPos);
     hide = true;
  }
  // BrowserUtil.alert ( "startLayer(" + layerName + "," + leftPos + "," + topPos + ")");
  if (BrowserType.is_nav4 && !PopupClass.forceDIV) 
  {
      if ( imageURL ) bgOpt = " BACKGROUND=\"" + imageURL + "\"";
      if ( hide ) visStr = " VISIBILITY=hide";
      else visStr = " VISIBILITY=show";
      if ( topPos && leftPos ) posStr = "TOP=" + topPos + " LEFT=" + leftPos + " ";
      document.write("<LAYER " + idStr + visStr + " Z-INDEX=" + zPos + posStr  + bgOpt + jsEventStr + ">");
  }
  else 
  {
      if ( imageURL ) bgOpt = " background-image:url(" + imageURL + ");";
      if ( hide ) visStr = " VISIBILITY:hidden;";
      else visStr = " VISIBILITY:visible;";
      if ( topPos && leftPos ) posStr = "TOP: " + topPos + "px; LEFT: " + leftPos + "px; ";
      document.write("<DIV " + idStr + " STYLE=\"POSITION:absolute; " + visStr + " Z-INDEX:" + zPos + + posStr + bgOpt + "\"" + jsEventStr + ">");
  }
  // begin client area
  document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=top>");
}

function PopupClass_startLayerInline(layerName,zPos,leftPos,topPos,imageURL,jsEventStr)
{
  var bgOpt = "";
  var posStr = "";
  var idStr = "ID='" + layerName + "' NAME='" + layerName + "' ";
  if ( !zPos ) zPos = PopupClass.zNormal;
  var hide = false;
  var visStr = "";
  if ( zPos < 0 ) {
     zPos = Math.abs(zPos);
     hide = true;
  }
  // BrowserUtil.alert ( "startLayerInline(" + layerName + "," + leftPos + "," + topPos + ")");
  if (BrowserType.is_nav4 && !PopupClass.forceDIV) 
  {
      if ( imageURL ) bgOpt = " BACKGROUND=\"" + imageURL + "\"";
      else bgOpt = " BGCOLOR=\"white\"";
      if ( hide ) visStr = " VISIBILITY=hide";
      else visStr = " VISIBILITY=show";
      if ( topPos && leftPos ) posStr = "TOP=" + topPos + " LEFT=" + leftPos + " ";
      document.write("<ILAYER " + idStr + visStr + " Z-INDEX=" + zPos + posStr  + bgOpt + jsEventStr + ">");
  }
  else 
  {
      if ( imageURL ) bgOpt = " background-image:url(" + imageURL + ");";
      else bgOpt = " background-color:\"white\"";
      if ( hide ) visStr = " VISIBILITY:hidden;";
      else visStr = " VISIBILITY:visible;";
      if ( topPos && leftPos ) posStr = "TOP: " + topPos + "px; LEFT: " + leftPos + "px; ";
      document.write("<DIV " + idStr + " STYLE=\"POSITION:relative; " + visStr + " Z-INDEX:" + zPos + + posStr + bgOpt + "\"" + jsEventStr + ">");
  }
  // begin client area
  document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=top>");
}

function PopupClass_endLayer()
{
   document.write("</TD></TR></TABLE>");
   if (BrowserType.is_nav4 && !PopupClass.forceDIV) 
   {
      document.write("</LAYER>");
   }
   else 
   {
      document.write("</DIV>");
   }
}

function PopupClass_endLayerInline()
{
   document.write("</TD></TR></TABLE>");
   if (BrowserType.is_nav4 && !PopupClass.forceDIV) 
   {
      document.write("</ILAYER>");
   }
   else 
   {
      document.write("</DIV>");
   }
}

function PopupClass_startWindow(layerName,zPos,leftPos,topPos,title,imageURL,jsEventStr)
{
  PopupClass.startLayer(layerName,-Math.abs(zPos),leftPos,topPos,imageURL,jsEventStr);

  // standard window frame
  var borderWidth = 1;
  if ( title ) borderWidth = 4;
  document.write("<TABLE border=" + borderWidth + " cellspacing=0 cellpadding=2>");
  // write titlebar
  if ( title ) {
     document.write("<TR><TD valign=top>");
     document.write("<TABLE border=0 cellspacing=0 cellpadding=0 width=\"100%\" BGCOLOR=\"#08089C\"><TR>");
     if ( title ) {
        document.write("<TD ALIGN=LEFT VALIGN=TOP>&nbsp;<FONT SIZE=3 COLOR=\"#fffff\"><STRONG>");
        document.write(title);
        document.write("</STRONG></FONT></TD>");
     }
     document.write("<TD width=10>&nbsp;</TD>");
     document.write("</TR></TABLE>");
     document.write("</TD></TR>");
  }
  // begin client area
  document.write("<TR><TD>");
}

function PopupClass_endWindow()
{
  document.write("</TD></TR></TABLE>");
  PopupClass.endLayer();
}

