// Funções para Pandora Vestibular

/////////////////////////////////////////////////////////////////////////////////////////////////

function verificaEmail(newsletter,tipo){
	document.getElementById('acao').value = tipo;
	if(newsletter.email.value == ""){
		alert("Atenção!\nO campo EMAIL deve ser preenchido!");
		newsletter.email.focus();
		return false;
	}
	if(newsletter.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nVocê não preencheu o campo EMAIL corretamente!");
		newsletter.email.focus();
		return false;
	}
	return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Área do Aluno
function ValidaForm_Area_Aluno (form) {

  if ( form.matricula.value.length <= 1 ) {
	  alert("O campo Matrícula deve estar preenchido corretamente.");
	  form.matricula.focus();
	  return false;
  }


  if ( form.senha.value.length <= 1 ) {
	  alert("O campo Senha deve estar selecionado corretamente.");
	  form.senha.focus();
	  return false;
  }

}

////////////////////////////////////////////////////////////////////////////////////////////////////

//valida Formulário Esqueceu a Senha
function ValidaFormEsqueceu_Senha(form)
{

	if(form.login.value.length<=1)
  {
	   alert("O campo Login deve estar preenchido corretamente.");
	   form.login.focus();
	   return false;
   }

   var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
}
// função para vídeo
function fnVideo(){
	document.writeln('<object id="player" type="application/x-shockwave-flash" data="player-licensed.swf" width="233" height="200">');
	document.writeln('<param name="movie" value="player-licensed.swf" />');
	document.writeln('<param name="allowfullscreen" value="true" />');
	document.writeln('<param name="allowscriptaccess" value="always" />');
	document.writeln('<param name="flashvars" value="file=http://172.16.0.5/pandoravestibular.com.br/html/video/aprovados.FLV"/>');
	//document.writeln('<param name="flashvars" value="file=http://www.tvtercodalibertacao.com.br/video/video.FLV"/>');
	document.writeln('</object>');
}

////////////////////////////////////////////////////////////////////////////////////////////////////

// função newsletter
function ValidaForm_Newsletter(form){
  if ( form.nome.value.length <= 1 ){
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }
  var str_email = form.email.value ;
  if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'E-mail:' )) {
	  alert("O campo E-mail deve ser preenchido corretamente");
	  form.email.focus();
	  return false;
  }
}

////////////////////////////////////////////////////////////////////////////////////////////////////

//mostrar
function onOffVideos(id){
	visivel = document.getElementById(id).style.display;
	if ( visivel == "none" ){
		document.getElementById(id).style.display = "";
	}
	else{
		document.getElementById(id).style.display = "none";
	}
}

