//\/////
//\  overLIB Use Element Contents Plugin
//\
//\  You may not remove or change this notice.
//\  Copyright Erik Bosrup 1998-2003. All rights reserved.
//\  Contributors are listed on the homepage.
//\  See http://www.bosrup.com/web/overlib/ for details.
//\/////
////////
// PRE-INIT
// Ignore these lines, configuration is below.
////////
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.14)) alert('overLIB 4.14 or later is required for the Center Popup Plugin.');
else {
registerCommands('usecontents,replacebody,replacecap');
////////
// DEFAULT CONFIGURATION
// You don't have to change anything here if you don't want to. All of this can be
// changed on your html page or through an overLIB call.
////////
if (typeof ol_usecontents=='undefined') var ol_usecontents='';
if (typeof ol_replacebody=='undefined') var ol_replacebody='';
if (typeof ol_replacecap=='undefined') var ol_replacecap='';
////////
// END OF CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////
////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_usecontents='';
var o3_replacebody=o3_replacecap='';
////////
// PLUGIN FUNCTIONS
////////
function setElementContentsVariables() {
	o3_usecontents=ol_usecontents;
	o3_replacebody=ol_replacebody;
	o3_replacecap=ol_replacecap;
}
// Parses Shadow and Scroll commands
function parseElementContentsExtras(pf,i,ar) {
	var k=i,v;
	if (k < ar.length) {
		if (ar[k]==USECONTENTS) { eval(pf +'usecontents="'+ar[++k]+'"'); return k; }
		if (ar[k]==REPLACEBODY) { eval(pf +'replacebody="'+ar[++k]+'"'); return k; }
		if (ar[k]==REPLACECAP) { eval(pf +'replacecap="'+ar[++k]+'"'); return k; }
	}
	return -1;
}
// Creates the actual popup structure
function createPopup_1(lyrContent){
	// Write layer
	runHook("createPopup",FBEFORE,lyrContent);
	if (o3_wrap) {
		var wd,ww,theObj=(olNs4 ? over : over.style);
		theObj.top=theObj.left=-10000 + (!olNs4 ? 'px' : 0);
		layerWrite(lyrContent);
		wd = (olNs4 ? over.clip.width : over.offsetWidth);
		if (wd > (ww=windowWidth())) {
			lyrContent=lyrContent.replace(/\&nbsp;/g, ' ');
			o3_width=ww;
			o3_wrap=0;
		} 
	}
	layerWrite(lyrContent); 	
	if (!olNs4 && (o3_usecontents || o3_replacebody || o3_replacecap)) lyrContent=resetPUContents(lyrContent);
	// have to set o3_width for placeLayer() routine if o3_wrap is turned on
	if (o3_wrap) o3_width=(olNs4 ? over.clip.width : over.offsetWidth);
	runHook("createPopup",FAFTER,lyrContent);
	return true;
}
function getElement(ID) {
	return (document.all) ? o3_frame.document.all[ID] : o3_frame.document.getElementById(ID);
}
function resetPUContents(content) {
	var elem,obj,objT,tT,rR,cC,bCont='',cCont='';
	if (o3_usecontents) {
		if (!(elem=getElement(o3_usecontents))) return content;
		over.innerHTML = content = elem.innerHTML;
	} else {
		if (o3_replacebody) {
			elem=getElement(o3_replacebody);
			if (elem) bCont=elem.innerHTML;
		}
		if (o3_replacecap) {
			elem=getElement(o3_replacecap);
			if (elem) cCont=elem.innerHTML;
		}
		obj = (document.getElementsByTagName) ? over.getElementsByTagName("TABLE") : over.tags("TABLE");
		if (bCont) {
			tT = ((typeof CSSW3C != 'undefined' && o3_css == CSSW3C) || o3_background) ? 0 : (obj.length > 2 ? 2 : 1);
			rR = ((typeof CSSW3C != 'undefined' && o3_css == CSSW3C) && (o3_cap || cCont) || o3_background) ? 1 : 0;
			cC = (o3_background) ? 1 : 0;
			objT =  obj[tT];
			objT = (document.getElementsByTagName) ? objT.getElementsByTagName("TR") : objT.all.tags("TR");
			objT=objT[rR];
			objT = (document.getElementsByTagName) ? objT.getElementsByTagName("TD") : objT.all.tags("TD");
			objT[cC].innerHTML = bCont;
		}
		if (cCont && !o3_background) {			 
			tT = (typeof CSSW3C != 'undefined' && o3_css == CSSW3C) ? 0 : 1;
			rR = cC = 0;
			objT =  obj[tT];
			objT = (document.getElementsByTagName) ? objT.getElementsByTagName("TR") : objT.all.tags("TR");
			if (typeof CSSW3C != 'undefined' && o3_css == CSSW3C && objT.length > 1 || obj.length > 2) {
				objT=objT[rR];
				objT = (document.getElementsByTagName) ? objT.getElementsByTagName("TD") : objT.all.tags("TD");
				objT[cC].innerHTML = cCont;
			}
		}
		content=over.innerHTML;	
	}
	return content;
}
////////
// PLUGIN REGISTRATIONS
////////
registerRunTimeFunction(setElementContentsVariables);
registerCmdLineFunction(parseElementContentsExtras);
registerHook('createPopup',createPopup_1,FREPLACE);
}
//end 
