/***************/
// ACESSO RÁPIDO
/***************/
var ns = document.layers;
var ie = document.all;
var ns6 = (document.getElementById && !document.all);
var div_Move;
var pos_inicial = 110;
var lastScrollY = 0;
var body_central;

function SetaDivMove()
{
	if(ie) 
	{
		div_Move = document.all['ar'].style;
		body_central = document.all['central'].style;
	}
	else if(ns)
	{
		div_Move = document.ar;
		body_central = document.central;
	}
	else if(ns6)
	{
		div_Move = document.getElementById('ar').style;
		body_central = document.getElementById('central').style;
	}
	EventoScrol();
	
	if(screen.width <= 640)
	{
		body_central.overflow='auto';
	}
}

function EventoScrol()
{
	var percent;
	
	if(document.body.scrollTop != lastScrollY && document.body.scrollTop < 480) 
	{
		
		percent = .3 * (document.body.scrollTop - lastScrollY);
	
		if(percent > 0) 
		{
			percent = Math.ceil(percent);
		}
		else 
		{
			percent = Math.floor(percent);
		}
		if(ie) 
		{
			if (pos_inicial > 471){
			pos_inicial = 471;	
			}
			pos_inicial += percent; 
			div_Move.pixelTop = pos_inicial+110	;
		}
		if(ns) 
		{			
			div_Move.top = div_Move.top + percent;
		}
		if(ns6)
		{
			if (pos_inicial > 413){
			pos_inicial = 413;	
			}
			pos_inicial += percent;
			div_Move.top = pos_inicial;
		}		
		lastScrollY = lastScrollY + percent;
	}
	setTimeout('EventoScrol()',50);
} 
/********************/
// FIM: ACESSO RÁPIDO
/********************/



/**************/
// COR DA LINHA
/**************/
function CorMenu(id, cor) {
 var id = document.getElementById(id);
 id.style.backgroundColor = cor;
}
/******************/
// FIM: COR DA LINHA
/******************/


/********/
// LAYERS
/********/
function AFL(sId, sBotao){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
	var botao = document.getElementById(sBotao)
 if(sDiv.style.display == "none"){
  sDiv.style.display = "block";
		botao.src = "imgs/botoes/bt_menos_vm.gif"
 }else{
  sDiv.style.display = "none";
		botao.src = "imgs/botoes/bt_mais_vm.gif"
 }
 clearInterval(num);
 }
 ,100)
}

function AFL2(sId){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
 if(sDiv.style.display == "none"){
  sDiv.style.display = "block";
 }else{
  sDiv.style.display = "none";
 }
 clearInterval(num);
 }
 ,100)
}

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
/**********************/


/************/
// PULA CAMPO
/************/
function PulaCampo(v1,v2,prox){
	var tam = v1.length;
	var maximo = v2;
		if(tam == maximo){
			eval("document.forms[0]."+prox+".focus();")
		}
}
/**********************/
// FIM: SOMENTE NÚMEROS
/**********************/


/*****************/
// VALIDA CNPJ/CPF
/****************/
function ValidaCNPJ(s){
	var i;
	if (s.length > 14) {
		if (s.substr(0,1) == 0){
			var c = s.substr(1,12);
			var dv = s.substr(13,2);
		}
		else{
			var c = s.substr(0,12);
			var dv = s.substr(12,2);
		}
	} else {
		var c = s.substr(0,12);
		var dv = s.substr(12,2);
	}
	var d1 = 0;
	if (s.length < 14) {
		alert('- CNPJ inválido!');
		return false;
	}
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		alert('- CNPJ inválido!');
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		alert('- CNPJ inválido!');		
		return false;
	}
	return true;
}


function ValidaCPF(s){	
	var i;
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0){
		 alert('- CPF inválido!');
		 return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		 alert('- CPF inválido!');	
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		 alert('- CPF inválido!');	
		return false;
	}
	return true;
}
/**********************/
// FIM: VALIDA CNPJ/CPF
/**********************/


/***************
// VALIDA E-MAIL
****************/
function ValidaEmail(email) {
 var formato_errado = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
 var formato_certo = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
 var errado = new RegExp(formato_errado);
 var certo = new RegExp(formato_certo);
 return (!errado.test(email) && certo.test(email))
}
/********************
// FIM: VALIDA E-MAIL
*********************/


/*************
// CHECA SENHA
**************/
function CaracterSenha(e,id_element){
	var key
	if(window.event) {
		key = e.keyCode;  
		if (( key == 37 )||( key == 39 )||( key == 59 )||( key == 34 )||( key == 126)||( key == 96)||( key == 38)||( key == 36)) {
			alert('- Caractere inválido');
			window.event.returnValue = null; 
			return;
		}		
	}
	else if (e.which) {
		key = e.which;
		if (( key == 37 )||( key == 39 )||( key == 59 )||( key == 34 )||( key == 126)||( key == 96)||( key == 38)||( key == 36)) {
			alert('- Caractere inválido');
			e.preventDefault();
			return ; 
		}		
	}
}
/******************
// FIM: CHECA SENHA
*******************/



/***
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
********/


/****
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
**********/
