/*
     ##############################################
           SCRIPTS DE FORMATAÇÃO FORMULÁRIOS

          Proibída utilização sem autorização
     ##############################################
*/

    /* REMOÇÃO INTELIGENTE DE CADASTROS */
    function Excluir(id, seleciona)
    {
        var id;
        var nb;
        var ct = 0;

	    nb = document.forms[id].elements.length;
	    for (var i=0;i<nb;i++)
	    {
    	    var e = document.forms[id].elements[i];
            if (e.name == 'remover[]' && e.checked == '1')
            ct = ct + 1;
	    }

        if (ct == 0)
            alert("Por favor,\nselecione o(s) registro(s) que deseja remover.");
        else
        {
            if (ct > 1)
                var chk = confirm("Confirmar remoção dos "+ct+" registros selecionados ?", "Sim", "Não");
            else
                var chk = confirm("Confirmar remoção do registro selecionado ?", "Sim", "Não");

            if (chk == true)
            {
                document.getElementById("removedata").submit()
                document.getElementById("removedata").YES_DEL.value = "YES_DEL";
            }
        }
    }

    /* SELECIONA TODOS CHECKBOX DO FORMULÁRIO */
    function SelAll(id, seleciona) {
        var id;
        var seleciona;
        var nb;
	    var chk;

	    if (document.forms[id].SEL_ALL.value == 0) chk=1;
	    else chk=0;

	    nb = document.forms[id].elements.length;
	    for (var i=0;i<nb;i++)
	    {
	    	var e = document.forms[id].elements[i];
            if (e.name == seleciona && e.disabled == '')
            e.checked = chk;
	    }
	    document.forms[id].SEL_ALL.value = chk;
    }
    
    /* ADICIONA SOMBRA NAS TR's ONMOUSEOVER */
    function ShadowTit (obj, vr)
    {
        var obj, vr;

        if (vr == 1)
        obj.id = "show_bgon";

        if (vr == 2)
        obj.id = "show_bgoff";
    }
    
    /* LIMITAR TEXTAREAS */
    function LimitTextarea (obj, limite, idct)
    {
        var obj;
        var limite;
        var idct;
        
        document.getElementById(idct).value = (limite - obj.value.length);
        
        if (obj.value.length > limite)
        {
            obj.value = obj.value.substr(0, limite);
            document.getElementById(idct).value = (limite - obj.value.length);
        }
    }

    /* SETAR CORRETAMENTE AOS CAMPOS DE VALORES */
    function setValor(formnum, campo) {

        var ct;
        var formnum;
        var setcampo;

        setcampo = eval("document.form_edt."+campo);
        ct = setcampo.value;

        if (ct != "-") {
        setcampo.disabled = true;
        setcampo.value = "-";
        } else {
        setcampo.disabled = false;
        setcampo.value = "";
        }
    }

/*
     ##############################################
           SCRIPTS DE FORMATAÇÃO FORMULÁRIOS

           ENVIO DE FORMULARIOS DO CMSystem
     ##############################################
*/

    
    function SubmitBusca() {
		
		
                document.form.submit();
			
    }
	
	
	function SubmitProduto() {		
		
        if (document.form_edt.nome_produto.value.length < 3) {
            alert('Preencha corretamente o Nome do Produto');
            document.form_edt.produto.focus();
        }	
			else
            document.form_edt.submit();
			
    }
	
	function SubmitRepre() {		
		
        if (document.form_edt.repre.value == "default" ) {
            alert('Preencha corretamente o Nome do Fabricante');
            document.form_edt.repre.focus();
        }	
			else
            document.form_edt.submit();
			
    }
	
	function SubmitNews() {		
		
        if (document.form_edt.titulo.value == "default" ) {
            alert('Preencha corretamente o Título da Notícia');
            document.form_edt.titulo.focus();
        }	
			else
            document.form_edt.submit();
			
    }
    
    /* SEMI-NOVOS */
    function SubmitSeminovo() {

        if (document.form_edt.Modelo.value.length < 3) {
            alert('Preencha corretamente o Nome do Modelo');
            document.form_edt.Modelo.focus();
        } else if (document.form_edt.Cor.value.length < 1) {
            alert('Preencha corretamente a cor do veículo');
            document.form_edt.Cor.focus();
        } else if (document.form_edt.Ano.value.length < 2) {
            alert('Preencha corretamente o Ano do veículo');
            document.form_edt.Ano.focus();
        } else if (document.form_edt.Combustivel.value.length < 1) {
            alert('Preencha corretamente o Combustível do veículo');
            document.form_edt.Combustivel.focus();
        } else if (document.form_edt.Especificacoes.value.length < 10) {
            alert('Preencha corretamente as Especificações');
            document.form_edt.Especificacoes.focus();
        } else {
        
            // Verifica Campos - JPG
            var posf1 = document.form_edt.Foto1.value.search(/jpg/i);
            var posf2 = document.form_edt.Foto2.value.search(/jpg/i);
            var posf3 = document.form_edt.Foto3.value.search(/jpg/i);
            var posf4 = document.form_edt.Foto4.value.search(/jpg/i);

            // Verifica se campos são arquivos .jpg
            if (document.form_edt.Foto1.value.length > 10 && posf1 < 0) {

                alert('Favor preencher a Foto 1 com um arquivo JPG válido!');
                document.form_edt.Foto1.focus();
                
            } else if (document.form_edt.Foto2.value.length > 10 && posf2 < 0) {

                alert('Favor preencher a Foto 2 com um arquivo JPG válido!');
                document.form_edt.Foto2.focus();
                
            } else if (document.form_edt.Foto3.value.length > 10 && posf3 < 0) {

                alert('Favor preencher a Foto 3 com um arquivo JPG válido!');
                document.form_edt.Foto3.focus();
                
            } else if (document.form_edt.Foto4.value.length > 10 && posf4 < 0) {

                alert('Favor preencher a Foto 4 com um arquivo JPG válido!');
                document.form_edt.Foto4.focus();
                
            } else {
                document.form_edt.submit();
            }
        }
    }
    
