$(document).ready(function() {
  if(document.body.clientWidth <= 1024) {
        //window.scrollTo(180,0);
      document.getElementById('searchstring').size = document.getElementById('searchstring').size - 20;
    }
    else {
        if(document.getElementById('catid95')) {
            document.getElementById('searchstring').size = 80;
        }
        else {
            document.getElementById('searchstring').size = 80;
        }
  }
  var old_size = document.body.clientWidth;
  if(document.getElementsByClassName == undefined) { 
   document.getElementsByClassName = function(cl) { 
      var retnode = []; 
      var myclass = new RegExp('\\b'+cl+'\\b'); 
      var elem = this.getElementsByTagName('*'); 
      for (var i = 0; i < elem.length; i++) { 
         var classes = elem[i].className; 
         if (myclass.test(classes)) { 
            retnode.push(elem[i]); 
         } 
      } 
      return retnode; 
   } 
  };
  var buys = document.getElementsByClassName('delayed');
  if (buys.length) for (var i=0; i<buys.length; i++) buys[i].style.visibility = 'visible';
  window.onresize = function () {
    if(document.body.clientWidth <= 1024 && document.getElementById('searchstring').size <= 80) {
      document.getElementById('searchstring').size = (old_size > document.body.clientWidth?document.getElementById('searchstring').size - 10:document.getElementById('searchstring').size + 10);

    }
    else {
        if(document.getElementById('catid95')) {
            document.getElementById('searchstring').size = 80;
        }
        else {
            document.getElementById('searchstring').size = 80;
        }
    }
    old_size = document.body.clientWidth;
  }
});

    function check_search(type) {
        if(type == 1) {

            document.getElementById("set_inside_id").checked = '';
        }
        else {
            document.getElementById("set_inside").checked = '';

        }
    }


    function openWindowCart(status) {
        if(status) {
            $("#close_window_cart").css({display:'none'});
            $(".window_cart").css({height:'80px'});
            $("#open_window_cart").css({display:'block'});
        }
        else {
            $("#close_window_cart").css({display:'block'});
            $(".window_cart").css({height:'16px'});
            $("#open_window_cart").css({display:'none'});
        }
    }
    var cart_led = 0;
    function setWindowCart(items, shown) {
        var string = desc = string2 = '';
        if(items == 1) {
            desc += " товар";
        }
        else if(items > 1 && items <= 4) {
            desc += " товара";
        }
        else if(items > 4) {
            desc += " товаров";
        }
        string = "<a href=\"#\" onclick=\"javascript:openWindowCart(true);return false;\" id=\"status_window_cart\">[+]</a>";
        string += " <b>В вашей корзине <span id=\"close_count_product_cart\" style=\"color: red;\">"+items;
        string += desc+"</span></b>";
        string2 = "<a href=\"#\" onclick=\"javascript:openWindowCart(false);return false;\" id=\"status_window_cart\">[-]</a>";
        string2 += " <b>В вашей корзине <span id=\"close_count_product_cart\" style=\"color: red;\">"+items;
        string2 += desc+"</span></b>";
        $("#close_window_cart").css({'background-color': '#FFFF80'});
        $("#open_window_cart").css({'background-color': '#FFFF80'});
        var cart_win = window.setInterval(function(){
            cart_led++;
            if(cart_led%2) {
                $("#close_window_cart").css({'background-color': '#FFFF80'});
                $("#open_window_cart").css({'background-color': '#FFFF80'});
            }
            else {
                $("#close_window_cart").css({'background-color': '#E0E0E0'});
                $("#open_window_cart").css({'background-color': '#E0E0E0'});
            }
            if(cart_led >= 6) {
                clearInterval(cart_win);
                $("#close_window_cart").css({'background-color': '#E0E0E0'});
                $("#open_window_cart").css({'background-color': '#E0E0E0'});
            }
        }, 2000);
        $("#close_window_cart").html(string);
        $("#window_cart_open_count").html(string2);
        $("#open_count_cart_sum").html(shown);
    }

	function open_window(link,w,h) //opens new window
	{
		var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'newWin',win);
		newWin.focus();
	}

    function hidden_desc(evan) {
        var name = new String();
        var element = document.getElementsByTagName('a');
          for(var i=0; i<element.length; i++) {
              if(element[i].id.indexOf('wrapp_') != -1) {
                  name = element[i].id.replace(/(wrapp_|_hidden)/g,'');
                  if(element[i].id == evan.id) {
                      document.getElementById('wrapp_'+name+'_block').style.display = 'block';
                      document.getElementById(element[i].id).className = 'active';
                  }
                  else {
                      document.getElementById('wrapp_'+name+'_block').style.display = 'none';
                      document.getElementById(element[i].id).className = '';
                  }
              }
          }
    }


    function show_hidden_desc(type) {
        if(type == 1) {
            document.getElementById('wrapp_description_hidden').onclick();
        }
        else {
            var element = document.getElementsByTagName('a');
            for(var i=0; i<element.length; i++) {
              if(element[i].id.indexOf('wrapp_parent') != -1) {
                      document.getElementById(element[i].id).onclick();
                      break;
              }
          }
        }
    }
    function show_hidden_red_desc(type, productID) {
        var link = document.getElementById("get_link_detal_"+productID);
        if(type == 1) {
            window.location.assign(link+'#description_show');
        }
        else {
            window.location.assign(link+'#description_parent_show');
        }
    }
    function get_parent_check_detail() {
        var hash = window.location.hash.toString();
        if(hash == '#description_parent_show') {
            show_hidden_desc(2);
        }
    }
    function dom_lood() {
        get_parent_check_detail();
        set_order_method_ukr(2, 6);
    }

	function open_printable_version(link) //opens new window
	{
		var win = "menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'perintableWin',win);
		newWin.focus();
	}

	function confirmDelete(id, ask, url) //confirm order delete
	{
		temp = window.confirm(ask);
		if (temp) //delete
		{
			window.location=url+id;
		}
	}

    function remove_cookie(name)
     {
            var d=name+"=";
                d+=";expires="+(new Date()).toGMTString();
            document.cookie=d;
	}

	function set_cookie(name, value, expires)
         {
           if (!expires)
            {
               expires = new Date();
            }

        document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=";
	}

	function edit_cookie(name, value)
         {

       expires = new Date();
           expires.setTime(expires.getTime() + (1000 * 86400 * 365));

       if(get_cookie(name))
            {

          remove_cookie(name);

        set_cookie(name, value, expires);
            }
        else
         set_cookie(name, value, expires);
	}

    function get_cookie(name)
         {
            cookie_name   = name + "=";
            cookie_length = document.cookie.length;
            cookie_begin  = 0;

         while (cookie_begin < cookie_length)
              {
                 value_begin = cookie_begin + cookie_name.length;

          if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
                   {
                     var value_end = document.cookie.indexOf (";", value_begin);

               if (value_end == -1)
                        {
                           value_end = cookie_length;
                         }

              return unescape(document.cookie.substring(value_begin, value_end));
                   }

           cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;

          if (cookie_begin == 0)
                   {
                     break;
                   }
              }
               return '';
	}

