﻿function DisplayDefinition(img)
{
	var content = '<span class="webpartfont">' + img.longdesc + '<br /><br />';
	content = content + '<a href="/Public/Glossary.aspx" class="item" style="font-size:x-small">Click here for the full list...</a></span>';
	return overlib(content, BGCOLOR, '#D17E18', FGCOLOR, '#FFCC99', CAPTION, 'Glossary', STICKY, MOUSEOFF, CELLPAD, 5, CSSCLASS, CAPTIONFONTCLASS, 'glossaryHeaderFont', CLOSEFONTCLASS, 'glossaryCloseFont');
}

function RetrieveDefinition(target, term)
{			
	if (!target) return;
	
	var originalSrc = '/Images/save.gif';
	target.onload = DoNothing;
	target.src = '/Images/working.gif';			
	
	var xmlhttp = GetXmlHttpRequestObject();
  
  /* The callback function */
  xmlhttp.onreadystatechange = function() 
  {	    
		if (xmlhttp.readyState == 4) 
		{
			if (xmlhttp.status == 200)
			{
				//target.style='display:none';						
			
				var response = xmlhttp.responseXML.documentElement;	
						
				if(response)
				{						
					if(response.getElementsByTagName('Definition')[0])
					{
						target.longdesc = '<strong><i>' + term + '</i>:</strong> ' + response.getElementsByTagName('Definition')[0].firstChild.data;
						target.src = originalSrc;
						target.width=20;
					}
					else
					{						
						var terms = '<strong>Attention:</strong> Glossary term "<i>' + term + '</i>" has not been defined in the glossary.<br /><br />';
						
						if(response.getElementsByTagName('Term')[0])
						{
							terms = terms + 'Similar words include:<br />';
							for(var i=0; i<response.getElementsByTagName('Term').length; i++)
							{
								terms = terms + '&nbsp;&nbsp;- <i>' + response.getElementsByTagName('Term')[i].firstChild.data + '</i>';	
								
								if(i < response.getElementsByTagName('Term').length - 1)
									terms = terms + '<br />';
							}
						}
					
						target.longdesc = terms;
						target.src = originalSrc;
						target.width=20;
					}
				}
				else
				{
					target.longdesc = '<strong>Attention:</strong> Glossary term "<i>' + term + '</i>" has not been defined in the glossary.';
					target.src = originalSrc;
					target.width=20;					
				}
			}
      else
      {
				target.longdesc = '<strong>Attention:</strong> There is a problem with the glossary service. ' + xmlhttp.statusText;
				target.src = originalSrc;
				target.width=20;	
			}
    }
	}; 
	xmlhttp.open('POST', '/Public/RetrieveGlossary.aspx?Term=' + term + '&Rand=' + Math.random(), true);			

	/* Send the POST request */
	xmlhttp.setRequestHeader('Content-Type', 'text/xml');
	xmlhttp.send(null);
}	

function DoNothing()
{
}

function GetXmlHttpRequestObject()
{
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject)) 
	{
		try 
		{
			req = new XMLHttpRequest();
			if (req.overrideMimeType)
				req.overrideMimeType('text/xml');
		} 
		catch(e) 
		{
			req = false;
		}
	} 
	// branch for IE/Windows ActiveX version
	else if(window.ActiveXObject) 
	{
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) 
			{
				req = false;
			}
		}
	}
	
	return req;
}