LOADING = {
	show: function(title, help, image) {

		var default_skin = "#ajax-load-background {opacity:0.5; filter:alpha(opacity=50); position:fixed; width:100%; height:100%; left:0; top:0; background:none repeat scroll 0% 0%; background-color:#fff; z-index:99997;}#ajax-load {position:fixed; z-index:99998; top:50%; left:50%; margin-left:-20px; text-align:center;}#ajax-load #ajax-load-title, #ajax-load #ajax-load-help {color:#000;}#ajax-load #ajax-load-title {font-size:16px; font-weight:bold;}#ajax-load #ajax-load-help {font-size:10px;}";

		var head = document.getElementsByTagName("head")[0];

		// tricky hack for IE
		var htmDiv = document.createElement('div');

		htmDiv.innerHTML = '<p>x<\/p><style type="text/css">'+default_skin+'<\/style>';
		head.insertBefore(htmDiv.childNodes[1], head.firstChild);

		var bgDiv = document.createElement('div');
		bgDiv.id = 'ajax-load-background';

		var mainDiv = document.createElement('div');
		mainDiv.id = 'ajax-load';

		var titleDiv = document.createElement('div');
		titleDiv.id = 'ajax-load-title';
		titleDiv.innerHTML = title;

		var imgLoading = document.createElement('img');
		imgLoading.src = image;

		var helpDiv = document.createElement('div');
		helpDiv.id = 'ajax-load-help';
		helpDiv.innerHTML = help;

		mainDiv.appendChild(titleDiv);
		mainDiv.appendChild(imgLoading);
		mainDiv.appendChild(helpDiv);

		document.body.appendChild(bgDiv);
		document.body.appendChild(mainDiv);
	},

	hide: function() {
		if(document.getElementById('ajax-load-background')) {
			document.getElementById('ajax-load').parentNode.removeChild(document.getElementById('ajax-load'));
			document.getElementById('ajax-load-background').parentNode.removeChild(document.getElementById('ajax-load-background'));
		}
	}
};

/*
 * AddXbutton
 */
(function($) {
	$.fn.AddXbutton = function(options) {
		var defaults = {
			img: '/img/icons/x.png'
		};
		var opts = $.extend(defaults, options);
		var objs = new Array();
		$(this).each(
		function(i) {
			$obj = $(this);
			objs[i] = $obj;
			var marginBottom = '-1px';
			if(this.tagName == 'TEXTAREA') {
				marginBottom = '2px';
			}
			$(this).after(
				$('<input type="image" id="xButton' + i + '" src="' + opts['img'] + '" value="X" />')
					.css({ 'display': 'none', 'cursor': 'pointer', 'marginLeft': '-15px', 'marginBottom': marginBottom })
					.click(function() {
						objs[i].val('').keyup().focus();
						$("#xButton" + i).hide();
						return false;
					}))
			.keyup(function() {
				if($(this).val().length > 0) {
					$("#xButton" + i).show();
				}
				else {
					$("#xButton" + i).hide();
				}
			});
			if($obj.val() != '') {
				$("#xButton" + i).show();
			}
		});
	};
})(jQuery);

