function abreLoginWebmail()
{
    $("#loginCentral").fadeOut();	
	$("#loginWebmail").toggle();	
}

function abreLoginCentral()
{
	$("#loginWebmail").fadeOut();	
	$("#loginCentral").toggle();	
}

function abrirEmail()
{
	var posicao = $("#user").val().indexOf("@");
	if(posicao == -1)
	{
		alert("Informe seu e-mail corretamente.");	
		return;
	}
	if($("#pass").val() == "")
	{
		alert("Informe sua senha.");	
		return;
	}
	
	var dominio = $("#user").val().substr(posicao + 1);
    document.frmWebmail.action = "http://"+dominio+":2095/login/";
	document.frmWebmail.submit();
	$("#user").val("");
	$("#pass").val("");
	$("#loginWebmail").slideUp();	
}

function confirma(msg,url)
{
  if(true == confirm(msg))
    window.location = url;
}

function monta_periodicidade()
{
 combo = document.cadastro.periodo;
 
 for(i=(combo.options.length - 1); i>=0; i--)
   combo.options[i] = null;

 switch(document.cadastro.plano.value)
 {
   case "1" : {
	             op0 = new Option("Mensal (R$ 15,00/mês)","1");
				 op1 = new Option("Trimestral (R$ 13,00 x 3 = R$ 39,00/trimestre)","3");
				 op2 = new Option("Semestral (R$ 11,99 x 6 = R$ 71,94/semestre)","6");
				 combo.options[0] = op2;
				 combo.options[1] = op1;
				 combo.options[2] = op0;
			   }break;
   case "2" : {
	             op0 = new Option("Mensal (R$ 25,00/mês)","1");
				 op1 = new Option("Trimestral (R$ 23,00 x 3 = R$ 69,00/trimestre)","3");
				 op2 = new Option("Semestral (R$ 21,99 x 6 = R$ 131,94/semestre)","6");
				 combo.options[0] = op2;
				 combo.options[1] = op1;
				 combo.options[2] = op0;
			   }break;
   case "3" : {
	             op0 = new Option("Mensal (R$ 30,00/mês)","1");
				 op1 = new Option("Trimestral (R$ 28,00 x 3 = R$ 84,00/trimestre)","3");
				 op2 = new Option("Semestral (R$ 24,99 x 6 = R$ 149,94/semestre)","6");
				 combo.options[0] = op2;
				 combo.options[1] = op1;
				 combo.options[2] = op0;
			   }break;
   case "4" : {
	             op0 = new Option("Mensal (R$ 35,00/mês)","1");
				 op1 = new Option("Trimestral (R$ 33,00 x 3 = R$ 99,00/trimestre)","3");
				 op2 = new Option("Semestral (R$ 29,99 x 6 = R$ 179,94/semestre)","6");
				 combo.options[0] = op2;
				 combo.options[1] = op1;
				 combo.options[2] = op0;
			   }break;
   default   : {
	              op0 = new Option("---","0");
				  combo.options[0] = op0;
               }
 
 }
}
//-----------------------------------------------------------------------
//window.onload = iFrameHeight;
function iFrameHeight() {
	var h = 0;
	if ( !document.all ) {
		h = document.getElementById('blockrandom').contentDocument.height;
		document.getElementById('blockrandom').style.height = h + 10 + 'px';
	} else if( document.all ) {
		h = document.frames('blockrandom').document.body.scrollHeight;
		document.all.blockrandom.style.height = h + 5 + 'px';
	}
}
//-----------------------------------------------------------------------
function pop_up(url,x,y,rol)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
	rol -> Rolagem (yes/no)
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   window.open(url,'login','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+''); 
}
//-----------------------------------------------------------------------
function limpa_helpdesk()
{
  document.login.password.value = document.login.password_x.value;
  document.login.user.value = document.login.user_x.value;
  document.login.password_x.value = "";
  document.login.user_x.value = "";
  document.login.submit();	
}
//------------------------------------------------------------------
function limpa_cpanel()
{
  document.cpanel.pass.value = document.cpanel.pass_x1.value;
  document.cpanel.user.value = document.cpanel.user_x1.value;
  document.cpanel.pass_x1.value = "";
  document.cpanel.user_x1.value = "";
  document.cpanel.submit();
}
//------------------------------------------------------------------
function limpa_mail()
{
  document.mail.pass.value = document.mail.pass_x2.value;
  document.mail.user.value = document.mail.user_x2.value;
  document.mail.pass_x2.value = "";
  document.mail.user_x2.value = "";
  document.mail.submit();	
}
//------------------------------------------------------------------
function abre(url,x,y,rol)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
	rol -> Rolagem (yes/no)
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   window.open(url,'login','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+''); 
}
//-------------------------------------------------------------------
function enviar()
{
if(document.contato.nome.value == "")
	{
	alert("Informe seu nome");
	document.contato.nome.focus();
	}
	else
	if(document.contato.email.value == "")
	{
	alert("Informe o seu E-mail de contato");
	document.contato.email.focus();
	}
	else
	if(document.contato.ass.value == "")
	{
	alert("Informe um assunto para sua mensagem");
	document.contato.ass.focus();
	}
	else
	if(document.contato.msg.value == "")
	{
	alert("Digite sua mensagem");
	document.contato.msg.focus();
	}
	else
	  document.contato.submit();
}
//-------------------------------------------------------------------
function enviar_pagamento()
{
if(document.contato.fatura.value == "")
	{
	alert("Informe o Número da Fatura");
	document.contato.fatura.focus();
	}
	else
	if(document.contato.data.value == "")
	{
	alert("Informe data do pagamento");
	document.contato.data.focus();
	}
	else
	if(document.contato.valor.value == "")
	{
	alert("Informe o valor pago");
	document.contato.valor.focus();
	}
	else
	if(document.contato.forma.options[document.contato.forma.selectedIndex].value == 0)
	{
	alert("Informe a forma de pagamento");
	}
	else
	if(document.contato.forma.options[document.contato.forma.selectedIndex].value == 2)
	{
		if(document.contato.agencia.value == "")
		{
		alert("Informe sua agência");
		document.contato.agencia.focus();
		}
		else
		if(document.contato.conta.value == "")
		{
		alert("Informe sua conta");
		document.contato.conta.focus();
		}
		else
		document.contato.submit();
    }
	else
	if(document.contato.forma.options[document.contato.forma.selectedIndex].value == 1)
	{
	    if(document.contato.envelope.value == "")
		{
		 alert("Informe o número do envelope ou comprovante de depósito");
		 document.contato.envelope.focus();
		}
		else
		 document.contato.submit();
	}
	else
    document.contato.submit();
}
//-------------------------------------------------------------------
function normaliza(campo)
{
  //if(campo.value.length > 1)
    campo.style.border = '1px solid #CACACA';
}

