// Envoyer a un ami management.
jQuery( function() {
    // Validation on submit of the form.
    $( '#form-sendpage' ).submit( function() {
        var all_valid = true;

        // Validation of required field.
        $( '#form-sendpage input.required, #form-sendpage textarea.required' ).each( function( arg ) {
            if( $( this ).attr( 'value' ) === '' ) {
                $( this ).addClass( 'notvalid' );
                all_valid = false;
            }
        } );
 
        if( all_valid ) {
            $( '#form-sendpage input:disabled' ).each( function( arg ) {
                $( this ).attr( 'disabled', false );
            } );
            return true;
        } else {
            return false;
        }
    } );

    // Removed notvalid class on focus of field.
    $( '#form-sendpage input.required, #form-sendpage textarea.required' ).bind( 'focus', function() {
        $( this ).removeClass( 'notvalid' );
    } );

    // On reset also reset notvalid status.
    $( '#form-sendpage' ).bind( 'reset', function() {
        $( '#form-sendpage input.required, #form-sendpage textarea.required' ).each( function() {
            $( this ).removeClass( 'notvalid' );            
        } );
    } );

    $( '#sendpage' ).live( 'click', function() {
        $( '#sendpageurl' ).val( window.location.href );
        $( '#sendpageform' ).submit();
        return false;
    } );

    // Test de tooltip in a form
    $("#sendpage_to").tooltip({ 
        // place tooltip on the right edge 
        position: ['center', 'right'], 
        // a little tweaking of the position 
        offset: [-2, 10], 
        // use a simple show/hide effect 
        effect: 'toggle', 
        // custom opacity setting 
        opacity: 0.7 
    });
    
    
} );

