//<Script Language="Javascript">
//*************************************************************************************/
// File:  dhtml.js
// Purpose: Dynamic HTML toolkit.
// Please don't distribute without prior written consent. 
// Programmers:
// - Stacy Haven
//
//*************************************************************************************/
//*************************************************************************************/

//Page Browser Object
function PageBrowserObject(){
	//User Agent
	this.bAgent=navigator.userAgent;
	//Windows

	this.bWin=(this.bAgent.search(/win/i)>-1)?true:false;
	//Mac
	this.bMac=(this.bAgent.search(/mac/i)>-1)?true:false;
	//IE 4
	this.bIE4=(this.bAgent.search(/msie 4\./i)>-1)?true:false;
	//IE 5
	this.bIE5=(this.bAgent.search(/msie 5\./i)>-1)?true:false;
	//IE 6
	this.bIE6=(this.bAgent.search(/msie 6\./i)>-1)?true:false;
	//IE 4.0+
	this.bIE4plus=(document.all)?true:false;
	//Netscape 4.0
	this.bNS4=(document.layers)?true:false;
	//Netscape 6.0
	this.bNS6=(!document.layers && (this.bAgent.indexOf('Netscape6')!=-1))?true:false;
	//Netscape 7.0
	this.bNS7=(!document.layers && (this.bAgent.indexOf('Netscape')!=-1) && !this.bNS6)?true:false;
	//OSX Safari
	this.bSaf=(!document.layers && this.bAgent.search(/applewebkit/i)>-1 && !this.bNS6 && !this.bNS7 && this.bAgent.search(/gecko/i)>-1)?true:false;
	//Mozilla1.1
	this.bMOZ=(!document.layers && this.bAgent.search(/netscape/i)==-1 && !this.bNS6 && !this.bNS7 && !this.bSaf && this.bAgent.search(/gecko/i)>-1)?true:false;
	//IE 4.0+ or NS 4.0+ or NS 6+
	this.bVer4=(this.bNS4||this.bNS6||this.bNS7||this.bMOZ||this.bIE4plus)?true:false;
	//Version
	this.bAgent.search(/mozilla\/(.*)$/i);
	this.bVer=RegExp.$1;
	//IE puts it's actual version number somwhere other than after the Mozilla string.
	//This grabs the correct number.
	if(this.bVer.search(/msie/)>-1){
		this.bVer.search(/msie (.*)/i);
		this.bVer = RegExp.$1;
	}
	//Netscape 6 and above puts it's actual version number somwhere other than after the Mozilla string.
	//This grabs the correct number.
	if(this.bVer.search(/netscape/)>-1){
		this.bVer.search(/netscape..?(\d[0-9\.]+)./i);
		this.bVer = RegExp.$1;
	}
	//Mozilla puts it's actual version number somwhere other than after the Mozilla string.
	//This grabs the correct number.
	if(this.bMOZ){
		this.bVer.search(/rv\:(\d[0-9\.]+)./i);
		this.bVer = RegExp.$1;
	}
	//Safari puts it's actual version number somwhere other than after the Mozilla string.
	//This grabs the correct number.
	if(this.bSaf){
		this.bVer.search(/Safari\/(\d[0-9\.]+)/i);
		this.bVer = RegExp.$1;
	}
	//Major version (ex 5)
	this.bMajVer=parseInt(this.bVer);
	//Minor Version (5.01)
	this.bMinVer=parseFloat(this.bVer);
	//Function to show all values in the Page Browser Object.
	this.SeeAll=function(){var bData="";for(a in this)if(this[a])bData+=a+"="+this[a]+"\n";alert(bData);};
}

PBO=new PageBrowserObject();

//Doc Object
//*************************************************************************************/
//	Write to Object - This function will write anything to a DHTML object
//		Arguments
//			textIn = the text or HTML that you want to write to the object.
//		Returns
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_writeToObject(textIn){
	if(PBO.bIE4plus || PBO.bNS6 || PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		this.innerHTML = textIn;
	}else if(PBO.bNS4){
		this.document.write(textIn);
		this.document.close();
	}else if(!PBO.bVer4){
		return false;
	}
	this.pos = this.getObjectData();
	return true;
}


