

function ajax_doUpdater(content_div,url)
{
	new Ajax.Updater(content_div,url, {
		onCreate: new Function("ajax_spin_div('" +content_div+ "');"),
		'method':'get',
		'parameters':'asAjax=Y',
		'evalScripts': true
	});
	return false;
}

function ajax_submitForm(divid,frm)
{


	if (typeof(CMS_FCK_prepare_submit) == 'function') {
		CMS_FCK_prepare_submit();
	}

	params =  Form.serialize(frm, true);
	params.asAjax = 'Y';

	new Ajax.Updater(divid,frm.action,
		{
			onCreate: new Function("ajax_spin_div('" +divid+ "');"),
			method: frm.method,
			parameters: params, 
			evalScripts: true
		}
	);
	
	return false;
}


function util_getStyle(elem,styleProp)
{
	var y;

	if (typeof elem.currentStyle != 'undefined')
		y = elem.currentStyle[styleProp];
	else if (typeof window.getComputedStyle != 'undefined')
		y = document.defaultView.getComputedStyle(elem,null).getPropertyValue(styleProp);
	return y;	
}

function util_getStyleMulti(elem,styleProp1, styleProp2, styleProp3)
{
	
	var style = util_getStyle(elem, styleProp1);

	if (!style && typeof styleProp2 != 'undefined')
		style = util_getStyle(elem, styleProp2);

	if (!style && typeof styleProp3 != 'undefined')
		style = util_getStyle(elem, styleProp3);

	return style;
}


function ajax_spin_div(div_id)
{

	try {
		var container = document.getElementById(div_id);

		var spin_div = document.createElement("div");

		spin_div.style.zIndex = 100;
		spin_div.className = 'spin_div';

		var firstChild = container.firstChild;

		// position spin div relative to this relativeDiv
  		var relativeDiv = document.createElement("div");


		relativeDiv.appendChild(spin_div);

		if (firstChild) 
			firstChild.parentNode.insertBefore(relativeDiv, firstChild);
		else
			container.appendChild(relativeDiv);


		var setHeightTo, setWidthTo;

		// try to get div that's exactly the size of 
		// the container minus padding/border

		if (navigator.appVersion.indexOf("MSIE 6.") != -1 ||
			navigator.appVersion.indexOf("MSIE 7.") != -1) {
	
			// for IE7
			// put "feelers" out to get the height and width.
			relativeDiv.style.width='100%';
			spin_div.style.width='100%';
			relativeDiv.style.height='100%';
			spin_div.style.height='100%';

			setWidthTo = spin_div.offsetWidth+'px';
			setHeightTo = spin_div.offsetHeight+'px';
	
			relativeDiv.style.width='auto';
			relativeDiv.style.height='auto';
	
			// IE7 div is absolute wrt the window,
			// not wrt the relativeDiv
			spin_div.style.position = 'absolute';
			spin_div.style.top = container.scrollTop+'px';
			spin_div.style.left = '0px';
			relativeDiv.style.position = 'relative';
	
			// Set timeout due to IE7/IE8-compatibility mode problem
			setTimeout(function() {
				spin_div.style.height = setHeightTo;
				spin_div.style.width = setWidthTo;
			}, 1);
	

		}
		else {
			relativeDiv.style.width='100%';
			spin_div.style.width='100%';
			setWidthTo = spin_div.offsetWidth;
			relativeDiv.style.width='auto';
	
			setHeightTo = container.scrollHeight;
	
			// subtract top/bottom padding if necessary
			var paddingTop,  paddingBottom;
	
			try {
				// Opera already subtracts padding
				if (navigator.userAgent.indexOf('Opera') == -1) {

					paddingBottom =  parseInt(util_getStyleMulti(container, 'paddingBottom', 'padding-bottom'));
					paddingTop =  parseInt(util_getStyleMulti(container, 'paddingTop', 'padding-top'));
	
					if (typeof paddingBottom != 'number' || isNaN(paddingBottom))
						paddingBottom = 0;
	
					if (typeof paddingTop != 'number' || isNaN(paddingTop))
						paddingTop = 0;
	
	
					// FF and IE don't add bottom padding when there is an overflow of content
					// actual padding can be between 0 and bottomPadding depending on size of content
					// Safari always adds padding at the bottom.
	
					setHeightTo -= paddingTop;
	
					if (navigator.userAgent.indexOf('AppleWebKit/') == -1) {
						setHeightTo -= Math.min(paddingBottom, Math.max(0,
				 			paddingBottom - (container.scrollHeight - container.clientHeight)));
					}
					else {
						setHeightTo -= paddingBottom;
					}
				}
			} catch (e) {}


			spin_div.style.position = 'absolute';
			relativeDiv.style.position = 'relative';

			spin_div.style.height = setHeightTo+'px';
			spin_div.style.width = setWidthTo + 'px';
		}
	}
	catch (e) {}
} 

