﻿var id_show_menu = 0;
function opnewWin (s, w, h, is_centered)
{	
	if (is_centered == 1)
	{
		var coord = new Array();
		coord = get_center_window_coord(h, w);
		left_pos = coord["x"];
		top_pos = coord["y"];
		winank = window.open(s, "picture", "height=" + h + ",width=" + w + ",,,,,,top=" + top_pos + ",left=" + left_pos);
	}
	else
	{
		winank = window.open (s, "picture", "width= " + w + ", height= " + h);
	}	
}
function show(value)
{
	document.all[value].style.visibility = "visible" 
	val = document.body.scrollTop + event.y + 10
	document.all[value].style.top = val
	val = document.body.scrollLeft + event.x + 10
	document.all[value].style.left = val
}
function hid (value)
{
	document.all[value].style.visibility = "hidden";
}

function change_root(id, topic)
{
	//all_1 = document.all;
//	all_1.root.value = id;
	document.forms['insert_form'].elements['root'].value=id;
	document.forms['insert_form'].elements['topic'].value=topic;
//	all_1.root.focus();
//	document.all["root"].value = id
}
function change_lang(cur_lang)
{
	document.getElementById('lang_' + cur_lang).bgColor = '#993333';
	obj = document.getElementById('div_lang_' + cur_lang);
	obj.innerHTML = cur_lang;
}

function img_change(id, src)
{
	document.getElementById(id).src = src;
}

function show_child(id)
{
	if (id_show_menu != 0 )
	{
		document.getElementById("menu_" + id_show_menu).style.visibility = "hidden";
	}
	if (document.getElementById("menu_" + id) != null){
			document.getElementById("menu_" + id).style.visibility = "visible";
	}
	id_show_menu = id;
}


function show_child_(id, b_root)
{
	obj = document.getElementById('menu_adm_' + id).style;
	pic = document.getElementById('pic_adm_' + id);
	if (obj.visibility == 'hidden')
	{
		obj.visibility = 'visible';
		obj.position = 'static';
		obj.display = 'block';
		if (b_root)
			pic.src = '/_img/arrow_menu2.gif';
		else
			pic.src = '/_img/arrow_menu4.gif';
	}
	else 
	{
		obj.visibility = 'hidden';
		obj.position = 'absolute';
		obj.display = 'none';
		if (b_root)
			pic.src = '/_img/arrow_menu1.gif';
		else 
			pic.src = '/_img/arrow_menu3.gif';
		hide_child_(id, b_root);
	}
	edit_header(id);
}

function hide_child_(root, b_root)
{
	for (var t = 0; t<obj_menu.length; t++)
	{
		if (obj_menu[t][1] == root)
		{
			document.getElementById('menu_adm_' + root).style.visibility = 'hidden';			
			document.getElementById('menu_adm_' + root).style.position = 'absolute';
			document.getElementById('menu_adm_' + root).style.display = 'none';
			if (b_root)
				document.getElementById('pic_adm_' + root).src = '/_img/arrow_menu1.gif';
			else 
				document.getElementById('pic_adm_' + root).src = '/_img/arrow_menu3.gif';
			hide_child_(obj_menu[t][0], false);
		}
	}
}

function find_root(id)
{
	for (var i = 0; i<obj_menu.length; i++)
	{
		if (obj_menu[i][0] == id)
			root = obj_menu[i][1];
	}
	return root;
}

function find_root_type(id)
{
	for (var i = 0; i<obj_menu.length; i++)
	{
		if (obj_menu[i][0] == id)
			root = obj_menu[i][5];
	}
	return root;
}


function hide_child(root, b_root)
{
	for (var t = 0; t<obj_menu.length; t++)
	{
		if (obj_menu[t][1] == root)
		{
			document.getElementById('menu_' + root).style.visibility = 'hidden';
			document.getElementById('menu_' + root).style.position = 'absolute';
			document.getElementById('menu_' + root).style.display = 'none';
			if (b_root)
				document.getElementById('pic_' + root).src = '/_img/arrow_menu1.gif';
			else 
				document.getElementById('pic_' + root).src = '/_img/arrow_menu3.gif';
			hide_child(obj_menu[t][0], false);
		}
	}
}

