/**
	@desc This file contains a handfull of helper functions

	$Log: helper.js,v $
	Revision 1.8  2009/07/10 05:37:47  cvsosir
	upd
	
	Revision 1.7  2009/05/11 09:41:10  cvsosir
	*** empty log message ***
	
	Revision 1.6  2009/01/12 10:00:16  cvsosir
	Added $Log: helper.js,v $
	Added Revision 1.8  2009/07/10 05:37:47  cvsosir
	Added upd
	Added
	Added Revision 1.7  2009/05/11 09:41:10  cvsosir
	Added *** empty log message ***
	Added
	

**/

//=== HERE A GLOBAL GETS CREATED THAT CAN BE USED IN ANY SCRIPT
gl=new Logger(false);

/*@param contentId A valid cointainer within the HTML DOM to be used to display received data*/ 
function AjaxHelper () 
{
	
	var sUrl;
	var sParams;
	var sContentId;
	
	/*Cares for sending an AJAX request
	@param URL The URL or parser to call
	@param params A list with params e.g. ('sessionId=4545345345646&category=RevCon')
	@param contentId A valid cointainer within the DOM to be used to display received data
	*/
	this.publicSend= function (url,params,contentId)
	{
		send(url,params,contentId);
	}
	
	/*Send the AJAX request 
	@See publicSend*/
	function send(url,params,contentId)
	{
		gl.log('=== send(' + url + ',' + params+ ',' + contentId +') ===','i');
		//storing the parameters
		sUrl=url;
		//adding the sessionId as default to every call
		sParams='sessionId='+ GLOBALSESSIONID+ '&' +params;
		sContentId=contentId;

		showLoading();
		
		//gl.log('Sending AJAX request with params: ' + sParams); 	
		//When evalScripts=true then javascript code within the response gets executed
		//var myAjax = new Ajax.Updater( sContentId,sUrl, {method: 'get',evalScripts: 'true', parameters: sParams, onComplete: showResponse} );
		var myAjax = new Ajax.Updater( sContentId,sUrl, {method: 'get',evalScripts: 'true', parameters: sParams, onComplete: checkSession } );
		gl.log('=== THE END send(' + url + ',' + params+ ',' + contentId +') ===','i');
			
	}
	/*Used to display a loading indicator*/
	function showLoading ()
	{
		try
		{
			$(sContentId).innerHTML= '&#160;<img src="images/animated/red2.gif" id="progress" />';	
		}
		catch(err)
		{
			//alert('Content id not found.');
		}
	}
	
		
	function checkSession(originalRequest)
	{
		isSessionExpired(originalRequest.responseText);
	}	
	/*Executed when the AJAX response of the server is received*/
	function showResponse(originalRequest) 
	{
		
		var newData = originalRequest.responseText;
	
		try
		{
			$(sContentId).innerHTML = newData;	
		}
		catch(err)
		{
			alert('Content id not found.');
		}
	}	
}




/*This class can uses the log4J logger to log messages
@param bStatus default(true) true when active , false when not
*/
function Logger (bStatus)
{
	var status;
	var log=null;
	
	//default
	if(bStatus == null)
	{
		status=true;
	}
	else
	{
		status=bStatus;
	}
	//only initializing logger when active 
	if(status == true)
	{
		var log=null;
		//creating a log4j object
		try{
		
			log = log4javascript.getDefaultLogger();
			
		}
		catch(e)
		{
			alert(e);
		}
	}	
				
	/*@This function is used to log the messages
	@param message The message to log
	@param log The log level t=trace,d=debug,i=info,w=warn,e=error,f=fatal (default is d)
	*/
	this.log= function(message,level)
	{	
		//only log when active
		if(status == true)
		{
			
			if(level == null)
			{
				level="d";
			}
			
			switch (level)
			{
				case "t": 
					log.trace(message);
					break;
				case "d":
					log.debug(message);
					break;
				case "i":
					log.info(message);
					break;
				case "w":
					log.warn(message);
					break;
				case "e":
					log.error(message);
					break;
				case "f":
					log.fatal(message);
					break;	
			}
		}
	}
	/*This function can be used to activate or deactvate the logging mechanism
	@param bStatus True for active, false inactive 
	*/	
	this.setStatus =function(bStatus)
	{
		status=bStatus;
		
		//when no logger is initialized yet...
		if(log == null)
		{
			log = log4javascript.getDefaultLogger();
		}
	}	
}

/** This function can be used to display a tooltip. 
@param element A pointer to the element that cointains the text to display.
**/

function createToolTip(element)
{
	//gl.log('=== createToolTip(' + element + ') ===');
	
	new Tip(element, element.rel, {title : "Info...", className: "hsbctip", showOn: "mousemove", viewport: true, fixed: false, 
closeButton: true, hideOn: "mouseout"});
	
 	
 	//gl.log('=== THE END createToolTip(' + element + ') ===');
}

/*
function LoadStaticDocsEx(doc)
{
	 var content = $('content');
	content.update('');
	var req = new Ajax.Request('[SERVER]!GetStaticDoc', { method: 'post', parameters: 'Doc=' + doc ,onLoading:  Loading(), encoding: 'WINDOWS-1252',onSuccess: function(transport) 
	{			
		var content =$('content');
		content.update('');
		content.update(unescape(transport.responseText));
	},
	onError: function(transport) 
	{
		alert(unescape(transport.responseText));
	}
}
);	
} */	

/**
 * This function can be used to link to an external website. The linkId can be used to identify
 * that link within the web statistics. (Before redirecting an image with linkId gets feeded into 
 * the HTML DOM.
 * @param linkId A unique ID for that link
 * @param url The URL to redirect to
*/
function redirectTo(linkId,url)
{
	createStatPic('Link_' + linkId);
	//window.location = url;

	window.open(url);
}






