////////////////////////////////////////////

// JavaScript - Ebirô Internet Solutions ///

////////////////////////////////////////////



// Prototype and Misc Functions



	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

	

	function validaField(obj, action)

	{

		var objset = document.getElementById(obj);

		if(action == 0){

			borda = "1px solid #A2976C";

			objset.style.border = borda;

			objset.style.backgroundColor = "#F8F8F8";

			objset.value = objset.value.trim();

			objset.value = objset.value.trim();

			objset.focus();

		}

		else{

			borda = "1px solid #CCCCCC";

			objset.style.border = borda;

			objset.style.backgroundColor = "#FFFFFF";

		}

	}

	

	

	function resetFields()

	{

    	for (var i = 0; i < arguments.length; i++) {

			document.getElementById(arguments[i]).value = "";

    	}	

	}

	

	function closeWindow()

	{

		self.close();

	}

	

	function onlyNum(field)

	{

		var wrote = "0123456789";

		var field_temp;

		for (var i=0; i<field.value.length; i++)

		{

			field_temp = field.value.substring(i,i+1);

			if (wrote.indexOf(field_temp)==-1)

			{

				field.value = field.value.substring(0,i);

				break;

			}

		}

	}

	

	function validaCPF(cpf)

	{

		if(cpf.length < 11)

			return false

		

		var cpfCount = ""

		

		for(i=0;i<10;i++)

		{

			cpfCount = ""

			

			for(j=0;j<11;j++)

				cpfCount += i

			

			if(cpfCount == cpf)

			{

				return false

				break

			}

		}

					 

		var a = []

		var b = new Number

		var c = 11

		

		for(i=0; i<11; i++)

		{

			a[i] = cpf.charAt(i)

			if(i < 9) b += (a[i] * --c)

		}

	

		if((x = b % 11) < 2) 

			a[9] = 0

		else

			a[9] = 11-x

	

		b = 0

		c = 11

		for(y=0; y<10; y++) b += (a[y] * c--) 

	

		if((x = b % 11) < 2)

			a[10] = 0

		else

			a[10] = 11-x

	

		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))

			return false

	

		return true

	}

	

	function validaCNPJ(CNPJ)

	{

	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;

	   }

	  return true;

	}





// JPHP Functions



try

{

	ajax = new XMLHttpRequest();

}

catch(ee)

{

	try

	{

		ajax = new ActiveXObject("Msxml2.XMLHTTP");

	}

	catch(e)

	{

		try

		{

			ajax = new ActiveXObject("Microsoft.XMLHTTP");

		}

		catch(E)

		{

			ajax = false;

		}

	}

}



function jphp(metodo, url, post, funcao)

{	

	

	if(metodo == "GET")

	{

		ajax.open("GET", url, true);

		ajax.send(null);

	}

	else

	{

		ajax.open("POST", url, true);

		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");

		ajax.setRequestHeader("Pragma", "no-cache");

		ajax.send(post);

	}

	

	ajax.onreadystatechange = function()

	{

		if(ajax.readyState == 4 && ajax.status == 200)

			eval(funcao+"(url_decode(ajax.responseText));");

	}

}



function url_encode(str)

{ 

	var hex_chars = "0123456789ABCDEF"; 

	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 

	var n, strCode, hex1, hex2, strEncode = ""; 



	for(n = 0; n < str.length; n++)

	{ 

		if (noEncode.test(str.charAt(n)))

		{ 

			strEncode += str.charAt(n); 

		}

		else

		{ 

			strCode = str.charCodeAt(n); 

			hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 

			hex2 = hex_chars.charAt(strCode % 16); 

			strEncode += "%" + (hex1 + hex2); 

		} 

	}

	return strEncode;

} 



function url_decode(str)

{ 

	var n, strCode, strDecode = ""; 



	for (n = 0; n < str.length; n++)

	{ 

		if (str.charAt(n) == "%")

		{ 

			strCode = str.charAt(n + 1) + str.charAt(n + 2); 

			strDecode += String.fromCharCode(parseInt(strCode, 16)); 

			n += 2; 

		}

		else

		{ 

			strDecode += str.charAt(n); 

		} 

	}

	return strDecode; 

}





// Contact Functions



function sendMail()

