﻿function blockError(){return true;}
window.onerror = blockError;

/* NOTICIAS MAIS LIDAS - HOME */
function MaisLidas(pag){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_maislidas');
	tempIFrame.setAttribute('name','iframe_maislidas');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_maislidas.php?pag='+pag);
	IFrameObj = document.body.appendChild(tempIFrame);

}


/*
BOX NEWSLETTER
*/

function GravaNewsletter(){

	email = document.nwl.email.value;
	sexo = document.nwl.sexo.options[document.nwl.sexo.selectedIndex].value;
	idade = document.nwl.idade.options[document.nwl.idade.selectedIndex].value;
	uf = document.nwl.uf.options[document.nwl.uf.selectedIndex].value;

	if(sexo==0){
		alert('Por favor, informe o seu sexo.');
	}else if(email=='seu e-mail' || email==''){
		alert('Por favor, informe o seu e-mail.');
	}else if(idade==0){
		alert('Por favor, informe o seu ano de nascimento.');
	}else if(uf==0){
		alert('Por favor, informe o seu estado.');
	}else{

		var tempIFrame=document.createElement('iframe');
		tempIFrame.setAttribute('id','iframe_newsletter');
		tempIFrame.setAttribute('name','iframe_newsletter');

		tempIFrame.style.border = '0px';
		tempIFrame.style.width = '0px';
		tempIFrame.style.height = '0px';

		tempIFrame.setAttribute('src','includes/iframe_newsletter.php?sexo='+sexo+'&idade='+idade+'&uf='+uf+'&email='+email);
		IFrameObj = document.body.appendChild(tempIFrame);

	}

}

function RetornoNewsletter(){

	parent.document.getElementById('newsletter').innerHTML = '<span style="font-size:11px; line-height:14px;">Seu cadastro foi realizado com sucesso. <span style="font-weight:bold;">Obrigado</span>.</span>';

}

/*
BOX ENQUETE
*/

function ExibeResultadoEnquete(id){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_enquete');
	tempIFrame.setAttribute('name','iframe_enquete');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_enquete.php?tipo=1&id='+id);
	IFrameObj = document.body.appendChild(tempIFrame);

}

function RetornoResultadoEnquete(txt){

	parent.document.getElementById('enquete').innerHTML = txt;

}

function VotaEnquete(id){

	for (var i=0; i < document.enq.enquete.length; i++){
		if(document.enq.enquete[i].checked){
			var resposta = document.enq.enquete[i].value;
		}
   }

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_enquete');
	tempIFrame.setAttribute('name','iframe_enquete');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_enquete.php?tipo=2&id='+id+'&r='+resposta);
	IFrameObj = document.body.appendChild(tempIFrame);
}

function RetornoVotoEnquete(id){

	parent.document.getElementById('enquete').innerHTML = '<span style="font-size:11px; line-height:14px;">Seu voto foi computado com sucesso. <span style="font-weight:bold;">Obrigado</span>.</span><br /><br /><div id="b2" style="float:none; margin-left:0px;" onclick="ExibeResultadoEnquete('+id+')">ver resultado</div>';

}

/* ENVIO DE COMENTARIOS DE NOTICIAS */

function EnviaComentario(){

	uid = document.frm.uid.value;
	nome = document.frm.nome.value;
	email = document.frm.email.value;
	mensagem = document.frm.mensagem.value;
	mensagem = mensagem.replace(/[\n\r]/g,'<br />');

	if(nome.length<3){
		alert('Por favor, informe o seu nome.');
	}else if(email.length<3){
		alert('Por favor, informe o seu e-mail.');
	}else if(mensagem.length<3){
		alert('Por favor, preencha o campo de mensagem.');
	}else{

		var tempIFrame=document.createElement('iframe');
		tempIFrame.setAttribute('id','iframe_comentario');
		tempIFrame.setAttribute('name','iframe_comentario');

		tempIFrame.style.border = '0px';
		tempIFrame.style.width = '0px';
		tempIFrame.style.height = '0px';

		tempIFrame.setAttribute('src','includes/iframe_comentario.php?uid='+uid+'&nome='+nome+'&email='+email+'&mensagem='+mensagem);
		IFrameObj = document.body.appendChild(tempIFrame);

	}

}



