function ShowIfChecked(cb, what)
{
	qq = document.getElementById(what);
	if (cb.checked)
	{
		qq.style.opacity = '1';
		qq.style.filter = 'alpha(opacity: 100)';
	}
	else
	{
		qq.style.opacity = '0.3';
		qq.style.filter = 'alpha(opacity: 30)';
	}
}

function photo_change(input_name, info_name, cb_name)
{
	var fileInput = document.getElementById(input_name);
	var info = document.getElementById(info_name);
	var cb = document.getElementById(cb_name);
	var i = fileInput.value.lastIndexOf('\\');
	if (i < 0) { i = fileInput.value.lastIndexOf('/'); }
	var n;
	if (i >= 0) { n = fileInput.value.substring(i+1); } else { n = fileInput.value; }
	info.innerHTML = 'Выбран файл<br><b>'+n+'</b>';
	cb.checked = true;
	cb.onchange();
}

function showTime()
{
	var block = document.getElementById("time");
	vr=new Date();
	block.innerText=vr.getHours()+":"+vr.getMinutes()+":"+vr.getSeconds();
	setTimeout("showTime()",1000)
}

function HideBlock(blockName)
{
	var block = document.getElementById(blockName);
	if (block)
	{
		block.style.display = 'none';	
	}
}

function ShowBlock(blockName)
{
	var block = document.getElementById(blockName);
	if (block)
	{
		block.style.display = '';
	}
}

function ShowHideBlock(blockName, plus, selectName)
{
	var block = document.getElementById(blockName);
	if (block.style.display == 'none')
	{
		block.style.display = '';
		if (plus)
		{
			block = document.getElementById(blockName+"_expand");
			if (block)
			{
				block.innerHTML = "-";
			}
		}
		if (selectName != "")
		{
			block = document.getElementById(selectName);
			if (block)
			{
				block.focus();
				block.select();
			}
		}
	}
	else
	{
		block.style.display = 'none';
		if (plus)
		{
			block = document.getElementById(blockName+"_expand");
			if (block)
			{
				block.innerHTML = "+";
			}
		}
	}
}

var price = Array();
var old_price = Array();
var stock = Array();
var link = Array();

function SetValue(name, value, def)
{
	if (value == undefined)
	{
		value = def;
	}
	x = document.getElementById(name);
	x.innerHTML = value;
}

function UpdatePrice(productID, paramCount)
{
	var x;
	var values = '';
	for(var i=0; i<paramCount; i++)
	{
		x = document.getElementById('sel_'+productID+'_'+i);
		values = values + '_' + x.value;
	}
	SetValue('stock_'+productID, stock[productID+values], 'под заказ');
	SetValue('price_'+productID, price[productID+values], '0 руб.');
	SetValue('old_price_'+productID, old_price[productID+values], ' ');
	SetValue('link_'+productID, link[productID+values], ' ');
}

function keydown(D)
{
	D=D||window.event;
	var A=D.keyCode;
	if (D.ctrlKey)
	{
		var C;

		if (A==37)
		{
			C=document.getElementById("key_left")
		}
		if(A==39)
		{
			C=document.getElementById("key_right")
		}

		if (C)
		{
			location.href=C.href
		}
	}
}

document.onkeydown=keydown;

function selectFirst()
{
	var x = document.getElementById('focus');
	if (x)
	{
		x.focus();
		x.select();
	}
}

function str_replace(search, replace, subject) {
	return subject.split(search).join(replace);
}

function open_link_in_parent(addr)
{
	window.opener.location.href = addr;
	window.close();
}

function open_msg(url)
{
	x = (screen.availWidth-300)/2;
	y = (screen.availHeight-100)/2-20;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open(url,'msg','left='+x+',top='+y+',width=300,height=100,location="no",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="no"');
	newWin.focus();
}

function open_pic(pic, width, height)
{
	height = height + 80;
	x = (screen.availWidth-width)/2;
	y = (screen.availHeight-height)/2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open("",'picture','left='+x+',top='+y+',width='+width+',height='+height+',location="yes",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="yes"');
	newWin.moveTo(x,y);
	newWin.resizeTo(width,height);
	newWin.document.writeln("<html><head><title>"+pic+"</title>");
    	newWin.document.writeln("<style>");
    	newWin.document.writeln("<!--");
    	newWin.document.writeln(".no_border  { border: 0px solid white }");
    	newWin.document.writeln("-->");
    	newWin.document.writeln("</style></head>");
    	newWin.document.writeln("<body bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln("<table border=0 width='100%' height='100%'><tr><td valign='center' align='center'>");
    	newWin.document.writeln("<a href='#' class='no_border' title='Щёлкните чтобы закрыть окно' onClick='self.close()'><img class='no_border' src='"+pic+"'></a>");
    	newWin.document.writeln("</td></tr></table>");
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
}

function open_map(addr, toolbars)
{
	var map = new YMaps.Map(document.getElementById("YMapsID"));

	var gc = new YMaps.Geocoder(addr);
	YMaps.Events.observe(gc, gc.Events.Load, function () {
	    if (this.length()) {
	        map.setBounds(this.get(0).getBounds());
		    var geoResult = this.get(0).getBounds().getCenter();
	
	        var content = document.createElement('span');
	        content.innerHTML = addr;
	        map.openBalloon(geoResult, content);
	    }
	});

	if (toolbars == 1)
	{
		var topLeftPos = new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT, new YMaps.Size(150, 15)),
		    topRightPos = new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(170, 15)),
		    scaleLine = new YMaps.ScaleLine(),
		    curPos = topLeftPos;
	
		map.addControl(scaleLine, curPos);
		map.addControl(new YMaps.TypeControl(), new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT));
		map.addControl(new YMaps.Zoom());
		map.addControl(new YMaps.MiniMap(), new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT));
	}
}

