/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/
 
AIM = {

        inProgress : false,
	frame : function(c) {
//debugger;
                if(typeof( this.iFrame) !='undefined' ) {
                    var parent = this.iFrame.parentNode;
                    parent.removeChild(this.iFrame);
                }
                var n = 'f' + Math.floor(Math.random() * 99999);
                var d = document.createElement('DIV');
                d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
                document.body.appendChild(d);
                this.iFrame = d;

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
                    i.onComplete = c.onComplete;
		}

                if (c && typeof(c.onError) == 'function') {
                    i.onError = c.onError;
		}
		return n;
	},
 
	form : function(f, name) {
		f.setAttribute('target', name);
	},
 
	submit : function(f, c) {
                // debugger;
                if(typeof (c.parameters)=='object')
                    this.parameters = c.parameters;
                
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart(c.parameters);
		} else {
			return true;
		}

	},
 
	loaded : function(id) {


		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
               // debugger;
		if (d.location.href == "about:blank") {
                        if ( (typeof(i.onError) == 'function') && (AIM.cancelled==false) ) {
                            i.onError(this.parameters);
                        }
                        AIM.cancelled=false;
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML,this.iFrame,this.parameters);
		}
                AIM.cancelled=false;
	},
        cancelled : false
 
}
