function check_cpf(objCampo) {

	var novoCpf;
	var rExp1 = /\./g;
	var rExp2 = /\//g;
	var rExp3 = /-/g;

	novoCpf = new String(objCampo.value);
	CPF = novoCpf.replace(rExp1, "");
	CPF = CPF.replace(rExp2, "");		
	CPF = CPF.replace(rExp3, "");	
	
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); 

	for (I=0; I<=8; I++) {
		DIGITO[I] = CPF.substr( I, 1);
	}

	POSICAO = 10;
	SOMA = 0;
	for (I=0; I<=8; I++) {
		SOMA = SOMA + DIGITO[I] * POSICAO;
		POSICAO = POSICAO - 1;
	}

	DIGITO[9] = SOMA % 11;
	
	if (DIGITO[9] < 2) {
		DIGITO[9] = 0;
	} else {
		DIGITO[9] = 11 - DIGITO[9];
	}

	POSICAO = 11;
	SOMA = 0;

	for (I=0; I<=9; I++) {
		SOMA = SOMA + DIGITO[I] * POSICAO;
		POSICAO = POSICAO - 1;
	}

	DIGITO[10] = SOMA % 11;

	if (DIGITO[10] < 2) {
		DIGITO[10] = 0;
	} else {
		DIGITO[10] = 11 - DIGITO[10];
	}

	DV = DIGITO[9] * 10 + DIGITO[10];

	if (DV != DV_INFORMADO) {
		lightbox("Mensagem","O CPF informado é inválido!",objCampo.name);
		return false;
	}

	for (I=0; I<=9; I++) {

		if (DIGITO[I] == DIGITO[9] && DIGITO[I] == DIGITO[8] && DIGITO[I] == DIGITO[7] && DIGITO[I] == DIGITO[6] && DIGITO[I] == DIGITO[5] && DIGITO[I] == DIGITO[4] && DIGITO[I] == DIGITO[3] && DIGITO[I] == DIGITO[2] && DIGITO[I] == DIGITO[1] && DIGITO[I] == DIGITO[0]) {
			lightbox("Mensagem","O CPF informado é inválido!",objCampo.name);
			return false;
		}
	}
}

function goCampo(element) {
		document.getElementById(element).focus();
}
function trim(str) {
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);
  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);
  return str;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function check_email(objCampo) {

	var str=objCampo.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)) {
		return true;
	} else {
		lightbox("Mensagem","O E-Mail digitado é inválido!",objCampo.name);
		return false;
	}
}
function goEnviarContato() {

	var form = document.getElementById("ajaxpost");
	form.action = "php/contato_enviar.php";
	
	if ( trim(document.getElementById("nome").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Nome!","nome");
		return false;
	}
	if ( trim(document.getElementById("email").value) == "" ) {
		lightbox("Mensagem","Preencha o campo E-Mail!","email");
		return false;
	} else {
		if ( check_email(document.getElementById("email")) == false ) {
			return false;
		}		
	}
	if ( trim(document.getElementById("ddd_fone").value) == "" ) {
		lightbox("Mensagem","Preencha o campo DDD do Telefone!","ddd_fone");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("ddd_fone").value))) {
			lightbox("Mensagem","O campo DDD do Telefone deve conter apenas números!","ddd_fone");
			return false;
		}
	}
	if ( trim(document.getElementById("telefone").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Telefone!","telefone");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("telefone").value))) {
			lightbox("Mensagem","O campo Telefone deve conter apenas números!","telefone");
			return false;
		}
	}
	if ( trim(document.getElementById("mensagem").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Mensagem!","mensagem");
		return false;
	}
	
	lightconfirm(form.id, "centro", "Confirmação", "Confirma o envio da mensagem de contato?");
	return false;

}