{

	var nome = document.getElementById('ContatoNome'),

		empresa = document.getElementById('ContatoEmpresa'),

		mail = document.getElementById('ContatoEmail'),

		assunto = document.getElementById('ContatoAssunto'),

		msg = document.getElementById('ContatoMsg'),

		status = document.getElementById('botao')

	

		if(nome.value.trim() == "") {

			validaField(nome.id, 0)

			return false

		}

		

		if(mail.value.trim() == "")	{

			validaField(mail.id, 0)

			return false

		}

		

		if(assunto.value.trim() == "")	{

			validaField(assunto.id, 0)

			return false

		}

		

		if(msg.value.trim() == "") 	{

			validaField(msg.id, 0)

			return false;	

		}

		

		var email = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	

		if (!email.exec(mail.value)) {

			validaField(mail.id, 0)

			alert("Ops, email inválido.")

			formulario.focus()

			return false

		}

		

	status.value = " Enviando... ";

	status.disabled = true	

	

	var fields  = "nome="+ url_encode(nome.value);

		fields += "&empresa="+ url_encode(empresa.value);

		fields += "&email="+ mail.value;

		fields += "&assunto="+ url_encode(assunto.value);

		fields += "&mensagem="+ url_encode(msg.value);

	

	jphp("POST", "functions/sendMail.php", fields, "sentMail");

	resetFields(nome.id, empresa.id, mail.id, assunto.id, msg.id);

}



function sentMail(result)

{

	var status = document.getElementById('botao');

	

	if(result == 1)

		alert("Oba, o contato foi enviado com sucesso.\nEm breve estaremos retornando seu email.")

	else

		alert("Ops, nosso servidor recusou a tentativa de envio do contato.\n\nDesculpe-nos o encomodo, tente novamente dentro de alguns minutos.")



	status.value = " Enviar "

	status.disabled = false

}



// Help Functions



function openFAQ(id)

{

	var popWidth = 417;

	var popHeight = 200;

	var popLeft = (screen.availWidth/2)-(popWidth/2);

	var popTop = (screen.availHeight/2)-(popHeight/2);

	

	window.open('inc_ajuda_faqs.php?answer='+id, 'FAQS', 'width='+popWidth+',height='+popHeight+',top='+popTop+',left='+popLeft+',scrollbars=yes');

}



function openHELP(id)

{

	var popWidth = 417;

	var popHeight = 300;

	var popLeft = (screen.availWidth/2)-(popWidth/2);

	var popTop = (screen.availHeight/2)-(popHeight/2);

	

	window.open('inc_ajuda_faqs.php?answer='+id, 'FAQS', 'width='+popWidth+',height='+popHeight+',top='+popTop+',left='+popLeft+',scrollbars=yes');

}



function openGLOSSARY(id)

{

	var popWidth = 417;

	var popHeight = 200;

	var popLeft = (screen.availWidth/2)-(popWidth/2);

	var popTop = (screen.availHeight/2)-(popHeight/2);

	

	window.open('inc_ajuda_faqs.php?answer='+id, 'FAQS', 'width='+popWidth+',height='+popHeight+',top='+popTop+',left='+popLeft+',scrollbars=yes');

}



function subHelpSH(id) {

	if(document.getElementById(id).style.display == "none")

		document.getElementById(id).style.display = "block"

	else

		document.getElementById(id).style.display = "none"

}



// Domain Functions



function openDomain(mode) {

	var dominio = document.getElementById("post_dominio")

	

	if (dominio.value.length == 0) {

		alert("Ops, nenhum domínio foi digitado.\nInsira um domínio para continuar com a pesquisa.\n\nExemplo: \"ebiro.com.br\".")

		dominio.focus()

		} else {	

			if(mode == 1) {

				document.getElementById("botao").disabled = true

				document.getElementById("botao").value = "Pesquisando..."

				

				jphp("POST", "functions/sessDomain.php", "post_dominio="+dominio.value, "openedDomain")

			} else

				verifyDomain(dominio.value)

		}

}



function openedDomain(html) {

	window.location = "?lnk=1&subCls=1&domain=1&sDominio="+html;

}



function verifyDomain(sDominio) {

	document.getElementById("botao").value = " Pesquisando... "

	document.getElementById("botao").disabled = true

	

	jphp("POST", "functions/searchDomain.php", "dominio="+ sDominio +"&tipo="+ document.getElementById("tipo").value, "verifiedDomain")

}



function verifiedDomain(html)

{

	document.getElementById('pesquisa_DomainResult').innerHTML = html;	

	document.getElementById("botao").value = " Pesquisar "

	document.getElementById("botao").disabled = false

}



// Sign Functions



function signInit(plano) {

	var vars = "plano="+plano	

	jphp("POST", "functions/signPlanInit.php", vars, "signInitied")

}



function signInitied(html)

{

	window.location = '?lnk=1&subCls=3';	

}



function sign1of3()

