//-------------------------------------------функция входа: предложение о перенесении в туду-------
function popupClick(item) 
{
   if(item && item.src)
   { 
  e('appWindow').src = '../empty.html';
  e('appWindow').style.display =item.display; //item.getAttribute('display');

  e('appWindow').src =item.src;
   hidePanel("workPanel");
   }
}
//-------------------------------------------------------------------------------------------------
//---------------------------------------------------вырожденное уезжание панели---------------------------
var leftTimeout, rightTimeout;
function move(object, count, orient){
var c;
if (orient=='left'){
if (count>0){
clearTimeout(rightTimeout);
c=parseInt(e(object).style.left)-300;
e(object).style.left=c+'px';
count=count-25;
func="move('"+object+"','"+count+"','left');";
leftTimeout=window.setTimeout(func,1);
}}
if (orient=='right'){
if (count>0){
clearTimeout(leftTimeout);
c=parseInt(e(object).style.left)+300;
if(c<10){
e(object).style.left=c+'px';
count=count-25;
func="move('"+object+"','"+count+"','right');";
rightTimeout=window.setTimeout(func,1);
}}}}
//-------------------------------------------------------------------------------------------------
//--------------------------скрытие панели (без уезжания)------------------------------------------
function hidePanel(obj){
e(obj).style.display='none';
}
function showPanel(obj){
e(obj).style.display='block';
}
function smartShowHidePanel(obj){
if(e(obj).style.display=='none'){e(obj).style.display='block';}else{e(obj).style.display='none';}
}
//-------------------------------------------------------------------------------------------------

