function mostraTermos() {
	pulatela('contrato_nfemais.html');
}

function preenche_login(x) {
	if(x.value.indexOf(' ') == -1) document.getElementById('loginc').value = x.value.toLowerCase();
}

function formaAbrir() {
	if(document.getElementById('checkFormaAbrir').checked) {
		javascript:pulatela("http://nfe2.nfemais.com.br", 1024, 768);
	}
	else {
		window.location = 'http://nfe2.nfemais.com.br';
	}
}

function veriemail(x) {
	if ((x == "") ||
		(x.indexOf("@") < 1) ||
		(x.indexOf(".") < 1) ||
		(x.indexOf("@.") > -1) ||
		(x.indexOf(".@") > -1) ||
		(x.indexOf(" ") > -1) ||
		(x.indexOf(",") > -1)) {
		return false;
	} else {
		return true;
	}
}

function veri_form_contato(x) {
	if(x.nome.value == '') {
		alert('Por favor, preencha seu nome.');
		x.nome.select();
		return false;
	} else if(!veriemail(x.email.value)) {
		alert('Por favor, informe corretamente seu e-mail.');
		x.email.select();
		return false;
	} else if(x.mensagem.value == '') {
		alert('Por favor, escreva sua mensagem antes de clicar no botão.');
		x.mensagem.select();
		return false;
	} else {
		return true;
	}
}

function veri_form_cadastro(x) {
	if(!vericpfcgc(x.cpfcnpj)) {
		alert('CPF ou CNPJ inválido.');
		x.cpfcnpj.select();
		return false;
	} else if(x.razao.value == '') {
		alert('Por favor, preencha seu nome ou Razão Social de sua empresa.');
		x.razao.select();
		return false;
	} else if(x.uf.value == '') {
		alert('Por favor, selecione o seu Estado.');
		return false;
 	} else if(x.fone.value == '') {
		alert('Por favor, informe corretamente seu telefone com DDD.');
		x.fone.select();
		return false;
 	} else if(!veriemail(x.email.value)) {
		alert('Por favor, informe corretamente seu e-mail.');
		x.email.select();
		return false;
 	} else if(x.login.value == '') {
		alert('Por favor, preencha um login válido.');
		x.login.select();
		return false;
 	} else if(x.senha.value == '') {
		alert('Por favor, preencha uma senha válida.');
		x.senha.select();
		return false;
 	} else if(x.senha.value != x.senha2.value) {
		alert('A senha digitada não confere com a senha repetida.');
		x.senha.select();
		return false;
	} else if(x.aceitoTermos.checked == false) {
		alert('Para concluir seu cadastro, é obrigatório que você aceite os Termos de Utilização do sistema.');
		x.aceitoTermos.select();
		return false;
	}
	return true;
}


function vericpf(x) {
	var CPF = x.value;
	if(CPF=='') var faiado = true;
	else {
		if(CPF == "00000000000" || CPF == "11111111111" ||
			CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
			CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
			CPF == "88888888888" || CPF == "99999999999" || CPF == "00000000000") {
			var faiado = true;
		}
		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))) var faiado = true;
		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))) var faiado = true;
	}
	if(faiado) return false;
	else return true;
}

function vericgc(x) {
	var s = x.value;
	var i;
	if(s.length == "15") s = s.substr(1,14);
	if(s == '00000000000000') var faiado = true;
	else {
		var c = s.substr(0,12);
		var dv = s.substr(12,2);
		var d1 = 0;
		for (i = 0; i < 12; i++) d1 += c.charAt(11-i)*(2+(i % 8));
		if (d1 == 0) var faiado = true;
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if(dv.charAt(0) != d1) var faiado = true;
		d1 *= 2;
		for (i = 0; i < 12; i++) d1 += c.charAt(11-i)*(2+((i+1) % 8));
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1) var faiado = true;
	}
	if(faiado) return false;
	else return true;
}


function vericpfcgc(x) {
	if (x.value.length <= 13) return vericpf(x);
	else return vericgc(x);
}

//Limitador de Caracteres
//Tem como função limitar que as pessoas só possam digitar os caracteres permitidos pelo programador.
//por Vini L.Azev. - favor manter os créditos
function limitachars(z, y) {
    x = z.value;
    y = y.toUpperCase();
    y = y.replace('A-Z', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    y = y.replace('0-9', '1234567890');
    var chars_permitidos = y;
    var resposta = '';
    for(ii=0; ii<x.length; ii++) {
        if ((chars_permitidos.indexOf(x.charAt(ii).toUpperCase()) > -1) || (chars_permitidos.indexOf(x.charAt(ii).toLowerCase()) > -1)) {
            resposta += x.charAt(ii);
        }
    }
    z.value = resposta;
}

function pulatela(url, w, h) {
	if(isNaN(w)) var w=750;
	if(isNaN(h)) var h=600;
	var y = screen.availHeight/2-h/2;
	var x = screen.availWidth/2-w/2;
	var aleatorio = Math.random();
	aleatorio = "a" + aleatorio;
	var ultimo = aleatorio.charAt(aleatorio.length-1);
	ultimo = ultimo + aleatorio.charAt(aleatorio.length-2);
	telapopup = window.open(url, 'tela'+ ultimo, 'width='+ w +', height='+ h +', left='+ x +', top='+ y +', scrollbars=1, resizable=1');
	if(!telapopup) alert('Atenção, o seu navegador está bloqueando as janelas popups, é necessário que você habilite a visualização de Popups.');
}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function pega_ref() {
//	document.formulario.afiliado.value = getCookie("nfemaisref");
}

function mostraChat() {
	$('#chatBox').className = 'chatVisible';
}


function mostraBannerChat() {
//	if(getCookie('egestorhidechat')) {
//		$('#miniChatBox').animate({'left': '+=26px'}, 'slow');
//	} else {
//		$('#chatBox').animate({'top': '+=450px'}, 2000);
		$('#chatBox').animate({'bottom': '+=78px'}, 'slow');
//	}
}

function someBannerChat() {
	//$('#chatBox').animate({'left': '-=630px'}, 'slow', '', function() {
	//	$('#chatBox').hide();
	//	$('#miniChatBox').animate({'left': '+=26px'}, 'slow');
	//});
	//createCookie('egestorhidechat', true, 2);
}

//Teste para sumir o chat ao chegar no fim da página
//$(window).scroll(function(){
        //if  ($(window).scrollTop() == $(document).height() - $(window).height()){
           //lastPostFunc();
        //}
//});

clicado = false;
function pulatelachat(w, h) {
	if(isNaN(w)) var w=486;
	if(isNaN(h)) var h=390;
	var y = screen.availHeight/2-h/2;
	var x = screen.availWidth/2-w/2;
	var aleatorio = Math.random();
	aleatorio = "a" + aleatorio;
	var ultimo = aleatorio.charAt(aleatorio.length-1);
	ultimo = ultimo + aleatorio.charAt(aleatorio.length-2);
	if (!clicado) {
		telapopup = window.open('http://zipline.com.br/zipchat/?system=nfe&x='+ ultimo, 'tela'+ ultimo, 'width='+ w +', height='+ h +', left='+ x +', top='+ y +', scrollbars=1, resizable=1');
		if(telapopup) clicado = true;
		if(!telapopup) alert('Atenção, o seu navegador está bloqueando as janelas popups, é necessário que você habilite a visualização de Popups.');
	}
}


