var g_our_dialog;
/* ************************************************************ */
function SLEEPDialogOKCancel( header, url, funcOK)
{

	SLEEP_LoadURL( 'GET', url, function(type, text)
	{
		buttonsArray = [
			{ text:"Cancel", 	handler:_HandleCancel, 	isDefault:false },	
			{ text:"OK", handler:funcOK, isDefault:true },	
		];
	
		return _SLEEPDialog( header, text, buttonsArray);
	});
}
/* ************************************************************ */
function SLEEPDialogOK( header, url, funcOK)
{
	SLEEP_LoadURL( 'GET', url, function(type, text)
	{
		buttonsArray = [
			{ text:"OK", handler:funcOK, isDefault:true },	
		];
	
	return _SLEEPDialog( header, text, buttonsArray);
	});
}
/* ************************************************************ */
function SLEEPBigDlg(  icon, funcOK)
{
	var url = 'custom/dialogs/D_About.php';

	SLEEP_LoadURL( 'GET', url, function(type, text)
	{
		header = "SLEEP Alert"
		buttonsArray = [
			{ text:"OK", 		handler:funcOK, 	isDefault:true },	
		];
	
		return _SLEEPAlert( 450, icon, header, text, buttonsArray );
	});
}
/* ************************************************************ */
function SLEEPAlertOK(  icon, body, funcOK)
{
	header = "SLEEP Alert"
	buttonsArray = [
		{ text:"OK", 		handler:funcOK, 	isDefault:true },	
	];

	return _SLEEPAlert( 450, icon, header, body, buttonsArray );
}
/* ************************************************************ */
function SLEEPAlertOKCancel(  icon, body, funcOK)
{
	header = "SLEEP Alert"
	buttonsArray = [
		{ text:"Cancel", 	handler:_HandleCancel, 	isDefault:false },	
		{ text:"OK", 		handler:funcOK, 	isDefault:true },	
	];

	return _SLEEPAlert( 450, icon, header, body, buttonsArray );
}
/* ************************************************************ */
function SLEEPAlertSaveCancel(  icon, body, funcSave)
{
	header = "SLEEP Alert"
	buttonsArray = [
		{ text:"Cancel", 	handler:_HandleCancel, 	isDefault:false },	
		{ text:"Save", 		handler:funcSave, 	isDefault:true },	
	];

	return _SLEEPAlert( 450, icon, header, body, buttonsArray );
}
/* ************************************************************ */
function SLEEPAlertYesNo(  icon, body, funcYes)
{
	header = "SLEEP Alert"
	buttonsArray = [
		{ text:"No", 	handler:_HandleCancel, 	isDefault:false },	
		{ text:"Yes", 	handler:funcYes, 	isDefault:true },	
	];

	return _SLEEPAlert( 450, icon, header, body, buttonsArray );
}
/* ************************************************************ */
function _SLEEPAlert( width, icon, header, body, buttonsArray)
{
	var ourWidth = width +'px';
	var ourBodyText = body;
	var ourHeader = header;
	var ourIcon = icon;
	var ourButtons = buttonsArray;
	
	ourSLEEPDialog = 
	new YAHOO.widget.SimpleDialog("sleep_dialog_position", 
							 { 			
							 	width: 	ourWidth,			   
							  fixedcenter: true,
							   visible: false,
							   draggable: true,
							  constraintoviewport : true,
							   close: false,
							   modal: true,
							   text: ourBodyText,
							   icon: ourIcon,
							   constraintoviewport: true,
							   buttons: ourButtons
							 } );
	ourSLEEPDialog.setHeader( ourHeader);

	// Render the Dialog
	ourSLEEPDialog.render('sleep_dialog');
	ourSLEEPDialog.show();

	// We have to use a global since we
	// are called from an async callback	
	g_our_dialog = 	ourSLEEPDialog;
		
return ourSLEEPDialog;
}
/* ************************************************************ */
function _SLEEPDialog( header, body, buttonsArray)
{
	var ourBodyText = body;
	var ourHeader = header;
	var ourButtons = buttonsArray;
	
	ourSLEEPDialog = 
	new YAHOO.widget.SimpleDialog("sleep_dialog_position", 
							 { 			
							  fixedcenter: true,
							   visible: false,
							   draggable: true,
							  constraintoviewport : true,
							   close: false,
							   modal: true,
							   text: ourBodyText,
							   constraintoviewport: true,
							   buttons: ourButtons
							 } );
	ourSLEEPDialog.setHeader( ourHeader);

	// Render the Dialog
	ourSLEEPDialog.render('sleep_dialog');
	SLEEP_RunScriptsFromHTML( body);
	ourSLEEPDialog.show();
		
	// We have to use a global since we
	// are called from an async callback	
	g_our_dialog = 	ourSLEEPDialog;
	
return ourSLEEPDialog;
}
/* ************************************************************ */
function _HandleCancel()
{
	CloseModelDialog( this);
}
/* ************************************************************ */
function CloseModelDialog( )
{
	g_our_dialog.hide();
	g_our_dialog.destroy();
}
/* ************************************************************ */
/*
    SimpleDialog.ICON_BLOCK = "blckicon";
    SimpleDialog.ICON_ALARM = "alrticon";
    SimpleDialog.ICON_HELP  = "hlpicon";
    SimpleDialog.ICON_INFO  = "infoicon";
    SimpleDialog.ICON_WARN  = "warnicon";
    SimpleDialog.ICON_TIP   = "tipicon";
*/
/* ************************************************************ */