{

	

}



function typeUser(mode)

{

	switch(mode)

	{

		case 1:		document.getElementById('tipoJF').value = 'f';

					document.getElementById('RSN').innerHTML = 'Nome:';

					document.getElementById('DOC').innerHTML = 'CPF:';

					document.getElementById('post_documento').maxLength = '11';

					document.getElementById('post_documento').value = document.getElementById('post_documento').value.substring(0,11);

					document.getElementById('txtTipo').style.display = 'none';

					document.getElementById('txtTipo2').style.display = 'block';

					break;

					

		default:	document.getElementById('tipoJF').value = 'j';

					document.getElementById('RSN').innerHTML = 'Raz&atilde;o Social:';

					document.getElementById('DOC').innerHTML = 'CNPJ:';

					document.getElementById('post_documento').maxLength = '14';

					document.getElementById('txtTipo').style.display = 'block';

					document.getElementById('txtTipo2').style.display = 'none';

					break;

	}

}



function typeFrm(mode)

{

	document.getElementById('BD').value = mode;

	refreshValues();

}	



function selfUser(mode)

{

	if(mode == 0){

		if(document.getElementById('tipoJF').value == 'f'){

			document.getElementById('post_responsavel').value = document.getElementById('post_rn').value;}

	}else{

		document.getElementById('post_cpf').value = document.getElementById('post_documento').value;

	}

}



function sign2of3()

{

	var dominio = document.getElementById('post_dominio');

	if(dominio.value.trim() == "")

	{

		validaField(dominio.id, 0);

		return false;

	}

	var vars;

	vars = 'post_dominio='+dominio.value;

	jphp("POST", "functions/sessDomain.php", vars, "popSession");

}



function popSession(html)

{

	window.location = '?lnk=1&subCls=4';

}



function sign3of3()

