function admin_select_row(id, color, row)
{
	var cb=document.getElementById('cb_'+id);
	if (cb)
	{
		if (cb.checked)
		{
			cb.checked = 0;
			row.style.backgroundColor = color;
		}
		else
		{
			cb.checked = 1;
			row.style.backgroundColor = '#FF9999';
		}
	}
}

function get_calendar(url, mon, year, calendar_id)
{
	 $("#calendar").load(url, {'n': 1, 'mon': mon, 'year': year});

}
function check_admin_login()
{
	$.post("./admin_auth.php", {n:"3"}, function(xml){ 
		 var res = $(xml).find('to').text();
		 if (res == 1)
		 {
			$('form:#main_form').submit();
		 }
		 else
		 {
			$('#login_form1').show();
			$('#login_form2').show();
			try {
			document.admin_login_form.login.focus();
			} catch (e) {}
		 }
	});
}

function do_admin_login(login, pass)
{
	$.post("./admin_auth.php", {n:"1", login: login, pass: pass}, function(xml){ 
		  var res = $(xml).find('auth').text();
		  if (res == 1)
		  {
			$('#login_form1').hide();
			$('#login_form2').hide();

			var main_form = document.getElementById('main_form');
			if (main_form)
			{
				main_form.submit();
			}
			else
			{
				window.location.reload();
			}
		  }
		  else
		  {
			$('#login_form1').show();
			$('#login_form2').show();
			try {
			document.admin_login_form.login.focus();
			} catch (e) {}
			alert("Неверный логин или пароль, повторите ввод");
		  }
	});
     
}

function do_admin_logout()
{
	$.post("./admin_auth.php", {n:"2"}, function(xml){ 
		window.location.reload();
	});
}

function wait_banner(banner)
{
	var pos = bfx[banner]['pos'];
	var count = bfx[banner]['count'];
	var bw = bfx[banner]['width'];
	var bh = bfx[banner]['height'];

	var pos_prev = pos-1;
	if (pos_prev < 0)
	{
		pos_prev = count-1;
	}

	HideBlock('bbb_'+banner+'_'+pos_prev);

	$('div.bbb_'+banner+'_'+pos_prev).css('z-index', 0);

	$('div.bbb_'+banner+'_'+pos_prev).animate({left:0, top:0, width: bw, height:bh, opacity:1}, 0);

	setTimeout('switch_banner('+banner+')', bfx[banner][pos]['wait']);	
}

function switch_banner(banner)
{
	var count = bfx[banner]['count'];

	var pos = bfx[banner]['pos'];

	var pos_next = pos+1;
	if (pos_next >= count)
	{
		pos_next = 0;
	}

	bfx[banner]['pos'] = pos_next;

	if (bfx[banner][pos]['speed'] == 0)
	{
		HideBlock('bbb_'+banner+'_'+pos);
		ShowBlock('bbb_'+banner+'_'+pos_next);

		setTimeout('switch_banner('+banner+')', bfx[banner][pos]['wait']);	
	}
	else
	{
		$('div.bbb_'+banner+'_'+pos).css('z-index', 2);
		$('div.bbb_'+banner+'_'+pos_next).css('z-index', 1);

		ShowBlock('bbb_'+banner+'_'+pos_next);
		$('div.bbb_'+banner+'_'+pos).animate(bfx[banner][pos]['effects'], bfx[banner][pos]['speed'], 'swing', function(){wait_banner(banner);});
	}
}

function show_for_edit(rowID_1, rowID_2, link_id)
{
	var i = 1;
	while(other_param = document.getElementById("param_group_"+i))
	{
		other_param.style.display = 'none';
		i++;
	}
	if (rowID_2)
	{
		row_2 = document.getElementById(rowID_2);
		row_2.style.display = '';
	}
	row = document.getElementById(rowID_1);
	row.style.display = '';
	
	var j = 1;
	while(other_link = document.getElementById("link_"+j))
	{
		other_link.style.background = '#DDDDDD';
		other_link.style.color = '';
		j++;
	}
	active_part = document.getElementById(link_id);
	active_part.style.background = '#999999';
	active_part.style.color = '#ffffff';
}

