	function capitaliseFirstLetter(string)
	{
	    return string.charAt(0).toUpperCase() + string.slice(1);
	}
	
	//pdf processing functions
	function convertLeafletsSize2Booklets(size) 
	{
		switch (size) {
			case 'Colour front, blank back':
			case 'Colour front, B/W back':
				return '4x1';
				break;
			case 'Colour both sides':
				return '4x4';
				break;
			case 'B/W both sides':
				return '1x1';
				break;
		}
	}
	//pdf processing functions

	function showConfirmPanel(msg)
	{
		if(confirm(msg)) 
			return true;
		else
			return false;
	}
	
	function getWindowHeight()
	{
		if (navigator.userAgent.match("Opera")  )
			return window.innerHeight;
		else 
			return $j(window).height();
	}
	
	function showModalWindow(options)
	{
		var defaultWidth = 500;
		
		if (!options.slideDownDuration) options.slideDownDuration = 3;
		if (!options.slideUpDuration) options.slideUpDuration = 3;
		if (!options.resizeDuration) options.resizeDuration = 2;
		
		if (!options.isAutoHeight)
			options.height = 
				document.viewport.getDimensions().height;
		
		if (options.defaultWidth)		
			defaultWidth = options.defaultWidth;
			
		if (document.viewport.getDimensions().width < defaultWidth)
			options.width = defaultWidth;
		else
			options.width = 
				document.viewport.getDimensions().width;
		
		options.beforeHide = 
			function () {
				//fixed evel bug with wrong css for ie on edit profile page
				$$('link[title="reset"]').each(function(item) {
					item.remove();
				});
				
				$$('link[title="style"]').each(function(item) {
					item.remove();
				});
				
				$('MB_content').update('');
			};
		
		Modalbox.show(options.href, options);
		
		return false;
	}
	
	jQuery(document).ready(function()
	{
		jQuery.fn.optionDisable = function(withValues)
		{
			if (!withValues) var withValues = [];
			
			jQuery.each(this, function(index, value) {
				var ths = jQuery(value);
				
				if(
					ths.attr('tagName').toLowerCase() == 'option'
					&& (
						(withValues.length == 0)
						|| (jQuery.inArray(ths.val(), withValues) != -1)
					)
				)
				{
					ths.before(jQuery('<optgroup>&nbsp;</optgroup>').css({color:'#ccc',height:ths.height()}).attr({id:ths.attr('value'),label:ths.text()})).remove();
				}
				return ths;
			})
		}
		
		jQuery.fn.optionEnable = function(withValues)
		{
			if (!withValues) var withValues = [];
			
			jQuery.each(this, function(index, value) {
				var ths = jQuery(value);
				var tag = ths.attr('tagName').toLowerCase();
				
				if(
					(tag == 'option')
					&& (
						(withValues.length == 0)
						|| (jQuery.inArray(ths.val(), withValues) != -1)
					)
				)
				{
					ths.removeAttr('disabled');
				}
				else if(
					(tag == 'optgroup')
					&& (
						(withValues.length == 0)
						|| (jQuery.inArray(ths.attr('id'), withValues) != -1)
					)
				)
				{
					ths.before(jQuery('<option />').attr({value:ths.attr('id')}).text(ths.attr('label'))).remove();
				}
				return ths;
			})
		}
	});
	
	function checkAuth() 
	{
		jQuery(document).ajaxSend(
			function(e, xhr, settings) 
			{
				if (settings.url != '/main/auth/check') {
					jQuery.ajax({
						type	: "POST",
						async	: false,
						url 	: '/main/auth/check',
						success	: function (answer) {
							if (answer == 'false') {
								window.location.href = '/main/auth/login';
							}
						}
					});
				}
			}
		);
	}
	
	function isset(varname) 
	{
		try {
			var t = typeof(varname);
		} catch(e) {
			return false;
		}
		
		if ( t !== 'undefined' && t != 'function') 
			return true;
		else
			return false;
	}
	
	function GlobalRegistry()
	{
		this.registry = [];
		
		GlobalRegistry.prototype.add = 
			function ($name, $value) {
				this.registry[$name] = $value;
				
				return this;
			}
		
		GlobalRegistry.prototype.get = 
			function ($name, $value) {
				if (!this.registry[$name]) {
					return null;
				}
				
				return this.registry[$name];
			}
	}
	
	(function(jQuery){
		jQuery.fn.serializeJSON = function() {
			var json = {};
			
			jQuery.map(jQuery(this).serializeArray(), function(n, i){
				json[n['name']] = n['value'];
			});
			
			return json;
		};
	})(jQuery);
