﻿// JScript File
function validaCNPJ(CNPJ) 
{
    //CNPJ = document.validacao.CNPJID.value;
    erro = new String;
    if (CNPJ.length < 18) 
        erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
    if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
    {
        if (erro.length == 0) 
            erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
    }
    //substituir os caracteres que nao sao numeros
    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)) 
        erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";
    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]))
    {
        erro +="Digito verificador com problema!";
    }
    if (erro.length > 0)
    {
        alert(erro);
        return false;
    } 
    else 
    {
        alert("CNPJ valido!");
    }
    return true;
}

function mascara_cpf(cpf)
{
    var mycpf = '';
    mycpf = mycpf + cpf.value;
   
    if (mycpf.length == 3)
    {
        mycpf = mycpf + '.';
        cpf.value = mycpf;
    }
    if (mycpf.length == 7)
    {
        mycpf = mycpf + '.';
        cpf.value = mycpf;
    }
    if (mycpf.length == 11)
    {
        mycpf = mycpf + '-';
        cpf.value = mycpf;
    }
    if (mycpf.length == 14)
    {
   
    }
}

function mascara_cnpj(cnpj)
{
    var mycnpj = '';
    mycnpj = mycnpj + cnpj.value;
   
    if (mycnpj.length == 2)
    {
        mycnpj = mycnpj + '.';
        cnpj.value = mycnpj;
    }
    if (mycnpj.length == 6)
    {
        mycnpj = mycnpj + '.';
        cnpj.value = mycnpj;
    }
    if (mycnpj.length == 10)
    {
        mycnpj = mycnpj + '/';
        cnpj.value = mycnpj;
    }
    if (mycnpj.length == 15)
    {
        mycnpj = mycnpj + '-';
        cnpj.value = mycnpj;
    }
}

function mascaraTelefone(telefone)
{
    var meuTelefone = '';
    meuTelefone = meuTelefone + telefone.value;
   
    if (meuTelefone.length == 0)
    {
        meuTelefone = meuTelefone + '(';
        telefone.value = meuTelefone;
    }
    if (meuTelefone.length == 3)
    {
        meuTelefone = meuTelefone + ')';
        telefone.value = meuTelefone;
    }
    if (meuTelefone.length == 8)
    {
        meuTelefone = meuTelefone + '-';
        telefone.value = meuTelefone;
    }
    if (meuTelefone.length == 14)
    {
   
    }
}

function mascaraData(data)
{
    var xdata = '';
    xdata = xdata + data.value;
   
    if (xdata.length == 2)
    {
        xdata = xdata + '/';
        data.value = xdata;
    }
    if (xdata.length == 5)
    {
        xdata = xdata + '/';
        data.value = xdata;
    }
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function cv_senha_perdida()
{
	email	=	window.prompt('Para recuperar sua senha digite seu E-mail:','');

	if(email != null)
	{
		xmlhttp	=	mount_XMLHttp();
		url	=	"trabalheconosco_login_email.aspx?email="+email;
		xmlhttp.open("GET", url,true);
	
		xmlhttp.onreadystatechange=function() {
		
			if(xmlhttp.readyState==4){
				alert(xmlhttp.responseText);
			}
		}
	
	xmlhttp.send(null);
	}
}

function mount_XMLHttp()
{
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
return xmlhttp;
}

function popUp(URL) 
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');");
}

function popUp2(URL) 
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=700');");
}

function OnTipoChanged(cmbTipo) {
    CmbMarca.PerformCallback(cmbTipo.GetValue().toString());
}

function OnAreaChanged(cmbArea) {
    CmbCargo.PerformCallback(cmbArea.GetValue().toString());
}

function OnMarcaChanged(cmbMarca) {
    pesmarca.PerformCallback(cmbMarca);
    return false;
}
    




