﻿// JScript File

function JCMenuDialogBG()
{
	this.showUI	= JCMenuDialogBG_showUI;

	this.onselectstart = DisableSelection;

	this.spacerWidth = this.mSpacerWidth ? parseInt(this.mSpacerWidth ) : 6;

	this.mMenuWidth = this.mMenuWidth ? parseInt( this.mMenuWidth ) + this.spacerWidth : 140;
	
	this.content = this.children.length > 0 ? this.children[this.children.length-1] : null;
	this.menuPanel = this.menu = this.children.length > 1 ? this.children[0] : null;
	
	this.getBackgroundHTML = JCMenuDialogBG_getBackgroundHTML;
	this.updateUI = JCMenuDialogBG_updateUI;
	
	this.setHelpButton = function( sTitle, sOnClick )
	{
		this.setMenuHTML();// make sure the menu is created
		var newMenuPanel = document.createElement("SPAN");
		newMenuPanel.mClass = "JCBodyFooterLayout";
		newMenuPanel.style.height = this.menuPanel.style.height;
		//newMenuPanel.style.border = "dotted 1px blue";
		newMenuPanel.style.verticalAlign = "top";
		
		//this.menuPanel.style.height = "";
		this.menuPanel.applyElement( newMenuPanel );
		this.menuPanel = newMenuPanel;

		this.helpButton = document.createElement("DIV");
		this.helpButton.style.textAlign = "right";
		this.helpButton.style.padding = "4px";
		//this.helpButton.style.border = "dotted 1px red";
		
		this.helpButton.style.paddingRight = this.spacerWidth;
		this.menuPanel.insertAdjacentElement("beforeEnd", this.helpButton);
		this.helpButton.innerHTML = "<span mClass=JCButton onclick=\"" + sOnClick + "\">" + sTitle + "</span>";
		//this.arrangeLayout();

		InitDocObjects(this.menuPanel);
		//UseBaseClass( this.menuPanel, JCBodyFooterLayout );
		//this.menuPanel.onAddToDocument();
	}
	
	this.setMenuHTML = function(sHTML)
	{
		if(!this.menu)
		{
			this.menuPanel = this.menu = document.createElement("SPAN");
			
			this.menu.id = "idMenuPanel";
			this.content.insertAdjacentElement("beforeBegin",this.menu);
			this.updateUI();
		}
		
		if(sHTML){
			this.menu.innerHTML = sHTML;
			this.processInnerClasses();
			this.arrangeLayout();
		}
	};
	
	this.arrangeLayout = function(){

		var BackgroundElement = document.getElementById("idMispDlgBackground" + this.id );
		var width  = this.clientWidth;
		var height = this.offsetHeight;
		var menuWidth = this.menu ? this.mMenuWidth : 0;

		if( BackgroundElement ){
			BackgroundElement.style.width = width;
			BackgroundElement.style.height = height;
		}

		if(this.content){
			this.content.style.width = ( 100 * ( width - menuWidth - 1 - 2) / width ).toString() + "%";
			this.content.style.height = "100%";
		}
		
		if(this.menu){
			this.menu.style.width = menuWidth;
			this.menu.style.paddingRight = this.spacerWidth;
			this.menuPanel.style.height = this.content.style.height;
		}		
	}
}

function JCMenuDialogBG_getBackgroundHTML()
{
	var menuWidth = this.menu ? this.mMenuWidth - this.spacerWidth - 2 : 0;
	
	var sBackground = "" +
	"<table style='background-repeat:repeat-x;width:100%;height:100%' cellpadding=0 cellspacing=0 border=0>" +
	"<tr>" + 
		"<td style='width:2px;height:2px;'><img width=2 height=2 src='" + gImageBase + "dlg_tl_br_corner.gif'></td>" + 
		( menuWidth ? "<td style='height:2px;background:white;background-image:url(" + gImageBase + "dlg_t_side.gif);background-repeat:repeat-x'></td>" + 
					  "<td style='width:9px;height:2px'><img width=9 height=2 src='" + gImageBase + "dlg_splitter_top.gif'></td>" : "" ) +  
		"<td width=100% style='height:2px;background-image:url(" + gImageBase + "dlg_t_side.gif);background-repeat:repeat-x'></td>" + 
		"<td style='width:2px;height:2px;'><img width=2 height=2 src='" + gImageBase + "dlg_bl_tr_corner.gif'></td>" +
	"</tr>" +
	"<tr>" + 
		"<td style='width:2px;height:100%;" + (menuWidth ? "background:white;" : "" ) + "background-image:url(" + gImageBase + "dlg_l_side.gif);background-repeat:repeat-y'></td>" + 
		( menuWidth ? "<td style='height:100%;background:white'><span style='width:" + ( menuWidth ).toString() + "px'></span></td>" +
					  "<td style='width:9px;height:100%;background-image:url(" + gImageBase + "dlg_splitter.gif);background-repeat:repeat-y'></td>" : "" ) + 
		"<td width=100% style='height:100%;'></td>" +
		"<td style='width:2px;height:100%;background-image:url(" + gImageBase + "dlg_r_side.gif);background-repeat:repeat-y'></td>" +
	"</tr>" +
	"<tr>" + 
		"<td style='width:2px;height:2px'><img width=2 height=2 src='" + gImageBase + "dlg_bl_tr_corner.gif'></td>" + 
		( menuWidth ? "<td style='height:2px;background:white;background-image:url(" + gImageBase + "dlg_b_side.gif);background-repeat:repeat-x'></td>" +
					  "<td style='width:9px;height:2px'><img width=9 height=2 src='" + gImageBase + "dlg_splitter_bottom.gif'></td>" : "" ) + 
		"<td width=100% style='height:2px;background-image:url(" + gImageBase + "dlg_b_side.gif);background-repeat:repeat-x'></td>" +
		"<td style='width:2px;height:2px'><img width=2 height=2 src='" + gImageBase + "dlg_tl_br_corner.gif'></td>" +
	"</tr>" +
	"</table>";	
	
	return sBackground;
}

function JCMenuDialogBG_updateUI()
{
	var BackgroundElement = document.getElementById("idMispDlgBackground" + this.id );
	BackgroundElement.innerHTML = this.getBackgroundHTML();
}

function JCMenuDialogBG_showUI()
{
	var menuWidth = this.menu ? this.mMenuWidth : 0;
	
	var sBackground = "<div id=idMispDlgBackground" + this.id + " class='misp_app_body_bg'>" + this.getBackgroundHTML() + "</div>";

	this.className  = "misp_dlg_body";
	this.insertAdjacentHTML( "afterBegin", sBackground );
	this.onresize = new Function( this.sID + ".arrangeLayout()" );
	this.arrangeLayout();
}
