window.defaultStatus = "SGS - Sistema de Gerenciamento do Site";

function preenche(num, id)
{
	obj = document.getElementById(id);
	val = obj.value;
	fim = val + num;
	obj.value = "";
	obj.value = fim;
}

function testaSenha(senha,confirmacao,formulario)
{
	if (erro == true) 
		return true;
	obj1 = eval("document."+formulario+"."+senha);
	obj2 = eval("document."+formulario+"."+confirmacao);
	if (obj1.value != obj2.value)
	{
		alert ('Sua senha não foi confirmada!');
		document.formulario.senha.focus();
		return true;
	}
	else 
		return false;
}

function testaVazio(campo,comparacao,formulario,mensagem,erro) 
{
	if (erro == true)
		return true;
	obj1 = eval("document."+formulario+"."+campo);
	if (obj1.value == comparacao)
	{
		alert (mensagem);
		obj1.focus();
		return true;
	}
	else 
		return false;
}

function testaNumero(campo,formulario,mensagem,erro)
{
	if (erro == true)
		return true;
	obj1 = eval("document."+formulario+"."+campo);
	if (isNaN(obj1.value)) 
	{
		obj1.value = "";
		alert (mensagem);
		obj1.focus();
		return true;
	}
	else 
		return false;
}

function mostraConteudo(id_cont,  id_local)
{
	obj_cont = document.getElementById(id_cont);
	obj_local = document.getElementById(id_local);
	
	obj_local.innerHTML = obj_cont.innerHTML;
}

function verDados(valor, option)
{
	if(valor == "")
	{
		alert("Você deve escolher um valor válido!");
	}
	else if(valor == 0)
	{
		alert("Você deve escolher um valor, não uma categoria!");
	}
	else
	{
		document.location = "principal.php?m=" + option + "&action=ver&valor=" + valor	;
	}
}

function closeObj(id, method)
{
	obj = document.getElementById(id);
	
	if(method == 'display')
		obj.style.display = 'none';
	else
		obj.style.visibility = 'hidden';
	
}

function openObj(id, method)
{
	obj = document.getElementById(id);
	
	if(method == 'display')
		obj.style.display = 'block';
	else
		obj.style.visibility = 'visible';
	
}

function gerenciaAbas(abre,total)
{
    document.getElementById('aba').value = abre;
    
	for(x = 1; x <= total; x++)
	{
		document.getElementById('aba_bt_'+x).className = '';
		document.getElementById('abas_cad_'+x).style.display = 'none';
	}
	document.getElementById('aba_bt_'+abre).className = 'selected';
	document.getElementById('abas_cad_'+abre).style.display = 'block';

}

//USA JQUERY
function changeAba(pre,aba,total)
{
    for(x = 1; x <= total; x++)
	{
        $('#'+pre+'aba_'+x).removeClass('choose');
        $('#'+pre+'aba_'+x).addClass('aba');
        $('#'+pre+'div_'+x).hide();
    }
    $('#'+pre+'aba_'+aba).removeClass('aba');
    $('#'+pre+'aba_'+aba).addClass('choose');
    $('#'+pre+'div_'+aba).show();
}

var lastzoekstr = 'J29dWTNVQV8TugOoCaLplUHwWPTgbWE8';
function selectSearch(zoekstr, ListOfValues)
{
	zoekstr = zoekstr.toLowerCase();
	if (zoekstr != lastzoekstr && zoekstr != '')
	{
		lastzoekstr = zoekstr;
		var LOV = ListOfValues;
		var aantal = LOV.options.length;
		var gevonden = 0;

		for (var x = 0; x < aantal; x++)
		{
			var CurrentRecordIndex = LOV.options[x].value;
			var CurrentRecordText  = LOV.options[x].text;

			if ((zoekstr == '') || (CurrentRecordText.toLowerCase().indexOf(zoekstr) >= 0))
			{
					LOV.options[x].selected = true;
					LOV.options[x].style.display = 'block';
			} else {
					LOV.options[x].style.display = 'none';
			}
		}
	}
}

function resetaSelectSearch(ListOfValues)
{
	var LOV = ListOfValues;
	var aantal = LOV.options.length;
	var gevonden = 0;

	for (var x = 0; x < aantal; x++)
	{
		LOV.options[x].style.display = 'block';
	}
	LOV.options[0].selected = true;
}


function FormataValor(id,tammax,teclapres) {

    if(window.event) { // Internet Explorer
        var tecla = teclapres.keyCode;
    }
    else if(teclapres.which) { // Nestcape / firefox
        var tecla = teclapres.which;
    }


    vr = document.getElementById(id).value;
    vr = vr.toString().replace( "/", "" );
    vr = vr.toString().replace( "/", "" );
    vr = vr.toString().replace( ",", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    tam = vr.length;

    if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

    if (tecla == 8 ){ tam = tam - 1; }

    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
        if ( tam <= 2 ){
        document.getElementById(id).value = vr; }
        if ( (tam > 2) && (tam <= 5) ){
        document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 6) && (tam <= 8) ){
        document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 9) && (tam <= 11) ){
        document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 12) && (tam <= 14) ){
        document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 15) && (tam <= 17) ){
        document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
    }
}

function checkAll(pre,tot,che)
{
    if(che == true)
    {
        for(x = 0; x < tot; x++)
            document.getElementById(pre+x).checked = true;
    }
    else
    {
         for(x = 0; x < tot; x++)
            document.getElementById(pre+x).checked = false;
    }
}
function relogio() //usa jquery
{
    momentoAtual = new Date()
    hora = momentoAtual.getHours();
    minuto = momentoAtual.getMinutes();
    segundo = momentoAtual.getSeconds();
    hora = hora.toString();
    minuto = minuto.toString();
    segundo = segundo.toString();
    if(hora.length == 1) hora = '0' + hora;
    if(minuto.length == 1) minuto = '0' + minuto;
    if(segundo.length == 1) segundo = '0' + segundo;

    horaImprimivel = hora + ":" + minuto + ":" + segundo;

    $('#hr').html(horaImprimivel);
    setTimeout("relogio()",1000);
}

function alerta(msg,classe) // usa jquery
{
    $('#alerta').html(msg);
    $('#alerta').removeClass('error');
    $('#alerta').removeClass('ok');
    $('#alerta').addClass(classe);
    $('#alerta').slideDown();

    setTimeout("$('#alerta').slideUp();",2000);
}

function fechaSessao(obj)
{
    //alert(obj.location);
    //document.location = 'deslogar.php';
}