/*
*	Tne MAINEST point of techonology!!!
* Creates hidden frame, in which our form will targeting.
*/
function createIFrame() {
	var id = 'f' + Math.floor(Math.random() * 99999);
	var div = document.createElement('div');
	iframeString = "<iframe style=\"display:none; width=300px; height=150px; \" src=\"about:blank\"" + " id=\"" + id + "\" name=\"" + id + "\" onload=\"sendComplete('" + id + "')\"></iframe>";
	div.innerHTML = iframeString;
	document.body.appendChild(div);
	return document.getElementById(id);
}

/*
Функция sendComplete будет вызвана по окончании загрузки фрейма.
Её задача - обработка результата операции, либо просто уведомление пользователя о завершении загрузки.
Для этого будет вызвана пользовательская программа func с двумя аргументами:
пользовательский arg, плюс DOM-результат, возвращенный сервером.
Мы подразумеваем, что сервер возвращает XML.
Для его извлечения из фрейма служит довольно громоздкая функция getIFrameXML,
нивелирующая различия между интернет-браузерами.
*/

function sendForm(form, url) {
	if (!document.createElement) return; // not supported
	if (typeof(form)=="string") form=document.getElementById(form);
	var frame = createIFrame();
	form.setAttribute('target', frame.id);
	form.setAttribute('action', url);
	form.submit();
}

function sendComplete(id) {
	var iframe=document.getElementById(id);
	if (iframe.onSendComplete && typeof(iframe.onSendComplete) == 'function')
	iframe.onSendComplete();
}

function getIFrameXML(iframe) {
	var doc=iframe.contentDocument;
	if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
	if (!doc) doc=window.frames[iframe.id].document;
	if (!doc) return null;
	if (doc.location=="about:blank") return null;
	if (doc.XMLDocument) doc=doc.XMLDocument;
	return doc;
}

var cnt=0;
function uploadComplete(element, doc) {
	if (!doc) return;
	if (typeof(element)=="string") element=document.getElementById(element);
	element.innerHTML = 'Результат запроса #' + (++cnt)	+ ': ' + doc.documentElement.firstChild.nodeValue;
}