var AjaxForm = function(){}; AjaxForm.prototype = { instance : "", hostPath : "", sendingText : "", valText : "", uploadText : "", sessionId : "", isChecking : false, isSending : false, delay : 350, onCheckActions : [], add_observers: function() { var $this = this; var $formId = "#af_"+this.instance; //jQuery($formId+" input:first").focus(); jQuery("#"+this.instance+"_sendbutton").click(function(){ $this.check_form(); }); jQuery("#af_"+this.instance+" .af_file_field").change(function(){ $this.submit_file(this.parentNode.id); }); jQuery("#af_"+this.instance+" .af_file").each(function(){ var $fileFormId = this.id; jQuery("#"+$fileFormId+"_iframe").load(function(){ $this.finish_upload($fileFormId); }); }); jQuery($formId+" input:text, "+$formId+" input:password").keyup(function(e){ if(e.keyCode == 13) $this.check_form(); }); }, add_oncheck_action: function(action) { this.onCheckActions.push(action); }, initialize: function(instance) { this.instance = instance; }, submit_file: function(id) { jQuery("#af_loader_"+this.instance).html(this.uploadText); this.startLoading(); var responseDiv = jQuery("#"+id+"_response").get(0); var formObject = jQuery("#"+id).get(0); formObject.submit(); }, finish_upload: function(id) { var responseDiv = jQuery("#"+id+"_response"); var responseFrame = jQuery("#"+id+"_iframe"); var responseForm = jQuery("#"+id); var response = responseFrame.contents().find("body").html(); var doneStr = ""; if(response != "") { responseDiv.html(response); if(response.indexOf(doneStr) != -1){ responseForm.hide(); } this.add_observers(); } this.stopLoading(); }, check_form: function() { if(!this.isChecking) { this.isChecking = true; var $this = this; var loader = jQuery("#af_loader_"+this.instance); var parameters = this.getDivFormActions(); loader.html(this.valText); this.startLoading(); parameters["action"] = "checkform"; parameters["session_id"] = $this.sessionId; parameters["instance"] = $this.instance; var succes_actions = function(responseText) { var div = jQuery("#af_"+$this.instance); if(responseText == ""){ loader.html($this.sendingText); $this.add_form_javascript_functions(); $this.send_form(); } else { div.html(responseText); $this.add_form_javascript_functions(); $this.ajax_reset(); $this.stopLoading(); location.href = "#"+$this.instance+"_top"; } $this.isChecking = false; } var ajax_error = function(XMLHttpRequest, textStatus, errorThrown) { $this.stopLoading(); $this.isChecking = false; jQuery("#af_"+$this.instance+" .af_errors").html(textStatus); } setTimeout(function(){ jQuery.ajax({ url : $this.hostPath+"action.php", type : "post", data : parameters, success : succes_actions, error : ajax_error }); },this.delay); } }, add_form_javascript_functions: function() { for(var $i=0; $i