var childNumCorrector = 2;
var childNumFirst = 1;
var browser = "other";
var t;
var element;
var factHeight;
var step;
var HelpNode;
var act_cname = "CNAME";
if (navigator.appName == "Microsoft Internet Explorer") {
	childNumCorrector = 1;
	childNumFirst = 0;
	browser = "IE";
}
var isOpera8 = navigator.userAgent.search("Opera 8");
if (isOpera8>-1) {
	childNumCorrector = 2;
	childNumFirst = 1;
	browser = "other";
}

function offsetPosition(element) {
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
    } while (element = element.offsetParent);
    return [offsetLeft, offsetTop];
}

function showHelp(oThis, type) {
	pos = offsetPosition(oThis);
	document.getElementById("Help").style.display = "block";
	document.getElementById("Help").style.background ="url(/img/"+type+"Help.gif) center top no-repeat";
	if (type == "min_or_exp") {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 46;
		document.getElementById("Help").style.width = "110px";
	}
	else if (type == "min_or_exp_left") {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 86;
		document.getElementById("Help").style.width = "110px";
	}
	else if (type == "mailto_exp") {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 86;
		document.getElementById("Help").style.width = "110px";
	}
	else if (type == "ytboo_exp") {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 86;
		document.getElementById("Help").style.width = "110px";
	}
	else if (type == "rating_exp") {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 40;
		document.getElementById("Help").style.width = "110px";
	}
	else {
		topPosition = pos[1] - 20;
		leftPosition = pos[0] - 32;
		document.getElementById("Help").style.width = "82px";
	}
	document.getElementById("Help").style.top = topPosition +"px";
	document.getElementById("Help").style.left = leftPosition +"px";
}

function clearHelp() {
	document.getElementById("Help").style.display = "none";
}

function decreaseHeight() {
	newHeight = element.offsetHeight;
	newHeight = newHeight - step;
	if (newHeight < 0) newHeight = 0;
	element.style.height = newHeight + "px";
	t = setTimeout("decreaseHeight()", 3);
	if (newHeight == 0) {
		window.clearTimeout(t);
		/*clearHelp();
		HelpNode.onmouseover = showHelp(HelpNode, "min_or_exp");*/
	}
}

function increaseHeight(start) {
	if (start) newHeight = start; else newHeight = element.offsetHeight;
	//alert(element.offsetHeight);
	newHeight = newHeight + step;
	if (newHeight > factHeight) newHeight = factHeight;
	element.style.height = newHeight + "px";
	t = setTimeout("increaseHeight()", 3);
	if (newHeight == factHeight) {
		window.clearTimeout(t);
		/*clearHelp();
		HelpNode.onmouseover = showHelp(HelpNode, "min_or_exp");*/
	}
}

function minimize() {
	/*topNode = oThis.parentNode.parentNode.parentNode;
	element = topNode.childNodes[childNumFirst + childNumCorrector];*/
	if (element.style.height != "0px") {
		element.style.overflow = "hidden";
		step = parseInt(element.offsetHeight/5);
		decreaseHeight();
	}
}

function expand() {
	/*topNode = oThis.parentNode.parentNode.parentNode;
	element = topNode.childNodes[childNumFirst + childNumCorrector];*/
	if (element.style.height == "0px") {
		element.style.overflow = "hidden";
		element.style.height = "auto";
		element.style.display == "";
		factHeight = element.offsetHeight;
		element.style.height = "0px";
		step = parseInt(factHeight/5);
		increaseHeight(0);
	}
}
function rating_exp(oThis) {
	HelpNode = oThis;
	topNode = oThis.parentNode.parentNode.parentNode;
	element = topNode.childNodes[childNumFirst + childNumCorrector];
	if (element.style.height != "0px") minimize();
	else expand();
}
function min_or_exp(oThis) {
	HelpNode = oThis;
	topNode = oThis.parentNode.parentNode.parentNode;
	element = topNode.childNodes[childNumFirst + childNumCorrector];
	if (element.style.height != "0px") minimize();
	else expand();
}
function remove(oThis) {
	topNode = oThis.parentNode.parentNode.parentNode;
	arNodes = topNode.childNodes[childNumFirst + childNumCorrector].childNodes[childNumFirst].childNodes;
	for (i=childNumFirst+childNumCorrector; i<arNodes.length; i=i+childNumCorrector) {
		if(arNodes[i].className != "hide") actNode = arNodes[i];
	}
	actNode.className = "hide";
	element = topNode.childNodes[childNumFirst + childNumCorrector];
	if (element.style.height != "0px") element.style.height = "auto";
}