function RetornoComentario(){

	parent.document.getElementById('comentariopost').innerHTML = '<h1>Deixe o seu coment&aacute;rio:</h1>Seu coment&aacute;rio foi gravado com sucesso.<br />Em breve ele ser&aacute; postado aqui.';

}

/*
function BuscaProfissional(){

	var selObj = document.getElementById('modsel');
	var selIndex = selObj.selectedIndex;
	mod = selObj.options[selIndex].value;

	if(mod==0){
		esp = 0;
	}else{
		var selObj = document.getElementById('profsel');
		var selIndex = selObj.selectedIndex;
		esp = selObj.options[selIndex].value;
	}

	var selObj = document.getElementById('es');
	var selIndex = selObj.selectedIndex;
	es = selObj.options[selIndex].value;

	var selObj = document.getElementById('cd');
	var selIndex = selObj.selectedIndex;
	cd = selObj.options[selIndex].value;

	//document.getElementById('botaobt').style.backgroundColor = '#FF0000';
	document.location.href = 'profissionais.php?esp='+esp+'&mod='+mod+'&cd='+cd+'&es='+es;

}
*/

/* vendo noticias */
function add_bookmark(tit){
	if (document.all)window.external.AddFavorite(document.location.href,tit)
} 


/* notas para noticias */

function TrocaEstrelas(valor){
	if(valor==1){
		document.getElementById('str1').src = 'images/star-on.png';
	}else if(valor==2){
		document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('str2').src = 'images/star-on.png';
	}else if(valor==3){
		document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('str3').src = 'images/star-on.png';
	}else if(valor==4){
		document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('str3').src = 'images/star-on.png';
		document.getElementById('str4').src = 'images/star-on.png';
	}else if(valor==5){
		document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('str3').src = 'images/star-on.png';
		document.getElementById('str4').src = 'images/star-on.png';
		document.getElementById('str5').src = 'images/star-on.png';
	}
}

function DestrocaEstrelas(){
	document.getElementById('str1').src = 'images/star-off.png';
	document.getElementById('str2').src = 'images/star-off.png';
	document.getElementById('str3').src = 'images/star-off.png';
	document.getElementById('str4').src = 'images/star-off.png';
	document.getElementById('str5').src = 'images/star-off.png';
}

function SalvaNota(voto,id){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_nota');
	tempIFrame.setAttribute('name','iframe_nota');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_salvanota.php?voto='+voto+'&id='+id);
	IFrameObj = document.body.appendChild(tempIFrame);

	document.getElementById('desuanota').innerHTML = '<span style="font-size:10px;">Obrigado! Seu voto foi computado com sucesso.</span>';

}

/* troca tamanho da fonte na noticia */

tam = 12;

function MudaFonte(tipo,elemento){
	if (tipo=="mais") {
		if(tam<16) tam+=1;
	} else {
		if(tam>10) tam-=1;
	}
	document.getElementById(elemento).style.fontSize = tam+'px';
}

/* DOWNLOAD DO PDF na noticia */
function GeraPDF(num){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_pdf');
	tempIFrame.setAttribute('name','iframe_pdf');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_pdf.php?id='+num);
	IFrameObj = document.body.appendChild(tempIFrame);

}

/* TROCA IMAGEM DO PDF NO TOPO */
function TrocaCapa(valor1){
	if(valor1!=0){
		var valor2;
		valor2=valor1.split(',');
		document.getElementById('conteudo_capa').innerHTML="<a href="+valor2[1]+" TARGET='_blank'><img name='img_capa' id=\"img_capa\" src="+valor2[0]+" alt='' /></a>";
	}
}

/* envia noticia por email */
function EnviaNoticiaEmail(){
	mErro = '';
	if(document.eml.nome1.value.length == 0 ) mErro+= '· Seu nome é um campo obrigatório!\n';
	if(document.eml.email1.value.length == 0 ) mErro+= '· Seu E-mail é um campo obrigatório!\n';
	if(document.eml.nome2.value.length == 0 ) mErro+= '· Nome do Destinat&aacute;rio é um campo obrigatório!\n';
	if(document.eml.email2.value.length == 0 ) mErro+= '· E-mail do Destinat&aacute;rio é um campo obrigatório!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulário:\n\n'+mErro);
		return false;
	}

	document.eml.action = 'noticias-email.php';
	document.eml.submit();
}

