$(document).ready(function() {
    $('input.blendfield:text').keypress( function(e) {
        // Don't submit the form on 'enter' key
        if (e.which == '13') {
            e.preventDefault();
            $(this).blur();
        }
    });

    // Submit new relationship to the server when the field loses focus
    $('input.blendfield:text').focusout( function() {
        var jqxhr = $.post(
            'ajax.php',
            {
                'action': $(this).attr('action'),
                'userid': $(this).attr('userid'),
                'data': $(this).val()
            },
            function(msg) {
                var result = jQuery.parseJSON(msg);
                if (result.hasOwnProperty('error')) {
                    alert(result.status);
                } else {
                    $('span#'+result.field+'.blendstatus').text(result.status);
                }
            }
        ).error(function() { alert("error"); } );
    });

    $('input.blendfield:text').click( function() {
        $(this).select();
    });

    $('div.blendfield').mouseenter( function() {
        $(this).css('background-color', '#DADDE4');
        $(this).css('padding', '0px');
        $(this).find('*').css('background-color', '#DADDE4');
        $(this).find('input:text').css('border-width', '1px');
        $(this).find('input:text').css('border-color', 'black');
        $(this).find('input:text').css('border-style', 'solid');
    });

    $('div.blendfield').mouseleave(blendFieldLeave);
    
    function blendFieldLeave () {
        $(this).css('background-color', '');
        $(this).css('padding', '');
        $(this).find('*').css('background-color', '');
        $(this).find('input:text').css('border', 'none');
    }
});