function create_ID_struct(id,id_struct)
{
	for (i = 0; i<obj_menu.length; i++)
	{
       	var oOption = document.createElement("OPTION");
		document.forms('form_' + id).id_structure.options.add(oOption);
		oOption.innerText = obj_menu[i][2];
		oOption.value = obj_menu[i][0];        
		if (obj_menu[i][0] == id_struct)
			document.forms('form_' + id).id_structure.options[i].selected = true;
	}	
}

function show_drivers(form_name)
{
	for (i = 0; i<drivers_arr.length; i++)
	{
       	var oOption = document.createElement("OPTION");
		form_name.adv_dostavka_slyjba.options.add(oOption);		
		oOption.innerText = drivers_arr[i][0];
		oOption.value = drivers_arr[i][1];
	}
}

function show_forum_title(id)
{
	document.all[id].style.visibility = "visible" 
	val = document.body.scrollTop + event.y + 10
	document.all[id].style.top = val
	val = document.body.scrollLeft + event.x + 10
	document.all[id].style.left = val
}
function hid_forum_title (value)
{
	document.all[value].style.visibility = "hidden";
	document.all[value].style.position = "absolute";
}
//������� ���������� ���������� ������ �������� ���� ����, �������������� �� ������
//h_desc � w_desc ������ � ������ ������������ ����
function get_center_window_coord(h_desc, w_desc)
{
	var coord = new Array("x", "y");
	var swidth=0;
	var sheight=0;
	var left_pos, top_pos;
	h_desc = h_desc || 500;
	w_desc = w_desc || 600;
	if (self.screen) { // for NN4 and IE4
	  swidth = screen.width;
	  sheight = screen.height	  
	} else if (self.java) { // for NN3 with enabled Java
	  var jkit = java.awt.Toolkit.getDefaultToolkit();
	  var scrsize = jkit.getScreenSize();
	  swidth = scrsize.width;
	  sheight = scrsize.height;
	}
	coord["x"] = (swidth/2) - (w_desc/2);
	coord["y"] = (sheight/2) - (h_desc/2);
	return coord;
}
//������� ������ ������� �������� ��������� � ��������� ����
function show_full_description(id)
{	
	var h_desc = 500, w_desc = 600;
	var coord = new Array();
	coord = get_center_window_coord(h_desc, w_desc);
	left_pos = coord["x"];
	top_pos = coord["y"];
	full_desc_obj = window.open( "/products/full_description/" + id + "/", "description","height=" + h_desc + ",width=" + w_desc + ",toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,top=" + top_pos + ",left=" + left_pos);
	full_desc_obj.is_from_ekt = true; //���� �������� � ������ �������� ������ � ���� ������ �� true
	return false;
}
//������� ���������� ������ � ������� (��� ����� ������ �������)
/*function add_in_recycled(id, title, from_full_desc)
{
	if (from_full_desc == 0)
	{
		iframe_form = document.recycled.document.add_product;
		document.getElementById('saved_' + id).style.display = 'block';
		document.getElementById('saved_' + id).style.position = 'static';
	}
	else
	{		
		iframe_form = window.opener.document.recycled.document.add_product;		
	}	
	iframe_form.title.value = title;
	iframe_form.id.value = id;
	iframe_form.amount.value = document.getElementById('amount_' + id).value;
	iframe_form.action.value= "add_product";
	iframe_form.submit();	
}*/
//���������� ������ �� Enter
function is_add(id, title, from_full_desc, amount_in_recycled, by_manager, is_registered, is_from_ekt)
{
	if (window.event.keyCode == 13)
	{			
		add_in_recycled(id, title, from_full_desc, amount_in_recycled, by_manager, is_registered, is_from_ekt)
	}
	else
	{
		return false;
	}
}
//������� ���������� ������ � ������� (�� ������ �������)
/*function add_in_recycled(id, title, from_full_desc, amount_in_recycled, by_manager, is_registered)
{		
	var add_more_goods = false;
	if (amount_in_recycled > 0)
	{
		add_more_goods = window.confirm("���� ������� ������ ��� ���� � ���� ������!\n\t        ʳ������: " + amount_in_recycled + " ��.\n\t           ������ ��?");
	}	
	if (((amount_in_recycled > 0) & (add_more_goods)) | (amount_in_recycled == 0))
	{
		if (!is_registered)
		{
			window.alert("��� ���� ��� ������ ����� �� ������, �������� ������ ����, ��� ��������������. \n����-�����, ������ �� ��?� � ��� ����� � ������� ��������. \n\nhttp://www.kt.kiev.ua/users/insert/\n\nhttp://www.acula.com.ua/users/insert/");
		}
		else
		{
			if (by_manager == 1)
			{
				window.alert("���������� ���� ������� ����� �������� � ����������");
			}
		}		
		if (from_full_desc == 0)
		{			
			main_form = document.add_product;		
		}
		else
		{	
			main_form = window.opener.document.add_product;
			window.parent.close();
		}	
		main_form.title.value = title;
		main_form.id.value = id;
		main_form.amount.value = document.getElementById('amount_' + id).value;
		main_form.action.value = "add_product";
		main_form.submit();	
	}	
}*/
//���������� (������) div
function show_hide_div(id)
{	
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(id).style.position = 'static';
	}	
	else
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(id).style.position = 'absolute';
	}
}