//*************************************************************************************/
//	Relativly Position Object - This function will position any object relative to
//					any other object on the screen. This helps when
//					you know that you want to place an object relative
//					to another, but don't have the info for that object.
//		Arguments
//			refO = the reference object that you are trying to position relative to.
//			hJ = Horozontal justification. 0 is Left. 1 is Center, 2 is Right.
//			hI =  Horozontal Indent. This is the offset from the justification position.
//			vJ = Vertical justification. 0 is Top. 1 is Center, 2 is Bottom.
//			vI = Vertical Indent. This is the offset from the justification position.
//			resize = boolean of if this is an internal reset of the positioning values.
//		Returns
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_relPosObject(refO,hJ,hI,vJ,vI,resize){
	var addW,addH;
	if ((!this.refOData) || (resize))
		refO.oData=this.getObjectData(refO);
	var oD=this.pos;
	var refOD=refO.oData;
	if (hJ==0)addW=hI;
	if (hJ==1)addW=Math.round((parseInt(refOD.w)-oD.w)/2)+hI;
	if (hJ==2)addW=Math.round((parseInt(refOD.w)-oD.w))+hI;
	if (vJ==0)addH=vI;
	if (vJ==1)addH=Math.round((parseInt(refOD.h)-oD.h)/2)+vI;
	if (vJ==2)addH=Math.round(parseInt(refOD.h)-(oD.h))-vI;
//	alert("AddW = "+addW +"\nAddL = "+addH+"\nL = "+(refOD.l+addW)+"\nT = "+(refOD.t+addH));
	this.pos = this.getObjectData();
	return this.moveTo(refOD.l+addW,refOD.t+addH);
}


function Layerobj_getObjectName(o){
	return (o.name)?o.name:o.id;
}


//*************************************************************************************/
//	Move To - This will move any DHMTL object to the specified location.
//		Arguments
//			l = the left position
//			t = the top position
//		Return
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_moveTo(l,t){
	if(PBO.bIE4plus){
		o=this.getObjectName(this);
		if(t!=null){
			eval("document.all."+o+".style.pixelTop="+t)
		};
		if(l!=null){
			eval("document.all."+o+".style.pixelLeft="+l);
		}
	}else if(PBO.bNS4){
		if(t!=null){
			this.top=t;
		}
		if(l!=null){
			this.left=l;
		}
	}else if(PBO.bNS6 || PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		if(t!=null){
			this.style.top=t;
		}
		if(l!=null){
			this.style.left=l;
		}
	}else if(!PBO.bVer4){
		return false;
	}
	this.pos.l=l;
	this.pos.t=t;
	return true;
}

/*}elsif($PWB->{bNS7} || $PWB->{bMOZ}){
		mfpleasewait.contentWindow.document.write(((this.waitWinText)?this.waitWinText:waitwin));
		mfpleasewait.contentWindow.document.close();
}elsif($PWB->{bNS6}){
		mfpleasewait.contentDocument.write(((this.waitWinText)?this.waitWinText:waitwin));
		mfpleasewait.contentDocument.close();
*/

//*************************************************************************************/
//	Show It - Either shows the layer or not.
//		Arguments
//			oIn - object that you want to change state of.
//			on - boolean of whether to show or not to show the layer.
//		Returns
//			None
//*************************************************************************************/
function Layerobj_showIt(on){
    if(PBO.bIE4plus){
		o=this.getObjectName(this);
		eval("document.all."+o+".style.visibility=("+on+")?'visible':'hidden'");
	}else if(PBO.bNS6||PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		this.style.visibility=(on)?"visible":"hidden";
	}else if(PBO.bNS4){
        this.visibility=(on)?"show":"hide";
	}else if(!PBO.bVer4){
		return false;
	}
	return true;
}

//*************************************************************************************/
//	Move By - This will move any DHMTL object by the amount specified.
//		Arguments
//			l = the amount to move to the left
//			t = the amount to move to the top
//		Return
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_moveBy(l,t){
	if(PBO.bIE4plus){
		o=this.getObjectName(this);
		eval("document.all."+o+".style.pixelTop="+t+"+parseInt(document.all."+o+".style.pixelTop)");
		eval("document.all."+o+".style.pixelLeft="+l+"+parseInt(document.all."+o+".style.pixelLeft)");
	}else if(PBO.bNS4){
		this.top+=t;
		this.left+=l;
	}else if(PBO.bNS6||PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		this.style.top=parseInt(this.style.top)+t;
		this.style.left=parseInt(this.style.left)+l;
	}else if(!PBO.bVer4){
		return false;
	}
	this.pos.l+=l;
	this.pos.t+=t;
	return true;
}


