// OPCIONAIS NO CADASTRO DE CLIENTES;
var opcionais   = new Array("aid","pid","cliente_agente_id","cliente_parceiro_id","acao","cliente_sobrenome", "cliente_complemento","cliente_telefone","cliente_celular", "cliente_comercial", "cliente_fax", "cliente_email_opcional");
// OPCIONAIS NO CADASTRO DE AGENTES VOIP;
var opAgentes   = new Array("pid","acao","agente_complemento","agente_telefone","agente_celular", "agente_comercial", "agente_fax", "agente_url");
// OPCIONAIS NO FORMULARIO DE TURBINE SEU VOIP;
var opTurbine   = new Array("turbine_nome","turbine_tel_res");

function validaformulario(opcional)
{
    frmAdquira = document.getElementById("adquiraja");

    for(i=0; i < frmAdquira.length; i++)
    {
        if(frmAdquira[i].value === "")
        {
            if(!in_array(frmAdquira[i].name, opcional))     //CAMPO NÃO OPCIONAL
            {
                cForm = frmAdquira[i].name.toLowerCase();

				if(cForm.indexOf('tipo_id') >= 0)
					cForm = 'Tipo de Pessoa';
				else if(cForm.indexOf('estado_id') >= 0)
					cForm = 'Estado';
				else if(cForm.indexOf('banco_id') >= 0)
					cForm = 'Banco';
				cForm = cForm.toString();
				cForm = cForm.replace("cliente_",	'');
				cForm = cForm.replace("agente_",	'');
				cForm = cForm.replace("turbine_",	'');

				campo = cForm;

                alert(' Campo ' + campo + ' esta no formato invalido');
                frmAdquira[i].focus();
                campo = "";
                cForm = "";
                return false;
            }
        }
    }
    return true;
}

function in_array(valor, array)
{
    var key;

    for(key in array)
    {
        value = array[key];
        if(value == valor)
            return true;
    }
    return false;
}

function validarFormPag(objForm)
{
	if( false == (document.getElementById('pagBoleto').checked || document.getElementById('pagVisa').checked || document.getElementById('pagMastercard').checked) )
	{
		alert('Selecione uma forma de pagamento');
		return false;
	}

	return true;
}

function validarContrato(objForm)
{		
	if( false == (document.getElementById('aceito').checked) )
	{
		alert('Para continuar, aceite os termos do contrato!');
		return false;
	}
		
	return true;
}

function vContrato()
{
    
	contrato = document.forms[0].contrato;
    
	if(contrato.checked == true)
	{
        document.forms[0].adicionar.disabled = false;
    }
	else
	{
		document.forms[0].adicionar.disabled = true;
	}
}

function vContratoCompra()
{
	if(document.forms[0].contrato.checked == false)
	{
		alert('Você deve ler e aceitar os termos e condições de uso!');
		return false;
	}		
	return true;
}

function finalizarCompra()
{
	document.getElementById("carrinho").acao.value	= "finalizar_pedido";
	document.getElementById("carrinho").action		="voip.php?page=pagamento";
	document.getElementById("carrinho").submit();
}

function popularCombo(tarifas)
{
	for(i=0; i < tarifas.length; i++)
		document.forms[0].selecao.options[i] = new Option(tarifas[i][0], i);

}

function mostarTarifa(indice)
{
	if(indice)
	{
		document.getElementById("valor_tarifa").value = tarifas[indice][1];
	}
}
