////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////																																	////////
////////								Ñèñòåìà óïðàâëåíèÿ Èíòåðíåò-êàòàëîãîì òîâàðîâ														////////
////////									MininPortalSystem (WebCMS): catalogue															////////
////////			ÂÑÅ ÏÐÀÂÀ ÍÀ ÐÀÑÏÐÎÑÒÐÀÍÅÍÈÅ È ÈÇÌÅÍÅÍÈÅ ËÞÁÛÕ ×ÀÑÒÅÉ ÊÎÄÀ ÏÐÈÍÀÄËÅÆÀÒ ÀÂÒÎÐÓ È ÊÎÌÏÀÍÈÈ WEB-ARENA 						////////
////////			ÈÑÏÎËÜÇÓß ÝÒÎÒ ÏÐÎÄÓÊÒ (ÈËÈ ÅÃÎ ×ÀÑÒÈ) Â ÏÐÎÅÊÒÀÕ ÁÅÇ ÐÀÇÐÅØÅÍÈß ÏÐÀÂÎÎÁËÀÄÀÒÅËÅÉ, ÂÛ ÍÀÐÓØÀÅÒÅ	ÇÀÊÎÍ!					////////			
////////					ÏÎ ÂÑÅÌ ÂÎÏÐÎÑÀÌ ÎÁÐÀÙÀÉÒÅÑÜ ÏÎ ÒÅËÅÔÎÍÀÌ (495) 723-45-69, (498) 601-24-22										////////
////////																																	////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// JavaScript Document
function get_id(id)
{
	return document.getElementById(id);
}

function get_val(id)
{
return get_id(id).value;
}

function get_sel(id)
{
	return get_id(id).options[get_id(id).selectedIndex].value;
}
function change_focus(id)
{
	document.getElementById(id).focus();
}

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
} 


function show_submenu(cat_id)
{
var cat_div = "menu_" + cat_id;
var now_visibility = get_id(cat_div).style.display;
if (now_visibility=="")
{
	get_id(cat_div).style.display = "none";
}
else
{
	get_id(cat_div).style.display = "";
}
}

function show_help_window(div,img)
{
		function mousePageXY(e)
		{
		  var x = 0, y = 0;
		
		  if (!e) e = window.event;
		
		  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;
		  }
		
		  return {"x":x, "y":y};
		}
var mCur = mousePageXY();
get_id(div).style.top = mCur.y+5 +"px";
get_id(div).style.left = mCur.x+5 +"px";
if (get_id('photo_image').src && get_id('photo_image').src!=img)
{
	get_id('photo_image').src = img;
}

}

var scroll_action = "";
var scroll_div = "";
function scroll_start(action,div)
{
	scroll_action = action;
	scroll_div = div;
	scroll_left();
}
function scroll_left()
{
	if (scroll_action=="") return;
	if (scroll_action=="+")
	{
get_id(scroll_div).scrollLeft = get_id(scroll_div).scrollLeft+1;
	}
	else
	{
	get_id(scroll_div).scrollLeft = get_id(scroll_div).scrollLeft-1;	
	}
	setTimeout("scroll_left()",10);
}

////////////////////////////////////////////////// ÊÀÒÀËÎÃ
/////////// ÂÛÄÅËÈÒÜ ÂÑÅ
function select_all()
{
	var inputs = document.getElementsByTagName('input');
		 for (var i = 0; i < inputs.length; i++) 
	 						  {
								  if (inputs[i].id=="check_item")
								  	{
										inputs[i].checked=true;
									}
							  }
	
}

function unselect_all()
{
	var inputs = document.getElementsByTagName('input');
		 for (var i = 0; i < inputs.length; i++) 
	 						  {
								  if (inputs[i].id=="check_item")
								  	{
										inputs[i].checked=false;
									}
							  }
	
}

function photo_next(selected_photo, photos, id)
{
	var big_img = new Image();	
	var big_src = photos[selected_photo].replace("_thumb", "");
    big_img.src = "catalog_photos/item_"+id+"/"+big_src;
	get_id('photo').innerHTML="<img src='catalog_photos/item_"+id+"/thumb/"+photos[selected_photo]+"' onClick=\"tobig(this, widths[selected_photo], heights[selected_photo]);\">";						
	var next = selected_photo+1;
						get_id('photo_now').innerHTML = next;
						if (typeof photos[next]=='undefined')
							{
							get_id('next_photo').innerHTML = '';
							}
							
							var prev = selected_photo-1;
						if (typeof photos[prev]!='undefined')
							{
							get_id('prev_photo').innerHTML = ' &laquo; ';
							}
}

function photo_prev(selected_photo, photos, id)
{
	var big_img = new Image();	
	var big_src = photos[selected_photo].replace("_thumb", "");
    big_img.src = "catalog_photos/item_"+id+"/"+big_src;
	get_id('photo').innerHTML="<img src='catalog_photos/item_"+id+"/thumb/"+photos[selected_photo]+"' onClick=\"tobig(this, widths[selected_photo], heights[selected_photo]);\">";

						var next = selected_photo+1;
						get_id('photo_now').innerHTML = next;
						if (typeof photos[next]!='undefined')
							{
							get_id('next_photo').innerHTML = ' &raquo; ';
							}
							
							var prev = selected_photo-1;
						if (prev<0 || typeof photos[prev]=='undefined')
							{
							get_id('prev_photo').innerHTML = '';
							}
}

