/* ----------------------------------------------------------------------------
 * validacoes.js
 * ----------------------------------------------------------------------------
 */

function validaFormLogon() {
	
  var caDoc = document.getElementById("caDoc");
  var anSenha = document.getElementById("anSenha");

  if (isEmpty(caDoc) || !validaCpf(caDoc.value)) {
    caDoc.focus();
    mostraAlerta("CPF inv&aacute;lido.");
    return false;
  }	

  if (isEmpty(anSenha) || anSenha.value.length < 6) {
    anSenha.focus();
    mostraAlerta("Senha inv&aacute;lida.");
    return false;
  }

  mostraAguarde();
  
  return true;
}



function validaFormCadastroP1() {    

  var preCadastro_caDoc = document.getElementById("preCadastro.caDoc");
  var preCadastro_anEmail = document.getElementById("preCadastro.anEmail");
  var preCadastro_anEmailConf = document.getElementById("preCadastro.anEmailConf");
  var preCadastro_anSenha = document.getElementById("preCadastro.anSenha");
  var preCadastro_anSenhaConfirma = document.getElementById("preCadastro.anSenhaConfirma");
  var preCadastro_nmTelResDdd = document.getElementById("preCadastro.nmTelResDdd");
  var preCadastro_nmTelResNumero = document.getElementById("preCadastro.nmTelResNumero");
  var btnFinalizarCadastro = document.getElementById("btn-finalizar-cadastro");
  
  
	  if (!preCadastro_boParticiparProgrRelac.checked) {
			preCadastro_boParticiparProgrRelac.focus();
			mostraAlerta("Para prosseguir com o seu cadastramento, &eacute; necess&aacute;rio que leia o regulamento e aceite os crit&eacute;rios de participa&ccedil;&atilde;o do programa de relacionamento t vantagens.");
			return false;
	  	
	  }
	  
	  if (isEmpty(preCadastro_caDoc)) {
	    preCadastro_caDoc.focus();
	    mostraAlerta("Digite o seu CPF.");
	    return false;
	  }	
	
	  if (!validaCpf(preCadastro_caDoc.value)) {
	    preCadastro_caDoc.focus();
	    mostraAlerta("Digite um CPF v&aacute;lido.");  
	    return false;
	  }
	  
	  if (isEmpty(preCadastro_anEmail) || preCadastro_anEmail.value.length < 4 || !isValidMail(preCadastro_anEmail.value)) {
	      preCadastro_anEmail.focus();
	      mostraAlerta("Endere&ccedil;o de e-mail inv&aacute;lido.");
	      return false;
	  }
	  
	  if (isEmpty(preCadastro_anEmailConf) || preCadastro_anEmailConf.value.length < 4 || !isValidMail(preCadastro_anEmailConf.value)) {
	      preCadastro_anEmailConf.focus();
	      mostraAlerta("Confirma&ccedil;&atilde;o do endere&ccedil;o de e-mail inv&aacute;lido.");
	      return false;
	  }
	
	  if (preCadastro_anEmailConf.value != preCadastro_anEmail.value) {
	      preCadastro_anEmailConf.focus();
	      mostraAlerta("A confirma&ccedil;&atilde;o do seu e-mail est&aacute; incorreta.");
	      return false;
	  }
	
	
	  if (isEmpty(preCadastro_anSenha) || preCadastro_anSenha.value.length < 6) {
	    preCadastro_anSenha.focus();
	    mostraAlerta("Digite uma senha com no m&iacute;nimo 06 caracteres.");
	    return false;
	  }	
	
	
	  if (isEmpty(preCadastro_anSenhaConfirma) || preCadastro_anSenhaConfirma.value != preCadastro_anSenha.value ) {
	    preCadastro_anSenhaConfirma.focus();
	    mostraAlerta("A confirma&ccedil;&atilde;o da sua senha n&atilde;o confere com a senha digitada.");
	    return false;
	  }
	  
		if (isEmpty(preCadastro_nmTelResDdd) || preCadastro_nmTelResDdd.value.length < 2) {
		  preCadastro_nmTelResDdd.focus();
		  mostraAlerta("Informe o DDD do n&uacute;mero de telefone residencial");
		  return false;
		}	
		
		if (isEmpty(preCadastro_nmTelResNumero) || preCadastro_nmTelResNumero.value.length < 6 ) {
		  preCadastro_nmTelResNumero.focus();
		  mostraAlerta("Informe o n&uacute;mero de telefone residencial");
		  return false;
		}
		btnFinalizarCadastro.style.visibility = "hidden";
		//btnFinalizarCadastro.disabled=true;

				
  return true;
}


