// JavaScript Document

    var xmlhttp;
    var id;

	function CriaObjetoAjax(){
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {    
        xmlhttp = false;
        }
    }
    
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined' )
    {
        try
        {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e)
        {
            xmlhttp = false;
        }
    }
    }
	
	function extraiScript(texto){
		var ini = 0;
		while (ini!=-1){
			ini = texto.indexOf('<script', ini);
			if (ini >=0){
				ini = texto.indexOf('>', ini) + 1;
				var fim = texto.indexOf('</script>', ini);
				codigo = texto.substring(ini,fim);
				novo = document.createElement("script")
				novo.text = codigo;
				document.body.appendChild(novo);
			}
		}
	}	

	function change(){
		
	if (xmlhttp.readyState==1){
    	document.getElementById(x_id).innerHTML='<img src="img/loading.gif" width="16" height="16" />';
	}

		if (xmlhttp.readyState==4){
			texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
			document.getElementById(x_id).innerHTML=texto;
			extraiScript(texto);
        }
			
    }		
	
    function CarregaPagina(id,acao,dados){
		url = "funcao.asp?acao="+acao;
		campos = "&id="+dados;
		x_id = id;

		CriaObjetoAjax();

		if (xmlhttp) {
			xmlhttp.open("GET",url+campos,true);	
			xmlhttp.onreadystatechange=change;
			xmlhttp.send(null);	
		}
    }
	
    function EnviaForm(url,campos,id){    
		CriaObjetoAjax();
		x_id = id;
		document.getElementById(x_id).innerHTML="";
		if (xmlhttp) {
			xmlhttp.open("GET",url+campos,true);
			xmlhttp.onreadystatechange=change;
			xmlhttp.send(null);	
		}
    }
	
	function setarIndique() {
		campos = "?nome="+encodeURI(document.getElementById('frm_indique_nome').value);
		campos += "&email="+encodeURI(document.getElementById('frm_indique_email').value);
		campos += "&nomeamigo="+encodeURI(document.getElementById('frm_indique_nomeamigo').value);
		campos += "&emailamigo="+encodeURI(document.getElementById('frm_indique_emailamigo').value);
		campos += "&acao=form_indique";
	}	

	function mostra(item1,ops){
		var item1 = document.getElementById(item1);
    	if (ops=='none'){
			item1.style.display='none';
		}else{
			item1.style.display='block';
		}
	}
	
	function checkMail(mail){
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(er.test(mail)){ return true; }
		}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){ 
				return true; 
			}
		}else{
			return false;
		}
	}
