function createXMLHTTP(){
		var ajax;
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
				alert(ajax);
			} catch(ex) {
				try {
					ajax = new XMLHttpRequest();
				} catch(exc) {
					 alert("Esse browser não tem recursos para uso do Ajax");
					 ajax = null;
				}
			}
			return ajax;
		}
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
		for (var i=0; i < arrSignatures.length; i++){
			try	{
				var oRequest = new ActiveXObject(arrSignatures[i]);
				return oRequest;
			} catch (oError) {
			}
		}
		throw new Error("MSXML is not installed on your system.");
}

function create_opcao(subcategoria) { 
    var new_opcao = document.createElement("option"); 
    var texto = document.createTextNode(subcategoria.childNodes[0].data);
    new_opcao.setAttribute("value",subcategoria.getAttribute("cod")); 
    new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
   return new_opcao; // Retorna a nova OPTION.
}

function enviaContato(idioma){
	var mensagem = new Array('Data sent successfully. Soon we will contact you.','Dados enviados com sucesso. Em breve entraremos em contato.');
	var camposobrig = new Array('All fields are required','Todos os campos sao obrigatorios');
	var email = document.getElementById('email').value;
	var name = document.getElementById('name').value;
	var subject = document.getElementById('subject').value;
	var message = document.getElementById('message').value;
	if(email == "" || name == ""  || subject == ""  || message == ""){
		alert(camposobrig[idioma]);
	} else {
		var HttpReq = createXMLHTTP();
		HttpReq.open("GET", "envia.php?email=" + email + "&name=" + name + "&subject=" + subject + "&message=" + message, true);
		HttpReq.onreadystatechange=function(){
		if (HttpReq.readyState == 4 && HttpReq.status == 200){
        			var result = HttpReq.responseXML;
        			var subcategorias = result.getElementsByTagName("nome");
					if(subcategorias[0].getAttribute("cod") == 0){
						alert(mensagem[idioma]);
						document.getElementById('contato').reset();
					}
    	}
		}
		HttpReq.send(null);
	}
}
