//**** Função mouseOver ****
function mouseOver(imageName)
{
	document[imageName].src = "img/" + imageName + "_on.gif";
}


//**** Função mouseOut ****
function mouseOut(imageName)
{
	document[imageName].src = "img/" + imageName + ".gif";
}


//**** Função para exibir a descrição dos programas, esconde e exibe divs ****
function showProgram(prg)
{
	var displayPrg = document.getElementById(prg).style.display;

	for (i=1; i<9; i++){
		document.getElementById('prg'+i).style.display = 'none';
	}
	if (displayPrg == ''){
		document.getElementById(prg).style.display = 'none';
	}
	else{
		document.getElementById(prg).style.display = '';
	}
}


//**** Função para limpar o value dos campos ****
function limparTexto(obj){
	if(obj!=null)
		if((obj.value =='Nome')||(obj.value =='Telefone')||(obj.value =='E-mail')||(obj.value =='Mensagem'))
			obj.value ='';
}


//**** Função para enviar o formulário de contato ****
function enviarContato(){
	if((document.frm.nome.value=='')||(document.frm.nome.value=='Nome')){
		alert('Preencha corretamente o campo Nome.');
		document.frm.nome.focus();
	}
	else if((document.frm.telefone.value=='')||(document.frm.telefone.value=='Telefone')){
		alert('Preencha corretamente o campo Telefone.');
		document.frm.telefone.focus();
	}
	else if(!checkMail()){
		alert('Preencha corretamente o campo E-mail.');
		document.frm.email.focus();
	}
	else if((document.frm.mensagem.value=='')||(document.frm.mensagem.value=='Mensagem')){
		alert('Escreva uma mensagem.');
		document.frm.mensagem.focus();
	}
	else {
		document.frm.action='contato_feedback.asp';
		document.frm.submit();
	}
}


//**** Função para validar email ****
function checkMail(){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(document.frm.email.value) == "string"){
		if(er.test(document.frm.email.value)){
			return true;
		}
	}else if(typeof(document.frm.email.value) == "object"){
		if(er.test(document.frm.email.value)){ 
			return true; 
		}
	}else{
		return false;
		}
}


//**** Função que permite apenas a digitação de números em um campo ****
function somenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    
	if (tecla >95 && tecla<106)
		return true;
		    
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if ((tecla != 8)&& (tecla != 16) && (tecla != 37) && (tecla != 39) && (tecla != 46) && (tecla != 35) && (tecla != 36)) return false;
    else return true;
    }
}


//**** Função que permite apenas a digitação de letras em um campo ****
function somenteLetras(e){
    var tecla=(window.event)?event.keyCode:e.which;
       
	if (tecla >96 && tecla<105)
		return false;
   
	if (( tecla < 47 || tecla > 58 )) return true;
    else{
		if (tecla != 8) 
			return false;
		else 
			return true;
    }
}


//Função para determinar o maxLength em campos textarea
function maxLength(textAreaField, limit) {
	var ta = document.getElementById(textAreaField);
	
	if (ta.value.length >= limit) {
		ta.value = ta.value.substring(0, limit-1);
	}
}

//Função para abrir janela popup
function OpenWindow(pagina,largura,altura) {
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;
	
	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	
	//abre a nova janela, já com a sua devida posição
	self.open(pagina,'pop','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+''); 
}
