Event.observe(window, 'load', menu_seg_location);

function menu_seg_location()
{
    menu_links = $$('#menu ul a');

    menu_links.each(function(a){
        
        var src = new RegExp("^"+a.readAttribute('href')+'(\/)?([0-9]+)?(\/)?([a-zA-Z0-9]+)?$');

        if(window.location.href.search(src) != -1)
        {
            a.addClassName('ativo');
        }
        
        if(a.up().hasClassName('submenu_normal') && window.location.href.search('/solutions/') != -1 )
        {
            a.addClassName('ativo');
        }
        
    });
//    $$('#lingua a').each(function(a){
        var src = new RegExp('\/pt\/');
        var src2 = new RegExp('\/es\/');
//console.log(window.location.href.search(src));
//console.log(a.readAttribute('href').search(src));
        if(window.location.href.search(src) != -1){
            $$('#lingua a').first().removeAttribute('href');
        }else if(window.location.href.search(src2) != -1){
            $$('#lingua a').last().removeAttribute('href');
        }
//    });
}

Event.observe(window, 'load', menus);

function menus(){

    var navegador = navigator.appName

    if (navegador == "Microsoft Internet Explorer"){
        navHoverIE();
    }else{
        navHover();
    }

}


//Menu Principal - IE
function navHoverIE() {

//    alert(navigator.appName);


    var lis = document.getElementById("navmenu").getElementsByTagName("LI");
    for (var i=0; i<lis.length; i++) {
        lis[i].onmouseover=function() {
            this.className+=" iehover";
        }
        lis[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" iehover\\b"), "");
            /*this.className= addClassName(this, " iehover");*/
        }
        lis[i].onclick=function() {
            if(this.firstChild.target == '_self') {
                window.location=this.firstChild.href;
            }
        }
    }
}

//Menu Principal - Outros Navegadores
function navHover() {

//    alert(navigator.appName);
    if(document.getElementById("navmenu") == null)
        return false;

    var lis = document.getElementById("navmenu").getElementsByTagName("LI");
    for (var i=0; i<lis.length; i++) {
//        lis[i].onmouseover=function() {
//            this.className+=" iehover";
//        }
//        lis[i].onmouseout=function() {
//            this.className=this.className.replace(new RegExp(" iehover\\b"), "");
//        }
        lis[i].onclick=function() {
            if(this.firstChild.target == '_self') {
                window.location=this.firstChild.href;
            }
        }
    }
}

// Limpa ao clicar no campo de busca
Event.observe(window, 'load', busca);
function busca()
{
    Event.observe(document.getElementById('txt_busca'), 'click',
        function(){
            if(this.defaultValue == this.value)
                this.value = '';
            else if(this.value == '')
                this.value = this.defaultValue;
        }
    );
}

function language(lang)
{
        window.location.href = window.location.href.replace(/\/(pt|en|es)\//, '/'+lang+'/');        
}