var tempScroll;
var units = new Array();
var okonch = new Array();

function saved()
{
	dst = document.getElementById('added');
	dst.style.display = 'block';
	w1 = dst.offsetWidth;
//	h1 = dst.offsetHeight;
	cLeft	= (screen.width-w1)/2;
//	cTop	= (screen.height-h1)/2;
	dst.style.left = cLeft+'px';
//	dst.style.top  = cTop+'px';
	window.setTimeout("hideSaved()",3000);
}

function hideSaved()
{
	dst = document.getElementById('added');
	dst.style.display = 'none';
}

function out_alert(str)
{
	dst = document.getElementById('ibox_alert');
	dst.innerHTML = str;
	dst.style.display = 'block';
	w1 = dst.offsetWidth;
	h1 = dst.offsetHeight;
	cLeft	= (screen.width-w1)/2;
	cTop	= (screen.height-h1)/2;
	dst.style.left = cLeft;
	dst.style.top  = cTop;
	stepX = Math.floor(cLeft / 20);
	stepY = Math.floor(cTop / 20);
	window.setTimeout("hideAlert("+stepX+","+stepY+")",2000);
}

function hideAlert(stepX,stepY)
{
	dst = document.getElementById('ibox_alert');
    cLeft = dst.style.left;
	cTop  = dst.style.top;
	cLeft = Math.floor(cLeft.replace(/px/g,''));
	cTop  = Math.floor(cTop.replace(/px/g,''));
	if (cTop>0)
	{
		cLeft += stepX;
		cTop  -= stepY;
		dst.style.left = cLeft;
		dst.style.top = cTop;
	    window.setTimeout("hideAlert(" + stepX + "," + stepY +")",10);
	}
	else
		dst.style.display = 'none';
}

function set_act(val)
{
	dst = document.getElementById('d_act');
	dst.value = val;
}

function setCook(name, value, expires)
{
        var curCookie = name + "=" + value + "; expires=" + expires.toGMTString() + "; ";
        document.cookie = curCookie
}

function getCook(name)
{
        var prefix = name + "=";
        var cookieStartIndex = document.cookie.indexOf(prefix);
        if (cookieStartIndex == -1)
          return '';
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length;
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

okonch[1] = 'я';
okonch[2] = 'и';
okonch[3] = 'и';
okonch[4] = 'и';

function update_order_status(k,sum)
{
	var dst_count = document.getElementById('order_status_count');
	var dst_sum   = document.getElementById('order_status_sum');
	var dst_note  = document.getElementById('order_status_note');
	if (dst_sum)	dst_sum.innerHTML = sum;
	if (dst_count)	dst_count.innerHTML = k;
	if (okonch[k % 10])
			okonchanie = okonch[k % 10];
		else
			okonchanie = 'й';
	if (dst_note)
		if (k>0)
				dst_note.innerHTML = 'В вашем заказе ' + k + ' позици' + okonchanie;
			else
				dst_note.innerHTML = 'Заказ пуст';
}

function checkAlltask(value)
{
	prefix = 'checkbox_task_';
	var src = document.getElementById('form_project');
	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1)
		{
			src[i].checked = value;	
		}
	}

	return false;
}

function checkAllproject(value)
{
	prefix = 'ch_box_';
	var src = document.getElementById('list_projects');
	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1)
		{
			src[i].checked = value;	
		}
	}

	return false;
}


function out_task_list(id_project)
{
	i_dst_frame.location = "e_tasks.php?act=out_task_list&id_project="+id_project;
}

function drop_task(prefix,id_project)
{
	var src = document.getElementById('form_project');
	var task_list = "";

	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1 && src[i].checked==true)
		{
			task_list = task_list + src[i].name +"_";
		}
	}

	i_dst_frame.location = "e_tasks.php?act=drop_task&id_project="+id_project+"&task_list="+task_list;

	return false;
}


function drop_project(prefix)
{
	var src = document.getElementById('list_projects');
	var task_list = "";

	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1 && src[i].checked==true)
		{
			task_list = task_list + src[i].name +"_";
		}
	}

	i_dst_frame.location = "e_saving.php?act=drop_project&task_list="+task_list;
}

function drop_archive_project()
{
	form.submit();
	return false;
}

function arch_project(prefix)
{
	var src = document.getElementById('list_projects');
	var task_list = "";

	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1 && src[i].checked==true)
		{
			task_list = task_list + src[i].name +"_";
		}
	}

	i_dst_frame.location = "e_saving.php?act=arch_project&task_list="+task_list;
}