function popup_map(addr)
{
	var width = screen.availWidth;
	var height = screen.availHeight;
	x = 0;
	y = 0;
	newWin = window.open("",'map','left='+x+',top='+y+',width='+width+',height='+height+',location="yes",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="yes"');
	newWin.moveTo(x,y);
	newWin.resizeTo(width,height);
	newWin.document.writeln("<html><head><title>"+addr+"</title>");
	newWin.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>");
	// Є«оз ¤«п www.test2.ru
	newWin.document.writeln("<script type='text/javascript' src='http://api-maps.yandex.ru/1.0/?key=APC2HkoBAAAAokAlZQIAs9_kFdpApO0Ot_Of-Z9Dn2Ui0CgAAAAAAAAAAAA19tpKZ2ejD3XO4eUMTDa1hiHnIw=='></script>");
	// Є«оз ¤«п mlts.ru
//	newWin.document.writeln("<script type='text/javascript' src='http://api-maps.yandex.ru/1.0/?key=ABC2HkoBAAAAamOkAQIAGsPK7y6f7Gd1jQ__4t1vheJLibAAAAAAAAAAAAAkJVm3dB-YN52mz3jFImyXFd137A=='></script>");
	newWin.document.writeln("<script type='text/javascript' src='/images/style/main.js'></script></head>");
    	newWin.document.writeln("<body onload='open_map(\""+addr+"\", 1);' bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln("<div id='YMapsID' style='height:100%; width:100%;'></div>");
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
}

function confirmDelete(question, where)
{
	temp = window.confirm(question);
	if (temp) //delete
	{
		window.location=where;
	}
}

function validate_order(form)
{
/*	if (form.first_name.value=="")
	{
		alert("Вы не указали Ваше имя");
		return false;
	}

	if (form.last_name.value=="")
	{
		alert("Вы не указали Вашу фамилию");
		return false;
	}
*/
	if (form.email.value=="")
	{
		alert("Вы не указали EMail адрес");
		return false;
	}

	if (form.phone.value=="")
	{
		alert("Вы не указали телефон");
		return false;
	}

	if (form.transfer_method.value==0)
	{
		alert("Вы не выбрали способ доставки");
		return false;
	}

	if (form.pay_method.value==0)
	{
		alert("Вы не выбрали способ оплаты");
		return false;
	}

	if (form.zip.value=="")
	{
		alert("Вы не указали почтовый индекс");
		return false;
	}
/*
	if (form.country.value=="")
	{
		alert("Вы не указали страну");
		return false;
	}
*/
	if (form.state.value=="")
	{
		alert("Вы не указали область");
		return false;
	}

	if (form.city.value=="")
	{
		alert("Вы не указали город");
		return false;
	}

	if (form.address.value=="")
	{
		alert("Вы не указали адрес доставки");
		return false;
	}

	return true;
}

function validate_comment(form)
{
	if (form.description.value=="")
	{
		alert("Вы не ввели текст");
		return false;
	}
	if (form.user_name.value=="")
	{
		alert("Вы не указали Ваше имя");
		return false;
	}
	if (form.digits.value=="")
	{
		alert("Вы не ввели цифры с картинки");
		return false;
	}

	return true;
}

function WordCount(text)
{
	words=text.split(" ");
	var count= words.length;
	if ((count > 1) && (words[count-1]=="")) count--;
	if ((count > 0) && (words[0]=="")) count--;
	return count;
}

var tooltip = {

	/* НАЧАЛО НАСТРОЕК */
	options: {
		attr_name: "tooltip", // наименование создаваемого tooltip'ого атрибута
		blank_text: "<br>(откроется в новом окне)", // текст для ссылок с target="_blank"
		newline_entity: "<br>", // укажите пустую строку (""), если не хотите использовать в tooltip'ах многострочность; ежели хотите, то укажите тот символ или символы, которые будут заменяться на перевод строки
		max_width: 0, // максимальная ширина tooltip'а в пикселах; обнулите это значение, если ширина должна быть нелимитирована
		delay: 100, // задержка при показе tooltip'а в миллисекундах
		skip_tags: ["link", "style"] // теги, у которых не обрабатываем атрибуты alt и title
	},
	/* КОНЕЦ НАСТРОЕК */

	t: document.createElement("DIV"),
	c: null,
	g: false,
	canvas: null,

	m: function(e){
		if (tooltip.g){
			var x = window.event ? event.clientX + tooltip.canvas.scrollLeft : e.pageX;
			var y = window.event ? event.clientY + tooltip.canvas.scrollTop : e.pageY;
			tooltip.a(x, y);
		}
	},

	d: function(){
		tooltip.canvas = document.getElementsByTagName(document.compatMode && document.compatMode == "CSS1Compat" ? "HTML" : "BODY")[0];
		tooltip.t.setAttribute("id", "tooltip");
		document.body.appendChild(tooltip.t);
		if (tooltip.options.max_width) tooltip.t.style.maxWidth = tooltip.options.max_width + "px"; // all but ie
		var a = document.all && !window.opera ? document.all : document.getElementsByTagName("*"); // in opera 9 document.all produces type mismatch error
		var l = a.length;
		for (var i = 0; i < l; i++){

			if (!a[i] || tooltip.options.skip_tags.in_array(a[i].tagName.toLowerCase())) continue;

			var tooltip_title = a[i].getAttribute("title"); // returns form object if IE & name="title"; then IE crashes; so...
			if (tooltip_title && typeof tooltip_title != "string") tooltip_title = "";

			var tooltip_alt = a[i].getAttribute("alt");
			var tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip.options.blank_text;
			if (tooltip_title){
				a[i].setAttribute(tooltip.options.attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip.options.blank_text : tooltip.options.blank_text) : tooltip_title);
				if (a[i].getAttribute(tooltip.options.attr_name)){
					a[i].removeAttribute("title");
					if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}else if (tooltip_alt && a[i].complete){
				a[i].setAttribute(tooltip.options.attr_name, tooltip_alt);
				if (a[i].getAttribute(tooltip.options.attr_name)){
					a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}
			if (!a[i].getAttribute(tooltip.options.attr_name) && tooltip_blank){
				//
			}
		}
		document.onmousemove = tooltip.m;
		window.onscroll = tooltip.h;
		tooltip.a(-99, -99);
	},
	
	_: function(s){
		s = s.replace(/\&/g,"&amp;");
		s = s.replace(/\</g,"&lt;");
		s = s.replace(/\>/g,"&gt;");
		return s;
	},

	s: function(e){
		if (typeof tooltip == "undefined") return;
		var d = window.event ? window.event.srcElement : e.target;
		if (!d.getAttribute(tooltip.options.attr_name)) return;
		var s = d.getAttribute(tooltip.options.attr_name);
		if (tooltip.options.newline_entity){
			var s = tooltip._(s);
			s = s.replace(eval("/" + tooltip._(tooltip.options.newline_entity) + "/g"), "<br />");
			tooltip.t.innerHTML = s;
		}else{
			if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
			tooltip.t.appendChild(document.createTextNode(s));
		}
		tooltip.c = setTimeout(function(){
			tooltip.t.style.visibility = 'visible';
		}, tooltip.options.delay);
		tooltip.g = true;
	},

	h: function(e){
		if (typeof tooltip == "undefined") return;
		tooltip.t.style.visibility = "hidden";
		if (!tooltip.options.newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		clearTimeout(tooltip.c);
		tooltip.g = false;
		tooltip.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera 7b workaround!
		else if (o.attachEvent) o.attachEvent("on" + e, a);
			else return null;
	},

	a: function(x, y){
		var w_width = tooltip.canvas.clientWidth ? tooltip.canvas.clientWidth + tooltip.canvas.scrollLeft : window.innerWidth + window.pageXOffset;
		var w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : tooltip.canvas.clientHeight + tooltip.canvas.scrollTop; // should be vice verca since Opera 7 is crazy!

		if (document.all && document.all.item && !window.opera) tooltip.t.style.width = tooltip.options.max_width && tooltip.t.offsetWidth > tooltip.options.max_width ? tooltip.options.max_width + "px" : "auto";
		
		var t_width = tooltip.t.offsetWidth;
		var t_height = tooltip.t.offsetHeight;

		tooltip.t.style.left = x + 0 + "px";
		tooltip.t.style.top = y + 20 + "px";
		
		if (x + t_width > w_width) tooltip.t.style.left = w_width - t_width + "px";
		if (y + t_height > w_height) tooltip.t.style.top = w_height - t_height + "px";
	}
}

Array.prototype.in_array = function(value){
	var l = this.length;
	for (var i = 0; i < l; i++)
		if (this[i] === value) return true;
	return false;
};

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
	if (root.addEventListener) root.addEventListener("load", tooltip.d, false);
	else if (root.attachEvent) root.attachEvent("onload", tooltip.d);
}