function goEnviarIndicacao() {

	var form = document.getElementById("indicacao");
	form.action = "php/indicacao_enviar.php";

	if ( trim(document.getElementById("seu_nome").value) == "" ) {
		lightbox("Mensagem","Preencha o seu Nome!","seu_nome");
		return false;
	}
	if ( trim(document.getElementById("seu_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","seu_email");
		return false;
	} else {
		if ( check_email(document.getElementById("seu_email")) == false ) {
			return false;
		}		
	}
	if ( trim(document.getElementById("nome_indicado").value) == "" ) {
		lightbox("Mensagem","Preencha o Nome para Indicação!","nome_indicado");
		return false;
	}
	if ( trim(document.getElementById("email_indicado").value) == "" ) {
		lightbox("Mensagem","Preencha o E-Mail para Indicação!","email_indicado");
		return false;
	} else {
		if ( check_email(document.getElementById("email_indicado")) == false ) {
			return false;
		}		
	}
	
	lightconfirm(form.id, "indique","Confirmação","Confirma o envio da Indicação para "+document.getElementById("nome_indicado").value+" ?");
	return false;

}

function goVerificaEmail() {
	
	var form = document.getElementById("cadastre");

	if ( trim(document.getElementById("cad_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","cad_email");
		return false;
	} else {
		if ( check_email(document.getElementById("cad_email")) == false ) {
			return false;
		}		
	}
	
	ajaxpage('php/cadastro_verificar.php?cad_email='+document.getElementById("cad_email").value, 'verEmail','GET');
	
}
function goLiberaBotao(bol) {
	
	document.getElementById("emailok").value = bol;
	
}
function goEnviarCadastro() {

	var form = document.getElementById("cadastre");
	form.action = "php/cadastro_gravar.php";

	
	if ( trim(document.getElementById("cad_nome").value) == "" ) {
		lightbox("Mensagem","Preencha o seu Nome!","cad_nome");
		return false;
	}
	if ( trim(document.getElementById("cad_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","cad_email");
		return false;
	} else {
		if ( check_email(document.getElementById("cad_email")) == false ) {
			return false;
		}		
	}
	if( document.getElementById("emailok").value == 0 ) {
		lightbox("Mensagem","Informe um E-Mail válido!","cad_email");
		return false;		
	}
	if ( document.getElementById("cad_cpf").value == "" ) {
		lightbox("Mensagem","Preencha o seu CPF!","cad_cpf");
		return false;
	} else {
		if ( check_cpf(document.getElementById("cad_cpf")) == false ) {
			return false;
		}
	}	
	if ( trim(document.getElementById("cad_dia").value) == "" ) {
		lightbox("Mensagem","Selecione o Dia do seu Aniversário!","cad_dia");
		return false;
	}
	if ( trim(document.getElementById("cad_mes").value) == "" ) {
		lightbox("Mensagem","Selecione o Mês do seu Aniversário!","cad_mes");
		return false;
	}
	
	if ( trim(document.getElementById("cad_dddtel").value) == "" ) {
		lightbox("Mensagem","Preencha o campo DDD do Telefone!","cad_dddtel");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("cad_dddtel").value))) {
			lightbox("Mensagem","O campo DDD do Telefone deve conter apenas números!","cad_dddtel");
			return false;
		}
	}
	if ( trim(document.getElementById("cad_telefone").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Telefone!","cad_telefone");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("cad_telefone").value))) {
			lightbox("Mensagem","O campo Telefone deve conter apenas números!","cad_telefone");
			return false;
		}
	}
	
	if ( trim(document.getElementById("cad_area").value) == "" ) {
		lightbox("Mensagem","Selecione a Área de Atividade!","cad_area");
		return false;
	}
	if ( trim(document.getElementById("cad_atividade").value) == "" ) {
		lightbox("Mensagem","Selecione a Atividade!","cad_atividade");
		return false;
	}

	if ( trim(document.getElementById("cad_senha").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Senha!","cad_senha");
		return false;
	}
	if ( trim(document.getElementById("cad_csenha").value) == "" ) {
		lightbox("Mensagem","Confirme a sua Senha!","cad_csenha");
		return false;
	}
	if ( trim(document.getElementById("cad_senha").value) != trim(document.getElementById("cad_csenha").value) ) {
		lightbox("Mensagem","As Senhas informadas não conferem!","cad_senha");
		return false;
	}	

	
	if ( trim(document.getElementById("cad_cep").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Cep!","cad_cep");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("cad_cep").value))) {
			lightbox("Mensagem","O campo Cep deve conter apenas números!","cad_cep");
			return false;
		}
	}
	if ( trim(document.getElementById("cad_endereco").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Endereço!","cad_endereco");
		return false;
	}
	
	if ( trim(document.getElementById("cad_numero").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Número!","cad_numero");
		return false;
	} else {
		if ( isNaN(trim(document.getElementById("cad_numero").value))) {
			lightbox("Mensagem","O campo Número deve conter apenas números!","cad_numero");
			return false;
		}
	}
	
	if ( trim(document.getElementById("cad_bairro").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Bairro!","cad_bairro");
		return false;
	}
	if ( trim(document.getElementById("cad_cidade").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Cidade!","cad_cidade");
		return false;
	}
	if ( trim(document.getElementById("cad_uf").value) == "" ) {
		lightbox("Mensagem","Selecione o campo Uf!","cad_uf");
		return false;
	}
	if ( trim(document.getElementById("cad_como").value) == "" ) {
		lightbox("Mensagem","Indique como tomou conhecimento do Portal CGS!","cad_como");
		return false;
	}
	
	if ( document.getElementById("cad_regulamento").checked == false ) {
		lightbox("Mensagem","Você deve ler e aceitar o regulamento do Portal CGS!","cad_regulamento");
		return false;
	}
	

	lightconfirm(form.id,'cadastro_form',"Confirmação",document.getElementById("cad_nome").value+", você está confirmando o seu cadastro junto ao Portal CGS.<br><br>Clique no botão OK para finalizar o processo.");

	return false;

}

function goPedido(curso) {
	
	ajaxpage('php/pedidos.php?cursos['+curso+']=1', 'conteudo');
	
}

function goRetornaPedido() {
	
	ajaxpage('php/pedidos.php', 'conteudo');
	
}

function goRemoverPedido(curso) {
	
	ajaxpage('php/pedidos_remover.php?curso='+curso, 'conteudo');
	
}
function goMaisCursos(cod) {
	
	ajaxpage('php/segmento_listar.php?s='+cod, 'conteudo');
	
}
function goNavegar(pagina) {
	
	ajaxpage('navega.php?p='+pagina, 'conteudo');
	
}

function goPagina(pagina) {
	
	ajaxpage('pagina.php?p='+pagina, 'conteudo');
	
}

function goRecalcular() {
	
//	ajaxpost('php/pedidos_recalcular.php', 'conteudo','POST','pedido_confirmar');
	document.getElementById("pedido_confirmar").submit();
	
}

function goConfirmar() {
	
	var form = document.getElementById("pedido_confirmar");
	ajaxpost("php/pedidos_confirmar.php", "conteudo", "POST", form.id );
	
}

function goExibirDados(){
		if(document.getElementById('opt1').checked == true)
		document.getElementById('set1').style.display = "block";
		else {
			document.getElementById('ddlPontos')[0].selected = true;
			document.getElementById('set1').style.display = "none";
            document.getElementById('ecard_pontos_assinantes').innerHTML = document.getElementById('PontosAtual').value;
		}
}

function atualizaPontos()
{
    var temp;        
    temp = new Number(document.getElementById('PontosAtual').value);
    if (document.getElementById('ddlPontos').value != ""){
        ponto = document.getElementById('ddlPontos');
        x = ponto.selectedIndex;
        xx = ponto.options[x].text.split("-");
        temp2 = new Number(trim(xx[0]));
    } else
        temp2 = 0;
    temp = temp - temp2;
    document.getElementById('ecard_pontos_assinantes').innerHTML = temp;
}

function goRemoverDesconto()
{
    ajaxpage("php/pedidos_confirmar.php?pontos=", "conteudo");
}

function goRemoverPromocao()
{
    ajaxpage("php/pedidos_confirmar.php?codigopromo=", "conteudo");
}

function goConcluir() {	
	var form = document.getElementById("ajaxpost");
	lightconfirm(form.id,'conteudo',"Confirmação","Você está confirmando o seu pedido junto ao<br>Portal CGS.<br><br>Clicando no botão OK, você estará autorizando<br>o Portal CGS a proceder com o método de<br> pagamento escolhido.<br><br>Clique no botão OK para finalizar o processo.");		
}

function utilizarPontos(){

    var id = document.getElementById("ddlPontos").value;
    var perc = document.getElementById("ddlPontos").value;
    ajaxpage("php/pedidos_confirmar.php?pontos="+id, "conteudo");


}

function calcularPromocao(){

    if(trim(document.getElementById("codigopromo").value) != "")
        ajaxpage("php/pedidos_confirmar.php?codigopromo="+trim(document.getElementById("codigopromo").value), "conteudo");


}

function goSelecionaPagamento(qual){

	with ( document.getElementById("pedido_confirmar") ) {
		tipo_pagamento[qual].checked = true;
	}
	
}

function goEnqueteResultados() {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 550) / 2);

	enquetes=dhtmlwindow.open("ajaxbox", "ajax", "php/enquete_exibir.php", "Portal CGS .:. Enquete", "width=550px,height=400px,resize=0,scrolling=1,left="+left)
	
	
//	ajaxwin.onclose=function(){return window.confirm("Close window 3?")} //Run custom code when window is about to be closed

//	lightboxContent("showenquete","550px","Portal CGS .:. Enquete","<div id='enquetediv'>"+ajaxpage("php/enquete_exibir.php", 'enquetediv','GET' )+"</div>");

}

function goEnquetesAnteriores(pId) {
	
//	enquetes.setForms("enquete_anteriores");
//	enquetes.load('ajax','php/enquete_exibir.php?eId='+pId+'&exibir=1','','POST');
	enquetes.load('ajax','php/enquete_exibir.php?eId='+pId+'&exibir=1');
	
}
function goEnqueteVotar() {

	var i, k = 0;

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 550) / 2);


	with( document.getElementById("enquete_votar") ) {
	
		for( i=0;i<elements.length;i++) {
			if( elements[i].type == "radio" && elements[i].checked == true ){
				k++;
			}
		}
		
		if( k > 0 ){

			enquetes=dhtmlwindow.open("ajaxbox", "ajax", "php/enquete_votar.php", "Portal CGS .:. Enquete", "width=550px,height=400px,resize=0,scrolling=1,method=1,left="+left,"","enquete_votar");

		}else{
			lightbox("Mensagem","Selecione a resposta antes de votar.",'');
		}
	}
}
function goIndicar() {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 400) / 2);

	indique=dhtmlwindow.open("indicar", "inline", document.getElementById("form_indique").innerHTML, "Portal CGS .:. Indique o Portal", "width=400,height=400,resize=0,scrolling=1,left="+left);
	
