$(function(){
  
});

// popup
function janela(url, nome, param) {
  window.open(url, nome, param);
}

// track de sessões com o GA
function track(sessao) {
	pageTracker._trackPageview(sessao);
}

// Validação de CPF
function validaCPF(cpf) 
{
  cpf = cpf.replace(/(\.|\-)+/g, '');
  
	if ( cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || 
		cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || 
		cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || 
		cpf == "88888888888" || cpf == "99999999999" ) {
		return false;
	}
	soma = 0;
	for ( i=0; i < 9; i ++ ) {
		soma += parseInt(cpf.charAt(i)) * (10 - i);
	}
	resto = 11 - (soma % 11);
	if ( resto == 10 || resto == 11 ) {
		resto = 0;
	}
	if ( resto != parseInt(cpf.charAt(9)) ) { 
		return false;
	}
	soma = 0;
	for ( i = 0; i < 10; i ++ ) { 
		soma += parseInt(cpf.charAt(i)) * (11 - i);
	}
	resto = 11 - (soma % 11);
	if ( resto == 10 || resto == 11 ) { 
		resto = 0;
	}
	if ( resto != parseInt(cpf.charAt(10)) ) { 
		return false;
	}
	return true;
}

function validaEmail(s){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(s); 
}

// Máscara
function mascara(obj, what) {
	var s = new String(obj.value);
	// Remove todos os caracteres não numéricos
	s = s.replace(/\D/g,'');
	
	switch(what) {
  	case 'cpf' :
  	  s = s.replace(/(\d{3})(\d)/, "$1.$2");
    	s = s.replace(/(\d{3})(\d)/, "$1.$2");
    	s = s.replace(/(\d{3})(\d)/, "$1-$2");
    	break;
    case 'data' :
      s = s.replace(/(\d{2})(\d)/, "$1/$2");
      s = s.replace(/(\d{2})(\d)/, "$1/$2");
      break;
    case 'telefone' :
      s = s.replace(/(\d{2})(\d)/, "($1) $2");
      s = s.replace(/(\d{4})(\d)/, "$1-$2");
      break;
	}
	
	obj.value = s;
	
	return true;
}
