/**
 * @author Shawn Welch
 */
$(function(){
	/** Post - instead of get - JSON function **/
    $.postJSON = function(url, data, callback){
        $.post(url, data, callback, "json");
    };
	
	/** Validation **/
    $.fn.validateForm = function(ajax_submit, options){
        var defaults = {
            onfocusout: false,
            onkeyup: false,
            showErrors: function(errorMap, errorList){
                if (errorList.length > 0) {
                    var message = "Please fix the following errors:\n\n"
                    for (key in errorList) {
                        // Add to message
                        message += '- ' + errorList[key].message + "\n";
                    }
                    alert(message);
                }
            },
            submitHandler: function(form){
                $(form).ajaxSubmit(ajax_submit);
            }
        }
        
        var settings = $.extend(true, defaults, options);
        
        $(this).validate(settings);
    }
	
	/** Element blocking **/
    $.blockOptions = {
        message: '<img src="/images/ajax-loader.gif" />',
        css: {
            backgroundColor: '#FFF',
            border: 'none',
            width: '180px'
        },
        overlayCSS: {
            backgroundColor: '#FFF'
        },
		fadeIn: 0
    }
    
    $.fn.blockElement = function(){
        $(this).block($.blockOptions)
    }
});