//*************************************************************************************/
//	Resize Object To - This will alter the size of any DHTML object.
//		Arguments
//			h = the new height of the object
//			w = the new width of the object
//		Return
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_resizeTo(w,h){
	if(PBO.bIE4plus){
		o=this.getObjectName(this);
		if(w!=null){
			eval("document.all."+o+".style.pixelWidth="+w);
		}
		if(h!=null){
			eval("document.all."+o+".style.pixelHeight="+h);
		}
	}else if(PBO.bNS4){
		if(w!=null){
			this.clip.width=w;
		}
		if(h!=null){
			this.clip.height=h;
		}
	}else if(PBO.bNS6||PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		if(w!=null){
			this.style.width=w;
		}
		if(h!=null){
			this.style.height=h;
		}
	}else if(!PBO.bVer4){
		return false;
	}
	this.pos.w=w;
	this.pos.h=h;
	return true;
}


//*************************************************************************************/
//	Resize Object By - This will alter the size of any DHTML object by the amount specified.
//		Arguments
//			h = addition to the height of the object
//			w =addition to the new width of the object
//		Return
//			true of complete
//			false if browser not supported
//*************************************************************************************/
function Layerobj_resizeBy(w,h){
	if(PBO.bIE4plus){
		o=this.getObjectName(this);
		(w!=0)?eval("document.all."+o+".style.pixelWidth+="+w):"";
		(h!=0)?eval("document.all."+o+".style.pixelHeight+="+h):"";
	}else if(PBO.bNS4){
		this.clip.width+=w;
		this.clip.height+=h;
	}else if(PBO.bNS6||PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		this.style.width=parseInt(this.style.width)+w;
		this.style.height=parseInt(this.style.height)+h;
	}else if(!PBO.bVer4){
		return false;
	}
	this.pos.w+=w;
	this.pos.h+=h;
	return true;
}


//*************************************************************************************/
//	Get Object Data - This will return the information about an object.
//				(t for top, l for left, w for width, h for height)
//		Arguments
//		Return
//			Object with these properties
//				t = top coordinate
//				l = left coordinate
//				w = width of object
//				h = height of object
//		    else
//			false if browser not supported
//*************************************************************************************/
function Layerobj_getObjectData(oIn){
	var oOut={t:0,l:0,w:0,h:0};
	if(oIn)
		var el=oIn;
	else
		var el=this;
	if (PBO.bMac && PBO.bIE4){
		while (el.tagName!="BODY"){
			el=el.parentElement;
			if (PSisInt(el.offsetTop)&&el.tagName.toLowerCase()!="center")
				oOut.t+=el.offsetTop;
			if (PSisInt(el.offsetLeft)&&el.tagName.toLowerCase()!="center")
				oOut.l+=el.offsetLeft;	}
		oOut.w=eval(el).offsetWidth;
		oOut.h=eval(el).offsetHeight;
	}
	if ((PBO.bMac && PBO.bIE5) || (PBO.bIE4plus && !PBO.bMac)){
		oOut.l=el.offsetLeft;
		oOut.t=el.offsetTop;
		var newp=el.offsetParent;
		while(newp != null){
			oOut.l+=newp.offsetLeft;
			oOut.t+=newp.offsetTop;
			newp=newp.offsetParent;}
	if(PBO.bMac){
			oOut.t+=parseInt(document.body.topMargin);
			oOut.l+=parseInt(document.body.leftMargin);
	}
		oOut.h=(el.height)?el.height:el.offsetHeight;
		oOut.w=(el.width)?el.width:el.offsetWidth;
	}
	if (PBO.bNS4){
		oOut.l=el.x;
		oOut.t=el.y;
		oOut.w=el.width;
		oOut.h=el.height;
		if(!oOut.w){
			oOut.w=el.clip.width;
			oOut.h=el.clip.height;}
	}
	if (PBO.bNS6){
		oOut.l=el.offsetLeft+document.getElementsByTagName('body')[0].offsetLeft;
		oOut.t=el.offsetTop+document.getElementsByTagName('body')[0].offsetTop;
		oOut.w=el.offsetWidth;
		oOut.h=el.offsetHeight;
	}
	if (PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		oOut.l=el.offsetLeft;
		oOut.t=el.offsetTop;
		var newp=el.offsetParent;
		while(newp != null){
			oOut.l+=newp.offsetLeft;
			oOut.t+=newp.offsetTop;
			newp=newp.offsetParent;}
		oOut.h=(el.height)?el.height:el.offsetHeight;
		oOut.w=(el.width)?el.width:el.offsetWidth;
	}
	if(!PBO.bVer4){
		return false;
	}
	return oOut;
}


