// JavaScript Document
function $div(quem) {
	return document.getElementById(quem);
}

function extraiScript(texto){
	
    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);
        }
    }	
}

function __loadPage(page){
		
	$div('divConteudo').style.display 	= "block";
	
	$div('divConteudo').innerHTML = "";
	
	try {
		
		var ajax = null;
		ajax = _initXML_http();
		if(ajax) {//se tiver suporte ajax
	
			var params =  [
			'act=alterar'].join('&');
			
			ajax.open("GET", page, true);
                        
			ajax.onreadystatechange = function() {
				
				//enquanto estiver processando...emite a msg de carregando			
				if(ajax.readyState == 1) {
				   //idOpcao.innerHTML = "Carregando...!  ";   
				}
				
				if(ajax.readyState == 4) {
					
					if(ajax.status == 200) {
						
		                $div('divConteudo').innerHTML = ajax.responseText;
                        //document.getElementById('tblCarregando').style.display 	= 'none';
						texto	= unescape(ajax.responseText.replace(/\+/g," "));
				        extraiScript(texto);				        		               		                

		                //initForm();
		                
					} else {
						<!-- ajax.statusText; -->
						alert("");
					}
				}
			
			}							
			ajax.send(null);
			
		}

  	} catch(e) {
		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");
  	}	
			
}

function _openWindow(page,option){
	window.open(page,"_blank",option);
}

function __PostarContato(){
	
	var Nome		= $div("txtNome").value;
	var Email		= $div("txtEmail").value;	
	var Cidade		= $div("txtCidade").value;
	var Estado		= $div("txtEstado").value;	
	var Pais		= $div("txtPais").value;
	var Telefone	= $div("txtTelefone").value;	
	var Assunto		= $div("cmbAssunto").value;
	var Mensagem	= $div("txtMensagem").value;	

	try {

		var ajax = null;
		ajax = _initXML_http();
		if(ajax) {//se tiver suporte ajax
	
			var params =  [
			'act=enviar',
			'Nome=' + Nome,
			'Email=' + Email,
			'Cidade=' + Cidade,
			'Estado=' + Estado,
			'Pais=' + Pais,
			'Telefone=' + Telefone,
			'Assunto=' + Assunto,
			'Mensagem=' + Mensagem].join('&');
			
			ajax.open("GET", "contato.php?" + params, true);
			
			ajax.onreadystatechange = function() {
				
				//enquanto estiver processando...emite a msg de carregando			
				if(ajax.readyState == 1) {
				   //idOpcao.innerHTML = "Carregando...!  ";   
				}
				
				if(ajax.readyState == 4) {
					
					if(ajax.status == 200) {
				        //alert(ajax.responseText)
						$div('divConteudo').innerHTML = ajax.responseText
		                
					} else {
						
					}
				}
			
			}							
			ajax.send(null);
			
		}
			
  	} catch(e) {
		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");
  	}  					

}