////////////////////////////////////////////////////////////////////////////////////////
//funcao para o (mostrar e ocultar)
function onOff(id){
		esconder = (document.getElementById(id).style.display == 'block');
		/*if ( visivel == "" || visivel == "none" ) { document.getElementById(id).style.display = "block" }
		else{ document.getElementById(id).style.display = "none"; }*/
		divs = document.getElementsByTagName('DIV');
		for(d=0; d<divs.length; d++){
			_div = divs[d];
			if (_div.className == 'titulo'){
				id_link = 'titulo_'+(_div.id);
				_link = document.getElementById(id_link);
				if(_div.id != id){ _div.style.display = 'none'; }
				else{ _div.style.display = esconder ? 'none' : 'block'; }
			}
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////

//função para a enquete
function ValidaForm_Enquete(form){
    check = 0;
    for(i=0; i<document.formEnquete.enquete.length; i++){
        if(document.formEnquete.enquete[i].checked){
            check = 1;
            break;
        }
    }
    if(check != 1){
        alert("Atenção!\nVocê deve escolher uma das opções da Enquete para votar.");
        falso = 2;
        return false;
    }
    else{ document.formEnquete.submit(); }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Contato
function ValidaForm_Contato (form) {

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }


  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}


  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  if ( form.cidade.value.length <=1 ) {
	  alert("O campo Cidade deve estar preenchido corretamente.");
	  form.cidade.focus();
	  return false;
  }


  if ( form.estado.value.length <=1 ) {
	  alert("O campo Estado deve estar preenchido corretamente.");
	  form.estado.focus();
	  return false;
  }

  if ( form.mensagem.value.length <=1 ) {
	  alert("O campo Mensagem deve estar preenchido corretamente.");
	  form.mensagem.focus();
	  return false;
  }

  if ( form.cod.value.length <=1 ) {
	  alert("Digite o Código de Segurança.");
	  form.cod.focus();
	  return false;
  }
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Eventos
function ValidaForm_Eventos(form) {

	if((form.p1.checked == false)&&(form.p2.checked == false)&&(form.p3.checked == false)&&(form.p4.checked == false)){
		alert("O campo Eventos deve estar selecionado corretamente.");
		form.p1.focus();
		return false;
	}

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }
  if ( form.turma.value.length <= 1 ) {
	  alert("O campo Turma deve estar preenchido corretamente.");
	  form.turma.focus();
	  return false;
  }

  if ( form.ra.value.length <= 8) {
	  alert("O campo R.A. deve estar preenchido corretamente.");
	  form.ra.focus();
	  return false;
  }
}












//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Cadastre
function ValidaForm_Cadastre (form) {

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }

  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}

  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  if ( form.cidade.value.length <=1 ) {
	  alert("O campo Cidade deve estar preenchido corretamente.");
	  form.cidade.focus();
	  return false;
  }


  if ( form.estado.value.length <=1 ) {
	  alert("O campo Estado deve estar preenchido corretamente.");
	  form.estado.focus();
	  return false;
  }

  if ( form.mensagem.value.length <=1 ) {
	  alert("O campo Mensagem deve estar preenchido corretamente.");
	  form.mensagem.focus();
	  return false;
  }

  if ( form.cod.value.length <=1 ) {
	  alert("Digite o Código de Segurança.");
	  form.cod.focus();
	  return false;
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Formulario Concurso de Bolsas
function ValidaForm_Concurso_Bolsa (form) {

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }

  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}

	if ( form.cidade.value.length <= 1 ) {
	  alert("O campo Cidade deve estar preenchido corretamente.");
	  form.cidade.focus();
	  return false;
  }

  if ( form.estado.value.length <= 1 ) {
	  alert("O campo Estado deve estar preenchido corretamente.");
	  form.estado.focus();
	  return false;
  }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Formulario Concurso de Bolsas
function ValidaForm_Concurso (form) {

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }

   if ( form.datadenascimento.value.length <= 1 ) {
	  alert("O campo Data de Nascimento deve estar preenchido corretamente.");
	  form.datadenascimento.focus();
	  return false;
  }

   if ( form.rg.value.length <= 1 ) {
	  alert("O campo RG deve estar preenchido corretamente.");
	  form.rg.focus();
	  return false;
  }

  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}

	if ( form.cidade.value.length <= 1 ) {
	  alert("O campo Cidade deve estar preenchido corretamente.");
	  form.cidade.focus();
	  return false;
  }

  if ( form.estado.value.length <= 1 ) {
	  alert("O campo Estado deve estar preenchido corretamente.");
	  form.estado.focus();
	  return false;
  }
  if ( form.datadaprova.value.length <= 1 ) {
	  alert("O campo Data da Prova deve estar preenchido corretamente.");
	  form.datadaprova.focus();
	  return false;
  }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//valida Data
