
jQuery.fn.defaulter = function() {
    return this.each(function() {
        var element = $(this);
        var defaultText = element.val();

        $(this).closest('form').submit(function() {
            if(element.val() == defaultText) {
               element.val('');
            }
        });

        element.focus(function() {
            if(element.val() == defaultText) {
                element.val('');
            }
        });
        element.blur(function() {
            if(element.val() == '') {
                element.val(defaultText);
            }
        });
    });
}

jQuery.validator.setDefaults({
    errorPlacement: function(error, element) {
        element.bt(error.html(), {
            trigger: 'none',
            spikeLength: 10,
            fill: "#ffc",
            strokeStyle: "#993",
            strokeWidth: 1,
            positions: 'bottom',
            shrinkToFit: true,
            closeWhenOthersOpen: false
        }).btOn();
    },
    highlight: function(element, errorClass, validClass) {
    },
    unhighlight: function(element, errorClass, validClass) {
        $('.bt-wrapper').btOff();
    },
    invalidHandler: function(form, validator) {
//        var errors = validator.numberOfInvalids();
//        if (errors) {
//            alert(errors + ' errors found, errors are displayed on the form.\n\n'+
//                  'Please check the form and try again.');
//        }
    }
});


$(document).ready(function() {
    $('.plus-minus label').click(function() {
        var parentLi = $(this).closest('li');
        if(parentLi.hasClass('plus')) {
            $(this).nextAll('.items-table').show();
            parentLi.addClass('minus');
            parentLi.removeClass('plus');
        } else {
            $(this).nextAll('.items-table').hide();
            parentLi.addClass('plus');
            parentLi.removeClass('minus');
        }
    }).css('cursor', 'pointer');

//    $('.sm-icon').mouseover(function() {
//        $('#smttip').html(this.title);
//    });
//    $('.sm-icon').mouseout(function() {
//        $('#smttip').html('&nbsp;');
//    });

    $('.premium-badge').bt('Premium Member', {
        spikeLength: 10,
        fill: "#ffc",
        strokeStyle: "#993",
        strokeWidth: 1,
        positions: 'bottom',
        shrinkToFit: true
    });
    $('#terms-link').click(function(e) {
        e.preventDefault();

        var url = this.href;

        $('<div>Loading...</div>').dialog({
            title: 'Terms & Conditions',
            autoOpen: true,
            width: 550,
            height: 450,
            modal: true,
            resizable: true,
            buttons: {
                'Close Window': function() {
                    $(this).dialog('close');
                }
            },
            close: function() {
                $(this).remove();
            }
        }).load(url);
    });
});
