// JavaScript Document

function link_util(link){
		// eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		//parent.location = (link);

		window.open(link);
	}
	
function carregaBannerDireita(titulo, url, imagem){

	var i = 0;
	
	var titulo2 = titulo.split(";");
	var url2 = url.split(";");
	var imagem2 = imagem.split(";");
	

	if(titulo2.length > 1){
		
		document.getElementById("imagemBannerDireita").src = "banner/"+imagem2[0];
		document.getElementById("linkBannerDireita").href=url2[0];
		document.getElementById("imagemBannerDireita").alt=titulo2[0];
		document.getElementById("imagemBannerDireita").title=titulo2[0];
		//document.getElementById("tituloBanner").innerHTML = titulo2[0];
	}
	
	if(titulo2.length > 2){
		setTimeout("alteraBannerDireita('"+titulo2+"','"+url2+"','"+imagem2+"' , 1)", 5000);
	}

	
}

function alteraBannerDireita(titulo, url, imagem, pos) {
	
	titulo = titulo.split(",");
	url = url.split(",");
	imagem = imagem.split(",");
	
	
	
	document.getElementById("imagemBannerDireita").src = "banner/"+imagem[pos];
	document.getElementById("linkBannerDireita").href=url[pos];
	document.getElementById("imagemBannerDireita").alt = titulo[pos];
	document.getElementById("imagemBannerDireita").title = titulo[pos];
	//document.getElementById("tituloBanner").innerHTML = titulo[pos];
	
	if(imagem.length - 2 > pos){
     	//alert(pos);
	 	pos = pos + 1;
	setTimeout("alteraBannerDireita('"+titulo+"', '"+url+"', '"+imagem+"', "+pos+")", 5000);
	}
	else{
		pos = 0;
		setTimeout("alteraBannerDireita('"+titulo+"', '"+url+"', '"+imagem+"', "+pos+")", 5000);
	}

  }


function carregaBannerColaborador(titulo, url, imagem){

	var i = 0;
	
	var titulo2 = titulo.split(";");
	var url2 = url.split(";");
	var imagem2 = imagem.split(";");
	//alert(titulo2[0]);
	//banner = document.getElementById("contribua").innerHtml;
	//alert(banner);
	if(titulo2.length > 1){
		document.getElementById("imagemBannerColaborador").src = "banner/"+imagem2[0];
		document.getElementById("linkBannerEsquerda").href=url2[0];
		document.getElementById("imagemBannerColaborador").alt=titulo2[0];
		document.getElementById("imagemBannerColaborador").title=titulo2[0];
	}
	
	if(titulo2.length > 2){
	
		setTimeout("alteraBannerColaborador('"+titulo2+"','"+url2+"','"+imagem2+"' , 1)", 5000);
	}

	
}

function alteraBannerColaborador(titulo, url, imagem, pos) {
	
	titulo = titulo.split(",");
	url = url.split(",");
	imagem = imagem.split(",");
	
	
	
	document.getElementById("imagemBannerColaborador").src = "banner/"+imagem[pos];
	document.getElementById("linkBannerEsquerda").href=url[pos];
	document.getElementById("imagemBannerColaborador").alt = titulo[pos];
	document.getElementById("imagemBannerColaborador").title = titulo[pos];
	
	if(imagem.length - 2 > pos){
     	//alert(pos);
	 	pos = pos + 1;
	setTimeout("alteraBannerColaborador('"+titulo+"', '"+url+"', '"+imagem+"', "+pos+")", 5000);
	}
	else{
		pos = 0;
		setTimeout("alteraBannerColaborador('"+titulo+"', '"+url+"', '"+imagem+"', "+pos+")", 5000);
	}

  }
  
  function ampliaFoto(imagem, legenda){

	  	document.getElementById("fotoAmpliada").src="img/galeria/"+imagem;
		document.getElementById("fotoAmpliada").alt=legenda;
		return false;
	  
	  }
	  
