
	/* **********************************************************
	*
	*	div_popup
	*
	************************************************************/

popup_count = 0;

function div_popup(){

	//this.width = 300;
	//this.height = 200;
	this.title = "";
	this.identifier = "";
	this.count = popup_count++;
	this.zIndex = ++zIndex;
	
	if(IE_sux()){
		this.width = document.body.offsetWidth/2;
		this.height = document.body.offsetHeight/2;
	}else{
		this.width = window.innerWidth/2;
		this.height = window.innerHeight/2;
	}
}

/*********************************************
*
*	make_window
*
*********************************************/

div_popup.prototype.make_window = function(){
	this.zIndex = ++zIndex;

	if(!this.popup_window){
		this.make_popup_window();
		this.make_title_bar();
		this.make_content_area();
	}
}

/*********************************************
*
*	open_window
*
*********************************************/

div_popup.prototype.open_window = function(){
	if(this.popup_window){
		this.display_popup();
	}
}

/*********************************************
*
*	make_popup_window
*
*********************************************/

div_popup.prototype.make_popup_window = function(){

	this.popup_window = document.createElement("<div>");
	this.popup_window.setAttribute("id", "popup_window_" + this.count);
	
	if(IE_sux()){
		var position = "absolute";
		var left_pos = (document.body.offsetWidth - this.width)/2 + document.body.scrollLeft;
		var top_pos = (document.body.offsetHeight - this.height)/2 + document.body.scrollTop;
	}else{
		var position = "fixed";
		var left_pos = (window.innerWidth - this.width)/2;
		var top_pos = (window.innerHeight - this.height)/2;
	}
	
	//alert_test(this.zIndex);
	var cssText = "" + 
		"left: " + left_pos + "px; " + 
		"top: " + top_pos + "px; " + 
		"border: 1px solid #000000; " + 
		"background-color: #FFFFFF; " +
		"color: #000000; " + 
		"width: " + this.width + "px; " + 
		"text-align: left;";
	this.popup_window.style.cssText = cssText;
	
	this.popup_window.style.zIndex = this.zIndex;
	this.popup_window.style.position = position;

}

/*********************************************
*
*	set_width
*
*********************************************/

div_popup.prototype.set_width = function(width){	
	
	if(IE_sux()){
		var max_width = document.body.offsetWidth * .9;
	}else{
		var max_width = window.innerWidth * .9;
	}
	
	if(width > max_width){
		this.width = max_width;
	}else{
		this.width = width;
	}

	if(this.popup_window){
		this.popup_window.style.width = this.width + "px";
	}
	//alert_test(this.width);
}

/*********************************************
*
*	set_height
*
*********************************************/

div_popup.prototype.set_height = function(height){
	
	if(IE_sux()){
		var max_height = document.body.offsetHeight * .9;
	}else{
		var max_height = window.innerHeight * .9;
	}

	if(height > max_height){
		this.height = max_height;
	}else{
		this.height = height;
	}

	if(this.content_area){
		this.content_area.style.height = this.height + "px";
	}
	//alert_test(this.height);
}

/*********************************************
*
*	set_title
*
*********************************************/

div_popup.prototype.set_title = function(title){
	this.title = title;
	
	if(this.title_name){
		this.title_name.innerHTML = "";
		var text = document.createTextNode(this.title);
		this.title_name.appendChild(text);
	}
}

/*********************************************
*
*	make_title_bar
*
*********************************************/

var z_index = 10000;


div_popup.prototype.make_title_bar = function(){

	/*******************************************
	*
	*	title bar - "this.title_bar"
	*
	*******************************************/

	this.title_bar = document.createElement("<div>");
	var cssText = "" + 
		"background-color: #FF0000; " +
		"cursor: move; " + 
		"padding: 2px; " + 
		"text-align: right; " +
		"font-weight: bold; " + 
		"color: #FFFFFF; ";
	this.title_bar.style.cssText = cssText;
	
	if(IE_sux()){
		eval("this.title_bar.onmousedown = function(){Move_IE(this)}");
	}else{
		this.title_bar.addEventListener("mousedown", function(e){Move_MOZ(this, e)}, true);
	}
	
	this.popup_window.appendChild(this.title_bar);
	
	/*******************************************
	*
	*	title - "this.title_name"
	*
	*******************************************/

	this.title_name = document.createElement("<span>");
	cssText = "float: left;";
	this.title_name.style.cssText = cssText;
	text = document.createTextNode(this.title);
	this.title_name.appendChild(text);
	this.title_bar.appendChild(this.title_name);
	
	/*******************************************
	*
	*	close button - "this.close_button"
	*
	*******************************************/
	
	this.close_button = document.createElement("<input>");
	cssText = "" + 
		"background-color: #FF0000; " +
		"cursor: pointer; " + 
		"padding: 0px; " + 
		"margin: 0px; " +
		"font-weight: normal; " + 
		"border: 1px solid #FFFFFF;" +
		"color: #FFFFFF; ";
	this.close_button.style.cssText = cssText;
	this.close_button.setAttribute("type", "button");
	this.close_button.setAttribute("value", "X");
	this.close_button.setAttribute("title", "Close window");
	this.title_bar.appendChild(this.close_button);
	eval("this.close_button.onclick = function(){" + this.identifier + "close_window();}");
}

/*********************************************
*
*	make_content_area
*
*********************************************/

div_popup.prototype.make_content_area = function(){
	this.content_area = document.createElement("<div>");
	var cssText = "" + 
		"background-color: #FFFFFF; " +
		"overflow: auto; " + 
		"padding: 4px; " + 
		"border-top: 1px solid #000000; " + 
		"height: " + this.height + "px; ";
	this.content_area.style.cssText = cssText;
	this.popup_window.appendChild(this.content_area);
	eval("this.content_area.onclick = function(){" + this.identifier + "popup_window.style.zIndex = zIndex++;}");
}

/*********************************************
*
*	set_content
*
*********************************************/

div_popup.prototype.set_content = function(nodes){
	this.content_area.innerHTML = "";
	this.content_area.appendChild(nodes);
}

/*********************************************
*
*	close_window
*
*********************************************/

div_popup.prototype.close_window = function(){
	var tgt = document.body;
	tgt.removeChild(this.popup_window);
	this.bgnd.parentNode.removeChild(this.bgnd);
	delete this.popup_window;
}

/*********************************************
*
*	hide_window
*
*********************************************/

div_popup.prototype.hide_window = function(){
	this.popup_window.style.display = "none";
}

/*********************************************
*
*	display_popup
*
*********************************************/

div_popup.prototype.display_popup = function(){
	var tgt_div = document.body;

	this.bgnd = document.createElement("div");
	this.bgnd.setAttribute("class", "background_cover");
	this.bgnd.setAttribute("className", "background_cover");
	this.bgnd.style.zIndex = this.zIndex;
	tgt_div.appendChild(this.bgnd);
	
	tgt_div.appendChild(this.popup_window);
}