function pinta(campo)
{
   campo.style.border = '1px solid #339900';
}

function verifica(valor)
{
	if(document.cadastro.dominio_proprio.value == "" && document.cadastro.registro_dominio[0].checked)
	{
		alert("Informe o seu Domínio");
		document.cadastro.dominio_proprio.focus();
		document.cadastro.dominio_proprio.style.border = '1px solid #FF0000';
	}
    else
	if(document.cadastro.comprar_dominio.value == "" && document.cadastro.registro_dominio[1].checked)
	{
		alert("Informe o seu Domínio");
		document.cadastro.comprar_dominio.focus();
		document.cadastro.comprar_dominio.style.border = '1px solid #FF0000';
	}
    else
    if(document.cadastro.plano.options[document.cadastro.plano.selectedIndex].value == 0)
	{
	alert("Selecione um Plano de Hospedagem");
	document.cadastro.plano.focus();
	document.cadastro.plano.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.nome_responsavel.value == "")
	{
	alert("Informe o nome do responsável pela hospedagem");
	document.cadastro.nome_responsavel.focus();
	document.cadastro.nome_responsavel.style.border = '1px solid #FF0000';
	}
	else
	if((document.cadastro.razao_social.value == "")&&(document.cadastro.tipo[1].checked))
	{
	alert("Informe a Razão Social de sua empresa");
	document.cadastro.razao_social.focus();
	document.cadastro.razao_social.style.border = '1px solid #FF0000';
	}
	else
	if((!ValidaCNPJ(document.cadastro.cnpj.value))&&(document.cadastro.tipo[1].checked))
	{
	alert("Informe corretamente seu CNPJ");
	document.cadastro.cnpj.focus();
	document.cadastro.cnpj.style.border = '1px solid #FF0000';
	}
	else
	if((!ValidaCPF(document.cadastro.cpf.value))&&(document.cadastro.tipo[0].checked))
	{
	alert("Informe corretamente seu CPF");
	document.cadastro.cpf.focus();
	document.cadastro.cpf.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.email.value == "")
	{
	alert("Informe um E-mail");
	document.cadastro.email.focus();
	document.cadastro.email.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.endereco.value == "")
	{
	alert("Informe o endereço");
	document.cadastro.endereco.focus();
	document.cadastro.endereco.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.numero.value == "")
	{
	alert("Informe o Número de sua Residência ou Empresa");
	document.cadastro.numero.focus();
	document.cadastro.numero.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.bairro.value == "")
	{
	alert("Informe o Bairro");
	document.cadastro.bairro.focus();
	document.cadastro.bairro.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.cidade.value == "")
	{
	alert("Informe a cidade");
	document.cadastro.cidade.focus();
	document.cadastro.cidade.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.pais.value == "")
	{
	alert("Informe o país");
	document.cadastro.pais.focus();
	document.cadastro.pais.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.estado.options[document.cadastro.estado.selectedIndex].value == 0)
	{
	alert("Informe o Estado");
	document.cadastro.estado.focus();
	document.cadastro.estado.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.cep.value == "")
	{
	alert("Informe o CEP");
	document.cadastro.cep.focus();
	document.cadastro.cep.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.tel_residencial.value == "")
	{
	alert("Informe o seu telefone");
	document.cadastro.tel_residencial.focus();
	document.cadastro.tel_residencial.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.usuario_central.value.length < 3)
	{
	alert("Informe um nome de usuário (login) com pelo menos 3 caracteres");
	document.cadastro.usuario_central.focus();
	document.cadastro.usuario_central.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.senha.value.length < 6)
	{
	alert("Informe uma senha com pelo menos 6 caracteres");
	document.cadastro.senha.focus();
	document.cadastro.senha.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.senha.value != document.cadastro.senha2.value)
	{
	alert("Repita a senha informada");
	document.cadastro.senha2.focus();
	document.cadastro.senha2.style.border = '1px solid #FF0000';
	}
	else
	if(document.cadastro.conf.value != valor)
	{
	alert("Digite corretamente o código de validação");
	document.cadastro.conf.focus();
	document.cadastro.conf.style.border = '1px solid #FF0000';
	}
	else
	if(!document.cadastro.lido.checked)
	{
	acordo = confirm("Para prosseguir, é necessário estar de acordo com o Contrato de Prestação de Serviços e com nossa política Anti-SPAM.");
	if(acordo)
	{  
	document.cadastro.lido.checked = true;
	document.cadastro.submit();
	}
	}
	else
	{
	  document.cadastro.bt_enviar.disabled = false;
	  document.cadastro.submit();
	}
}
//-------------------------------------------------------  
// Permite somente a digitacao de numeros
function aceita_numero() {

	if (event.keyCode==34 || event.keyCode==38 || event.keyCode==39) {
		event.keyCode=0;
	}
   	if ((event.keyCode < 48)||(event.keyCode > 57)) {
      	event.keyCode=0;
    }
}