function validaFormAlterarSenha() {
	var anSenhaAtual = document.getElementById("anSenhaAtual");	
	var anSenhaNova = document.getElementById("anSenhaNova");
	var anSenhaNovaConfirma = document.getElementById("anSenhaNovaConfirma");

	if(isEmpty(anSenhaAtual) || anSenhaAtual.value.length < 6){
		anSenhaAtual.focus();
	    mostraAlerta("Digite uma senha com no m&iacute;nimo 06 caracteres.");
	}else if (isEmpty(anSenhaNova) || anSenhaNova.value.length < 6) {
		anSenhaNova.focus();
	    mostraAlerta("Digite uma nova senha com no m&iacute;nimo 06 caracteres.");
	    return false;
	}else if (isEmpty(anSenhaNovaConfirma) || anSenhaNovaConfirma.value != anSenhaNova.value ) {
		anSenhaNovaConfirma.focus();
	    mostraAlerta("A confirma&ccedil;&atilde;o da sua nova senha n&atilde;o confere com a senha digitada.");
	    return false;
	}
	
	return true;
}


function validaFormCadastroP0(){
	var preCadastro_caDoc = document.getElementById("cadastroForm.caDoc");
	if (isEmpty(preCadastro_caDoc)) {
	    preCadastro_caDoc.focus();
	    mostraAlerta("Digite o seu CPF.");
	    return false;
	}else if(!validaCpf(preCadastro_caDoc.value)) {
	    preCadastro_caDoc.focus();
	    mostraAlerta("Digite um CPF válido.");  
	    return false;
	}
	return true;
}

function proximoCampo(value){
	var fild = document.getElementsByName(value);
	if(fild != null){
		fild.focus();
	}
}


function validaFormObterLembreteSenha(){
	var caDoc = document.getElementById("lembrete.caDoc");
	if (isEmpty(caDoc) || !validaCpf(caDoc.value)) {
		caDoc.focus();
	    mostraAlerta("CPF inv&aacute;lido.");
	    return false;
	}
	
	mostraAguarde();
	
	return true;
}

	
function validaFormObterNovaChaveAtivacao() {
	var caDoc = document.getElementById("lembrete.caDoc");
	if (isEmpty(caDoc) || !validaCpf(caDoc.value)) {
		caDoc.focus();
	    mostraAlerta("CPF inv&aacute;lido.");
	    return false;
	}

	mostraAguarde();
	
	return true;
}




function validaFormFaleConoscoTfn(){
	var contatoTfn_anNome = document.getElementById("contatoTfn.anNome");
	var contatoTfn_anEmail = document.getElementById("contatoTfn.anEmail");
	var contatoTfn_nmTelDdd = document.getElementById("contatoTfn.nmTelDddTfn");
	var contatoTfn_nmTelNumero = document.getElementById("contatoTfn.nmTelNumero");
	var contatoTfn_caAssunto = document.getElementById("contatoTfn.caAssunto");
	var contatoTfn_anMensagem = document.getElementById("contatoTfn.anMensagem");

	if (isEmpty(contatoTfn_anNome) || contatoTfn_anNome.value.length < 6) {
		contatoTfn_anNome.focus();
		mostraAlerta("Digite o seu nome completo");
		return false;
	}else if (isEmpty(contatoTfn_anEmail) || !isValidMail(contatoTfn_anEmail.value)) {
	    contatoTfn_anEmail.focus();
	      mostraAlerta("Endere&ccedil;o de e-mail inv&aacute;lido.");
	    return false;
	}else if (isEmpty(contatoTfn_nmTelDdd) || contatoTfn_nmTelDdd.value.length == 0) {
		contatoTfn_nmTelDdd.focus();
		mostraAlerta("Selecione o DDD");
		return false;
	}else if (isEmpty(contatoTfn_nmTelNumero) || contatoTfn_nmTelNumero.value.length < 6 ) {
		contatoTfn_nmTelNumero.focus();
		  mostraAlerta("Digite um Telefone v&aacute;lido");
		return false;
	}else if (isEmpty(contatoTfn_caAssunto) || contatoTfn_caAssunto.value.length == 0) {
		contatoTfn_caAssunto.focus();
		mostraAlerta("Selecione o Assunto");
		return false;
	}else if (isEmpty(contatoTfn_anMensagem) || contatoTfn_anMensagem.value.length < 10 ) {
		contatoTfn_anMensagem.focus();
		mostraAlerta("Digite a sua mensagem");
		return false;
	}
	return true;
}