function search_cookie(name)
{
	var string_cookie  = document.cookie.split(';');
	var search_value = new Array();
	var string = new String;

	for(var i=0; i<string_cookie.length; i++)
	{
		if(string_cookie[i])
		{
			if(string_cookie[i].indexOf(name) > -1)
			{
				var search_value = string_cookie[i].split("=");
				for(s=0;s<search_value.length;s++)
				{
					if(search_value[s])
					{
						value = search_value[s+1];
						if(value)
						{
							string += value + ' ';
						}
					}
				}
			}
		}
	}
	return string;
}

      function clear_comparison()
       {
         var string = search_cookie("comparison_productID_").split(' ');

          for(var i=0; i<string.length; i++)
               {
                  if(string[i])
                   {
                     remove_cookie("comparison_productID_"+string[i]);
                   }

           }

       }

      function getPricPlan(summ,dtotal, productID) {
          if(summ && dtotal) {
              if(document.getElementById("price_plan_total")) {
                  document.getElementById("price_plan_total").innerHTML = summ;
              }
              summ = Math.ceil(summ / dtotal);

          }
          document.getElementById("price_plan").innerHTML = summ;
          document.getElementById("link_pay_cred").innerHTML = "<input type=\"button\" style=\"background:#009300; color: black;\" name=\"get_credit\" onclick=\"javascript:bay_cart_ip("+productID+");\" id=\"link_pay_cred\" value=\"Оформить заявку на кредит\" />";
      }

      function change_form(form) {
    if(form && form.value) {
        var id = form.value;
    }
    else if(form) {
        var id = form;
    }
    document.getElementById("order_form").innerHTML = document.getElementById("order_form_"+id).innerHTML;
}


function clear_form() {
    window.location = "index.php?lodging=yes&clear_form=yes";
}

