jQuery(
function($) {
	$.fn.replace=function(content) {
		$(this).empty().append(content);
		return this;
	}
	;
	$.fn.TEAjaxForm=function(opt) {
		return this.each(function() {
			var f=$(this);
			opt=opt|| {
			}
			;
			if(typeof opt.action=="undefined"||!/^(append|prepend|replace)$/.test(opt.action)) {
				opt.action='append';
			}
			function _setMask(formData,jqForm,options) {
				var _e,_p=f.position(),_x=_p.left+'px',_y=(_p.top+f.height()/2)+'px',_w=f.width()+'px',_mask="<div class='TEAjaxFormMask' style='text-align:center;position:absolute;width:"+_w+";left:"+_x+";top:"+_y+"'><img src=\"images/ajax-loader.gif\"/></div>";
				if(f.attr('onSubmit')) {
					_e=f.attr('onSubmit');
					_e=(typeof _e=='string')?new Function(_e)():_e();
					if(_e==false) {
						return false;
					}
				}
				if(typeof Spry!='undefined') {
					var r=Spry.Widget.Form.validate(jqForm[0]);
					if(!r)return r;
				}
				f.fadeTo("normal",0.33);
				f.after(_mask);
			}
			;
			function _success(content) {
				try {
					f.siblings('.TEAjaxFormMask').remove();
					$('#'+opt.container)[opt.action](content);
				}
				catch(e) {
				}
				f.fadeTo("normal",1);
			}
			;
			f.ajaxForm( {
				url:opt.container+'.php',type:'POST',beforeSubmit:_setMask,success:_success,resetForm:true
			}
			);
		}
		);
	}
	;
}
);
