/*------------------------------------------------------------------------------------------
Floating Window Object

Usage Example:
	1. Create this object on the page. This should be done in the onLoadActions() function.  An error may occur if the object is created before that.
	var oFloatingWindow = new ckFloatingWindowObj();
	
	2. Associate an HTML object on your page (DIV/TABLE/whatever) with a unique ID.  Add as many content types as you want. 
	Different IDs may point to the same content.  This is done in the example below where the same HTML object is associated
	with two unique IDs...each having a different window title.  The concept of content types was implemented so a single
	"ckFloatingWindowObj" can display numerous different pieces of content
	
	oFloatingWindow.addContentType("noteCreate","Add A Note",document.getElementById("editNoteContent"));
	oFloatingWindow.addContentType("noteEdit","Edit A Note",document.getElementById("editNoteContent"));
	oFloatingWindow.addContentType("linkEdit","Edit A Link",document.getElementById("editLinkContent"));
	
	3. At the appropriate time for whatever your page needs, call the show() function.  The paramter passed is the
	unique ID that you used in addContentType.  The show function will "shield" the screen with a semi-transparent
	layer so no items underneath it may be clicked, then display a window centered on the page that contains the
	HTML object you specified for the ID passed.
	
	oFloatingWindow.show("noteCreate")
	
	4. At the appropriate time for whatever your page needs, call the hide() function.
	
	oFloatingwindow.hide();
	
	
Usage Example:
	If you just need to implement the "shield" feature of the floating window, call show() without any paramters
	
	var oFloatingWindow = new ckFloatingWindowObj();
	oFloatingWindow.show();
	oFloatingWindow.hide();
	
------------------------------------------------------------------------------------------*/

function ckFloatingWindowObj() {
	this.uniqueID = this._getUniqueID(); //since more than one floating window can be declared on a page, need a way to uniquely identify the DOM elements built for each
	this.shieldContainer = null;
	this.windowContainer = null;
	this.frameContainer = null;
	
	this.contentContainer = null;
	this.titleContainer = null;
	this.messageContainer = null;
	this.closeContainer = null;
	this.errWarnInfoContainer= null;
	
	this.returnHandler = null; //what to call after closing window
	this.oWindowContent = null; //the current window content obj (floatingWindowContentObj) being displayed
	
	this.bShowing = false;
	this.bShowingWait = false;
	this.bShowingAndWaiting = false; //indication of a special call, not just a combo of bShowing and bShowingWait
	
	this.bAllowClose = true; 
	this.aExternalContent = new Array();
	this.aPresetMessages = new Array();

	
	this.bShowingConfirm = false;
	this._fnConfirmCaller = null;
	this._confirmCallerArgs = null;
	this._oPreservedContext = null;

	this.bInit = false;
	
	return this;
}

