var ie4=document.all;
var ns6=document.getElementById&&!document.all;

timer = 5000;
objDropDownItem = new Object;
objDropDownItem="";
intOpacity = 100;


function fnSwitchMenu(objSwitch, strMode, blnTimeout)
{
  try
  {
  if ((objDropDownItem!="")&&(objDropDownItem!=objSwitch))
    fnRemoveMenu();
  
  fnFindBrowserStyle(document.getElementById(objSwitch)).display=strMode;
  if (objDropDownItem!="") changeOpacity(100, objDropDownItem);
  intOpacity = 100;
  
  if (blnTimeout)
    objDropDownItem="";
  else
    clearTimeout(timer);
  
  objDropDownItem = objSwitch;  
  }
  catch(e)
  {
  }
}


function fadeMenu()
{
  
  intOpacity-=10;   
  
  changeOpacity(intOpacity, objDropDownItem);
  
  if (intOpacity <= 0)
    fnRemoveMenu();    
  else
    timer=setTimeout('fadeMenu()', 50);
}

function changeOpacity(newOpacity, objObject)
{
    if (ie4)
        fnFindBrowserStyle(document.getElementById(objObject)).filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+newOpacity+")"
    else
    {
        fnFindBrowserStyle(document.getElementById(objObject)).KhtmlOpacity = (newOpacity/100);
    	fnFindBrowserStyle(document.getElementById(objObject)).MozOpacity = (newOpacity/100);
    }  
}

function fnRemoveMenu()
{
  fnFindBrowserStyle(document.getElementById(objDropDownItem)).display="none";
  changeOpacity(100, objDropDownItem);
  intOpacity = 100;
}

function xmlInit()
{
  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();
}


function AJAXRequest(Filename, CallbackFunction)
{
  xmlInit();
  xmlhttp.open("GET", Filename, true);
  xmlhttp.onreadystatechange=CallbackFunction;
  xmlhttp.send(null)
}


function InitAJAXDropDown(Filename, TextBoxValue, TextBoxIdent, DropDownIdent, AllowMulti)
{
	Suggestion = GetLastSuggestion(TextBoxValue, AllowMulti);
	
	if (Suggestion=="")
	  fnFindBrowserStyle(document.getElementById(DropDownIdent)).display="none";
	else
	{
      DropMenu = DropDownIdent;
	  DropMenuMulti = AllowMulti;
	  DropTextBoxId = TextBoxIdent;
	  
	  document.getElementById(DropMenu).innerHTML = "Fetching suggestions...";	  
	  fnFindBrowserStyle(document.getElementById(DropDownIdent)).display="block";
	  AJAXRequest(Filename+"&sug="+Suggestion, cb_FeedDropMenu);
	}
}

function MessageSuggest(parent_id, Pseudonym)
{
	if (DropMenuMulti)
	{
		if (document.getElementById(DropTextBoxId).value.lastIndexOf(';') >= 0)
			document.getElementById(DropTextBoxId).value = document.getElementById(DropTextBoxId).value.substr(0, document.getElementById(DropTextBoxId).value.lastIndexOf(';')) + "; "+Pseudonym+"; ";
		else 
			document.getElementById(DropTextBoxId).value = Pseudonym+"; ";
	}
	else
  		document.getElementById(DropTextBoxId).value = Pseudonym;
		
	fnFindBrowserStyle(document.getElementById(DropMenu)).display="none";
	document.getElementById(DropTextBoxId).focus();
}


function cb_FeedDropMenu()
{
	if (xmlhttp.readyState==4) // Ensure it only attempts to populate details on success.
	{
	  Results = xmlhttp.responseText;
	  
	  if (Results=="")
	  {
		 fnFindBrowserStyle(document.getElementById(DropMenu)).display="none";
	  }
	  else
	  {
	  	document.getElementById(DropMenu).innerHTML = Results;
	  	fnFindBrowserStyle(document.getElementById(DropMenu)).display="block";
	  }
	}
}


function GetLastSuggestion(TextBoxValue, AllowMulti)
{
  if ((AllowMulti) && (TextBoxValue.indexOf(";") >= 0))
  {
	arrSuggestions = TextBoxValue.split(";");
	return (TrimString(arrSuggestions[arrSuggestions.length-1]));
  }
  else
    return (TrimString(TextBoxValue));
}

function TrimString(strVal)
{
	while (strVal.substring(0,1) == ' ')
		strVal = strVal.substring(1, strVal.length);
	while (strVal.substring(strVal.length-1, strVal.length) == ' ')
		strVal = strVal.substring(0,strVal.length-1);
		
	return strVal;
}

function highlightMenu(menuId)
{  document.getElementById(menuId).className="menOver";	 }

function unHighlightMenu(menuId)
{  document.getElementById(menuId).className="";  }

function fnFindBrowserStyle(objIdent)
{ return ((ie4||ns6) ? objIdent.style : objIdent); }