/* Overriding Javascript's Alert Dialog */
//
//function alert(msg) {
//  $('#alert')
//    .jqmShow()
//    .find('div.jqmAlertContent')
//      .html(msg);
//}
//
//$().ready(function() {
//  $('#alert').jqm({overlay: 0, modal: true, trigger: false});
//  
//  // trigger an alert whenever links of class alert are pressed.
//  $('a.alert').click(function() { 
//    alert('You Have triggered an alert!'); 
//    return false;
//  });
//});


/* Overriding Javascript's Confirm Dialog */

// NOTE; A callback must be passed. It is executed on "cotinue". 
//  This differs from the standard confirm() function, which returns
//   only true or false!

// If the callback is a string, it will be considered a "URL", and
//  followed.

// If the callback is a function, it will be executed.

function processConfirm(msg,callback) {
	$('#confirm')
	.jqmShow()
	.find('p.jqmConfirmMsg')
	.html(msg)
	.end()
	.find(':submit:visible')
	.click(function(){
		if (this.value == 'tak') {
			if (typeof callback == 'string') {
				window.location.href = callback;
			} else {
				callback();
			}
		}
		$('#confirm').jqmHide();
	});
}
function confirm(msg,callback) {
	if ($('#confirm').size() == 0) {
		$().ajaxStop($.unblockUI);
		$.blockUI('<h1>Processing</h1>', {
			border: '3px solid #a00'
		});
		$.ajax({
			type: "GET",
			dataType: "html",
			url: baseDir + "addons-load/confirm.html",
			success: function(data){
				$('body').append(data);
				$('#confirm').jqm({overlay: 88, modal: true, trigger: false});
				processConfirm(msg, callback);
			}
		});
	} else {
		processConfirm(msg, callback);
	}
	return false;
	
}


//$().ready(function() {
//  $('#confirm').jqm({overlay: 88, modal: true, trigger: false});
//  
//  // trigger a confirm whenever links of class alert are pressed.
//  $('a.confirm').click(function() { 
//    confirm('About to visit: '+this.href+' !',this.href); 
//    return false;
//  });
//});