/* formulario de contato */
function EnviaContato(){
	mErro = '';
	if(document.frm.nome.value.length == 0 ) mErro+= '· Nome é um campo obrigatório!\n';
	if(document.frm.email.value.length == 0 ) mErro+= '· E-mail é um campo obrigatório!\n';
	if(document.frm.tel11.value.length != 2 ) mErro+= '· Telefone (DDD) é um campo obrigatório!\n';
	if(document.frm.tel12.value.length == 0 ) mErro+= '· Telefone é um campo obrigatório!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulário:\n\n'+mErro);
		return false;
	}

	document.frm.action = 'contato.php';
	document.frm.submit();
}

/* formularios de cadastro e login */

function EnviaCadastroUsuario(){
	mErro = '';
	if(document.frm.nome.value.length == 0 ) mErro+= '· Nome é um campo obrigatório!\n';
	if(document.frm.email.value.length == 0 ) mErro+= '· E-mail é um campo obrigatório!\n';
	if(document.frm.senha.value.length < 4 ) mErro+= '· Senha é um campo obrigatório e deve ter pelo menos 4 dígitos!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulário:\n\n'+mErro);
		return false;
	}

	document.frm.action = 'cadastro-usuario.php';
	document.frm.submit();
}

function EnviaLogin(){
	mErro = '';
	if(document.frm.login.value.length == 0 ) mErro+= '· E-mail é um campo obrigatório!\n';
	if(document.frm.senha.value.length < 4 ) mErro+= '· Senha é um campo obrigatório e deve ter pelo menos 4 dígitos!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulário:\n\n'+mErro);
		return false;
	}

	document.frm.action = 'login-usuario.php';
	document.frm.submit();
}

function ReenviaSenha(){
	mErro = '';
	if(document.frm.login.value.length == 0 ) mErro+= '· E-mail é um campo obrigatório!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulário:\n\n'+mErro);
		return false;
	}

	document.frm.action = 'reenvio-de-senha.php';
	document.frm.submit();
}

/* notas para guias */
/* notas para noticias */

function TrocaEstrelasG(div,valor){
	if(valor==1){
		document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-on.png';
	}else if(valor==2){
		document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str2').src = 'images/star-on.png';
	}else if(valor==3){
		document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str3').src = 'images/star-on.png';
	}else if(valor==4){
		document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str3').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str4').src = 'images/star-on.png';
	}else if(valor==5){
		document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str2').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str3').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str4').src = 'images/star-on.png';
		document.getElementById('nota'+div).document.getElementById('str5').src = 'images/star-on.png';
	}
}

function DestrocaEstrelasG(div){
	document.getElementById('nota'+div).document.getElementById('str1').src = 'images/star-off.png';
	document.getElementById('nota'+div).document.getElementById('str2').src = 'images/star-off.png';
	document.getElementById('nota'+div).document.getElementById('str3').src = 'images/star-off.png';
	document.getElementById('nota'+div).document.getElementById('str4').src = 'images/star-off.png';
	document.getElementById('nota'+div).document.getElementById('str5').src = 'images/star-off.png';
}

function SalvaNotaG(voto,id){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_nota');
	tempIFrame.setAttribute('name','iframe_nota');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_salvanota_guia.php?voto='+voto+'&id='+id);
	IFrameObj = document.body.appendChild(tempIFrame);
	//window.open('includes/iframe_salvanota_guia.php?voto='+voto+'&id='+id);

	document.getElementById('nota'+id).innerHTML = '<span style="font-size:10px;">Obrigado! Seu voto foi computado com sucesso.</span>';

}

/* pagina anuncie aqui */

function validaAnuncio(){

	mErro = '';
	if(document.frm.nome.value.length == 0 ) mErro+= '- Nome e um campo obrigatorio!\n';
	if(document.frm.tel1.value.length == 0 || document.frm.tel2.value.length == 0 ) mErro+= '- Telefone e um campo obrigatorio!\n';
	if(document.frm.estado.value == 0 ) mErro+= '- Estado e um campo obrigatorio!\n';
	if(document.frm.idade.value == 0 ) mErro+= '- Idade e um campo obrigatorio!\n';
	if(document.frm.email.value.length == 0 ) mErro+= '- E-mail e um campo obrigatorio!\n';
	if((document.frm.email.value.indexOf("@") < 1) || (document.frm.email.value.indexOf('.') < 7)) mErro+= '- E-mail incorreto!\n';
	if(document.frm.texto.value =="") mErro+= '- Campo de texto invalido!\n';

	if(mErro.length>0) {
		alert('Preencha corretamente o formulario:\n\n'+mErro);
		return false;
	}

	document.frm.action = 'anuncie.php';
	document.frm.submit();
}