//*************************************************************************************/
//	Create Layer - This will create a layer at the specified location.
//		Arguments
//			c = object with the following properties
//				l = left coordinate;
//				t = top coordinate;
//				w = width;
//				h = height;
//			oType = object type (DIV, IFRAME) (NS will always be a Layer)
//			oText = object text;
//			aIn = args In;
//		Return
//			Object Handle
//			false if browser isn't supported
//*************************************************************************************/
function Layerobj(c,oType,oText,aIn){
    var ID = Math.random();
    var oID = "L"+Math.round(ID*1000000000000);
	if (PBO.bIE4plus){
		var nL = "<" + oType;
		if (aIn&&aIn.objArgs)
			for (a in aIn.objArgs)
				nL+=" "+a+"='"+aIn.objArgs[a]+"' ";
		nL+=" STYLE='position: absolute;left:"+c.l+"px;top:"+c.t+"px;";
		nL+=" width: "+c.w+((typeof c.w=="number")?"px":"")+
		";height:"+c.h+((typeof c.w=="number")?"px":"")+";";
		if (aIn&&aIn.styleArgs)
			for (a in aIn.styleArgs)
				nL+=" "+a+":"+aIn.styleArgs[a]+";";
		nL+="' id='"+oID+"'>"+oText+"</"+oType+">";
		if(this.id)
			if(PBO.bMac&&PWB.bIE4)
				this.innerHTML += nL;
			else
				document.all[this.id].insertAdjacentHTML('beforeEnd', nL);
		else
			document.body.insertAdjacentHTML('beforeEnd', nL);
		nL=eval(oID);

	}else if(PBO.bNS4){
		if(this.lID)
			nL=new Layer(c.w,this);
		else
			nL=new Layer(c.w,self);
		nL.left=c.l;
		nL.top=c.t;
		nL.clip.height=c.h;
		nL.document.open();
		nL.document.write(oText);
		nL.document.close();
		nL.visibility = 'show';
		if(aIn && aIn.styleArgs)
			for (a in aIn.styleArgs)
				if(a.indexOf("-")==-1)
					eval("nL."+a+"='"+aIn.styleArgs[a]+"'");
		if(aIn&&aIn.objArgs){
			if(aIn.objArgs.src){
				setTimeout("nL.load('"+aIn.objArgs.src+"',100)",500);
			}
		}
		nL.lID = oID;
	}else if(PBO.bNS6||PBO.bNS7 || PBO.bMOZ || PBO.bSaf){
		var nL = document.createElement(oType);
		nL.innerHTML = oText;
		nL.style.position = "absolute";
		if(aIn && aIn.objArgs)
			for (a in aIn.objArgs)
				nL.setAttribute(a,aIn.objArgs[a]);
		if(aIn && aIn.styleArgs)
			for (a in aIn.styleArgs)
				if(a.indexOf("-")==-1)
					eval("nL.style."+a+"='"+aIn.styleArgs[a]+"'");

		if(this.lID)
			var mybody=this;
		else
			var mybody=document.body;
		mybody.appendChild(nL);
		nL.style.top = c.t;
		nL.style.left = c.l;
		nL.lID = oID;
		if(c.w)
			nL.style.width = c.w;
		if(c.h)
			nL.style.height = c.h;
	}
	else if(!PBO.bVer4){
		return false;
	}
	nL.writeToObject = Layerobj_writeToObject;
	nL.moveTo = Layerobj_moveTo;
	nL.moveBy = Layerobj_moveBy;
	nL.resizeTo = Layerobj_resizeTo;
	nL.resizeBy = Layerobj_resizeBy;
	nL.getObjectData = Layerobj_getObjectData;
	nL.relPosObject = Layerobj_relPosObject;
	nL.showIt = Layerobj_showIt;
	nL.getObjectName = Layerobj_getObjectName;
	nL.pos = nL.getObjectData();
	nL.createLayer = Layerobj;
	return nL;
}
