/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*	Filename: mocc_lib_divs.js																		*/
/*	current version: 2.0												*/
/*	date: 2007-09-11													*/
/*	Description: This file contains the necessary functions to modify DIV text		*/
/*						and visibility.																*/
/*																											*/
/*	Dependencies: mocc_lib_elems.js																*/
/*	Contributors (chronological order, starting with originating author):									*/
/*					1. Matt Olinger (MO)																	*/
/*					2. Cliff Chambers (CC)																*/
/*																											*/
/*************************************************************************************/
/*	version history:													*/
/*************************************************************************************/
/*	Prior to version 2, version history was not kept.								*/
/*	Changes to version 2.0 (2007-09-11):												*/
/*		-moved function (getElem) to mocc_lib_elems.js									*/
/*  Version 2.1, updated 2007-10-20 with function: createOverDIV (CC, MO)
/*  Version 2.1, updated 2007-10-28 with additions to function: createOverDIV (MO)
/*																*/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/


/*********************************************************************************/
/*	FUNCTION setDiv																					*/
/*	Parameters: ob=string specifying ID of the element (DIV) to be modified			*/
/*					txt=text to insert into the DIV 												*/
/*						if txt=null or undefined, txt is not changed							*/
/*					txtMode=how to insert the text:												*/
/*									'overwrite'=overwrite the existing text in the DIV		*/
/*									'append'=append txt to the existing text in the DIV	*/
/*									'prepend'=prepend txt to the existing text in the DIV	*/
/*					vis=visibility to which the DIV should be set							*/
/*						if vis=null or undefined, the visibility is not changed			*/
/*																											*/
/*	Returns: Nothing																					*/
/*																											*/
/*	Dependencies: mocc_liv_elems.js (getElem)															*/
/*																											*/
/*********************************************************************************/
function setDiv(ob,txt,txtMode,vis) {
	elem=getElem(ob);
	if (elem=='undefined' || elem==null) { 
		alert('an error occurred in updating '+ob+'. Try reloading the page to fix this issue or contact the website administrator with this message.'); 
	} else {
		if (txt!=undefined && txt!=null) {
			if (txtMode==undefined || txtMode==null) txtMode='overwrite';
			if (txtMode=='append') elem.innerHTML+=txt;
			else if (txtMode=='prepend') elem.innerHTML=txt+elem.innerHTML;
			else	elem.innerHTML = txt;
		}
		if (vis!=undefined && vis!=null) elem.style.display=vis;
	}
}

/*********************************************************************************/
/*	FUNCTION setDivText																				*/
/*	Parameters: ob=string specifying ID of the element (DIV) to be modified			*/
/*					txt=text to insert into the DIV 												*/
/*						if txt=null or undefined, txt is not changed							*/
/*					txtMode=how to insert the text:												*/
/*									'overwrite'=overwrite the existing text in the DIV		*/
/*									'append'=append txt to the existing text in the DIV	*/
/*									'prepend'=prepend txt to the existing text in the DIV	*/
/*																											*/
/*	Returns: Nothing																					*/
/*																											*/
/*	Dependencies: none																		*/
/*																											*/
/*********************************************************************************/
function setDivText(ob,txt,txtMode) {
	if (txtMode==undefined || txtMode==null) txtMode='overwrite';
	setDiv(ob,txt,txtMode);
}


/*********************************************************************************/
/*	FUNCTION createOverDIV																			*/
/*	Parameters: id=string specifying ID of the element (DIV) to be created			*/
/*					class=string specifying class of the DIV to be created				*/
/*					txt=text to insert into the DIV 												*/
/*																											*/
/*	Returns: Nothing																					*/
/*																											*/
/*	Dependencies: mocc_lib_divs.js, mocc_lib_HMI.js, mocc_lib_browser.js
/*																											*/
/*********************************************************************************/
var GiFrame;
function createOverDIV(did,dclass,txt,x,y) {
	var bt=determineBrowser();

	var childattrib = new Array("class," + dclass,"id," + did);
	var parent="document";
	if (x==undefined) {
		x=o3_x + 15;
	}
	if (y==undefined) {
		y=o3_y - 10;
	}

	insertElem(parent,'div','',childattrib);

	var docTop=getScrollTop(bt);
	var docRight=getScrollLeft(bt) + getDocWidth(bt);

	var elem=getElem(did);
	setDiv(did,txt);
	var top = y - elem.offsetHeight - 10;
	var r = x + elem.offsetWidth - 10;

	if (docRight<r) var left=x - elem.offsetWidth - 20; //going off the screen to the right, so go left
	else var left=x;

	if (docTop>top) top=y + 10;	//going off the screen at top, so go below the mouse pointer
	else top=y - elem.offsetHeight + 10;

	setElemStyle(did,'top: '	+ top + 'px; left: ' + left + 'px;');

	if (bt == 'IE') { //start iFrame workaround code for ie6
	    var iFrame = document.createElement("IFRAME");
	    iFrame.setAttribute("src", "");
		iFrame.id = "gdframe";
	    iFrame.style.position = "absolute";
	    iFrame.style.left = left + 'px';
	    iFrame.style.top = top + 'px';
	    iFrame.style.width = elem.offsetWidth + 'px';
	    iFrame.style.height = elem.offsetHeight + 'px';
	    document.body.appendChild(iFrame);
	    GiFrame = iFrame;
	}	//end iFrame workaround code ie6
}

function createShadowDIV(elemID,shadowclass,xoffset,yoffset,color) {
	if (getElemCountByID(elemID)>0) {
		ob=getElem(elemID);
		divx=ob.offsetLeft + xoffset;
		divy=ob.offsetTop + yoffset;
		divw=ob.offsetWidth;
		divh=ob.offsetHeight;
		divz=ob.style.zIndex - 1;

		if (getElemCountByID(elemID + '_shadow')==0) {
			createOverDIV(elemID + '_shadow',shadowclass,'',divx+xoffset,divy+yoffset);
		}
		ob=getElem(elemID + '_shadow');
		ob.style.top = divy; 
		ob.style.left = divx;
		ob.style.width = divw;
		ob.style.height = divh;
		if (color!=undefined) {
		}
		ob.style.zIndex=divz;
		ob.style.display='block';
	}
}

function toggleDiv(dID) {
	if (document.getElementById) {	// this is the way the standards work
		var style2 = document.getElementById(dID).style;
		style2.display = style2.display!="block"? "block":"none";
	}
	else if (document.all) {			// this is the way old msie versions work
		var style2 = document.all[dID].style;
		style2.display = style2.display!="block"? "block":"none";
	}
	else if (document.layers) {		// this is the way nn4 works
		var style2 = document.layers[dID].style;
		style2.display = style2.display!="block"? "block":"none";
	}
}

