// Span/Layer form v3.0
// author: Evgenij Elizarov
// Creation date: 10.03.2003
// + detect.js

//Initialize Form parametrs
frmParam = new Array();
	//Different parameters
	if(NN && br.version < 5){
		frmParam[0] = new Array("visibility","hide","show","inherit");
		frmParam[5] = new Array("bgcolor","#");
	}else{
		frmParam[0] = new Array("visibility","hidden","visible","inherit");
		frmParam[5] = new Array("backgroundColor","#");
	}
	frmParam[1] = new Array("left","#");
	frmParam[2] = new Array("top","#");
	frmParam[3] = new Array("width","#");
	frmParam[4] = new Array("height","#");


function frmSetParam(id,p,val){	
	param = frmParam[p][0];
	value = val;
	if(frmParam[p][1] !== "#"){
		value = frmParam[p][val + 1];
	}
	if(NN && br.version < 5){
		//Methods for Netscape 4.xx
		code = 'document.layers["form'+id+'"].'+param+' = "'+value+'"';
	}else{
		 obj = MM_findObj("form"+id);
		//Methods for MSIE and else
		//!!!!
		//alert(obj);
		//if (obj.style){
          //     obj = obj.style;
          //     obj = eval(obj param+" = "+value);
	     //}
          code = 'document.all.form'+id+'.style.'+param+' = "'+value+'"';
	}
	eval(code);
}

var frmCount = 0;

//Initialize form object
function form() {
	var i,a = form.arguments;

	this.id			= frmCount;

	// default settings
	this.x			= 0;
	this.y			= 0;
	this.w			= 100;
	this.h			= 100;
	this.visible	= 1;
	this.bgcolor	= "#BABABA";
	this.body     	= "form" + frmCount;
	this.event	    = "";
	this.cls	    = "";
	
	//reset setigns if set
	for(i=0;i<(a.length-8);i+=9){
		if(a[i] != null)  this.x 		= a[i];		//x
		if(a[i+1] != null)this.y 		= a[i+1];	//y
		if(a[i+2] != null)this.w 		= a[i+2];	//w
		if(a[i+3] != null)this.h 		= a[i+3];	//h
		if(a[i+4] != null)this.visible  = a[i+4];	//visible
		if(a[i+5] != null)this.bgcolor	= a[i+5];	//bgcolor
		if(a[i+6] != null)this.body		= a[i+6];	//body
		if(a[i+7] != null)this.event	= a[i+7];	//event
		if(a[i+8] != null)this.cls		= a[i+8];	//class
	}

	//Methods
	this.create			= frmCreate;
	this.setVisible		= frmVisible;
	this.move		    = frmMove;
	this.setBody	    = frmBody;
	this.setBgcolor     = frmBgcolor;
	//Create form
	this.create();
	frmCount++;
}

//Create Form
function frmCreate(){
	if(NN && br.version < 5){
		header 		= '<layer class="'+this.cls+'" '+this.event+' id="form'+this.id+'" left="'+this.x+'" top="'+this.y+'" z-index="1" width="'+this.w+'" height="'+this.h+'" visibility="'+frmParam[0][this.visible + 1]+'" bgcolor="'+this.bgcolor+'">';
		footer		= '</layer>';
	}else{
		header 		= '<div class="'+this.cls+'" '+this.event+' id="form'+this.id+'" style="position:absolute; left:'+this.x+'px; top:'+this.y+'px; width:'+this.w+'px; height:'+this.h+'px; z-index:1; visibility: '+frmParam[0][this.visible + 1]+' ; background-color: '+this.bgcolor+'; layer-background-color: '+this.bgcolor+';">';
		footer		= '</div>';
	}

	obj = header;	obj += this.body;	obj += footer;
	document.write(obj);
}

//Object functions
function frmVisible(value){
	MM_showHideLayers('form'+this.id,'',value);
}

function frmBgcolor(value){
	if(NN && br.version < 5){
		//Methods for Netscape 4.xx
		MM_changeProp('form'+this.id,'','document.bgColor',value,'LAYER')
	}else{
     		MM_changeProp('form'+this.id,'','style.backgroundColor',value,'DIV')
	}
}

function frmMove(){
	var i,a=frmMove.arguments;
	for(i=0;i<(a.length-1);i+=2){
		if(a[i] != null)frmSetParam(this.id,1,a[i]);
		if(a[i+1] != null)frmSetParam(this.id,2,a[i+1]);
	}
}

function frmBody(newText) {
  objName = "form"+this.id;
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {
		document.write(unescape(newText)); document.close();
	}
    else innerHTML = unescape(newText);
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) {
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
