/*******************************************************************************************
VALIDA E-MAIL
*******************************************************************************************/
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-MAIL
*******************************************************************************************/


/********************************************************************************************
LAYER x SELECT
********************************************************************************************/
function DivSetVisible(sDiv){
 var DivRef = document.getElementById(sDiv);
 var IfrRef = document.getElementById('if_'+sDiv);

 DivRef.style.display = "block";
 IfrRef.style.width = DivRef.offsetWidth;
 IfrRef.style.height = DivRef.offsetHeight;
 IfrRef.style.top = DivRef.style.top;
 IfrRef.style.left = DivRef.style.left;
 IfrRef.style.zIndex = DivRef.style.zIndex - 1;
 IfrRef.style.display = "block";
}
/********************************************************************************************
FIM: LAYER x SELECT
********************************************************************************************/


/********************************************************************************************
MONTA BOX DOS ALERTAS
********************************************************************************************/
function Alerta(erros){
	var monta  = '<iframe id="if_msg_alerta" src="" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe><div>'
	+ ' <div class="alerta_topo" align="right"><a href=javascript:void(0) onclick=FL("msg_alerta") class="font_link_preto_10"><font class="font_preto_10">fechar</font> <img src="img/botoes/btn_fechar.gif" width="6" height="11" alt="" border="0"></a>&nbsp;&nbsp;&nbsp;</div>'
	+ ' <div class="alerta_c">'
	+ '  <div style="padding-left:30px; padding-right:20px">'
	+ '   <img src="img/alertas/tit_alertas.gif" width="117" height="48" alt=""><br>'
	+ '   <font class="font_padrao">'+erros+'</font>'
	+ '  </div>'
	+ ' </div>'
	+ ' <div class="alerta_fim"></div>'
	+ '</div>'
	+ '</div>'
document.getElementById("msg_alerta").style.display = "block"
document.getElementById("msg_alerta").innerHTML = monta;
}

/* SEM BOTÃO FECHAR */
function Alerta2(erros){
	var monta  = '<iframe id="if_msg_alerta" src="" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe><div>'
	+ ' <div class="alerta_topo" align="right"></div>'
	+ ' <div class="alerta_c">'
	+ '  <div style="padding-left:30px; padding-right:20px">'
	+ '   <img src="img/alertas/tit_alertas.gif" width="117" height="48" alt=""><br>'
	+ '   <font class="font_padrao">'+erros+'</font>'
	+ '  </div>'
	+ ' </div>'
	+ ' <div class="alerta_fim"></div>'
	+ '</div>'
	+ '</div>'
document.getElementById("msg_alerta").style.display = "block"
document.getElementById("msg_alerta").innerHTML = monta;
}
/********************************************************************************************
FIM: MONTA BOX DOS ALERTAS
********************************************************************************************/


/********************************************************************************************
MENU DE PAÍSES
********************************************************************************************/
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 abrirMenu(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("abrirMenu('"+ reference +"','"+ menu +"')",2000)
	}else{
		stopTime()
	}
}

function stopTime(){
	if(intval!=""){
		window.clearInterval(intval)
		intval = ""
	}
}
/********************************************************************************************
FIM: MENU DE PAÍSES
********************************************************************************************/
  

/********************************************************************************************
SCRIPT CALENDÁRIO
********************************************************************************************/
var strCampo = "";

function InputCalendario(sLocal, sStatus, sDia, sMes, sAno, sCampo){
 var sMesAno
 
 if (sDia == undefined){
  sMesAno = ''
 }
 else{
  sMesAno = sMes.toString() + sAno.toString()
  eval("document.form_cl."+sCampo+".selectedIndex = "+sDia);
 }
 
 var datas = new Date();
 var Dia = datas.getDate();
 var Mes = datas.getMonth();
 var Ano = datas.getFullYear();
 
 function CriaTab (n){
  this.length = n
  for (var x = 1 ; x<= n ; x++){
   this[x] = ""
  }
 }

 MesAtual = new CriaTab(12)
 MesAtual[0] = "Jan"
 MesAtual[1] = "Fev"
 MesAtual[2] = "Mar"
 MesAtual[3] = "Abr"
 MesAtual[4] = "Mai"
 MesAtual[5] = "Jun"
 MesAtual[6] = "Jul"
 MesAtual[7] = "Ago"
 MesAtual[8] = "Set"
 MesAtual[9] = "Out"
 MesAtual[10] = "Nov"
 MesAtual[11] = "Dez"

	x = 0
	Mes1 = Mes
	Ano1 = Ano
 strFormato ="<select name=\"mes_"+sLocal+"\" id=\"mes_"+sLocal+"\" style=\"width:80px;\""+sStatus+">";

 while (x < 11){
		if (Mes1 >= 12){
			Mes1= 0
			Ano1 = Ano + 1
		}

	MesExt = MesAtual[Mes1];
	Mes1 = Mes1 + 1;
  
 if (Mes1 <= 9) {
 	if (sMesAno == Mes1.toString() + Ano1.toString()){
   strFormato += "<option value=0"+ Mes1 + Ano1 + " selected>" + MesExt + " " + Ano1+"</option>";
  }
  else{
   strFormato += "<option value=0"+ Mes1 + Ano1 + ">" + MesExt + " " + Ano1+"</option>";
  }
 }
	else{
  strFormato += "<option value="+ Mes1 + Ano1 + ">" + MesExt + " " + Ano1+"</option>";
  x++;
	} 
 }
 strFormato += "</select>";
 document.getElementById(sLocal).innerHTML = strFormato;
}
/********************************************************************************************
FIM: SCRIPT CALENDÁRIO
********************************************************************************************/


