/**
 *	PineTree CMS *tm
 *	@author	Kirill I Sosnin kirill@sosnin.spb.ru
 *
 *	License: GPL
 *
 */
dom = (document.getElementById) ? (true) : (false);
ie = (document.all) ? (true) : (false);
ie4 = ie && !dom;
nn4 =(document.layers) ? (true) : (false);

function popup(file, query)
{
window.open(file+'?'+query,'popup', 'width=640,height=640,screenX=210,screenY=200,top=100,left=100,copyhistory=no,directories=no, menubar=no,location=no,scrollbars=yes,resizable=yes');
}
function showItem(id)
{
window.open('/includes/misc/popup_item.php?id='+id,'popup', 'width=800,height=700,screenX=210,screenY=200,top=100,left=100,copyhistory=no,directories=no, menubar=no,location=no,scrollbars=yes,resizable=yes');
}



function cat_show_hide(root, form_id, level) {	var root_form_id;

	root_form_id = "cat"+root;

	if(dom) { root_div = document.getElementById(root_form_id); div = document.getElementById(form_id);
		ul_root_div = document.getElementById("li_"+form_id); a_root_div = document.getElementById("a_"+form_id);
		goods_div = document.getElementById("goods_"+form_id);
		}
	else if(ie4) {
		root_div = document.all[root_form_id];
		div = document.all[form_id];
		ul_root_div = document.all["li_"+form_id];
		a_root_div = document.all["a_"+form_id];
		goods_div = document.all["goods_"+form_id];
	}
	else if(nn4) {
		root_div = document.layers[root_form_id];
		div = document.layers[form_id];
		ul_root_div = document.layers["li_"+form_id];
		a_root_div = document.layers["a_"+form_id];
		goods_div = document.layers["goods_"+form_id];
	}
	else return false;

	if(div)
	{
		if(div.style.display == "block")
		{

			div.style.display = "none";
			if(goods_div) { goods_div.style.display = "none"; }
			if(ul_root_div)
			{				ul_root_div.style.backgroundImage = "url(/images/circrow.gif)";
				a_root_div.style.color = "#14599C";
				a_root_div.style.fontWeight = "normal";
				a_root_div.style.textDecoration = "underline";
			}
		}
		else
		{
			div.style.display = "block";
			if(goods_div) { goods_div.style.display = ""; }
			if(ul_root_div)
			{				ul_root_div.style.backgroundImage = "url(/images/circrow_a.gif)";
				a_root_div.style.color = "#EB3D00";
				a_root_div.style.fontWeight = "bold";
				a_root_div.style.textDecoration = "none";
				hide_others(root, form_id, level);
			}
			if(document.location.href.indexOf('oborudovanie') != -1)
			{

				window.location.hash = 'ancor_top';
/*				if(window.location.hash == '')
					document.location.href = document.location.href + '#ancor_top';
				else
					document.location.href = document.location.href;
*/
			}

		}
	}
//else
//	alert('К данной странице нельзя добавить отзыв');
	return false;
}

function show_hide(form_id) {
if(document.getElementById(form_id))
{
	if(document.getElementById(form_id).style.display == "block")
	{
		document.getElementById(form_id).style.display = "none";
	}
	else
	{
		document.getElementById(form_id).style.display = "block";
		document.getElementById(form_id).style.background = "url(/images/logo.gif)";
	}
}
//else
//	alert('К данной странице нельзя добавить отзыв');
	return false;
}


function hide_others(cur_id, form_id, level) {
	var _form_id;
	var div;
	var ul_root_div;
	var a_root_div;
	if(level==0||level==1)
	{
		 for (var i=1; i<50; i++)
		 {
			if(level==0) {				_form_id = "cat"+ i;
			div = document.getElementById(_form_id);
			}
			else
			{				_form_id = "items"+ i;
				div = document.getElementById(_form_id);
			}

			if(!div)
			{
				_form_id = "items"+ i;
				div = document.getElementById(_form_id);
			}

				if(div && _form_id!=form_id && _form_id!="cat1")
				{
					div.style.display = "none";
					if(document.getElementById("goods_"+_form_id)) { document.getElementById("goods_"+_form_id).style.display = "none"; }

					ul_root_div = document.getElementById("li_cat"+i);
					if(!ul_root_div)	ul_root_div = document.getElementById("li_items"+i);

					if(ul_root_div)
					ul_root_div.style.backgroundImage = "url(/images/circrow.gif)";

					a_root_div = document.getElementById("a_cat"+i);
					if(!a_root_div) a_root_div = document.getElementById("a_items"+i);

					if(a_root_div)
					{
						a_root_div.style.color = "#14599C";
						a_root_div.style.fontWeight = "normal";
						a_root_div.style.textDecoration = "underline";
					}
				}
		}
	}
	return false;
}


function show_picture(gid, id, f, c, w, h, color, title)
{ var size="width="+w+",height="+h; picture = window.open("/includes/misc/popup_img.php?gid="+gid+"&id="+id+'&f='+f+"&c="+c+"&col="+color+"&tit="+title, "picture", "dependent=yes,status=yes,directories=no,menubar=no,scrollbars=yes,resizable=yes,"+size);
}
function show_cat_picture(gid, id, f, c, w, h, color, title)
{ var size="width="+w+",height="+h; picture = window.open("/includes/misc/popup_cat_img.php?gid="+gid+"&id="+id+'&f='+f+"&c="+c+"&col="+color+"&tit="+title, "picture", "dependent=yes,status=yes,directories=no,menubar=no,scrollbars=yes,resizable=yes,"+size);
}


function checkEmail(mail)
{
	var mailstr= new String(mail);
	var indexOfDog = mailstr.indexOf("@");
	var indexOfPeriod = mailstr.indexOf(".");
	var indexOfSpace = mailstr.indexOf(" ");
    var regex5=/[^a-zA-Z_0-9]/;
    var regex7=/[а-я]/;
    var regex8=/[А-Я]/;
    var error_message = "";

	if(indexOfDog==-1){
		error_message+="\nEmail не полон, пропущена @";
		error=1;
	}

	if(indexOfDog==0){
		error_message+="\nEmail не полон, перед @ ничего нет";
		error=1;
	}

	if(indexOfSpace!=-1){
		error_message+="\nEmail не должен содержать пробелов";
		error=1;
	}

	if(indexOfPeriod==-1){
		error_message+="\nEmail не полон, пропущена точка";
		error=1;
	}

	if(regex7.test(mail)||regex8.test(mail)||regex5.test(mail))
	{
		error_message+="\nEmail может содержать только цифры и английские буквы";
		error=1;
	}

	return error_message;
}

	function getRef(id) 
	{
		if (dom) return document.getElementById(id);
		if (ie4) return document.all[id];
		if (nn4) return document.layers[id];
	}
	function image_swap(cur_index) {
		getRef('imgMain').src = '/images/main_rotated/' + cur_index + '.jpg';
		if(cur_index == 12) cur_index = 0;
		setTimeout('image_swap(' + (cur_index + 1) + ')', 6000);	
	} 