function VworkPanel(container){
this.container=container;
this.item=getWordLang('panel');
this.HidePanel = function (){hidePanel("workPanel");}//скрывает рабочую панель
this.resetButton=function()//переводит все кнопки в начальное состояние
  {
	for(var i=0; i<e('buttonContainer').childNodes.length; i++){
		e('buttonContainer').childNodes[i].className="wbutton";
	}
  }
 this.changeName = function (name) // изменяет имя рабочей панели
  {
   if (USER!=""){ch=': ';}else{ch=' ';} 
//   e('workpanelname').innerHTML=USER+ch+name;
   e('workpanelname').innerHTML=name;
  }

this.countPopup = 0;
this.createMainButton= function(containerButton, xml, nameItems){
	//формирование кнопок из xml и помещение их в containerButton. nameItems - имя панели для которой формируются кнопки
	var items = xml.XMLDocument.documentElement.getElementsByTagName('item');
	var Buttons= new Array;

	while (containerButton.hasChildNodes()){
		containerButton.removeChild(containerButton.firstChild);
	}
	activdisplay=null;
	this.countPopup = 0;
	try{
		for (var i = 0; i < items.length; i++)
		{
			if(items.item(i).getAttribute('name')==nameItems)
		 	{
				for (var j = 0; j < items.item(i).childNodes.length; j++)
				{
					Buttons['Button'+j]=new WorkPanelButton(containerButton);
					Buttons['Button'+j].Name=items.item(i).childNodes[j].getAttribute('name');
					if (items.item(i).childNodes[j].getAttribute('addAttribute'))
					{ 
						var attr = items.item(i).childNodes[j].getAttribute('addAttribute').split('@');
						for(var pa = 0; pa < attr.length; pa++){
							var zhach=attr[pa].split('~');
							Buttons['Button'+j].setAttribute(zhach[0], zhach[1]);
						}
					}
					Buttons['Button'+j].setAttribute('href', items.item(i).childNodes[j].getAttribute('href'));
					Buttons['Button'+j].CreateButton();
					this.countPopup++;
				}
				var caption = items.item(i).getAttribute('caption');
				if(!caption)caption = nameItems;
				this.changeName(caption);
				var onclick = items.item(i).getAttribute('onclick');
				if(onclick) eval(onclick);
			}
		}
	}catch(e)
	{
		errorStatus(); 
		statusText(getWordLang('errorselect'));
	}
}



this.createPanel = function (container) {
this.MainTable= document.createElement("table");
this.MainTable.insertRow(0);
this.MainTable.rows[0].insertCell(0);
this.MainTable.insertRow(1);
this.MainTable.rows[1].insertCell(0);
this.MainTable.rows[1].cells[0].id="buttonContainer"; // название контейнера с кнопками на рабочей панели. С помощью него можно найти кнопки. Название не изменять
this.MainTable.insertRow(2);
this.MainTable.rows[2].insertCell(0);
this.MainTable.insertRow(3);
this.MainTable.rows[3].insertCell(0);
this.MainTable.insertRow(4);
this.MainTable.rows[4].insertCell(0);
this.MainTable.insertRow(5);
this.MainTable.rows[5].insertCell(0);
this.MainTable.className="workPanel";
this.MainTable.cellPadding='0px';

//this.krest=document.createElement("img");
//this.krest.src="/img/button/minikrest.gif";
//this.krest.border="0px";
//this.krest.setAttribute("style", "margin: 3px;float:right; ");
this.NamePanelDiv=document.createElement("div");
this.NamePanelDiv.className="dpt1";
this.NamePanelDiv.id="workpanelname";


this.MainTable.rows[0].cells[0].appendChild(this.NamePanelDiv);
this.MainTable.rows[0].cells[0].style.whiteSpace = 'nowrap';
//this.MainTable.rows[0].cells[0].appendChild(this.krest);

this.MainTable.rows[0].cells[0].className="wpt1";
this.MainTable.rows[0].cells[0].onclick=this.HidePanel; 
this.MainTable.rows[0].cells[0].id="workpanelname1";

var items = xmlMenu.XMLDocument.documentElement.getElementsByTagName('item');
if(this.items==undefined){this.items=getWordLang('buttonWork');}

this.NamePanelDiv.innerHTML=USER+this.items;
//this.MainTable.rows[0].cells[0].innerHTML=this.items;
this.MainTable.rows[0].cells[0].onmouseover=function()
	 { 
		 if(this.className=="wpt1")
		 {
		 this.className="hwpt1";
		 }
	 } 
this.MainTable.rows[0].cells[0].onmouseout=function()
	 {
		 if(this.className=="hwpt1")
		 {
		 this.className="wpt1";
		 }
	  } 
this.MainTable.rows[1].cells[0].className="wpt2";
var containerButton=this.MainTable.rows[1].cells[0];

this.createMainButton(containerButton, xmlMenu, this.items);// создание кнопок

//----------------------------дисплеи----------------//
this.MainTable.rows[2].cells[0].style.height='50%';
display1 = new VButtonFrom3Part(this.MainTable.rows[2].cells[0]);
display1.Name='&nbsp;';
display1.LeftPart='img/blackwindowleft.gif';
display1.FonPart='url(img/blackwindowfon.gif)';
display1.RightPart='img/blackwindowright.gif';
display1.mainId="display1";
display1.CreateButton();
//this.MainTable.rows[3].cells[0].style.height='30%';
display2 = new VButtonFrom3Part(this.MainTable.rows[2].cells[0]);
display2.Name='<ul style="text-align: left; margin-left: 17px; padding: 0px"> '+getWordLang('demo2')+' <li style="margin-left: 15px;"><b>FireFox 3.0</b> '+getWordLang('demo3')+'<!-- ,</li> <li style="margin-left: 15px;"><b>Internet Explorer 6.0</b></li>--></ul><!--a href="http://gps.vi-tel.ru/temp/dogovor_oferti.doc" target="_blank" style="color:#FFFFFF; cursor: pointer">'+getWordLang('demo4')+'</a-->';
display2.LeftPart='img/leftshar.gif';
display2.FonPart='url(img/fonshar.gif)';
display2.RightPart='img/rightshar.gif';
display2.mainId="display2";
display2.CreateButton();
//this.MainTable.rows[4].cells[0].style.height='10%';
display3 = new VButtonFrom3Part(this.MainTable.rows[2].cells[0]);
display3.Name='&nbsp;';
display3.LeftPart='img/blackwindowleft.gif';
display3.FonPart='url(img/blackwindowfon.gif)';
display3.RightPart='img/blackwindowright.gif';
display3.mainId="display3";
display3.CreateButton();
//----------------------------/дисплеи------------------------//


//------------------------------------формирование кнопок вниз, ок, вверх------------------/
this.MainTable.rows[5].cells[0].style.height='10%';
this.MainTable.rows[5].cells[0].style.textAlign='center';
//this.MainTable.rows[5].cells[0].style.border='#fff solid 5px';
this.MainTable.rows[5].cells[0].style.verticalAlign='top';
this.MainTable.rows[5].cells[0].style.paddingBottom='10px';
this.contButOK= document.createElement("div");
this.contButOK.style.margin="0px auto";
this.contButOK.style.width="100px";
//this.contButOK.style.marginBottom="10px";
//this.contButOK.style.border='#ccc solid 5px';
var contBut=this.contButOK;
ButtonTop=new buttonOK(contBut);
ButtonTop.Name='<img src="/img/button/top.gif" style="margin-top: 5px;" />';
ButtonTop.onclick=function(){buttontop();}
ButtonTop.attributeSet('style.marginRight', '5px');
//ButtonTop.attributeSet('style.margin', '5px');
ButtonTop.CreateButton();

ButtonOK=new buttonOK(contBut);
ButtonOK.Name='ОК';
ButtonOK.onclick=function(){buttonok();}
//ButtonOK.attributeSet('style.marginLeft', '5px');
ButtonOK.attributeSet('style.marginRight', '5px');
ButtonOK.CreateButton();

ButtonBottom=new buttonOK(contBut);
ButtonBottom.Name='<img src="/img/button/bottom.gif" style="margin-top: 5px;" />';
ButtonBottom.onclick=function(){buttonbottom();}
//ButtonBottom.attributeSet('style.margin', '5px');
ButtonBottom.CreateButton();
this.MainTable.rows[5].cells[0].appendChild(this.contButOK);

//------------------------------------формирование кнопок вниз, ок, вверх------------------/
this.container.appendChild(this.MainTable);
}

this.ClearPanel = function (container){
while (this.container.hasChildNodes()){
this.container.removeChild(this.container.firstChild);
}
activdisplay=null;
}}

