

/* ------------ jQuery ------------- */

jQuery().ready(function(J){

	
J('#menu li').hover(
		function(){
			J(this).addClass('hover');
			J(this).css('z-index',65);
		},
		function(){
			var self = J(this);
			self.removeClass('hover');
		}
	);

J('#submenu li').hover(
		function(){
			J(this).addClass('hover');
		},
		function(){
			var self = J(this);
			self.removeClass('hover');
		}
	);
	
	J('form #cpf').mask('999.999.999-99', { placeholder:"_", allowPartial: true });
	J.mask.definitions['~']='[0-9\\-./]';  
	J('form #cnpjcpf').mask('~~~~~~~~~~~~~~~~~~', { placeholder:" "});
	
});


function validarContato(objForm){
	msgErro = "";
	if(Trim(objForm.nome.value) == ""){
		msgErro = "<p>Nome</p>";
	}
	if(!checkMail(objForm.email.value)){
		msgErro += "<p>Email</p>";
	}
	if(Trim(objForm.fone.value) == ""){
		msgErro += "<p>Fone</p>";
	}
	if(Trim(objForm.mensagem.value) == ""){
		msgErro += "<p>Informe sua mensagem</p>";
	}

	if(msgErro != ""){
		msgErro = "<p>Informe os seguintes campos: </p>"+msgErro;
		mensagemErro(msgErro);
		return false;
	 } else{
	 	objForm.submit();
	 }
	
}

function mensagemErro(msgErro){
	document.getElementById('divMsg').innerHTML = 	msgErro + '<a href="#" onClick="document.getElementById(\'divMsgPai\').style.display = \'none\';">Fechar</a>';
	document.getElementById('divMsgPai').style.display = 'block';
}

function mostrarConteudoAjax(site,conteudo){

	//window.open(site+'conteudoAjax/'+conteudo,'Útil','width=500px');

	new Ajax.Request(site+'conteudoAjax/'+conteudo, {
	    onSuccess: function(transport){
	      var response = transport.responseText || "no response text";
	      jQuery.facebox(response);/*
	      J("#divMsg").html(response+"<br><br><br>");
	      J("divMsgPai").style.width = '600px';
	      J("divMsgPai").style.margin = '0px 0px 0px -300px';
	      J("divMsgPai").style.display = 'block';
			J("#divMsg").css('width','600px');
			J("#divMsg").css('margin', '0px 0px 0px -300px');
			J("#divMsg").css('display', 'block');
			alert(response);*/
	    },
	    onFailure: function(){ alert('Something went wrong...') }
	});

	return false;
}
function enviarEsqueciCodigo(site,conteudo, objForm){

	new Ajax.Request(site+'conteudoAjax/'+conteudo, {
		method:'post',
	    onSuccess: function(transport){
	      var response = transport.responseText || "no response text";
	      J("#divMsg").html("Sua solicitação foi enviada com sucesso. Em breve entraremos em contato.<br><br><br>");
	      alert('Sua solicitação foi enviada com sucesso.');
	    },
	    parameters: {matricula: objForm.matricula.value},
	    onFailure: function(){ alert('Something went wrong...') }
	});

	return false;
}
/*********************************
VALIDA EMAIL
*********************************/
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
			return true;
		}
    }else{
        return false;
	}
}

function Trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}

function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

	tam = s.length + 1;

	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;

		case 'CNPJ' :

			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;

		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;

 		case 'CEP' :
			if (tam == 6)
				campo.value = s +'-';

		break;

		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}


/*********************************
PERMITE SOMENTE NUMEROS NO CAMPO
onkeypress="return somenteNumero(event);"
*********************************/
function somenteNumeros(e) {
	if (!e) e = window.event;
	var tecla;
	if(e.keyCode)    tecla = e.keyCode;
	else if(e.which) tecla = e.which; //Netscape 4.?

	if ((tecla > 47 && tecla < 58) || (tecla == 44 && campo.value.indexOf(",") == -1) || (tecla == 8) || (tecla == 9)){
		return true;
	} else{
		return false;
	}
}


