var eval_var = '';
var left_menu_ids = new Array();
window.onload = function(){init_document();}
function init_document()
{
	eval(eval_var);		
}

/*********************************************************/
//Работа с главным меню

function inits_menu()
{
	
	for(i in left_menu_ids)
	{
	chage_status_menu(left_menu_ids[i],1);
	}	
	roll_menu(true);
}

function chage_status_menu(id,typ)
{
	
	var obj	=	document.getElementById('left_menu_place_'+id);		
	if(!obj) return;
	var obj1	=	document.getElementById('left_menu_marker_'+id);	
	if(!obj1) return;
	
	
	if(typ==1)
	{
		var str_cookie	=	findCookie('open_left_menu');
		var cookies		=	new Array;
		if(str_cookie.length	> 0)cookies	=	str_cookie.split("|");
		var newStrCookies	=	"";
		
		for(i in cookies)
		{
			if	(cookies[i]==id)
			{
				obj.className	=	'hidden';
				obj1.className	=	'left_menu_punkt_arrow float_left hidden_overflow left_menu_unselect_ar';
				return;		
			}
		}
		
		
		return;
	}
	if(typ==2)
	{
		if(obj.className	==	'hidden')
		{
			
			remove_open_menu(id);
			obj.className	=	'left_menu_subpunkt_place';
			obj1.className	=	'left_menu_punkt_arrow float_left hidden_overflow left_menu_select_ar';
		}
		else
		{
			set_open_menu(id);
			obj.className	=	'hidden';
			obj1.className	=	'left_menu_punkt_arrow float_left hidden_overflow left_menu_unselect_ar';
		}
		return;
	}
	

	
}

function addCookie(szName,szValue,dtDaysExpires) 
{
   var dtExpires = new Date();
   var dtExpiryDate = "";

   dtExpires.setTime(dtExpires.getTime() + 
     dtDaysExpires * 24 * 60 * 60 * 1000);

   dtExpiryDate = dtExpires.toGMTString();
	document.cookie = szName + "=" + szValue + "; expires=" + dtExpiryDate;
}

function findCookie(szName) 
{
  var i = 0;
  var nStartPosition = 0;
  var nEndPosition = 0;  
  var szCookieString = document.cookie;  

  while(i <= szCookieString.length) 
  {
    nStartPosition = i;
    nEndPosition = nStartPosition + szName.length;

    if(szCookieString.substring( 
        nStartPosition,nEndPosition) == szName) 
    {
      nStartPosition = nEndPosition + 1;
      nEndPosition = 
        document.cookie.indexOf(";",nStartPosition);

      if(nEndPosition < nStartPosition)
        nEndPosition = document.cookie.length;

      return document.cookie.substring( 
          nStartPosition,nEndPosition);  
      break;    
    }
    i++;  
  }
  return "";
}

function set_open_menu(id)
{
	remove_open_menu(id);
	var str_cookie	=	findCookie('open_left_menu');
	if(str_cookie.length	> 0)str_cookie	=	str_cookie+"|"+id;
	else str_cookie	=	id;
	addCookie('open_left_menu',str_cookie,3650);	
}

function remove_open_menu(id)
{
	var str_cookie	=	findCookie('open_left_menu');
	var cookies		=	new Array;
	cookies	=	str_cookie.split("|");
	var newStrCookies	=	"";
	var mod	=	"";
	for(i in cookies)
	{
		if	(cookies[i]==id)continue;
		newStrCookies	=	newStrCookies+mod+cookies[i];
		mod	=	"|";
	}
	addCookie('open_left_menu',newStrCookies,3650);
}

function roll_menu(auto)
{
	menu = document.getElementById('left_menu');
	if(!menu)return;
	if(!auto)
	{
		if(menu.className!='hidden')
		{
			menu.className = 'hidden';
			addCookie('hidden_left_menu','1',3650);
		}
		else
		{
			menu.className = '';
			addCookie('hidden_left_menu','0',3650);
		}
		return;
	}
	
	cook = findCookie('hidden_left_menu');
	if(cook==1)
	{
		menu.className = 'hidden';	
	}
}

eval_var	+= ' inits_menu(); ';
/****************************************************************************/


/*Данные по размеру окна*/
function clientWidth()
{
   return (window.innerWidth)?window.innerWidth:((document.all)?document.documentElement.offsetWidth:null);
}

function clientHeight()
{
     return (window.innerHeight)?window.innerHeight:((document.all)?document.documentElement.offsetHeight:null);
}

function ScrollY()
{
   return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function ScrollX()
{
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function offsetPosition(element) 
{
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
    } while (element = element.offsetParent);
    return [offsetLeft, offsetTop];
}

/****************************/

/*Всплывающее окно*/
function show_image(src,how_call)
{
	
	div	=	document.getElementById('prew_zoom');
	if(div != null)
	{
		if(div['tagName']!='DIV')
		{
			alert('КОНФЛИКТ СЛОЯ ID = "prew_zoom"');
			return;	
		}			
	}
	else
	{
		div = document.createElement("div");
		div.setAttribute("id", "prew_zoom");
		document.body.appendChild(div);	
	}
	
	
	called=	document.getElementById(how_call);
	if(!called)return;
	
	ofPosition = offsetPosition(called);
	
	div.className	=	'show_zoom';
		
	x	=	ofPosition[0];
	y	=	ofPosition[1]+called.offsetHeight;;
	
	height	=	div.offsetHeight;
	recty	=	clientHeight()+ScrollY();
	
	width	=	div.offsetWidth;
	rectx	=	clientWidth()+ScrollX();
	
	if((y+height)>(recty-15))y=recty-height-15;
	if((x+width)>(rectx-15))x=rectx-width-15;
	
	div.style.left = (x+10)+'px';
    div.style.top = (y+10)+'px';
	div.innerHTML = '<img src="'+src+'" alt="PREW" />';
	
	
}

function show_text(src,how_call)
{
	
	div	=	document.getElementById('prew_zoom');
	if(div != null)
	{
		if(div['tagName']!='DIV')
		{
			alert('КОНФЛИКТ СЛОЯ ID = "prew_zoom"');
			return;	
		}			
	}
	else
	{
		div = document.createElement("div");
		div.setAttribute("id", "prew_zoom");
		document.body.appendChild(div);	
	}
	
	
	called=	document.getElementById(how_call);
	if(!called)return;
	
	ofPosition = offsetPosition(called);
	
	div.className	=	'show_zoom';
		
	x	=	ofPosition[0];
	y	=	ofPosition[1]+called.offsetHeight;;
	
	height	=	div.offsetHeight;
	recty	=	clientHeight()+ScrollY();
	
	width	=	div.offsetWidth;
	rectx	=	clientWidth()+ScrollX();
	
	if((y+height)>(recty-15))y=recty-height-15;
	if((x+width)>(rectx-15))x=rectx-width-15;
	
	div.style.left = (x+10)+'px';
    div.style.top = (y+10)+'px';
	div.innerHTML = src;
	
	
}

function hidden_prew()
{
	div	=	document.getElementById('prew_zoom');
	if(!div)return;
	div.innerHTML 	= '';
	div.className	=	'hidden';	
}

function show_hidden_user_setup()
{
	div	=	document.getElementById('user_right_mod_place');
	div2	=	document.getElementById('user_right_mod_button');
	if(!div)return;
	if(div.className	==	'hidden')
	{
		div.className	=	'';
		div2.value		=	'Скрыть права клиента';
	}
	else
	{
		div.className	=	'hidden';
		div2.value		=	'Показать права клиента';
	}
}
