function SelecionaTipoAssinatura(valor) {
	
	if (valor != "") {
		
		if (valor == "Semestral") {
			
			document.getElementById('parcelas_sem').style.display = '';
			document.getElementById('parcelas_an').style.display = 'none';
			document.getElementById('textoAssinatura').style.display = 'none';
						
		}
		
		else {
			
			document.getElementById('parcelas_sem').style.display = 'none';
			document.getElementById('parcelas_an').style.display = '';
			document.getElementById('textoAssinatura').style.display = 'none';
			
		}
		
	}
	
}

function Print(id) {
	
	pg = '/imprimir'
	
    var oPrint, oJan;
	
   	var width = 670;

	var height = 550;
    
    oPrint = window.document.getElementById(id).innerHTML;
    
    oJan = window.open(pg,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);
    
	oJan.window.print();
    
	oJan.history.go();
    
}

function deleteCookie(nome){
	
    var exdate = new Date();
    
    exdate.setTime(exdate.getTime() + (-1 * 24 * 3600 * 1000));
       
    document.cookie = nome + "=" + escape("")+ ((-1 == null) ? "" : "; expires=" + exdate);
       
} 

function PopUp(url, altura, largura) {

	window.open(url, 'PUBLICIDADE', "resizable=no,toolbar=no,status=no,menubar=no,titlebar = no,location=no,scrollbars=no,directories=no,width=" + largura + ",height=" + altura);

}

function TrocarSenha() {

    if ((document.getElementById('s').value == "") 
	 || (document.getElementById('ns1').value == "") 
	 || (document.getElementById('ns2').value == "")) {
	 	
		alert('Preencha todos os campos por favor!');

    }

    else {
         
        if (document.getElementById('ns1').value == document.getElementById('ns2').value) {
        	
        	return true;
         
        }
        
        else {
			
			alert('Senha não confirmada! Verifique se as senhas digitadas são iguais.');
			
			document.getElementById('frmTrocarSenha').action = history.go(0);
			
		}

    }

}

function senhaEnviar() {

    if (document.getElementById('email').value != "") {

         document.getElementById('frmSenha').submit();

    }

    else {

         alert('Preencha o campo E-mail por favor!');

    }

}

function Logar(url) {

    var l = document.getElementById('l').value;
    var s = document.getElementById('s').value;
    var f = document.getElementById('frmAssinante');
    
    if ((l == "") || (s == "")) {
         
         alert('Por Favor, preencha os campos corretamente!');
	
		 f.action = history.go(0);
	
		 return false;

    }
    
    else {
    	
    	 f.action = url+'/logar';
         
         return true;
    
    }
    
}

function FaleEnviar() {

    var nome = document.getElementById('nome').value;
    var tel = document.getElementById('tel').value;
    var email = document.getElementById('email').value;
    var assunto = document.getElementById('assunto').value;
    var msg = document.getElementById('msg').value;
    var form = document.getElementById('formFaleConosco');
    
    if ((nome == "") || (email == "") || (tel == "") || (assunto == "") || (msg == "")) {
    
		alert('Por favor, preencha os campos corretamente!');
    
    }
    
    else {
       
         if (TesteEmail(email)) {
         
             form.submit();
         
         }
         
         else {

             alert('O E-mail digitado é inválido!');
         
         }
    
    }

}


function AnuncieEnviar() {

    var nome = document.getElementById('nome').value;
    var tel = document.getElementById('tel').value;
    var email = document.getElementById('email').value;
    var tipoanuncio = document.getElementById('tipoanuncio').value;
    var msg = document.getElementById('msg').value;
    var form = document.getElementById('formAnuncie');
    
    if ((nome == "") || (email == "") || (tel == "") || (msg == "") || (tipoanuncio == "")) {
    
		alert('Por favor, preencha os campos corretamente!');
    
    }
    
    else {
       
         if (TesteEmail(email)) {
         
             form.submit();
         
         }
         
         else {

             alert('O E-mail digitado é inválido!');
         
         }
    
    }

}

function AssineEnviar() {

    var nome = document.getElementById('nome').value;
    var tel = document.getElementById('tel').value;
    var email = document.getElementById('email').value;
    var tipoassinatura = document.getElementById('tipoassinatura').value;
    var msg = document.getElementById('msg').value;
    var form = document.getElementById('formAssine');
    
    if ((nome == "") || (email == "") || (tel == "") || (msg == "") || (tipoassinatura == "")) {
    
		alert('Por favor, preencha os campos corretamente!');
    
    }
    
    else {
       
         if (TesteEmail(email)) {
         
             form.submit();
         
         }
         
         else {

             alert('O E-mail digitado é inválido!');
         
         }
    
    }

}


