// jQuery UI Alert functions
//
// Version 0.1
//
// Tomas Hnilica
// http://tomas.webstep.net
// 14/3/2010
//
//
// Usage:
//		thAlert( message, [title, callback] )
//		thConfirm( message, [title, callback] )
//		thPrompt( message, [value, title, callback] )
//		thDialog( code, [title, callback])
// 
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2010 Tomas Hnilica 
//



function thAlert(message, title, callback, options) {
	$('#fx-alert-div').remove();
	var params = {
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback('Ok');
			}
		},
		height: "auto",
		width: "auto",
		maxWidth: 900,
		maxHeight: 700,
		minWidth: 300,
		minHeight: 150
	}
	jQuery.extend(params, options);
	jQuery("<div />", { id:"fx-alert-div", html: message.replace(/\n/, "<br />"), "title": title }).dialog(params);
}

function thConfirm(message, title, callback, options) {
	$('#fx-confirm-div').remove();

	var params = {
			buttons: {
				"Ok": function() { 
					$(this).dialog("close");
					if (callback) callback(true);
				},
				"Zrušit": function() { 
					$(this).dialog("close");
					if (callback) callback(false);
				}
			}	
		}
	if (options) jQuery.extend(params, options);	
	jQuery("<div />", { id:"fx-confirm-div", html: message.replace(/\n/, "<br />"), "title": title }).dialog(params);
}

function thPrompt(message, value, title, callback, options ) {
	$('#fx-prompt-div').remove();
	var params = {
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback(true, $('#fx-prompt-div-input').val());
			},
			"Zrušit": function() { 
				$(this).dialog("close");
				if (callback) callback(false, $('#fx-prompt-div-input').val());
			}
		}	
	}
	if (options) jQuery.extend(params, options);	

	var htmlcode = message.replace(/\n/, "<br />") + "<br><input type='text' id='fx-prompt-div-input' size='40'>";
	jQuery("<div />", { id:"fx-prompt-div", html: htmlcode, "title": title }).dialog(params);
	$('#fx-prompt-div-input').val(value);
	

}

function thDialog(code, title, callback, options) {
	$('#fx-dialog-div').remove();
	var htmlcode = code;
	var params = {
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback(true, $('#fx-dialog-div'));
			},
			"Zrušit": function() { 
				$(this).dialog("close");
				if (callback) callback(false, $('#fx-dialog-div'));
			}
		},
		height: "auto",
		width: "auto",
		maxWidth: 900,
		maxHeight: 700,
		minWidth: 300,
		minHeight: 150
	}
	if (options) jQuery.extend(params, options);	
	dlg = jQuery("<div />", { id:"fx-dialog-div", html: htmlcode, "title": title }).dialog(params);
	return dlg;
}
