function ShowProcessingDialog(element, text) {
	var is_element = true;
	if(text==undefined || text=="" || text==null) text = "Now Saving ...";
	if(element==undefined || element=="" || element==null) is_element = false;
	if(is_element){
		$("#"+element).block({
			message: '<h1 style="font-size:20px;color:#FFFFFF;">' + text + '</h1>',
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'border-radius': '10px',
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#FFFFFF' 
			}
		});
	}else{
		$.blockUI({
			message: '<h1 style="font-size:20px;color:#FFFFFF;">' + text + '</h1>',
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'border-radius': '10px',
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#FFFFFF' 
			}
		});
	}
}

function CloseProcessingDialog(element,callback) {
	var is_element = true;
	if(element==undefined || element=="" || element==null) is_element = false;
	var callback_obj = {};
	if(callback != undefined && callback != null && typeof callback == "function") {
		callback_obj = { onUnblock: function() { callback(); } }
	}
	if(is_element){
		$("#"+element).unblock(callback_obj);
	}else{
		$.unblockUI(callback_obj);
	}
}

function ShowSavingDialog(text) {
	if(text==undefined || text=="" || text==null) text = "Now Saving ...";
	$("#saving-dialog").dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		resizable: false,
		draggable: false,
		title: 'Please wait',
		height: 160,
		width: 280,
		open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
		close: function(event, ui) { $(".ui-dialog-titlebar-close").show(); }
	}).html('<p><img src="resources/images/indicator.gif" width="16" height="16" style="vertical-align:middle;" /><span style="padding-left:5px;height:16px;vertical-align:middle;text-align:left">' + text + '</span></p>').dialog('open');
}

function CloseSavingDialog(callback) {
	$('#saving-dialog').dialog('close');
}

function ShowDialog(type,message,callback1,callback2,callback3) {
	var height = ($.browser.msie) ? 300 : 240;
	var width = ($.browser.msie) ? 460 : 420;
	
	var icon = 'ui-icon-info';
	var title = 'Alert';
	var button = {
		'OK': function() {
			$(this).dialog('close');
			 if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
				callback1();
			 }
		}
	};
	var messages = '<table align="center" width="100%"><tr><td><span class="ui-icon ' + icon + '" style="float:left; margin:0 5px;text-align:justify;"></span>' + message + '</td></tr></table>';
	
	switch(type) {
		case "error": 
			id = 'error';
			icon = 'ui-icon-alert'; 
			title = 'Error'; 
			break;
		case "fatalerror": 
			id = 'error';
			icon = 'ui-icon-alert'; 
			title = 'Fatal Error'; 
			height = $(window).height() - 30;
			width = $(window).width() - 30;
			break;
		case "warning": 
			id = 'warning';
			icon = 'ui-icon-alert'; 
			title = 'Warning'; 
			break;		
		case "success":
		case "complete":
			id = 'success';
			icon = 'ui-icon-circle-check'; 
			title = 'Complete'; 
			break;
		case "prompt":
			height = 150;
			width = 450;
			id = 'prompt';
			icon = 'ui-icon-info';
			title = message;
			messages = '<table align="center" width="95%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" valign="middle"><input type="text" name="prompt_textbox" id="prompt_textbox" value="" style="width:95%;padding:.3em;" /></td></tr></table>';
			button = {
				'OK': function() {
					if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
						callback1($('#prompt_textbox').val());
					}
					$(this).dialog('close');
				},
				'Cancel': function() {
					$(this).dialog('close');
				}
			}
			break;
		case "confirm": 
			id = 'confirm';
			icon = 'ui-icon-alert'; 
			title = 'Confirm';
			button = {
				'Yes': function() {
					$(this).dialog('close');
					if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
						callback1();
					}
				},
				'No': function() {
					$(this).dialog('close');
					if(callback2 != undefined && callback2 != null && typeof callback2 == "function") {
						callback2();
					}
				}
			}
			break;
		case "okcancel": 
			id = 'confirm';
			icon = 'ui-icon-alert'; 
			title = 'Confirm';
			button = {
				'OK': function() {
					$(this).dialog('close');
					if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
						callback1();
					}
				},
				'Cancel': function() {
					$(this).dialog('close');
					if(callback2 != undefined && callback2 != null && typeof callback2 == "function") {
						callback2();
					}
				}
			}
			break;
		case "yesnocancel": 
			id = 'confirm';
			icon = 'ui-icon-alert'; 
			title = 'Confirm';
			button = {
				'Yes': function() {
					$(this).dialog('close');
					if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
						callback1();
					}
				},
				'No': function() {
					$(this).dialog('close');
					if(callback2 != undefined && callback2 != null && typeof callback2 == "function") {
						callback2();
					}
				},
				'Cancel': function() {
					$(this).dialog('close');
					if(callback3 != undefined && callback3 != null && typeof callback3 == "function") {
						callback3();
					}
				}
			}
			break;	
		case "pjwarning": 
			id = 'pjwarning';
			icon = 'ui-icon-alert'; 
			title = 'Warning';
			button = {
				'Confirm': function() {
					$(this).dialog('close');
					if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
						callback1();
					}
				},
				'Cancel': function() {
					$(this).dialog('close');
					if(callback2 != undefined && callback2 != null && typeof callback2 == "function") {
						callback2();
					}
				}
			}
			break;			
		case "info": 
		default: 
			id = 'info';
			icon = 'ui-icon-info'; 
			title = 'Information'; 
			
			var btar = type.split(',');
			if(btar.length>1){
				button = {};
				
				button[btar[0]] = function() {
						$(this).dialog('close');
						if(callback1 != undefined && callback1 != null && typeof callback1 == "function") {
							callback1();
						}
					}
				button[btar[1]] = function() {
						$(this).dialog('close');
						if(callback2 != undefined && callback2 != null && typeof callback2 == "function") {
							callback2();
						}
					}
							
			
			}
			
			
			break;
		
	}
	
	$("#" + id + "-dialog").attr('title',title).dialog({
		title: title,
		bgiframe: true,
		modal: true,
		autoOpen: false,
		resizable: false,
		show: 'fade',
		hide: 'fade',
		height: height,
		width: width,
		buttons: button,
		close: function() {
			$(this).html('<table align="center" width="95%" height="100%" border="0"><tr><td align="center" valign="middle"><img src="resources/images/indicator.gif" />&nbsp;Now Loading ...</td></tr></table>');
		}
	}).html(messages).dialog('open');
}