/********************************************************************************************
LIMPA CAMPO QUANDO CLICADO
********************************************************************************************/
 function LimpaCampo(form,campo){
  eval("document."+form+"."+campo+".value = ''")
 }
/********************************************************************************************
FIM: LIMPA CAMPO QUANDO CLICADO
********************************************************************************************/


/********************************************************************************************
COR DO CAMPO DOS FORMS QUANDO CLICADO
********************************************************************************************/
function InputOn(n,c) {
	n.className = c;
}

function InputOff(n) {
	if(n.className=='input') {
		n.className = 'input_on';
	} else {
		n.className = 'input';
	}
}
/********************************************************************************************
FIM: COR DO CAMPO DOS FORMS QUANDO CLICADO
********************************************************************************************/


/********************************************************************************************
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); 
}

function OpenPopup2(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)+100; 
 var CenterPopUpY = (screen.height/2)-(Hpopupsize)+50; 
 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
********************************************************************************************/


/********************************************************************************************
ABRE E FECHA AS LAYERS
********************************************************************************************/
function AFL(sId){ 
 var num;
 num = setInterval(function(){
 var DivRef = document.getElementById(sId);
 var IfrRef = document.getElementById('if_'+sId);
 
	if(DivRef.style.display == "none"){
	 DivRef.style.display = "block";
	 IfrRef.style.width = DivRef.offsetWidth;
	 IfrRef.style.height = DivRef.offsetHeight;
	 IfrRef.style.top = DivRef.style.top;
	 IfrRef.style.left = DivRef.style.left;
	 IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	 IfrRef.style.display = "block";
	}else{
	 DivRef.style.display = "none";
	 IfrRef.style.width = DivRef.offsetWidth;
	 IfrRef.style.height = DivRef.offsetHeight;
	 IfrRef.style.top = DivRef.style.top;
	 IfrRef.style.left = DivRef.style.left;
	 IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	 IfrRef.style.display = "none";
 }
 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 FL(sId){ 
 var num;
 num = setInterval(function(){
 var sDiv = document.getElementById(sId);
	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)
}
/********************************************************************************************
FIM: ABRE E FECHA AS LAYERS
********************************************************************************************/


/********************************************************************************************
COR DA TD
********************************************************************************************/

var sCampo;

function CorTd(id, color) {
 var id = document.getElementById(id);
 id.style.backgroundColor = color;
}

function CorTd2(n, qtde, color, campo){
 for(x=1;x<=qtde;x++){
		c = eval('document.getElementById("'+campo+'' + x + '").style');
  if(x==n){
			c.backgroundColor = color;
  }else {
			c.backgroundColor = '#FAFAFA';
  }
 }
}
/********************************************************************************************
FIM: COR DA TD
********************************************************************************************/

 
/********************************************************************************************
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 + '");');
  if(x==n)
  {
    if (aba != null)
    {
        aba.className = 'current';
    }
	if(aba_cont != null)
	{
	    aba_cont.style.display = '';
	}
  }
  else 
  {
    if (aba != null)
    {
        aba.className = '';
    }
	if(aba_cont != null)
	{
	    aba_cont.style.display = 'none';
	}
  }
 }
}

function abas2(n, qtde){
 for(x=1;x<=qtde;x++){
		aba_cont = eval('document.getElementById("aba_cont' + x + '").style;');
  if(x==n){
			aba_cont.display = '';
  }else {
			aba_cont.display = 'none';
  }
 }
}

function abas3(n, qtde){
 for(x=1;x<=qtde;x++){
		aba_cont = eval('document.getElementById("aba_cont_int' + x + '").style;');
  if(x==n){
			aba_cont.display = '';
  }else {
			aba_cont.display = 'none';
  }
 }
}
/********************************************************************************************
FIM: ABAS
********************************************************************************************/

function setTab(n)
{
    $("input[@id*='CURTAB']").val(n);
}