/*------------------------------------------------------------------------------------------
Init
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype._init = function() {
	//broken out of the instantiation routine so the object could be created immediately on page instead of onload. When waiting
	// to create onload, it caused errors when other functions (also onload) attempted to access it before this onload was fired.
	try {
		//Create these dummy functions that lead to prototyped functions so we can continue using the "this" syntax in event generated calls. 
		//	Otherwise the variable name for this object would always have to be the same in the calling page
		var oParent = this;
		this._fnOnresize = function() {	oParent._onresize(); }
		this._fnOnresizeContent = function() { oParent._onresize_content(); }
		this._fnOnclickClose = function() { oParent.hide(); }
		
		//create the shield behind the floating window
		var oDiv = document.createElement("DIV");
		oDiv.id="floatingWindow.shield." + this.uniqueID;
		oDiv.className = "floatingWindow-shield"; 
		oDiv = document.body.appendChild(oDiv);
		this.shieldContainer = oDiv; 

		
		//create floating window shell
		this._createFloatingWindow();

		//
		
		this.addPresetMessage("systemCandyCane",'<div class="floatingWindow-candyCaneStatusBar">Working.  Please wait...</div>')
		
		var oDiv = document.createElement("DIV"); //so error will show on an Ajax call that doesn't have a floating window already open
		oDiv.id="floatingWindow.standaloneError." + this.uniqueID;
		oDiv.style.display="none";
		oDiv = document.body.appendChild(oDiv);
		this.addContentType("standaloneError","Error",oDiv);
		
		this.bInit = true;
				
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj._init()",err);
	}	
	
	
}

/*------------------------------------------------------------------------------------------
Set Opacity
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.setOpacity = function(opacity) {
	if (opacity != "") {
		if (this.shieldContainer) {
			this.shieldContainer.style.filter="alpha(opacity=" + opacity + ")";
			this.shieldContainer.style.opacity="0." + opacity;
		}
	}
}
/*------------------------------------------------------------------------------------------
Allow/DoNotAllow Close
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.allowClose = function() {
	this.bAllowClose = true;
}
ckFloatingWindowObj.prototype.doNotAllowClose = function() {
	this.bAllowClose = false;
}

/*------------------------------------------------------------------------------------------
getOrCreate
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.getOrCreate = function(containerID,width) { //optional: sTitle,contentID
	//if contentTypeID not explicitly passed in, use containerID
	var sTitle = (arguments.length >=3 ? arguments[2] : "");
	var contentID = (arguments.length >=4 ? arguments[3] : containerID);
	
	var oEl = document.getElementById(containerID);
	if (!oEl) {
		oEl = document.createElement("DIV")
		oEl.id = containerID;
		oEl.style.width=(width==0 ? "auto" : width + "px");
		oEl.style.display="none";
		document.body.appendChild(oEl);
	}
	if (oEl) this.addContentType(contentID,sTitle,oEl);
	
	return oEl;
}
/*------------------------------------------------------------------------------------------
show
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.showAndWait = function(contentID) {
	//common enough a sequence to have it's own function
	var sTitle = (arguments.length ==2 ? arguments[1] : null);
	this.fillAndShow(contentID,"",sTitle); //clears existing content. If we're calling a show and wait, we assume the interior content is dynamic and should be cleared each time
	this.showWait();
	this.bShowingAndWaiting = true;
}
ckFloatingWindowObj.prototype.fillAndShow = function(contentID,sHTML) {
	var oWindowContent;
	if (oWindowContent =this.aExternalContent[contentID]) {
    	if (oWindowContent.externalContainer) {
    		oWindowContent.externalContainer.innerHTML = sHTML;
    		this.hideWait();
    		this.hideErrWarnSuccess();

			var sTitle = (arguments.length==3 ? arguments[2] : null);
    		this.show(contentID,sTitle);

    		return true;
    	}
    } else throwConsoleError("ckFloatingWindowObj.fillAndShow()","Container with id='" + contentID + "' was not found");
    return false;
}

ckFloatingWindowObj.prototype.show = function() {
	if (!this.bInit) this._init();
	try {
		var contentID = (arguments.length >=1 ? arguments[0] : ""); //a blank contentID will show the shield and nothing else

		var aExcludeForParentIDs = null;
		
		//Hide any quickviews still open. The only problem is it only catches this if we've used the default oQuickview variable name on the page (normal though)
		var bQuickviewDeclared;
		try { bQuickviewDeclared = (oQuickview != null); } catch(err) { bQuickviewDeclared=false; }
		if (bQuickviewDeclared) oQuickview.hide();
		
		//if one show called directly after another, need to hide before showing again unless we called showAndWait() which assumes the next call will be fillAndShow() so we don't need to hide first
		if (!this.bShowingAndWaiting) {
			if (this.isShowing()) this.hide(); 

			if (contentID != "") {
				if (this.oWindowContent =this.aExternalContent[contentID]) {
			   
					//allow for dynamic assignment of objects...not just ones passed in onload
			    	if (!this.oWindowContent.externalContainer) this.oWindowContent.externalContainer = document.getElementById(this.oWindowContent.externalContainerID)
			    
			    	if (this.oWindowContent.externalContainer) {
			     		aExcludeForParentIDs = Array(this.oWindowContent.externalContainer.id);
					    this.titleContainer.innerHTML = (((arguments.length >=2) && (arguments[1])) ? arguments[1] : this.oWindowContent.windowTitle); //optional to replace the preset title with a different one during show;
	
			     		if (document.all) {
			      			this.contentContainer.swapNode(this.oWindowContent.externalContainer);
					    } else {
							var oParent = this.contentContainer.parentNode;
							oParent.removeChild(this.contentContainer);
			      
							this.oWindowContent.externalContainer.parentNode.appendChild(this.contentContainer);
							this.oWindowContent.externalContainer.parentNode.removeChild(this.oWindowContent.externalContainer);
			      
							oParent.appendChild(this.oWindowContent.externalContainer);
						}
	
						this.oWindowContent.externalContainer.style.display="block";
						this._fnOnresizeContent();
	
						this.addEvent(this.oWindowContent.externalContainer,"resize",this._fnOnresizeContent);
						
					} else throw ("Setup error. The HTML object specified for the requested\ncontent (" + contentID + ") does not exist");
				} else throw ("Requested content (" + contentID + ") does not exist.\n");
			}
	 
			this.addEvent(window,"resize",this._fnOnresize);
			
			//if there is a SELECT tag within the HTML surrounded by the contentID we're displaying, then it can't be hidden.
			hideSpecificHTMLTag('select',true,aExcludeForParentIDs);
		} else {
			if ((arguments.length >=2) && (arguments[1])) this.titleContainer.innerHTML = arguments[1]; //still need to provide this feature when using showAndWait
		}

		this._fnOnresize();
		this.bShowing = true;


		if (this.closeContainer) this.closeContainer.style.display=(this.bAllowClose ? "block" : "none");
		
		this.clearMessage(); //always a good idea to clear??
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.show",err);
	}
}
ckFloatingWindowObj.prototype.isShowing = function() {
	return this.bShowing;
}
/*------------------------------------------------------------------------------------------
Alert
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.alert = function(sText) {
	var sStyle = (arguments.length>= 2 ? arguments[1] : "alert");
	
	var oEl = this.getOrCreate("floatingWindow.alert." + this.uniqueID,400);
	if (oEl) {
		this.addContentType("alert","",oEl);
		oEl.style.width= (sText.length > 300 ? "500px" : "400px");
		/*
		sHTML = '<div style="float:left;padding:0 20px 20px 0"><img src="/_ckcommon/images/fw/' + sStyle + '.gif" width="40" /></div><br/>'
		sHTML += sText;
		*/
		sHTML = '<div style="float:left;width:60px;"><img src="/_ckcommon/images/fw/' + sStyle + '.gif" width="40" /></div>';
		sHTML += '<div style="float:left;width:' + (sText.length > 300 ? "430px" : "330px") + '">' + sText + '</div>';
		
		sHTML += '<div align="center" style="padding-top:20px;clear:both">';
		
		if (sStyle=="confirm") {
			sHTML += '<div id="floatingWindow.confirmButtons"><input type="button" class="button" value="Ok" style="width:70px" onclick="oFloatingWindow.__returnConfirm(true)">&nbsp;';
			sHTML += '<input type="button" class="button" value="Cancel" style="width:70px" onclick="oFloatingWindow.__returnConfirm(false)"></div>';
		} else {
			sHTML += '<input type="button" class="button" value="Ok" style="width:60px" onclick="oFloatingWindow.hide()">';
		}
		sHTML += '</div>';
		
		oEl.innerHTML = sHTML;

		if (this.isShowing()) this.hide(); //hide before showing again in here (even though show will do it) so we can preserve the doNotAllowClose and title
		this.doNotAllowClose();

		this.show("alert","");

	}
}