//	goCampo("seu_nome");

//	lightboxContent("indicar","325px","Portal CGS .:. Indique o Portal",document.getElementById("form_indique").innerHTML);

}
function goCadastro() {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 20 - 600) / 2);

	cadastro_form=dhtmlwindow.open("ajaxbox", "ajax", "php/cadastro.php", "Portal CGS .:. Cadastro Fidelidade", "width=600px,height=600px,resize=0,scrolling=1,left="+left)

//	cadastro=dhtmlwindow.open("cadastros", "inline", document.getElementById("form_cadastro").innerHTML, "Portal CGS .:. Cadastro Fidelidade", "width=600,height=570,resize=0,scrolling=1,left="+left);

//	goCampo("cad_nome");

}
function goTabelaPontos() {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 20 - 600) / 2);


	cadastro=dhtmlwindow.open("tabela", "ajax", "php/cadastro_tabela.php", "Portal CGS .:. Tabela de Pontos", "width=600,height=300,resize=0,scrolling=1,left="+left);

}
function goEsqueceuSenha() {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var left = ((arrayPageSize[0] - 400) / 2);

	esqueceu=dhtmlwindow.open("lembrar", "ajax", "php/esqueceu_senha.php", "Portal CGS .:. Esqueceu sua senha?", "width=400,height=200,resize=0,scrolling=1,left="+left);

}

