
/* MODIFIED FOR NGRID TO SUPPORT THE CALL FROM THE WEB PAGE WITH ONE MORE PARAM (param=RegionName)
 * NEW PROTOCOL! WOULD BE INTERESTING TO INCLUDE TO THE STORMCENTER PRODUCT BY DEFAULT
 */
IFactorPanelsHandler.prototype.showPanel = function(idPanel,idListener,param)
{
	
	var panelDef = this.panelDefinition[idPanel];
	
	if (panelDef == null)
	{
		// The panel definition is not included in the panel configuration,
		// then the panel is just ignored
		alert("Panel not defined!");
		return;
	} 

	var first_time = false;
	var panelObject = this.overlayManager.find(idPanel);

	// Panel creation only the first time	
	if (panelObject == null)
	{
		// The panel has not been add to the overlayManager

		// Creation of the YUI panel properties object from the panel definition
		var yuiPanelProperties = new Object();
		var prop;
		for (prop in panelDef)
		{
			var val = panelDef[prop];
			
			if (prop == "panel_name" || prop == "header" || prop == "footer" ||
			    prop == "body" || prop == "panel_reload_event")
			{
				// Ignore this properties, not YUI Panel properties
				continue;
			}
			else if (prop == "x" || prop == "y")
			{
				if (this.valueIsTypeOf(val,"String"))
					val = this[val](panelDef);  // Call the function
				//else if (!this.valueIsTypeOf(val,"Number"))
				//	val = null;
			}
			else if (prop == "xy")
			{
				if (this.valueIsTypeOf(val,"String"))
					val = this[val](panelDef);  // Call the function
				//else if (!this.valueIsTypeOf(val,"Array") || val.length != 2)
				//	val = null;
			}
			
			if (val != null)
				yuiPanelProperties[prop] = val;
		}
		this.setDefaultValues(yuiPanelProperties);
		
		
		// Creation of the YUI panel
		panelObject = new YAHOO.widget.Panel(idPanel,yuiPanelProperties);
        panelObject.hideEvent.subscribe(function() {   
					window.document.getElementById(idPanel).style.display = "none";  
				});   // Needed to hide residual lines over the map when the panel is closed and the panel contained a YUI DataTable
		panelObject.render();
		
		// Register the panel in the overlay manager
		this.overlayManager.register([panelObject]);
		
		// Identify that it is the first time the panel is opened
		first_time = true;
		
	}
	
	
	// Set Listeners if proceed
	if (idListener != null)
	{
		// Add the listener. Only the firts time and if it is given to this function showPanel()
		if (YAHOO.util.Event.addListener(idListener,"click") == false)
			YAHOO.util.Event.addListener(idListener, "click", panelObject.show, panelObject, true);
	}
	
	
	// Set the header, body and footer of the panel if it is the first time the panel is opened or
	// it is not the first time and the panel must be reloaded every time the panel is opene or reopened
	var only_first_time = this.findOutIfOnlyFirstTime(panelDef);
	
	if (!only_first_time || only_first_time && first_time)
	{
		// The panel must be reloaded
		
		// Header
		var headerContent = this.getPanelElementContent(panelDef,"header",param);
		if (headerContent != null)
			panelObject.setHeader(headerContent);
			
		// Body
		var bodyContent = this.getPanelElementContent(panelDef,"body",param);
		if (bodyContent != null)
			panelObject.setBody(bodyContent);
			
		// Footer
		var footerContent = this.getPanelElementContent(panelDef,"footer",param);
		if (footerContent != null)
			panelObject.setFooter(footerContent);
 	}
	

	// Make the panel visible and set the focus to it	
	window.document.getElementById(idPanel).style.display = "block";
  	this.overlayManager.bringToTop(idPanel);
	if (first_time || idListener == null)
		panelObject.show();
	this.overlayManager.focus(idPanel);

} 

/* MODIFIED FOR NGRID TO SUPPORT THE CALL FROM THE WEB PAGE WITH ONE MORE PARAM (param=RegionName) 
 * NEW PROTOCOL! WOULD BE INTERESTING TO INCLUDE TO THE STORMCENTER PRODUCT BY DEFAULT
 */
IFactorPanelsHandler.prototype.getPanelElementContent = function(panelDef,panelElementName,param)
{
	res = null;
	panelElementDef = panelDef[panelElementName];
	
	if (panelElementDef == null)
		return null;
	
	if (panelElementDef.type == "text")
		res = panelElementDef.properties.text;
	else if (panelElementDef.type == "custom")
		res = this[panelElementDef.properties.custom_method](panelDef,param);
	else if (panelElementDef.type == "iframe")
	{
		str = "<iframe";
		
		var prop;
		for (prop in panelElementDef.properties)
		{
			val = panelElementDef.properties[prop];
			
			if (val != null)
				str = str + " " + prop + "=\"" + val + "\"";
		}
		
		str = str + "></iframe>";
		
		res = str;
	}
		
	return res;
}

/* MODIFIED FOR NGRID TO SUPPORT THE CALL FROM THE WEB PAGE WITH ONE MORE PARAM (region=RegionName) 
 * NEW PROTOCOL! WOULD BE INTERESTING TO INCLUDE TO THE STORMCENTER PRODUCT BY DEFAULT
 */
IFactorPanelsHandler.prototype.createCustomerChart = function(panelDef,param)
{
	var w, h;
	
	var pw = this.getPixelsAsNumber(panelDef.width);
	if (pw == null)
		w = 550;
	else
		w = pw - 20;
		
	var ph = this.getPixelsAsNumber(panelDef.height);
	if (ph == null)
		h = 570;
	else
		h = ph - 30;
	
	var dataFile;
	if (param === undefined) // Not passed parameter region
		dataFile = this.stormCenter.getFullPathCustomerChartFile();
	else
		dataFile = this.stormCenter.getFullPathCustomerChartFile(param);
	
	var bodyStr = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + w + "px' height='" + h + "px' id='customerfusionchart'>";
	bodyStr = bodyStr + "<param name='movie' value='flashcharts/FC_2_3_MSColumnLine_DY_2D.swf'/>";
	bodyStr = bodyStr + "<param name='FlashVars' value='&dataURL=" + dataFile + "&chartWidth=" + w + "&chartHeight=" + h + "'/>";
	bodyStr = bodyStr + "<param name='quality' value='high'/>";
	bodyStr = bodyStr + "<param name='bgcolor' value='#FFFFFF'/>";
	bodyStr = bodyStr + "<embed src='flashcharts/FC_2_3_MSColumnLine_DY_2D.swf' flashvars='&dataURL=" + dataFile + "' quality='high' bgcolor='#FFFFFF' width='" + w + "px' height='" + h + "px' name='customerfusionchart' type='application/x-shockwave-flash' pluginspace='http://www.macromedia.com/go/getflashplayer'></embed>";
	bodyStr = bodyStr + "</object>";
	
	return bodyStr;
}

IFactorPanelsHandler.prototype.headerCustomerChart = function(panelDef,param)
{
	var sufix = "";
	if (param != null && param != "")
		sufix = " (" + param.toUpperCase() +")";
		
	return "Outage History Chart" + sufix;
}