Valraiso.namespace('Cbsa.contact');
Cbsa.contact =
{
    checkContactForm : function()
    {
        var noerror = true;
        
        noerror = Beware.checkField('name')    && noerror;
        noerror = Beware.checkField('email')   && noerror;
        noerror = Beware.checkField('subject') && noerror;
        noerror = Beware.checkField('content') && noerror;
        
        if (noerror)
        {
            noerror = Beware.checkEmail('email');
        }
        
        return noerror;
    }
}

Valraiso.namespace('Cbsa.carte');
Cbsa.carte =
{
    checkDemandeCarteForm : function()
    {
        var noerror = true;
        
        noerror = Beware.checkField('nom')        && noerror;
        noerror = Beware.checkField('prenom')     && noerror;
        noerror = Beware.checkField('adresse')    && noerror;
        noerror = Beware.checkField('cp')         && noerror;
        noerror = Beware.checkField('ville')      && noerror;
        noerror = Beware.checkField('tel')        && noerror;
        noerror = Beware.checkField('email')      && noerror;
        noerror = Beware.checkListField('statut') && noerror;
        
        if ($('#statut').val() == 'Autre')
        {
            noerror = Beware.checkField('autre') && noerror;
        }
        
        if (noerror)
        {
            noerror = Beware.checkEmail('email');
        }
        
        return noerror;
    },
    
    checkMotDePasseOublieForm : function()
    {
        var noerror = true;
        
        noerror = Beware.checkField('numero') && noerror;
        noerror = Beware.checkField('email')  && noerror;
        
        if (noerror)
        {
            noerror = Beware.checkEmail('email');
        }
        
        return noerror;
    },
    
    checkStatut : function()
    {
        if ($('#statut').val() == 'Autre')
        {
            $('#autreLab').show();
            $('#autreVal').show();
        }
        else
        {
            $('#autreLab').hide();
            $('#autreVal').hide();
        }
    }
}

Valraiso.namespace('Cbsa.bilan');
Cbsa.bilan =
{
    showEntreprisesForm : function()
    {
        $('#btnEntreprises').addClass('current');
        $('#btnParticuliers').removeClass('current');
        
        if ($('#form-particuliers').is(':visible'))
        {
            $('#form-particuliers').hide(500);
            $('#form-entreprises').show(500);
        }
        else
        {
            $('#form-entreprises').show(500);
        }
        
        return false;
    },
    
    showParticuliersForm : function()
    {
        $('#btnParticuliers').addClass('current');
        $('#btnEntreprises').removeClass('current');
        
        if ($('#form-entreprises').is(':visible'))
        {
            $('#form-entreprises').hide(500);
        }
        
        $('#form-particuliers').show(500);
        
        return false;
    },
    
    checkEntreprisesForm : function()
    {
        var noerror = true;
        
        noerror = Beware.checkField('name')    && noerror;
        noerror = Beware.checkField('email')   && noerror;
        noerror = Beware.checkField('subject') && noerror;
        noerror = Beware.checkField('content') && noerror;
        
        if (noerror)
        {
            noerror = Beware.checkEmail('email');
        }
        
        return noerror;
    },
    
    checkParticuliersForm : function()
    {
        var noerror = true;
        
        noerror = Beware.checkField('name')    && noerror;
        noerror = Beware.checkField('email')   && noerror;
        noerror = Beware.checkField('subject') && noerror;
        noerror = Beware.checkField('content') && noerror;
        
        if (noerror)
        {
            noerror = Beware.checkEmail('email');
        }
        
        return noerror;
    },
    
    checkBilanParodontalEntreprises : function(bilanName, optionName)
    {
        var bilan  = EL(bilanName);
        var option = EL(optionName);

        if (bilan.selectedIndex < option.selectedIndex)
        {
            option.selectedIndex = bilan.selectedIndex;
        }
    },

    checkOptionParodontalEntreprises : function(bilanName, optionName)
    {
        var bilan  = EL(bilanName);
        var option = EL(optionName);

        if (bilan.selectedIndex < option.selectedIndex)
        {
            bilan.selectedIndex = option.selectedIndex;
        }
    },
    
    checkBilanParodontalParticuliers : function ()
    {
        var checkBilan  = EL('BilanParodontal');
        var checkOption = EL('OptionParodontal');
        
        if (!checkBilan.checked && checkOption.checked)
        {
            checkOption.checked = false;
        }
        
        return true;
    },

    checkOptionParodontalParticuliers : function()
    {
        var checkBilan  = EL('BilanParodontal');
        var checkOption = EL('OptionParodontal');
        
        if (checkOption.checked && !checkBilan.checked)
        {
            checkBilan.checked = true;
        }
        
        return true;
    },
    
    checkEmailForSend : function(formToSubmit)
    {
        if (Beware.checkEmailDefault('mail', 'divErrorEmail'))
        {
            $('#' + formToSubmit).attr('target', '_self');
            $('#' + formToSubmit).attr('action', actionSend);
            $('#email-contact').val($('#mail').val());
            $('#envoyerdevis').hide(500);
            $('#' + formToSubmit).submit();
        }
        
        return false;
    },
    
    printDevis : function(formToSubmit)
    {
        $('#' + formToSubmit).attr('target', '_blank');
        $('#' + formToSubmit).attr('action', actionPrint);
        $('#' + formToSubmit).submit();
        
        return false;
    },
    
    contactDevis : function(formToSubmit)
    {
        $('#' + formToSubmit).attr('target', '_self');
        $('#' + formToSubmit).attr('action', actionContact);
        $('#' + formToSubmit).submit();
        
        return false;
    }
}


