/****************************************************************************************************
* Function: modalAlert                                                                          
* Description: Generate a Modal Alert with Jquery UI
* Type: Public
* Parameters: Options Colection
*                     [ Width
                       ,Height
					   ,Title
					   ,Message
					   ,alertIcon: Icon to Show with the message ("", "alert", "check", "info", for others find .ui-icon- in : jquery-ui.custom.css)
*****************************************************************************************************/
function modalAlert(p_options)
{
	var v_options = {width: 300, height: 'auto', title: "Information Window", message: "", alertIcon: ""};
	$.extend(v_options, p_options);
	
	if (($.browser.msie) && ($.browser.version="6.0"))
		alert(v_options.message);
	else
	{
		if ($("#pnlModal").length == 0)
			$("<div id=\"pnlModal\"><div id=\"pnlModalContent\" style=\"color: #00557B;font-family: Verdana; font-size: 12px;text-align: left;padding:10px;height: auto;\"></div></div>").appendTo("body");

		$("#pnlModalContent").html(getIconHtml(v_options.alertIcon) + v_options.message);
		
		$("#pnlModal").dialog(
								{ autoOpen: false,
								  modal: true,
								  width: v_options.width,
								  height: v_options.height,
								  title: v_options.title,
								  buttons: [
											{
												text: "Ok",
												click: function() { $(this).dialog("close"); }
											}
										]
								 }
								);
								
		$("#pnlModal" ).dialog('open');

	}
	
	//$('.ui-dialog :button').blur();

	return;
}


/****************************************************************************************************
* Function: modalWindow
* Description: Generate a Modal Window to display HTML Content
* Type: Public
* Parameters: Options Colection
*                     [ Width
                       ,Height
					   ,Title
					   ,Message
					   ,alertIcon: Icon to Show with the message ("", "alert", "check", "info", for others find .ui-icon- in : jquery-ui.custom.css)
*****************************************************************************************************/
function modalWindow(p_options)
{

	var v_options = {width: 300, height: 'auto', title: "Information Window", content: "", buttons: [{text: "Ok",click: function() { $(this).dialog("close"); }}] };
	$.extend(v_options, p_options);
	
	if ($("#pnlModal").length == 0)
		$("<div id=\"pnlModal\"><div id=\"pnlModalContent\" style=\"color: #00557B;font-family: Verdana; font-size: 12px;text-align: left;padding:10px;height: auto;\"></div></div>").appendTo("body");

	$("#pnlModalContent").html(v_options.content);
	
	$("#pnlModal").dialog(
							{ autoOpen: false,
							  modal: true,
							  width: v_options.width,
							  height: v_options.height,
							  title: v_options.title
							}
							);


	if (v_options.buttons)
	{
		$("#pnlModal").dialog({	buttons: v_options.buttons});
	}
							
	$("#pnlModal" ).dialog('open');

	
	//$('.ui-dialog :button').blur();
	return;
}

/****************************************************************************************************
* Function: modalConfirm
* Description: Generate a Modal Confirm Window with Jquery UI
* Type: Public
* Parameters: Options Colection
*                     [ Width
                       ,Height
					   ,Title
					   ,Message
					   ,confirmIcon: Icon to Show with the message ("", "alert", "check", "info", for others find .ui-icon- in : jquery-ui.custom.css)
					   ,callBackTrue: Function to execute When Confirmed
					   ,callBackFalse: Function to execute When Canceled
*****************************************************************************************************/

function modalConfirm(p_options)
{
	
	var v_options = {width: 300, height: 'auto', title: "Confirm Window", message: "", confirmIcon: 'alert', callBackTrue: function() {}, callBackFalse: function() {}};

	$.extend(v_options, p_options);
	
	if (($.browser.msie) && ($.browser.version="6.0"))
	{
		var v_res = confirm(v_options.message);
		if (v_res)
		{
			if ($.isFunction(v_options.callBackTrue)) {
				v_options.callBackTrue.apply();
			}
		}
		else
		{
			if ($.isFunction(v_options.callBackFalse)) {
				v_options.callBackFalse.apply();
			}
		}
	}
	else
	{
		
		if ($("#pnlModal").length == 0)
			$("<div id=\"pnlModal\"><div id=\"pnlModalContent\" style=\"color: #00557B;font-family: Verdana; font-size: 12px;text-align: left;padding:10px;\"></div></div>").appendTo("body");

		$("#pnlModalContent").html(getIconHtml(v_options.confirmIcon) + v_options.message);
		
		$("#pnlModal").dialog(
								{ autoOpen: false,
								  modal: true,
								  width: v_options.width,
								  height: v_options.height,
								  title: v_options.title,
								  buttons: {
												"Cancel": function() { $(this).dialog("close"); 
																	if ($.isFunction(v_options.callBackFalse)) {
																		v_options.callBackFalse.apply();
																	}
																  }											,
												"Accept": function() { 
																	if ($.isFunction(v_options.callBackTrue)) {
																		v_options.callBackTrue.apply();
																	}
																  }
											}
								 }
								);		
		$("#pnlModal" ).dialog('open');
    
		return (false);
	}

}

/****************************************************************************************************
* Function: getIconHtml
* Description: Generate a SPAN for the required ICON
* Type: Private
* Parameters: 
*             p_icon_type: icon type
*****************************************************************************************************/

function getIconHtml(p_icon_type)
{
	var v_icon = "";
	
	if (p_icon_type != "")
	{
		if (p_icon_type == "check")
			v_icon += "<span class=\"ui-icon ui-icon-circle-check";
		else
			v_icon += "<span class=\"ui-icon ui-icon-" + p_icon_type;	

		v_icon += "\" style=\"float:left; margin:0 7px 50px 0;\"></span>";
	}

	return v_icon;
}


/****************************************************************************************************
* Function: showNotification
* Description: Show Top Bar Notification
* Type: Public
* Parameters: Options Colection
*                     [ Type: 'warning' , 'information', 'success', 'failure'
					   ,Message: Message to Show in the Notification Window
					   ,delay: Time to Keep the Notification
*****************************************************************************************************/

function showNotification(p_options)
{
	var v_options = {type: 'information', message: '', delay: 2000};
	$.extend(v_options, p_options);
	
	if (($.browser.msie) && ($.browser.version="6.0"))
		alert(v_options.message);
	else
	{
		if ($("#pnlNotifications").length == 0)
				$("<div id=\"pnlNotifications\"></div>").appendTo("body");

		$("#pnlNotifications").html("<div class=\"notification " + v_options.type + "\"><p>" + v_options.message + "</p></div>");            

		$('#pnlNotifications').show('blind', { direction: 'vertical' }, 1500).delay(v_options.delay).hide('blind', { direction: 'vertical' }, 500);
	}
}
