//alert(1);

// // Inspired by base2 and Prototype
// (function() {
    // var initializing = false, fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/ : /.*/;

    // // The base MyClass implementation (does nothing)
    // this.MyClass = function () { };

    // // Create a new MyClass that inherits from this class
    // MyClass.extend = function(prop) {
        // var _super = this.prototype;

        // // Instantiate a base class (but only create the instance,
        // // don't run the init constructor)
        // initializing = true;
        // var prototype = new this();
        // initializing = false;

        // // Copy the properties over onto the new prototype
        // for (var name in prop) {
            // // Check if we're overwriting an existing function
            // prototype[name] = typeof prop[name] == "function" &&
        // typeof _super[name] == "function" && fnTest.test(prop[name]) ?
        // (function(name, fn) {
            // return function() {
                // var tmp = this._super;

                // // Add a new ._super() method that is the same method
                // // but on the super-class
                // this._super = _super[name];

                // // The method only need to be bound temporarily, so we
                // // remove it when we're done executing
                // var ret = fn.apply(this, arguments);
                // this._super = tmp;

                // return ret;
            // };
        // })(name, prop[name]) :
        // prop[name];
        // }

        // // The dummy class constructor
        // function MyClass() {
            // // All construction is actually done in the init method
            // if (!initializing && this.init)
                // this.init.apply(this, arguments);
        // }

        // // Populate our constructed prototype object
        // MyClass.prototype = prototype;

        // // Enforce the constructor to be what we expect
        // MyClass.constructor = MyClass;

        // // And make this class extendable
        // MyClass.extend = arguments.callee;

        // return MyClass;
    // };
// })();

// MyClass = MyClass.extend({
	// 'trigger': function (name, args) {
		// if (this.container) {
			// jQuery(this.container).trigger(name, args);
		// }
		// jQuery(this).trigger(name, args);
	// },
	// 'bind': function (name, func) {
		// jQuery(this).bind(name, func);
	// },
	// 'unbind': function(name) {
		// jQuery(this).unbind(name);   
	// },
	// 'callback': function (fnMethod) {
		// var objSelf = this;
		// return (function (e) { 
			// var sender = this; 
			// if (e) e.sender = sender;
			// return (fnMethod.apply(objSelf, arguments)); 
		// });
	// }
// });

var EventClass = Class.create({
	'initialize': function(container) {
	},
	'trigger': function (name, args) {
		if (this.container) {
			jQuery(this.container).trigger(name, args);
		}
		jQuery(this).trigger(name, args);
	},
	'bind': function (name, func) {
		jQuery(this).bind(name, func);
	},
	'unbind': function(name) {
		jQuery(this).unbind(name);   
	},
	'callback': function (fnMethod) {
		var objSelf = this;
		return (function (e) { 
			var sender = this; 
			if (e) e.sender = sender;
			return (fnMethod.apply(objSelf, arguments)); 
		});
	}
});

Array.prototype.removeValue = function(value){
	for (var i = 0; i < this.length; i++) {
		if (this[i] == value) {
			//alert('remove');
			this.splice(i, 1);
		}
	}
};

Array.prototype.hasValue = function(value){
	for (var i = 0; i < this.length; i++) {
		if (this[i] == value) {
			return true;
		}
	}
};

Array.prototype.contains = Array.prototype.hasValue;

Array.prototype.hasDate = function(value){
	for (var i = 0; i < this.length; i++) {
		if (this[i] - value == 0) {
			return true;
		}
	}
};

Array.prototype.removeDate = function(value){
	for (var i = 0; i < this.length; i++) {
		if (this[i] - value == 0) {
			//this.splice(i, 1);
		}
	}
};

JSON.parse2 = function(json) {
	var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
	var reMsAjax = /^\/Date\((d|-|.*)\)\/$/;

	return JSON.parse(json, function(key, value) {
		if (typeof value === 'string') {
			var a = reISO.exec(value);
			if (a)
				return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));                                                
			a = reMsAjax.exec(value);
			if (a) {
				var b = a[1].split(/[-,.]/);
				return new Date(+b[0]);
			}
		}
		return value;
	});
};

jQuery(function($) {
	$('a[type=submit], div[type=submit]').click(function() {
		var a = $(this);
		var form = a.closest('form');

		form.find('input.SubmitHidden').remove();

		var hidden = $('<input />').attr({
			'type': 'hidden',
			'name': a.attr('name'),
			'value': a.attr('value')
		}).addClass('SubmitHidden');

		form.append(hidden);

		var eventResult = true;
		if (form[0].onsubmit) form[0].onsubmit(); 
		
		//alert(eventResult);
		
		if (typeof(eventResult) == 'undefined' || eventResult) {
			form[0].submit();
		}

		return false;
	});
	
	$('input.EnterSubmit').each(function() {
		var textBox = $(this);
		var form = textBox.closest('form');
		var button = form.find('a.EnterSubmit, div.EnterSubmit');
	
		var detectEnterKey = function(e) {
			if (e.which == 13) {
				textBox.unbind('keydown', detectEnterKey);
				textBox.unbind('keypress', detectEnterKey);
				textBox.unbind('keyup', detectEnterKey);
				
				button.click();
				return false;
			}
		};
		
		textBox.bind('keydown', detectEnterKey);
		textBox.bind('keypress', detectEnterKey);
		textBox.bind('keyup', detectEnterKey);
	});
	
	$('.Unselectable a').each(function() {
		var a = $(this);
		a.unbind();
		a.attr('disabled', 'disabled').attr('href', 'javascript:void(0)');
	});
});

//var Person = MyClass.extend({
//    init: function(isDancing) {
//        this.dancing = isDancing;
//    },
//    dance: function() {
//        return this.dancing;
//    }
//});

//var Ninja = Person.extend({
//    init: function() {
//        this._super(false);
//    },
//    dance: function() {
//        // Call the inherited version of dance()
//        return this._super();
//    },
//    swingSword: function() {
//        return true;
//    }
//});

//var EventClass = MyClass.extend({
//    'init': function() {

//    },
//    'addEventListener': function(eventType, eventData, handler) {
//        $(this).bind(eventType, eventData, handler);
//    }
//});

//aaa
