﻿var toolTipRequest = null;   
function tooltipRequestCallback(id, ajaxResponse)
{           
	return;
  var xmlDoc = ajaxResponse.responseXML;  			  			
 
  var title = xmlDoc.getElementsByTagName("Title")[0].firstChild.data;
  var content = xmlDoc.getElementsByTagName("Content")[0].firstChild.data;
      
  document.body.setAttribute("ToolTipTitle_" + id, title);
  document.body.setAttribute("ToolTipContent_" + id, content);
  document.body.setAttribute("ToolTipChecking_" + id, 'FALSE');
}
function sendTooltipRequest(pageName, id)
{	    
	return;
	document.body.setAttribute("ToolTipChecking_" + id, 'TRUE');
	this._showTimerId = null;
	var options = 
	      {
	        method:		'get',
	        asynchronous: true,
	        parameters: 	null,
	        onComplete: 	null
	      };
	
	options.onComplete = tooltipRequestCallback.bind(this, id);	
	options.parameters = "id=" + escape(id);
	
	try
	{
	    toolTipRequest = new Ajax.Request(_baseUrl + pageName, options);
	}
	catch (e) 
	{
	    vocusLog(e);
	}    
}

var _vocusToolTip = null;
function getTooltipContent(pageName, id)
{
	return;
  if (document.body.getAttribute("ToolTipContent_" + id) != null)
  {
  	return document.body.getAttribute("ToolTipContent_" + id);
	}
	else
	{
		if (document.body.getAttribute("ToolTipChecking_" + id) == null || document.body.getAttribute("ToolTipChecking_" + id) == 'FALSE')
			sendTooltipRequest(pageName, id);
		return null;
//    var xmlDoc = getAjaxXML(_baseUrl + pageName+"?id=" + escape(id));
//   
//    var title = xmlDoc.getElementsByTagName("Title")[0].firstChild.data;
//    var content = xmlDoc.getElementsByTagName("Content")[0].firstChild.data;
//        
//    document.body.setAttribute("ToolTipTitle_" + id, title);
//    document.body.setAttribute("ToolTipContent_" + id, content);
//    
//    return content;
	}
}
function getTooltipTitle(pageName, id)
{
	return;
  if (document.body.getAttribute("ToolTipTitle_" + id) != null)
  {
  	return document.body.getAttribute("ToolTipTitle_" + id);
	}
	else
	{
    var xmlDoc = getAjaxXML(_baseUrl + pageName+"?id=" + escape(id));
   
    var title = xmlDoc.getElementsByTagName("Title")[0].firstChild.data;
    var content = xmlDoc.getElementsByTagName("Content")[0].firstChild.data;
        
    document.body.setAttribute("ToolTipTitle_" + id, title);
    document.body.setAttribute("ToolTipContent_" + id, content);
    
    return title;
	}
}
var vocusTooltipId = null;
function hasAttribute(el, attr)
{
	var attributeNode = el.getAttributeNode(attr);
	if (attributeNode)
		if (attributeNode.specified)
			return true;
	return false;
}
function showToolTip(element, event, pageName, id, win)
{	
	if (typeof(isDocumentLoaded) != 'undefined' && !isDocumentLoaded)
		return;
	var delay = 1000;
	
	// for ajax tooltip
  //if (document.body.getAttribute("ToolTipTitle_" + id) != null)
	//	delay = 1000;
	
	var direction = '';
	
	var winWidth = GetWindowWidth();
	var winHeight = GetWindowHeight();
	mouseX = Event.pointerX(event);
	mouseY = Event.pointerY(event);
	
	if (mouseY > (winHeight/2))
	{
		if (mouseX > (winWidth/2))
			direction = 'northwest';
		else
			direction = 'northeast';
	}
	else
	{
		if (mouseX > (winWidth/2))
			direction = 'southwest';
		else
			direction = 'southeast';
	}
	//VocusHideAllTooltips();
	if (vocusTooltipId != null)
	{
		//domTT_deactivate(vocusTooltipId);
		//document.body.removeChild($(vocusTooltipId));
		//document.body.removeChild($('iframe'+vocusTooltipId));
	}
	var content = '';
	var caption = '';
	if (hasAttribute(element,'tooltiptitle'))
		caption = element.getAttribute('tooltiptitle');
	else
		caption = element.id;
		
	if (hasAttribute(element,'tooltipcontent'))
		content = element.getAttribute('tooltipcontent');
	else
		content = 'Default content for: '+element.id;
	
	vocusTooltipId = domTT_activate(element, event, 'content', content, 'trail', true, 'caption', caption, 'styleClass', 'Vocus'+direction, 'delay', delay, 'direction', direction, 'parent',document.body);

	// for ajax tooltip
	//vocusTooltipId = domTT_activate(element, event, 'content', getTooltipContent, 'trail', true, 'caption', getTooltipTitle, 'styleClass', 'Vocus'+direction, 'delay', delay, 'vocusPageName', pageName, 'vocusId', id, 'position', 'absolute', 'direction', direction, 'closeAction','destroy', 'parent',document.body);



//	if (VocusCurrentToolTips.indexOf(vocusTooltipId) == -1)
//	{
//		VocusCurrentToolTips[VocusCurrentToolTips.length] = vocusTooltipId;
//	}
	//vocusLog(vocusTooltipId, true);
	return true;  
}
function showStaticToolTip(element, event, content, inIFrame)
{	
	if (!domLib_useLibrary || (domTT_postponeActivation && !domTT_documentLoaded)) { return false; }
	if (inIFrame)
	{
		if (!window.parent.domLib_useLibrary || (window.parent.domTT_postponeActivation && !window.parent.domTT_documentLoaded))
		{
			return;
		}
	}
//	var direction = '';
//	
//	var winWidth = GetWindowWidth();
//	var winHeight = GetWindowHeight();
//	mouseX = Event.pointerX(event);
//	mouseY = Event.pointerY(event);
//	
//	if (mouseY > (winHeight/2))
//	{
//		if (mouseX > (winWidth/2))
//			direction = 'northwest';
//		else
//			direction = 'northeast';
//	}
//	else
//	{
//		if (mouseX > (winWidth/2))
//			direction = 'southwest';
//		else
//			direction = 'southeast';
//	}
	if (vocusTooltipId != null)
	{
		domTT_deactivate(vocusTooltipId);
	}
	var parentBody = null;
	if (inIFrame)
		parentBody = window.parent.document.body;
	else
		parentBody = document.body;
	vocusTooltipId = domTT_activate(element, event, 'content', content, 'trail', true, 'styleClass', 'Vocus', 'parent',parentBody, 'inframe', inIFrame);
	return true;  
}
var VocusCurrentToolTips = new Array();
function VocusHideAllTooltips()
{
	for(var i=0; i<VocusCurrentToolTips.length; i++)
	{
		domTT_deactivate(VocusCurrentToolTips[i]);
	}
}
function hideToolTip(element)
{
	domTT_deactivate(element.id); 
}
function hideGlobalTooltip()
{
	if (vocusTooltipId)
		domTT_deactivate(vocusTooltipId); 
}
function getAjaxXML(url)
{
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
    try {     
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
     try {       
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
      xmlhttp = false;
     }  
    }   
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
  	xmlhttp = new XMLHttpRequest();
  //if(xmlhttp.overrideMimeType) 
  //	xmlhttp.overrideMimeType('text');
  if(url != "")
  {
		xmlhttp.open("GET", url, false);
		xmlhttp.send(null);
		var str = xmlhttp.responseXML;
		return str;
  }
}