function validaFormFaleConoscoNao(){
	var contatoNao_anNome = document.getElementById("contatoNao.anNome");
	var contatoNao_anEmail = document.getElementById("contatoNao.anEmail");
	var contatoNao_anMensagem = document.getElementById("contatoNao.anMensagem");		  
  
	if (isEmpty(contatoNao_anNome) || contatoNao_anNome.value.length < 6) {
		contatoNao_anNome.focus();
	  	mostraAlerta("Digite o seu nome completo");
	  	return false;
	}else if (isEmpty(contatoNao_anEmail) || !isValidMail(contatoNao_anEmail.value)) {
      	contatoNao_anEmail.focus();
        mostraAlerta("Endere&ccedil;o de e-mail inv&aacute;lido.");
      	return false;
	}else if (isEmpty(contatoNao_anMensagem) || contatoNao_anMensagem.value.length < 10 ) {
	  	contatoNao_anMensagem.focus();
	  	mostraAlerta("Digite a sua mensagem");
	  	return false;
	}	
	return true;
}
	
// gerais

function isEmpty(objeto) {
	if(objeto != null){
		if (objeto.value.length == 0) {
			return true;
		}
	}
	return false; 
}
	

function contemString(objeto, caractere) {
  if (objeto.value.indexOf(caractere,0) > -1) {
    return true;
  }
  return false; 
}


function contagemCaracte(objetoCampo, qtdMaxima) {
  qtdRestante = qtdMaxima - objetoCampo.value.length;
  if( qtdRestante <= 0 ) {
    objetoCampo.value=objetoCampo.value.substring(0,qtdMaxima);
  }
}


function apenasNumeroDigitado(evento) {
  var tecla = document.all ? evento.keyCode : evento.which;
  //alert(tecla);
  if (tecla == 0 || tecla == 8) {
     return true;
  } else if (!(tecla >= 48 && tecla <= 57)) {
     return false;
  } else {
     return true;
  }
}


function validaCpf(s) {  var i; 
  var c = s.substr(0,9);
  var dv = s.substr(9,2);
  var d1 = 0;

  for (i = 0; i < 9; i++) {
    d1 += c.charAt(i)*(10-i);
  }

  if (d1 == 0) {
    return false;
  }

  d1 = 11 - (d1 % 11);

  if (d1 > 9) d1 = 0;

  if (dv.charAt(0) != d1) {
    return false;
  }

  d1 *= 2;

  for (i = 0; i < 9; i++) {
    d1 += c.charAt(i)*(11-i);
  }

  d1 = 11 - (d1 % 11);

  if (d1 > 9) d1 = 0;

  if (dv.charAt(1) != d1) {
    return false;
  }

  return true;
}


// Mensagens de Alerta
function fechaAlerta(){
  document.getElementById("divAlerta").style.visibility = "hidden";
}


function mostraAlerta(mensagem, titulo){
	if(mensagem != null && mensagem.length > 1) {
		if(titulo != null && titulo.length > 1) {
			document.getElementById("txtTituloAlerta").innerHTML=titulo;
		}	
		document.getElementById("txtAlertaNovo").innerHTML=mensagem;
		createMask();
		createLightbox('box-modal-alerta','319','219');
	}	
}


function mostraAguarde(){
	$('div.box-modal-aguarde').show();
	var bodyHeight = document.documentElement.clientHeight;
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) { 
          var docScroll = document.documentElement.scrollTop;
		  $('select').each(function(){$(this).hide()});
		  var hb = bodyHeight;
      } else {
	  	var docScroll = '0';
		var hb = '100%';
	  }
	} else {
		var docScroll = '0';
		var hb = '100%';
	}
	/* $('body').append('<div class="bg-modal-aguarde"></div>'); */
	/* $('div.containerAguarde').append('<img src="_img/aguarde49.gif" border="0" />'); */
	
	$('div.bg-modal-aguarde').css({
		'top':docScroll+ "px",
		'height':hb
	});
	$('div.bg-modal-aguarde').show();
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) { 
			$(window).scroll(function () {
				var docScroll = document.documentElement.scrollTop;
				$('div.bg-modal-aguarde').css('top',docScroll+'px');
				var leftScroll = document.documentElement.scrollLeft;
				$('div.bg-modal-aguarde').css('left',leftScroll+'px');
			});
		}
	} 
	createLightbox('box-modal-aguarde','319','219');
	
}

