﻿
var Alterou = false;
var ValorCampoOriginal;

function AlteraSeVazio() {
	for(i=0; i < document.forms[0].length; i++) {
		obj = document.forms[0].elements[i];
		if ( obj.className == 'ObjetoForm-01-Disabled-Vazio') {
			if ( obj.value == '' ) {
				obj.className = 'ObjetoForm-01';
				obj.readOnly = false;
			}
		}
	}
}

function ExibMsgPermissao(msg) {
   if ( msg == '' ) {
   		window.alert("Você não tem permissão para acessar esta aba!");
   } else {
   		window.alert(msg);
   }
   return false;
}

function AbreJanelaCentralizada(pagina, nomedajanela, w, h, pStatus, pScroll, pRedimensiona, pBarraMenu) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',status='+pStatus+',scrollbars='+pScroll+',resizable='+pRedimensiona+',menubar='+pBarraMenu+''
    win = window.open(pagina, nomedajanela, winprops)

    if (parseInt(navigator.appVersion) >= 4) { 
        win.window.focus(); 
    }
}

function Ordena(PgSubmit,Campos,Ordem){
  document.form.action = PgSubmit
  document.form.Ordem.value = Campos+' '+Ordem;
  document.form.submit();
}

function MostraMsg( sMsg ){
   if ( sMsg != "" ){
      alert( sMsg );
   }
}

function VerificaCPF(cpf){   
   if (cpf.length > 0){
      if (isNaN(cpf) == true){
         alert('CPF é de preenchimento numérico. Sem pontos ou quaisquer separadores.');
	      return false;
      }
      if (cpf == 0 ){
         alert('CPF está zerado. Informe corretamente.');	
	      return false;
      }
      var nr = 0;
      for (i = cpf.length - 1; i > 0; i--){ 
         if (cpf.charAt(i) != cpf.charAt(i-1)){
            nr = 1;
         }
      }
	   if (nr == 0 ){
         alert('Todos os dígitos iguais! Informe corretamente.');
		   return false;
	   }
      var peso = 20;
      var dv   = 0;
      for (i = cpf.length - 2; i > 0; i--){ 
         dv += cpf.substring(i,i-1) * peso;
         peso += 10; 
      }
      dv %= 11;
	   if (dv == 10)
		   dv = 0;
	   if (cpf.substring(cpf.length - 2,cpf.length - 1) != dv){ 
         alert('Controle CPF inválido!!!');
         return false;
      }
      var peso = 20;
      var dv   = 0;
      for (i = cpf.length - 1; i > 0; i--){ 
         dv += cpf.substring(i,i-1) * peso;
         peso += 10; 
       }
      dv %= 11;
	   if (dv == 10)
		   dv = 0;
	   if (cpf.substring(cpf.length - 1,cpf.length) != dv){ 
         alert('Controle CPF inválido!!!');
         return false;
      }
    return true;
}
}


function VerificaCNPJ(cgc){
   if (cgc.length > 0){
      if (isNaN(cgc) == true){
         alert('CNPJ é de preenchimento numérico. Sem pontos ou quaisquer separadores.');
         return false;
      }
      if (cgc == 0 ){
         alert('CNPJ está zerado. Informe corretamente.');	
         return false;
      }
      var nr = 0;
      for (i = cgc.length - 1; i > 0; i--){
         if (cgc.charAt(i) != cgc.charAt(i-1)){
            nr = 1;
         }
   }
   if (nr == 0 ){
      alert('Todos os dígitos iguais! Informe corretamente.');
      return false;
   }
   var peso = 20;
   var dv   = 0;
   for (i = cgc.length - 2; i > 0; i--){ 
      dv += cgc.substring(i,i-1) * peso;
      peso += 10; 
      if (peso > 90){ 
         peso = 20
      }
   }
   dv %= 11;
	if (dv == 10)
		dv = 0;
	if (cgc.substring(cgc.length - 2,cgc.length - 1) != dv){ 
      alert('Controle CNPJ inválido!!!');
      return false;
   }
   var peso = 20;
   var dv   = 0;
   for (i = cgc.length - 1; i > 0; i--) 
       {dv += cgc.substring(i,i-1) * peso;
         peso += 10; 
         if (peso > 90)
         {peso = 20}
       }
    dv %= 11;
	if (dv == 10)
		dv = 0;
	if (cgc.substring(cgc.length - 1,cgc.length) != dv){
      alert('Controle CNPJ inválido!!!');
      return false;
   }
   return true;
}
}