//--------------------------------------------------------
// Valida o CPF informado
function ValidaCPF(numCPF) {
	var campo="";
	// retira carateres não numericos do identificador( CPF )
	for (i=0; i<numCPF.length;i++){
		if ((numCPF.charAt(i)!=".") && (numCPF.charAt(i)!="-") && (numCPF.charAt(i)!="/")){campo = campo + numCPF.charAt(i)}}

	if (campo.length>0)
	{
		// exclui números inválidos
		if ((campo=="00000000000") || (campo == "11111111111") || (campo == "22222222222") || (campo == "33333333333") || (campo == "44444444444") || (campo == "55555555555") || (campo == "66666666666") || (campo == "77777777777") || (campo == "88888888888") || (campo == "99999999999") || (campo == "12345678901")){return false;}
		tam = campo.length;
		// calcula primeiro digito
		val1 = tam-1;
		soma = 0
		for (i=0;i<=tam-3;i++)
		{
			val2 = campo.substring(i,i+1);
			soma = soma + ( val2 * val1);
			val1 = val1 - 1;
		}
		dig1 = 11 - (soma % 11);
		if (dig1 == 10) dig1=0 ;
		if (dig1 == 11) dig1=0 ;
		//calcula segundo digito
		val1 = 11;
		soma = 0;
		for (i=0;i<=tam-2;i++)
		{
			soma = soma + (campo.substring(i,i+1) * val1);
			val1 = val1 - 1;
		}
		dig2 = 11 - (soma % 11);
		if (dig2 == 10) dig2=0;
		if (dig2 == 11) dig2=0;
		// valida digitos verificadores
		if ((dig1 + "" + dig2) == campo.substring(tam,tam-2))
		{
			return true;
		}
		else {	return false;	}
	}
}

