﻿jQuery.fn.serializeObject = function() {
    var o = {};
    var a = 
        this.map(function(){
			return this.elements ? jQuery.makeArray(this.elements) : this;
		})
		.filter(function(){
			return this.name && !this.disabled &&
				(/select|textarea/i.test(this.nodeName) ||
					/checkbox|text|hidden|password|search/i.test(this.type));
		})
		.map(function(i, elem){
			var val = /checkbox/i.test(jQuery(this).attr("type")) ? jQuery(this).attr("checked") : jQuery(this).val();
			return val == null ? null :
				jQuery.isArray(val) ?
					jQuery.map( val, function(val, i){
						return {name: elem.name, value: val};
					}) :
					{name: elem.name, value: val};
		}).get();
    jQuery.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value != undefined ? this.value : '');
        } else {
            o[this.name] = this.value != undefined ? this.value : '';
        }
    });
    return o;
};