function mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}
function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}

function data(v){ 
	v=v.replace(/\D/g,"")
	v=v.replace(/(\d{2})(\d)/,"$1/$2")
	v=v.replace(/(\d{2})(\d)/,"$1/$2")
	return v  
}

function validarCPF(CPF){ 
	if (CPF != ''){ 
		if (!verificarCPF(CPF)){ 
			alert('CPF Inválido!'); 
			document.formulario.txtCPF.value=''; 
			document.formulario.txtCPF.focus(); 
		} 
	} 
}  

function verificarCPF(c){ 
	c = c.replace('.','');	
	c = c.replace('.','');	
	c = c.replace('-','');	
	var i;  
	s = c; 
	var c = s.substr(0,9);  
	var dv = s.substr(9,2);  
	var d1 = 0;  
	var v = false; 
	for (i = 0; i < 9; i++)  
	{  
		d1 += c.charAt(i)*(10-i);  
	}  
	if (d1 == 0){  
	v = true;  
	return false;  
	}  
	d1 = 11 - (d1 % 11);  
		if (d1 > 9) d1 = 0;  
			if (dv.charAt(0) != d1)  
			{  
		v = true; 
		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)  
	{  
	v = true; 
	return false;  
	}  
	if (!v) { 
	return true; 
	} 
}

function cpf(v){
	v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
	//de novo (para o segundo bloco de números)
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
	return v
}

function formatarCPF (campo,teclapres) { 
	var tecla = teclapres.keyCode;  
	if ((tecla < 48) || (tecla > 57)) {
		return false;
	} 
	vr = campo.value;  
	vr = vr.replace( '-', '' );  
	vr = vr.replace( '.', '' );  
	vr = vr.replace( '.', '' );  
	tam = vr.length; 
	 
	if (tam < 11 && tecla != 8){ tam = vr.length + 1 ; }  
	if (tecla == 8 ){	tam = tam - 1 ; }  
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){  
		if ( tam <= 2 ){  
	 		campo.value = vr ; }  
	 	if ( (tam > 2) && (tam <= 5) ){  
	 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }  
	 	if ( (tam >= 6) && (tam <= 8) ){  
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }  
	 	if ( (tam >= 9) && (tam <= 11) ){  
			campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }  
	}
}