function cloneCombo(place_id, src_combo_id, selected_value, id_value, name_value, combo_filter, childfrom_value, combo_width)
{
	var place = document.getElementById(place_id);
	var src_combo = document.getElementById(src_combo_id);
	if (src_combo && place)
	{
		var clone = src_combo.cloneNode(true);

		clone.setAttribute('id', id_value);
		clone.setAttribute('name', name_value);
		clone.setAttribute('selvalue', selected_value);
		if (childfrom_value)
		{
			var clone2 = src_combo.cloneNode(true);
			clone2.setAttribute('id', id_value);
			clone2.setAttribute('name', name_value);
			clone2.setAttribute('childfrom', '');
			child_values[name_value] = clone2;

			clone.setAttribute('childfrom', childfrom_value);
		}
        
		clone.selectedIndex = 0;
		if (selected_value)
		{
			for (var i = 0; i < clone.options.length; i++)
			{
				if (clone.options[i].value == selected_value)
				{
					try {
					clone.focus();
					} catch (e) {}
					clone.selectedIndex = i;
					clone.onchange();
					break;
				}
			}
		}
		place.appendChild(clone);
		clone.style.display = '';
		clone.style.width = combo_width;
		clone.style.height = '21';
		if (combo_filter && 0)
		{
			clone.style.filter = 'alpha(opacity: 30); opacity: 0.3';
		}
		return clone;
	}
	return null;
}

function photo_change2(photoNum)
{
	var fileInput = document.getElementById('photo_'+photoNum+'_fi');
	var pic = document.getElementById('photo_'+photoNum+'_pi');
	var cb = document.getElementById('photo_'+photoNum+'_en');
	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; }
	pic.innerHTML = 'Выбран файл<br><b>'+n+'</b>';
	cb.checked = true;
	cb.onchange();
}

function DoPhoto(cb, varNum)
{
	varNumNext = Number(varNum) + 1;
	if (varNumNext < 10)
		varNumNext = String(0) + String(varNumNext);
	else
		varNumNext = String(varNumNext);

	if (cb.checked)
	{
		row = document.getElementById("rowphoto_"+varNumNext);
		if (row)
		{
			cb = document.getElementById("photo_"+varNumNext+"_en");
			row.style.display = '';
			if (!cb.checked)
			{
				row.style.opacity = '0.3';
				row.style.filter = 'alpha(opacity: 30)';
			}
		}
		row = document.getElementById("rowphoto_"+varNum);
		row.style.opacity = '1';
		row.style.filter = 'alpha(opacity: 100)';
	}
	else
	{
		row = document.getElementById("rowphoto_"+varNum);
		row.style.opacity = '0.3';
		row.style.filter = 'alpha(opacity: 30)';
	}
}

function DoCat(combo)
{
	varNum = combo.name.substr(10,2);
	varNumNext = Number(varNum) + 1;
	if (varNumNext < 10)
		varNumNext = String(0) + String(varNumNext);
	else
		varNumNext = String(varNumNext);

	if (combo.value > 0)
	{
		row = document.getElementById("rowcat_"+varNumNext);
		if (row && row.style.display)
		{
			row.style.display = '';
			row.style.opacity = '0.3';
			row.style.filter = 'alpha(opacity: 30)';
		}
		row = document.getElementById("rowcat_"+varNum);
		row.style.opacity = '1';
		row.style.filter = 'alpha(opacity: 100)';
	}
	else
	{
		row = document.getElementById("rowcat_"+varNum);
		row.style.opacity = '0.3';
		row.style.filter = 'alpha(opacity: 30)';
	}
}

function DoParam(cb, varNum, varNumNext, blockNum)
{
	var copyFromPrev = 0;
	if (cb.checked)
	{
		if (varNumNext != "")
		{
			row = document.getElementById("row"+blockNum+"_"+varNumNext);
			cb = document.getElementById("par"+blockNum+"_"+varNumNext+"_en");
			row.style.display = '';
			if (!cb.checked)
			{
				row.style.opacity = '0.3';
				row.style.filter = 'alpha(opacity: 30)';
			}
		}
		row = document.getElementById("row"+blockNum+"_"+varNum);
		row.style.opacity = '1';
		row.style.filter = 'alpha(opacity: 100)';

		var varNumPrev = varNum - 1;
		if (varNumPrev > 0)
		{
			if (varNumPrev < 9)
			{
				varNumPrev = '0'+varNumPrev;
			}

			// скопировать значения параметров из varNumPrev в varNum
			copyFromPrev = 1;
		}
	}
	else
	{
		row = document.getElementById("row"+blockNum+"_"+varNum);
		row.style.opacity = '0.3';
		row.style.filter = 'alpha(opacity: 30)';
	}

	var p;
	var p2;
	p = document.getElementById("par"+blockNum+"_"+varNum+"_en");
	p.style.filter = row.style.filter;

	p = document.getElementById("par"+blockNum+"_"+varNum+"_so");
	p.style.filter = row.style.filter;

	for(var i = 0; i<20; i++)
	{
		var ii;
		if (i < 10) { ii = '0'+i; } else { ii = i; }
		p = document.getElementById("par"+blockNum+"_"+varNum+"_"+ii);
		if (p)
		{
			p.style.filter = row.style.filter;
	        
			if (copyFromPrev==1)
			{
				p = document.getElementById("par"+blockNum+"_"+varNum+"_"+ii+"_val");
				p2 = document.getElementById("par"+blockNum+"_"+varNumPrev+"_"+ii+"_val");
				if (p && p2)
				{
					try {
					p.focus();
					} catch (e) {}
					p.value = p2.value;
					p.selectedIndex = p2.selectedIndex;
					p.onchange();
				}
			}
		}
	}
}