function validaData(DATA){
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var msgErro = 'Formato inválido de data.';
	var vdt = new Date();
	var vdia = vdt.getDay();
	var vmes = vdt.getMonth();
	var vano = vdt.getYear();
	var vano = parseInt(vano)+1900;
	if ((DATA.value.match(expReg))&&(DATA.value!='')){
		var dia = DATA.value.substring(0,2);
		var mes = DATA.value.substring(3,5);
		var ano = DATA.value.substring(6,10);
		if((mes==04 && dia > 30)||(mes==06 && dia > 30)||(mes==09 && dia > 30)||(mes==11 && dia > 30)){
			alert("Dia incorreto! O mês especificado contém no máximo 30 dias.");
			DATA.focus();
			return false;
		}
		else{
			//1
			if(ano%4!=0 && mes==2 && dia>28){
				alert("Data incorreta! O mês especificado contém no máximo 28 dias.");
				DATA.focus();
				return false;
			}
			else{ //2
				if(ano%4==0 && mes==2 && dia>29){
					alert("Data incorreta! O mês especificado contém no máximo 29 dias.");
					DATA.focus();
					return false;
				}
				else{ //3
					if(ano > vano){
						alert("Data incorreta! Ano informado maior que ano atual.");
						DATA.focus();
						return false;
					}
					else{ //4
					//alert ("Data correta!");
					return true;
					} //4-else
				} //3-else
			}//2-else
		}//1-else
	}
	else{ //5
		alert(msgErro);
		DATA.focus();
		return false;
	} //5-else
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao da Mascara
function fnMascara(objeto, evt, mask)
{
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos  = '().-:/ ';
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
 	var ntecla = (evt.which) ? evt.which : evt.keyCode;
 	tecla = Charset.substr(ntecla - 32, 1);
 	if (ntecla < 32) return true;

 	var tamanho = value.length;
 	if (tamanho >= mask.length) return false;

 	var pos = mask.substr(tamanho,1);
 	while (Fixos.indexOf(pos) != -1)
	 	{
 	 		value += pos;
 	 		tamanho = value.length;
 	 		if (tamanho >= mask.length) return false;
 	 		pos = mask.substr(tamanho,1);
		}

 	switch (pos)
		{
   			case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   			case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   			case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   			case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   			case '*' : objeto.value = value; return true; break;
   			default : return false; break;
 		}
	}
	objeto.value = value;
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Função de popup
function MM_openBrWindow(theURL,winName,features)
{
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Função para o Menu PopUp
function fnImagemPopUp( titulo, largura , altura , imagem , alt )
{
		var janela ;
		janela = window.open("","popFoto","width="+largura+",height="+altura+",scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left=300,top=300'");
		janela.document.write('<html><head><title>' + titulo + '</title></head>');
		janela.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
		janela.document.write('<a href="javascript:window.close();"><img src="'+ imagem + '" alt="' + alt + '" border="0" /></a> ');
		janela.document.write('</body></html>');
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Função Adiciona a Favoritos
function fnAdicionaFavoritos()
{
	str_titulo = "Pandora Vestibulares";
	str_url = "http://www.pandoravestibular.com.br";
	//FireFox
	if (window.sidebar)
	{
   		window.sidebar.addPanel(str_titulo, str_url,"");
	}
	//IE
	else if( window.external )
	{
  		window.external.AddFavorite( str_url, str_titulo);
	}
	//Opera
	else if(window.opera && window.print)
	{
   		return true;
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////

//Função Validação do Indique Amigo
function ValidaForm_IndiqueAmigo(form)
{

	if (form.nome.value=="")
	{
		alert("O campo Seu nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}


	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo Seu E-mail deve ser preenchido corretamente.");
    	form.email.focus();
    	return false;
	}

	var str_email = form.emailamigo.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail do Destinatário deve ser preenchido corretamente.");
    	form.emailamigo.focus();
    	return false;
	}


}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//Função para o flash

function fnFlash(str_url, int_largura, int_altura)
{
	document.writeln('<object type="application/x-shockwave-flash" data="' + str_url + '" width="' + int_largura + '" height="' + int_altura + '">');
	document.writeln('<param name="movie" value="' + str_url + '">');
	document.writeln('<param name="quality" value="high">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('</object>');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//Opacidade das fotos - lIGHTbox
function mostra(campo)
{
   document.getElementById(campo).style.filter='alpha(opacity=50)' ;
   document.getElementById(campo).style.opacity='.5' ;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Valida Contato
function ValidaForm_Bolsa(form) {
  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }
  if ( form.rg.value.length <= 7 ) {
	  alert("O campo RG deve estar preenchido corretamente.");
	  form.rg.focus();
	  return false;
  }


  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}


  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  if ( form.escola.value.length <=1 ) {
	  alert("O campo Escola deve estar preenchido corretamente.");
	  form.escola.focus();
	  return false;
  }

}

//Valida 2 Fase
function ValidaForm_2fase (form) {

  if ( form.nome.value.length <= 1 ) {
	  alert("O campo Nome deve estar preenchido corretamente.");
	  form.nome.focus();
	  return false;
  }

  if ( form.rg.value.length <= 7 ) {
	  alert("O campo RG deve estar preenchido corretamente.");
	  form.rg.focus();
	  return false;
  }

  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }

  var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}

	if ( form.onde_estudou.value.length <= 1 ) {
	  alert("O campo Onde estudou deve estar preenchido corretamente.");
	  form.onde_estudou.focus();
	  return false;
 	}

}

