/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/
//var IFrameObj;	/*global reference to dynamicly created iframe*/
AIM = {

	IFrameObj: '',
	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		//var d = document.createElement('DIV');
		//html = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		//d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		//document.body.appendChild(d);
		//document.body.innerHTML+=html;

		/*
		var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id',n);
      tempIFrame.setAttribute('name',n);
      tempIFrame.setAttribute('src','about:blank');
      tempIFrame.style.border='2px solid black';
      tempIFrame.style.width='100px';
      tempIFrame.style.height='100px';
      //tempIFrame.onload=AIM.loaded(n);
      IFrameObj=document.body.appendChild(tempIFrame);
      //IFrameObj.onload=AIM.loaded(n);
      IFrameObj.onload=alert('serd');
    */

    if(window.ActiveXObject) {
			var io = document.createElement('<iframe style="display:none" src="about:blank" id="' + n + '" name="' + n + '" onload="AIM.loaded(\''+n+'\')"/>');
		}
			else
		{
			var io = document.createElement('iframe');
			io.id = n;
			io.name = n;
			io.src='about:blank';
			io.style.display='none';
			/*
			io.style.border='0px';
      io.style.width='0px';
      io.style.height='0px';
      */
      io.setAttribute('onload','AIM.loaded(\''+n+'\')');
		}

		AIM.IFrameObj=document.body.appendChild(io);

		if (c && typeof(c.onComplete) == 'function') {
			AIM.IFrameObj.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			//alert('start submitting...');
			return true;
		}
	},

	loaded : function(id) {

		//IFrameObj=document.getElementById(id);
		//var i = document.getElementById(id);

		if (AIM.IFrameObj.contentDocument) {
			var d = AIM.IFrameObj.contentDocument;
		} else if (AIM.IFrameObj.contentWindow) {

			var d = AIM.IFrameObj.contentWindow.document;
		} else {
			var d = window.frames[AIM.IFrameObj.id].document;
		}
		if (d.location.href == "about:blank") {
			return ;
		}

		if (typeof(AIM.IFrameObj.onComplete) == 'function') {

			AIM.IFrameObj.onComplete(d.body.innerHTML);
		}
		document.body.removeChild(AIM.IFrameObj);
	}

}//end AIM