function EnableAllControls()
{
	values = document.getElementsByTagName("input");
	for (var i = 0; i < values.length; i++)
	{
		values[i].removeAttribute("disabled");
	}

	values = document.getElementsByTagName("select");
	for (var i = 0; i < values.length; i++)
	{
		values[i].removeAttribute("disabled");
	}

	values = document.getElementsByTagName("textarea");
	for (var i = 0; i < values.length; i++)
	{
		values[i].removeAttribute("disabled");
	}

	values = document.getElementsByTagName("checkbox");
	for (var i = 0; i < values.length; i++)
	{
		values[i].removeAttribute("disabled");
	}

	return true;
}

function CopyBlock(from_name, to_name)
{
	from_block = document.getElementById(from_name);
	to_block = document.getElementById(to_name);
	if (from_block && to_block)
		to_block.innerHTML = from_block.innerHTML;
}

function MoveBlock(from_name, to_name)
{
	from_block = document.getElementById(from_name);
	to_block = document.getElementById(to_name);
	if (from_block && to_block)
	{
		to_block.innerHTML = from_block.innerHTML;
		from_block.innerHTML = "";
	}
}

function OpenBuyMode()
{
	var cmp_form = document.getElementById('buy_form');
	if (cmp_form)
	{
		cmp_form.submit();
		return false;
	}
	return true;
}

function OpenCompareMode()
{
	var cmp_form = document.getElementById('compare_form');
	if (cmp_form)
	{
		cmp_form.submit();
		return false;
	}
	return true;
}

function SelectColor(div_id)
{
	$(document).ready(function(){
		$('#'+div_id).ColorPicker({
			color: document.getElementById(div_id+'_value').value,
			onChange: function (hsb, hex, rgb) {
				$('#'+div_id+' div').css('backgroundColor', '#' + hex); 
				document.getElementById(div_id+'_value').value = '#' + hex;}
		});
	});
}

function open_parent(addr)
{
	window.opener.location.href = addr;
	window.close();
}

function GetAbsolutePos(obj)
{
	var x = 0;
	var y = 0;
	var p = obj;
	while (p)
	{
		x += p.offsetLeft;
		y += p.offsetTop;
		p = p.offsetParent;
	}
	return {"x":x,"y":y};
}

var mouseX;
var mouseY;

var menu = null; menu_button = null;

/* direction: 1-left, 2-right, 3-down, 4-up */
function ShowMenu(blockName, btn, direction)
{
	if (menu)
	{
		menu.style.display = 'none';
		menu = null;
		menu_button = null;
	}

	var block = document.getElementById(blockName);
	if (block && btn)
	{
		var p = GetAbsolutePos(btn);
		block.style.display = '';
		if (direction == 1)
		{
			block.style.left = p.x - btn.offsetWidth;
			block.style.top = p.y;
		}
		if (direction == 2)
		{
			block.style.left = p.x + btn.offsetWidth;
			block.style.top = p.y;
		}
		if (direction == 3)
		{
			block.style.left = p.x-30;
			block.style.top = p.y + btn.offsetHeight+5;
		}
		if (direction == 4)
		{
			block.style.left = p.x;
			block.style.top = p.y - btn.offsetHeight;
		}
		menu = block;
		menu_button = btn;
	}
}

