window.document.write('<script src="/Scripts/jquery-1.4.2.js" language="Javascript" type="text/javascript"></script>');

/******************************************* 
INICIA O AJAX 
********************************************/ 
function openAjax() 
{ 
var ajax; 
try 
{ajax = new XMLHttpRequest();} // Para Firefox, Safari, dentre outros. 
catch(ee) 
{ 
try 
{ajax = new ActiveXObject("Msxml2.XMLHTTP");} // Para o IE da MS 
catch(e) 
{ 
try 
{ajax = new ActiveXObject("Microsoft.XMLHTTP");} // Para o IE da MS 
catch(E) 
{ajax = false;} 
} 
} 
return ajax; 
} 

/******************************************* 
EXIBE TEXTO - AJAX 
********************************************/ 
function exibeTexto(resultado) 
{ 
// resolve o problema com acentos 
resultado = resultado.replace(/\+/g," "); 
resultado = unescape(resultado); 

return resultado; 
} 



/******************************************* 
ABRE OS CONTEUDOS INTERNOS
********************************************/ 
function abreConteudoInt(url,conteudoID) 
{ 
	$(conteudoID).html("carregando...");

	$.get(url, function(data) {
		$(conteudoID).html(data);
	});

} 

function carrega(url,conteudoID) 
{ 
	$("#"+conteudoID).html("carregando...");

	$.get(url, function(data) {
		$("#"+conteudoID).html(data);
		
	});

} 

function carrega2(url,conteudoID) 
{ 

	$("#"+conteudoID).html("carregando...");

	$.get(url, function(data) {
		$("#"+conteudoID).html(data);
	});

} 
 
function abreConteudo(url,conteudoID) 
{ 
	$(conteudoID).html("carregando...");
	$.get(url, function(data) {
		$(conteudoID).html(data);
	});

} 

function PrintElementID(id, pg) {
    var oPrint, oJan;
    oPrint     = window.document.getElementById(id).innerHTML;
    oJan     = window.open(pg);
    oJan.document.write(oPrint);
    oJan.history.go();
    oJan.window.print();
}

function mostraCarinha(imagem,local,voto,id)
{ 
	document.getElementById(local).innerHTML = "<img src='../_imagens/cozinha/"+imagem+"' width='140' height='80'>";

	// Inicia o Ajax. 
	var ajax = openAjax(); 

	// Envia o termo da busca como uma querystring para o filtro 
	ajax.open("GET", "../votos.php?voto="+voto+"&id="+id, true); 
	ajax.onreadystatechange = function() 
	{ 

	if(ajax.readyState == 4 && ajax.status==200) 
		var texto = ajax.responseText;
		eval(texto);
	} 
	ajax.send(null)
  
} 

function voto_enquete(form)
{ 
	// Inicia o Ajax. 
	var ajax = openAjax(); 
    for(i = 0; i < form.length; i++){
        if(form[i].name = "voto" && form[i].checked){
            	var valor = form[i].value;
				break;
        }else{
			var valor ='';
		}
    }

	// Envia o termo da busca como uma querystring para o filtro 
	ajax.open("GET", "../votos.php?voto="+valor+"&s=e", true); 
	ajax.onreadystatechange = function() 
	{ 

	if(ajax.readyState == 4 && ajax.status==200) 
		var texto = ajax.responseText;
		eval(texto);
	} 
	ajax.send(null)

} 


function Contar(Campo){
	document.getElementById("Qtd").innerText = 10-Campo.value.length

}

//envia forms com o metodo post
    function enviar(pagina, local,id) { 
        var grupo = document.getElementById(id).getElementsByTagName('input');
        var stri = "";
        var codigo = "";
        var descricao = "";
        for (i = 0; i < grupo.length; i++) {
            if ((grupo[i].getAttribute('type') != 'button') && (grupo[i].getAttribute('type') != 'checkbox')) {
                codigo    = grupo[i].name;
                descricao = document.getElementById(codigo).value;
                stri = strin(stri,codigo,descricao);
            }else if((grupo[i].getAttribute('type') == 'checkbox') && (grupo[i].checked == true)){
            	 codigo    = grupo[i].name;
                descricao = document.getElementById(codigo).value;
                stri = strin(stri,codigo,descricao)            	
            }
        }
        
        var grupo = document.getElementById(id).getElementsByTagName('select');
        
        for (i = 0; i < grupo.length; i++) {
            codigo    = grupo[i].name;
            descricao = document.getElementById(codigo).value;
            stri = strin(stri,codigo,descricao);
        } 
        carregaPost(pagina, local,stri);
    }

    function strin(str,codigo,valor) {
        if(str) {
            str = str + '&' + codigo + '=' + valor;
        } else {
            str = codigo + '=' + valor;
        }
        return str;
    }

function carregaPost(pagina, local, post){

    xmlhttp.open("POST", pagina,true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
    xmlhttp.setRequestHeader("Pragma", "no-cache");
    xmlhttp.send(post);
    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText;

            var conteudo=document.getElementById(local);
            conteudo.innerHTML=texto;
        }
    }

}

 var max=100; 
 var ancho=300; 
 function progreso_tecla(obj) { 
   var progreso = document.getElementById("progreso");  
   if (obj.value.length < max) { 
		progreso.style.backgroundColor = "#FFFFCC";  
		progreso.style.backgroundImage = "url(../_imagens/papo/mural/textarea.png)";  
		progreso.style.color = "#000000"; 
		var pos = ancho-parseInt((ancho*parseInt(obj.value.length))/100); 
		progreso.style.backgroundPosition = "-"+pos+"px 0px"; 
   } else { 
		obj.value = obj.value.substring(0, 100);
		progreso.style.backgroundColor = "#CC0000";  
		progreso.style.backgroundImage = "url()";  
		progreso.style.color = "#FFFFFF"; 
   }  
   progreso.innerHTML = obj.value.length+" caracteres de "+max; 
 } 
 
    function Contador(field,MaxLength) {
      obj = document.all(field);
      if (MaxLength !=0) {
         if (obj.value.length > MaxLength)  {
            obj.value = obj.value.substring(0, MaxLength);
            }
      }
      document.form1.contador.value = obj.value.length + '/300';
   }
