function $(obj) {
	return document.getElementById(obj);
}
function abrir(url, width, height)
{
var lado = (screen.width - width) / 2;
var topo = (screen.height - height) / 2;
window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}

function abrirnb(url, width, height)
{
var lado = (screen.width - width) / 2;
var topo = (screen.height - height) / 2;
window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}

function criaMascara(_RefObjeto, _Modelo){

 var valorAtual = _RefObjeto.value;        
 var valorNumerico = '';
 var nIndexModelo = 0;
 var nIndexString = 0;
 var valorFinal = '';
 var adicionarValor = true;
    
     
 // limpa a string valor atual para verificar 
 // se todos os caracteres são números
 for (i=0;i<_Modelo.length;i++){
  if (_Modelo.substr(i,1) != '#'){
	valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
  }
 }
      
 // verifica se todos os caracteres são números
 for (i=0;i<valorAtual.length;i++){
  if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
	valorNumerico = valorNumerico + valorAtual.substr(i,1);
  }
 }
      
 // aplica a máscara ao campo informado usando
 // o modelo de máscara informado no script
 for (i=0;i<_Modelo.length;i++){
  if (_Modelo.substr(i,1) == '#'){
    if (valorNumerico.substr(nIndexModelo,1) != ''){
	valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
	nIndexModelo++;nIndexString++;
    } 
    else {
        adicionarValor = false;
    }
  }
  else {
     if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
  	valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
	nIndexString++;
     }
  }
 }
    
 //alert(valorFinal)
 _RefObjeto.value = valorFinal 

}

function apagar(p,codigo,pag)
{
 var resp=confirm("Você tem certeza que deseja excluir este registro?") 
 if(resp){
   window.location="admin.asp?pag="+pag+"&id=5&p="+p+"&cd"+p+"="+codigo;
 } 
}

function FormataValor(campo,tammax,teclapres)
{

    var tecla = teclapres.keyCode;
    vr = campo.value;
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( ",", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.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 ){
             campo.value = vr; }
         if ( (tam > 2) && (tam <= 5) ){
             campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 6) && (tam <= 8) ){
             campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 9) && (tam <= 11) ){
             campo.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) ){
             campo.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) ){
             campo.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 );}
    }            
}


var anterior = '';
var num = 0;

function abrirsubmenu(camada){
	if (num != 0){
		document.getElementById(anterior).style.display = 'none';
	}
	if(anterior != camada){
		document.getElementById(camada).style.display = 'block';
		anterior = camada;
		num = 1;
	}else{
		anterior = '';
		num = 0;
	}
 return false;
}


function soNums(e,args)
{        
//  onKeyPress ="return (soNums(event,'(/){,}.'));"
   var valid_chars    = new Array();
   if (document.all){var evt=event.keyCode;}
   else{var evt = e.charCode;}
   var chr= String.fromCharCode(evt);
   if (evt <20 || (evt >47 && evt<58) || (args.indexOf(chr)>-1 ) ){return true;}
   return false;
} 


function gerarswf(arquivo,largura,altura,id){
    document.writeln('    <object id="globalnav-object" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + largura + '" height="' + altura + '" id="' + id + '" name="' + id + '">');
    document.writeln('        <param name="movie" value="' + arquivo + '" />');
    document.writeln('        <param name="FlashVars" value="loc=en_US&htmlApp=false&gatewayURL=gwurl" />');
    document.writeln('        <param name="menu" value="false" />');
    document.writeln('        <param name="quality" value="high" />');
    document.writeln('        <param name="salign" value="tl" />');
	document.writeln('        <param name="scale" value="noscale" />');
    document.writeln('        <param name="wmode" value="transparent" />');
    document.writeln('        <embed id="globalnav-embed" src="' + arquivo + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="loc=en_US&htmlApp=false&gatewayURL=gwurl" bgcolor="#ffffff" menu="false" quality="high" salign="tl" scale="noscale" id="' + id + '" width="' + largura + '" height="' + altura + '"></embed>');
    document.writeln('    </object>');
}


function ContaCaracteres(tamanho,form,campo,camporetorno){
   	var campo = document.forms[form].elements[campo];
	intCaracteres = tamanho - campo.value.length;
	if (camporetorno.length > 0){
		document.forms[form].elements[camporetorno].value = intCaracteres ;
	}
	if (intCaracteres > 0){
	      	return true;
	}
	else {
		campo.value = campo.value.substr(0,tamanho);
		return false;
	}
}