function add(oThis, type) {
	topNode = oThis.parentNode.parentNode.parentNode;
	arNodes = topNode.childNodes[childNumFirst + childNumCorrector].childNodes[childNumFirst].childNodes;
	for (i=childNumFirst+childNumCorrector; i<arNodes.length; i=i+childNumCorrector) {
		if(arNodes[i].className == "hide") {
			actNode = arNodes[i];
			break;
		}
	}
	if (type == "news" && i == childNumFirst + childNumCorrector)
		actNode.className = "first";
	else
		actNode.className = "";
	element = topNode.childNodes[childNumFirst + childNumCorrector];
	if (element.style.height != "0px") element.style.height = "auto";
}

function showImg(oThis, picSrc, picHref) {
	topNode = oThis.parentNode.parentNode;
	topNode.childNodes[childNumFirst].childNodes[childNumFirst].style.backgroundColor = "#034b82";
	topNode.childNodes[childNumFirst + childNumCorrector].childNodes[childNumFirst].style.backgroundColor = "#034b82";
	topNode.childNodes[childNumFirst + childNumCorrector*2].childNodes[childNumFirst].style.backgroundColor = "#034b82";
	oThis.style.backgroundColor = "#d43c29";
	document.getElementById("newsImg").src = picSrc;
	document.getElementById("newsImg").parentNode.href = picHref;
}
function bw(oThis, pic) {
	oThis.src = pic;
}
function search(oThis, type) {
	if (oThis.value == "" && type == "blur") {
		oThis.value = "поиск по сайту";
		oThis.style.color = "#b2b2b2";
	}
	if (oThis.value == "поиск по сайту" && type == "focus") {
		oThis.value = "";
		oThis.style.color = "#414141";
	}
}




var xmlHttp = createXMLHttpObj();

function createXMLHttpObj()
{
	var xmlHttp;
	if (window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	else
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	if (!xmlHttp)
		alert("Ошибка создания XMLHttpRequest");
	else
		return xmlHttp;
}

function changeBanner() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		xmlHttp.open("GET", "/banner.php", true);
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	else {
		 setTimeout("changeBanner()", 5000);
	}
}

function handleServerResponse() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			document.getElementById("banner").innerHTML = xmlHttp.responseText;
		}
		setTimeout("changeBanner()", 5000);
	}
}
var type;
function show_form(section) {
	document.getElementById("form").style.display="block";
	document.getElementById("form_content").innerHTML = "Загрузка...";
	document.getElementById("form").style.height=document.getElementById("middle_part").offsetHeight;
	if (section) type = section;
	//alert(type);
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		if (type != "corupt") {
			formData = "SECTION="+type;
			xmlHttp.open("GET", "/blog/form.php?"+formData, true);
			xmlHttp.onreadystatechange = handleServerResponse_form;
			xmlHttp.send(null);
		}
		else {
			xmlHttp.open("GET", "/blog/corupt_form.php", true);
			xmlHttp.onreadystatechange = handleServerResponse_form;
			xmlHttp.send(null);
		}
	}
	else {
		 setTimeout("show_form()", 1000);
	}
}
function close_form() {
	document.getElementById("form").style.display="none";
}
function chek_form() {
  errorDis = "<span>";
  if (document.blog_form.REGION.value == "Регион") { errorDis += "Выберите регион<br />"; }
  if (act_cname == "CNAME")
	  if (document.blog_form.CNAME.value == "Название банка") { errorDis += "Укажите банк<br />"; }
  if (act_cname == "CNAME2")
	  if (document.blog_form.CNAME2.value == "Введите название") { errorDis += "Укажите банк<br />"; }
  if (document.blog_form.AGE.value == "Возраст") { errorDis += "Укажите возраст<br />"; }
  if (document.blog_form.SEX.value == "Пол") { errorDis += "Укажите пол<br />"; }
  if (document.blog_form.ACT.value == "Ваш случай" || document.blog_form.ACT.value=="") { errorDis += "Вы не указали ваш случай<br />"; }
  if (errorDis != "<span>") document.getElementById("error").innerHTML = errorDis+"</span>";
  else {
   document.blog_form.style.display = "none";
   document.getElementById("error").innerHTML = "Загрузка...";
   submit_form();
  }
}