/*------------------------------------------------------------------------------------------
Confirm
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.confirm = function(sText) { //opt:oPreservedContext,bShowWaitIfConfirmed
	
	if (!this.bShowingConfirm) {
		this._fnConfirmCaller = arguments.callee.caller;
		this._confirmCallerArgs = this._fnConfirmCaller.arguments; //arguments.callee.caller.arguments;
		//second parameter is used to preserve context of JS objects calling this from within on of their prototypes
		this._oPreservedContext = (arguments.length>=2 ? arguments[1] : null)
		
		this.alert(sText,"confirm");
		this.bShowingConfirm = true; //very important that we now set a confirm is in progress (after calling alert) so the next call to this doesn't come in here
		return false; //the calling script will have to know script execution doesn't stop. We're just simulating the behavior of the built in confirm function
	} else {
		/*This is the second call to confirm which originated from __returnConfirm. So return true...the indication that the Ok button was pressed
			There is always something going on after a confirm, so show wait. Calling script can hideWait or hide altogether if necessary
			Showing wait also allows errors to show in floating window.
		*/
		var oEl = document.getElementById("floatingWindow.confirmButtons");
		if (oEl) oEl.style.visibility="hidden";
		this.showWait(); 

		return true;
	}
}


ckFloatingWindowObj.prototype.__returnConfirm = function(bConfirmed) {
	if (!bConfirmed) {
		this.hide();
		this.bShowingConfirm = false;
	} else {
		//call the originating function again, which will cause another call to confirm() but we know it's the second call because the bShowingConfirm flag is still set
		var sArgs = arrayToString(this._confirmCallerArgs);
		sEval = "this._fnConfirmCaller.call(this._oPreservedContext" + (sArgs !="" ? "," + sArgs : "") + ")";
		eval(sEval);
	}
	this._oPreservedContext = null;
	this._fnConfirmCaller = null;
	this._confirmCallerArgs = null;
}

