function isEmail(email){
	var suportado = 0;
	EmailInv = false;

	if (window.RegExp) {
		var tempReg = /a/;
		if (tempReg.test("a")){
			suportado = 1;
		}
	}

	if (!suportado){
		if(((email.indexOf(".") <= 0) || (email.indexOf("@") <= 0)) || ((email.lastIndexOf(".") == (email.length - 1)) || (email.lastIndexOf("@") == (email.length -1)))){
			EmailInv = true;
		}
	}else{
		var tmp1 = /(@.*@)|(\.\.)|(@\.)|(^\.)/;
		var tmp2 = /^.+@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(tmp1.test(email) || !tmp2.test(email)){
			EmailInv = true;
		}
	}

	return !EmailInv;
}

function isCPF(cpf){
	var cpf_limpo = cpf.replace(/\D/g,"");
	if (cpf_limpo.length !=11)
		return false;

	var soma = 0;
	for (var i=0; i<9; i++)
		soma += parseInt(cpf_limpo.charAt(i)) * (10-i);

	if (soma == 0)
		return false;

	primeiro_digito = 11 - soma % 11;
	if (primeiro_digito > 9)
		primeiro_digito = 0;

	if (cpf_limpo.substr(9,1) != primeiro_digito)
		return false;

	var soma = 0;
	for (var i=0; i<10; i++)
		soma += parseInt(cpf_limpo.charAt(i)) * (11-i);

	var segundo_digito = 11 - soma % 11;

	if (segundo_digito > 9)
		segundo_digito = 0;
	if (cpf_limpo.substr(10,1) != segundo_digito)
		return false;

	return true;
}

function isCNPJ(CNPJ) {
	while(/\D/.test(CNPJ))
		CNPJ = CNPJ.replace(/\D/,"");
	if (CNPJ.length < 14)
		return false;
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) {
		a[12] = 0
	} else {
		a[12] = 11-x
	}
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2) {
		a[13] = 0;
	} else {
		a[13] = 11-x;
	}

	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
		return false;
	else
		return true;
}


function mascara(expressao, evento) {
	var e = evento;
	var ascii;

	if (e.keyCode)
		ascii = e.keyCode;
	else if (e.which)
		ascii = e.which;

	chr = String.fromCharCode(ascii);
	if(ascii == 8 || ascii == 9 || ascii == 13 || ascii == 116 || ascii == 37 || ascii == 39 || ascii == 36 || ascii == 35 || ascii == 46){
		return true;
	}
	var regx = new RegExp(expressao);
	return (regx.test(chr));
}

function popup(url,name,features) {
	// Tamanho da janela
	var width = /width=(\d+)/i.exec(features);
	wwidth = width[1];
	var height = /height=(\d+)/i.exec(features);
	wheight = height[1];

	// Tamanho da tela
	swidth  = screen.availWidth;
	sheight = screen.availHeight;

	// Distância do topo esquerdo
	_left = parseInt((swidth / 2) - (wwidth / 2));
	_top = parseInt((sheight / 2) - (wheight / 2));

	features.replace("/top=\d+,?/","");
	features.replace("/left=\d+,?/","");

	features += ',top='+ _top +',left='+ _left;


	//Abre a Janela
	jan = window.open(url,name,features);
	jan.focus();
}

/**
* mascaraCep
*
* Complementa o valor do campo CEP com o traço.
* @param Campo de texto alvo.
* @param Objeto "event" do Javascript.
*/
function mascaraCep(obj,evento) {
	ascii = (evento.keyCode) ? evento.keyCode : evento.which;

	if(ascii == 8 || ascii == 9 || ascii == 13 || ascii == 116 || ascii == 37 || ascii == 39 || ascii == 36 || ascii == 35 || ascii == 46)
		return true;

	str = obj.value.replace(/\D/g,"");
	if (str.length >= 5)
		str = str.substring(0,5) +"-"+ str.substring(5);
	obj.value = str;
	return mascara(/\d/,evento);
}