{

	var post_rn = document.getElementById('post_rn');

	var post_documento = document.getElementById('post_documento');

	var post_endereco = document.getElementById('post_endereco');

	var post_numero = document.getElementById('post_numero');

	var post_complemento = document.getElementById('post_complemento');

	var post_cep = document.getElementById('post_cep');

	var post_bairro = document.getElementById('post_bairro');

	var post_cidade = document.getElementById('post_cidade');

	var post_estado = document.getElementById('post_estado');

	var post_telefone = document.getElementById('post_telefone');

	var post_fonefax = document.getElementById('post_fonefax');

	var post_responsavel = document.getElementById('post_responsavel');

	var post_rg = document.getElementById('post_rg');

	var post_cpf = document.getElementById('post_cpf');

	var post_mailCobranca = document.getElementById('post_mailCobranca');

	var post_mailContato = document.getElementById('post_mailContato');

	var tipo = document.getElementById('tipoJF');

		

		if(post_rn.value.trim() == "")

		{

			validaField(post_rn.id, 0);

			return false;

		}

		if(post_documento.value.trim() == "")

		{

			validaField(post_documento.id, 0);

			return false;

		}

		if(tipo.value == 'j')

		{					

			if(validaCNPJ(post_documento.value) == false)

			{

				alert('CNPJ Inválido');

				validaField(post_documento.id, 0);

				return false;

			}

		}

		else

		{

			if(validaCPF(post_documento.value) == false)

			{

				alert('CPF	 Invalido');	

				validaField(post_documento.id, 0);

				return false;

			}

		}

		if(post_endereco.value.trim() == "")

		{

			validaField(post_endereco.id, 0);

			return false;

		}

		if(post_numero.value.trim() == "")

		{

			validaField(post_numero.id, 0);

			return false;

		}

		if(post_cep.value.trim() == "")

		{

			validaField(post_cep.id, 0);

			return false;

		}

		if(post_bairro.value.trim() == "")

		{

			validaField(post_bairro.id, 0);

			return false;

		}

		if(post_cidade.value.trim() == "")

		{

			validaField(post_cidade.id, 0);

			return false;

		}

		if(post_estado.value.trim() == "")

		{

			validaField(post_estado.id, 0);

			return false;

		}

		if(post_telefone.value.trim() == "")

		{

			validaField(post_telefone.id, 0);

			return false;

		}

		if(post_responsavel.value.trim() == "")

		{

			validaField(post_responsavel.id, 0);

			return false;

		}

		if(post_rg.value.trim() == "")

		{

			validaField(post_rg.id, 0);

			return false;

		}

		if(validaCPF(post_cpf.value) == false)

		{

			alert('CPF Inválido');	

			validaField(post_cpf.id, 0);

			return false;

		}

		if(post_mailCobranca.value.trim() == "")

		{

			validaField(post_mailCobranca.id, 0);

			return false;

		}

		

		if(post_mailCobranca.value.indexOf('@') == "-1" || post_mailCobranca.value.lastIndexOf('.') < post_mailCobranca.value.indexOf('@') || post_mailCobranca.value.indexOf('@') == "0" || post_mailCobranca.value.indexOf('.') == (post_mailCobranca.value.indexOf('@'))+1 || post_mailCobranca.value.lastIndexOf('.') == (post_mailCobranca.value.length)-1){

			validaField(post_mailCobranca.id, 0);

			return false;

		}

		var firstpos = post_mailCobranca.value.indexOf('@');

		var lastpos = post_mailCobranca.value.lastIndexOf('@');

		

		if(post_mailCobranca.value.indexOf(',') >= 0){

			validaField(post_mailCobranca.id, 0);

			return false;

		}

		if(post_mailCobranca.value.indexOf(';') >= 0){

			validaField(post_mailCobranca.id, 0);

			return false;

		}

		if(lastpos > firstpos){

			validaField(post_mailCobranca.id, 0);

			return false;

		}

		

		if(post_mailContato.value.indexOf('@') == "-1" || post_mailContato.value.lastIndexOf('.') < post_mailContato.value.indexOf('@') || post_mailContato.value.indexOf('@') == "0" || post_mailContato.value.indexOf('.') == (post_mailContato.value.indexOf('@'))+1 || post_mailContato.value.lastIndexOf('.') == (post_mailContato.value.length)-1){

			validaField(post_mailContato.id, 0);

			return false;

		}

		var firstpos = post_mailContato.value.indexOf('@');

		var lastpos = post_mailContato.value.lastIndexOf('@');

		

		if(post_mailContato.value.indexOf(',') >= 0){

			validaField(post_mailContato.id, 0);

			return false;

		}

		if(post_mailContato.value.indexOf(';') >= 0){

			validaField(post_mailContato.id, 0);

			return false;

		}

		if(lastpos > firstpos){

			validaField(post_mailContato.id, 0);

			return false;

		}

		

		var fields;

			fields = '';

			fields += 'post_rn='+url_encode(post_rn.value);

			fields += '&post_documento='+post_documento.value;

			fields += '&post_endereco='+url_encode(post_endereco.value);

			fields += '&post_numero='+post_numero.value;

			fields += '&post_complemento='+url_encode(post_complemento.value);

			fields += '&post_cep='+post_cep.value;

			fields += '&post_bairro='+url_encode(post_bairro.value);

			fields += '&post_cidade='+url_encode(post_cidade.value);

			fields += '&post_estado='+url_encode(post_estado.value);

			fields += '&post_telefone='+post_telefone.value;

			fields += '&post_fonefax='+post_fonefax.value;

			fields += '&post_responsavel='+url_encode(post_responsavel.value);

			fields += '&post_rg='+post_rg.value;

			fields += '&post_cpf='+post_cpf.value;

			fields += '&post_mailCobranca='+url_encode(post_mailCobranca.value);

			fields += '&post_mailContato='+url_encode(post_mailContato.value);

			fields += '&tipo='+tipo.value;

			

		

		jphp("POST", "functions/signPlan2of3.php", fields, "signToEnd");

}



function signToEnd(html)

{

	if(html == "Error")

	{

		alert('Erro na transferencia dos dados!')	;

	}else

	{

		window.location = '?lnk=1&subCls=5';

	}

}



function signEnd()

{

	var agreeContrato = document.getElementById('contrato');

	

	var formadepagamento = document.getElementById('frmPagamento');

	

	var tipo = document.getElementById('BD');

	

	if(agreeContrato.checked == false)

	{

		alert ("Você precisa concordar com os termos do contrato");

		agreeContrato.focus();

		return false;

	}

	

	window.location = 'functions/sendContrato.php?frmPgto='+formadepagamento.value+'&tipo='+tipo.value;

}



function refreshValues()

{

	frmPgto = document.getElementById('frmPagamento').value;

	tipoPgto = document.getElementById('BD').value;

	

	

	var fields;

		fields = 'frm='+frmPgto+'&tipo='+tipoPgto;



	jphp("POST", "functions/refreshValues.php", fields, "refreshedValues");

}



function refreshedValues(html)

{	

	if(html == "Error")

	{

		document.getElementById('pgto').innerHTML = "Erro na conexão com os dados";

	}

	else

	{

		document.getElementById('pgto').innerHTML = html;

	}

}



function readContrato()

