document.iframeLoaders = {};
processForm = Class.create();
processForm.prototype =
{
initialize: function(form, options, loadingMessage)
{
if (!options) options = {};
this.form = form;
this.uniqueId = new Date().getTime();
document.iframeLoaders[this.uniqueId] = this;
this.transport = this.getTransport();
this.onComplete = options.onComplete || null;
this.update = $(options.update) || null;
this.updateMultiple = options.multiple || false;
form.target= 'frame_'+this.uniqueId;
form.setAttribute("target", 'frame_'+this.uniqueId);
form.submit();
this.loadingMessage = loadingMessage;
this.update.innerHTML = '

'+this.loadingMessage+'
';
},
onStateChange: function()
{
this.transport = $('frame_'+this.uniqueId);
try //NS6
{
var doc = this.transport.contentDocument.document.body.innerHTML; this.transport.contentDocument.document.close();
}
catch (e)
{
try //IE5.5 AND IE6
{
var doc = this.transport.contentWindow.document.body.innerHTML; this.transport.contentWindow.document.close();
}
catch (e)
{
try //IE5
{
var doc = this.transport.document.body.innerHTML; this.transport.document.body.close();
}
catch (e)
{
try //BROWSERS WHICH SUCK
{
var doc = window.frames['frame_'+this.uniqueId].document.body.innerText;
}
catch (e) {} //END OF STORY
}
}
}
this.transport.responseText = doc;
if (this.onComplete)
{
setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
}
if (this.update)
{
setTimeout(function(){this.update.innerHTML = this.transport.responseText; execJs(this.update);}.bind(this), 10);
}
if (this.updateMultiple)
{
setTimeout(
function() //JSON
{
try
{
var hasscript = false; eval("var inputObject = "+this.transport.responseText);
for (var i in inputObject)
{
if (i == 'script')
{
hasscript = true;
}
else
{
if (elm = $(i))
{
elm.innerHTML = inputObject[i];
execJs(elm);
}
else
{
alert('Element error: '+i+'!');
}
}
}
if (hasscript)
{
eval(inputObject['script']);
}
}
catch (e)
{
alert('Error: '+this.transport.responseText);
}
}
.bind(this), 10);
}
},
getTransport: function()
{
var divElm = document.createElement('DIV');
divElm.style.position = "absolute";
divElm.style.top = "0";
divElm.style.marginLeft = "-10000px";
if (navigator.userAgent.indexOf('MSIE') > 0 && navigator.userAgent.indexOf('Opera') == -1)
{
divElm.innerHTML = '';
}
else
{
var frame = document.createElement("iframe");
frame.setAttribute("name", "frame_"+this.uniqueId);
frame.setAttribute("id", "frame_"+this.uniqueId);
frame.addEventListener("load", function(){ this.onStateChange(); }.bind(this), false);
divElm.appendChild(frame);
}
document.getElementsByTagName("body").item(0).appendChild(divElm);
}
};