function EscreveTipo(){
   Controle = true
   for(var i=0;Controle == true; i++){
      if( document.form.Regiao.options[i].selected == true ){
         Controle = false;
         document.form.Regiao.selectedIndex = i;
         document.form.TipoRegiao.value = document.form.Regiao.options[document.form.Regiao.selectedIndex].Tipo;
      }
   }
}

function Reseta(Nome){
   if( document.form[Nome].type == "text"){
      document.form[Nome].value = "";
   }
   if( document.form[Nome].type == "select-one"){
      if(Nome == "Regiao"){
         document.form.TipoRegiao.value = "";
      }
      document.form[Nome].selectedIndex = 0;
   }
}

function Navegacao(PgSubmit,Acao,Pg){
var Temp;
var RegPagina = document.form.RegPPag.value;
   document.getElementById("totalregistros").innerHTML = unescape("Aguarde...");
   if (Acao == 'PRIMEIRO'){
      document.form.PgAtual.value = "1";
   }
   if (Acao == 'ANTERIOR'){
         Temp = parseInt(document.form.PgAtual.value--); 
   }
   if (Acao == 'PROXIMO'){
      Temp = parseInt(document.form.PgAtual.value++); 
   }
   if (Acao == 'ULTIMO'){
      if (document.form.PgTotal.value.length > 0){
         document.form.PgAtual.value = Math.round(document.form.PgTotal.value / RegPagina); 
      }
   }
   if (Acao == 'IRPG'){
      if (Pg != ''){
         document.form.PgAtual.value = Pg; 
      }
   }
   document.form.action = PgSubmit;
   document.form.method = "post";
   document.form.submit();
}


/*
function LigaCor(evt,Cor1,Cor2){
    if (evt.className.indexOf("Disabled") == -1 ){
        if (document.all){
            evt.attributes['className'].value=Cor1;
        }else{
            evt.attributes['class'].value=Cor1;
        }
     }
}
function DesligaCor(evt,Cor1,Cor2){
    if (evt.className.indexOf("Disabled") == -1 ){
        if (document.all){
            evt.attributes['className'].value=Cor1;
        }else{
            evt.attributes['class'].value=Cor1;
        }            
    }
}
*/

function LigaCor(Obj,Cor1,Cor2){
    if ( window.event.srcElement.className.indexOf("Disabled") == -1 ){
      //Obj.className = Cor1;
		Obj.attributes['class'].value=Cor1;
   }
}

function DesligaCor(Obj,Cor1,Cor2){
	if ( window.event.srcElement.className.indexOf("Disabled") == -1 ){
      //Obj.className = Cor1;
		Obj.attributes['class'].value=Cor1;
   }
}


function AbreTblAux( NomeTbl, Campos, Whr, E_Aux, CmpRetorno, LstRetorno, sDescricao, sDescricaoTbl, ControleAcesso ){
   Nome = new String(Math.random())
   if ( ControleAcesso != "disabled" ) {
      openWin(''+Nome.substring(2,4)+'','ManterTabelas_01.asp?Tbl='+NomeTbl+'&Campos='+Campos+'&WhrInterno='+Whr+'&CmpRetorno='+CmpRetorno+'&LstRetorno='+LstRetorno+'&E_Aux='+E_Aux+'&sDescricao='+sDescricao+'&sDescricaoTbl='+ sDescricaoTbl+'',450,330,false,false);
   }
}

	function openWin(winName, urlLoc, w, h, showStatus, isViewer) {
      l = (screen.availWidth - w)/2;
		t = (screen.availHeight - h)/2;
		features  = "toolbar=no";      // yes|no 
		features += ",location=no";    // yes|no 
		features += ",directories=no"; // yes|no 
		features += ",status=" + (showStatus?"yes":"no");  // yes|no 
		features += ",menubar="+ (winName == "Boleto"?"yes":"no");     // yes|no 
		features += ",scrollbars=" + (isViewer?"yes":"no");   // auto|yes|no 
		features += ",resizable=" + (isViewer?"yes":"no");   // yes|no 
		features += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
		features += ",height=" + h;
		features += ",width=" + w;
		features += ",left=" + l;
		features += ",top=" + t;
		winName = winName.replace(/[^a-z]/gi,"_");
		WinPop = window.open(urlLoc,winName,features);
		try { 
			WinPop.focus();
		} 
		catch(er) {
      	alert("Um aplicativo anti-popup pode ter bloqueado a abertura desta página.\nSe você tiver um aplicativo anti-popup desabilite para poder abrir esta janela.")
		} 	
		
	} 
	