function calcula() {
	if (document.form_emprestimo.valor_emprestimo.value == '3.000,00') {
		if  (document.form_emprestimo.nr_parcelas.value == '1') {
			document.form_emprestimo.valor_cada_cheque.value = '3.045,00';
			document.form_emprestimo.valor_total_cheque.value = '3.045,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '2') {
			document.form_emprestimo.valor_cada_cheque.value = '1.530,00';
			document.form_emprestimo.valor_total_cheque.value = '3.060,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '3') {
			document.form_emprestimo.valor_cada_cheque.value = '1.030,00';
			document.form_emprestimo.valor_total_cheque.value = '3.090,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '6') {
			document.form_emprestimo.valor_cada_cheque.value = '530,00';
			document.form_emprestimo.valor_total_cheque.value = '3.180,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '12') {
			document.form_emprestimo.valor_cada_cheque.value = '280,00';
			document.form_emprestimo.valor_total_cheque.value = '3.360,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '18') {
			document.form_emprestimo.valor_cada_cheque.value = '195,00';
			document.form_emprestimo.valor_total_cheque.value = '3.510,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '24') {
			document.form_emprestimo.valor_cada_cheque.value = '155,00';
			document.form_emprestimo.valor_total_cheque.value = '3.720,00';			
		}								
	}

   if (document.form_emprestimo.valor_emprestimo.value == '5.000,00') {
		if  (document.form_emprestimo.nr_parcelas.value == '1') {
			document.form_emprestimo.valor_cada_cheque.value = '5.075,00';
			document.form_emprestimo.valor_total_cheque.value = '5.075,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '2') {
			document.form_emprestimo.valor_cada_cheque.value = '2.550,00';
			document.form_emprestimo.valor_total_cheque.value = '5.100,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '3') {
			document.form_emprestimo.valor_cada_cheque.value = '1.710,00';
			document.form_emprestimo.valor_total_cheque.value = '5.130,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '6') {
			document.form_emprestimo.valor_cada_cheque.value = '880,00';
			document.form_emprestimo.valor_total_cheque.value = '5.280,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '12') {
			document.form_emprestimo.valor_cada_cheque.value = '465,00';
			document.form_emprestimo.valor_total_cheque.value = '5.580,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '18') {
			document.form_emprestimo.valor_cada_cheque.value = '325,00';
			document.form_emprestimo.valor_total_cheque.value = '5.850,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '24') {
			document.form_emprestimo.valor_cada_cheque.value = '255,00';
			document.form_emprestimo.valor_total_cheque.value = '6.120,00';			
		}								
	}

   if (document.form_emprestimo.valor_emprestimo.value == '8.000,00') {
		if  (document.form_emprestimo.nr_parcelas.value == '1') {
			document.form_emprestimo.valor_cada_cheque.value = '8.120,00';
			document.form_emprestimo.valor_total_cheque.value = '8.120,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '2') {
			document.form_emprestimo.valor_cada_cheque.value = '4.080,00';
			document.form_emprestimo.valor_total_cheque.value = '8.160,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '3') {
			document.form_emprestimo.valor_cada_cheque.value = '2.740,00';
			document.form_emprestimo.valor_total_cheque.value = '8.220,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '6') {
			document.form_emprestimo.valor_cada_cheque.value = '1.410,00';
			document.form_emprestimo.valor_total_cheque.value = '8.460,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '12') {
			document.form_emprestimo.valor_cada_cheque.value = '740,00';
			document.form_emprestimo.valor_total_cheque.value = '8.880,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '18') {
			document.form_emprestimo.valor_cada_cheque.value = '520,00';
			document.form_emprestimo.valor_total_cheque.value = '9.360,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '24') {
			document.form_emprestimo.valor_cada_cheque.value = '410,00';
			document.form_emprestimo.valor_total_cheque.value = '9.840,00';			
		}								
	}

   if (document.form_emprestimo.valor_emprestimo.value == '10.000,00') {
		if  (document.form_emprestimo.nr_parcelas.value == '1') {
			document.form_emprestimo.valor_cada_cheque.value = '10.150,00';
			document.form_emprestimo.valor_total_cheque.value = '10.150,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '2') {
			document.form_emprestimo.valor_cada_cheque.value = '5.100,00';
			document.form_emprestimo.valor_total_cheque.value = '10.200,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '3') {
			document.form_emprestimo.valor_cada_cheque.value = '3.430,00';
			document.form_emprestimo.valor_total_cheque.value = '10.290,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '6') {
			document.form_emprestimo.valor_cada_cheque.value = '1.760,00';
			document.form_emprestimo.valor_total_cheque.value = '10.560,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '12') {
			document.form_emprestimo.valor_cada_cheque.value = '930,00';
			document.form_emprestimo.valor_total_cheque.value = '11.160,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '18') {
			document.form_emprestimo.valor_cada_cheque.value = '650,00';
			document.form_emprestimo.valor_total_cheque.value = '11.700,00';			
		}
		if  (document.form_emprestimo.nr_parcelas.value == '24') {
			document.form_emprestimo.valor_cada_cheque.value = '510,00';
			document.form_emprestimo.valor_total_cheque.value = '12.240,00';			
		}								
	}

}		

function numdias(mes,ano) {    
	if((mes<8 && mes%2==1) || (mes>7 && mes%2==0)) return 31;    
	if(mes!=2) return 30;    
	if(ano%4==0) return 29;    
	return 28;
}

function somadias() { 
x = 1;
while(x<=24){
document.getElementById( 'data'+x ).value = "";
x = x+1;
}
var r = new Date();
d = (r.getDate() + '/' + (r.getMonth()+1) + '/' + r.getFullYear());
parc = document.form_emprestimo.nr_parcelas.value;
dias = parc * 30;   
data = d.split('/');    
diafuturo = parseInt(data[0])+dias;    
mes = parseInt(data[1]);
ano = parseInt(data[2]); 
 
x = 1;
	while(diafuturo>numdias(mes,ano)) {        
		diafuturo-=numdias(mes,ano);        
		mes++;        
		if(mes>12) {            
			mes=1;            
			ano++;        
		} 
document.getElementById( 'data'+x ).readOnly=false;
if(mes<10) mes='0'+mes; 
document.getElementById( 'data'+x ).value = "20/"+mes+"/"+ano;
x = x+1;
	}
	
}
