var objCount = 0; // количество изображений на web-странице
var result;
var new_win;
pics = new Array();


var cookieList = document.cookie.split("; ");
var cookieArray = new Array();
var isUserLogin = 1;
var is_user_be_here;
/*for (var i = 0; i < cookieList.length; i++)
{
	var cookname2 = cookieList[i].split("=");
	if(unescape(cookname2[0])=="isUserLogin"){ isUserLogin = unescape(cookname2[1]);}
	if(unescape(cookname2[0])=="uniq_cookie_id"){ is_user_be_here = unescape(cookname2[1]);}
}
if (is_user_be_here != '' && isUserLogin != 2) 
{
	document.write('<');
	document.write('script');
	document.write(' src=/js/auth.php?' + Math.random());
	document.write('></');
	document.write('script');
	document.write('>');
//	alert(is_user_be_here);
}
*/

function on_close_win()
{
	result = false;
}
function show_big_img(href_beg,win_w,win_h,img_src)
{
	if (result) result.close();
	left_pos = (screen.width - (1*win_w))/2;
	top_pos = (screen.height - (1*win_h))/2;
	set_scrollbars = "no";
	win_add_w = 0;
	if(left_pos<40)
	{
		left_pos = 40;
		win_w = screen.width-80;
		set_scrollbars = "yes";
	}
	tt_win_w = 1*win_w;
	if(top_pos<40)
	{
		top_pos = 20;
		win_h = screen.height-80;
		if(set_scrollbars == "no") tt_win_w += 18;
		set_scrollbars = "yes";
	}
	doc_text = "<HTML><HEAD><TITLE>Webo</TITLE></HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 LEFTMARGIN=0 RIGHTMARGIN=0 TOPMARGIN=0 BGCOLOR=white onunload='opener.on_close_win()'>";
	doc_text += "<div align=center><img src='"+img_src+"' border=0></div>";
	doc_text += "</BODY></HTML>";
	result = open("", "displayWindow","width="+tt_win_w+",height="+win_h+",left="+left_pos+",top="+top_pos+",resizable=yes,status=no,toolbar=no,menubar=no,scrollbars="+set_scrollbars);
	result.document.open();
	result.document.write(doc_text);
	result.document.close();
	result.focus();
}
function open_new_win(win_href,win_w,win_h)
{
	if (result) result.close();
	left_pos = (screen.width - (1*win_w))/2;
	top_pos = (screen.height - (1*win_h))/2;
	set_scrollbars = "no";
	win_add_w = 0;
	if(left_pos<40)
	{
		left_pos = 40;
		win_w = screen.width-80;
		set_scrollbars = "yes";
	}
	tt_win_w = 1*win_w;
	if(top_pos<40)
	{
		top_pos = 20;
		win_h = screen.height-80;
		if(set_scrollbars == "no") tt_win_w += 18;
		set_scrollbars = "yes";
	}
	result = open(win_href, "displayWindow","width="+tt_win_w+",height="+win_h+",left="+left_pos+",top="+top_pos+",resizable=no,status=no,toolbar=no,menubar=no,scrollbars="+set_scrollbars);
	result.focus();
}

function show_big_image(img_id){
	if (img_id < 1) return;
	if (result) result.close();
	result = open('/rus/showimg/' + img_id + '/', "displayWindow","width=100,height=100,left=50,top=50,resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=no");
	result.focus();
}

function preload(name, first, second)
{
	// предварительная загрузка изображений и размещение их в массиве
	pics[objCount] = new Array(3);
	pics[objCount][0] = new Image();
	pics[objCount][0].src = first;
	pics[objCount][1] = new Image();
	pics[objCount][1].src = second;
	pics[objCount][2] = name;
	objCount++;
}

function on_out(type, event)
{
	if (this.event) event = this.event;
	if (event.target) el = event.target;
	else el = event.srcElement;
//	alert(type);
	if (el && el.src)
	{
		for (var i=0; i < objCount; i++)
		{
			if (pics[i][2] == el.name)
			{
				if (type == 1) el.src = pics[i][0].src;
				else el.src = pics[i][1].src;
			}
		}
	}
}

function on(name)
{
	for (i = 0; i < objCount; i++)
	{
		if (document.images[pics[i][2]] != null)
			if (name != pics[i][2])
			{
				// вернуть в исходное систояние все другие изображения
				document.images[pics[i][2]].src = pics[i][0].src;
			}else{
				// показывать вторую картинку, поскольку курсор пересекает данное изображение
				document.images[pics[i][2]].src = pics[i][1].src;
			}
	}
}

function off()
{
	for (i = 0; i < objCount; i++)
	{
		// вернуть в исходное систояние все изображения
		if (document.images[pics[i][2]] != null)
			document.images[pics[i][2]].src = pics[i][0].src;
	}
}
function on_inp(el,img_src){el.src = img_src;}

