function popup_window( id, width, height ) {
	if (!width) width = 900;
	if (!height) height = 800;
	wnd = window.open( "/prod_popup.php?id=" + id, "_blank", "width="+width+",height="+height+",status=1,toolbar=0,resizable=1,scrollbars=1,menubar=1");
	wnd.focus();
}

function popup_delivery( id, width, height, obj ) {
	if (!width) width = 900;
	if (!height) height = 800;
	var c = absPosition(obj);
	wnd = window.open( "/delivery_cost/?id=" + id, "_blank", "width="+width+",height="+height+",left="+c.x+", top="+c.y+",status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

function open_poll( one )
{
	act = document.pollform.act.value;
	poll_id = document.pollform.poll_id.value;
	
	if( one == "1" ) { // radio
		q = "&q=" + get_radio_value( document.pollform.q );
	}
	
	if( one == "0" ) { // checkbox
		q = get_checkbox_values( document.pollform ); 
	}
	
	wnd = window.open( "/poll_action.php?act="+act+"&poll_id=" + poll_id + q, "_blank", "width=300,height=150,status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

function open_claim(){
	name = document.claimform.name.value;
	email = document.claimform.email.value;
	phone = document.claimform.phone.value;
	comment = document.claimform.comment.value;
		
	wnd = window.open( "/claim_action.php?name="+name+"&email=" +email+"&phone=" +phone+"&comment=" +comment, "_blank", "width=300,height=150,status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

function get_radio_value( obj ) {
	var i=0; var q=0;
    while((i<obj.length)&&(obj[i].checked!=1)) {i++;}
   	if (i!=obj.length) q =obj[i].value;
	return q;
}

function get_checkbox_values( obj )
{
 	var ret="";

	for( i = 0; i < obj.elements.length; i++ )
	{
		var item=obj.elements[i];
		if( item.checked==true && item.value > 0 ) ret = ret + "&q[]=" + item.value;
	}
	return ret;
}

function open_compare(product_id) {
	wnd = window.open( '/compare.php?action=add&id=' + product_id,  '_compare' ); 
	wnd.focus();
}

var imgname = "";
var description = "";

function start_window(img, desc, width, height){

	nw = window.open("./popup_map.html", "_blank", "width="+width+",height="+height+",status=no,toolbar=no,menubar=no");
    imgname=img;
    description=desc;
}

//Ї®Є § ў Їа ў®© Є®«®­ЄҐ бЇЁбЄ  в®зҐЄ, Ј¤Ґ в®ў а Ґбвм
function show_exist(city_id)
{
	s = document.getElementById('exist'+city_id).style;
	d = document.getElementById('n_exist'+city_id).style;

	if (s.display == 'none')
	{
		s.display = 'block';
		d.display = 'none';
	}
	else 
	{
		s.display = 'none';
		d.display = 'block';
	}
}

function close_all()
{
	s = document.getElementById('tenderf').style;
	s.display = 'none';
	s2 = document.getElementById('errorf').style;
	s2.display = 'none';
}

function show( id )
{
	s = document.getElementById(id).style;

	if (s.display == 'block')
	{
		s.display = 'none';
	}
	else 
	{
		s.display = 'block';
	}
}

function show_div( id )
{
	close_all();

	s = document.getElementById(id).style;

	if (s.display == 'block')
	{
		s.display = 'none';
	}
	else 
	{
		s.display = 'block';
		document.location.replace( "#"+id );
		//scrollTo(id);
	}
}

function show_div2( id )
{
	s = document.getElementById(id).style;
	s.display = 'block';
}

function hide_div2( id )
{
	s = document.getElementById(id).style;
	s.display = 'none';
}

//Ўл«® ў html_page.inc
var src_st;
function header_over(c)
{
	src_st = c.style["backgroundColor"];
	c.style["backgroundColor"] = "#FF9900";
	c.style['cursor'] = 'pointer';
}

function header_out(c)
{
	c.style['cursor'] = 'inherit';
    if (src_st != null) c.style["backgroundColor"] = src_st;
}

function absPosition(obj) {
      var x = y = 0;
      do {
            x += obj.offsetLeft;
            y += obj.offsetTop;
			//alert(obj.offsetTop);
            obj = obj.offsetParent;
      } while(obj);
	  
      return {x:x, y:y};
} 

function setWindowPosition(d, x, y)
{
	d.left = (x - 170) + 'px';
	d.top = (y + 0) + 'px';
	
	d.visibility = "visible";
	//d.display = "block";
}

function setWindowPosition2(d, x, y)
{
	d.left = (x) + 'px';
	d.top = (y) + 'px';
}

function close_barand()
{
	var d = document.getElementById('BrandInfoDiv').style;
	d.visibility = "hidden";
}

function show_brand_info()
{
	var d = document.getElementById('BrandInfoDiv').style;
	var c = document.getElementById('brandname');
	var pos = absPosition(c);
		
	setWindowPosition( d, pos.x, pos.y );
}

function print_obj( o )
{
	for (i in o)
	{
		var s = '';
		s += i;
		s += '<br />';
		document.write(s);
	}
}

/*
Класс ImgCheckbox
В конструктор передаются параметры:
    imgId        id картинки, которая будет служить чекбоксом
    inputId      id «настоящего» чекбокс-элемента формы
    imgOn        url картинки «включённого» чекбокса
    imgOff       url картинки «выключённого» чекбокса
*/
function ImgCheckbox(imgId, inputId, imgOn, imgOff)
 {
    this.imgOn   = imgOn;
    this.imgOff  = imgOff;
    this.image   = document.getElementById(imgId);
    this.input   = document.getElementById(inputId);
 
    // предзагрузка картинок
    this.preload_imgOn      = new Image();
    this.preload_imgOn.src  = imgOn;
    this.preload_imgOff     = new Image();
    this.preload_imgOff.src = imgOff;
 
    // скрываем обычный чекбокс…
    this.input.style.display = "none";
    // и показываем чекбокс-картинку
    this.image.style.display = "inline";
    
    // установка начального состояния чекбокса
    this.setState(this.input.checked)
}
 
// установка состояния чекбокса
ImgCheckbox.prototype.setState = function(state) 
{
    // меняем состояние скрытого чекбокса
    this.input.checked     = state;
    // меняем картинку
    this.image.src   = state ? this.imgOn : this.imgOff;
}
 
// изменение состояния чекбокса на обратное (вкл -> выкл и наоборот)
ImgCheckbox.prototype.flip = function() 
{
	this.setState(!this.input.checked);
	PriceCheck();
}

function PriceCheck() 
{
	var real_minp = $('#min_price').val();
	var real_maxp = $('#max_price').val();
	
	//alert( "real_minp = " + real_minp + "; real_maxp = " + real_maxp );

	var c = $('.cat_options').find('input:checked');
	var maxp = 0;
	var minp = real_maxp;
	var tmin = 0; 
	var tmax = 0;

	if( c.length > 0 )
	{	
		//alert( "c.length=" + c.length );
		for( var i=0; i<=c.length; i++ )
		{
			tmin = $(c[i]).data('min');
			tmax = $(c[i]).data('max');
			
			//alert( "tmin = " + tmin + "; tmax = " + tmax );
	
			minp = ( tmin <  minp) ? tmin : minp;
			maxp = ( tmax >  maxp) ? tmax : maxp;
		}
	}
	else
	{
		minp = real_minp;
		maxp = real_maxp;
	}
	
	$('#minp').html(minp);
	$('#maxp').html(maxp);
	//alert( "minp = " + minp + "; maxp = " + maxp ); 	
}

function ChangeCountPerPages( sel )
{
	var newurl = new String(window.location);
	//alert(newurl);
	var reg=/&pp=(\d+)/i 
	newurl = newurl.replace(reg, '');
	reg=/&offset=(\d+)/i 
	newurl = newurl.replace(reg, '');
	//alert(newurl);
	newurl = newurl + "&pp=" + $(sel).find("option:selected").val();
	window.location = newurl;
}

// --------------------

	var mccur = 0;

	function mcpic_position(w, h)
	{
		var dpic = document.getElementById('pics');
		var body = document.body;
		var docElem = document.documentElement;
		var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
		var InnerHeight = window.innerHeight || docElem.clientHeight || body.clientHeight;
		var ClientWidth = docElem.clientWidth || body.clientWidth;

		var width = (ClientWidth - w)/2;
		var height = (InnerHeight - h)/2 + scrollTop;  
  
		//alert( "width = " + width + "; height = " + height  );

		dpic.style.top = height + 'px';
		dpic.style.left = width + 'px'; 

		dpic.style.display = 'block';
	}

var mcpics = {};

	function mcpic_load( id )
	{	
		mccur = id;

		var url = mcpics[id].url;
		var alt = mcpics[id].alt;
		var w = mcpics[id].w;
		var h = mcpics[id].h;
		var first_el = mcpics[id].first;
		var end_el = mcpics[id].end;

		var dpic = document.getElementById('pics');
		var nw = w + 20;	var nh = h + 50;
		dpic.style.width = nw + 'px';
		dpic.style.height = nh + 'px'; 

		var bpic = document.getElementById('bpic');
		bpic .src = url; 
		bpic .width = w; 
		bpic .height = h;

		var bpicalt =  document.getElementById('bpicalt');
		bpicalt.innerHTML = alt;

		var mcleft = document.getElementById('mcleft');
		var mcright = document.getElementById('mcright');
		mcleft.style.display = 'block';
		mcright.style.display = 'block';

		//alert( "first = " + first_el  + "; end = " + end_el );

		if(  first_el != 0 ) mcleft.style.display = 'none';
		if(  end_el != 0 ) mcright.style.display = 'none'; 
	
		//alert( "nw = " + nw + "; nh = " + nh  );
		mcpic_position(nw, nh);
	}

	function mcfind(arr, picid, increasing) 
	{
		var max_id = 0;

		for (var key in mcpics) { 
			var num = new Number(key);
			if( num > max_id ) max_id = num; 
		}

		var step = increasing ? 1 : -1;
		for(var i=picid+step; i>=0 && i<=max_id; i+=step)
			if( arr[i] ) return i;
	}

	function mcleft()
	{
		mcpic_load( mcfind(mcpics, mccur, false));
	}

	function mcright()
	{
		mcpic_load(mcfind(mcpics, mccur, true));
	}
	