function CheckMenu()
{
	if (!menu) return;

	var p = GetAbsolutePos(menu);
	var d = 50;
	if ((mouseX < p.x - d) || (mouseX > p.x + menu.offsetWidth + d) || (mouseY < p.y - d) || (mouseY > p.y + menu.offsetHeight + d))
	{
		var p = GetAbsolutePos(menu_button);
		if ((mouseX < p.x - d) || (mouseX > p.x + menu.offsetWidth + d) || (mouseY < p.y - d) || (mouseY > p.y + menu.offsetHeight + d))
		{
			menu.style.display = 'none';
			menu = null;
		}
	}
}

function selectSearchWhat(search_form_name, search_what)
{
	var search_form;

	for(var i=-5; i<10; i++)
	{
		if (i == search_what)
			ShowBlock(search_form_name+"search_form_"+i);
		else
			HideBlock(search_form_name+"search_form_"+i);
	}

	var qq = document.getElementById(search_form_name+"search_what_"+search_what);
	if (qq)
	{
		for (i = 0; i<qq.options.length; i++)
		{
			if (qq.options[i].value == search_what)
			{
				try {
				qq.focus();
				} catch (e) {}
				qq.selectedIndex = i;
				qq.onchange();
				break;
			}
		}
	}
}

function comboOrderConditionChange(combo)
{
	$("select[childfrom^='"+combo.id+"']").each(function (i) {

		while (this.options.length)
		{
			this.remove(0);
		}
		values = child_values[this.name].getElementsByTagName("option");

		this.selectedIndex = 0;
		for (var i = 0; i < values.length; i++)
		{
			if ((values[i].className == "") || (values[i].className == 0) || !values[i].className || (values[i].className == combo.value))
			{
				this.appendChild(values[i].cloneNode(true));

				if (!this.selectedIndex)
				{
					if (this.getAttribute("selvalue") && (values[i].value == this.getAttribute("selvalue")))
					{
						try {
						this.focus();
						} catch (e) {}
						this.selectedIndex = this.options.length-1;
						this.onchange();
					}
					if (this.getAttribute("seltext") && (values[i].text == this.getAttribute("seltext")))
					{
						try {
						this.focus();
						} catch (e) {}
						this.selectedIndex = this.options.length-1;
						this.onchange();
					}
				}
			}
		}

		if (this.options.length > 1)
			this.disabled = false;
		else
			this.disabled = true;
		comboOrderConditionChange(this);
	});
	for(var i = 0; i < combo.options.length; i++)
	{
		var v = combo.options[i].value;
		var nv = -combo.options[i].value;

		if (v)
		if (combo.selectedIndex == i)
		{
			$("tr[rel^='transpay_"+v+"x']").css("display", "");
			$("tr[rel^='transpay_"+nv+"x']").css("display", "none");
		}
		else
		{
			$("tr[rel^='transpay_"+v+"x']").css("display", "none");
			$("tr[rel^='transpay_"+nv+"x']").css("display", "");
		}
	}
}

function searchReset(search_form_name, product_type)
{
	var search_param;

	search_param = document.getElementById(search_form_name+"search_category_"+product_type);
	if (search_param != null)
	{
		search_param.value = "";
	}

	search_param = document.getElementById(search_form_name+"search_text_"+product_type);
	if (search_param != null)
	{
		search_param.value = "";
	}

	search_param = document.getElementById(search_form_name+"search_stock_"+product_type);
	if (search_param != null)
	{
		search_param.checked = "";
	}

	search_param = document.getElementById(search_form_name+"search_min_price_"+product_type);
	if (search_param != null)
	{
		search_param.value = "";
	}

	search_param = document.getElementById(search_form_name+"search_max_price_"+product_type);
	if (search_param != null)
	{
		search_param.value = "";
	}

	for(var i=0; i<50; i++)
	{
		search_param = document.getElementById(search_form_name+"search_param_"+product_type+"_var0_"+i+"_1");
		if (search_param != null)
		{
			search_param.value = "";
		}
		search_param = document.getElementById(search_form_name+"search_param_"+product_type+"_var0_"+i+"_2");
		if (search_param != null)
		{
			search_param.value = "";
		}		
		search_param = document.getElementById(search_form_name+"search_param_"+product_type+"_var1_"+i+"_1");
		if (search_param != null)
		{
			search_param.value = "";
		}
		search_param = document.getElementById(search_form_name+"search_param_"+product_type+"_var1_"+i+"_2");
		if (search_param != null)
		{
			search_param.value = "";
		}		
	}
}