/*------------------------------------------------------------------------------------------
Messages
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.addPresetMessage = function(id,sHTML) {
	if (id != "") this.aPresetMessages[id] = sHTML;
}
ckFloatingWindowObj.prototype.showPresetMessage = function(id) {
	var sAdditional = (arguments.length==2 ? arguments[1] : "");
	if (this.aPresetMessages[id]) {
		var sHTML = this.aPresetMessages[id] + "&nbsp;" + sAdditional;
		this.showMessage(sHTML);
	}
}
ckFloatingWindowObj.prototype.clearMessage = function() {
	if (this.messageContainer) {
		this.messageContainer.innerHTML = ""; //blank string will cause the bar to appear to hide, which may be a nice feature
		this.messageContainer.style.display="none";
	}
}

ckFloatingWindowObj.prototype.showMessage = function(sHTML) {
	if (this.messageContainer) {
		this.messageContainer.innerHTML = sHTML;
		this.messageContainer.style.display="block";
	}
}
/*------------------------------------------------------------------------------------------
Err Warn Success
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.hideErrWarnSuccess = function() { if (this.errWarnInfoContainer) this.errWarnInfoContainer.style.display="none"; }
ckFloatingWindowObj.prototype.showError = function(sText) { this._showErrWarnSuccess("error",sText); }
ckFloatingWindowObj.prototype.showSuccess = function(sText) { this._showErrWarnSuccess("success",sText); }
ckFloatingWindowObj.prototype.showWarning = function(sText) { this._showErrWarnSuccess("warning",sText); }

ckFloatingWindowObj.prototype._showErrWarnSuccess = function(sType,sText) {
	if (this.bShowing && !this.bShowingConfirm) {
		//display inline
		this.hideWait();
		
		var oContainer;
		if (oContainer = this.errWarnInfoContainer) {
			oContainer.cells.item(0).innerHTML=sText
			oContainer.cells.item(0).className=(sType=="error" ? "errorDisplay" : (sType=="warning" ? "warningDisplay" : "infoDisplay"));
			oContainer.style.display="";

			this.refreshDisplay();	
		}
	} else if (this.bShowingWait && !this.bShowing) {	
		this.hideWait();
		this.alert(sText,sType);
	} else {
		this.alert(sText,sType)
	}
	
}

/*------------------------------------------------------------------------------------------
Wait
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.showWait = function() {
	var sTitle = (arguments.length==1 ? arguments[0] : "Working. Please Wait...");
	
	this.hideErrWarnSuccess();
	if (this.isShowing()) {
		//show the wait symbol in the bottom status bar
		this.showPresetMessage("systemCandyCane");
	} else {
		//show the large wait window
		var oDiv = this.getOrCreate("floatingWindow.candyCane." + this.uniqueID,0); //width controlled via stylesheet. Use 0 to trigger "auto"
		oDiv.innerHTML = '<div class="floatingWindow-candyCane-text">' + sTitle + '</div><div class="floatingWindow-candyCane"></div>';
		this.addContentType("systemCandyCane","",oDiv);
		
		this.doNotAllowClose();
		this.show("systemCandyCane","");
		this.bShowing=false; //the .show() return sets bShowing, but we need to be able to distinguis between showing content and showing the wait window, so unset it here
	}
	
	this.bShowingWait = true;
}
ckFloatingWindowObj.prototype.hideWait = function() {
	if (this.bShowingWait) {
		if (this.isShowing()) {
			//the wait symbol in the bottom status bar
			this.clearMessage();
		} else {
			//the large wait window
			this.hide();
		}
		this.bShowingWait = false;
	}
}

ckFloatingWindowObj.prototype.refreshDisplay = function() {
	this._onresize_content();
	this._onresize();
}
ckFloatingWindowObj.prototype.refreshFrame = function() {
	//originally separate so we can resize just the frame when needed after dynamically adding/removing an element from the FW display
	if (this.frameContainer) {
		with (this.frameContainer) {
			style.top = this.windowContainer.style.top;
			style.left = this.windowContainer.style.left;
			style.width = this.windowContainer.offsetWidth; //style.width;
			style.height = this.windowContainer.offsetHeight;
			style.display = this.windowContainer.style.display;
		}
	}
}

/*------------------------------------------------------------------------------------------
hide
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.hide = function() {
	if (this.bShowing || this.bShowingWait) try {
		if (this.shieldContainer) this.shieldContainer.style.display="none";
		if (this.windowContainer) this.windowContainer.style.display="none";
		if (this.frameContainer) this.frameContainer.style.display="none";

		this.removeEvent(window,"resize",this._fnOnresize);
		
		//resets done before window content cleared in case close handler functions also make calls to hide floatingWindow. Otherwise too much recursion
		hideSpecificHTMLTag('select',false);
		this.hideErrWarnSuccess();
		this.clearMessage();
		this.bShowing = false;
		this.bShowingWait = false;
		this.bShowingConfirm = false;
		this.bShowingAndWaiting = false;
		this.allowClose(); //by default, always revert back to being allowed to close the window
		
		if (this.oWindowContent) {
			with (this.oWindowContent) {
				if (externalContainer) {
	
					this.removeEvent(externalContainer,"resize",this._fnOnresizeContent);	
					externalContainer.style.display="none";
					if (document.all) {	
						externalContainer.swapNode(this.contentContainer);
					} else {
						var oParent = externalContainer.parentNode;
						oParent.removeChild(externalContainer);
						this.contentContainer.parentNode.appendChild(externalContainer);
						this.contentContainer.parentNode.removeChild(this.contentContainer);
						oParent.appendChild(this.contentContainer);
					}
				}
				for (var index=0; index < aCloseHandlers.length; index++) {
					if (aCloseHandlers[index] != null) aCloseHandlers[index]();
				}
			}
		}
		this.oWindowContent = null;
		
		

	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.hide()", err);
	}
}


/*------------------------------------------------------------------------------------------
addContentType

Parameters:
	contentID = your own unique id that will be associated with the externalContainer. You will use this contentID when calling "show()"
	windowTitle = whatever text (HTML allowed) to display in the title area of the floating window
	externalContainer = pointer to the HTML object (DIV/TABLE/whatever) that will be displayed within the floating window
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.addContentType = function(contentID,windowTitle,externalContainer) {
	try {
		var closeHandler = (arguments.length==4 ? arguments[3] : null);
		
		this.aExternalContent[contentID] = new ckFloatingWindowContentObj(contentID,windowTitle,externalContainer,closeHandler)
	} catch(err) {
		throwConsoleError("ckFloatingWindowObj.addContentType(" + contentID + ")",err);
	}
}


/*------------------------------------------------------------------------------------------
PRIVATE FUNCTIONS

	These will never be called by anything other than this object itself.
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype._createFloatingWindow = function() {
	try {
		var oDiv = document.createElement("DIV");
		oDiv.id = "floatingWindow.shell." + this.uniqueID;
		oDiv.style.width="auto"; //switch made from 400px so we can control via stylesheet. CK site wanted small loading window "400px";
		oDiv.style.height="200px";
		oDiv.style.position="absolute";
		oDiv.className="floatingWindowShell";
		
		oDiv.style.zIndex=1000;
		oDiv.style.display="none";
		
		oDiv = document.body.appendChild(oDiv);
		this.windowContainer = oDiv; 
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.createFloatingWindow()\nCreating Shell.",err);
	}
	
	/*
	Not needed in CK environment
	try {
		var oEl = document.createElement("IFRAME");
		oEl.id = "floatingWindow.frame." + this.uniqueID;
		oEl.style.width="402px";
		oEl.style.height="202px";
		oEl.style.position="absolute";
		oEl.className="floatingWindowFrame";
		
		oEl.style.zIndex=999;
		oEl.style.display="none";
		
		oEl = document.body.appendChild(oEl);
		this.frameContainer = oEl; 
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.createFloatingWindow()\nCreating Frame.",err);
	}
	*/
	
	sHTML = '<table width="100%" cellpadding="0" cellspacing="1" class="floatingWindow">';
	sHTML +='<tr>';
	sHTML +='	<td class="titleCell">';
	sHTML +='		<div id="floatingWindow.title.' + this.uniqueID + '" class="title" style="float:left"></div>';
	sHTML +='		<div id="floatingWindow.close.' + this.uniqueID + '" class="close" style="float:right;display:none" onmouseover="this.className=\'close-over\'" onmouseout="this.className=\'close\'">&nbsp;</div>';
	sHTML +='	</td>';
	sHTML +='</tr>';
	sHTML +='<tr id="floatingWindow.errWarnInfo.' + this.uniqueID + '" style="display:none"><td style="padding:8px"></td></tr>';
	
	sHTML +='<tr><td style="padding:20px" valign="top"><div id="floatingWindow.content.' + this.uniqueID + '" style="position:relative"></div></td></tr>';	
	sHTML +='</table>';
	sHTML += '<div class="floatingWindow-message" id="floatingWindow.message.' + this.uniqueID + '">&nbsp;</div>';
	
	try {
		if (this.windowContainer) this.windowContainer.innerHTML = sHTML;

		this.titleContainer = document.getElementById("floatingWindow.title." + this.uniqueID);
		this.contentContainer = document.getElementById("floatingWindow.content." + this.uniqueID);
		this.messageContainer = document.getElementById("floatingWindow.message." + this.uniqueID);
		this.closeContainer = document.getElementById("floatingWindow.close." + this.uniqueID);
		this.errWarnInfoContainer= document.getElementById("floatingWindow.errWarnInfo." + this.uniqueID);

		if (this.closeContainer) this.addEvent(this.closeContainer,"click",this._fnOnclickClose);
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.createFloatingWindow()\nCreating Content Container.",err);
	}
}