//�������������� ������
function edit_prod(edit_link)
{	
	var h_desc = 500, w_desc = 600;
	var coord = new Array();
	coord = get_center_window_coord(h_desc, w_desc);
	left_pos = coord["x"];
	top_pos = coord["y"];
	full_desc_obj = window.open(edit_link, "edit_prod", "height=" + h_desc + ",width=" + w_desc + ",toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,top=" + top_pos + ",left=" + left_pos);
}

function highlight_r_menu(id)
{
	if (document.getElementById('r_menu_img_' + id) != null)
	{	
		document.getElementById('r_menu_img_' + id).src = empty_jol.src;
	}			
}

var open_menu = 0;
		  
function show_submenu(id)
{	
	if (open_menu != 0 )
	{		
		show_hide_div('s' + open_menu);
	}
	var obj = document.getElementById('s' + id).style;
	if (obj.display == 'none')
	{	
		obj.display = 'block';
		obj.position = 'static';
		open_menu = id;
	}
	else 
	{
		obj.display = 'hidden';
		obj.position = 'absolute';
	}
}

function highlight(id)
{
	if(id != 0)
	{
		if (document.getElementById('s' + id) != null)
		{
			var obj = document.getElementById('s' + id).style;
			obj.display = 'block';
			obj.position = 'static';
			open_menu = id;
			if(document.getElementById('r_pic_' + id) != null)
			{
				document.getElementById('r_pic_' + id).src = "/_img/kr_t.gif";
			}
		}
	}
}
function open_str_menu(id)
{
	if (document.getElementById("menu_"+id) != null){
		document.getElementById("menu_"+id).style.display = "block";
//		document.getElementById("menu_"+id).style.position = "static";
	}
}



function bookmark(title, url) {
	if (title == undefined)
		title = document.title;

	if (url == undefined)
		url = top.location.href;

	if (window.sidebar) {
		window.sidebar.addPanel(title, url, '');
	} else if (window.opera && window.print) {
		var t = document.createElement('a');
		t.setAttribute('rel', 'sidebar');
		t.setAttribute('href', url);
		t.setAttribute('title', title);
		t.click();
	} else {
		window.external.AddFavorite(url, title);
	}
	return false;
}