var activdisplay=null;
var countstep=1;
var nameaction='шаг';
function buttontop(){
if(activdisplay!=null){ if(activdisplay.previousSibling!=null){
activdisplay=activdisplay.previousSibling;
e('display1').innerHTML=activdisplay.getAttribute('display1');
var display = activdisplay;
  if(display.getAttribute('onload')){eval(activdisplay.getAttribute('onload'));}
var innerdisplay2='';
/*
if(activdisplay.firstChild.xml){
e('display2').innerHTML=activdisplay.firstChild.xml;
}
else{
e('display2').innerHTML="";
for(var j=0; j<display.childNodes.length;j++){
e('display2').appendChild(activdisplay.childNodes[j].cloneNode(true)); 
}
e('display2').innerHTML=e('display2').innerHTML; //ВНИМАНИЕ! БУБЕН строчку не стирать!
}*/
if(!(/MSIE/.test(navigator.userAgent))){
  e('display2').innerHTML="";
  for(var j=0; j<display.childNodes.length;j++){
   e('display2').appendChild(display.childNodes[j].cloneNode(true));
  }
  e('display2').innerHTML=e('display2').innerHTML; //ВНИМАНИЕ! БУБЕН строчку не стирать!
	}
else
 {
	var ttext='';
	for(var j=0; j<display.childNodes.length;j++){
  ttext+=display.childNodes[j].xml;
 }
 e('display2').innerHTML=ttext;
 }
countstep=countstep-1;
e('display3').innerHTML=nameaction+" "+countstep+getWordLang('of')+ activdisplay.parentNode.childNodes.length;
if(activdisplay.getAttribute('focus')){e(activdisplay.getAttribute('focus')).focus();}
}}
//helpPanel.writeText(" ");
}