{

	//var tipo = document.getElementById('frmPagamento').value;
	var tipo = document.getElementById('frmPagamento').options[document.getElementById('frmPagamento').selectedIndex].text;
	
/*
	if(tipo == 1)

		var tc = 'mensal';

	if(tipo == 2)

		var tc = 'trimestral';

	if(tipo == 3)

		var tc = 'semestral';

	if(tipo == 4)

		var tc = 'anual';
*/
		

	//window.open(tc+'.html','','width=500,height=350,scrollbars=1');
	window.open(tipo.toLowerCase()+'.html','','width=500,height=350,scrollbars=1');
}



// Help Desk Functions



function sendHelp()

{

	

	var nome = document.getElementById('SuporteNome'),

		www = document.getElementById('SuporteWWW'),

		mail = document.getElementById('SuporteEmail'),

		assunto = document.getElementById('SuporteAssunto'),

		msg = document.getElementById('SuporteMsg'),

		status = document.getElementById('botao')

	

		if(nome.value.trim() == "") {

			validaField(nome.id, 0);

			return false;

		}

		

		if(www.value.trim() == "") {

			validaField(www.id, 0);

			return false;

		}

		

		if(mail.value.trim() == "") {

			validaField(mail.id, 0);

			return false;

		}

		

		if(assunto.value.trim() == "") {

			validaField(assunto.id, 0);

			return false;	

		}

		

		if(msg.value.trim() == "") {

			validaField(msg.id, 0);

			return false;	

		}

		

		var email = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	

		if (!email.exec(mail.value)) {

			validaField(mail.id, 0)

			alert("Ops, email inválido.")

			formulario.focus()

			return false

		}

		

	status.value = " Enviando... "

	status.disabled = true

	

	var fields  = "nome="+ url_encode(nome.value);

		fields += "&www="+ url_encode(www.value);

		fields += "&email="+ mail.value;

		fields += "&assunto="+ url_encode(assunto.value);

		fields += "&mensagem="+ url_encode(msg.value);



	jphp("POST", "functions/sendSuporte.php", fields, "sentHelp");

	resetFields(nome.id, www.id, mail.id, assunto.id, msg.id);

}



function sentHelp(result)

{

	var status = document.getElementById('botao');

	

	if(result == 1)

		alert("Oba, o pedido de suporte enviado com sucesso.\nEm breve estaremos retornando seu email.")

	else

		alert("Ops, nosso servidor recusou a tentativa de envio de suporte.\n\nDesculpe-nos o encomodo, tente novamente dentro de alguns minutos.")

	

	status.value = " Enviar "

	status.disabled = false

}



// Admin Server functions



function logins(mode)

{

	

	if(mode == 0)

	{

		document.getElementById('frmCpanel').submit();

	}

	if(mode == 1)

	{

		document.getElementById('frmWebMail').submit();

	}

}



// Search Functions



function buscarSite()

{

	var campo = document.getElementById("str")

	

	if(campo.value.length == 0) {

		alert("Ops, não é possível fazer uma busca sem alguma palavra.\nInsira alguma palavra para fazer a busca.\n\nExemplo: \"planos\".")

		campo.focus()

	} else

		window.location = "?lnk=8&str="+ campo.value +"&startAt=0&page=1"

}



function verificarWebMail() {

	var usuario = document.getElementById("login_username"),

	senha = document.getElementById("secretkey")

	

	if (usuario.value.length == 0 || senha.value.length == 0) {

		alert("Ops, não é possível prosseguir sem um e-mail e/ou senha.\n\Insira corretamente seu e-mail e senha para acessar o WebMail.\n\nObs.: o e-mail deve ser completo (exemplo: \"nome@seudominio.com.br\").")

		

		if (usuario.value.length == 0)

			usuario.focus()

		else

			senha.focus()

			

		return false

	}

	

	var email = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	

	if (!email.exec(usuario.value)) {

		alert("Ops, o e-mail digitado não é válido.\nInsira um e-mail válido para acessar o WebMail.\n\nExemplo: \"nome@seudominio.com.br\".")

		usuario.focus()

		return false

	}
	
	return true;
}



function verificar_cPanel() {

	var usuario = document.getElementById("user"),

	senha = document.getElementById("pass")

	

	if (usuario.value.length == 0 || senha.value.length == 0) {

		alert("Ops, não é possível prosseguir sem um usuário e/ou senha.\n\Insira corretamente seu usuário e senha para acessar o cPanel®.")

		

		if (usuario.value.length == 0)

			usuario.focus()

		else

			senha.focus()

			

		return false

	}

}