var menuoff = 0;
var menutime = 200;

var GB_ROOT_DIR = location.href.substring(0, location.href.lastIndexOf('/')) + '/_box/';

function GE(objid){ return document.getElementById(objid); }

function setClassName(obj, cssClass)
{
    obj.className = cssClass;
}

function setInnerHTML(id, str) {
	if (document.getElementById(id)) {
		document.getElementById(id).innerHTML = str;
	} else if (document.all[id]) {
		document.all[id].innerHTML = str;
	}
}

function getInnerHTML(id) {
	if (document.getElementById(id)) {
		return document.getElementById(id).innerHTML;
	} else if (document.all[id]) {
		return document.all[id].innerHTML;
	}
}

function swpText(num){
	if(GE("itxt"+num).style.display == ""){
		GE("itxt"+num).style.display = "none";
	}else{
		GE("itxt"+num).style.display = "";
	}
}

function popUp(x,w,h) {
	var l = ( (window.screen.width  - w) / 2 );
	var t = ( (window.screen.height - h) / 2 );
	newWindow = window.open(x,'fundo','leftmargin=0,topmargin=0,marginheight=0,marginwidth=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
	newWindow.focus();
}

function goTo(url){
	window.location.href = url;
}

function menuOver(num){
	habilitarSelect(false);
	var i = 0;
	for(i=1;i<=7;i++){
		GE("menu" +i).src = "_img/menu/menu_"+i+".gif";
		if(i <= 5) GE("submenu"+i).style.display = 'none';
	}
	GE("menu" +num).src = "_img/menu/menu_"+num+"_on.gif";
	if(num == 6) num = 3;
	if (GE("submenu"+num)) GE("submenu"+num).style.display = '';
	if(menuoff)	clearInterval(menuoff);
}

function menuOut(num){
	menuoff = self.setInterval('menuGoOff('+num+')', menutime);
}

function menuGoOff(num){
	habilitarSelect(true);
	GE("menu" +num).src = "_img/menu/menu_"+num+".gif";
	if(num == 6) num = 3;
	if (GE("submenu"+num)) GE("submenu"+num).style.display = 'none';
	if(menuoff)	clearInterval(menuoff);
}

function submenuOver(obj){
	obj.className = "submenuItemOver";
	if(menuoff)	clearInterval(menuoff);
}

function submenuOut(num, obj){
	obj.className = "submenuItem";
	menuOut(num, GE("menu"+num).name);
}

var v_obj;

function mascara(o,f){
    v_obj=o
    setTimeout("execmascara()",1)
}

function execmascara(o,f){
    v_obj.value=cpf(v_obj.value)
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function FormSelect(id, valor){ 
	if(valor == "")
		valor = 0;

	var ate = GE(id).length;

    for(j=0; j < ate; j++){
       if(GE(id).options[j].value == valor){ 
            GE(id).options[j].selected = true;
			return;
       }
    }
    
    return;
} 

function habilitarSelect(ParamAcao)
{
	if (document.getElementsByTagName)
	{
		var a = (ParamAcao)? 'visible' : 'hidden';
		var s = document.getElementsByTagName("select");
		if (s.length > 0)
		{
			window.select_current = new Array();
			for (var i=0, select; select = s[i]; i++)
			{
				select.style.visibility = a;
			}
		}
	}
}

function GetRadioSelectedValue(ParamCampo)
{
	var valor = '';
	
	if (!ParamCampo.length && ParamCampo.checked)
		return ParamCampo.value;

	for (i = 0; i < ParamCampo.length; i++)
	{
		if (ParamCampo[i].checked)
			valor = ParamCampo[i].value
	}
	
	return valor;
}
