//Permite apenas numeros
function soNumero(evento){
	var BACKSPACE=  8; 
	var TAB= 9;
    var DEL=  46; 
    var FRENTE=  39; 
    var TRAS=  37; 
    var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
    
    if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)||(tecla == TAB)){
         return true; 
	}
    if ( tecla == 13 )     return false; 

	if ((tecla >= 48 && tecla <= 57) || (tecla == 44)) {
		return true;
	}else{
		evento.returnValue = false; 
		return false;
	}
}


//Ajustar Telefone
function ajustarFone(input, evento){
	var ie = (typeof window.ActiveXObject != 'undefined');  
	var tecla;  
	if (ie)
		tecla = evento.keyCode;
	else
		tecla = evento.which; 

	valor = input.value;
	valor = valor.replace( "(", "" );
	valor = valor.replace( ")", "" );
	valor = valor.replace( " ", "" );
	valor = valor.replace( "-", "" );
	tamanhoMaximo = 10;
	tamanho = valor.length;
	if(!soNumero(evento)){
		return false;
	} else { 
		if (tamanho < tamanhoMaximo && tecla != 8) {
		tamanho = valor.length + 1 ;
		}
		if (tecla == 8 ) {
			tamanho = tamanho - 1 ;
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
			if ( tamanho <= 4 ) { 
				input.value = valor ;
			}
			if ( (tamanho > 4) && (tamanho <= 8) ) {
				input.value = valor.substr(0,tamanho-4) + '-' + valor.substr( tamanho - 4, tamanho ) ;
			}
			if ( (tamanho >= 9) && (tamanho <= 10) ) {
				input.value = '(' + valor.substr(0,2) + ') ' + valor.substr(2,tamanho-6) + '-' + valor.substr(tamanho-4,tamanho) ;			
			}
		}
	}
	return true;
}

//Completa a data com as barras "/"
function ajustarData(input, evento){
    if(!soNumero(evento)){
	    return false;
	} else { 
		if ((input.value.length == 2)||(input.value.length == 5)) {
		   input.value = input.value + "/" ;
		   }
	}
	return true;
}

// Valida endereço de e-mail
function validaEmail(email){
	var resultado = false
	var emailStr = new String(email)
	var index = emailStr.indexOf("@");
	if (index > 0){
		var indice = emailStr.indexOf(".",index);
		if ((indice > index+1) && (emailStr.length > indice+1)){
			resultado = true;
		}
	}
	return resultado;
}


function mudaImagem(img){
	var texto = '<img src="fig_projeto/'+ img +'" style="border: 6px solid #fff;" />';
	document.getElementById("figuras_projetos").innerHTML = texto;
}


//valida a pagina Contato
function validaContato(){
	with(document.frm_contato){
		if (nome.value == ""){
			alert("Insira seu Nome.");
			nome.focus();	
			return false;
		}else if(email.value == ""){
			alert("Insira seu e-mail.");
			email.focus();
			return false;
		}else if(!validaEmail(email.value)){
			alert("E-mail Inválido. Verifique seu email.");
			email.focus();
			return false;
		}else if(comentarios.value == ""){
			alert("Escreva a sua Mensagem.");
			comentarios.focus();
			return false;
		}else if(hex_md5(uword.value) != cword.value){
			alert("Verificação de segurança não confere.");
			uword.focus();
			return false;
		}else{
			submit();
			return true;
		}
	}	
}

function validaNewsletter(idN){
	with(document.frm_newsletter){
		if (idN == "1" || idN == 1){
			if (txt_email_news_home.value == "" || txt_email_news_home.value == "SEU E-MAIL AQUI"){
				alert("Insira o Email antes de confirmar.");
				txt_email_news_home.focus();
				return false;
			}else{
				submit();
				return true;
			}
		}else{
			if (txt_email_news.value == ""){
				alert("Insira o Email antes de confirmar.");
				txt_email_news.focus();
				return false;
			}else{
				submit();
				return true;
			}
		}
	}
}

$(document).ready(function(){

	$(function() {
		for(i=0; i<=6; i++){
			$('#caixa_externa_'+i).hover(function(){
				$(this).find('div').animate({top:'0px'},{queue:false,duration:500});
			}, function(){
				$(this).find('div').animate({top:'133px'},{queue:false,duration:500});
			});
		}
	});

});
