function ShowHideLoadingForm(show)
{
	if (show == true)
		{
			LoadingDiv = document.getElementById("loading_form");
			LoadingDiv.style.visibility = "visible";
		}
	else
		{
			LoadingDiv = document.getElementById("loading_form");
			LoadingDiv.style.visibility = "hidden";
		}
}

function setCookie(cookieName, cookieContent, cookieExpireTime)
{
  if(cookieExpireTime>0)
    {
      var expDate=new Date();
      expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60);
      var expires=expDate.toGMTString();
      document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"; expires="+expires;
    }
  else
    document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"";
}

function getCookie(cookieName)
{
  var ourCookie=document.cookie;
  if(!ourCookie || ourCookie=="") return "";
  ourCookie=ourCookie.split(";");
  var i=0;
  var Cookie;
  while(i<ourCookie.length)
    {
      Cookie=ourCookie[i].split("=")[0];
      if(Cookie.charAt(0)==" ")
        Cookie=Cookie.substring(1);
      if(Cookie==cookieName)
        return unescape(ourCookie[i].split("=")[1]);
      i++
    }
  return "";
}

function delCookie(cookieName)
{
  setCookie(cookieName, "0", -24*3);
}

function HookKeyPress(e)
{
  if (MenuIsDroped == true)
    {
      kk = navigator.appName == 'Netscape' ? e.which : e.keyCode;
      if (kk == 13) ArticlesSearch(CurAjaxMode, CurAjaxBrandId);
    }
}

// проверка на совместимый браузер
function CheckBrowser()
{
  if(!navigator.cookieEnabled)
    window.alert("Для правильной работы сайта, вам нужно включить cookies!");
}

// это относится к магазину

var PrevElemId = ""; /* id предыдущей строчки в левом меню магазина */
var MarketCurSubCatId = 0; /* id текущей подкатегории магазина */
var MarketSearchParamStr = ""; /* параметры для поиска данных */
var MarketStartPos = 0;
var MarketSpecCurSubCatId = "";
var prev_block_id = "";

var BrowserId = 2;
var MenuIsDroped = false;

var CurAjaxMode;
var CurAjaxBrandId;

if (navigator.appName == "Netscape") BrowserId = 1;
else if  (navigator.appName == "Microsoft Internet Explorer") BrowserId = 2;
else BrowserId = 3;

function art_submenu(elem)
{
  if (document.getElementById(elem).style.display != "block")
    {
      document.getElementById(elem).style.display = "block";
			setCookie("bigwall_articles_"+elem, "1", 24*30);
    }
  else
    {
      document.getElementById(elem).style.display = "none";
			setCookie("bigwall_articles_"+elem, "0", 24*30);
    }
}

function lm_submenu(elem)
{
	if (document.getElementById(elem))
		{
			if (document.getElementById(elem).style.display != "block")
				{
					document.getElementById(elem).style.display = "block";
					setCookie("bigwall_market_leftmenu_"+elem, "1", 24*30);
				}
			else
				{
					document.getElementById(elem).style.display = "none";
					setCookie("bigwall_market_leftmenu_"+elem, "0", 24*30);
				}
		}
}

function lm_showall(mode)
{
	switch(mode)
		{
			case "catalog":
				div_id = "left_market_catalog_div";
			break;
			case "brands":
				div_id = "left_market_brands_div";
			break;
		}
  c = document.getElementById(div_id);
  if (c)
    {
      divs = c.getElementsByTagName("div");
      for (i=0; i<divs.length; i++)
        {
          elem_id = divs[i].id;
          document.getElementById(elem_id).style.display = "block";
          setCookie("bigwall_market_leftmenu_"+elem_id, "1", 24*30);
        }
    }
}

