
var ModelContactUploader = {
	uploadUrl:	'uploader.php',

	nextIFrameID:	1,

	registerUploadForm: function (form, callback) {
		//
		// Allocate a new frame id
		//
		var id = 'file-upload-iframe-' + this.nextIFrameID++ ;

		//
		// Create a hidden iframe
		//
		var div = document.createElement ('div') ;
		div.innerHTML = '<iframe id="' + id + '" name="' + id + '" src="about:blank" style="width:0px;height:0px;border:0px;"></iframe>' ;
		document.body.appendChild (div) ;
		var iframe = $(id) ;

		//
		// Attach a load event listener to the hidden frame
		//
		Event.observe (
			iframe,
			'load',
			function (evt) {
				var doc = iframe.contentDocument
					? iframe.contentDocument
					: (iframe.contentWindow
						? iframe.contentWindow.document
						: window.frames[id].document) ;
				if (doc.location.href != 'about:blank') {
					//
					// Grab the hidden frame contents and evaluate it as javascript.
					//
					var response ;
					//Doesn't work in IE7
					//eval ('response = ' + doc.body.textContent + ' ;') ;
					eval ('response = ' + doc.body.firstChild.firstChild.data + ' ;') ;


					//
					// Invoke the callback
					//
					callback (response) ;
				}
			},
			false
		) ;

		//
		// Point the form action at the uploader
		//
		form.setAttribute ('action', this.uploadUrl) ;

		//
		// Point the form target to the hidden iframe
		//
		form.setAttribute ('target', id) ;
	}

} ;
