//<!--

var req;
var alvo;
var carregando = '<table width="100%" border="0"><tr><td width="100%"><img src="imagens/loader.gif" border="0"></td></tr></table>';

function loadXMLDoc(url){
	req = null;

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange1;
		req.open("GET", url, true);
		req.send('');
	} else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		} catch(e) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
			} catch(e) {
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e) {
						req = false;
					}
				}
			}
		}
		if (req) {
			req.onreadystatechange = processReqChange1;
			req.open("GET", url, true);
			req.send('');
		}
	}
}

function processReqChange1(){ 
	if (req.readyState == 4) {
		if (req.status == 200) {
			texto = req.responseText.replace(/\+/g," ");
			
			extraiScript(texto);

			document.getElementById(alvo).innerHTML = req.responseText;
		} else {
			alert("Houve um problema ao atualizar os dados:\n" + req.statusText);
		}
	} else {
		document.getElementById(alvo).innerHTML = carregando;
	}
}

function atualiza(url, target){
	alvo = target;
	
	loadXMLDoc(url);
}

function extraiScript(texto){
	/*
	 * Autor: SkyWalker.TO do imasters/forum 
	 * http://forum.imasters.com.br/index.php?showtopic=165277
	 * 
	 * Permite a esecução de um script/função como retorno do HttpRequest/Ajax
	 */
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}

function newsletter(email, idioma) {
	er1 = /[A-Za-z0-9_.-]+@([A-Za-z0-9_-]+)+\.[A-Za-z]{2,}/;
	
	if (! er1.test(email)) {
		msgErro(2, idioma);
	} else {
		atualiza('newsletter.php?email=' + email, 'divN');
	}
}

var intContaTam = 0;
var vetFonte = new Array ();
vetFonte [0] = "12px";
vetFonte [1] = "13px";
vetFonte [2] = "14px";
vetFonte [2] = "16px";
vetFonte [2] = "18px";
vetFonte [2] = "20px";

function tamTexto (strAD) {
	
	if (strAD=="A") {
		intContaTam++;
		if (intContaTam>=vetFonte.length)
			intContaTam = vetFonte.length-1;
		document.getElementById('spanTexto').style.fontSize = vetFonte[intContaTam];
	} else {
		intContaTam--;
		if (intContaTam<0)
			intContaTam=0;
		document.getElementById('spanTexto').style.fontSize = vetFonte[intContaTam];
	}
}

function validaForm(id, idioma){
	switch (id)	{
		case 1:
			f = document.formFale;
			
			er1 = /[A-Za-z]{3,}/;
			er2 = /[A-Za-z0-9_.-]+@([A-Za-z0-9_-]+)+\.[A-Za-z]{2,}/;
			
			if(! er1.test(f.nome.value) || ! er2.test(f.email.value) || f.telefone.value == '' || ! er1.test(f.mensagem.value)) {
				msgErro(1, idioma);
				
				f.nome.focus();
				
				return false;
			}

			return true;
			
			break;
	}
}

function msgErro(tipo, idioma){
	switch (idioma) {
		case 'en':
			switch (tipo) {
				case 1:
					msg = 'Fill all form fields. Thank you.';
							
					break;
					
				case 2:
					msg = 'Fill the e-mail address. Thank you.';
							
					break;
			}
			
			break;
			
		case 'pt-br':
			switch (tipo) {
				case 1:
					msg = 'Preencha corretamente todos os campos do formulário. Obrigado.';
							
					break;
					
				case 2:
					msg = 'Informe corretamente o e-mail para cadastro. Obrigado.';
							
					break;
			}
			
			break;
	}

	alert (msg);
}

//-->