function isEmail(text){
   var    arroba = "@",
          ponto = ".",
         posponto = 0,
         posarroba = 0;
   
    if (text =="") return false;
   
    for (var indice = 0; indice < text.length; indice++){
       if (text.charAt(indice) == arroba) {
          posarroba = indice;
            break;
       }
    }
   
   for (var indice = posarroba; indice < text.length; indice++){
      if (text.charAt(indice) == ponto) {
         posponto = indice;
           break;
      }
   }
   if (posponto == 0 || posarroba == 0) return false;
   if (posponto == (posarroba + 1)) return false;
   if ((posponto + 1) == text.length) return false;
   return true;
}

function isEmpty(campo){ 
   var   len = campo.length; 
   var pos; 
   var vStrnewtext = ""; 

   for (pos=0; pos<len; pos++){ 
      if (campo.substring(pos, (pos+1)) != " "){ 
         vStrnewtext = vStrnewtext + campo.substring(pos, (pos+1)); 
      } 
   } 

   if (vStrnewtext.length > 0) 
      return false; 
   else 
      return true; 
}
function ajaxInit() {
var req;

try {
 req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
 try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
 } catch(ex) {
  try {
   req = new XMLHttpRequest();
  } catch(exc) {
   alert("Esse browser não tem recursos para uso do Ajax");
   req = null;
  }
 }
}

return req;
}

function cadastraEmail() {
	
	var email = document.getElementById("email").value;
	if(isEmpty(email))
	{
		
		alert("Email não pode ser vazio");
		return false;
	}
	else if(!isEmail(email)){
		
		alert("Formato de email incorreto");
		return false;
	}

		
			/*else{
	
				var ajax = ajaxInit();
				ajax.open("GET", "includes_site/cadastro.php?email="+email, true);
				ajax.onreadystatechange = function() {
				
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						var retVal = ajax.responseText; 
						
						//alert(retVal);
						if(retVal == 1){
							
							alert("E-mail cadastrado com êxito");
								
							}
						if(retVal == 2){
								
								alert("Erro de cadastro, tente novamente");	
							}
							if(retVal == 3){
								
								alert("Este e-mail já está cadastrado");	
							}
							
						} 
						
						
					}
				}
				ajax.send(null); 
				}*/
				else{
				return true;
				}
	
}

function apagaEmail(valor){
		if(valor == "digite seu e-mail"){
			document.getElementById("email").value = "";
		}
		
	
	}
function colocaEmail(valor){
	
		if(isEmpty(valor)){
			document.getElementById("email").value = "digite seu e-mail";
			}
	}
	
function validaDescadastro(){
		
			var email = document.getElementById("txtEmail").value;
				if(isEmpty(email))
				{
					
					alert("Email não pode ser vazio");
					return false;
				
				}
				else if(!isEmail(email)){
					
					alert("Formato de email incorreto");
					return false;
					}
				else{
					return true;
					}
		}
		
function contato(){
		var nome = document.getElementById("txtNome").value;
		var telefone = document.getElementById("txtTelefone").value;
		var email = document.getElementById("txtEmailContato").value;
		var assunto = document.getElementById("slcAssunto").value;
		var mensagem = document.getElementById("txtMensagem").value;

		if(isEmpty(email) || isEmpty(nome) || isEmpty(telefone) || isEmpty(email) || isEmpty(assunto) || isEmpty(mensagem))
				{
					
					//alert("Email não pode ser vazio");
					document.getElementById("erro").innerHTML = "<p><img src='img/icone_erro.jpg' />Alguns campos são de preenchimento obrigatório!</p>";
					return false;
				
				}
				else if(!isEmail(email)){
					
					document.getElementById("erro").innerHTML = "<p><img src='img/icone_erro.jpg' />Formato de email incorreto.</p>";
					//alert("Formato de email incorreto");
					return false;
					}
				else{
					return true;
					}
	}