/**
* mascaraData
*
* Complementa o valor do campo DATA com as barras.
* @param Campo de texto alvo.
* @param Objeto "event" do Javascript.
*/
function mascaraData(obj,evento) {
	ascii = (evento.keyCode) ? evento.keyCode : evento.which;

	if(ascii == 8 || ascii == 9 || ascii == 13 || ascii == 116 || ascii == 37 || ascii == 39 || ascii == 36 || ascii == 35 || ascii == 46)
		return true;

	str = obj.value.replace(/\D/g,"");
	if (str.length >= 4)
		str = str.substring(0,2) +"/"+ str.substring(2,4) +"/"+ str.substring(4);
	else if (str.length >= 2)
		str = str.substring(0,2) +"/"+ str.substring(2);
	obj.value = str;
	return mascara(/\d/,evento);
}

function validaCartao(numero) {
	var valido = true;
	
	while(/\D/.test(numero))
		numero = numero.replace(/\D/ ,"");


	if ((parseInt(numero.charAt(0)) == 3 && numero.length != 15) || ((parseInt(numero.charAt(0)) == 4 || parseInt(numero.charAt(0)) == 5) && numero.length != 16))
		valido = false;

	var total = 0;
	var multiplica = true;
	for(var i=0;i<numero.length;i++) {
		var n = numero.charAt(i);
		n = parseInt((multiplica) ? n*2 : n);
		n -= (n > 9) ? 9 : 0;
		total += n;
		multiplica = !multiplica;
	}
	
	valido = ((total%10)==0);

	if (numero.length == 0 || total == 0)
		valido = false;

	return valido;
}
var palavras = Array();
function glossario(palavra) {
	for(var i=0;i<palavras.length;i++) {
		var state = "none";
		if (palavras[i] == palavra)
			state = "block";
		document.getElementById(palavras[i]).style.display = state;
	}
}

function atualizarAssinatura() {
	var meses;
	if (document.getElementById("tipo_assinatura1").checked){
		meses 	= 3;
		dias	= 92;
	}else if (document.getElementById("tipo_assinatura2").checked){
		meses 	= 6;
		dias	= 183;
	}else if (document.getElementById("tipo_assinatura3").checked){
		meses 	= 12;
		dias	= 365;
	}else if (document.getElementById("tipo_assinatura4") != null && document.getElementById("tipo_assinatura4").checked){
		meses 	= 0;
		dias	= 0;
	}else
		return;

	var plano;
	if (document.getElementById("plano1").checked)
		plano = 1;
	else if (document.getElementById("plano2").checked)
		plano = 5;
	else if (document.getElementById("plano3").checked)
		plano = 10;
	else
		return;

	var valor;
	if (meses == 3 && plano == 1)
		valor = "R$ 25,00";
	else if (meses == 3 && plano == 5)
		valor = "R$ 30,00";
	else if (meses == 3 && plano == 10)
		valor = "R$ 50,00";
	if (meses == 6 && plano == 1)
		valor = "R$ 30,00";
	else if (meses == 6 && plano == 5)
		valor = "R$ 50,00";
	else if (meses == 6 && plano == 10)
		valor = "R$ 80,00";
	if (meses == 12 && plano == 1)
		valor = "R$ 50,00";
	else if (meses == 12 && plano == 5)
		valor = "R$ 80,00";
	else if (meses == 12 && plano == 10)
		valor = "R$ 120,00";
	
	var dataAgora = new Date();
	dataAgora.setDate(dataAgora.getDate()+dias);
	
	//dataAgora.setMonth(dataAgora.getMonth()+meses);
	document.getElementById("validade").innerHTML = dataAgora.getDate() +"/"+ (dataAgora.getMonth() < 10 ? "0" : "") + (dataAgora.getMonth()+1) +"/"+ dataAgora.getFullYear();
	document.getElementById("preco").innerHTML = valor;

}
