// parent: template.tpl.
// requires: jquery-1.x.x.min.js, jquery.form.js, jquery.tools.js.
//-------------------------------------------------------------------------------------
// global variables
//-------------------------------------------------------------------------------------
var $dialog = $('<div></div>');
//-------------------------------------------------------------------------------------
// on document ready methods.
//-------------------------------------------------------------------------------------
$(document).ready(function () {
	// add a styler class to the global dialog object.
	$dialog.addClass("dialog");
});
//-------------------------------------------------------------------------------------
// callable functions.
//-------------------------------------------------------------------------------------
$.strPad = function(i,l,s) {
	// pads a string with a specified character.
	var o = i.toString();
	if (!s) { s = '0'; }
	while (o.length < l) {
		o = s + o;
	}
	return o;
};
//-------------------------------------------------------------------------------------
function uiAlert(title, message, args)
{
	// replace \n's with <br />.
	message = message.replace(/\n/g,'<br />');
	
	// prepare the arguments.
	if (args) {
		// if args exists, set initial options.
		args.title = title;
		if (!args.buttons) args.buttons = {"Aceptar" : function() { $( this ).dialog("close"); } };
	} else {
		// args does not exist. create a new one.
		args = {"title":title, buttons: {"Aceptar" : function() { $( this ).dialog("close"); } } };
	}
	
	// set common options.
	args.modal = true;
	
	// destroy and show the dialog.
	$dialog.dialog("destroy");
	$dialog.html(message).dialog(args);
}
//-------------------------------------------------------------------------------------
function uiConfirm(title, message, callbackOnConfirm, args)
{
	// replace \n's with <br />.
	message = message.replace(/\n/g,'<br />');
	
	if (args) {
		// if args exists, set initial options.
		args.title = title;
		if (!args.buttons) args.buttons = {"Aceptar" : callbackOnConfirm, "Cancelar" : function() { $( this ).dialog("close"); } };
		if (!args.open) args.open = function() { $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus(); }; 
	} else {
		// args does not exist. create a new one.
		args = {
			"title":title
			,buttons: {"Aceptar" : callbackOnConfirm, "Cancelar" : function() { $( this ).dialog("close"); } }
			,open: function() { $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus(); }			
		};
	}
	
	// set common options.
	args.modal = true;
	
	// destroy and show the dialog.
	$dialog.dialog("destroy");
	$dialog.html(message).dialog(args);	
}
//-------------------------------------------------------------------------------------
function uiNotify(title, message, args)
{
	// replace \n's with <br />.
	message = message.replace(/\n/g,'<br />');
	
	// instantiante notification.
	$notify = $("#notify-container")	
	$notify.notify();	
	$notify.notify("create", "notify-default", {"title": title, text: message}, args);
}


