 /* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
var arr_request;
var request = false;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
  }
}

if (!request)
  alert("Error initializing XMLHttpRequest!");


// JavaScript Document
function str_replace(search, replace, subject) {
return subject.split(search).join(replace);
}

function str_del_cifra(str)
{
	str = str_replace('0', '', str);	
	str = str_replace('1', '', str);
	str = str_replace('2', '', str);
	str = str_replace('3', '', str);
	str = str_replace('4', '', str);
	str = str_replace('5', '', str);
	str = str_replace('6', '', str);
	str = str_replace('7', '', str);
	str = str_replace('8', '', str);
	str = str_replace('9', '', str);
	return str;
}

function MyLoad() {
	setPosition();	
}

function DisplayBlock(i)
{
	 if (document.getElementById("block_"+i).style.display != "block") {
  	document.getElementById("block_"+i).style.display = "block";
 	}
 	else {
  	document.getElementById("block_"+i).style.display = "none";
 	}
 	setPosition();	
}

//функция возвращает ширину видимой части окна
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

//функция возвращает высоту видимой части окна
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

//Функция возвращает объект со свойствами left, top, width, height, определяющими координаты элемента относительно верхнего угла страницы, а так же его размеры
function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function setPosition() 
{
	var h_t = 0;
	//окончание текста во всех колонках
	var end_left = getElementPosition("end_left").top;
	var end_right = getElementPosition("end_right").top;

	var end = end_left;
	if(end < end_right)
	{
		end = end_right;
	}

	//прибитие футера
 	if(end < getClientHeight())
 	{
  		document.getElementById("footer").style.position = "absolute";
  		document.getElementById("footer").style.top = getClientHeight() - 30 + "px";
  		h_t = getClientHeight() - 30;
 	}
 	else
 	{
  		document.getElementById("footer").style.position = "absolute";
  		document.getElementById("footer").style.top = end + "px";
  		h_t = end;  
 	}

	//левая колонка
	document.getElementById("left_column").style.height = h_t + "px";
/*
 	//ширина футера
 	var foot_w = getElementPosition("right_column").left + getElementPosition("right_column").width;
  	var w;
	 if(foot_w > 500)//картинка + правая панель
 	{
 		w = foot_w;
 	}
 	else
 	{
 		w = 500;//картинка + правая панель	 
 	}
	document.getElementById("footer").style.width = w + "px";
*/
}

//для ресайза окна
window.onresize= resize;
function resize() {
	setPosition();	
}



//Выполнить запрос с Ajax
function ForgetPSW() 
{
	var email = document.getElementById('author_user_email').value;
	if(email == '')
	{
		alert('Введите ваш email');
		return false;
	}
	//проверка наличия собаки и точки в мэйле
	num1 = email.indexOf("@");
	num2 = email.indexOf(".");
	if(num1 == -1 || num2 == -1)
	{
		alert('mail указан неверно');
		return false;
	}
  // Создать URL для подключения
  var url = "ajax_action/forget_psw.php?email=" + escape(email);

  // Открыть соединение с сервером
  request.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  request.onreadystatechange = ResForgetPsw;

  // SПередать запрос
  request.send(null);
  return false;
}
//Обработка ответа от сервера
function ResForgetPsw()
{
	if (request.readyState == 4)
	{
		if (request.status == 200)
		{
	    	var response = decodeURIComponent(request.responseText);//с перекодировкой из юникода в CP1251
			//уберём комментарий
			var arr = response.split('abrakadabra');
			//arr_request = response.split('abrakadabra');
			//arr_request.splice(0, 1);//удалили комент - нулевой элемент
			var res = arr[1];
			if(res == 1)
			{
				alert('Ваш пароль выслан на ваш электронный адрес');
			}
			else
			{
				alert('Ваш пароль НЕ удалось выслать на ваш электронный адрес, попробуйте ещё раз или обратитесь в техническую поддержку сайта');
			}
	  	}
		else
		{
			if (request.status == 404)
		    {
				alert('Ответ с сервера не получен, попробуйте ещё раз или обратитесь в техническую поддержку сайта');
			}
       		else
			{
         		alert('Ошибка: статус-код: ' + request.status + ', попробуйте ещё раз или обратитесь в техническую поддержку сайта');
			}
		}
  	}
}

function SECR()
{
	window.location.href="admin/admin.php";//NATA
}
function AdminOut()
{
	document.admin.task.value = 'admin_out';
	document.admin.submit();
}

//НАЧАЛО ФУНКЦИЙ ДЛЯ СТРАНИЦ шаблона NEW
function SaveNew(id_new)
{
	document.rss.task.value = 'save_new';
	document.rss.new_id.value = id_new;
	document.rss.new_title.value = document.admin_new.title.value;
	document.rss.new_date.value = document.admin_new.date.value;
	document.rss.new_text.value = document.post.message.value;
	if(document.rss.new_title.value == '' || document.rss.new_date.value == '' || document.rss.new_text.value == '')
	{
		alert('Заполните все поля');
	}
	else
	{
		document.rss.submit();	
	}
}

function EditNew(id_new)
{
	document.rss.task.value = 'edit_new';
	document.rss.new_id.value = id_new;
	document.rss.submit();
}

function PreviewNew(id_new)
{
	document.rss.task.value = 'preview_new';
	document.rss.new_id.value = id_new;
	document.rss.new_title.value = document.admin_new.title.value;
	document.rss.new_date.value = document.admin_new.date.value;
	document.rss.new_text.value = document.post.message.value;
	if(document.rss.new_title.value == '' || document.rss.new_date.value == '' || document.rss.new_text.value == '')
	{
		alert('Заполните все поля');
	}
	else
	{
		document.rss.submit();	
	}
}

function UpdateNew(id_new)
{
	document.rss.task.value = 'update_new';
	document.rss.new_id.value = id_new;
	document.rss.new_title.value = document.admin_new.title.value;
	document.rss.new_date.value = document.admin_new.date.value;
	document.rss.new_text.value = document.post.message.value;
	if(document.rss.new_title.value == '' || document.rss.new_date.value == '' || document.rss.new_text.value == '')
	{
		alert('Заполните все поля');
	}
	else
	{
		document.rss.submit();	
	}
}
	
function DeleteNew(id_new)
{
   	if (confirm("Вы, действительно хотите удалить новость?")) 
   	{
		document.rss.task.value = 'delete_new';
		document.rss.new_id.value = id_new;
		document.rss.submit();
	}	
}

function AddNew() {
	document.rss.task.value = 'add_new';
	document.rss.new_id.value = 'no';
	document.rss.submit();
}

function JustNew(id)
{
	document.new_podrobno.id.value = id;
	document.new_podrobno.submit();
}

function SetYearAndMonth(year, month)
{
	document.rss.new_year.value = year;
	document.rss.new_month.value = month;
	document.rss.submit();
}

function SetNewsState(state)
{
	document.rss.news_state.value = state;
	document.rss.submit();		
}
//КОНЕЦ ФУНКЦИЙ ДЛЯ СТРАНИЦ шаблона NEW

function GoTo(my_url)
{
	window.location.href=my_url;
}