function check_comparison(productID)
{
	name = "comparison_productID_"+productID;
	var element = document.getElementById('ch_' + productID);
	if(get_cookie(name))
	{
		element.checked = true;
	}
}
      function selectMethodShip(id) {
          var hide_ship = document.getElementById('hide_ship');
          var hide_city = document.getElementById('hide_city');
          var hide_address = document.getElementById('hide_address');
          if(id == 2) {
              hide_ship.style.display = 'none';
              //hide_city.value = '---';
              //hide_address.value = '---';
          }
          else {
              hide_ship.style.display = 'block';
              //hide_city.value = '';
              //hide_address.value = '';
          }
      }

      function selectMethodPay(id) {
          if(id == 2 || id == 2) {
              document.getElementById("hide_pay").style.display ='none';
          }
          else if(id == 1) {
              document.getElementById("hide_pay").style.display = 'block';
          }
      }

      function set_order_method_ukr(id, sid) {
          var ukr_nal = document.getElementById('nal');
          var ukr_spd = document.getElementById('spd');
          if(ukr_nal && ukr_spd) {
              if(!id) {
                ukr_nal.disabled = "disabled";
                var ukr_spd = document.getElementById('spd');
                ukr_spd.checked = "checked";
    	    }
             else if(id == 2) {
                ukr_nal.disabled = "";
                ukr_spd.checked = "checked";
                if(sid == 6) {
                  // set_order_method_ukr();
                  ukr_nal.checked = 'checked';
                }
             }
          }
      }

      function set_hide_product_price(id) {
          if(id.innerHTML == 'все') {
              document.getElementById("show_product_price").value = 'yes';
          }
          else {
              document.getElementById("show_product_price").value = 'not';
          }
          document.form_show_product_price.submit();
      }

      function set_show_table_products(id) {
          if(id.innerHTML == 'картинками') {
              document.getElementById("show_table_products").value = 'yes';
          }
          else {
              document.getElementById("show_table_products").value = 'not';
          }
          document.form_show_table_products.submit();
      }

      function set_user_bonus(sum) {
          document.getElementById('user_bonus_bay').innerHTML = sum;
      }

      function show_product_hide_all(id) {
          var product_hide_all = document.getElementById('product_hide_all');
          if(product_hide_all.style.display == 'none') {
              product_hide_all.style.display = 'block';
              id.innerHTML = 'Скрыть все товары';
          }
          else {
              product_hide_all.style.display = 'none';
              id.innerHTML = 'Показать все товары';
          }
      }

      function bay_cart_ip(productID, detal, categoryID, parentID, type_s) {
      	  var variant = '';
          var count = 1;
          x_get_aj_add_card(productID,variant,count,categoryID,3,reques_bay_cart);
          setTimeout(function() { document.location.href = '/index.php?shopping_cart=yes&order_quick=yes&ip=1'; }, 500)
	  }

      function bay_cart_pr(productID, detal, categoryID, parentID, type_s) {
      	  var variant = '';
          var count = 1;
          x_get_aj_add_card(productID,variant,count,categoryID,3,reques_bay_cart);
          setTimeout(function() { document.location.href = '/index.php?shopping_cart=yes&order_quick=yes&ip=2'; }, 500)
	  }

      function bay_cart(productID, detal, categoryID, parentID, type_s) {
      	  var variant = '';
          var count = 1;
          x_get_aj_add_card(productID,variant,count,categoryID,3,reques_bay_cart);
          setTimeout(function() { document.location.href = '/index.php?shopping_cart=yes&order_quick=yes'; }, 500)
          /*
          //

          var variant = '';
          var count;
          sett = {};
          butt_n = { 'Добавить': true, 'Отмена': false };
          if(detal) {
              o = {count:1};
                var message_title = '<h1>Товар на который нужен счет<h1><p><table width="100%" cellspacing="0" cellpadding="0" style="font-weight: normal;">';
                    message_title += '<tr><td width="65%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Товар</td><td width="10%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Количество</td><td width="30%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Сумма с НДС</td></tr>';
                    message_title += '<tr><td align="left" style="border-bottom: 1px black solid;margin-top:40px;"><img border="0" height="120" width="120" style="float:left;margin-top:-40px;" src="products_pictures/'+$('#cart_one_image_'+productID).html()+'">'+$('#cart_one_name_'+productID).html()+'</td><td align="center" style="border-bottom: 1px black solid;font-weight: bold;"><div class="field" style="width:60px;color:#008000;"><input type="text" size="2" style="width:30px;color:#008000;text-align: right;" name="intcount" id="intcount" value="'+ o.count +'" /> шт.</div></td><td align="center" style="border-bottom: 1px black solid;color:#008000; font-size:14px;font-weight: bold;">'+$('#cart_one_price_'+productID).html()+' грн.</td></tr>';
                    message_title += '<tr><td colspan="3" align="right" style="color:#008000; font-size:14px;font-weight: bold;"><span style="color: black;">Итого</span> '+(parseFloat($('#shpcrtgc_s').html())+parseFloat($('#cart_one_price_'+productID).html()))+' грн.</td></tr>';
                    message_title += '</table></p><p style="text-align: center; font-size:12px;font-weight: normal;">Стоимость товара автоматически пересчитывается на безналичный курс</p>';
                var message_title2 = '<h1>Товар в рассрочку<h1><p><table width="100%" cellspacing="0" cellpadding="0" style="font-weight: normal;">';
                    message_title2 += '<tr><td width="65%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Товар</td><td width="10%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Количество</td><td width="30%" align="center" style="border-bottom: 1px black solid;font-weight: bold;">Сумма с НДС</td></tr>';
                    message_title2 += '<tr><td align="left" style="border-bottom: 1px black solid;margin-top:40px;"><img border="0" height="120" width="120" style="float:left;margin-top:-40px;" src="products_pictures/'+$('#cart_one_image_'+productID).html()+'">'+$('#cart_one_name_'+productID).html()+'</td><td align="center" style="border-bottom: 1px black solid;font-weight: bold;"><div class="field" style="width:60px;color:#008000;"><input type="text" size="2" style="width:30px;color:#008000;text-align: right;" name="intcount" id="intcount" value="'+ o.count +'" /> шт.</div></td><td align="center" style="border-bottom: 1px black solid;color:#008000; font-size:14px;font-weight: bold;">'+$('#cart_one_plan_'+productID).html()+' грн.</td></tr>';
                    message_title2 += '<tr><td colspan="3" align="right" style="color:#008000; font-size:14px;font-weight: bold;"><span style="color: black;">Итого</span> '+(parseFloat($('#shpcrtgc_s').html())+parseFloat($('#cart_one_plan_'+productID).html()))+' грн.</td></tr>';
                    message_title2 += '</table></p><p style="text-align: center; font-size:12px;font-weight: normal;">Авансовый платеж равен итоговой сумме указаной выше</p>';

                var formstr = '<p>Введите желаемое количество товаров для добавления в корзину:<\/p>'+
                    '<div class="field"><label for="intcount">Количество<\/label><input type="text" name="intcount" id="intcount" value="'+ o.count +'" /><\/div>';
                if(type_s === 1) {
                    formstr = message_title;
                    {prefix:'imp_bnal'}
                    butt_n = { 'Оформить счет': true, 'Продолжить наполнение счета': false };
                }
                else if(type_s === 2) {
                    formstr = message_title2;
                    {prefix:'imp_bnal'}
                    butt_n = { 'Оформить заявку': true, 'Продолжить оформление товара': false };
                }

                jqistates = {
                    state0: {
                        html: formstr,
                        focus: 1,
                        zIndex:999,
                        buttons: butt_n,
                        submit: function(v, m, f){
                            var e = "";
                            m.find('.errorBlock').hide('fast',function(){ jQuery(this).remove(); });
                            if (v) {
                                if(isNaN(f.intcount))
                                    e += "Пожалуйста введите желаемое количество товаров для добавления в корзину<br>";
                                if (e == "") {
                                    var element = document.getElementsByTagName('input');
                                    for(var i=0; i<element.length; i++) {
                                      if(element[i].name.indexOf('option_select_hidden_') != -1) {
                                        variant += element[i].value;
                                        if(i < element.length-1) {
                                          variant += ',';
                                        }
                                      }
                                    }
                                   message_send_request();
                                   x_get_aj_add_card(productID,variant,f.intcount,categoryID,3,reques_bay_cart);
                                    return true;
                                }
                                else{
                                    jQuery('<div class="errorBlock" style="display: none;">'+ e +'<\/div>').prependTo(m).show('slow');
                                }
                                return false;
                            }
                            else return true;
                        }
                    }
                };
                $.prompt(jqistates, sett);
          }
          else {
              count = document.getElementById('bay_cart_count_'+productID).value;
          var element = document.getElementsByTagName('input');
          for(var i=0; i<element.length; i++) {
              if(element[i].name.indexOf('option_select_hidden_') != -1) {
                  variant += element[i].value;
                  if(i < element.length-1) {
                      variant += ',';
                  }
              }
          }
          if(!parentID) {
              message_send_request();
               x_get_aj_add_card(productID,variant,count,categoryID,3,reques_bay_cart);
          }
          else {
              message_send_request();
              x_get_aj_add_card(productID,variant,count,categoryID,2,parentID,reques_bay_cart);
          }
          }
          */
      }
      function message_send_request() {
          jqistates = {
                    state0: {
                        html: 'Пожалуйста подождите, идет выполнение операции...',
                        focus: 1,
                        buttons: { },
                        submit: function(v, m, f){
                            var e = "";
                            m.find('.errorBlock').hide('fast',function(){ jQuery(this).remove(); });
                            if (v) {
                                return true;
                            }
                            else return true;
                        }
                    }
                };
      			$.prompt(jqistates,{timeout:2000});
      }
      function reques_parent_show_all(prod) {
          if(prod.product.parentID) {
              var str_prod = '';
              var parent = document.getElementById('wrapp_parent'+prod.product.parentID+'_block');
              var parent_hidden = document.getElementById('wrapp_parent'+prod.product.parentID+'_hidden');
              parent_hidden.onclick = new Function("hidden_desc(this);");
              for(list in prod.product.product_list) {
                  for(product in prod.product.product_list[list].product) {
                      str_prod += "<span style=\"display: inline-table; margin: 10px 15px; width: 150px; height: auto; text-align: center;\">"+
                      "<a target=\"_blank\" href=\"index.php?productID="+prod.product.product_list[list].product[product].productID+"\"><img border=0 width=\"120px\" src=\"products_pictures/"+prod.product.product_list[list].product[product].picture+"\"><\/a><br>"+
                      "<h1><a target=\"_blank\" style=\"color: black; font-size:9px;\" title=\""+prod.product.product_list[list].product[product].name+"\" href=\"index.php?productID="+prod.product.product_list[list].product[product].productID+"\">"+prod.product.product_list[list].product[product].name+"<\/a><\/h1>";
                      if(prod.parent && prod.product.product_list[list].product[product].dis_anch_num > 1) {
                          str_prod += "<p>Цена:<strong style=\"color: red; text-decoration: line-through;\">"+prod.product.product_list[list].product[product].PriceWithUnit+"<\/strong> <strong style=\"color: red;\">"+prod.product.product_list[list].product[product].PriceWithDisAnch+"<\/strong><\/p>";
                      }
                      else {
                          str_prod += "<p>Цена:<strong style=\"color: red;\">"+prod.product.product_list[list].product[product].PriceWithUnit+"<\/strong><\/p>";
                      }
                      str_prod += "<p>кол-во:<input type=\"text\" id=\"bay_cart_count_"+prod.product.product_list[list].product[product].productID+"\" size=\"1\" value=\"1\"> <a href=\"javascript:void(0);\" onclick=\"javascript:bay_cart("+prod.product.product_list[list].product[product].productID+", false, "+prod.product.product_list[list].product[product].categoryID+", "+prod.productID+"); return false;\" style=\"color: #585858;\"><\/p><p>Поместить в корзину<\/a><\/p>"+
                      "<\/span>";
                  }
              }
              parent.innerHTML = str_prod;
          }
      }
      function set_parent_show_all(parentID, productID) {
          var parent = document.getElementById('wrapp_parent'+parentID+'_block');
          parent.innerHTML = "<center><img src=\"images/loading.gif\"><\/center>";
          x_get_aj_product_list(parentID,productID,reques_parent_show_all);
      }
      function reques_parent_show(prod) {
          if(prod.product.parentID) {
              var str_prod = '';
              var parent = document.getElementById('wrapp_parent'+prod.product.parentID+'_block');
              str_prod += "<a href=\"#\" onclick=\"javascript:set_parent_show_all("+prod.product.parentID+", "+prod.productID+"); return false;\" style=\"font-weight: bold; color: red; size: 12px;\">Показать остальные товары<\/a><br>";
              for(list in prod.product.product_list) {
                  for(product in prod.product.product_list[list].product) {
                      str_prod += "<span style=\"display: inline-table; margin: 10px 15px; width: 150px; height: auto; text-align: center;\">"+
                      "<a target=\"_blank\" href=\"index.php?productID="+prod.product.product_list[list].product[product].productID+"\"><img border=0 width=\"120px\" src=\"products_pictures/"+prod.product.product_list[list].product[product].picture+"\"><\/a><br>"+
                      "<h1><a target=\"_blank\" style=\"color: black; font-size:9px;\" title=\""+prod.product.product_list[list].product[product].name+"\" href=\"index.php?productID="+prod.product.product_list[list].product[product].productID+"\">"+prod.product.product_list[list].product[product].name+"<\/a><\/h1>";
                      if(prod.parent && prod.product.product_list[list].product[product].dis_anch_num > 1) {
                          str_prod += "<p>Цена:<strong style=\"color: red; text-decoration: line-through;\">"+prod.product.product_list[list].product[product].PriceWithUnit+"<\/strong> <strong style=\"color: red;\">"+prod.product.product_list[list].product[product].PriceWithDisAnch+"<\/strong><\/p>";
                      }
                      else {
                          str_prod += "<p>Цена:<strong style=\"color: red;\">"+prod.product.product_list[list].product[product].PriceWithUnit+"<\/strong><\/p>";
                      }
                      str_prod += "<p>кол-во:<input type=\"text\" id=\"bay_cart_count_"+prod.product.product_list[list].product[product].productID+"\" size=\"1\" value=\"1\"> <a href=\"javascript:void(0);\" onclick=\"javascript:bay_cart("+prod.product.product_list[list].product[product].productID+", false, "+prod.product.product_list[list].product[product].categoryID+", "+prod.productID+");\" style=\"color: #585858;\"><\/p><p>Поместить в корзину<\/a><\/p>"+
                      "<\/span>";
                  }
              }
              str_prod += "<br><a href=\"#\" onclick=\"javascript:set_parent_show_all("+prod.product.parentID+", "+prod.productID+"); return false;\" style=\"font-weight: bold; color: red; size: 12px;\">Показать остальные товары<\/a>";
              parent.innerHTML = str_prod;
          }
      }
      function set_parent_show(parentID, productID) {
          var parent = document.getElementById('wrapp_parent'+parentID+'_block');
          parent.innerHTML = "<center><img src=\"images/loading.gif\"><\/center>";
          x_get_aj_product_list(parentID,productID,5,reques_parent_show);
      }
      function reques_show_aux_page(aux_page) {
                $.prompt(aux_page.page_body?aux_page.page_body:'<p>Страница не найдена!<\/p>',{ pos:true, prefix: 'colsJqi', opacity: 0, buttons: { 'Закрыть': false }, focus: 0 });
      }
      function show_aux_page(id_page) {
          x_showAuxPage(id_page,reques_show_aux_page);
      }
      function reques_show_aux_page(aux_page) {
                $.prompt(aux_page.page_body?aux_page.page_body:'<p>Страница не найдена!<\/p>',{ pos:true, prefix: 'colsJqi', opacity: 0, buttons: { 'Закрыть': false }, focus: 0 });
      }
      function showTabsOpen(productID) {
          if($("#dialog"+productID).dialog( "isOpen" ) == true) {
              $("#dialog"+productID).dialog("close");
          }
          else {
              $("#dialog"+productID).dialog({ zIndex: 900, position: [getRandomInt(250,350),getRandomInt(50,100)], width: 800 });
          }
      }
	  function showPriceOpen(productID) {
	  	  if($("#dialog_"+productID).dialog( "isOpen" ) == true) {
              $("#dialog_"+productID).dialog("close");
          }
          else {
              $("#dialog_"+productID).dialog({ zIndex: 900, position: [getRandomInt(450,550),getRandomInt(450,500)] });
          }

	  }
      function showPodborPC()  {
          if($("#podborpc").dialog( "isOpen" ) == true) {
              $("#podborpc").dialog("close");
          }
          else {
              $("#podborpc").dialog({ zIndex: 900 });
          }
      }
      function showFaxTable(id)  {
          document.getElementById('send_product_name').value = id;
          if($("#faxtable").dialog( "isOpen" ) == true) {
              $("#faxtable").dialog("close");
          }
          else {
              $("#faxtable").dialog({ zIndex: 900 });
          }
      }
      function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
      }
      function sendFax(id) {
          document.getElementById('send_product_name').value = id;
      }

	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;

	function jsddm_open()
	{  jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

	function jsddm_close()
	{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}

	function jsddm_canceltimer()
	{  if(closetimer)
	{  window.clearTimeout(closetimer);
	closetimer = null;}}

	$(document).ready(function()
	{  $('#jsddm > li').bind('mouseover', jsddm_open)
	$('#jsddm > li').bind('mouseout',  jsddm_timer)});

	document.onclick = jsddm_close;

	function confirmUnsubscribe() //unsubscription confirmation
	{
		temp = window.confirm('Вы уверены, что хотите отменить регистрацию в магазине?');
		if (temp) //delete
		{
			window.location="index.php?killuser=yes";
		}
	}

	function validate() // newsletter subscription form validation
	{
		if (document.subscription_form.email.value.length<1)
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		if (document.subscription_form.email.value == 'Email')
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		return true;
	}
	function validate_disc() // review form verification
	{
		if (document.formD.nick.value.length<1)
		{
			alert("Пожалуйста, введите Ваш псевдоним");
			return false;
		}

		if (document.formD.topic.value.length<1)
		{
			alert("Пожалуйста, введите тему сообщения");
			return false;
		}

		return true;
	}
	function validate_search()
	{

		if (document.Sform.price1.value!="" && ((document.Sform.price1.value < 0) || isNaN(document.Sform.price1.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}
		if (document.Sform.price2.value!="" && ((document.Sform.price2.value < 0) || isNaN(document.Sform.price2.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}

		return true;
	}

      function reques_bay_cart(id) {
          if(!id.not) {
          var message = 'Товар: ('+id.name+') в количестве '+id.count+'шт. добавлен в корзину!';
          if(id.parent >= 1) {
              //message += ' Теперь вы можете купить прикрепленные товары со скидкой!';
          }
          message += ' Можете продолжить дальнейший выбор товаров. Для оформления заказа нажмите на символ "Корзины" в верхней части экрана!';
          }
          else {
              message = "Уважаемый клиент! Данный товар, по цене которую Вы видите, можно купить только в комплекте с "+id.name+", на странице которого Вы находитесь. Поместите "+id.name+" в корзину, после этого Вы сможете добавить другие товары со скидками";
          }
          jqistates = {
                    state0: {
                        html: message,
                        focus: 1,
                        buttons: { OK: true },
                        submit: function(v, m, f){
                            var e = "";
                            m.find('.errorBlock').hide('fast',function(){ jQuery(this).remove(); });
                            if (v) {
                                return true;
                            }
                            else return true;
                        }
                    }
                };
                //$.prompt(jqistates);
          if(!id.not) {
          document.getElementById('shpcrtgc').innerHTML = id.items + ' товар(ов): ';
          document.getElementById('shpcrtca').innerHTML = id.shown;
          document.getElementById('shpcrtgc_s').innerHTML = id.value;
          setWindowCart(id.items, id.shown);
          openWindowCart(true);
          document.getElementById('img_orpay').style.display = 'block';
          var element = document.getElementsByTagName('a');
          var parentID = '';
          for(var i=0; i<element.length; i++) {
              if(/wrapp_parent\d+_hidden/.test(element[i].id)) {
                  parentID = /\d+/.exec(element[i].id);
                  element[i].onclick = new Function("hidden_desc(this);javascript:set_parent_show("+parentID[0]+", "+id.productID+");");
                  if(element[i].className == 'active' && id.reload == 3) {
                      //element[i].onclick();
                  }
              }
          }
          }
	}


function niw(imgf) {
		window.open('/showimage.php?img='+imgf,'bigimage'+imgf.replace('.','_'),'width=100,height=100,top=100,left=100,toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=1,status=0,fullscreen=0');
	  }
var bi;
function startBlick() {
	if (bi) { return false; }
	if (document.getElementById('infoa').innerHTML == '+') {
		bi = window.setInterval("doBlick()",20);
	}
}
function doBlick() {
	var e = document.getElementById('infoheadtd');
	var bp = e.style.backgroundPosition;
	var bpa = bp.split(' ');
	var curleft = parseInt((bpa[0].replace('px','')) ? bpa[0].replace('px','') : bpa[0].replace('px',''));
	if (curleft < 210) {
		e.style.backgroundPosition = (curleft+1).toString() + 'px 0px';
	} else {
		e.style.backgroundPosition = '-210px 0px';
		window.clearInterval(bi);
		bi = null;
	}
}
function expandInfoTD (e) {
	var oldie = false;
	var p = navigator.userAgent.indexOf('MSIE');
	if (p > 0) {
		if ((navigator.userAgent.charAt(p+5) == '6') || (navigator.userAgent.charAt(p+5) == '7')) {
			oldie = true;
			bi = true;
		}
	}
	if (e.innerHTML == '+') {
		if (oldie) {
			document.getElementById('infotd').style.visibility = 'visible';
		}
		if (!oldie) wi = window.setInterval("expandStep()",1);
		e.innerHTML = '-';
		e.title = 'Свернуть';
		var dt = new Date();
		document.cookie = 'infotime=' + dt.getTime().toString();
	} else {
		if (oldie) {
			document.getElementById('infotd').style.visibility = 'hidden';
		}
		if (!oldie) wi = window.setInterval("shrinkStep()",1);
		e.innerHTML = '+';
		e.title = 'Развернуть';
	}
	e.blur();
}
function shrinkInfoTD() {
	var e = document.getElementById('infoa');
	if (e.innerHTML == '-') {
		expandInfoTD(e);
	}
}
function expandStep() {
	var td = document.getElementById('infotd');
	var span = document.getElementById('infospan');
	var sh = ((navigator.userAgent.toLowerCase().indexOf('firefox') > -1) || (navigator.userAgent.toLowerCase().indexOf('ie') > -1) || (navigator.userAgent.toLowerCase().indexOf('opera') > -1)) ? 20 : 0;
	if ((parseInt(td.style.height.replace('px',''))) < (((span.scrollHeight) ? span.scrollHeight : td.scrollHeight)+sh)) {
		if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
			td.style.height = (span.scrollHeight+40).toString() + 'px';
		} else {
			td.style.height = (parseInt(td.style.height.replace('px','')) + 10).toString() + 'px';
		}
	} else {
		window.clearInterval(wi);
	}
}
function shrinkStep() {
	var td = document.getElementById('infotd');
	if (parseInt(td.style.height.replace('px','')) > 0) {
		if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
			td.style.height = '0px';
		} else {
			td.style.height = (parseInt(td.style.height.replace('px','')) - 10).toString() + 'px';
		}
	} else {
		window.clearInterval(wi);
	}
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function checkInfoExpand() {
	// alert ('autostart');
	var td = document.getElementById('infotd');
	var p = navigator.userAgent.indexOf('MSIE');
	if (p > 0) {
		if ((navigator.userAgent.charAt(p+5) == '6') || (navigator.userAgent.charAt(p+5) == '7')) {
			// td.style.top = '150px';
			document.getElementById('infodivall').style.visibility = 'hidden';
			return true;
		} else {
			document.getElementById('infodivall').style.visibility = 'visible';
		}
	} else {
		document.getElementById('infodivall').style.visibility = 'visible';
	}
	var coo = getCookie('infotime');
	var dt = new Date();
	if (null == coo) {
		var cook = 'infotime=' + (dt.getTime()+30000).toString();
		document.cookie = cook;
		expandInfoTD(document.getElementById('infoa'));
		wii = window.setTimeout("shrinkInfoTD()",Math.ceil(30000));
	} else {
		if (coo > dt.getTime()) {
			expandInfoTD(document.getElementById('infoa'));
			wii = window.setTimeout("shrinkInfoTD()",Math.ceil((coo - dt.getTime())));
		}
	}
}
var wii;
// window.onLoad = function() {checkInfoExpand();}
$(document).ready(function() {window.setTimeout("checkInfoExpand()",1000); window.setInterval("startBlick();",10000);});
function compare(el)
{
	if ($('#ch_' + el).is(':checked'))
	{
		$('#ch_' + el).attr('checked','');
		comparison_clear(el);
	}
	else
	{
		$('#ch_' + el).attr('checked','checked');
		comparison_add(el);
	}
}
function compare_s(el)
{
	if ($('#ch_' + el).is(':checked'))
	{
		comparison_add(el);
	}
	else
	{
		comparison_clear(el);
	}
}
function PacketIntoHiddenValue1()
{
	var ComparedProducts = search_cookie("comparison_productID_");
	if(ComparedProducts)
	{
		document.ComparisonForm1.ComparisonHidden1.value = ComparedProducts;
		document.ComparisonForm1.submit();
	}
}
function Compared_summ()
{
	var ComparedProducts = search_cookie("comparison_productID_");
	var test  = ComparedProducts.split(' ');
	return test.length - 1;
}

function show_b()
{
	var summ = Compared_summ();
	if(summ > 0)
	{
      		var stt = $('#comp_but').val();
      		var st = stt.split(' ');
      		$('#comp_but').val(st[0] + ' ' + st[1] + ' ' + summ);
        	$('#comp_but').show();
        	$('#comp_but_del').show();
	}
	else
	{
      	$('#comp_but').hide();
       	$('#comp_but_del').hide();
	}
}
var summ = Compared_summ();
/*$(document).ready(
	function()
	{
		if ((summ > 0) && (null != $('#comp_but')))
		{
      		var stt = $('#comp_but').val();
      		var st = stt.split(' ');
      		$('#comp_but').val(st[0] + ' ' + st[1] + ' ' + summ);
        	$('#comp_but').show();
        	$('#comp_but_del').show();
		}
	}
);*/
function comparison_add(productID)
{
	var name = "comparison_productID_"+productID;
	if(get_cookie(name))
		edit_cookie(name, productID);
	else
		edit_cookie(name, productID);
}
function comparison_clear(productID)
{
	name = "comparison_productID_"+productID
	remove_cookie(name);
}
function Сomp_but_del()
{
	var string = search_cookie("comparison_productID_").split(' ');
	for(var i=0; i<string.length; i++)
	{
		if(string[i])
		{
			remove_cookie("comparison_productID_"+string[i]);
		}
	}
	$('#comp_but').hide();
	$('#comp_but_del').hide();
	$('.listproducts input:checkbox').attr('checked','');
}
function showPriceOpen(productID)
{
	if($("#dialog_"+productID).dialog("isOpen") == true) {
    	$("#dialog_"+productID).dialog("close");
    } else {
     	$("#dialog_"+productID).dialog({ zIndex: 900, position: [getRandomInt(450,550),getRandomInt(250,300)] });
    }
}
