﻿// Dependent on JQuery

// Declare Global Variables to keep application-wide javascript settings.
jQuery.appSettings = {
    enableLog: true,
    enableAlert: false
};

// Implement logging function.
jQuery.log = function(message) {
    if ($.appSettings.enableLog == true) {
        if (window.console) {
            console.debug('Application Debug: ' + message);
        }
        if ($.appSettings.enableAlert == true) {
            alert('Application Debug: ' + message);
        }
    }
};


/* Extend jQuery with functions for PUT and DELETE requests. */
function _ajax_request(url, data, callback, type, method) {
    if (jQuery.isFunction(data)) {
        callback = data;
        data = {};
    }
    return jQuery.ajax({
        type: method,
        url: url,
        data: data,
        success: callback,
        dataType: type
    });
}

jQuery.extend({
    put: function(url, data, callback, type) {
        return _ajax_request(url, data, callback, type, 'PUT');
    },
    delete_: function(url, data, callback, type) {
        return _ajax_request(url, data, callback, type, 'DELETE');
    }
});