/* cadastro de profissionais - altera cidade */

function TrocaCadastroCidade(uf){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_newsletter');
	tempIFrame.setAttribute('name','iframe_newsletter');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_cidades.php?uf='+uf);
	IFrameObj = document.body.appendChild(tempIFrame);

}

//valida cadastro de profissional

function validaCadastroProf(){
	if (document.frm.nome.value ==""){
    alert('Nome incorreto');
	document.frm.nome.focus();

}else if (document.frm.modal.value ==0) {
    alert('Profissão Inválida');
	document.frm.modal.focus();

}else if (document.frm.espec.value ==0) {
    alert('Especialidade Inválida');
	document.frm.espec.focus();

}else if(document.frm.doc.value == ''){
    alert('Documento Inválido');
	document.frm.doc.focus();

}else if (document.frm.tfixoddd.value.length != 2) {
    alert('DDD do telefone 1 inválido');
	document.frm.tfixoddd.focus();

}else if (document.frm.tfixo.value.length != 9) {
    alert('Telefone 1 inválido');
	document.frm.tfixo.focus();

}else if (document.frm.email.value ==""){
    alert('Digite um email');
	document.frm.email.focus();
}else if ((document.frm.email.value.indexOf('@')==-1) || (document.frm.email.value.indexOf('.')==-1)) {
    alert('Email incorreto');
	document.frm.email.focus();
}else if (document.frm.email.value != document.frm.vemail.value)  {
    alert('O email de verificação não coincide');
	document.frm.email.focus();
/*
}else if (document.frm.login.value =="") {
    alert('Login invalido');
	document.frm.login.focus();
*/
}else if (document.frm.senha.value =="") {
    alert('Senha invalida');
	document.frm.senha.focus();
}else if (document.frm.senha.value.length < 4) {
    alert('Senha deve conter ao menos 4 dígitos');
	document.frm.senha.focus();
}else if (document.frm.senha.value != document.frm.vsenha.value)  {
    alert('A senha de verificação não coincide');
	document.frm.vsenha.focus();
}else if (document.frm.aceito.checked == false )  {
    alert('Não foi aceito os termos de uso');
}else{
	document.frm.submit();
  }
  
  /*fim valida*/
}


/* -----------------------------
------------ GUIA RJ -----------
----------------------------- */

function TrocaGuiaCidade(uf){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_cidade');
	tempIFrame.setAttribute('name','iframe_cidade');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	url = 'includes/iframe_guia_cidades.php?uf='+uf;

	tempIFrame.setAttribute('src',url);
	IFrameObj = document.body.appendChild(tempIFrame);

}

function TrocaGuiaBairro(cidade){

	var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_bairros');
	tempIFrame.setAttribute('name','iframe_bairros');

	tempIFrame.style.border = '0px';
	tempIFrame.style.width = '0px';
	tempIFrame.style.height = '0px';

	tempIFrame.setAttribute('src','includes/iframe_guia_bairros.php?cidade='+cidade);
	IFrameObj = document.body.appendChild(tempIFrame);

}

/* MASCARA PARA FORMS */

function maskIt(w,e,m,r,a){
	
	// Cancela o evento backspace
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	// para aceitar letras trocar /d por /w
	// Variaveis da funcao
	var txt = (!r) ? w.value.replace(/[^\d]+/gi,'') : w.value.replace(/[^\d]+/gi,'').reverse();
	var mask = (!r) ? m : m.reverse();
	var pre  = (a ) ? a.pre : "";
	var pos  = (a ) ? a.pos : "";
	var ret  = "";
	
	if(code == 9 || code == 8 || txt.length == mask.replace(/[^#]+/g,'').length) return false;
	
	// Loop na máscara para aplicar os caracteres
	for(var x=0,y=0, z=mask.length;x<z && y<txt.length;){
		if(mask.charAt(x)!='#'){
			ret += mask.charAt(x); x++;
		} else{
			ret += txt.charAt(y); y++; x++;
		}
	}
	
	// Retorno da funcao
	ret = (!r) ? ret : ret.reverse()
	w.value = pre+ret+pos;

}

String.prototype.reverse = function(){
	return this.split('').reverse().join('');
};