var PreloadedImages = new Array();

function PreloadImages()
{
	for(i=0; i<PreloadImages.arguments.length; i++)
	{
		k = PreloadedImages.length-1;
		PreloadedImages[k] = new Image();
		PreloadedImages[k].src = PreloadImages.arguments[i];
	}	
}

function NoAccess()
{
	alert('Извините, у Вас нет доступа к этому разделу');
}

function PlayMP3(mp3_num, name, default_name)
{
	var player = document.getElementById("mp3_player");
	var status = document.getElementById("mp3_status");
	if (mp3_num)
	{
		if (status)
		{
			status.innerHTML = 'Воспроизведение: '+name+' <a href="#" onclick="PlayMP3(0,\'\',\''+default_name+'\'); return false;"><b>СТОП</b></a>';
		}
		player.innerHTML = '<embed allowScriptAccess="never" src="/userfiles/mp3player/mp3player.swf" align="middle" menu="false" quality="high" bgcolor="Transparent" width="2" height="2" name="index" allowScriptAccess="never" type="application/x-shockwave-flash"  wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="playlist=/xml/'+mp3_num+'" />';
	}
	else
	{
		if (status)
		{
			status.innerHTML = default_name;
		}
		player.innerHTML = '&nbsp;';
	}
}

function dynamicSelect(id1, id2)
{
	if (document.getElementById && document.getElementsByTagName) {
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		var clone = sel2.cloneNode(true);
		var clonedOptions = clone.getElementsByTagName("option");
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		}
	}
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions)
{
	while (sel2.options.length)
	{
		sel2.remove(0);
	}
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");

	for (var i = 0; i < clonedOptions.length; i++)
	{
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2))
		{
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}


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 setOpacity(element, opacity)
{
	var e = document.getElementById(element);
	if (e)
	{
		if (opacity <= 0)
		{
			e.style.display = 'none';
		}
		else
		{
			e.style.opacity = opacity/100;
			e.style.filter = 'alpha(opacity: '+opacity+')';
			e.style.display = '';
		}
	}
}

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 ShowBlocks(propName, propValue)
{
	$("["+propName+"^='"+propValue+"']").css("display", "");
}

function HideBlocks(propName, propValue)
{
	$("["+propName+"^='"+propValue+"']").css("display", "none");
}

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)
			{
				try {
				block.focus();
				} catch (e) {}
				block.select();
			}
		}
	}
	else
	{
		block.style.display = 'none';
		if (plus)
		{
			block = document.getElementById(blockName+"_expand");
			if (block)
			{
				block.innerHTML = "+";
			}
		}
	}
}

function ShowHideBlock3(blockName, plus, selectName)
{
	var block = document.getElementById(blockName);
	if (block.style.display == 'none')
	{
		block.style.display = '';
		if (plus)
		{
			block = document.getElementById(blockName+"_expand1");
			if (block)
			{
				block.style.display = '';
			}
			block = document.getElementById(blockName+"_expand2");
			if (block)
			{
				block.style.display = 'none';
			}
		}
		if (selectName != "")
		{
			block = document.getElementById(selectName);
			if (block)
			{
				try {
				block.focus();
				} catch (e) {}
				block.select();
			}
		}
	}
	else
	{
		block.style.display = 'none';
		if (plus)
		{
			block = document.getElementById(blockName+"_expand1");
			if (block)
			{
				block.style.display = 'none';
			}
			block = document.getElementById(blockName+"_expand2");
			if (block)
			{
				block.style.display = '';
			}
		}
	}
}

var traversal = typeof document
                           .createElement('div')
                               .childElementCount != 'undefined';

var next = traversal ? function(node) {
    return node.nextElementSibling;
} : function(node) {
    while(node = node.nextSibling) if(node.nodeType == 1) break;
    return node;
};
var previous = traversal ? function(node) {
    return node.previousElementSibling;
} : function(node) {
    while(node = node.previousSibling) if(node.nodeType == 1) break;
    return node;
};

