﻿var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function AtivaEnter(evento, NomeBotao)
{
    var botao = document.getElementById(NomeBotao);
    var keyCode = (isNN) ? evento.which : evento.keyCode;

    if ( keyCode == 13 )
    {
        evento.preventDefault? evento.preventDefault() : evento.returnValue = false;
        botao.click();
    }
}
        
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
        
function ValidaCPF(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!isCPF(valor)) arguments.IsValid = false;
}


function LimitaTamanho( campo , campo_total , total ) {
    var campo_texto = document.getElementById(campo)
 	if ( campo_texto.value.length > total ) {
		campo_texto.value = campo_texto.value.substring(0, total);
		alert ("Por favor, o texto não pode conter mais de "+total+" caracteres");
	}
	var restante = total - campo_texto.value.length;
	document.getElementById(campo_total).innerHTML = restante;
}


function LimitaTamanho2(campo, campo_total, total, total_texto) {
    var campo_texto = document.getElementById(campo)
    if (campo_texto.value.length > total) {
        campo_texto.value = campo_texto.value.substring(0, total);
        alert("Por favor, o texto não pode conter mais de " + total_texto + " caracteres");
    }
    var restante = total - campo_texto.value.length;
    //document.getElementById(campo_total).innerHTML = restante;
}

function isCPF(s)
{ 
    s = s.replace('.', '')
    s = s.replace('.', '')
    s = s.replace('-', '')

    if ( s == "00000000000" || s == "11111111111" || s == "22222222222" || s == "33333333333" || s == "44444444444" || s == "55555555555" || s == "66666666666" || s == "77777777777" || s == "88888888888" || s == "99999999999" )
    { 
        return false; 
    } 

    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; 
}

function FormataInteiro(campo,evento){
	var keyCode = (isNN) ? evento.which : evento.keyCode;
	if ( (!(keyCode >= 48 && keyCode <= 57)) && keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
}
        
function validaCNPJNET(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!isCNPJ(valor)) arguments.IsValid = false;
}

function isCNPJ(CNPJEnviado) {
    var CNPJ = CNPJEnviado;

    var erro = new String;
    
    if (CNPJ.length < 18) return false;
    if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
    if (erro.length == 0) return false;
    }
    //substituir os caracteres que não são números
    if(document.layers && parseInt(navigator.appVersion) == 4){
           x = CNPJ.substring(0,2);
           x += CNPJ. substring (3,6);
           x += CNPJ. substring (7,10);
           x += CNPJ. substring (11,15);
           x += CNPJ. substring (16,18);
           CNPJ = x; 
    } else {
           CNPJ = CNPJ. replace (".","");
           CNPJ = CNPJ. replace (".","");
           CNPJ = CNPJ. replace ("-","");
           CNPJ = CNPJ. replace ("/","");
    }
    var nonNumbers = /\D/;
    if (nonNumbers.test(CNPJ)) return false; 

    if ( CNPJ == "00000000000000" || CNPJ == "11111111111111" || CNPJ == "22222222222222" || CNPJ == "33333333333333" || CNPJ == "44444444444444" || CNPJ == "55555555555555" || CNPJ == "66666666666666" || CNPJ == "77777777777777" || CNPJ == "88888888888888" || CNPJ == "99999999999999" ) return false;

    var a = [];
    var b = new Number;
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
    for (i=0; i<12; i++){
       a[i] = CNPJ.charAt(i);
       b += a[i] * c[i+1];
    }
    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
    b = 0;
    for (y=0; y<13; y++) {
           b += (a[y] * c[y]); 
    }
    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
    if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
        return false;
    }
    
    return true;
}

Date.parseLocale = function(s, f){return Date.localeParse(s, f);};

function DesbilitaCopiarColar(evento) {
  // current pressed key
  var keyCode = (isNN) ? evento.which : evento.keyCode;
  var pressedKey = String.fromCharCode(keyCode).toLowerCase();

  if (evento.ctrlKey && (pressedKey == "c" || pressedKey == "v")) {
    // disable key press porcessing
    if (window.event) //IE
    {
      evento.returnValue = false;
    }
    else //Firefox
    {
      evento.preventDefault(); // <-- What should I write here instead
    }
  }

} // onKeyDown

function janela(url) {
   //var nomearq = param;
   window.open(url,'mcComprovante',"scrollbars=yes,location=no,directories=no,status=yes,menubar=no,resizable=no,toolbar=no,top=50,left=50,width=280,height=440");
   //document.form_pos.submit();
}


function verifica_selecionados_formacao()
{
    var Total = document.getElementById("ctl00_ContentPlaceHolder1_TotalFormacao").value;
    for(var i = 0; i < Total; i++)
    {
        if (document.getElementById("ctl00_ContentPlaceHolder1_ExcluirFormacao" + i))
        {
            if (document.getElementById("ctl00_ContentPlaceHolder1_ExcluirFormacao" + i).checked == true)
                return true;
        }
    }
    
    alert("Por favor, selecione uma formação para ser excluída!");
    return false;    
}


function verifica_selecionados_experiencia()
{
    var Total = document.getElementById("ctl00_ContentPlaceHolder1_TotalExperiencia").value;
    for(var i = 0; i < Total; i++)
    {
        if (document.getElementById("ctl00_ContentPlaceHolder1_ExcluirExperiencia" + i))
        {
            if (document.getElementById("ctl00_ContentPlaceHolder1_ExcluirExperiencia" + i).checked == true)
                return true;
        }
    }
    
    alert("Por favor, selecione uma experiência profisisonal para ser excluída!");
    return false;
}

function MudaUnidade(Campo) {
    if (Campo.value != "") {
        if (Campo.value.indexOf("http://www") != -1) {
            document.getElementById("popup").action = Campo.value;
            document.getElementById("popup").submit();
        }
        else
            window.location.href = Campo.value;
    }
}