AIM = {

	submit : function(frame, callbacks) {
		
		//create random iframe
		var frameId = 'frame' + Math.floor(Math.random() * 999999);
		var d = document.createElement('div');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+frameId+'" name="'+frameId+'" onload="AIM.loaded(\''+frameId+'\')"></iframe>';
		document.body.appendChild(d);
		
		//set iframe complete listener
		var i = document.getElementById(frameId);
		i.onComplete = callbacks.onComplete;
		
		frame.setAttribute('target', frameId);
		return callbacks.onStart();
	},

	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;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}