//======CONSTRUCTOR=======================
function popBox(locationId, openStatus) //status is T/F for opened/closed
{
	this.locationObj = document.getElementById(locationId);
	this.locationId = locationId;

	this.openStatus = openStatus;

	//Control Objs/Ids
	this.popOutObj = null;
	this.popOutId = null;
	this.popOutEvent = null;

	this.popInObj = null;
	this.popInId = null;
	this.popInEvent = null;

	this.reset = true;   //resetOnClose
	this.originalHTML = null;

	this.saveOriginalHTML();
	this.contentInitFunction = null;

	//this.setPopBoxParameters = createMethodReference(this, this.setPopBoxParameters);
	createMethodReference(this, this.restoreOriginalHTML);
}
//========================================



popBox.prototype.setPopBoxParameters = function(popOutId, popOutEvent, popInId, popInEvent)
{
	//document.write(this.locationId);
	this.popOutId = popOutId;
	this.popOutEvent = popOutEvent;
	this.popInId = popInId;
	this.popInEvent = popInEvent;
}
//========================================
popBox.prototype.setPopBoxLocationObj = function(locationObj)
{
	this.locationObj = locationObj;
	var id = this.locationId = locationObj.id;


	this.saveOriginalHTML();

}
popBox.prototype.setPopBoxLocationFromId = function(locationId)
{
	this.locationId = locationId;
	this.locationObj = document.getElementById(locationId);

	this.saveOriginalHTML();
}
//========================================
popBox.prototype.setPopOutObj = function(obj)
{
	this.popOutObj = obj;
	if(this.popOutObj.id)
		this.popOutId = this.popOutObj.id;
	else
		this.popOutId = null;
}
popBox.prototype.setPopOutFromId = function(id)
{
	this.popOutId = id;
	this.popOutObj = document.getElementById(id);
}
popBox.prototype.setPopOutEvent = function(eventName)
{
	this.popOutEvent = eventName;
}
//========================================
popBox.prototype.setPopInObj = function(obj)
{
	this.popInObj = obj;
	this.popInId = this.popInObj.id;
}
popBox.prototype.setPopInFromId = function(id)
{
	this.popInId = id;
	this.popInObj = document.getElementById(id);
}
popBox.prototype.setPopInEvent = function(eventName)
{
	this.popInEvent = eventName;
}
//========================================
popBox.prototype.setOpenStatus = function(openStatus)
{
	this.openStatus = openStatus;
}
//========================================




popBox.prototype.resetOnClose = function(reset)  // T/F  TRUE by default
{
	this.reset = reset;
}

popBox.prototype.saveOriginalHTML = function()
{
	this.originalHTML = document.getElementById(this.locationId).innerHTML;
}

popBox.prototype.restoreOriginalHTML = function()
{
	//document.write(this.originalHTML);
	//document.write(this.locationId);

	if(this.reset)
		document.getElementById(this.locationId).innerHTML = this.originalHTML;
	this.init();
	this.contentInitFunction();
}

popBox.prototype.setContentInitFunction = function(initFcn)  // T/F  TRUE by default
{
	this.contentInitFunction = initFcn;
}
//========================================





popBox.prototype.init = function()
{

	if(!this.popOutId)
	{
		this.popOutId = this.locationId + "OpenCtrl";
		this.popOutObj = document.getElementById(this.popOutId);
	}
	if(!this.popInId)
	{
		this.popInId = this.locationId + "CloseCtrl";
		this.popInObj = document.getElementById(this.popInId);
	}
	if(!this.popOutEvent)
		this.popOutEvent = 'click';
	if(!this.popInEvent)
		this.popInEvent = 'click';

	//document.write(this.popInId + ' - ' + this.popInEvent);

	//xAddEventListener(document.getElementById(this.popOutId),   this.popOutEvent, createEventListenerMethodReference(this, this.popOut), false);
	//xAddEventListener(document.getElementById(this.popInId),   this.popInEvent, createEventListenerMethodReference(this, this.popIn), false);

}

popBox.prototype.initListeners = function()
{
	xAddEventListener(this.popOutObj,   this.popOutEvent, createEventListenerMethodReference(this, this.popOut), false);
	xAddEventListener(this.popInObj,   this.popInEvent, createEventListenerMethodReference(this, this.popIn), false);
}
//========================================



popBox.prototype.popOut = function()
{
	document.getElementById(this.locationId + 'Background').style.display = 'block';
	var docHeight = xHeight('content')+120+60;  //height of top PLUS footer
	//var docHeight = xHeight(document)   //WHY DOESN'T THIS WORK????
	document.getElementById(this.locationId + 'Background').style.height = docHeight + 'px';

	this.locationObj.style.display = 'block';

	openStatus = true;
}

popBox.prototype.popIn = function()
{
	document.getElementById(this.locationId + 'Background').style.display = 'none';
	this.locationObj.style.display = 'none';
	openStatus = false;

	if(this.reset)
		this.restoreOriginalHTML();
}






/*
function greetingButton(locationId, controlId)
{
	this.greeting = greeting;   //this was the parameter
	this.element = document.createElement("button");
	this.element.appendChild(document.createTextNode("Receive Greeting"));
	this.element.onclick = createMethodReference(this, this.greet);
}

greetingButton.prototype.greet = function()
{
	alert(this.greeting);
};
*/
