// JavaScript Document
function MostraImagem(id, new_image){

	new_image = "imgs/"+new_image +".png";
	document.getElementById(id).src=new_image;
}
function MostraPagina(nome){
		window.open(nome);
}

function validaForm(){
	var texto = "\n";
	var error = false;
	if (document.getElementById("nome").value==""){
		error = true;
		texto = texto + "- Nome \n";
	}
	if (document.getElementById("email").value==""){
		error = true;
		texto = texto + "- E-mail \n";
	}else{
		if (!ValidaEmail(document.getElementById("email").value)){
			error = true;
			document.getElementById("email").value = "";
			texto = texto + "- E-mail inválido \n";
		}
	}
	if (document.getElementById("assunto").value==""){
		error = true;
		texto = texto + "- Assunto \n";
	}
	if (document.getElementById("msg").value==""){
		error = true;
		texto = texto + "- Mensagem \n";
	}
	if (error){
		alert ('Verifique o(s) campo(s) abaixo: '+ texto +'\n Todos os campos são de preenchimento obrigatório');
	}else{
		
		document.getElementById("enviando").style.display = "block";
		var oHTTPRequest = createXMLHTTP(); 
		
		oHTTPRequest.open("post", "SendEmail.php", true); 
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		oHTTPRequest.onreadystatechange=function(){
			if (oHTTPRequest.readyState==4){
				var ErrorAlreadyExists = oHTTPRequest.responseText;
				alert (ErrorAlreadyExists);
				
				/*if (ErrorAlreadyExists=="ok"){
					alert ('Mensagem Enviado com sucesso!');
					window.location='http://www.bandacannes.com.br';
				}else{
					alert ('Problema ao tentar enviar a mensagem. \nTente novamente mais tarde.');
					window.location='Contato.php';
				}
				*/
				window.location='http://www.bandacannes.com.br';
				
				document.getElementById("enviando").style.display = "none";
				
			}
	}
	oHTTPRequest.send("nome="+ document.getElementById("nome").value +"&email="+ document.getElementById("email").value +"&assunto="+ document.getElementById("assunto").value +"&msg="+ document.getElementById("msg").value);
	
	}
	return false;
}

function ValidaEmail(mailvalue){
	if ( mailvalue.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1 ) {
		return false;
	}else{
		return true;
	}
}