/*
 * AbCore Standard JQuery Functions
 * version: 0.0.1 (13-AUG-2009)
 * @requires jQuery v1.3.2 or later
 */

/*
 * History:
 * 
 * 0.0.1	First version
 */

$.getAbModuleContainer = function(mid) {
	var mod = null;
	if ($("." + mid + "_ModuleContainer").length > 0) { // New Module Box Marker
		mod = $("." + mid + "_ModuleContainer");
	} else {
		if ($("#zone_" + mid + "_Table").length > 0) { // Old Module Box Marker
			mod = $("#zone_" + mid + "_Table");
		} else { // Unknown Module Box Marker
			mod = null;
		}
	}
	return mod;
};

$.errorMessage = function(message, header, close, timeout) {
	var o = {
		theme : 'ErrorMessage',
		sticky : true
	};
	if (timeout != null) {
		o['sticky'] = false;
		o['life'] = timeout;
	}
	if (header != null)
		o['header'] = header;
	if (close != null)
		o['close'] = close;
	$.jGrowl(message, o);
};
$.okMessage = function(message, header, close, timeout) {
	var o = {
		theme : 'OKMessage'
	};
	if (timeout != null) {
		o['life'] = timeout;
	} else {
		o['life'] = 2000;
	}
	if (header != null)
		o['header'] = header;
	if (close != null)
		o['close'] = close;
	$.jGrowl(message, o);
};
$.pleaseWait = function(relPath, message, obj, block) {
	if (message == null)
		message = 'Please Wait';
	var o = {
		message : "<img src=\"" + relPath + "images/loading.gif\" /> "
				+ message,
		forceIframe : true,
		overlayCSS: {
	        'z-index': '10000'
	    },
		css : {
	        'z-index': '10001',
			padding : '15px',
			'-webkit-border-radius' : '10px',
			'-moz-border-radius' : '10px',
			opacity : .5
		}
	};
	if (block != null)
		o['onBlock'] = block;
	if (obj == null)
		$.blockUI(o);
	else
		$(obj).block(o);
};

$.multiLanguageOrganizeTabs = function(start) {
	var currentLocale = 0;
	if (typeof (SystemLocales) != "undefined"
			&& typeof (SystemCurrentLocale) != "undefined") {
		for ( var i = 0; i < SystemLocales.length; i++) {
			if (SystemLocales[i] == SystemCurrentLocale) {
				currentLocale = i;
				break;
			}
		}
	}
	if (start) {
		$('.multiLanguageTabsEditor .EditorArea').each(function() {
			if (!$(this).hasClass('DisabledAuto'))
				startTinyMCE(this.id);
		});
		$('.multiLanguageTabs, .multiLanguageTabsEditor').each(function() {
			var o = $(this);
			if (!o.hasClass('alreadyTab')) {
				o.tabs( {
					event : 'mouseover',
					selected : currentLocale
				}).addClass('alreadyTab');
			}
		});
	} else {
		$('.multiLanguageTabs, .multiLanguageTabsEditor').each(function() {
			if (!$(this).hasClass('alreadyTab')) {
				if ($(this).hasClass('multiLanguageTabsEditor'))
					startTinyMCE(this.id);
				$(this).tabs( {
					event : 'mouseover',
					selected : currentLocale
				}).addClass('alreadyTab');
			}
		});
	}
};
$._rpcCli = null;
$._rpcCliPath = null;
$.jrpc = function(path) {
	if (!path)
		path = '';
	if ($._rpcCli == null) {
		$._rpcCli = $.jsonrpc( {
			url : path + 'jsonrpc.php'
		});
		$._rpcCliPath = path;
	}
	return $._rpcCli;
};
$.jrpcOnStart = function(fn) {
	if (typeof (fn) == "function") {
		$._rpcCli.options.start = fn;
	} else {
		$._rpcCli.options.start = null;
	}
};
$.jrpcOnEnd = function(fn) {
	if (typeof (fn) == "function") {
		$._rpcCli.options.success = fn;
	} else {
		$._rpcCli.options.success = null;
	}
};
$.jrpcRevert = function() {
	$._rpcCli = $.jsonrpc( {
		url : $._rpcCliPath + 'jsonrpc.php'
	});
};
$.jrpcAsync = function(s) {
	$._rpcCli.options.async = s;
};
$.jrpcConfig = function(c) {
	if (c != null) {
		for ( var x in c) {
			if (x == 'start')
				$.jrpcOnStart(c[x]);
			else if (x == 'end')
				$.jrpcOnEnd(c[x]);
			else if (x == 'async')
				$.jrpcAsync(c[x]);
		}
	} else {
		$.jrpcOnStart(null);
		$.jrpcOnEnd(null);
		$.jrpcAsync(false);
	}
};
$(function() {
	$.multiLanguageOrganizeTabs(true);
});
