﻿function itemSelected(source, ev) {
    var index = source._selectIndex;
    if (index >= 0)
    {
        var valor = source.get_completionList().childNodes[index]._value;
        source.get_element().value = valor;
    }
}

function RetiraAcentos(txt) {
    var Acentos = "áàãââÁÀÃÂéêÉÊíÍóõôÓÔÕúüÚÜçÇabcdefghijklmnopqrstuvxwyz";
    var Traducao ="aaaaaAAAAeeEEiIoooOOOuuUUcCABCDEFGHIJKLMNOPQRSTUVXWYZ";
    var Posic, Carac;
    var TempLog = "";
    var value = txt.toUpperCase();

    for (var i=0; i < txt.length; i++) {
        
        Carac = value.charAt(i);
        Posic = Acentos.indexOf(Carac);

        if (Posic > -1)
            TempLog += Traducao.charAt(Posic);
        else
            TempLog += value.charAt(i);
    }

    return TempLog;
}

function ClientPopulated(source, eventArgs) {
    if (source._currentPrefix != null) {        
        var list = source.get_completionList();
        var search = source._currentPrefix.toLowerCase();
        
        for (var i = 0; i < list.childNodes.length; i++) {
            
            var text = list.childNodes[i].innerHTML; 
            var index = RetiraAcentos(text).toLowerCase().indexOf(RetiraAcentos(search).toLowerCase());

            if (index != -1) {
                var value = text.substring(0, index);
                value += '<b>';
                value += text.substr(index, search.length);
                value += '</b>';
                value += text.substring(index + search.length);
                list.childNodes[i].innerHTML = value;
            }
        }
    }
} 


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
var iefix = (version == 6);


function CriaIframe(list){
    if(!iefix) return    
    var oSpan = list.parentNode;            
    var ifr = GetChildObj(oSpan,"IFRAME");            
    if(ifr) oSpan.removeChild(ifr);  
    ifr = document.createElement("IFRAME");            
    oSpan.appendChild(ifr);  
            
    ifr.style.display = "block";            
    ifr.style.position = "absolute";            
    ifr.style.width = list.style.width;            
    ifr.style.height = list.offsetHeight;            
    ifr.style.left = list.style.left;            
    ifr.style.top = list.style.top;
    ifr.style.zIndex = 98;
}

function ClientHiding(sender,args) {            
	if(!iefix)return    
	//ie6 only            
	var oList = sender.get_completionList();            
	var oSpan = oList.parentNode;            
	var ifr = GetChildObj(oSpan,"IFRAME");            
	if(ifr) oSpan.removeChild(ifr);        
}        

function GetChildObj(oCont,tag) {            
	for(var i = 0; i < oCont.childNodes.length; i++){       
        if(oCont.childNodes[i].tagName == tag)                    
	    return oCont.childNodes[i];            
	}
	return false;        
}

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();