// **************************************************************************************************************************
// MTS3 Layer Creator Javascript
// Filename:	MTS3LayerCreator.js
// By:		Danny Huang, Viewpoint New York, Jun. 8 2001
// Purpose:	Create layer upon different browser
// Usage:	call function openingLayer(vwpt_layerid,vwpt_parms,vwpt_events) and closingLayer()
//		arguments:
//			vwpt_layerid:	layer id of the layer you want create
//			vwpt_parms:	parameters
//				required:
//					top:		the top margin of the layer
//					left:		the left margin of the layer
//					width:		the width of the layer
//					height:		the height of the layer
//					zindex:		the z-index of the layer
//					show:		the visibility of the layer, 1 indicate visible, 0 indicate hidden
//				optional:
//					abs:		layer position, default is absolute, put abs=0 indicate related position
//					bgcolor:	the back ground color of the layer
//			vwpt_events:	mouse events to the layer (optional)
//		examples:
//			<script language="JavaScript">openingLayer('testlayer','top=20;left=20;width=384;height=512;zindex=1;show=1');</script>
//			<!-- the code of the content on the layer -->
//			<script language="JavaScript">closingLayer();</script>
// Support:	IE4, IE5, NS4, NS6
// **************************************************************************************************************************

var IE4 = (document.all && !document.getElementById) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;
var NS4 = navigator.appName.indexOf("Netscape") != -1 && !NS6;
var currentLayerID, vwpt_absValue;

function openingLayer(vwpt_layerid,vwpt_parms,vwpt_events){
 var vwpt_toLeftValue, vwpt_toTopValue, vwpt_widthValue, vwpt_heightValue, vwpt_ZIndexValue, vwpt_bgcolorValue, vwpt_borderValue, vwpt_visibleValue;
 currentLayerID = vwpt_layerid;
 vwpt_absValue = 1;
 if(vwpt_parms != null){
  var vwpt_parmArray = vwpt_parms.split(";");
  for(var i=0; i < vwpt_parmArray.length; i++){
   if(vwpt_parmArray[i] != ""){
    var vwpt_subParmArray = vwpt_parmArray[i].split("=");
    if(vwpt_subParmArray[0].toLowerCase() == "top") vwpt_toTopValue = parseInt(vwpt_subParmArray[1]);
    else if(vwpt_subParmArray[0].toLowerCase() == "left") vwpt_toLeftValue = parseInt(vwpt_subParmArray[1]);
    else if(vwpt_subParmArray[0].toLowerCase() == "width") vwpt_widthValue = parseInt(vwpt_subParmArray[1]);
    else if(vwpt_subParmArray[0].toLowerCase() == "height") vwpt_heightValue = parseInt(vwpt_subParmArray[1]);
    else if(vwpt_subParmArray[0].toLowerCase() == "zindex" || vwpt_subParmArray[0].toLowerCase() == "z-index") vwpt_ZIndexValue = parseInt(vwpt_subParmArray[1]);
    else if(vwpt_subParmArray[0].toLowerCase() == "bgcolor") vwpt_bgcolorValue = vwpt_subParmArray[1];
    else if(vwpt_subParmArray[0].toLowerCase() == "abs") vwpt_absValue = 0;
    else if(vwpt_subParmArray[0].toLowerCase() == "show" && vwpt_subParmArray[1] == 1) (NS4) ? vwpt_visibleValue = 'show' : vwpt_visibleValue = 'visible';
    else if(vwpt_subParmArray[0].toLowerCase() == "show" && vwpt_subParmArray[1] == 0) (NS4) ? vwpt_visibleValue = 'hide' : vwpt_visibleValue = 'hidden';
   }
  }
 }

 if(NS4){
  if(vwpt_absValue==0) document.write('<ilayer id="' + vwpt_layerid + '" left="' + vwpt_toLeftValue + '" top="' + vwpt_toTopValue + '" width="' + vwpt_widthValue + '" height="' + vwpt_heightValue + '" z-index="' + vwpt_ZIndexValue + '"');
  else document.write('<layer id="' + vwpt_layerid + '" position="absolute" left="' + vwpt_toLeftValue + '" top="' + vwpt_toTopValue + '" width="' + vwpt_widthValue + '" height="' + vwpt_heightValue + '" z-index="' + vwpt_ZIndexValue + '"');
  if(vwpt_bgcolorValue != null) document.write(' bgcolor="' + vwpt_bgcolorValue + '"');
  if(vwpt_visibleValue != null) document.write(' visibility="' + vwpt_visibleValue + '"');
  if(vwpt_events != null) document.write(" " + vwpt_events);
  document.write('>');
 }
 else{
  if(vwpt_absValue==0) document.write('<div id="' + vwpt_layerid + '" style="position:relative; left:' + vwpt_toLeftValue + 'px; top:' + vwpt_toTopValue + 'px; width:' + vwpt_widthValue + 'px; height:' + vwpt_heightValue + 'px; z-index:' + vwpt_ZIndexValue);
  else document.write('<div id="' + vwpt_layerid + '" style="position:absolute; left:' + vwpt_toLeftValue + 'px; top:' + vwpt_toTopValue + 'px; width:' + vwpt_widthValue + 'px; height:' + vwpt_heightValue + 'px; z-index:' + vwpt_ZIndexValue);
  if(vwpt_bgcolorValue != null) document.write('; background-color:' + vwpt_bgcolorValue + '; layer-background-color:' + vwpt_bgcolorValue);
  if(vwpt_visibleValue != null) document.write('; visibility:' + vwpt_visibleValue);
  document.write('"');
  if(vwpt_events != null) document.write(" " + vwpt_events);
  document.write('>');
 }
}

function closingLayer(){
 if(NS4){
  if(vwpt_absValue==1) eval("document."+ currentLayerID +".document.write('</layer>')");
  else eval("document."+ currentLayerID +".document.write('</ilayer>')");
 }
 else document.write('</div>');
}