function EnviarCurriculo() {
	
	var nome = document.getElementById('nome').value;
	var email = document.getElementById('email').value;
	var arq = document.getElementById('arq').value;
	var form = document.getElementById('frmCurriculo');
	
	if ((nome != "") || (email != "") || (arq != "")) {
		
		if (TesteEmail(email)) {
			
			ext = arq.split(".");
		
			//tamanho do array ext
			t = ext.length;
			
			//protecao caso o arquivo haja mais pontos
			//sempre pegar o ultimo array que sera a extensao
			ext = ext[t-1];
			
			//testa para ver se o arquivo é mesmo no formato doc
			if  (ext != "doc") {
			
				alert('É necessário que o arquivo esteja no formato .DOC (Microsoft WORD)!');	
			
			}
			
			else {
				
				form.submit();
			
	        }
	        
	    }
	    
	    else {
	    	
	    	document.getElementById('email').focus;
			
			alert('E-mail digitado é inválido!');
			
		}
		
	}
	
	else {
		
		alert('Por favor, preencha os campos corretamente!');
		
	}
	
}

function emailEnviar()  {
	
	var form = document.getElementById('formEmail');
    var nome = document.getElementById('nome').value;
    var email =  document.getElementById('email').value;
	var nome_dest =  document.getElementById('nome_dest').value;
    var email_dest = document.getElementById('email_dest').value;
    var msg = document.getElementById('msg').value;
	
	
	if ((nome != "") || (email != "") || (email_dest != "") || (msg != "") || (nome_dest != "")) {
	
		 if (TesteEmail(email)) {
		 
			if (TesteEmail(email_dest)) {
			
				form.submit();
			
			}
			
			else {
			
			   document.getElementById('email_dest').focus;
			
			   alert('O e-mail do destinatário está incorreto!');
			
			}

		 }
		 
		 else {
		 
			document.getElementById('email').focus;
		 
			alert('Seu e-mail está incorreto!');
		 
		 }
	
	}
	
	else {
	
	   alert('Preencha todos os campos por favor!');
	
	}
	
}

function TesteEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true
}
	
function Comentar() {

    var nome = document.getElementById('txtNome').value;
	var texto = document.getElementById('texto').value;
	var email = document.getElementById('txtEmail').value;
	var titulo = document.getElementById('txtTitulo').value;
	var root = document.getElementById('root').value;
	var id = document.getElementById('id').value;

    //limpa todas as possivel barras nos campos
	texto = encodeURIComponent(texto);
	texto = encodeURI(texto);
	
	titulo = encodeURIComponent(titulo);
    titulo = encodeURI(titulo);
    
    nome = encodeURIComponent(nome);
    nome = encodeURI(nome);
    
    email = encodeURIComponent(email);
    email = encodeURI(email);
	
	if ((texto == "") || (titulo == "")) {
		
		alert('Por favor, preencha os campos corretamente!');
		
	}
		
	else {
		
		ajaxAlert(root+'/comentarios/'+id+'/'+nome+'/'+email+'/'+titulo+'/'+texto, '0');
			
		window.location.reload();
		
	}
	
}

function AbreAdm(url) {

	window.open(url,"_blank","resizable=yes,fullscreen=yes,toolbar=no,status=yes,menubar=no,scrollbars=yes");

}

function Figura(url, width, height) {
	
	url = 'http://www.diariodejacarei.com.br/imagem/' + url;

	window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no,width=" + width + ",height=" + height)

}

function Abre(url, width, height) {

	window.open(url,"_blank","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height)

}


function Fun_Enviar(formID) {

	var formularios = document.forms.length;
	for(i=0;i<formularios;i++)
		{
		if(document.forms[i].name==formID)
		{
		var formulario = i;
		break;
		}
	}
	var num_respostas = document.forms[formulario].opcao.length;
	var resposta = num_respostas;
	var respostas = "";
	for(i=0;i<num_respostas;i++)
		{
		if(document.forms[formulario].opcao[i].checked)
			{
			resposta = i;
			if(respostas)
			{
				respostas=respostas + "&";
			}
			else
			{
				respostas=respostas + "?";
			}
			respostas=respostas + "opcao=" + document.forms[formulario].opcao[i].value;
		}
	}
	if(resposta==num_respostas)
	{
	alert("Uma opção deve ser escolhida!");
	}
	else
	{
	Abre("http://www.enquetes.com.br/enquete.asp" + respostas,400,400);
	}

}

function senha(url) {

   	var width = 440;

	var height = 280;
	
    window.open(url,"_blank","resizable=no,toolbar=no,status=yes,menubar=no,scrollbars=no,width=" + width + ",height=" + height);

}

function imprimir(url) {
	
	var width = 700;

	var height = 480;

	window.open(url,"_blank","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);

}

function email(url) {
	
	var width = 400;

	var height = 415;
	
	var oPrint, oJan;

	oJan = window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no,width=" + width + ",height=" + height);
	
	oJan.history.go();

}

function Buscar(url) {
	
	var txtPalavra = document.getElementById('txtPalavra');
	
	if (txtPalavra.value == "") {
		
		alert('Digite algo para realizar a busca.');
		exit;
		
	}
	
	else {
		
		window.location = url+txtPalavra.value;
		
	}
	
}

function AtualizaUltimas() {
	
	setTimeout('ajax("divUltimas","incUltimas2.php")',8000);
	
	setTimeout('AtualizaUltimas()',8000);
	
}