function apply_task(prefix,id_project)
{
	var src = document.getElementById('form_project');
	var task_list = "";

	for (i=0;i<src.length;i++)
	{
		var nn  = src[i].name;
		var re = new RegExp(prefix);
		var res = nn.search(re);
		if (res!=-1 && src[i].checked==true)
		{
			task_list = task_list + src[i].name +"_";
		}
	}

	i_dst_frame.location = "e_tasks.php?act=apply_task&id_project="+id_project+"&task_list="+task_list;

	return false;
}


function showPic(pic,alt,w1,h1) 
{
	w1 = w1 + 30;
	h1 = h1 + 80;
	if (typeof(tz)=='object') tz.close();
	tz=window.open("","wnd","width="+w1+",height="+h1+",status=no,left="+(screen.width-w1)/2+",top="+(screen.height-h1)/2+",toolbar=no,menubar=no,resizable=no,scrollbars=no")
	tz.document.open();
	tz.document.write('<html><head><title>'+alt+'</title><link href="style.css" rel="stylesheet" type="text/css">');
	tz.document.write('<meta http-equiv=Content-Type content="text/html;charset=windows-1251"></head>');
	tz.document.write('<body onload="self.focus();">');
	tz.document.write('<center><span style="padding-top:7px;font-size:8pt"><a href="javascript:window.close();">');
	tz.document.write('<img src="'+pic+'" border=0 alt="Закрыть" style="margin-bottom:5px;"></a><br>&laquo;'+alt+'&raquo;');
	tz.document.write('<br><br><a href="javascript: self.close();">Закрыть окно</a></span></center>');
	tz.document.write('</body></html>');
	tz.document.close();
} 


function hideImage()
{
	document.body.style.overflow = '';

	dst = document.getElementById('galleryBackground');
	dst.style.display = 'none';
	dst = document.getElementById('galleryImage');
	dst.style.display = 'none';
	dst = document.getElementById('galleryImageDst');
	dst.src = 'images/loading.gif';


	var list = document.getElementsByTagName('select');
	for (var i=0; i<list.length; i++) 
		list[i].style.visibility = 'visible';

}


function showImage(id,aText,prev)
{
	document.body.style.overflow = 'hidden';

	var list = document.getElementsByTagName('select');
	for (var i=0; i<list.length; i++) 
		list[i].style.visibility = 'hidden';

	dst = document.getElementById('galleryBackground');
	dst.style.height = document.body.clientHeight+'px';
	dst.style.width  = document.body.clientWidth+'px';
//	dst.style.top    = document.body.scrollTop+'px';
	dst.style.display = 'block';
	dst.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
	
//	alert(document.body.clientHeight);

	dst = document.getElementById('galleryImage');
	dst.style.height = document.body.clientHeight+'px';
	dst.style.width  = document.body.clientWidth+'px';
//	dst.style.top    = document.body.scrollTop+'px';
	dst.style.display = 'block';
/*
	dst = document.getElementById('galleryAbout');
	if (aText)
		dst.innerHTML = aText;
	else
		dst.innerHTML = "";
*/
	dst = document.getElementById('galleryImageDst');
	dst.src = id;

}


function unit_on(id)
{
	dst		= document.getElementById('sub_menu_'+id);
	dst_li  = document.getElementById('li_'+id);
	if (dst)
		if (dst.style.display != 'block')
		{
			dst.style.display = 'block';
			dst_li.src = 'images/arrow_down.gif';
			return true;
		}
		else
		{
			dst.style.display = 'none';
			dst_li.src = 'images/arrow_right.gif';
			return false;
		}
}


function body_on(el)
{
 for (i=1;i<=4;i++)
 {
	dst = document.getElementById('tab_'+i);
	if (dst!=null)
	{
		dst.className = 'off';
	}
	dst = document.getElementById('div_'+i);
	dst.style.display = 'none';
 }
	dst = document.getElementById('tab_'+el);
	dst.className = 'on';
	dst = document.getElementById('div_'+el);
	dst.style.display = 'block';
	dst = document.getElementById('d_on_tab');
	dst.value=el;
}

function arrow_on(id)
{
	dst = document.getElementById('arr_'+id);
	dst.style.background = "url('images/arrow.gif')";
}

function arrow_off(id)
{
	dst = document.getElementById('arr_'+id);
	dst.style.background = "none";
}

function hint_show(id)
{
	dst = document.getElementById('hint_'+id);
	dst.style.display='block';
}

function hint_hide(id)
{
	dst = document.getElementById('hint_'+id);
	dst.style.display='none';
}

function div_show(id)
{
	dst = document.getElementById(id);
	dst.style.display='block';
	return false;
}

function div_hide(id)
{
	dst = document.getElementById(id);
	dst.style.display='none';
	return false
}