ckFloatingWindowObj.prototype._onresize = function() {
	try {
		if (this.shieldContainer) {
			with (this.shieldContainer) {
				//clientHeight is height of visible area
				//scrollHeight is height of "content only" with scroll
				//if clientHeight > scrollHeight, there is no scroll bar
				
				style.width=document.body.scrollWidth;
				style.height=(document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight);

				style.display="block";
			}
		}
		
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.onresize()\nResizing content shield.",err);
	}

	try {
		if ((this.windowContainer) && (this.oWindowContent)) {
			with (this.windowContainer) {
				style.display="block";
			
				var iTop = (document.body.clientHeight / 2) - (clientHeight / 2) + document.body.scrollTop;
				style.top = (iTop < 0 ? 20 : iTop);
				style.left = (document.body.clientWidth / 2) - (clientWidth / 2);
			}
			
		}
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.onresize()\nResizing window.",err);
	}
	
	this.refreshFrame();
	
}


ckFloatingWindowObj.prototype._onresize_content = function() {
	try {
		if (this.oWindowContent) {
			if (this.windowContainer) {
				with (this.windowContainer) {
					var sDisplay = style.display; //if not displayed yet, we need to keep it that way to prevent screen jump since window not placed yet
					style.display="block"; //otherwise client values not accurate
					style.width = (this.oWindowContent.externalContainer.clientWidth + 50);  //table padding 20 left and right + 10 extra visual padding
					style.height = "auto";//(this.oWindowContent.externalContainer.clientHeight + 75); //table padding 20 top and bottom + 25 for window title + 10 extra visual padding
					style.display = sDisplay;
				}
			}
			
			this.refreshFrame();
		}
	} catch (err) {
		throwConsoleError("ckFloatingWindowObj.onresize_content()\nResizing window container.",err);
	}
	
}