//-----------------------------------------------------------
// Valida o CNPJ informado
function ValidaCNPJ(numCNPJ) {
	var campo="";
	// retira carateres não numericos do identificador( CNPJ )
	for (i=0; i<numCNPJ.length;i++){
	    if ((numCNPJ.charAt(i)!=".") && (numCNPJ.charAt(i)!="-") && (numCNPJ.charAt(i)!="/")){campo = campo + numCNPJ.charAt(i)}}

	if (campo.length>0)
	{
		if ((campo.length > 14)||(campo == "00000000000000") || (campo == "11111111111111") || (campo == "22222222222222") || (campo == "33333333333333") || (campo == "44444444444444") || (campo == "55555555555555") || (campo == "66666666666666") || (campo == "77777777777777") || (campo == "88888888888888") || (campo == "99999999999999")){return false;}
		dig2 = campo.substring (13,14)
		dig1 = campo.substring (12,13)
		mult = 5
		soma = 0
		// calcula primeiro digito
		for (i=0;i<=11;i++)
		{
			vnum = parseInt(campo.substring (i,i+1))
			vnum = vnum * mult
			soma = soma + vnum
			mult = mult - 1
			if (mult < 2)
			{
				mult = 9
			}
		}
		rest = parseInt(soma / 11)
		rest = soma - (rest * 11)
		rest = 11 - rest
		if (rest == 10 || rest == 11)
		{
			rest = 0
		}
		// valida primeiro digito
		if (rest == dig1)
		{
			mult = 6
			soma = 0
			// calcula segundo digito
			for (i=0;i<=12;i++)
			{
				vnum = parseInt(campo.substring (i,i+1))
				vnum = vnum * mult
				soma = soma + vnum
				mult = mult - 1
				if (mult < 2)
				{
					mult = 9
				}
			}
			rest = parseInt(soma / 11)
			rest = soma - (rest * 11)
			rest = 11 - rest
			if (rest == 10 || rest == 11)
			{
				rest = 0
			}
			// valida segundo digito
			if (rest != dig2)
			{	return false;	}
		}
		else
		{	return false;	}
		return true;
	}
}
//-----------------------------------------------------------------
function muda()
{
 if(document.cadastro.tipo[0].checked)
 {
  document.cadastro.cpf.disabled = false;
  document.cadastro.cnpj.disabled = true;
  document.cadastro.razao_social.disabled = true;
  document.cadastro.cnpj.value = "----------";
  document.cadastro.razao_social.value = "----------";
  document.cadastro.cpf.value = "";
 }
 else
 {
  document.cadastro.cpf.disabled = true;
  document.cadastro.cnpj.disabled = false;
  document.cadastro.razao_social.disabled = false;
  document.cadastro.cpf.value = "----------";
  document.cadastro.cnpj.value = "";
  document.cadastro.razao_social.value = "";
 }
}
//----------------------------------------------------------------
//--------------------------------------------------------
function formataMascara(format, field)
{
	var result = "";
	var maskIdx = format.length - 1;
	var error = false;
	var valor = field.value;
	var posFinal = false;
	if( field.setSelectionRange ) 
	{
    	if(field.selectionStart == valor.length)
    		posFinal = true;
    }
	valor = valor.replace(/[^0123456789Xx]/g,'')
	for (var valIdx = valor.length - 1; valIdx >= 0 && maskIdx >= 0; --maskIdx)
	{
		var chr = valor.charAt(valIdx);
		var chrMask = format.charAt(maskIdx);
		switch (chrMask)
		{
		case '#':
			if(!(/\d/.test(chr)))
				error = true;
			result = chr + result;
			--valIdx;
			break;
		case '@':
			result = chr + result;
			--valIdx;
			break;
		default:
			result = chrMask + result;
		}
	}

	field.value = result;
	field.style.color = error ? 'red' : '';
	if(posFinal)
	{
		field.selectionStart = result.length;
		field.selectionEnd = result.length;
	}
	return result;
}

function getTeclaPressionada(evt)
{
	if(typeof(evt)=='undefined')
		evt = window.event;
	return(evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode));
}

// teclas 63230 a 63240 = safari
function isTeclaEspecial(key)
{
	return key<32||(key>=35&&key<=36)||(key>=37&&key<=40)||key==46||(key>=63230&&key<=63240);
}

function isTeclaRelevante(key)
{
	return (key == 8)||(key == 46)||(key>=48&&key<=57)||(key>=96&&key<=105);
}

function isCaracterRelevante(key)
{
	return (key == 120)||(key>=48&&key<=57);
}

function StopEvent(evt)
{
	if(document.all)evt.returnValue=false;
	else if(evt.preventDefault)evt.preventDefault();
}

function filtraTeclas(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isTeclaRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function filtraCaracteres(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isCaracterRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function saltaCampo(campo,proxCampo,tamanhoMaximo){
	var vr = campo.value;
	var tam = vr.length;
	if (tam >= tamanhoMaximo)
	{
		proxCampo.focus();
	}
}