$(document).ready(function(){ 
    
    $('.btn_menu').hover(function(){
        $(this).attr('src', 'img/' + $(this).attr('id') + '_actif.jpg');    
    }, function(){
        $(this).attr('src', 'img/' + $(this).attr('id') + '.jpg');    
    });
    
    $('.btn_plaquette').hover(function(){
        $(this).attr('src', 'img/' + $(this).attr('id') + '_actif.jpg');    
    }, function(){
        $(this).attr('src', 'img/' + $(this).attr('id') + '.jpg');    
    });
    
    if ($('#featured').length !== 0)
    {
        $('#featured').tabs({fx:{opacity: 'toggle'}}).tabs('rotate', 0, true); 
    }
    
    $('#bloc_num .num').click(function(){
        $('#method1, #method2').hide(0);
        $('#method' + $(this).attr('id')).show(0);    
    });
    
    $('form[name=contact]').submit(function(){
        var msg = '';
        
        if ( $('input[name=nom], input[name=intitule], input[name=mail], input[name=tel], textarea[name=details]').val() == '')
        {
            msg = msg + 'Veuillez renseigner tous les champs avant de soumettre le formulaire \n';    
        }
        
        if (!is_mail($('input[name=mail]').val()))
        {
            msg = msg + 'L\'adresse mail saisie n\'est pas au bon format \n';  
        }
        
        if (!is_numeric($('input[name=tel]').val()))
        {
            msg = msg + 'Votre numéro de téléphone doit comporter uniquement des chiffres, et être au format français'; 
        }
        
        if (msg != '')
        {
            alert(msg);
            return false;
        }
           
    });
    
});

function is_mail(string)
{
    var regs = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return regs.test(string);

}

function is_numeric(string)
{
    var regs =/^(0)[0-9]{9}/gi;
    return regs.test(string);

}
