/*
 * AJAX TOOLTIP SCRIPT
 */
var offsetxpoint=0
var offsetypoint=15
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var showAjaxToolTipRequest = null;
var ajaxLoading = null;

function initializeAjaxToolTip(id, text, closeOnClick) {
	var div = '<div id="ajaxtooltip" style="visibility:hidden;">';
	div += '<table class="shadow"><tr>';
	div += '<td class="shadowTL">&nbsp;</td><td class="shadowMT">&nbsp;</td><td class="shadowTR">&nbsp;</td>';
	div += '</tr><tr><td class="shadowML">&nbsp;</td><td class="shadowBG">';		
	
	div += '';
	if( closeOnClick ) {
	 div += '<div id="ajaxtooltip_close" onclick="var doc = document;if( window.top.document.getElementById(\'page\') != null ) {doc = window.top.document;}$(doc.getElementById(\'ajaxtooltip\')).hide();">';
	} else {
	 div += '<div id="ajaxtooltip_close" onclick="var doc = document;if( window.top.document.getElementById(\'page\') != null ) {doc = window.top.document;}$(doc.getElementById(\'ajaxtooltip\')).hide();">&nbsp;</div>';
	}
	div += '<div id="'+ id +'">';
	div += '<div class="ajaxcontent">&nbsp;';
	if( typeof text != "undefined" ) {
		div += '<div class="loadingText">';
		div += text;
		div += '</div>';
	}	
	if( closeOnClick ) {
		div += '</div></div></div>';
	} else {
		div += '</div>';
	}
	

	
	div += '</td><td class="shadowMR">&nbsp;</td>'
	div += '</tr><tr>';
	div += '<td class="shadowBL">&nbsp;</td><td class="shadowMB">&nbsp;</td><td class="shadowBR">&nbsp;</td>'
	div += '</tr>'
	div += '</table></div>';

	if( window.top.document.getElementById('page') != null ) {
	   	new Insertion.Top(window.top.document.getElementById('page'),div);	
	} 

}

var tooltipOpener = null;

function showAjaxToolTip(url, parameters, divId, loadingMsg, opener, closeOnClick){

	tooltipOpener = opener;

	var doc = document;if( window.top.document.getElementById('page') != null ) {doc = window.top.document;}
	
	if( typeof closeOnClick == "undefined" ) {
		closeOnClick = true;
	}
	
	if( doc.getElementById( divId ) == null ) {
		initializeAjaxToolTip(divId, loadingMsg, closeOnClick);
	}

	if( ajaxLoading != null ) {
		doc.getElementById( divId ).innerHTML = ajaxLoading;
	}

	if ( typeof parameters != "undefined" ) {
		eval("showAjaxToolTipRequest = new Ajax.Request( '"+ url +"', {method: 'get', parameters: '&responseId="+ divId +""+ parameters +"', onComplete: handleShowAjaxToolTipAJAXResponse} );");			
	} else {
		eval("showAjaxToolTipRequest = new Ajax.Request( '"+ url +"', {method: 'get', parameters: '&responseId="+ divId +", onComplete: handleShowAjaxToolTipAJAXResponse} );");			
	}
	
	if (ns6||ie){
		var id = 'ajaxtooltip';
		enabletip=true;
		if( window.top.document.getElementById('page') != null ) {
			parent.positiontip(opener, id);
		} else {
			positiontip(opener, id);
		}
		if( ajaxLoading == null )
			ajaxLoading = doc.getElementById( divId ).innerHTML;
		$(doc.getElementById(id)).show();
		return false
	}
}

function handleShowAjaxToolTipAJAXResponse(res) {
	if( res.status = 200 ) {
		var doc = document;
		
		if( window.top.document.getElementById('page') != null ) {
			doc = window.top.document;
		}	
		doc.getElementById(res.request.parameters.responseId).innerHTML = res.responseText;	
		
		var id = 'ajaxtooltip';
		if( window.top.document != document ) {
			parent.positiontip(null, id);
		} else {			
			positiontip(tooltipOpener, id);
		} 
	}
}
/*
 START: TEMP HELPER FUNCTIONS
 */
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
/*
 END: TEMP HELPER FUNCTIONS
 */

function positiontip(opener, divId, parent){
	if( opener != null ) {
		var pos = Element.cumulativeOffset(opener);
		var scroll = Element.cumulativeScrollOffset(opener);		
		var top = 0;
		if( scroll.top > f_scrollTop() ) {
			top = pos.top - scroll.top;
		} else {
			top = pos.top;
		}
		var element = document.getElementById(divId);
		element.style.top = (top) + "px";
		element.style.left = (pos.left - scroll.left) + "px";
		element.style.visibility="visible"			
	} else {
		document.getElementById(divId).style.visibility="visible"		
		displayElementCenterScreeen(divId);
	}

}