ckFloatingWindowObj.prototype._getUniqueID = function () {
     var oDate = new Date();
     var uniqueId = oDate.getMonth() + '' + oDate.getDate() + '' + oDate.getTime() + '';

     return uniqueId;
}
/*------------------------------------------------------------------------------------------
askQuestion
------------------------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.askQuestion = function(sQuestion,aButtons) {
	//create question DIV if not already created
	//display
	//wait for input
	//hide
	//return index of button clicked on
}
/*----------------------------------------------------------------------------
Events (coded for Mozilla compatibility)
----------------------------------------------------------------------------*/
ckFloatingWindowObj.prototype.addEvent = function(oObject, sEventName, fnHandler) {
	if (oObject) {
		if (oObject.addEventListener) oObject.addEventListener(sEventName, fnHandler, false);
		else if (oObject.attachEvent) oObject.attachEvent("on" + sEventName, fnHandler);
	}
}
ckFloatingWindowObj.prototype.removeEvent = function(oObject, sEventName, fnHandler) {
	if (oObject) {
		if (oObject.removeEventListener) oObject.removeEventListener(sEventName, fnHandler, false);
		else if (oObject.detachEvent) oObject.detachEvent("on" + sEventName, fnHandler);
	}
}
ckFloatingWindowObj.prototype.addCloseHandler = function(contentID,fnRef) {
	//Pass in a reference to a custom function that will be called when the X[close] icon is clicked in addition to the standard one that simply closes the window
	//Multiple close handlers per contentID are allowed
	var oWindowContent = this.aExternalContent[contentID]; 
	if ((fnRef) && (oWindowContent)) oWindowContent.addCloseHandler(fnRef);
}
ckFloatingWindowObj.prototype.removeCloseHandler = function(contentID,fnRef) {
	var oWindowContent = this.aExternalContent[contentID];
	if ((fnRef) && (oWindowContent)) oWindowContent.removeCloseHandler(fnRef);
}
/*------------------------------------------------------------------------------------------
floatingWindowContentObj
------------------------------------------------------------------------------------------*/
ckFloatingWindowContentObj = function(contentID,windowTitle,externalContainer,closeHandler) {
	this.contentID = contentID;
	this.windowTitle = windowTitle;
	this.externalContainer = externalContainer;
	this.aCloseHandlers = new Array();
	this.addCloseHandler(closeHandler);

	return this;
}
ckFloatingWindowContentObj.prototype.addCloseHandler = function(fnRef) {
	var bDuplicate;
	if (fnRef) {
		for (var index=0; index < this.aCloseHandlers.length; index++) if (this.aCloseHandlers[index]==fnRef) bDuplicate=true;
		if (!bDuplicate) this.aCloseHandlers[this.aCloseHandlers.length] = fnRef;
	}
}
ckFloatingWindowContentObj.prototype.removeCloseHandler = function(fnRef) {
	if (fnRef) {
		for (var index=0; index < this.aCloseHandlers.length; index++) if (this.aCloseHandlers[index]==fnRef) this.aCloseHandlers[index]=null;
	}
}

