

// ------------------------ Ajax Engine ----------------------------------------


BaseAjax = {};
BaseAjax._count = 0;
BaseAjax._xArgs = {};

BaseAjax._xArray = {};


BaseAjax.makeAjaxCall = function(url) {
	
	BaseAjax._count++;
	
	BaseAjax._xArray[BaseAjax._count] = BaseAjax._xArgs;
	BaseAjax.doAjax(BaseAjax._count,url);
	
	BaseAjax._xArgs = {};
	
}

	
BaseAjax.doAjax = function(countVar, url){
		
	//$('#ajaxhelper').animate({ opacity: .9999}, 0001, '', function() { 
		if(BaseAjax._xArray[countVar].loader){	
			BaseAjax.setLoaderOverlay(BaseAjax._xArray[countVar].returnDiv);
			BaseAjax._xArray[countVar].noloader = false;
		}
		
		$.ajax({
			type:       "POST",
			url:        url,
			data:       BaseAjax._xArray[countVar].data,
			success:    function(p_sMsg) {
				
				//BaseAjax._tmp = BaseAjax._xArray[countVar];
				BaseAjax.onAjaxCallReturned(countVar, p_sMsg);
			}
		});

//	 });
	
}




BaseAjax.onAjaxCallReturned = function(countVar, p_sMsg) {
	
	
	if(BaseAjax._xArray[countVar].returnDiv){
		$(BaseAjax._xArray[countVar].returnDiv).html(p_sMsg);
	}
	
	BaseAjax.returnVar = p_sMsg;
	if(BaseAjax._xArray[countVar].callBack) {
		BaseAjax._xArray[countVar].callBack();
	}
	
	BaseAjax._xArray[countVar] = null;
}






BaseAjax.setLoaderOverlay = function( theElement ){
	var loadingImg = '/image/ajax-loader.gif';
	
	//$('#ajaxoverlay').remove();
	
	if( $(theElement).css('position') != 'absolute' )
		$(theElement).css('position','relative');
	
	padLeft = $(theElement).css('padding-left');
	padTop = $(theElement).css('padding-top');
	
	
	var l_nHeight = $(theElement).height();
	var l_nWidth = $(theElement).width();
	
	
	$(theElement).append(
		'<div id="ajaxoverlay" style="background:#fff;'+
		 			'width:'+l_nWidth+'px; '+
					'height:'+l_nHeight+'px; '+
		 			'position:absolute; '+
					'top:'+ padTop+'; '+
					'left:'+padLeft+'; '+
					'z-index:20; '+
					'filter:alpha(opacity=75);-moz-opacity:.75;opacity:.75;'+
					'z-index:1200; '+
					'"></div> '
		);
	
	$(theElement).append(
		'<img src="'+loadingImg+'" style="'+
		 			'position:absolute; '+
					'margin-top:'+ padTop+'; '+
					'margin-left:'+padLeft+'; '+
		 			'left:'+(l_nWidth - 51) / 2+'px; '+
					'top:'+(l_nHeight - 64) / 2+'px; '+
					'z-index:1201; '+
					'" /> '
		);

	
	
	//alert ( $(theElement).offset({border: true, padding: true})['left'])
	//alert ( $(theElement).offset()['left'])
	
	
	//var l_aOffset = $(theElement).offset({border: true, padding: true});
	
	//alert(l_nHeight);
	
	/*
	$('body').append( 
		 '<div id="ajaxoverlay" style="background:#000; '+
		 			'width:'+l_nWidth+'px; '+
					'height:'+l_nHeight+'px; '+
		 			'position:absolute; '+
					'top:'+l_aOffset['top']+'px; '+
					'left:'+l_aOffset['left']+'px;'+
					'"></div> '
	);
	*/
	
}