function ShowHideBlock2(blockName)
{
	var new_vis;
	var block = document.getElementById(blockName+"_expand");
	if (block)
	{
		if (block.innerHTML == "+")
		{
			block.innerHTML = "-";
			new_vis = "";
		}
		else
		{
			block.innerHTML = "+";
			new_vis = "none";
		}
	}

	var block = document.getElementById(blockName);
	var level = block.getAttribute("level");

	if (new_vis == "")
	{
		do
		{
			block = next(block);
			if (block.getAttribute("level")-1 == level)
			{
				block.style.display = new_vis;
			}
		}
		while (block.getAttribute("level") != level);
	}
	else
	{
		do
		{
			block = next(block);
			if (block.getAttribute("level") != level)
			{
				block.style.display = new_vis;
				var plus = document.getElementById(block.getAttribute("id")+"_expand");
				if (plus)
				{
					plus.innerHTML = "+";
				}
			}
		}
		while (block.getAttribute("level") != level);
	}
}

var bfx = Array();
var price = Array();
var old_price = Array();
var stock = Array();
var link = Array();
var child_values = Array();
var compare = Array();
var compare2 = Array();

function SetValue(name, value, def)
{
	if (value == undefined)
	{
		value = def;
	}
	x = document.getElementById(name);
	if (x)
		x.innerHTML = value;
}

function UpdatePrice(productID)
{
	var x;
	var values = '';
	x = document.getElementById('sel_'+productID);
	SetValue('stock_'+productID, stock[productID+'_'+x.value], '');
	SetValue('price_'+productID, price[productID+'_'+x.value], '0');
	SetValue('old_price_'+productID, old_price[productID+'_'+x.value], ' ');

	SetValue('link_'+productID, link[productID+'_'+x.value], ' ');
	SetValue('compare_link_'+productID, compare[productID+'_'+x.value], '');
	SetValue('compare2_link_'+productID, compare2[productID+'_'+x.value], '');
}

function UpdatePrice2(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], '');
	SetValue('old_price_'+productID, old_price[productID+values], ' ');

	SetValue('link_'+productID, link[productID+values], ' ');
	SetValue('compare_link_'+productID, compare[productID+values], '');
	SetValue('compare2_link_'+productID, compare2[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
		}
	}
}

function ClearSelectectionIfExists(D)
{
	var X=(D.target||D.srcElement);
	if (X)
	{
		var E=X.tagName;
		if (E=="INPUT" || E=="TEXTAREA") return;

		C=document.getElementById("invisible_edit");
		if (C)
		{	
			try {
			C.focus();
			} catch (e) {}
			C.select();
		}
	}
}

document.onkeydown=keydown;

function selectFirst()
{
	var x = document.getElementById('focus');
	if (x)
	{
		try {
		x.focus();
		} catch (e) {}
		x.select();
	}
}

function selectById(id)
{
	var x = document.getElementById(id);
	if (x)
	{
		try {
		x.focus();
		} catch (e) {}
		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=200,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_admin_print(title, config_url)
{
	var width = 800;//screen.availWidth-200;
	var height = 600;//screen.availHeight-100;

	x = (screen.availWidth-width)/2;
	y = (screen.availHeight-height)/2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open("",'admin_print','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>"+title+"</title>");
	newWin.document.writeln("<link rel=STYLESHEET href='http://"+config_url+"/images/backend/style-backend.css' type='text/css'>");
	newWin.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>");
	newWin.document.writeln("</head>");
    	newWin.document.writeln("<body bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln(document.getElementById('main_div').innerHTML);
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
	newWin.print();
}

function open_picture_print(picture)
{
	var width = 800;
	var height = 600;

	x = (screen.availWidth-width)/2;
	y = (screen.availHeight-height)/2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open("",'admin_print','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>Печать</title>");
	newWin.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>");
	newWin.document.writeln("</head>");
    	newWin.document.writeln("<body bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln("<img src='"+picture+"'/>");
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
	newWin.print();
}

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'>");
	newWin.document.writeln("<script type='text/javascript' src='http://api-maps.yandex.ru/1.1/index.xml?key="+yandex_map_key+"'></script>");
	newWin.document.writeln("<script type='text/javascript' src='/1js.php'></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)
	{
		window.location=where;
	}
}

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",
		blank_text: "<br>(откроется в новом окне)",
		newline_entity: "<br>",
		max_width: 0,
		delay: 100,
		skip_tags: ["link", "style"]
	},

	t: document.createElement("DIV"),
	c: null,
	g: false,
	canvas: null,

	m: function(e){
		var x = window.event ? event.clientX + tooltip.canvas.scrollLeft : e.pageX;
		var y = window.event ? event.clientY + tooltip.canvas.scrollTop : e.pageY;
		mouseX = x;
		mouseY = y;
		CheckMenu();
		if (tooltip.g){
			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);
}





