// 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) {
	$('#fx-alert-div').remove();
	jQuery("<div />", { id:"fx-alert-div", html: message.replace(/\n/, "<br />"), "title": title }).dialog({
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback('Ok');
			}
		}	
		});
}

function thConfirm(message, title, callback) {
	$('#fx-confirm-div').remove();
	jQuery("<div />", { id:"fx-confirm-div", html: message.replace(/\n/, "<br />"), "title": title }).dialog({
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback(true);
			},
			"Cancel": function() { 
				$(this).dialog("close");
				if (callback) callback(false);
			}
		}	
	});
}

function thPrompt(message, value, title, callback ) {
	$('#fx-prompt-div').remove();
	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({
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback(true, $('#fx-prompt-div-input').val());
			},
			"Cancel": function() { 
				$(this).dialog("close");
				if (callback) callback(false, $('#fx-prompt-div-input').val());
			}
		}	
	});
	$('#fx-prompt-div-input').val(value);
	

}

function thDialog(code, title, callback) {
	$('#fx-dialog-div').remove();
	var htmlcode = code;
	jQuery("<div />", { id:"fx-dialog-div", html: htmlcode, "title": title }).dialog({
		buttons: {
			"Ok": function() { 
				$(this).dialog("close");
				if (callback) callback(true, $('#fx-dialog-div'));
			},
			"Cancel": function() { 
				$(this).dialog("close");
				if (callback) callback(false, $('#fx-dialog-div'));
			}
		}	
	});
}