function delivery(href_beg,wtype)
{
	if (result) result.close();
	left_pos = (screen.width - 360)/2;
	top_pos = (screen.height - 200)/2;
	eval("result=window.open('"+href_beg+"/delivery/"+wtype+"/','delivery','resizable=no,menubar=no,status=no,scrollbars=no,width=360,height=200,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}

function go_delivery(p)
{
	if (document.deliv.y_email.value == '') 
	{
		alert('Введите Email');
		return false;
	}
	else
	{
		if (document.deliv.y_name.value == '' && document.deliv.wtype[0].checked)
		{
			alert('Введите Имя');
			return false;
		}
		else
		{
			if (result) result.close();
			left_pos = (screen.width - 360)/2;
			top_pos = (screen.height - 200)/2;
			result = window.open('','delivery','resizable=no,menubar=no,status=no,scrollbars=no,width=360,height=200,left=' + left_pos + ',top=' + top_pos);
			result.focus();
			document.deliv.submit();
		}
	}
}

function see_card(href_beg)
{
	if (result) result.close();
	left_pos = (screen.width - 360)/2;
	top_pos = (screen.height - 200)/2;
	eval("result=window.open('"+href_beg+"/','see','resizable=no,menubar=no,status=no,scrollbars=no,width=360,height=200,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}

function go_basket(id, lp)
{
	if (!new_win || new_win.closed)
	{
		new_win = window.open(lp + '/eshop/gobasket/' + id + '/', 'bas', 'resizable=no,menubar=no,status=no,scrollbars=no,width=170,height=80');
		new_win.focus();
	}
	else
	{
		new_win.location.href = lp + '/eshop/gobasket/' + id + '/';
		new_win.focus();
	}
}

function basket_del()
{
	if(confirm('Вы действительно хотите удалить эти товары?')) 
	{
		document.fbasc1.go_tov_delete.value=1;
		document.fbasc1.submit()
	} 
	else return false;
}

var old_cat_div = 'cat_groups';
function change_div(name){
	if (old_cat_div) {
		FIND(old_cat_div).style.display = 'none';
		FIND(old_cat_div + '_a').className = 'no_und l_gray bold s11';
//		FIND(old_cat_div + '_td').className = 'div_select_off';
	}
	FIND(name).style.display = 'block';
	FIND(name + '_a').className = 'no_und black bold s12';
//	FIND(name + '_td').className = 'div_select_on';
	old_cat_div = name;
}

function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function show_print_version(print_url)
{
	win_w = 700;
	win_h = 500;
	if (result) result.close();
	left_pos = (screen.width - (1*win_w))/2;
	top_pos = (screen.height - (1*win_h))/2;
	set_scrollbars = "no";
	print_url = print_url + '?print=1';
	set_scrollbars = "yes";
	result = open(print_url, "displayWindow","width="+win_w+",height="+win_h+",left="+left_pos+",top="+top_pos+",resizable=no,status=no,toolbar=no,menubar=no,scrollbars="+set_scrollbars);
	result.focus();
}

function getcookie (name)
{
    var arg  = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i    = 0;

    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}


function getCookieVal( offset )
{
    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Tue, 14 Dec 2010 23:59:59 GMT; path=/; domain=.svitmedia.net;";
}




var blocks = new Array();

function blocks_init(){
	var tmp_str = getcookie('close_blocks');
	if (tmp_str.length > 0)
	blocks = tmp_str.split(';');
}


function blocks_open_close(id){
	el = FIND(id);
	el_off = FIND(id + '_off');
	if (el){
		if (el.style.display == 'block') {
			el.style.display = 'none';
			if (el_off) el_off.style.display = 'block';	
			blocks_set(id, 1);
		}
		else{
			el.style.display = 'block';
			if (el_off) el_off.style.display = 'none';	
			blocks_set(id, 0);
		}
	}
}

function blocks_info(id){
	for(tmp_i = 0; tmp_i < blocks.length; tmp_i++){
		if (id == blocks[tmp_i]) return true;
	}
	return false;
}

function blocks_check(id){
	if (blocks_info(id)){
		el = FIND(id);
		el.style.display = 'none';
		el_off = FIND(id + '_off');
		if (el_off) el_off.style.display = 'block';
	}
}

function blocks_set(id, type){
	var tmp_str;
	if (type == 0){
		for(tmp_i = 0; tmp_i<blocks.length; tmp_i++){
			if (id == blocks[tmp_i]) {
				blocks[tmp_i] = '';
			}
		}
	}
	else{
		blocks[blocks.length] = id;
	}
	for(tmp_i = 0; tmp_i < blocks.length; tmp_i++){
		if (blocks[tmp_i] != ''){
			if (tmp_str != '') tmp_str = tmp_str + ";";
			tmp_str = tmp_str + blocks[tmp_i];
		}
	}
	SetCookie('close_blocks', tmp_str);
}

function blocks_reset(){
	for(tmp_i = 0; tmp_i < blocks.length; tmp_i++){
		if (blocks[tmp_i] != ''){
			el = FIND(blocks[tmp_i]);
			if (el) el.style.display = 'block';
			el_off = FIND(blocks[tmp_i] + '_off');
			if (el_off) el_off.style.display = 'none';
		}
	}
	SetCookie('close_blocks', '');
}

blocks_init();