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

var ajax = {
	
	abreEmail : function() {
		
		div = document.getElementById('conteudo');
		if(!document.getElementById('mail')){
			mail = document.createElement('div');
			mail['id'] = 'mail';
			div.appendChild(mail);
			anime.appear(mail, 0, 100, 500);
			anime.resizeAbre(mail, 35, 35, 350, 18, 18, 180);
			
		}else{
			alert('A tela de e-mail já se encontra aberta!');
		}
		
	},
	
	fechaEmail : function() {
		
		mail.innerHTML = '';	
		anime.fade(mail, 100, 0, 500);		
		anime.resizeFecha(mail, 350, 35, 35, 180, 18, 18);
		
	},
	
	enviaEmail : function(){
		nome = document.getElementById('nome').value
		email = document.getElementById('email').value
		if(nome == "" || nome == null){
			alert("Coloque seu nome!");
			return false;
		}else if(email == "" || email == null){
			alert("Coloque seu endereço de e-mail!");
			return false;
		}else{
			
			param = "nome="+nome+"&email="+email;
			xmlhttp.open("POST", "include/email.php", true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 1) {
					document.getElementById('formulario').innerHTML = carregandoHTML;
				}
				if(xmlhttp.readyState == 4) {
					if(xmlhttp.status == 200){
						document.getElementById('enviandomail').innerHTML = '<span>'+xmlhttp.responseText+'</span>';
					}
				}
			}
			xmlhttp.send(param);
			
		}
		
	},
	
	camposForm : function(oForm){
		var aParams = new Array();
		for (var i=0 ; i < oForm.length; i++) {
			var sParam = oForm[i].id;
			sParam += "=";
			sParam += oForm[i].value;
			aParams.push(sParam);
		}
		return aParams.join("&");
	}

}