function open_popup(j1,j2,pagesrc)
	{
	var opened;
	features="top=0,left=0,width="+j1+",height="+j2+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
	if ((!opened)||(NewWin.closed)){opened=true;NewWin=window.open(pagesrc,"NewWindow",features);NewWin.focus();}
	else{if ((opened)||(!NewWin.closed)){NewWin.location=pagesrc;NewWin.focus();}}
	}
	
	
var gate_url= sitedir+'/gate.php';

function get_color(item_id)
	{
	if (!document.forms['item_info'])return;
	var color_inp=document.forms['item_info'].elements['color'+item_id];
	if (!color_inp)return 0;
	if (!color_inp.length)return color_inp.value;
	for(i=0;i<100;i++)
		{
		if (!color_inp[i])continue;
	
	  	if(color_inp[i].checked || color_inp[i].type=='hidden')return color_inp[i].value;
    	}
	}
function get_var_id(item_id)
	{
		
	var vars_select=document.getElementById('var_sel_'+item_id);
	
	if (!vars_select)return 0;

	var_id=vars_select.options[vars_select.selectedIndex].value;
	return var_id;
	}	
function handle(item_id)
	{	
	var count = $('value'+item_id);
	var basket_info = $('basket_info');
	if (!count)return;
	color=get_color(item_id);
	var_id=get_var_id(item_id);
	if (!color)color=0;
	basket_info.update('обновление корзины...');
	if(obj=$('basket_total_row'))  obj.update('Итого: '+'обновление суммы...');
	params='?item_id='+item_id+'&count='+count.value+'&color='+color+'&var_id='+var_id;
	new Ajax.Request(gate_url+params, {
		method: 'post',
		encoding: 'windows-1251',
		onSuccess: function(result) 
			{
		    values=result.responseText.split('|||');
		    var str=values[1];
		    var show_basket=values[2];
		   	var total=values[3];
		    if (show_basket==1)
				{
				$('basket_empty').hide();
				$('in_your_basket').show();
				basket_info.update(str);					
		    	}
		    else
		    	{		    	
		    	$('basket_empty').show();
				$('in_your_basket').hide();
		    	basket_info.update('');		    	
		    	}			
			if(obj=$('basket_total_row'))  obj.update('Итого: '+str);
			}
			});		
	return false;
	}
	
function del_row(id)
	{
	if (row=$('tr_'+id))row.hide();
	}
	
function show_quantity(id) 
	{
	change_div(id,1);
  	handle(id);
  	$("value" + id).focus(); 
	}
	
function change_div(id,count) 
	{
	//if (!count)count=1;
	$('quantity' + id).update(
	    "<div class=\"updatebasket\"><input type=\"text\" name=\"b[" + id + "]\" id=\"value" + id +
	    "\" value=\""+count+"\" maxlength=2 onKeyUp=\"handle('" + id + "');\"><img src=\""+sitedir+"/files/img/inc-dec-basket.gif\" width=\"12\" height=\"15\" class=\"incdec\" id=\"incdec" + id +
	    "\" onMouseUp=\"this.src = '"+sitedir+"/files/img/inc-dec-basket.gif';\"><img src=\""+sitedir+"/files/img/delete-basket.gif\" alt=\"Удалить товар из корзины\" width=\"14\" height=\"15\" border=\"0\"" +
	    " class=\"delete\" onMouseUp=\"this.src = '"+sitedir+"/files/img/delete-basket.gif'; hide_quantity('" + id + "');\"></div>");
	$('incdec' + id).onmousedown = incdec_click;  		
	}

function incdec_click(eventMouse) 
	{
	if (document.all) 
	  	{ 
	  	if (event) 
	  		{ 
	  		var y = event.offsetY; 
	  		var el = event.srcElement; 
	  		var id = event.srcElement.id; 
	  		} 
	  	}
	else 
	  	{
	  	if (eventMouse) 
	  		{ 
	  		var y = eventMouse.pageY - eventMouse.currentTarget.y; 
	  		var el = eventMouse.currentTarget; 
	  		var id = eventMouse.currentTarget.id; 
	  		} 
	  	}
	id = id.substr(6);
	if (y < 7) {inc_quantity(id); }
	else if (y > 8) {dec_quantity(id); }
	}
	
function inc_quantity(id) 
	{
  	$('value' + id).value = $('value' + id).value * 1 + 1;
	$("value" + id).focus();
 	handle(id);
	}
	
function dec_quantity(id) 
	{
  	if ($('value' + id).value * 1 > 0) 
  		{
    	$('value' + id).value = $('value' + id).value * 1 - 1;
	   	handle(id);
    	$("value" + id).focus();
		}
	else 
		{
    	$("value" + id).focus();
  		}
}


function hide_quantity(id) 
	{
	$('value' + id).value = "0";
	handle(id);
	$('quantity' + id).update("<div class=\"addbasket\"><img src=\""+sitedir+"/files/img/add-basket.gif\" alt=\"Добавить товар в корзину\" width=\"86\" height=\"15\" border=\"0\"  onMouseUp=\"show_quantity('" + id + "');\"></div>");
	del_row(id);
	}

	
function start_search()	
	{
	if (obj=$('s_form'))
		{
		if($('w2').checked)
			{
			obj.action=sitedir+'/catalogue';
			}
		}
	return false;
	}
	
	
function Check_Nums(evt, elem) 
	{
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode < 48 || charCode > 57) 
    	{
        //alert("В это поле можно вводить только цифры.");
        return false;
  	  	}
	}
	
function reg_ch_type(t)
	{
	if (obj=$('reg_ur'))
		{
		obj.style.display=(t==2)?'block':'none';
		}
	
	}
	
function check_active_form()
	{
	var obj=$('another_adress');
	var disable=false;

	if(obj.checked)disable=false;
	else disable=true;
	
	$('fio').disabled=disable;
	$('email').disabled=disable;
	$('phone').disabled=disable;
	$('city').disabled=disable;
	$('index').disabled=disable;
	$('adress').disabled=disable;
	$('r1').disabled=disable;
	$('r2').disabled=disable;
	}
	
function order_submit()
	{
		
	disable=false;
	$('fio').disabled=disable;
	$('email').disabled=disable;
	$('phone').disabled=disable;
	$('city').disabled=disable;
	$('index').disabled=disable;
	$('adress').disabled=disable;
	$('r1').disabled=disable;
	$('r2').disabled=disable;
	$('order_form').submit();
	}
function ShowBigPicture(id,ev) // процедура увелечения картинки
{
	Pos = mouseCoords(ev);
	X = Pos.x;
	Y = Pos.y;
//	alert(Y);
	d = document.getElementById('BigPicture');
	d.innerHTML = '<img src="'+id.src+'" id="BP" align="center" />';
	d.style.top = Y - 250 / 2  + 'px';
	d.style.left = X - 350 / 2 + 'px';
	d.style.display = '';
}

function HideBigPicture() // процедура закрытия картинки
{
	d = document.getElementById('BigPicture');
	d.style.display = 'none';
	d.innerHTML = '';
}

function mouseCoords(ev) // процедура определения место нахождения курсора
{

    if (ev.pageX || ev.pageY) {
        return {x:ev.pageX, y:ev.pageY};
    }

    var docBody = document.documentElement
                        ? document.documentElement
                        : document.body;

    return {
        x: ev.clientX + docBody.scrollLeft - docBody.clientLeft,
        y: ev.clientY + docBody.scrollTop  - docBody.clientTop
    };
}