function AbreTabela( NomeTbl ){    
   Nome = new String(Math.random())
   //if ( ControleAcesso != "disabled" ) {
      openWin(''+Nome.substring(2,4)+'', NomeTbl,450,330,false,false);
   //}
}

function AbreTabelaMaior( NomeTbl ){
   Nome = new String(Math.random())
   //if ( ControleAcesso != "disabled" ) {
      openWin(''+Nome.substring(2,4)+'', NomeTbl,660,530,false,false);
   //}
}

	function openWin(winName, urlLoc, w, h, showStatus, isViewer) {
      l = (screen.availWidth - w)/2;
		t = (screen.availHeight - h)/2;
		features  = "toolbar=no";      // yes|no 
		features += ",location=no";    // yes|no 
		features += ",directories=no"; // yes|no 
		features += ",status=" + (showStatus?"yes":"no");  // yes|no 
		features += ",menubar="+ (winName == "Boleto"?"yes":"no");     // yes|no 
		features += ",scrollbars=" + (isViewer?"yes":"no");   // auto|yes|no 
		features += ",resizable=" + (isViewer?"yes":"no");   // yes|no 
		features += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
		features += ",height=" + h;
		features += ",width=" + w;
		features += ",left=" + l;
		features += ",top=" + t;
		winName = winName.replace(/[^a-z]/gi,"_");
		WinPop = window.open(urlLoc,winName,features);
		try { 
			WinPop.focus();
		} 
		catch(er) {
      	alert("Um aplicativo anti-popup pode ter bloqueado a abertura desta página.\nSe você tiver um aplicativo anti-popup desabilite para poder abrir esta janela.")
		} 	
		
	} 
	

function Trim(value) {
    var temp = "";
    if (value != undefined){
       var temp = value;
       var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
       if (obj.test(temp)){
          temp = temp.replace(obj, '$2');
       }
       var obj = / +/g;
       temp = temp.replace(obj, " ");
       if (temp == " "){
          temp = "";
       }
    }
   return temp;
}

function CompletaZeros(objeto, qtd){  
   var novovalor = objeto.value.toUpperCase();	
   var diferenca = 0;
   var i = 0;
   var tempzeros = '';
   if (novovalor.length != 0){
      if (novovalor.length < qtd) {
         diferenca = qtd - novovalor.length;
         for (i = 0; i < diferenca; i++) {
            tempzeros = tempzeros + '0';
         }     
      }
      objeto.value = tempzeros + novovalor;
   }
}

function Numerico(CD){
if ((CD >= 48 && CD <= 57))
     return true;
    return false;
}

function AlphaNumerico(CD){
if ((CD >= 48 && CD <= 57)|(CD >= 65 && CD <= 90)|(CD >= 97 && CD <= 122))
     return true;
    return false;
}

function Alpha(CD){
if ((CD >= 65 && CD <= 90) | 
	 (CD >= 97 && CD <= 122)|
	 (CD >= 224 && CD <= 226)|
	 (CD >= 232 && CD <= 234)|
	 (CD >= 236 && CD <= 238)|
	 (CD >= 242 && CD <= 244)|
	 (CD >= 249 && CD <= 251)|CD == 32|CD == 227|CD == 244)
     return true;
    return false;
}

function ValidaTel(CD){
if ((CD >= 48 && CD <= 57)|(CD == 40 | CD == 41 | CD == 45 |CD == 32))
     return true;
    return false;
}

function ValidaEmail(oField) {
	if (oField.value.length > 0){
	var addr = oField.value.split(";");
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;	// not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;	// valid
				
	for (var i in addr)
		if (reg1.test(addr[i]) || !reg2.test(addr[i]) || addr[i].indexOf("'") > -1) {
			oField.focus();return false;
		}
	return true;
}
	return true;
}