function buttonbottom()
{
	if(activdisplay!=null)
	{
		if(activdisplay.nextSibling!=null)
		{
			activdisplay=activdisplay.nextSibling;
			e('display1').innerHTML=activdisplay.getAttribute('display1');
			var innerdisplay2='';
			var display = activdisplay;
  			if(display.getAttribute('onload')){eval(activdisplay.getAttribute('onload'));}
/*if(window.ActiveXObject){
 e('display2').innerHTML=activdisplay.firstChild.xml;
}else{
e('display2').innerHTML="";
for(var j=0; j<display.childNodes.length;j++){

e('display2').appendChild(activdisplay.childNodes[j].cloneNode(true)); 
}
e('display2').innerHTML=e('display2').innerHTML; //ВНИМАНИЕ! БУБЕН строчку не стирать!
}*/
			if(!(/MSIE/.test(navigator.userAgent)))
			{
  				e('display2').innerHTML="";
  				for(var j=0; j<display.childNodes.length;j++)
				{
   					e('display2').appendChild(display.childNodes[j].cloneNode(true));
  				}
  				e('display2').innerHTML=e('display2').innerHTML; //ВНИМАНИЕ! БУБЕН строчку не стирать!
			}
			else
			{
				var ttext='';
				for(var j=0; j<display.childNodes.length;j++)
				{
					ttext+=display.childNodes[j].xml;
				}
 				e('display2').innerHTML=ttext;
 			}

			countstep=countstep+1;
			e('display3').innerHTML=nameaction+" "+countstep+getWordLang('of')+ activdisplay.parentNode.childNodes.length;
			if(activdisplay.getAttribute('focus')){e(activdisplay.getAttribute('focus')).focus();}
		}
	}
//helpPanel.writeText(" ");

}


function buttonok(){
eval(activdisplay.getAttribute('ok'));
}


function showError(text){
e('display2').innerHTML=text+"<br />"+e('display2').innerHTML;
}


function ButtonsWorkPanelOnClick(popupsName){
var popups;
var innerdisplay2="";

popups = xmlMenu.XMLDocument.documentElement.getElementsByTagName('popup');

  for (var i = 0; i < popups.length; i++)
   {
  if(popups[i].getAttribute('name')==popupsName){

	if(popups[i].getAttribute('bOnclick')){
	eval(popups[i].getAttribute('bOnclick'));
	}
  nameaction=popups[i].getAttribute('nameaction');

if(popups[i].firstChild){
  var display = popups[i].firstChild;
  if(display.getAttribute('onload')){eval(activdisplay.getAttribute('onload'));}
  e('display1').innerHTML=display.getAttribute('display1');
  var innerdisplay2='';
  if(!(/MSIE/.test(navigator.userAgent))){
  e('display2').innerHTML="";
  for(var j=0; j<display.childNodes.length;j++){

// Look Error here
   e('display2').appendChild(display.childNodes[j].cloneNode(true));
// may be like one
//    e('display2').innerHTML = e('display2').innerHTML + display.childNodes[j].xml;

// Look Error here

  }
//  alert(e('display2').innerHTML);
  e('display2').innerHTML=e('display2').innerHTML; //ВНИМАНИЕ! БУБЕН строчку не стирать!
}
else{

	var ttext='';
	for(var j=0; j<display.childNodes.length;j++){
ttext+=display.childNodes[j].xml;
}
e('display2').innerHTML=ttext;}

countstep=1;
e('display3').innerHTML=nameaction+" "+countstep+getWordLang('of')+ popups[i].childNodes.length;
activdisplay=display;   

if(activdisplay.getAttribute('focus')){e(activdisplay.getAttribute('focus')).focus();}}}
   }
   helpPanel.help(popupsName);
   e('helpButton').firstChild.innerHTML=getWordLang('buttonHelp');
}
