/********************************************************************************************
TEMPO
********************************************************************************************/
function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}else if (obj.x)
		curleft += obj.x;
		return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
		}else if (obj.y)
			curtop += obj.y;
		 return curtop;
}

function position(obj, reference) {
	if (document.all) {
		var newX = findPosX(reference);
		var newY = findPosY(reference); 
	}else{ 
		var newX = findPosX(reference)+2;
		var newY = findPosY(reference);
	}
	obj.style.left = newX;
	obj.style.top = newY - obj.style.height.substring(0, obj.style.height.indexOf("px"));
}

function abrirTempo(reference,menu) {
	stopTime();	
	var menuDiv = document.getElementById(menu);
	if (menuDiv.style.visibility == "hidden") {
		position(menuDiv, reference);
		menuDiv.style.visibility = "visible";
	}else{
		menuDiv.style.visibility = "hidden";						
	}
}

var intval = ""
function startTime(reference, menu){
	var menuDiv = document.getElementById(menu);
	if(intval=="" && menuDiv.style.visibility == "visible"){
		intval=window.setInterval("abrirTempo('"+ reference +"','"+ menu +"')",2000)
	}else{
		stopTime()
	}
}

function stopTime(){
	if(intval!=""){
		window.clearInterval(intval)
		intval = ""
	}
}
/********************************************************************************************
FIM: TEMPO
********************************************************************************************/


/********************************************************************************************
FECHA LAYER
********************************************************************************************/
function FL(sId){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
	sDiv.style.display = "none";
 clearInterval(num);
 }
 ,100)
}
/********************************************************************************************
FIM: FECHA LAYER
********************************************************************************************/

/********************************************************************************************
ABRE LAYER
********************************************************************************************/
function AL(sId){ 
	var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
 sDiv.style.display = "block";
 clearInterval(num);
 }
 ,100)
}
/********************************************************************************************
FIM: ABRE LAYER
********************************************************************************************/

/********************************************************************************************
VALIDA NÚMERO GALERIA
********************************************************************************************/
function ValidaNumero(objeto,msg){
	var contador=0;
	var total=objeto.value.length;
	var bNumero=true;
	if (contador!=-1)
		{
		while ((contador<total) && (bNumero))
			{
			if (isNaN(objeto.value.charAt(contador)))
				{
				bNumero=false;
				alert(msg);
				objeto.select();
				return(false);  
				}
			contador=contador+1;
			}
		}
	return(true);
}
/********************************************************************************************
FIM: VALIDA NÚMERO GALERIA
********************************************************************************************/

/********************************************************************************************
CONTA TEXTO
********************************************************************************************/
function ContaTexto(CampoMsg,CampoContador, TamMax){
	if (CampoMsg.value.length > TamMax)
		CampoMsg.value = CampoMsg.value.substring(0, TamMax);
	else
		CampoContador.value = TamMax - CampoMsg.value.length;
}
/********************************************************************************************
FIM: CONTA TEXTO
********************************************************************************************/

/********************************************************************************************
POP-UP
********************************************************************************************/
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: POP-UP
********************************************************************************************/

/*******************************************************************************************
PULA TEXTO
*******************************************************************************************/
function exibeValor(nomeCampo, lenCampo, controle){
 if ((nomeCampo.value.length == lenCampo) && (checarTabulacao)){	
  var i=0;
  for (i=0; i<document.form.elements.length; i++){
   if (document.form.elements[i].name == nomeCampo.name){
  while ((i+1) < document.form.elements.length){
   if (document.form.elements[i+1].type != "hidden"){
    document.form.elements[i+1].focus();
  break;}i++;}
  checarTabulacao=false;
  break;
}}}}

function stopTabCheck(nomeCampo){
 checarTabulacao=false;
}

function startTabCheck(){
 checarTabulacao=true;
}
/*******************************************************************************************
FIM: PULA TEXTO
*******************************************************************************************/

/******************************************************************************************/
// VÁLIDA E-MAILS
/******************************************************************************************/
function email_valido(email) {
 var formato_errado = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
 var formato_certo = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[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-MAILS
/******************************************************************************************/

/******************************************************************************************/
// VALIDA CPF
/******************************************************************************************/
function valida_CPF(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) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		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){
		return false;
	}
	return true;
}
/******************************************************************************************/
// FIM: VALIDA CPF
/******************************************************************************************/