/*---------------------------------------------------------------------------------------------------
hideSpecificHTMLTag - Utility required to make the floating window work
---------------------------------------------------------------------------------------------------*/
function hideSpecificHTMLTag(tagName) {
	var bHide = (arguments.length >= 2 ? arguments[1] : true);
	var aExcludeForParentIDs = (arguments.length >= 3 ? arguments[2] : null);
	var bUseDisplay = (arguments.length >=4 ? arguments[3] : false);
	
	var bContinue = true;
	var aTags = document.getElementsByTagName(tagName.toLowerCase());
	for (var index=0; index < aTags.length; index++) {
		oElement = aTags[index];
		
		if (aExcludeForParentIDs) { 
			var bChild = false;
			
			for (var excludeIndex=0; excludeIndex < aExcludeForParentIDs.length && !bChild; excludeIndex++) {
				//alert("checking if " + oElement.id + " is within " + aExcludeForParentIDs[excludeIndex]);
				bChild = oDHTML.isChildOfParentID(oElement,aExcludeForParentIDs[excludeIndex]);
			}
			bContinue = !bChild;
		}

		if (bContinue) {
			//some elements may already be hidden, so we can't do a blanket hide and show on everything
			//by default, use "visibility" instead of "display" so screen elements don't move around unneccessarily
			if (bHide) {
				if (bUseDisplay) {
					oElement.savedAttribute = oElement.style.display;
					oElement.style.display="none";
				} else {
					oElement.savedAttribute = oElement.style.visibility;
					oElement.style.visibility="hidden"
				}
			} else {
				if (oElement.savedAttribute != null) {
					if (bUseDisplay) oElement.style.display=oElement.savedAttribute;
					else oElement.style.visibility=oElement.savedAttribute;
				}
			}
		}
	}
}