function mostraAlertaGrande(mensagem){
  document.getElementById("txtAlerta").innerHTML=mensagem;
  document.getElementById("divAlerta").style.visibility = "visible";
}

 
function isValidMail(stringNeeded) {
    if(stringNeeded.match(/^[0-9a-zA-Z-_\.]+@[0-9a-zA-Z-_\.~]+(\.[a-zA-Z]+)+$/)) return true;
    return false;
}

  
/* ----------------------------------------------------------------------------
 * funcoes.js
 * ----------------------------------------------------------------------------
 */
function createMask() {
	var bodyHeight = document.documentElement.clientHeight;
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) { 
          var docScroll = document.documentElement.scrollTop;
		  $('select').each(function(){$(this).hide()});
		  var hb = bodyHeight;
      } else {
	  	var docScroll = '0';
		var hb = '100%';
	  }
	} else {
		var docScroll = '0';
		var hb = '100%';
	}
	$('body').append('<div class="bg-modal"></div>');
	$('div.bg-modal').css({
		'top':docScroll+ "px",
		'height':hb
	});
	$('div.bg-modal').show();
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) { 
			$(window).scroll(function () {
				var docScroll = document.documentElement.scrollTop;
				$('div.bg-modal').css('top',docScroll+'px');
				var leftScroll = document.documentElement.scrollLeft;
				$('div.bg-modal').css('left',leftScroll+'px');
			});
		}
	} 
};
function closeBox(n) {
    $('div.bg-modal').fadeOut('fast');
    $('div.'+n+'').fadeOut('fast');
    if (jQuery.browser.msie) { 
      if(parseInt(jQuery.browser.version) == 6) {
          $('select').each(function(){$(this).show()});
      }
    }
	$('div.bg-modal').remove();
};


function createLightbox(n,width, height) {
	var bodyHeight = document.documentElement.clientHeight;
	var bodyWidth = document.documentElement.clientWidth;
	if (jQuery.browser.safari) {
		var docScroll = document.body.scrollTop;
	} else {
		var docScroll = document.documentElement.scrollTop;
	}
	var docScroll = parseInt(docScroll);
	var bodyHeight = parseInt(bodyHeight);
	var height = parseInt(height);
	
	if (bodyHeight < height ) { 
		var top = (15 + docScroll );
		$('div.'+n+'').css('position','absolute');
	} else {
		if (jQuery.browser.msie) {
			if(parseInt(jQuery.browser.version) == 6) { 
			  var top = (((bodyHeight /2) - (height /2)) + docScroll );
			  $('div.'+n+'').css('position','absolute');
		  } else {
			var top = ((bodyHeight /2) - (height /2));
			$('div.'+n+'').css('position','fixed');
		  }
		} else {
			var top = ((bodyHeight /2) - (height /2));
			$('div.'+n+'').css('position','fixed');
		}
	}
	var top = parseInt(top);
	
	if (bodyWidth < width ) {
		var left = (width /2)+ 10 +'px';
	} else {
		var left = '48%';
	}
	$('div.'+n+'').css({
		'left': left,
		'top': top + "px",
		'width': width + 'px',
		'height': height + 'px',
		'margin-left': -width / 2
	});
	$('div.'+n+'').fadeIn();
};

$(document).ready(function() {

});

function mostraLighbox()
{
   createMask();
   createLightbox('box-modal','416','209');
}
function fechaLighbox()
{
   closeBox('box-modal');
}
function fechaAlertaNovo()
{
   closeBox('box-modal-alerta');
}  
  
  
/* ----------------------------------------------------------------------------
 * tooltip.js
 * ----------------------------------------------------------------------------
 */


/***********************************************
* Fixed ToolTip script- ï¿½ Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='150px' //default tooltip width
var tipbgcolor='#f5f5f5'  //tooltip bgcolor
var disappeardelay=150  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="10px" //horizontal offset of tooltip from anchor link
var horizontal_offset="80px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function abrirPopup(url, largura, altura){
	var tmt_Move_WindowX = (screen.width - largura) / 2; 
	var tmt_Move_WindowY = (screen.height - altura) / 2; 
	var windowPopup = window.open(url, 'popup','width=' + largura +',height=' + altura);
	windowPopup.moveTo(tmt_Move_WindowX, tmt_Move_WindowY);
}

