
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer') > -1);
var curDate = new Date();
var spoiler = false;
var pic_next = 0;
var pic_prev = 0;
var row_error = new Array();
var dimage = false;

function loadXMLDoc(url, add_post)
{
	if (ie && window.ActiveXObject) req = new ActiveXObject('Msxml2.XMLHTTP.3.0');
	else if (window.XMLHttpRequest) req = new XMLHttpRequest();
		else return false;
	req.onreadystatechange = processReqChange;
	req.open("POST", url, true);
//	if (!req.setRequestHeader) return false;
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//	alert("post: "+add_post);
	req.send(add_post);
//	alert("url 3: "+url+" \n");

	ab = window.setTimeout("req.abort();", 5000);
//	try {progress_main_init();} catch(e) {return;}
}

function processReqChange()
{
	var i;
	var j;
//	window.status = stat(req.readyState);
	if (req.readyState == 4)
	{
		clearTimeout(ab);

		if (req.status == 200)
		{

//			alert ("req.responseText: "+req.responseText);
			i = req.responseText.indexOf('#');
			pic_nid = req.responseText.substr(0, i);
			j = req.responseText.indexOf('#', ++i);
			pic_small = req.responseText.substr(i, j-i);
			i = req.responseText.indexOf('#', ++j);
			pic_big = req.responseText.substr(j, i-j);
			j = req.responseText.indexOf('#', ++i);
			pic_prev = req.responseText.substr(i, j-i);
			i = req.responseText.indexOf('#', ++j);
			pic_next = req.responseText.substr(j, i-j);

			document.getElementById("pic_show").src = pic_small;
			document.getElementById("pic_show").parentNode.href = pic_big;
		} else alert("Не удалось получить данные:\n" + req.statusText);
	}
}

function stat(n)
{
	switch (n) {
		case 0: return "не инициализирован"; break;
		case 1: return "загрузка..."; break;
		case 2: return "загружено"; break;
		case 3: return "в процессе..."; break;
		case 4: return "готово"; break;
		default: return "неизвестное состояние";  
	}
}

function pic_zoom()
{
/*
	var image = {
		src:	'',
		title:	'Untitled',
		description:	'',
		name:	'',
		index:	-1,
		image:	true
	};

	$.Lightbox = undefined;
	$.Lightbox = new $.LightboxClass();
*/
//	href = document.getElementById("pic_show").parentNode;

//	$.Lightbox.init();
//	$.Lightbox.images.add = document.getElementById("pic_show");
//	$.Lightbox.images.add =  image.src = href.pathname;

/*
	image.title = 'asd';
	image.image = true;
	image.src = href.pathname;
	image.index = 0;
*/
/*
	alert('111');
	$.Lightbox.add(image);
	alert('222');
	$.Lightbox.start();
	alert('333');
*/
//	$.Lightbox.construct();
/*
	Lightbox.show(href);
	init
*/

//	win = window.open(href, 'popup', 'toolbar = no, width=800, height=600, status = no');

//	win = window.open(", ", 'popup', 'toolbar = no, status = no');
//	win.document.write('<html><body><a href="#"><img src=">' + href.pathname + '"></a></body></html>');
//	win.document.href = href;

//	alert(href.pathname);

/*	
popWindow = window.open("","popWindow","toolbar=no,width=200,height=180,directories=no,menubar=no");

popWindow.document.writeln("<HTML><HEAD>");
popWindow.document.writeln("<SCRIPT LANGUAGE='JavaScript'>"); 
popWindow.document.writeln("function exitNow(){"); 
popWindow.document.writeln("opener.document.forms[0].elements[0].value='Открыть POP-UP';");
popWindow.document.writeln("opener.i=1 }");
popWindow.document.write("</\SCRIPT></\HEAD><\BODY bgcolor=black onClick=\"exitNow(); self.close()\">");

popWindow.document.write("Этот скрипт позволяет Вам закрыть");
popWindow.document.write("<a href='#'><img src='>" + href + "'></a>");
popWindow.document.write("</\BODY></HTML>");

document.forms[0].elements[0].value="Закрыть POP-UP";
*/


	
	return true;
}

function pic_init(p_prev, p_next)
{
	pic_next = p_next;
	pic_prev = p_prev;
}

function pic_change(direction)
{
	var nid = 0;
	if (direction == 1) nid = pic_next;
	else if (direction == -1) nid = pic_prev;
	loadXMLDoc("/pic.php", "pic="+nid);
	return true;
}

function spoiler_change()
{
	var sp = document.getElementById('spoiler');
	if (spoiler) {sp.style.display = "block"; spoiler = false;}
	else {spoiler = true; sp.style.display = "none";}
	return true;
}

function details_select(obj)
{
	var f = obj.form;
	if (f.cat1.value < 1) return false;
	var href =  '/details/list/'+f.cat1.value;
	if (f.cat2 && f.cat2.value>0) {href += '/'+f.cat2.value; if (f.cat3 && f.cat3.value>0) {href += '/'+f.cat3.value; if (f.cat4 && f.cat4.value>0) {href += '/'+f.cat4.value; if (f.cat5 && f.cat5.value>0) {href += '/'+f.cat5.value; if (f.cat6 && f.cat6.value>0) {href += '/'+f.cat6.value; if (f.cat7 && f.cat7.value>0) {href += '/'+f.cat7.value; if (f.cat8 && f.cat8.value>0) {href += '/'+f.cat8.value;}}}}}}}
	window.location = href;
	return false;
}

function details_login(f, c)
{
	if (c < 1) return true;
	var zayti = confirm("Выбранные Вами товары будут автоматически объеденнены с корзиной пользователя.\nЕсли объеденение не требуется, нажмите ОТМЕНИТЬ.");
	if (zayti)
	{
		var ej = document.getElementById('edit-join');
		ej.value = 1;
//		alert('Yes');
	}
	return true;

}

function details_change(obj, id, c, ost)
{
	var f = obj.form['details[count]['+id+']'];
	var z = parseInt(f.value);
	if (!z) z = 0;
	if (z >= -c) f.value = z + c;
	var tr = obj.parentNode.parentNode.parentNode;
	z = -1;
//	for (i=0; i < row_error.length; i++) if (row_error[i] == id) {z = i; break;}
	if (f.value > ost) {tr.style.color = '#f33';}
	else {tr.style.color = '';}

//	ce = document.getElementById('count_error');
//	if (f.value > ost) ce.innerHTML = 'Количество товара на складе не достаточно.';
}

function details_click_image()
{
	var left_tri = document.getElementById('left_tri');
	var content_tri_ = document.getElementById('content_tri_');
	var zdimg = document.getElementById('zdimg');
	if (dimage)
	{
		left_tri.style.display = '';
		content_tri_.style.marginLeft = '340px';
		zdimg.style.width = '600px';
		dimage = false;
	} else {
		left_tri.style.display = 'none';
		content_tri_.style.marginLeft = '40px';
		zdimg.style.width = '1000px';
		dimage = true;
	}
}

