/****
LISTAS
*****/
function ListaOn(obj){
	obj.style.backgroundColor = "#efefef";
}

function ListaOff(obj){
	obj.style.backgroundColor = "#f7f7f7";
}
/**********
FIM: LISTAS
**********/


/****
SETAS
*****/
function DivContent(n, num){
	obj = document.getElementById("linha"+n).style;
	if (obj.display =='block' ){
		obj.display ='none';
		document.getElementById("botao"+n).src = "imgs/botoes/seta_baixo.gif";
	}else{
		obj.display ='block'
		document.getElementById("botao"+n).src = "imgs/botoes/seta_cima.gif";
	}
	for(x=1;x<=num;x++){
		panel = document.getElementById("linha"+x).style;
		if(x!=n){
			panel.display='none';
			document.getElementById("botao"+x).src = "imgs/botoes/seta_baixo.gif";
		}
	}
}
/*********
FIM: SETAS
*********/



/****
POPUP
*****/
function OpenPopup(arq, width, height, scroll){    
 var URL = arq 
 var W = width 
 var H = height 
 var S = scroll 
 var Wpopupsize =(W/2); 
 var Hpopupsize =(H/2); 
 var CenterPopUpX = (screen.width/2)-(Wpopupsize); 
 var CenterPopUpY = (screen.height/2)-(Hpopupsize); 
 var pos = "left="+CenterPopUpX+",top="+CenterPopUpY; 
 var desktop = window.open( ""+URL, "_blank", "width="+W+",height="+H+",toolbar=no,location=no,status=no,menubar=no,scrollbars="+S+",resizable=no,"+pos); 
} 
/*********
FIM: POPUP
**********/


/********
// EDITAR
*********/
function editar(nn, atual, id, nome_campo, pagina) {
 elem = document.getElementById(nome_campo + nn);
 elem.innerHTML = "<input class=input maxlength=\"255\"type=\"text\" value=\"" + atual.innerHTML + "\" size=\"60\" onkeypress=\"return enter(this, event," + nn + "," + id +", '"+ nome_campo + "', '"+ pagina + "')\" onblur=\"return semfoco(this," + nn + "," + id +", '"+ nome_campo + "', '"+ pagina + "')\" />";
 elem.firstChild.focus();
}

function enter(campo, evt, idfld, id, nome_campo, pagina) {
 evt = (evt) ? evt : window.event;
 if (evt.keyCode == 13) {
  elem = document.getElementById(nome_campo + idfld);
  AjaxLink("conteudo/"+pagina+"?id="+id+"&value="+campo.value+"&campo="+nome_campo, "edit")
  elem.innerHTML = "<span onclick=\" editar(" + idfld + ", this," + id +", '"+ nome_campo + "', '"+ pagina + "');\">" + campo.value + "</span>";
  return false;
 }else{
   return true;
 }
}

function semfoco(campo, idfld, id, nome_campo, pagina) {
 if (campo.value!="") {
  elem = document.getElementById(nome_campo + idfld);
  //Ajax("usuarios/"+pagina+"", "conteudo")
  elem.innerHTML = "<span onclick=\" editar(" + idfld + ", this," + id +", '"+ nome_campo + "', '"+ pagina + "');\">"+ campo.value + "</span>";
  return false;
 }
	else{
	 alert('O preenchimento do campo é obrigatório.')
		return false;
	}
}
/*************
// FIM: EDITAR
*************/


/***
ABAS
****/
function Aba(n, qtde){
 for(x=1;x<=qtde;x++){
  tab=eval('document.all.tab' + x + ';');
	 panel=eval('document.all.panel' + x + '.style;');
  if(x==n){
   tab.className='tabOn';
   panel.display='';
  }else {
   tab.className='tab';
	  panel.display='none';
  }
 }
}
/********
FIM: ABAS
********/


/***
ABAS
****/
function abas(n, qtde){
 for(x=1;x<=qtde;x++){
  aba = eval('document.getElementById("aba' + x + '");');
		aba_cont = eval('document.getElementById("aba_cont' + x + '").style;');
  if(x==n){
   aba.className = 'current';
			aba_cont.display = '';
  }else {
   aba.className = '';
			aba_cont.display = 'none';
  }
 }
}
/********
FIM: ABAS
********/


/************
FORMATA VALOR
************/
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
 var sep = 0;
 var key = '';
 var i = j = 0;
 var len = len2 = 0;
 var strCheck = '0123456789';
 var aux = aux2 = '';
 var whichCode = (window.Event) ? e.which : e.keyCode;
 if (whichCode == 13) return true;
 key = String.fromCharCode(whichCode); // Valor para o código da Chave
 if (strCheck.indexOf(key) == -1) return false; // Chave inválida
 len = objTextBox.value.length;
 for(i = 0; i < len; i++)
     if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
 aux = '';
 for(; i < len; i++)
     if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
 aux += key;
 len = aux.length;
 if (len == 0) objTextBox.value = '';
 if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
 if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
 if (len > 2) {
     aux2 = '';
     for (j = 0, i = len - 3; i >= 0; i--) {
         if (j == 3) {
             aux2 += SeparadorMilesimo;
             j = 0;
         }
         aux2 += aux.charAt(i);
         j++;
     }
     objTextBox.value = '';
     len2 = aux2.length;
     for (i = len2 - 1; i >= 0; i--)
     objTextBox.value += aux2.charAt(i);
     objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
 }
 return false;
}
/*****************
FIM: FORMATA VALOR
*****************/ 


/*****
LAYERS
******/ 
function AL(sId){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
 sDiv.style.display = "block";
 clearInterval(num);
 }
 ,100)
}

function FL(sId){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
 sDiv.style.display = "none";
 clearInterval(num);
 }
 ,100)
}
/*********
FIM: LAYER
**********/ 


/******************/
// SOMENTE NÚMEROS
/******************/
function CampoNumerico(e,id_element){
	var key
	if(window.event) {
		key = e.keyCode; 
		if (( key < 47 )||( key > 58 )) {
			window.event.returnValue = null; 
			return;
		}		
	}
	else if (e.which) {
		key = e.which;
		if (( key < 47 )||( key > 58 )) {
			e.preventDefault();
			return ; 
		}		
	}
}
/**********************/
// FIM: SOMENTE NÚMEROS
/**********************/