function check_next_prev()
{
						var next = 1;
						if (typeof photos[next]=='undefined')
							{
							get_id('next_photo').innerHTML = '';
							}
}
//////Ïëàâíîå óâåëè÷åíèå
function getElementPosition(elem)
{
    
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    
    var l = 0;
    var t = 0;
    
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
var small_width;
var small_height;
var big_width;
var big_height;
var next_open = "";
var next_w = "";
var next_h = "";
function tobig(img, width, height) { 
if (document.getElementById('zoomed'))
{
tosmall();
next_open = img;
next_w = width;
next_h = height;
}
else
{
next_open = "";
next_w = "";
next_h = "";
pos = getElementPosition(img); 
var left = pos.left; 
var top = pos.top;

 imgOld = img; 
    rwidth = width; 
    rheight = height;
  img = document.createElement("img"); 
  var pict = imgOld.src;
  pict = pict.replace("thumb/", "");
   pict = pict.replace("_thumb", "");
    img.src = pict; 
    img.style.cursor = "pointer"; 
    document.body.appendChild(img); 
	img.style.position ="absolute";
img.id = "zoomed";
small_width = imgOld.width;
small_height = imgOld.height;
big_width = width;
big_height = height;
img.width = small_width;
img.height = small_height;
 img.style.left = left;
 img.style.top = top;
 img.attachEvent("onclick",tosmall);
move_to_big();
}
}
var allow = true;
function move_to_big()
{
 
var ratio_w = small_width/small_height;
	var ratio_h = 1;
	if (small_height > small_width) 
	{
	 ratio_h = small_height/small_width;
	 ratio_w = 1;
	
	}
obj = document.getElementById('zoomed');
if (obj.width < big_width && obj.height < big_height)
	{

	obj.style.left = parseInt(obj.style.left)-Math.round(10*ratio_w/2) + "px";
	obj.style.top =  parseInt(obj.style.top)-Math.round(10*ratio_h/2)  + "px";
	obj.width = Math.round(obj.width + 10*ratio_w);
	obj.height = Math.round(obj.height + 10*ratio_h);
	setTimeout('move_to_big()',5);
	 allow = false;
	}
	else
	{
	 allow = true;
	}

}

function move_to_small()
{
	var ratio_w = small_width/small_height;
	var ratio_h = 1;
	if (small_height > small_width) 
	{
	 ratio_h = small_height/small_width;
	 ratio_w = 1;
	}
obj = document.getElementById('zoomed');
if (obj.width > small_width && obj.height > small_height)
	{
	obj.style.left = parseInt(obj.style.left)+Math.round(10*ratio_w/2) + "px";
	obj.style.top =  parseInt(obj.style.top)+Math.round(10*ratio_h/2)  + "px";
	obj.width = Math.round(obj.width - 10*ratio_w);
	obj.height = Math.round(obj.height - 10*ratio_h);
	setTimeout('move_to_small()',5);
	}
	else
	{
	document.body.removeChild(obj);
	allow=true;
	if (next_open!="")
		{
		tobig(next_open, next_w, next_h);
		}
	}
}

function tosmall()
{
img = document.getElementById('zoomed');
if(allow)
{
allow=false;
move_to_small(img);
}
}

function basket_total_price(ids)
{
	var total_price=0;
for (i=0;i<ids.length;i++)
	{
		var cost_id = "cost_"+ids[i]; 
		var q_id = "q_"+ids[i];
		total_price = total_price + get_id(cost_id).value * get_id(q_id).value;
	}
	get_id('total_price').innerHTML = total_price.toFixed(2);
}

function open_consult() 
{
	
	var url = "http://www.etalonpribor.ru/consult.php";
	myWin= open(url, "displayWindow", "width=400,height=600,status=no,toolbar=no,menubar=no, titlebar=no, resizable=no, location=no, scrollbars=no");
}

//////////////// ÔÎÐÌÀ ÇÀÊÀÇÀ
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:window.innerHeight;

}
function getBodyScrollTop()
{
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft()
{
return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}
var fly_block ="";
function move_block()
{
var order_top = parseInt(get_id(fly_block).style.top);
var need_pos = getBodyScrollTop() -200 +Math.ceil(getClientHeight()/2);
//alert(order_top);
//alert(need_pos);
if (order_top < getBodyScrollTop()-500)
        {
        get_id(fly_block).style.top = getBodyScrollTop()-500 +'px';
        }
        if (order_top > getBodyScrollTop()+getClientHeight()-100)
        {
        get_id(fly_block).style.top =  getBodyScrollTop()+getClientHeight()-100 +'px';
        }
if (order_top<need_pos-15)
        {
        get_id(fly_block).style.top = parseInt(get_id(fly_block).style.top)+12+'px';
        }
        else if (order_top>need_pos+15)
        {
        get_id(fly_block).style.top = parseInt(get_id(fly_block).style.top)-12+'px';
        }
        else
        {
        return;
        }
                setTimeout("move_block()",5);
}
function quick_order(name)
{
get_id('order_fly').style.visibility= 'visible';
setOpacity();
get_id('q_order_text').value= name;
fly_block = "order_fly";
get_id('div_call_me').style.visibility = 'hidden';
move_block();
}
function call_me_form()
{
get_id('order_fly').style.visibility= 'hidden';
setOpacity();
fly_block = "div_call_me";
get_id('div_call_me').style.visibility = 'visible';
move_block();
}

//////////////////// ÇÀÒÅÌÍÅÍÈÅ
var value = 0;
function setOpacity() {
   value += 8;

   var testObj = document.getElementById('blur_div');

   testObj.style.width = "100%";
  testObj.style.height = document.body.offsetHeight;
   testObj.style.display = "block";
   testObj.style.opacity = value/10;
   testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
   myTimeout = setTimeout("setOpacity()", 1);

   if ((value/10) >= .8) {
      clearTimeout(myTimeout);
   }

}

function removeOpacity() {

   value -= 8;
   var testObj = document.getElementById('blur_div');

   myTimeout2 = setTimeout("removeOpacity()", 1);
   testObj.style.opacity = value/10;
   testObj.style.filter = 'alpha(opacity=' + value*10 + ')';

   if ((value/10) <= 0) {
      testObj.style.display = "none";
      clearTimeout(myTimeout2);
   }

}
////////////////////////////////////////////////
// Ïå÷àòü
var data = "";
function PrintPreview()
{
        data = document.getElementById("print_zone").outerHTML;
        window.open('/print_report.html',null,'target=_blank,status=0,toolbar=0,scrollbars=1,menubar=1');
}

// ïåðåòàñêèâàíèå
var flag=false;
var shift_x;
var shift_y;

function start_drag(itemToMove,e){
if(!e) e = window.event;
flag=true;
shift_x = e.clientX-parseInt(itemToMove.style.left);
shift_y = e.clientY-parseInt(itemToMove.style.top);

if(e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
if(e.preventDefault) e.preventDefault();
else e.returnValue = false;
}

function end_drag(){ flag=false; }

function dragIt(itemToMove,e){
if(!flag) return;
if(!e) e = window.event;
itemToMove.style.left = (e.clientX-shift_x) + "px";
itemToMove.style.top = (e.clientY-shift_y) + "px";

if(e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
if(e.preventDefault) e.preventDefault();
else e.returnValue = false;
}
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:window.innerHeight;

}
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:window.innerWidth;

}
function getBodyScrollTop()
{
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft()
{
return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function center_form()
{
	var need_pos = getBodyScrollTop() -200 +Math.ceil(getClientHeight()/2);
		var need_pos_x = getBodyScrollLeft() -289 +Math.ceil(getClientWidth()/2);
	get_id('drag_form').style.top = need_pos +'px';
	get_id('drag_form').style.left = need_pos_x +'px';
}

function order_form(name)
{
	center_form();
	get_id('pribor_name').innerHTML = name;
	get_id('comment').value = name;
	get_id('drag_form').style.display="";
}


function check_form_stat()
{
	var error = false;
	if (get_val('username_stat') == "" || get_val('username_stat') == "Èâàí Ïåòðîâ")
		{
			get_id('username_stat').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('username_stat').style.borderColor='#ffc903';
		}
		
		if (get_val('firma_stat') == "" || get_val('firma_stat') == "ÎÎÎ “Íàøà ôèðìà”")
		{
			get_id('firma_stat').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('firma_stat').style.borderColor='#ffc903';
		}
		
			if (get_val('phone_stat') == "" || get_val('phone_stat') == "+7 (900) 000-00-00")
		{
			get_id('phone_stat').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('phone_stat').style.borderColor='#ffc903';
		}
		if (error)
		{
			alert('Âû íå çàïîëíèëè îáÿçàòåëüíûå ïîëÿ!');
		}
		else
		{
			get_id('order_f_stat').submit();
		}
}

function check_form()
{
	var error = false;
	if (get_val('username') == "" || get_val('username') == "Èâàí Ïåòðîâ")
		{
			get_id('username').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('username').style.borderColor='#ffc903';
		}
		
		if (get_val('firma') == "" || get_val('firma') == "ÎÎÎ “Íàøà ôèðìà”")
		{
			get_id('firma').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('firma').style.borderColor='#ffc903';
		}
		
			if (get_val('phone') == "" || get_val('phone') == "+7 (900) 000-00-00")
		{
			get_id('phone').style.borderColor='#FF0000';
			error = true;
		}
	else
		{
			get_id('phone').style.borderColor='#ffc903';
		}
		if (error)
		{
			alert('Âû íå çàïîëíèëè îáÿçàòåëüíûå ïîëÿ!');
		}
		else
		{
			get_id('order_f').submit();
		}
}