function Alterou1( ValorCampo ){
   ValorCampoOriginal = Trim(ValorCampo);
	//alert( ValorCampoOriginal );
}

function Alterou2( NovoValor ){
   //alert( NovoValor+'...'+ValorCampoOriginal);
	if ( Trim(NovoValor) != ValorCampoOriginal){
      Alterou = true;
   }
}

function VerificaAlteracao(pg,strCod){
   if (strCod != 0){
      if (Alterou){
         if (confirm("Gostaria de salvar as alterações feitas?")){
            ValidaSubmit(pg)
         }else{
            document.location.href = pg;
         }
      }else{
         document.location.href = pg;
      }
   }else{
      alert("Você não tem permissão de acesso para esta tela!")
   }
}

function SelecionaSelectList(campo,valor){
   for(i=0;i<document.all[campo].options.length; i++){
    if (document.all[campo].options[i].value == valor){
       document.all[campo].selectedIndex = i;
         break;
    }//end if
   }//end for
}//end function

function SelecionaSelectPorTexto(campo,valor){
   for(i=0;i<document.all[campo].options.length; i++){
    if (document.all[campo].options[i].text == valor){
       document.all[campo].selectedIndex = i;
         break;
    }//end if
   }//end for
}//end function

// Rodrigo Landim - 13/01/2004
function SelecionaSelectText(campo,valor){
   for(i=0;i<document.all[campo].options.length; i++){
    if (document.all[campo].options[i].text == valor){
       document.all[campo].selectedIndex = i;
         break;
    }//end if
   }//end for
}//end function
//

function ValidaEdtCombo(campo,campo1,camparacao){
var valor1 
var valor2 
   if (document.forms[0][campo].selectedIndex != -1){
      valor1 = document.forms[0][campo].options[document.forms[0][campo].selectedIndex][camparacao];
      valor2 = document.forms[0][campo1].value;
      if (Trim(document.forms[0][campo1].value) != ""){
         if (valor1 != valor2){
            
            alert('Valor informado inválido');
            
            document.forms[0][campo1].value = "";
            document.forms[0][campo1].focus();
         }//end if3
      }else{
         document.forms[0][campo].selectedIndex = 0;
      }//end if2
   }else{
      if (Trim(document.forms[0][campo1].value) != ""){
         alert('Valor informado inválido');
         document.forms[0][campo1].value = "";
         document.forms[0][campo1].focus();
      }//end if4
   }//end if1
}//end function

function FormataCep(campo){
var ValorFormatado = "";
   if (campo.value.length == 8){
      for(var i=0;i<campo.value.length; i++){
         if (i == 2){
            ValorFormatado = ValorFormatado + ".";
         }//end if
         if (i == 5){
            ValorFormatado = ValorFormatado + "-";
         }//end if
         ValorFormatado = ValorFormatado + campo.value.substring(i,i+1);
      }//end for
      campo.value = ValorFormatado;
   }else{
      if( campo.value.length != 0){
         campo.focus();
         alert('Informe um CEP válido, com 8 posições.');
      }
   }//end if1
}

function LimpaCEP(campo){
var ValorLimpo = "";
   for(var i=0;i<campo.value.length; i++){
      if ( campo.value.substring(i,i+1) != '.' && campo.value.substring(i,i+1) != '-'){
         ValorLimpo = ValorLimpo + campo.value.substring(i,i+1);
      }//end if
   }//end for
   campo.value = ValorLimpo;
}//end function

function DesabilitaCampos(campo){
var campotrim = Trim(campo.value);
   if ( campotrim.length != 0 ){
      for (var i=0;i<document.form.elements.length;i++){
         if ( (document.form.elements[i].type == "text" || document.form.elements[i].type == "select-one") && (document.form.elements[i].name != campo.name)){
            document.form.elements[i].disabled = true; 
         }//end if
      }//end for
   }else{
      for (var i=0;i<document.form.elements.length;i++){
         if ( (document.form.elements[i].type == "text" || document.form.elements[i].type == "select-one") ){
            document.form.elements[i].disabled = false; 
         }//end if
      }//end for
   }//end if
}//end function

