// NETWORLD (WWW.NETWORLD.COM.BR)
// (c) 2006 Networld WebHost

function erro_login() {
    alert("Networld WebHost\n\n- Erro, Login ou Senha Inválida!");
}

function limpa_string(s) {
	var digitos = "0123456789";
	var temp = "";
	var digito = "";

    for (var i=0; i<s.length; i++){
		digito = s.charAt(i);
		if (digitos.indexOf(digito)>=0){temp=temp+digito}
	}
	return temp
}

function mask( formato, keypress, objeto )
{
		campo = eval(objeto);

		// CNPJ
		if (formato ==  'CNPJ')
		{
			var s = limpa_string(campo.value);
			if (s.length == 2)
				campo.value = s.substr(0, 2) + '.';
			else if (s.length == 5)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.';
			else if (s.length == 8)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/';
			else if (s.length == 12)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, 4) + '-' + s.substr(12, 2);
		}

		// CPF
		if (formato ==  'CPF')
		{
			var s = limpa_string(campo.value);
			if (s.length == 3)
				campo.value = s.substr(0, 3) + '.';
			else if (s.length == 6)
				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.';
			else if (s.length == 9)
				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '-';
		}

		// CEP
		if (formato ==  'CEP')
		{
			var s = limpa_string(campo.value);
			if (s.length == 2)
				campo.value = s.substr(0, 2) + '.';
			else if (s.length == 5)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '-';
		}

		// TELEFONE
		if (formato ==  'FONEGERAL')
		{
			var s = limpa_string(campo.value);
			if (s.length == 4)
				campo.value = s.substr(0, 4) + '-';
		}

		// NUMERO
		if (formato == 'NUMERO')
		{

		}
		var c = String.fromCharCode(keypress);
		if (isNaN(c) || keypress == 32) return false;
}

function hideshow( exibe, esconde )
{
	// exibe
	for(var i = 0; i < exibe.length; i++)
	{
		if(document.getElementById(exibe[i]))
		{
			document.getElementById(exibe[i]).style.display = 'block';
		}
	}
	// esconde
	for(var i = 0; i < esconde.length; i++)
	{
		if(document.getElementById(esconde[i]))
		{
			document.getElementById(esconde[i]).style.display = 'none';
		}
	}
}

function selectDisabled( obj )
{
    var i, len;

    len = obj.length;
    for (i = 0; i < len; i++)
    {
       obj.options[i].disabled = true;
    }
}

function selectEnabled( obj )
{
    var i, len;

    len = obj.length;
    for (i = 0; i < len; i++)
    {
       obj.options[i].disabled = false;
    }
}

function mPlano(selPlano)
{
    var form = document.forms['planos'];
    selPlano = form.elements['plano'].value;
    trafego = parseInt(form.elements['trafego'].value);
    espaco_site = parseInt(form.elements['espaco_site'].value);
    espaco_email = parseInt(form.elements['espaco_email'].value);
  
    if (selPlano == 'Redirect')
    {
        form.elements['trafego'].selectedIndex = 0;
        form.elements['trafego'].options[0].text = '0 GB';
        selectDisabled( form.elements['trafego'] );

        form.elements['espaco_site'].selectedIndex = 0;
        form.elements['espaco_site'].options[0].text = '0 MB';
        selectDisabled( form.elements['espaco_site'] );

        form.elements['espaco_email'].selectedIndex = 0;
        form.elements['espaco_email'].options[0].text = '0 MB';
        selectDisabled( form.elements['espaco_email'] );
        
        return true;
    }
    else
    {
        form.elements['trafego'].options[0].text = '1 GB';
        form.elements['espaco_site'].options[0].text = '100 MB';
        form.elements['espaco_email'].options[0].text = '50 MB';
    }
    
    if (selPlano == 'Email')
    {
        form.elements['espaco_site'].selectedIndex = 0;
        form.elements['espaco_site'].options[0].text = '0 MB';
        selectDisabled( form.elements['espaco_site'] );

        return true;
    }

}

