function createObject() {
	var request_type;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer")
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	else
		request_type = new XMLHttpRequest();
	return request_type;
}

var http = createObject();
var http_ph = createObject();
var nocache = 0;

function addChange()
{
	var params = '';
	document.getElementById('add_change_response').innerHTML = "Отправка заявки.";
	obj_code = encodeURIComponent (document.getElementById('eobj_code').value);
	document.getElementById('add_change_response').innerHTML = "Отправка заявки..";
	content1 = encodeURIComponent (document.getElementById('echangearea').value);
	document.getElementById('add_change_response').innerHTML = "Отправка заявки...";
	author = encodeURIComponent (document.getElementById('eauthor').value);
	document.getElementById('add_change_response').innerHTML = "Отправка заявки....";
	nocache = Math.random();
	params = "obj_code="+obj_code+"&content1="+content1+"&nocahce="+nocache;

	http.open('POST', '../_k/ajax/add_change.php', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = addReply_ch;
	http.send(params);
}

function addArticle()
{
	var params = '';
	document.getElementById('add_article_response').innerHTML = "Отправка статьи.";
	obj_code = encodeURIComponent (document.getElementById('eobj_code').value);
	document.getElementById('add_article_response').innerHTML = "Отправка статьи..";
	content1 = encodeURIComponent (document.getElementById('etextarea').value);
	document.getElementById('add_article_response').innerHTML = "Отправка статьи...";
	author = encodeURIComponent (document.getElementById('eauthor').value);
	document.getElementById('add_article_response').innerHTML = "Отправка статьи....";
	if (document.getElementById('ereport').checked==false)
		rep='off';
	else
		rep='on';
//	rep = encodeURIComponent (document.getElementById('ereport').value);
	document.getElementById('add_article_response').innerHTML = "Отправка статьи.....";
	nocache = Math.random();
	params = "obj_code="+obj_code+"&content1="+content1+"&author="+author+"&rep="+rep+"&nocahce="+nocache;

	http.open('POST', '../_Kernel/ajax/add_article.php', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = addReply;
	http.send(params);
}

function addPhoto()
{
	//
	// !! не вызывается. Фото отправляется через iframe в основном шаблоне
	//

	var params = '';
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии.";
	obj_code = encodeURIComponent (document.getElementById('eobj_code').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии..";

	author = encodeURIComponent (document.getElementById('eauthor').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии...";

	comment = encodeURIComponent (document.getElementById('eComment').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии....4";

	rep = encodeURIComponent (document.getElementById('eReport').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии.....5";

	filep = encodeURIComponent (document.getElementById('efileFoto').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии......6";

	date1 = encodeURIComponent (document.getElementById('date1').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии.......7";

	date2 = encodeURIComponent (document.getElementById('date2').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии........8";

	ftype = encodeURIComponent (document.getElementById('eFotoType').value);
	document.getElementById('add_photo_response').innerHTML = "Отправка фотографии.........9";

	params = "?obj_code="+obj_code+"&author="+author+"&comment="+comment+"&rep="+rep+"&filep="+filep+"&date1="+date1+"&date2="+date2+"&ftype="+ftype;
	nocache = Math.random();

	http.open('GET', '../_Kernel/ajax/add_photo.php'+params, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = addReply_ph;
	http.send(null);
	document.getElementById('add_photo_response').innerHTML = "Отправлено, обрабатываем."+params;
	// очистим поле Файл
	tmp=document.getElementById('filecontainer').innerHTML;
	alert(tmp);
	document.getElementById('filecontainer').innerHTML='';
	document.getElementById('filecontainer').innerHTML=tmp;
}

function addReply_ch()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response != '1')
			document.getElementById('add_change_response').innerHTML = '<font color=red>'+response+'</font>';
		else
		{
			document.getElementById('add_change_response').innerHTML = 'Заявка отправлена.';
			document.getElementById('echangearea').value = 'Заявка отправлена.';
		}
	}
}

function addReply()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response != '1')
			document.getElementById('add_article_response').innerHTML = '<font color=red>'+response+'</font>';
		else
		{
			document.getElementById('add_article_response').innerHTML = 'Статья отправлена.';
			document.getElementById('etextarea').value = 'Статья отправлена.';
			nicEditors.findEditor('etextarea').setContent('Статья отправлена.');
		}
	}
}

function addReply_ph()
{
	if(http_ph.readyState == 4)
	{
		var response = http_ph.responseText;
		if(response != '1')
			document.getElementById('add_photo_response').innerHTML = '<font color=red>'+response+'</font>';
		else
		{
			document.getElementById('add_photo_response').innerHTML = 'Фотография отправлена на проверку.';
			tmp=document.getElementById('filecontainer').innerHTML;
			document.getElementById('filecontainer').innerHTML='';
			document.getElementById('filecontainer').innerHTML=tmp;
		}
	}
}
function startUpload()
{
    document.getElementById('upload_target').style.display = '';
	var iframe = document.getElementById('upload_target');
	var doc;

	if (iframe.contentDocument)
		doc = iframe.contentDocument;
	else
		doc = iframe.contentWindow.document;
	doc.body.innerHTML = '<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_i/loader.gif"><br>';
    return true;
}