function lm_hideall(mode)
{
	switch(mode)
		{
			case "catalog":
				div_id = "left_market_catalog_div";
			break;
			case "brands":
				div_id = "left_market_brands_div";
			break;
		}	
  c = document.getElementById(div_id);
  if (c)
    {
      divs = c.getElementsByTagName("div");
      for (i=0; i<divs.length; i++)
        {
          elem_id = divs[i].id;
          document.getElementById(elem_id).style.display = "none";
          setCookie("bigwall_market_leftmenu_"+elem_id, "0", 24*30);
        }
    }
}

function ShowLeftMarketDiv(mode)
{
	switch(mode)
		{
			case "catalog":
				c = document.getElementById("left_market_brands_div");
				c.style.position = "absolute";
				c = document.getElementById("left_market_catalog_div");
				c.style.position = "static";				
			break;
			case "brands":
				c = document.getElementById("left_market_brands_div");
				c.style.position = "static";
				c = document.getElementById("left_market_catalog_div");
				c.style.position = "absolute";				
			break;
		}
}

function SetDefaultMarketLeftMenu()
{
  c = document.getElementById("left_market_catalog_div");
  if (c)
    {
      divs = c.getElementsByTagName("div");
      for (i=0; i<divs.length; i++)
        {
          elem_id = divs[i].id;
          cookieVal = getCookie("bigwall_market_leftmenu_"+elem_id);
          if (cookieVal == 1)
            document.getElementById(elem_id).style.display = "block";
          else
            {
              _links = divs[i].getElementsByTagName("a");
              for (j=0; j<_links.length; j++)
                if (_links[j].id == MarketSpecCurSubCatId)
                  lm_submenu(elem_id);
            }
        }
    }
  c = document.getElementById("left_market_brands_div");
  if (c)
    {
      divs = c.getElementsByTagName("div");
      for (i=0; i<divs.length; i++)
        {
          elem_id = divs[i].id;
          cookieVal = getCookie("bigwall_market_leftmenu_"+elem_id);
          if (cookieVal == 1)
            document.getElementById(elem_id).style.display = "block";
          else
            {
              _links = divs[i].getElementsByTagName("a");
              for (j=0; j<_links.length; j++)
                if (_links[j].id == MarketSpecCurSubCatId)
                  lm_submenu(elem_id);
            }
        }
    }
}

function SetDefaultArticles()
{
  c = document.getElementById("ArticlesDiv");
  if (c)
    {
      divs = c.getElementsByTagName("div");
      for (i=0; i<divs.length; i++)
        {
          elem_id = divs[i].id;
          cookieVal = getCookie("bigwall_articles_"+elem_id);
          if (cookieVal == 1)
            document.getElementById(elem_id).style.display = "block";
        }
    }
}

function ProcessPage()
{
  if (http_request.readyState == 4 )
    {
      if (http_request.status == 200)
        {
          MarketContent = http_request.responseText;
          if (MarketContent != "")
            {
              ConfBlock = document.getElementById("market_data");
              ConfBlock.innerHTML = MarketContent;
							ShowHideLoadingForm(false);
            }
					else
						{
							ShowHideLoadingForm(false);
						}
        }
      else
				{
        	window.alert("Возникли проблемы при загрузке данных!\nСлужебная информация: "+http_request.statusText);
					ShowHideLoadingForm(false);
				}
    }
}

