// JavaScript Document

//INICIA AJAX
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;
}


//CADASTRA NEWSLETTER
function enviaSugestao(lan) {
	ajax = ajaxInit();
	if(ajax) {
		noCache = new Date().getTime();
		var texto = encodeURIComponent(document.getElementById('textosugestao').value);
		var param = 'nc='+noCache+'&texto='+texto+'';
		
		if (lan == 'pt') document.getElementById('status_envio').innerHTML = 'Aguarde, sua sugestão está sendo enviada...';
		else document.getElementById('status_envio').innerHTML = 'Sendind suggestion...';

		if (lan == 'pt') ajax.open('POST','sugestao.php', true);
		else ajax.open('POST','sugestao_en.php', true);
		
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(param);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					var retorno = ajax.responseText;
					//alert(retorno);
					if (retorno != "") {
						if (lan == 'pt') document.getElementById('status_envio').innerHTML = 'Envie sua sugestão e ajude-nos a aprimorarmos nossos serviços';
						else document.getElementById('status_envio').innerHTML = 'Share your suggestion and help us improve our services';
						
						document.getElementById('textosugestao').value = '';
						alert(retorno);
					} 
				} else {
					alert(ajax.statusText);
				}
			}
		}
	}
	
	return false;
}

function checaArea(lan) {
	if (!document.getElementById('pesquisa').value)	 {
		if (lan == 'pt') alert('Escolha uma área para a pesquisa');	
		else alert('Choose an area to research');	
		return false;
	}
	
	if (!document.getElementById('texto').value) {
		if (lan == 'pt') alert('Forneça uma palavra para a pesquisa');	
		else alert('Enter a word to search');	
		return false;
	}
}