function CadNovo(pg){
   document.getElementById("totalregistros").innerHTML = unescape("Aguarde...");
   if( document.form.Permissao.value == 2 ){
      document.form.Novo.value = 1;
      document.form.action = pg;
      document.form.submit();
   }
}

function ExcluiReg(pg){
   switch (pg){
      case "Formacao_01.asp":
      Msg = "este curso"
      Acao = 2;
      PgDel = "Formacao_04.asp";
      break;
      case "Formacao_02.asp":
      Msg = "este evento"
      Acao = 2;
      PgDel = "Formacao_04.asp";
      break;
      case "Formacao_03.asp":
      Msg = "esta especialidade"
      Acao = 4;
      PgDel = "Formacao_04.asp";
      break;
      case "ExperienciaProfissional_01.asp":
      Msg = "esta experiência profissional, bem como responsabilidades ténicas e horários"
      Acao = 2;
      PgDel = "ExperienciaProfissional_03.asp";
      break;
      case "ExperienciaProfissional_02.asp":
      Msg = "esta responsabilidade técnica"
      Acao = 4;
      PgDel = "ExperienciaProfissional_07.asp";
      break;
      case "CadastroUsuarios_01_Temp.asp":
      Msg = "este usuário"
      Acao = 2;
      PgDel = "CadastroUsuarios_01_Temp.asp";
      break;
      case "OutrosDados_01_PJ.asp":
      Msg = "este capital social "
      Acao = 2;
      PgDel = "OutrosDados_02_PJ.asp";
      break;

   }
   if (confirm("Você realmente deseja excluir "+Msg+"?")) {
      document.getElementById("totalregistros").innerHTML = unescape("Aguarde...");
      document.form.Acao.value = Acao;
      document.form.action = PgDel;
      document.form.submit();
   }
}

function FormataData(campo,teclapres) {
	
	var tecla = teclapres.keyCode;
	vr = document.forms[0].elements[campo].value;
	
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
         	document.forms[0].elements[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
      	document.forms[0].elements[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
	
}

//N?o est? ligada a campo de formul?rio, podendo receber valores quaisquer passados como par?metros.
function ValidaDataLivre( field ) {
   var v_dia;
   var v_mes;
   var v_ano;
   var valido;
   
   v_dia = field.substring (0, 2);
   v_mes = field.substring (3, 5);
   v_ano = field.substring (6, 11);
   valido = true;
   
   if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0)) {
      valido = false;
    }
   if (v_dia > 31){
      valido = false;
   }
   if (v_mes > 12){
      valido = false;
   }
   if (v_dia == "31") {
      if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11")){
         valido =  false;
      }
   }
   if (v_mes == "02"){
      if (!(v_ano%4)) {
         if (v_dia > 29) {
            valido = false;
         }
      }
   else  if (v_dia > 28){
            valido = false;
         }
   }
   if ( ( field.length > 0 ) && ( field.length != 10 ) ){
	   valido = false;
   }
   return valido;
}

function ValidaData( field ) {
   var v_dia;
   var v_mes;
   var v_ano;
   var valido;
   
   v_dia = field.value.substring (0, 2);
   v_mes = field.value.substring (3, 5);
   v_ano = field.value.substring (6, 11);
   valido = true;
   
   if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0)) {
      valido = false;
    }
   if (v_dia > 31){
      valido = false;
   }
   if (v_mes > 12){
      valido = false;
   }
   if (v_dia == "31") {
      if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11")){
         valido =  false;
      }
   }
   if (v_mes == "02"){
      if (!(v_ano%4)) {
         if (v_dia > 29) {
            valido = false;
         }
      }
   else  if (v_dia > 28){
            valido = false;
         }
   }
   if ( ( field.value.length > 0 ) && ( field.value.length != 10 ) ){
      field.focus();
      alert( 'Data em formato inválido.\nUse o formato dd/mm/aaaa.' );
   
   }
   if (!valido ) {
      field.focus();
      alert( 'A Data informada é inválida!' );
   }
   return valido;
   
}

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 ) ;}
	}
}

// Funcao para trocar a imagen
function mOverOut(imgName, imgPath) 
{
	document.images[imgName].src = imgPath;
}