function goEnviarSenha() {
	
	var form = document.getElementById("esqueceu");

	if ( trim(document.getElementById("esq_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","esq_email");
		return false;
	} else {
		if ( check_email(document.getElementById("esq_email")) == false ) {
			return false;
		}		
	}
	
	if ( trim(document.getElementById("esq_dia").value) == "" ) {
		lightbox("Mensagem","Selecione o Dia da Data de Nascimento!","esq_dia");
		return false;
	}
	if ( trim(document.getElementById("esq_mes").value) == "" ) {
		lightbox("Mensagem","Selecione o Mês da Data de Nascimento!","esq_mes");
		return false;
	}
	
	ajaxpost("php/esqueceu_senha.php", "form_esqueceu", "POST", form.id );
//	lightconfirm(form.id,'lembrar',"Confirmação","Confirma o envio da sua senha?");
	
}

function goMenuAcessar() {
	
	var form = document.getElementById("acesso");

	if ( trim(document.getElementById("acesso_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","acesso_email");
		return false;
	} else {
		if ( check_email(document.getElementById("acesso_email")) == false ) {
			return false;
		}		
	}
	
	if ( trim(document.getElementById("acesso_pass").value) == "" ) {
		lightbox("Mensagem","Preencha a sua Senha!","acesso_pass");
		return false;
	}	


	ajaxpost("php/acesso.php", "geral", "POST", form.id );
	

	
}

function goCorpAcessar() {
	
	var form = document.getElementById("form_corp");

	if ( trim(document.getElementById("corp_log").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Login!","corp_log");
		return false;
	}
	
	if ( trim(document.getElementById("corp_pass").value) == "" ) {
		lightbox("Mensagem","Preencha o campo Senha!","corp_pass");
		return false;
	}	

	ajaxpost("../php/acesso_corp.php", "geral_corp", "POST", form.id );
	

	
}

function goSairCorp() {
	
	url = "/corporativo/sistemaCorp_sair.php";
	window.location = url; 
	
}
function goAreaRestritaCorp() {

	window.location="/corporativo/sistemaCorp.php";
//	window.open('sistemaCorp.php','principal','height=600,width=800,top=0,left=0,resizable=no,status=1, scrollbars=yes');
	
}



function goPedidoAcessar() {
	
	var form = document.getElementById("acesso");

	if ( trim(document.getElementById("pacesso_email").value) == "" ) {
		lightbox("Mensagem","Preencha o seu E-Mail!","pacesso_email");
		return false;
	} else {
		if ( check_email(document.getElementById("pacesso_email")) == false ) {
			return false;
		}		
	}
	
	if ( trim(document.getElementById("pacesso_pass").value) == "" ) {
		lightbox("Mensagem","Preencha a sua Senha!","pacesso_pass");
		return false;
	}
	
	document.getElementById("destino").value = "php/pedidos_confirmar.php";
	document.getElementById("acesso_pass").value = document.getElementById("pacesso_pass").value;
	document.getElementById("acesso_email").value = document.getElementById("pacesso_email").value;
	
	ajaxpost("php/acesso.php", "conteudo", "POST", form.id );
	
}
function goAreaRestrita() {

	window.location="/sistema.php";
	
}
function goSair() {
	
	window.location = '/sistema_sair.php';
}

function goNoticias(id){

	window.location = "php/noticias.php?id="+id;
}

function goCurso(id) {
	
	ajaxpage("php/cursos_exibir.php?id="+id, "conteudo");
	
}

function goShow(id) {
	
	objDiv = document.getElementById(id);
	var display = objDiv.style.display ? '' : 'none';
	objDiv.style.display = display;
	
}

function OpenSaibaMais(){
	
	window.open('http://www.visa.com.br/vbv/vbv_saibamais.asp','principal','height=435,width=270,top=0,left=0,resizable=no,status=1')
	
}

function goVisaVBV(){
	
	document.getElementById('visaVBV').submit();
	window.location='http://www.portalcgs.com.br/';
	
}