////////////////////////////////////////  AJAX  - GLOBAL VARIABLES ////////////////////////////////////////////////////////////
	this.requestURL;    //PARAMETERIZAR
	this.divName;  //PARAMETERIZAR
	this.txtName; //PARAMETERIZAR
	this.tagList; //PARAMETERIZAR
	this.IntTop; //PARAMETERIZAR
	
	this.txtSearch;
	this.mnSelMenuItem = 0; //INDICE DO MENU
	
	var xmlHttp; 
	var gReq=null;
	var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
	var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
	var is_opera = ((navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
	//netscape, safari, mozilla
	var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////// AJAX - FUNCTIONS ///////////////////////////////////////////////////////////
function InitAll(requestURL,divName,txtName,tagList,top)
{
	this.requestURL  = requestURL;
	this.divName = divName;
	this.txtName = txtName;
	this.tagList = tagList;
	this.IntTop = top - 0;	
}

function show_data(strQueryString)
{ 
	var divAjax = GetIDAjax();
	this.txtSearch = strQueryString;
	
	if (strQueryString.length > 0 && IsEventSearch())
	{ 
		var url = requestURL +  encodeURI(strQueryString); 
		
		xmlHttp = GetXmlHttpObject(stateChangeHandler); 

		xmlHttp_Get(xmlHttp, url); 
	} 
	else if(IsKeyMove())
	{
		KeyboardAction();
	}
	else 
	{ 
		SetIDAjax(''); 
	} 
} 

function stateChangeHandler() 
{ 
	var divAjax = GetIDAjax();
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{ 
		var str = xmlHttp.responseText;

		if (str != "")
		{
			SetIDAjax(doHighlight(str,txtSearch));

			HideMenuDiv(divAjax,str);
			SelectFirstItem();	
			//textboxSelect(GetIDTextBox(), txtSearch.length, GetLengthMenuItemDivID(GetMenuItemDiv(this.mnSelMenuItem)));
		}
		else
		{
			HideMenuDiv(divAjax,str);
		}
	} 
} 
function xmlHttp_Get(xmlhttp, url)
{ 
	xmlhttp.open('GET', url, true); 
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(null); 
} 

function GetXmlHttpObject(handler) 
{ 
	var objXmlHttp = null;   

	if (is_ie)
	{ 
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
		
		try
		{ 
			objXmlHttp = new ActiveXObject(strObjName);
			objXmlHttp.onreadystatechange = handler; 
		} 
		catch(e)
		{ 
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
			return; 
		} 
	} 
	else if (is_opera)
	{ 
		alert('Opera detected. The page may not behave as expected.'); 
		return; 
	} 
	else
	{ 
		// Mozilla | Netscape | Safari 
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload = handler; 
		objXmlHttp.onerror = handler; 
	} 
	
	return objXmlHttp; 
} 

//////////////////////////////////////////// AJAX - FUNCTIONS AUX ///////////////////////////////////////////////////////////
//////////////////////////////////////////// AJAX - FUNCTIONS EVENTS ///////////////////////////////////////////////////////////
function IsEventSearch()
{
	e = window.event; 

	if (e.keyCode) 
	{
		code = e.keyCode;
		
		if (!(code < 32 || (code >= 33 && code <= 46) || (code >= 112 && code <= 123)))
		{
			return true;
		}
		else if (code == 8 )
		{
			return true;
		}
		else 
		{
			return false;
		}
		
	}
}
function IsKeyMove()
{
	e = window.event; 
	
	switch(e.keyCode)
	{
		case 38:
			return true;
			break;

		case 40:
			return true;
			break;
			
		case 13:
			return true;
			break;
			
		case 9:
			return true;
			break;
			
		default:
			return false;
			break;
	}
}
function KeyboardAction()
{
	e = window.event; 
	
	switch(e.keyCode)
	{
		case 38:
			MoveUp();
			break;

		case 40:
			MoveDown();
			break;
	}
}
function KeyboardEnter()
{
	e = window.event; 
	
	switch(e.keyCode)
	{
		case 13:
			SelectItemByKeyBoard();
			return false;
			break;
			
		case 9:
			SelectItemByKeyBoard();
			return false;
			break;
	}
}
function MoveDown()
{
	var nMenuItem;
	nMenuItem = this.mnSelMenuItem + 1;
	
	if(nMenuItem != 0)
	{
		SelectMenuItem(nMenuItem);
	}
}
function MoveUp()
{
	var nMenuItem;
	nMenuItem = this.mnSelMenuItem - 1;
	
	if(nMenuItem != -1 )
	{
		SelectMenuItem(nMenuItem);
	}
}
function onMouseOver()
{
	for(i = 0; i< IntTop; i++)
	{
		var item = GetMenuItemDiv(i);
		if(item != null)
		{
			item.className =""
		}
	}
	this.mnSelMenuItem=0;
}
function onMouseOut()
{
	for(i = 0; i< IntTop; i++)
	{
		var item = GetMenuItemDiv(i);
		if(item != null)
		{
			item.className =""
		}
	}
	this.mnSelMenuItem=0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////// AJAX - FUNCTIONS GET's AND SET's ///////////////////////////////////////////////
function GetIDAjax()
{
	return document.getElementById(divName);
}
function SetIDAjax(txt)
{
	var div =  document.getElementById(divName);
	div.innerHTML = txt;
}
function GetIDTextBox()
{
	return document.getElementById(txtName);
}
function SetIDTextBox(txt)
{
	var TextBox =  document.getElementById(txtName);
	TextBox.value = txt;
}
function GetSelMenuItemDiv()
{
	return GetMenuItemDiv(this.mnSelMenuItem);
}
function GetMenuItemDivID(nMenuItem)
{
	return (tagList + nMenuItem);
}
function GetMenuItemDiv(nMenuItem)
{
	var sDivMenuItemID=GetMenuItemDivID(nMenuItem);
	return document.getElementById(sDivMenuItemID);
}
function SelectTextBox(id)
{
	var CAE = document.getElementById(id);
	document.getElementById(txtName).value = SplitCAE(CAE.innerText);
}

function SelectTextBoxOnClix(id)
{
	var CAE = document.getElementById(id);
	document.getElementById(txtName).value= SplitCAE(CAE.innerText);
	HideMenu(divName);
}
function GetLengthMenuItemDivID(id)
{
	var Actividade = SplitCAE(id.innerText);
	return Actividade.length;
}
function SelectItemByKeyBoard()
{
	for(i = 0; i< IntTop; i++)
	{
		var item = GetMenuItemDiv(i);
		
		if(item != null)
		{
			if(item.className == "divAJAXListScroll")
			{
				SelectTextBoxOnClix(GetMenuItemDivID(i));
				return;
			}
		}
		else
		{
			return;
		}
	}

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////// AJAX - FUNCTIONS AUX //////////////////////////////////////////////////////////
function SplitCAE(text)
{
	var Actividade = text.split(" | ");
	return Actividade[1];
}
function HideMenuDiv(divAjax,str)
{
	if(str != "")
	{
		divAjax.className = "divAJAXList";
	}
	else
	{
		divAjax.className = "divAJAXListOff";
		this.mnSelMenuItem=0;
	}	
}
function HideMenu(divName)
{
	var divAjax = GetIDAjax(divName);
	divAjax.className = "divAJAXListOff";
	this.mnSelMenuItem=0;
}
function SelectFirstItem()
{
	//SelectTextBox(tagList + this.mnSelMenuItem);
	var divMenuItem= GetMenuItemDiv(this.mnSelMenuItem);
	divMenuItem.className="divAJAXListScroll";
}

function SelectMenuItem(nMenuItem)
	{
		var divMenuItem = GetMenuItemDiv(nMenuItem);
		
		if(divMenuItem)
		{
			if (nMenuItem != this.mnSelMenuItem)
			{
				UnselectMenuItem();
				
				this.mnSelMenuItem = nMenuItem;
				
				//SelectTextBox(tagList + nMenuItem);
						
				divMenuItem.className = "divAJAXListScroll";
			}
			
			//textboxSelect(GetIDTextBox(), txtSearch.length, GetLengthMenuItemDivID(GetMenuItemDiv(this.mnSelMenuItem)));
		}
	}
function UnselectMenuItem()
	{
		var divMenuItem = this.GetSelMenuItemDiv()
	
		if(divMenuItem)
		{
			divMenuItem.className = "";
		}
	}

function textboxSelect(oTextbox, iStart, iEnd) { 

   switch(arguments.length) { 
       case 1: 
           oTextbox.select(); 
           break; 

       case 2: 
           iEnd = oTextbox.value.length;
       case 3:          
           //if (isIE) { 
               var oRange = oTextbox.createTextRange(); 
               oRange.moveStart("character", iStart); 
               oRange.moveEnd("character", - oTextbox.value.length + iEnd);      
               oRange.select();                                              
           //} else if (isMoz){ 
            //   oTextbox.setSelectionRange(iStart, iEnd); 
           //}                     
   } 
   oTextbox.focus();  
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




  