function validaFormRecado(){
	
	if(document.getElementById('sNome').value == ""){
		
		window.alert("Preencha o seu nome!");
		document.getElementById('sNome').focus();
		return false;
		
	}
	
	
	if(document.getElementById('iIdade').value == ""){
		
		window.alert("Preencha o sua idade!");
		document.getElementById('iIdade').focus();
		return false;
		
	}
			
	if(document.getElementById('txtRecado').value == ""){
		
		window.alert("Escreva seu recado!");
		document.getElementById('txtRecado').focus();
		return false;
		
	}	
	
	
	if(document.getElementById('sEmail').value == ""){
		
		window.alert("Preencha o seu e-mail!");
		document.getElementById('sEmail').focus();
		return false;
		
	}
	
	if(document.getElementById('sCidade').value == ""){
		
		window.alert("Preencha sua cidade!");
		document.getElementById('sCidade').focus();
		return false;
		
	}
	return true;	
}

function validaFormGaleria(){
	
	if(document.getElementById('sNome').value == ""){
		
		window.alert("Preencha o seu nome!");
		document.getElementById('sNome').focus();
		return false;
		
	}
	
	
	if(document.getElementById('iIdade').value == ""){
		
		window.alert("Preencha o sua idade!");
		document.getElementById('iIdade').focus();
		return false;
		
	}
			
	
	if(document.getElementById('sEmail').value == ""){
		
		window.alert("Preencha o seu e-mail!");
		document.getElementById('sEmail').focus();
		return false;
		
	}
	
	if(document.getElementById('sDesenho').value == ""){
		
		window.alert("Coloque seu desenho!");
		document.getElementById('sDesenho').focus();
		return false;
		
	}	
	
	if(document.getElementById('sCidade').value == ""){
		
		window.alert("Preencha sua cidade!");
		document.getElementById('sCidade').focus();
		return false;
		
	}	
	return true;
}

function validaFormEnvie(){
	
	
	if(document.getElementById('nome').value == ""){
		
		window.alert("Preencha o seu nome!")
		document.getElementById('nome').focus();
		return false;
		
	}
	
		
	if(document.getElementById('email').value == ""){
		
		window.alert("Preencha o seu e-mail!")
		document.getElementById('email').focus();
		return false;
		
	}
	
	if(document.getElementById('nome_dest').value == ""){
		
		window.alert("Preencha o nome de seu amiguinho!")
		document.getElementById('nome_dest').focus();
		return false;
		
	}	
	
	if(document.getElementById('email_dest').value == ""){
		
		window.alert("Preencha o e-mail de seu amiguinho!")
		document.getElementById('email_dest').focus();
		return false;
		
	}	
	return true;
	
}


function validaFormComente(){
	
	if(document.getElementById('nome').value == ""){
		
		window.alert("Preencha o seu nome!");
		document.getElementById('nome').focus()
		return false;
		
	}
	
	if(document.getElementById('idade').value == ""){
		
		window.alert("Preencha o sua idade!");
		document.getElementById('idade').focus()
		return false;
		
	}
			
	if(document.getElementById('email').value == ""){
		
		window.alert("Preencha o seu e-mail!");
		document.getElementById('email').focus()
		return false;
		
	}
	
	if(document.getElementById('cidade').value == ""){
		
		window.alert("Preencha sua cidade!")
		document.getElementById('cidade').focus();
		return false;
		
	}	
	
	if(document.getElementById('comentario').value == ""){
		
		window.alert("Preencha seu comentário!")
		document.getElementById('comentario').focus();
		return false;
		
	}	
	return true;
}

//ABRIR POP-UPS 
    function abrir(pagina){
        newWindow=window.open(pagina,"nova","width=600,height=600")
        if(newWindow)return false
    }

function mouseCarinha(imagem,local)
{ 
	window.document[local].src = imagem;
}

/*
	// Inicia o Ajax. 
	var ajax = openAjax(); 

	// Envia o termo da busca como uma querystring para o filtro 
	ajax.open("GET", url, true); 

	ajax.onreadystatechange = function() 
	{
		// Quando estiver carregando, exibe: carregando... 
		if (ajax.readyState == 1) 
			document.getElementById(conteudoID).innerHTML = "carregando..."; 

		if(ajax.readyState == 4 && ajax.status==200) 
			document.getElementById(conteudoID).innerHTML = ajax.responseText; 
	} 
	ajax.send(null);

// Inicia o Ajax. 
var ajax = openAjax(); 

// Envia o termo da busca como uma querystring para o filtro 
ajax.open("GET", url, true); 


ajax.onreadystatechange = function() 
{ 
// Quando estiver carregando, exibe: carregando... 
if (ajax.readyState == 1) 
conteudoID.innerHTML = "carregando..."; 

if(ajax.readyState == 4 )
if(ajax.status==200) 
conteudoID.innerHTML = exibeTexto(ajax.responseText); 
} 
ajax.send(null)
*/
