//////////////////////////////////////////////////////
/////////////////// REWEB 2007 ///////////////////////
//////////////////////////////////////////////////////


function getVal(id){ return document.getElementById(id) }

// ------------------------------------------------
function proximoCampo(obj,next,tam)
{
	proximo = document.getElementById(next);
	if(document.getElementById(obj).value.length == tam)
		proximo.select();
}

// ------------------------------------------------
function limpaCampos(campo,padrao){
	
	var obj = document.getElementById(campo);
	obj.select();
	if (obj.value == padrao)
		obj.value = '';
	
}

// ------------------------------------------------
function restauraCampos(campo,padrao){
	
	var obj = document.getElementById(campo);
	if (obj.value == '')
		obj.value = padrao;
	
}

// ------------------------------------------------
function toggleDiv( element ) {
    var e = document.getElementById(element);

    if (e) {
        e.style.display = ((e.style.display != 'none') ? 'none' : 'block');
    }
}

// ------------------------------------------------
function showHelp(obj,restrict){
	el = document.getElementById(obj);
	
	if (el)
		el.style.display = ( (el.style.display != 'block') ? "block" : "none" )
	
	if (restrict != 'TRUE')
		el.parentNode.style.position = ( (el.style.position != 'relative') ? "relative" : "static" )
}


// ------------------------------------------------
function changeRadio(id,x,y){
	document.getElementById(x).innerHTML = "<img src='resources/images/img_radio_selected.gif'/>";
	document.getElementById(y).innerHTML = "<img src='resources/images/img_radio.gif'/>";
	document.getElementById(id).value = x;
}

// ------------------------------------------------

// item_clicado = "";
// ANSI, var 'declara' variável - o que é diferente de apenas setar valor (mesmo que ela ainda não exista)
var item_clicado = "";

function showDescript(disparador,alvo){
	
	var li_link = getVal(disparador);
	var li_desc = getVal(alvo);
	var ul 		= getVal('oportunidades');
	
	for (i=0; i < ul.childNodes.length; i++){
		if (ul.childNodes[i].className == 'selecionado'){ ul.childNodes[i].className = '' }
		if (ul.childNodes[i].className == 'descricao'){ ul.childNodes[i].style.display = 'none' }
	}
	
	if (item_clicado == disparador){
		li_link.className = '';
		li_desc.style.display = 'none';
		item_clicado = '';
	} else {
		li_link.className = 'selecionado';
		li_desc.style.display = 'block';
		item_clicado = disparador;
	}
	
	return false;
}


// ------------------------------------------------
// SIMULA INPUT 
// ------------------------------------------------
function simulaCampo(origem,destino){
	var obj  = getVal(origem);
	var alvo = getVal(destino);
	
	if (obj.value == 'DDD') { obj.value = '' }
	
	var intervalo = window.setInterval( function (){ alvo.innerHTML = obj.value },50 );
}

//-------------------------------------------------
function aplicabg(){
	// ANSI, var 'declara' variável - o que é diferente de apenas setar valor (mesmo que ela ainda não exista)
	var i = 0;
	
	if (document.forms){
		for (i=0;i<document.forms.length;i++) {
			for (j=0;j<document.forms[i].elements.length;j++) {
				
				elementoId = document.forms[i].elements[j].id;
				el = document.getElementById(elementoId);
				
				if (el.type != 'hidden'){
					span = 'sp_' + elementoId;
					document.getElementById(span).innerHTML = el.value;
				}
				
			}
		}
	}
	return(void(0));
	// ANSI - se é uma função, é previsto que haja um return..
}


/// ONLOAD CROSSBROWSER ///
//alert(document.getElementById + "\n" + navigator.appName + "!= \"Microsoft Internet Explorer\"");
//var echelom = "asdf";
// echelom = echelom * 3;
// alert(echelom::1);
 
if (document.getElementById & navigator.appName != "Netscape"){
	// MAIORIA DOS BROWSERS
	function onready(el, func){
	alert(el + "\n" + func); // added for testing
	
	    this.args = new Array(el, func)
	    this.doTry = function(){
	        try{
	            var el = eval(this.args[0]);
	            el.onloading = this.args[1];
	            el.onloading();
	            clearInterval(this.args[2]);
	
	        }
	        catch(e){}
	    }
	    this.doTry.bind = function(object){
	        var method = this;
	        return function(){
	            method.apply(object);
	        }
	    }
	    this.args[2] = setInterval(this.doTry.bind(this), 250);
	    return this; // ; added
	}
	new onready( "document.body", aplicabg )
}

else if (document.opera){
	// OPERA
	document.onload = aplicabg;
}

// M.F.O.S.Y