//Variável global para a function mostraDiv
var ultima = ""

//Function mostraDiv
//Função para mostrar uma determinada div
//Parâmetro: id - o id da div que deve ser exibida
function mostraDiv(id){    
    if(ultima.length > 0)
        escondeDiv(ultima);
    if(ultima != id){
        ultima = id;
    
        document.getElementById(id).style.display = 'block';
    }else{
        ultima = "";
    }
}

//Function escondeDiv
//Função para esconder uma determinada div
//Parâmetro: id - o id da div que deve ser escondida
function escondeDiv(id){
    document.getElementById(id).style.display = 'none';
}

//Function camposBusca
//Função para quando for preenchido o campo de busca retira o texto default, 
//quando não preenchido retorna o valor anterior
function camposBusca(){
    try{
        var elementos = document.getElementById("form").getElementsByTagName("input");
        var valoresCampo = new Array();
        
        for(x = 0; x < elementos.length; x++){
            if(elementos[x].type == "text"){  
                valoresCampo[x] = elementos[x].value;  
                      
                elementos[x].onfocus = function(){                                    
                    for(y = 0; y < elementos.length; y++){
                        if(elementos[y].value == valoresCampo[y])
                            elementos[y].value = "";
                    }
                }
                elementos[x].onblur = function(){
                    for(y = 0; y < elementos.length; y++){
                        if(elementos[y].value == "")
                            elementos[y].value = valoresCampo[y];                        
                    }            
                }    
            }
            
            if(elementos[x].type == "image"){
            
                elementos[x].onclick = function(){                    
                    for(y = 0; y < elementos.length; y++){
                        if(elementos[y].type == "text"){ 
                            if(elementos[y].value == valoresCampo[y])
                                elementos[y].value = "";
                        }
                    }                    
                }
            }
        }
    }catch(e){}
}

//Function marcaMenu
//Função para marcar o menu do topo e fazer efeito de over e out
function marcaMenu(){
    url = location.href;
    var marcado = "";
    var elementos = document.getElementById("menu").getElementsByTagName("a");        
    for(x = 0; x < elementos.length; x++){            
        if(url.indexOf(elementos[x].href) > - 1){
            
            elementos[x].firstChild.src = elementos[x].firstChild.src.substr(0, elementos[x].firstChild.src.lastIndexOf(".")) + "_over.gif";
            
            marcado = elementos[x].firstChild.src;
        }
        
        elementos[x].onmouseover = function(){					
		    if(this.firstChild.src != marcado)
			    over(this.firstChild);			
	    }
		
	    elementos[x].onmouseout = function(){			
		    if(this.firstChild.src != marcado)
			    out(this.firstChild)
	    }
    }                    
}  

//Function over
//Função de efeito de mouseover em imagens
//Parâmetro: qual - Sobre qual imagem irá chamar a função
function over(qual){
    imagesOver = qual.src;
    imagesOver = imagesOver.substr(0, imagesOver.lastIndexOf(".")) + "_over.gif";
    qual.src = imagesOver;
}

//Function out
//Função de efeito de mouseout em imagens
//Parâmetro: qual - Sobre qual imagem irá chamar a função
function out(qual){	
    images = qual.src;
    if(images.indexOf("_over") > -1)		
	    images = images.substr(0, images.lastIndexOf("_over")) + ".gif";
    qual.src = images;
}  

//Function callFunctions
//Função para chamadas de funções no load da página;
function callFunctions(){
    camposBusca();
    marcaMenu();
}

window.onload = callFunctions;

function HttpRequest()
{
	try{
		return new XMLHttpRequest();
	}catch(ee){
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				return false;
				alert('Não foi possível criar o objeto ajax.');
			}
		}
	}
}

function CarregarDadosAssincronos(url, callBack, parametro)
{
	var objAjax = HttpRequest();
	
	objAjax.onreadystatechange = function() 
	{
		if (objAjax.readyState == 4)
		{
			if(objAjax.status == 200)
			{
				callBack(objAjax.responseText, parametro);
			}
		}
	}
	
	objAjax.open("GET", url, true);
	objAjax.send(null)
}

function MarcarCombo(combo, valor)
{
	for(var i = 0; i < combo.options.length; i ++)
	{
		if(combo.options[i].value == valor)
		{
			combo.options[i].selected = true;
			break;
		}
	}
}