function verificar(theForm)
{
    if (theForm.dominio.value.indexOf(".",0) == -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Domínio Corretamente.");
    theForm.dominio.focus();
    return (false);
    }

         cta = theForm.dominio.value.length;
         cta = cta - 1;

    if (theForm.dominio.value.indexOf(".",0) == cta) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Domínio Corretamente.");
    theForm.dominio.focus();
    return (false);
    }

    if (theForm.nome.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Nome.");
    theForm.nome.focus();
    return (false);
    }

	if (theForm.pessoa.value == 1) {
    if ( !valida_CPF(theForm.cpf.value) ) {
        alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu CPF Corretamente.");
		theForm.cpf.select();
		theForm.cpf.focus();
		return false;
	}
	}

	if (theForm.pessoa.value == 2) {
    if ( !valida_CNPJ(theForm.cnpj.value) ) {
        alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu CNPJ Corretamente.");
		theForm.cnpj.select();
		theForm.cnpj.focus();
		return false;
	}
	}

    if (theForm.endereco.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Endereço.");
    theForm.endereco.focus();
    return (false);
    }

    if (theForm.numero.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Número do Endereço.");
    theForm.numero.focus();
    return (false);
    }

    if (theForm.bairro.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Bairro.");
    theForm.bairro.focus();
    return (false);
    }

    if (theForm.cep.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu CEP.");
    theForm.cep.focus();
    return (false);
    }

    if (theForm.cidade.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar a sua Cidade.");
    theForm.cidade.focus();
    return (false);
    }

    if (theForm.uf.value == "00") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Selecione o seu Estado.");
    theForm.uf.focus();
    return (false);
    }

    if (theForm.ddd_fone.value == 0) {
    if (theForm.ddd_celular.value == 0) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o DDD do seu Telefone ou Celular.");
    theForm.ddd_fone.focus();
    return (false);
    } }

    if (theForm.telefone.value == "") {
    if (theForm.celular.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Telefone ou Celular.");
    theForm.telefone.focus();
    return (false);
    } }
    
	if (theForm.pessoa.value == 2) {
    if (theForm.responsavel.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o nome do Responsável Legal pela Empresa.");
    theForm.responsavel.focus();
    return (false);
    }
    }

	if (theForm.pessoa.value == 2) {
    if (theForm.cargo.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o cargo do Responsável Legal pela Empresa.");
    theForm.cargo.focus();
    return (false);
    }
    }

	if (theForm.pessoa.value == 2) {
    if (theForm.rg_resp.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o RG do Responsável Legal pela Empresa.");
    theForm.rg_resp.focus();
    return (false);
    }
    }

	if (theForm.pessoa.value == 2) {
    if ( !valida_CPF(theForm.cpf_resp.value) ) {
        alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o CPF do Responsável Legal pela Empresa.");
		theForm.cpf_resp.focus();
		return false;
	}
	}

    if (theForm.contato.value == "") {
    vardominio = theForm.dominio.value;
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Nome da Pessoa para Contato sobre o Domínio ("+vardominio+").");
    theForm.contato.focus();
    return (false);
    }

    if (theForm.email_principal.value.indexOf("@",0) == -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email Principal para Contato Corretamente.");
    theForm.email_principal.focus();
    return (false);
    }

    x = theForm.email_principal.value.length;
    x = x - 1;

    if (theForm.email_principal.value.indexOf("@",0) == x) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email Principal para Contato Corretamente.");
    theForm.email_principal.focus();
    return (false);
    }

    if (theForm.email_principal.value.indexOf("@",0) == 0) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email Principal para Contato Corretamente.");
    theForm.email_principal.focus();
    return (false);
    }

    if (theForm.email_principal.value.indexOf(".@",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email Principal para Contato Corretamente.");
    theForm.email_principal.focus();
    return (false);
    }

    if (theForm.email_principal.value.indexOf("@.",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email Principal para Contato Corretamente.");
    theForm.email_principal.focus();
    return (false);
    }
    
    if (theForm.email_cobranca.value.indexOf("@",0) == -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    x = theForm.email_cobranca.value.length;
    x = x - 1;

    if (theForm.email_cobranca.value.indexOf("@",0) == x) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf("@",0) == 0) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf(".@",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf("@.",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.conftermos.value != 'sim') {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Selecione a Confirmação dos Termos de Prestação de Serviços de Hospedagem de Site.");
    theForm.conftermos.focus();
    return (false);
    }

    theForm.submit;
}

function verificar_alt(theForm)
{
    if (theForm.ddd_fone.value == 0) {
    if (theForm.ddd_celular.value == 0) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o DDD do seu Telefone.");
    theForm.ddd_fone.focus();
    return (false);
    } }

    if (theForm.telefone.value == "") {
    if (theForm.celular.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o seu Telefone.");
    theForm.telefone.focus();
    return (false);
    } }

    if (theForm.contato.value == "") {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Nome da Pessoa para Contato.");
    theForm.contato.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf("@",0) == -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    x = theForm.email_cobranca.value.length;
    x = x - 1;

    if (theForm.email_cobranca.value.indexOf("@",0) == x) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf("@",0) == 0) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf(".@",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    if (theForm.email_cobranca.value.indexOf("@.",0) != -1) {
    alert("Networld WebHost (CADASTRO Novo Cliente)\nExistem campos que precisam ser preenchidos corretamente.\n\n- Informar o Email de Cobrança Corretamente.");
    theForm.email_cobranca.focus();
    return (false);
    }

    theForm.submit;
}

function valida_CPF(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;

	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		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){
		return false;
	}
	return true;
}

function valida_CNPJ(s)
{
	var i;
	s = limpa_string(s);
	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) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	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) {
		return false;
	}
	return true;
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e)
{
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
    }

    function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)

    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
    }

    function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
    }

    return true;
}

function clean_fields_plesk(theForm) {
    theForm.login_name.value = theForm.nw_login.value;
    theForm.nw_login.value = '';
    theForm.passwd.value = theForm.nw_pass.value;
    theForm.nw_pass.value = '';
}

function clean_fields_mail(theForm) {
    theForm.imapuser.value = theForm.nw_mail.value;
    theForm.nw_mail.value = '';
    theForm.pass.value = theForm.nw_sen.value;
    theForm.nw_sen.value = '';
}

//