function chek_corupt_form() {
	  errorDis = "<span>";
	  if (document.corupt_form.name.value == "Ваше имя" || document.corupt_form.name.value == "") { errorDis += "Введите ваше имя<br />"; }
	  if (document.corupt_form.email.value == "E-mail" || document.corupt_form.email.value == "") { errorDis += "Введите ваш e-mail<br />"; }
	  if (document.corupt_form.ACT.value == "Ваш случай" || document.corupt_form.ACT.value=="") { errorDis += "Вы не указали ваш случай<br />"; }
	  if (errorDis != "<span>") document.getElementById("error").innerHTML = errorDis+"</span>";
	  else {
	   document.corupt_form.style.display = "none";
	   document.getElementById("error").innerHTML = "Загрузка...";
	   submit_corupt_form();
	  }
	}
function select_comp() {
	if (document.blog_form.CNAME.value == "Ваш вариант") {
		document.getElementById('CNAME2').style.display='inline';
		act_cname = "CNAME2";
	}
	else {
		document.getElementById('CNAME2').style.display='none';
		document.blog_form.CNAME2.value = "Введите название";
		act_cname = "CNAME";
	}
	//alert(ACT_CNAME);
}
function submit_form() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		if (act_cname == "CNAME") 
			cname_text = "&CNAME="+document.blog_form.CNAME.value;
		else
			cname_text = "&CNAME2="+document.blog_form.CNAME2.value;
	    formData = "REGION="+document.blog_form.REGION.value+cname_text+
	    "&AGE="+document.blog_form.AGE.value+
	    "&SEX="+document.blog_form.SEX.value+"&ACT="+document.blog_form.ACT.value+"&SECTION="+document.blog_form.SECTION.value;
		xmlHttp.open("GET", "/blog/submit_form.php?"+formData, true);
		xmlHttp.onreadystatechange = handleServerResponse_form;
		xmlHttp.send(null);
	}
	else {
		 setTimeout("submit_form()", 1000);
	}
}
function submit_corupt_form() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    formData = "NAME="+document.corupt_form.name.value+"&EMAIL="+document.corupt_form.email.value+
    "&ACT="+document.corupt_form.ACT.value;
		xmlHttp.open("GET", "/blog/submit_corupt_form.php?"+formData, true);
		xmlHttp.onreadystatechange = handleServerResponse_form;
		xmlHttp.send(null);
	}
	else {
		 setTimeout("submit_corupt_form()", 1000);
	}
}
function handleServerResponse_form() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			document.getElementById("form_content").innerHTML = xmlHttp.responseText;
		}
	}
}
margin = 0;
function scroll_down() {
  tagsHeight = 0 - document.getElementById("tags").offsetHeight + 112;
  if(margin > tagsHeight) margin = margin-3;
  document.getElementById("tags").style.marginTop = margin+"px";
  s = setTimeout("scroll_down()", 30);
}
function scroll_up() {
  if(margin < 0) margin = margin+3;
  document.getElementById("tags").style.marginTop = margin+"px";
  s = setTimeout("scroll_up()", 30);
}
function scroll_break() {
  window.clearTimeout(s);
}