/**
 * [Copyright]
 * 
 * Copyright (c) 2009, WebAlive Pty. Ltd.
 */

/**
 * Global helper functions
 */
var WC = {
	/**
	 * Popup a jQuery UI modal confirmation box. callback is fired
	 * if user confirms.
	 * 
	 * @param string msg the message which should be displayed to the user
	 * @param function callback [optional] a function which will be fired upon 
	 * 		  confirmation
	 */
	confirm: function(msg, callback) {
		var randomId = 'dialog'+Math.floor(Math.random()*1001);
		$('body').append('<p title="Confirm" id="'+randomId+'"><span style="margin: 0pt 7px 20px 0pt; float: left;" class="ui-icon ui-icon-alert"/>'+msg+'</span></p>');
		
		$("#"+randomId).dialog({
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Confirm: function() {
					if (callback) callback();
					$(this).dialog('destroy');
					$("#"+randomId).remove();
				},
				Cancel: function() {
					$(this).dialog('destroy');
					$("#"+randomId).remove();
				}
			}
		});	
	},
	/**
	 * popup a basic jquery ui dialog
	 * 
	 * @param string msg to display to the user
	 * @param string title the title of the dialog
	 */
	basicDialog: function(msg, title) {
		if (!title) {
			title = 'Information';
		}
		
		var randomId = 'dialog'+Math.floor(Math.random()*1001);
		$('body').append('<p title="'+title+'" id="'+randomId+'">'+msg+'</p>');
		$("#"+randomId).dialog({
			bgiframe: true,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
};