/* 
	JS Mixtura

*/

try{
	var xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			var xmlhttp = false;
		}
	}
}

function troca_menu( ref ){
	$( ref ).morph('height:375px;');
	//new Effect.Morph(ref, {style: 'height:100%;'});	

	document.getElementById('dvMenu').style.display = 'none';
	
	//mostra_conteudo
	$( 'dvQuadro' ).appear({ from: 0, to: 1 });
	
	//carrega menus
	$( 'dvMenuItems' ).appear({ from: 0, to: 1, queue: 'end' });	
	
	return false;	
}

function troca_fundo( cor ){
	$('dvFundo').morph('background:#' + cor +';');
	
	return false;
}

function load( what, color, params ){
	//Exibe o texto carregando no div conteúdo
	conteudo = document.getElementById( 'dvConteudo' );
	conteudo.innerHTML = "<br><br><br><br><br><br><br><br><img src='imgs/loading.gif'/>carregando...";

	if( color != '' ){
		troca_fundo( color );
	}

	//Abre a url
	if( params == ""){
		xmlhttp.open("GET", "action.php?act=" + what, true);
	}else{
		xmlhttp.open("GET", "action.php?act=" + what + "&" + params, true);
	}

	//Executada quando o navegador obtiver o código
	xmlhttp.onreadystatechange = function() {

		if (xmlhttp.readyState == 4){
			//Lê o texto
			texto = xmlhttp.responseText;
			//Desfaz o urlencode
			texto = texto.replace(/\+/g, " ");
			texto = unescape( texto );
			//Exibe o texto no div conteúdo
			conteudo.innerHTML = texto;
		}
	}

	xmlhttp.send(null);
}

function sendMail(){
	//get fields
	nome = document.getElementById("edtNome").value;
	mail = document.getElementById("edtMail").value;
	ass = document.getElementById("edtAss").value;
	msg = document.getElementById("txtMsg").value;

	//verifica campos
	if( nome == '' || mail == '' || ass == '' || msg == ''){
		document.getElementById("dvErro").innerHTML = 'Preencha todos os campos para enviar a mensagem!';
		return false;
	}
	
	load(9, '', "nome="+nome +"&mail="+mail +"&ass="+ass +"&msg="+msg);
}
