//<!--

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 alterna(quem){
	for(var i = 1; i < 5; i++){
		t = 'frota' + i;
		
		document.getElementById(t).style.background = 'url("imagens/bot_interno_a.jpg")';
	}
	
	z = 'frota' + quem;

	document.getElementById(z).style.background = 'url("imagens/bot_interno_b.jpg")';
}

function validaForm(id){
	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) || ! er1.test(f.mensagem.value)) {
				msgErro(1);
				
				f.nome.focus();
				
				return false;
			}

			f.submit();
			
			break;
			
		case 2:
			f = document.formOrca;
			
			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)) {
				msgErro(1);
				
				f.nome.focus();
				
				return false;
			}

			f.submit();
			
			break;
	}
}

function msgErro(tipo){
	switch (tipo) {
		case 1:
			msg = 'Preencha corretamente todos os campos do formulário. Obrigado.';
					
			break;
	}

	alert (msg);
}

//-->
