  function ShowButtonPopup(good_id,user_id,good_quantity,e) {	if (!e) e = window.event;

	var bww_string = $('div.button-wait').css('width');
	var bww = new Number(bww_string.replace('px',''));
	var bpw_string = $('div.button-popup').css('width');
	var bpw = new Number(bww_string.replace('px',''));

	if (e.pageX || e.pageY)
	{
    	x = e.pageX;
	    y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
    	x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
	    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	bwx = x;
	bpx = x;


	//Запустить подгрузку
	$.ajax({
	  type: "GET",
	  url: '/catalog/cart_popup.php',
	  data: {good_id: good_id, good_quantity: good_quantity, user_id: user_id, form_submitted: 'mainCart'},
	  success: function(msg){	  	$('div.button-wait').css('display', 'none');
	    $('div.button-popup').css('display', 'block');
	  }
	});

	//Проверяем, чтобы не вылазило по ширине
	if ( (bwx + bww) > screen.width) {		bwx = bwx - bww;	}
	if ( (bpx + bpw) > screen.width) {
		bpx = bpx - bpw;
	}

	$('div.button-wait').css('display', 'block');
	$('div.button-wait').css('top', y);
	$('div.button-wait').css('left', bwx);
	$('div.button-popup').css('top', y);
	$('div.button-popup').css('left', bpx);
  }
  function CloseButtonPopup() {
  	$('div.button-popup').css('display', 'none');
  }
  function MakeBorder(baget_image,baget_height,good_height,good_width,baget_price,baget_id) {
      var max_width = 650; //Максимальная ширина на экране вместе с багетом, в px


      var lt_img = document.getElementById('lt_img');
      var rt_img = document.getElementById('rt_img');
      var lb_img = document.getElementById('lb_img');
      var rb_img = document.getElementById('rb_img');
      var t_td = document.getElementById('t_td');
      var r_td = document.getElementById('r_td');
      var l_td = document.getElementById('l_td');
      var b_td = document.getElementById('b_td');
      var good_img = document.getElementById('good_img');
      var baget_div = document.getElementById('gb');
      var baget_button = document.getElementById('gb_button');
      var baget_length = ((good_height + good_width)*2 + 8*baget_height)/100;



      //Вычисляем масштаб изображения и багета
      var k = 2; //Коэффициент показывающий сколько пикселов приходится на 1 см
      var baget_height_px = 40; //высота багета в пикселах (как он отобразится на экране, приближенная)
      var img_width_px = good_img.width; //ширина картины в пикселах
      var i = 12;
      if (img_width_px + baget_height_px > max_width) {
      	  k = max_width / (baget_height*2 + good_width);
      } else {
          k = img_width_px / good_width;
      };
      baget_height_px = baget_height*k;
      if (baget_height_px <= 10) {
      	  baget_height_px = 10;
      } else if (baget_height_px >= 100) {
      	  baget_height_px = 100;
      } else {
          while (i < 100) {
             if (baget_height_px < i) {
             	if ((i-baget_height_px)<Math.abs(i-baget_height_px-2)) {
             		baget_height_px = i;
             	} else {
             		baget_height_px = i-2;
             	}
             	i = 100;
             } else {
             	i = i + 2;
             }
          }
      }
      img_width_px = Math.round(good_width*k);
      baget_height_px = Math.round(baget_height_px);

      good_img.width = img_width_px;

      lt_img.src = '/upload/good_baget/'+baget_image+baget_height_px+'_lt.jpg';
      rt_img.src = '/upload/good_baget/'+baget_image+baget_height_px+'_rt.jpg';
      lb_img.src = '/upload/good_baget/'+baget_image+baget_height_px+'_lb.jpg';
      rb_img.src = '/upload/good_baget/'+baget_image+baget_height_px+'_rb.jpg';
      t_td.style.background = 'url(/upload/good_baget/'+baget_image+baget_height_px+'_t.jpg)';
      r_td.style.background = 'url(/upload/good_baget/'+baget_image+baget_height_px+'_r.jpg)';
      l_td.style.background = 'url(/upload/good_baget/'+baget_image+baget_height_px+'_l.jpg)';
      b_td.style.background = 'url(/upload/good_baget/'+baget_image+baget_height_px+'_b.jpg)';

      //Надпись про багет и кнопка купить багет
      if (baget_price > 0) {
	      baget_div.innerHTML = 'Цена багета на картину:<br><b class="price">';
    	  baget_div.innerHTML += Math.round(baget_price*baget_length)+' руб.</b>';
      	  $('#gb_button').css('display', 'block');
      } else {	      baget_div.innerHTML = '';
      	  $('#gb_button').css('display', 'none');      }

	  baget_button.onclick=function(event) { ShowButtonPopup(baget_id,0,baget_length,event); };

  }

var check_check = '1';
function sel_all(name_of_form){


   if( !document.getElementById(name_of_form)) {   	  return;
  } else {
      for(var i=0;i<document.getElementById(name_of_form).elements.length;i++) {

      	currentNode = document.getElementById(name_of_form).elements[i];
        if (currentNode.type == 'checkbox') {
	        if (check_check=='0')
            	currentNode.checked = true;
         	else
            	currentNode.checked = false;
        }
      }
      if (check_check=='0') check_check = '1';
      else check_check = '0';
   }
}

function ShowIframePopup(iframe_id,link) {

    document.getElementById(iframe_id).src = link;
    document.getElementById(iframe_id).style.display = 'block';
    document.getElementById(iframe_id).width = '500px';
    document.getElementById(iframe_id).height = '500px';
}