function data2(vValor){ 
	var checkStr = ''; 
	checkStr = vValor; 
	var err=0; 
	var psj=0; 
	var dia = 0; 
	var mes = 0; 
	var ano = 0; 
	var barra1 = ''; 
	var barra2 = ''; 
	dia = checkStr.substring(0, 2); 
	barra1 = checkStr.substring(2, 3); 
	mes = checkStr.substring(3, 5); 
	barra2 = checkStr.substring(5, 6); 
	ano = checkStr.substring(6, 10); 
	//verifica??es b?sicas 
	if (checkStr.length != 10) 
		err = 1; 
	if (mes<1 || mes>12) 
		err = 1; 
	if (barra1 != '/') 
		err = 1; 
	if (dia<1 || dia>31) 
		err = 1; 
	if (barra2 != '/') 
		err = 1; 
	if (ano<=1930 || ano>2900) 
		err = 1; 
	//verifica??es avan?adas 
	// m?s com 30 dias 
	if (mes==4 || mes==6 || mes==9 || mes==11){ 
		if (dia==31) 
			err=1; 
	} 
	// fevereiro e ano bissexto 
	if (mes==2){ 
		var g = parseInt(ano/4); 
		if (isNaN(g)) { 
			err=1; 
		} 
		if (dia>29) 
			err=1; 
		if (dia==29 && ((ano/4)!=parseInt(ano/4))) 
			err=1; 
	} 
	if (err==1) {
		alert('Data Inválida, a data deve ser no formato: dd/mm/yyyy');
		return 'Nascimento';
	}else {
		return vValor; }
}
function cep(v){
	v=v.replace(/\D/g,"")                //Remove tudo o que não é dígito
	v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
	return v
}
function numero(v){
	v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	return v
}
function numeroCorp(v){
	v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
	return v
}
function telefone(v){
	v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	v=v.replace(/^(\d\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
	v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
	return v
}
function termos() {
	window.open( "termos/termos.htm", "SKY", "status = 1, height = 580, width = 550, scrollbars=yes, resizable=no" )
}
function condicoes() {
	window.open( "termos/condicoes.htm", "SKY", "status = 1, height = 580, width = 550, scrollbars=yes, resizable=no" )
}
function prime() {
	window.open( "termos/prime.htm", "SKY", "status = 1, height = 580, width = 550, scrollbars=yes, resizable=no" )
}
function globo() {
	window.open( "termos/globo.htm", "SKY", "status = 1, height = 580, width = 550, scrollbars=yes, resizable=no" )
}
function sbt() {
	window.open( "termos/sbt.htm", "SKY", "status = 1, height = 580, width = 550, scrollbars=yes, resizable=no" )
}
function pacote() {
	window.open( "termos/pacotes.htm", "SKY", "status = 1, height = 580, width = 590, scrollbars=yes, resizable=no" )
}
function assine(id){
	var combo = document.getElementById("cboPacote");
	var cpf = document.getElementById("txtCPF");
	var nome = document.getElementById("txtNome");
	var Sobrenome = document.getElementById("txtSobreNome");
	var nascimento = document.getElementById("txtNascimento");
	var email = document.getElementById("txtEmail");
	var DDDTel = document.getElementById("txtDDDTel");
	var telefone = document.getElementById("txtTelefone");
	var cep = document.getElementById("txtCep");
	var bairro = document.getElementById("txtBairro");
	var estado = document.getElementById("txtEstado");
	var cidade = document.getElementById("txtCidade");
	var endereco = document.getElementById("txtEndereco");
	var numero = document.getElementById("txtNumero");
	
	if(combo.value=='0'){
		alert('Escolha um Pacote!');
		combo.focus();
		
	}
	else if(nome.value==''||nome.value=='Nome'){
		alert('Preencha o campo NOME corretamente!');
		nome.focus();
		
	}
	else if(Sobrenome.value==''||Sobrenome.value=='Sobrenome'){
		alert('Preencha o campo SOBRENOME corretamente!');
		Sobrenome.focus();
	}
	else if(cpf.value==''){
		alert('Preencha o campo CPF corretamente!');
		cpf.focus();
	}
	else if(nascimento.value==''||nascimento.value=='Nascimento'){
		alert('Preencha o campo DATA DE NASCIMENTO corretamente!');
		nascimento.focus();
	}
	else if(DDDTel.value==''||DDDTel.value=='DDD'||DDDTel.value.length<3){
		alert('Preencha o campo DDD corretamente!');
		DDDTel.focus();
	}
	else if(telefone.value==''||telefone.value=='Telefone'){
		alert('Preencha o campo TELEFONE corretamente!');
		telefone.focus();
	}
	else if(cep.value==''||cep.value=='CEP'||cep.value.length<9){
		alert('Preencha o campo CEP corretamente!');
		cep.focus();
	}
	else if(bairro.value==''||bairro.value=='Bairro'){
		alert('Preencha o campo BAIRRO corretamente!');
		bairro.focus();
	}
	else if(estado.value==''||estado.value=='Estado'){
		alert('Preencha o campo ESTADO corretamente!');
		estado.focus();
	}
	else if(cidade.value==''||cidade.value=='Cidade'){
		alert('Preencha o campo CIDADE corretamente!');
		cidade.focus();
	}
	else if(endereco.value==''||endereco.value=='Endereço'){
		alert('Preencha o campo ENDEREÇO corretamente!');
		endereco.focus();
	}
	else if(numero.value==''||numero.value=='Número'){
		alert('Preencha o NÚMERO da Casa ou Apartamento!');
		numero.focus();
	}
	else{
		document.formulario.action='?ac=assine&id='+id;
		document.formulario.submit();
	}
}
function atualizaPacotes(id){
	location.href="?ac=compre&id="+id;
}