function LoadDataById(elem_id, mode, my_id)
{
  if (window.XMLHttpRequest)
    { // IE 7, Mozilla, Safari, ...
      http_request = new XMLHttpRequest();
      //http_request.overrideMimeType('text/xml');
    }
  else if (window.ActiveXObject)
    { // IE 5,6
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
  MarketContent = "";
  /* выделяем тек. строку */
  if (elem_id != "" && elem_id != PrevElemId)
    {
      document.getElementById(elem_id).className = "catalog_selected";
      if (PrevElemId != "")
        document.getElementById(PrevElemId).className = "";
      PrevElemId = elem_id;
    }
	CurAjaxMode = mode;
	CurAjaxBrandId = 0;
  if (mode == "list")
    {
      if (my_id != MarketCurSubCatId)
        {
          MarketSearchParamStr = "";
          MarketStartPos = 0;
        }
      MarketCurSubCatId = my_id;
    }
  if (mode == "detail")
    MarketSpecCurSubCatId = elem_id;
  http_request.onreadystatechange = ProcessPage;
  http_request.open("GET", "ajax.php?id="+my_id+"&mode="+mode+"&startpos="+MarketStartPos+MarketSearchParamStr, true);
	ShowHideLoadingForm(true);
  http_request.send(null);
}

function LoadDataByBrand(elem_id, mode, my_id, brand_id)
{
  if (window.XMLHttpRequest)
    { // Mozilla, Safari, ...
      http_request = new XMLHttpRequest();
      //http_request.overrideMimeType('text/xml');
    }
  else if (window.ActiveXObject)
    { // IE
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
  MarketContent = "";
  /* выделяем тек. строку */
  if (elem_id != "" && elem_id != PrevElemId)
    {
      document.getElementById(elem_id).className = "catalog_selected";
      if (PrevElemId != "")
        document.getElementById(PrevElemId).className = "";
      PrevElemId = elem_id;
    }
	CurAjaxMode = mode;
	CurAjaxBrandId = brand_id;		
  if (mode == "list_by_brand")
    {
      if (my_id != MarketCurSubCatId)
        {
          MarketSearchParamStr = "";
          MarketStartPos = 0;
        }
      MarketCurSubCatId = my_id;
    }
  if (mode == "detail_by_brand")
    MarketSpecCurSubCatId = elem_id;
  http_request.onreadystatechange = ProcessPage;
  http_request.open("GET", "ajax.php?id="+my_id+"&brand_id="+brand_id+"&mode="+mode+"&startpos="+MarketStartPos+MarketSearchParamStr, true);
	ShowHideLoadingForm(true);
  http_request.send(null);
}

function ZoomMarketImage(id)
{
  fname = document.getElementById("ImgPath_"+id).value;
  tit = document.getElementById("ImgName_"+id).value;
  width = document.getElementById("ImgWidth_"+id).value;
  height = document.getElementById("ImgHeight_"+id).value;

  img1 = new Image(width, height);
  img1.src = fname;
  outf="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>"+tit+"</title><style>body{margin:0px; padding:0px}</style></head>"
  +"<body leftmargin=0 topmargin=0><a href=\"javascript:void(0)\" onclick=\"self.close();\"><img src=\""+fname+"\" border=0 alt=\"\"></a></body></html>";
  if(img1.width!=0)
    {
      iwin=self.open("", "", "width="+(img1.width)+",height="+(img1.height)+",top=0,left=0,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes,alwaysRaised=yes,dialog=yes");
      iwin.document.write(outf);
      iwin.focus();
    }
  img1 = null;
}

function ZoomMarketAdvImage(num, id)
{
  fname = document.getElementById("AdvImg"+num+"Path_"+id).value;
  tit = document.getElementById("AdvImg"+num+"Name_"+id).value;
  width = document.getElementById("AdvImg"+num+"Width_"+id).value;
  height = document.getElementById("AdvImg"+num+"Height_"+id).value;

  img1 = new Image(width, height);
  img1.src = fname;
  outf="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>"+tit+"</title><style>body{margin:0px; padding:0px}</style></head>"
  +"<body leftmargin=0 topmargin=0><a href=\"javascript:void(0)\" onclick=\"self.close();\"><img src=\""+fname+"\" border=0 alt=\"\"></a></body></html>";
  if(img1.width!=0)
    {
      iwin=self.open("", "", "width="+(img1.width)+",height="+(img1.height)+",top=0,left=0,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes,alwaysRaised=yes,dialog=yes");
      iwin.document.write(outf);
      iwin.focus();
    }
  img1 = null;
}

function SelectMarketListCell(id)
{
  c = document.getElementById("Market_list_cell_"+id);
  c.style.border = "1px red dotted";
}

function UnSelectMarketListCell(id)
{
  c = document.getElementById("Market_list_cell_"+id);
  c.style.border = "1px white dotted";
}

function isCorrectFloat(s)
{
  if (s == "")
    return true;
  else
    return /^(\d{1,9}|\d{1,9}\.\d{1,2})$/.test(s);
}

function CheckSearchForm()
{
  if (!isCorrectFloat(document.getElementById("begin_price").value))
    {
      window.alert("Начальная цена должна состоять только из цифр и иметь разделяющую точку!\nПосле разделяющей точки должно быть от 1 до 2 цифр!");
      document.getElementById("begin_price").focus();
      return false;
    }
  else if (!isCorrectFloat(document.getElementById("end_price").value))
    {
      window.alert("Конечная цена должна состоять только из цифр и иметь разделяющую точку!\nПосле разделяющей точки должно быть от 1 до 2 цифр!");
      document.getElementById("end_price").focus();
      return false;
    }
  else
    return true;

}

function ArticlesGoToPage(start_pos, mode, brand_id)
{
  MarketStartPos = start_pos;
	switch(mode)
		{
			case "list":
				LoadDataById("", "list", MarketCurSubCatId);
			break;
			case "list_by_brand":
				LoadDataByBrand("", "list_by_brand", MarketCurSubCatId, brand_id);
			break;
		}
}

function ArticlesSearch(mode, brand_id)
{
  if (CheckSearchForm())
    {
      rpp_val = document.getElementById("rpp").value;
      order_val = document.getElementById("order_name").value;
      order_dir_val = document.getElementById("order_dir").value;
      begin_price_val = document.getElementById("begin_price").value;
      end_price_val = document.getElementById("end_price").value;
      insight_val = document.getElementById("in_sight").checked;
      if (document.getElementById("exact_fit"))
        exact_fit_val = document.getElementById("exact_fit").checked;
      else
        exact_fit_val = false;
      /* просматриваем все checkbox's брендов и формируем фильтр */
      brands_list_val = "";
      brands_spec_val = "";
      is_first_brand = true;
      c = document.getElementById("Market_search_brands_tbl");
      if (c) {
        tr = c.getElementsByTagName("tr");
        for (i=0; i<tr.length-1; i++) {
          c = document.getElementById("Market_search_brands_tbl").rows[i].cells[0];
          _input = c.getElementsByTagName("input");
          elem_id = _input[0].id;
          if (document.getElementById(elem_id).checked)
            if (is_first_brand == true) {
              is_first_brand = false;
              brands_list_val = "and (brand_id="+document.getElementById(elem_id).value;
              brands_spec_val = document.getElementById(elem_id).value;
            }
            else {
              brands_list_val = brands_list_val+" or brand_id="+document.getElementById(elem_id).value;
              brands_spec_val = brands_spec_val+","+document.getElementById(elem_id).value;
            }
        }
      }
      if (brands_list_val != "") brands_list_val = brands_list_val + ") ";
      // просматриваем все параметры и формируем фильтр
      param_list_val = "";
      param_spec_val = "";
      is_first_param = true;
      c = document.getElementById("Market_search_params_tbl");
      if (c) {
        tr = c.getElementsByTagName("tr");
        for (i=0; i<tr.length-2; i++) {
          c = document.getElementById("Market_search_params_tbl").rows[i].cells[0];
          _select = c.getElementsByTagName("select");
          elem_id = _select[0].id;
          if (document.getElementById(elem_id).value != 0)
            if (is_first_param == true) {
              is_first_param = false;
              param_list_val = elem_id;
              param_spec_val = document.getElementById(elem_id).value;
            }
            else {
              param_list_val = param_list_val+","+elem_id;
              param_spec_val = param_spec_val+"<:!:>"+document.getElementById(elem_id).value;
            }
        }
      }
      MarketStartPos = 0;
      MarketSearchParamStr = "&rpp="+rpp_val+"&order_name="+order_val+"&order_dir="+order_dir_val+"&begin_price="+begin_price_val+"&end_price="+end_price_val+"&insight="+insight_val+"&brands_list="+brands_list_val+"&brands_spec="+brands_spec_val+"&param_list="+param_list_val+"&param_spec="+param_spec_val+"&exact_fit="+exact_fit_val;
			switch(mode)
				{
					case "list":
						LoadDataById("", "list", MarketCurSubCatId);
					break;
					case "list_by_brand":
						LoadDataByBrand("", "list_by_brand", MarketCurSubCatId, brand_id);
					break;
				}
      MenuIsDroped = false;
    }
}

function ResetSearch(mode, brand_id)
{
  MarketStartPos = 0;
  MarketSearchParamStr = "";
	switch(mode)
		{
			case "list":
				LoadDataById("", "list", MarketCurSubCatId);
			break;
			case "list_by_brand":
				LoadDataByBrand("", "list_by_brand", MarketCurSubCatId, brand_id);
			break;
		}
  MenuIsDroped = false;
}

function SelectAllArticles()
{
  c = document.getElementById("market_list");
  if (c) {
    comp_cb = c.getElementsByTagName("input");
    for (i=0; i<comp_cb.length; i++)
      comp_cb[i].checked = true
  }
}

function CompareArticles()
{
  c = document.getElementById("market_list");
  if (c) {
    comp_cb = c.getElementsByTagName("input");
    id_str = "";
    is_first_art = true;
    for (i=0; i<comp_cb.length; i++) {
      if (comp_cb[i].checked == true)
        {
          _id = comp_cb[i].id;
          // получаем номер товара
          _id = _id.substring(4,_id.length);
          if (is_first_art == true) {
            is_first_art = false;
            id_str = id_str + _id;
          }
          else id_str = id_str + "," + _id;
        }
    }
    if (id_str != "") {
      _width = screen.availWidth;
      _height = screen.availHeight;
      iwin=self.open("compare.php?ids="+id_str, "_blank", "width="+_width+",height="+_height+",top=0,left=0,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
      iwin.resizeTo(_width, _height);
      iwin.focus();
    }
  }
}

function OpenMarketDetailArt(id, cat_id)
{
  // открываем новое окно с описанием товара
  iwin=self.open("index.php?page=market&id="+id+"&mode=detail&elem_id="+cat_id, "_blank", "");
  iwin.focus();
}

function ShowSearchDiv(block_id, link_num)
{
  var DropDownMode = true;
  // смотрим есть ли в блоке данные
  switch(block_id)
    {
      case "Market_search_brands_div":
        c = document.getElementById("Market_search_brands_tbl");
        if (c)
          {
            tr = c.getElementsByTagName("tr");
            if (tr.length == 1) DropDownMode = false;
          }
      break;
      case "Market_search_params_div":
        c = document.getElementById("Market_search_params_tbl");
        if (c)
          {
            tr = c.getElementsByTagName("tr");
            if (tr.length == 1) DropDownMode = false;
          }
      break;
    }
  if (DropDownMode == true)
    {
      // закрываем предыдущий див
      if (prev_block_id != "")
        {
          c = document.getElementById(prev_block_id);
          c.style.left = "-1000px";
          c.style.top = "-1000px";
          c.style.visibility = "hidden";
        }
      c = document.getElementById(block_id);
      // определяем нужную ссылку
      _link = document.getElementById("link_"+link_num);
      mouse_x = getBounds(_link).left;
      mouse_y = getBounds(_link).top;
      c.style.left = mouse_x+"px";
      c.style.top = (mouse_y + 10)+"px";
      c.style.visibility = "visible";
      prev_block_id = block_id;
      MenuIsDroped = true;
    }
}

function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft;
    top += parent.offsetTop;
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function CloseSearchDiv(block_id)
{
  c = document.getElementById(block_id);
  c.style.left = "-1000px";
  c.style.top = "-1000px";
  c.style.visibility = "hidden";
  MenuIsDroped = false;
}

function openBasket()
{
  basketWin = open('modules/market/basket.php','basket', 'height=300, width=600, innerHeight=300, innerWidth=600, status=no, resizable=yes, scrollbars=yes, menubar=no, toolbar=yes, location=no, top=10, left=50');
  basketWin.focus();
}

function AddArticleToBasket(art_id, top_win)
{
  cookieVal = getCookie("bigwall_market_basket");
  if (cookieVal != '' && cookieVal != 'undefined')
    {
      /* проверяем, есть ли такой товар в корзине */
      re = new RegExp(art_id, "g");
      result = cookieVal.match(re);
      if (result == null)
        {
					if (document.getElementById("color_size_select"))
						c_s_s = ":"+document.getElementById("color_size_select").value;
					else
						c_s_s = "";
          cookieVal = cookieVal + "," + art_id + c_s_s;
          /* добавляем товар в корзину */
          setCookie("bigwall_market_basket", cookieVal, 24*30);
          /* наращиваем счетчик товаров в корзине */
          if (top_win == true)
            {
							if (document.getElementById("TotalQuantity")) {
              	OldQuantity = parseInt(document.getElementById("TotalQuantity").innerHTML);
              	OldQuantity = OldQuantity+1;
              	document.getElementById("TotalQuantity").innerHTML = OldQuantity;
							}
            }
          else
            {
              OldQuantity = parseInt(top.window.opener.document.getElementById("TotalQuantity").innerHTML);
              OldQuantity = OldQuantity+1;
              top.window.opener.document.getElementById("TotalQuantity").innerHTML = OldQuantity;
            }
          window.alert("Этот товар успешно добавлен в вашу корзину!");
        }
      else
        window.alert("Этот товар уже есть в вашей корзине!");
    }
  else
    {
			if (document.getElementById("color_size_select"))
				c_s_s = ":"+document.getElementById("color_size_select").value;
			else
				c_s_s = "";
      /* добавляем товар в корзину */
      setCookie("bigwall_market_basket", art_id+c_s_s, 24*30);
      /* наращиваем счетчик товаров в корзине */
      if (top_win == true)
        {
					if (document.getElementById("TotalQuantity")) {
          	OldQuantity = parseInt(document.getElementById("TotalQuantity").innerHTML);
          	OldQuantity = OldQuantity+1;
          	document.getElementById("TotalQuantity").innerHTML = OldQuantity;
					}
        }
      else
        {
          OldQuantity = parseInt(top.window.opener.document.getElementById("TotalQuantity").innerHTML);
          OldQuantity = OldQuantity+1;
          top.window.opener.document.getElementById("TotalQuantity").innerHTML = OldQuantity;
        }
      window.alert("Этот товар успешно добавлен в вашу корзину!");
    }
}

function openBrand(brand_id)
{
  brandWin = open('modules/market/brands.php?brand_id='+brand_id,'basket', 'height=400, width=600, innerHeight=400, innerWidth=600, status=no, resizable=yes, scrollbars=yes, menubar=no, toolbar=no, location=no, top=10, left=50');
  brandWin.focus();
}

function ShowAddArticlePreview()
{
	oEditor = FCKeditorAPI.GetInstance('TitleEditor');
	_title = oEditor.EditorDocument.body.innerHTML;
	oEditor = FCKeditorAPI.GetInstance('AnnouncEditor');
	_announc = oEditor.EditorDocument.body.innerHTML;
	oEditor = FCKeditorAPI.GetInstance('TextEditor');
	_body = oEditor.EditorDocument.body.innerHTML;
  outf="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>Предварительный просмотр статьи</title><style>body{margin:0px; padding:0px}</style></head>"
  +"<body leftmargin=0 topmargin=0><a href='javascript:void(0);' onclick='self.close();'>Закрыть окно</a><br><br><h2>"+_title+"</h2><h2>"+_announc+"</h2>"+_body+"<br><br><br><a href='javascript:void(0);' onclick='self.close();'>Закрыть окно</a></body></html>";
  iwin=self.open("", "", "top=0, left=0, toolbar=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, modal=no, alwaysRaised=no, dialog=no");
  iwin.document.write(outf);
  iwin.focus();
}

function ShowAddNewsPreview()
{
	oEditor = FCKeditorAPI.GetInstance('TitleEditor');
	_title = oEditor.EditorDocument.body.innerHTML;
	oEditor = FCKeditorAPI.GetInstance('AnnouncEditor');
	_announc = oEditor.EditorDocument.body.innerHTML;
	oEditor = FCKeditorAPI.GetInstance('TextEditor');
	_body = oEditor.EditorDocument.body.innerHTML;
  outf="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>Предварительный просмотр новости</title><style>body{margin:0px; padding:0px}</style></head>"
  +"<body leftmargin=0 topmargin=0><a href='javascript:void(0);' onclick='self.close();'>Закрыть окно</a><br><br><h2>"+_title+"</h2><h2>"+_announc+"</h2>"+_body+"<br><br><br><a href='javascript:void(0);' onclick='self.close();'>Закрыть окно</a></body></html>";
  iwin=self.open("", "", "top=0, left=0, toolbar=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, modal=no, alwaysRaised=no, dialog=no");
  iwin.document.write(outf);
  iwin.focus();
}

function DeleteComment()
{
	if (confirm("Вы действительно желаете удалить этот комментарий?"))
		return true;
	else
		return false;
}

function CommentValid()
{
	if (document.getElementById('comment_body').value == "")
		{
			alert('Вы должны ввести отзыв!');
			document.getElementById('comment_body').focus();
			return false;
		}
	else
		return true;
}

function FillStars(star)
{
	for(i=1; i<=star; i++)
		{
			document.getElementById('vote_'+i).src = '/images/vote_star_active.gif';
		}
}

function ClearStars()
{
	for(i=1; i<=5; i++)
		{
			document.getElementById('vote_'+i).src = '/images/vote_star_disable.gif';
		}
}

//--------------------------------------------------------------------------------------------------------
//new
var lastopenedelem='';
function open_menu(elem, plussrc, minusrc){
	if (plussrc=='')
		plussrc='plus';
	if (minusrc=='')
		minusrc='minus';
	var elem1;
	var elem1_sub;
	var elem1_img;
	if (lastopenedelem!='' && lastopenedelem!=elem){
		elem1=document.getElementById(lastopenedelem);
		elem1_sub=document.getElementById(lastopenedelem+'_sub');
		elem1_img=document.getElementById(lastopenedelem+'_img');
		if (elem1 && elem1_sub){
			elem1_sub.style.display="none";
			elem1.className="menu_first_level_normal";
			if (elem1_img)
				elem1_img.src='images/'+plussrc+'.gif';
		}
	}
	elem1=document.getElementById(elem);
	elem1_sub=document.getElementById(elem+'_sub');
	elem1_img=document.getElementById(elem+'_img');
	if (elem1 && elem1_sub){
		if (elem1_sub.style.display!="block"){
			elem1_sub.style.display="block";
			elem1.className="menu_first_level_active";
			if (elem1_img)
				elem1_img.src='images/'+minusrc+'.gif';
			//writeCookie(elem, "1", 24*30);
		}
		else {
			elem1_sub.style.display="none";
			elem1.className="menu_first_level_normal";
			if (elem1_img)
				elem1_img.src='images/'+plussrc+'.gif';
			//writeCookie(elem, "0", 24*30);
		}
		lastopenedelem=elem;
	}
}
