/* Classes for menu
   programmer (c) Alexandr Vladykin, 2002-2003 <alexandr@vladykin.pp.ru>
   especcially for brickup technology
   v.0.5
   To do
   -- Sdelat' vozmozhnost' ispol'zovat' odin item dl'a mnogih paneley
   */

var menPanId = 0;
var itemId = 0;


isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isIE=isMSIE=document.all && document.all.item;// && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*

var __LEFT_BUTTON__ = (isMozilla || isOpera) ? 0 : 1;
var __RIGHT_BUTTON__ = 2;
var all_panels = new Array();
var all_menu_panels = new Array();
var panId = 0;
var menId = 0;
top.visible_panel = null;
top.vis = null;
var hiding_in = false;
var z_Index = 10000;

// Delat' pri onLoad...
// Spasibo Vova Grigoriev <vrussian@krovatka.net>
/*var loadId;
waitForLoading();

function waitForLoading () {
	loadId = window.setInterval("checkForLoad()", 1000);
}

function checkForLoad () {
	if (document.body) {
		window.clearInterval (loadId);
		myLoad();
	}
}


function myLoad () {
	setOnclick (docclick);
	setOncontext (docclick);
}*/

function docclick () {
	if (top.visible_panel) {
		top.visible_panel.rollout();
		top.visible_panel = null;
	}
}

                          
// ******************* Object TPanel *******************************
// paneli

// constructor            
function TPanel (doc, objid, itemDesign, imgWidth, imgHeight) {
     this.type = 'TPanel';
     this.docIn = doc;  // document (window.document), v kotoriy nuzhno vpisat' dannuyu panel'
     this.doc = doc;
     this.objid = objid;  // id objecta, v kotoriy nuzhno pomestit' dannuyu panel'
     this.itemDesign = itemDesign; // Dizayn dl'a vseh elementov paneli po umolchaniyu
     this.obj = this.doc.getElementById(this.objid); // Sam objekt na stranice
     this.imgWidth = imgWidth;
     this.imgHeight = imgHeight;
     this.items = new Array(); // Soderzhmiye elementy paneli, tipa TItem
     this.activeItem = null; // Aktivniy item
     all_panels[panId++] = this;
}                 

// Funkciya, vstavl'ayuschaya object (TItem) na opredelennuyu poziciyu (pos)
TPanel.prototype.insert = function(obj, pos) {
    _insertItem(this, obj, pos);
    return true;
}

// Funkciya, udal'ayuschaya object s opredelennoy pozicii
TPanel.prototype.remove = function(pos) {
    _removeItem (this, pos);
    return true;
}

TPanel.prototype.removeAll = function() {
    this.items.length = 0;
    return true;
}

// Funkciya, prevraschayuschaya panel v kod na JScript
TPanel.prototype.toJScript = function() {
	// Pod voprosom, nuzhna li?
}


// Funkciya, risuyuschaya panel so vsemi vhod'aschimi elementami
TPanel.prototype.draw = function() {
    var inn = this.obj.innerHTML;
    //this.obj.innerHTML = '';
    this.mtb =  this.doc.createElement ('TABLE');
    this.mtb.width = '100%';
    this.mtb.cellPadding = 0;
    this.mtb.cellSpacing = 0;
    this.mtr = this.mtb.insertRow(0);
    this.objLa = this.mtr.insertCell(0);
    this.objLa.align = 'left';
    //this.objLa.innerHTML = inn;
    this.objRa = this.mtr.insertCell(1);
    this.objRa.align = 'right';
    this.obj.appendChild(this.mtb);
    for (var i=0; i<=this.items.length-1; i++) {
        this.items[i].panel = this;
        this.items[i].roditel = this;
        this.items[i].draw();
    }
    //this.obj.onpropertychange = function(event) {alert (event.propertyName)};
    this.obj.onmouseover = function(event) {_FrameMouseOver(event)};
    this.obj.onmouseout = function(event) {_FrameMouseOut(event)};
    //alert (this.obj.onmouseout);
    return true;
}

// Funkciya, obnovl'ayuschaya panel'
TPanel.prototype.Refresh = function () {
    this.erase();
    this.draw ();
    return false;
}

// Funkciya, udal'ayuschaya panel' s ekrana;
TPanel.prototype.erase = function() {
    this.obj.innerHTML = '';
    return false;
}

TPanel.prototype.rollout = function() {
	if (this.activeItem) {
		this.activeItem.deactivate();
	}
}

// ******************* Object TItem *******************************
// Vse komandy menu

function TItem (img, caption, command, hint, menuPanel, align, disabled, disabledImg, itemDesign, imgWidth, imgHeight, hoverImg, activeImg) {
     this.type = 'TItem';
     this.img = img; // Kartinka
     this.caption = caption; // Nazvaniye elementa
     this.command = command; // Funkciya, vyzyvaemaya pri srabatyvanii objecta
     this.hint = hint;
     this.menuPanel = menuPanel; // Menu, kotoroye prinadlezhit dannomu itemu
     this.align = align ? align : 'left'; // Vyravnivanie
     this.disabled = disabled ? disabled : false;
     this.disabledImg = disabledImg; //Kartinka, esli element otkl'uchen
     this.itemDesign = itemDesign; // Dizayn elementa
     this.imgWidth = imgWidth;
     this.imgHeight = imgHeight; // Razmery kartinki
     this.hoverImg = hoverImg; // Kartinka, esli nad elementom provod'at myshkoy
     this.activeImg = activeImg; // Kartinka, esli element aktiven
     this.objid = '_ITEM_'+itemId++;
     this.active = false;
}

/*TItem.prototype.getPath = function () {
    if ((!this.numpp)&&(! (this.numpp === 0))) {
        return false;
    }
    return getPath(this);
}*/
 

TItem.prototype.draw = function() {
    var init = '';
    this.doc = this.roditel.docIn;
    this.itemDesign = this.itemDesign ? this.itemDesign : this.roditel.itemDesign;
    

    this.imgWidth = this.imgWidth ? this.imgWidth : this.roditel.imgWidth;
    this.imgHeight = this.imgHeight ? this.imgHeight : this.roditel.imgHeight;
 
    if (this.roditel.type == 'TPanel') {
    	init = this.doc.createElement('TABLE');
    	init.style.cursor = 'default';
    	init.style.display = 'inline';
    	init.cellPadding = 0;
    	init.cellSpacing = 0;
   	init.border = 0;
   	var io;
   	if (this.align=='left') {
   		io = this.panel.objLa
   	}
	else if (this.align=='right') {
		io = this.panel.objRa
	}
    	io.appendChild(init);
    	
    }
    else {
    	init = this.roditel.obj.getElementById('MAINTABLE');
    }

	this.obj = init.insertRow(init.rows.length);
	this.obj.scrObj = this;
	this.obj.onselectstart = function(event) {return false};
	this.obj.onmousemove = function(event) {return false};
	this.obj.onmouseover = function(event) {_MouseOver(event, this.scrObj)};;
	this.obj.onmouseout = function(event) {_MouseOut(event, this.scrObj)};
	this.objtdimg = this.obj.insertCell(this.obj.cells.length);
	this.objtdimg.vAlign = 'center';
	if (this.imgWidth) {
    		this.objtdimg.width = this.imgWidth ? this.imgWidth : 0;
	}
	if (this.imgHeight) {
    		this.objtdimg.height = this.imgHeight ? this.imgHeight : 0;
	}
	
	
    	if (this.img) {
    		this.objimg = this.doc.createElement('IMG');
    		this.objimg.align = 'absmiddle';
    		if (this.imgHeight) {this.objimg.height = this.imgHeight};
    		if (this.imgWidth) {this.objimg.width = this.imgWidth};
    		this.objtdimg.appendChild(this.objimg);
    		this.objimg.src = this.img;
    		this.notNormalImg=false;
    	}
	else {
		this.objtdimg.innerHTML = '&nbsp;';
	}

	this.objtdtxt = this.obj.insertCell(this.obj.cells.length);
	this.objtdtxt.vAlign = 'center';
	this.objtdtxt.align = 'left';
	if (this.caption) {
		this.tblcpt = this.doc.createElement ('TABLE');
		this.tblcpt.cellPadding = 0;
		this.tblcpt.cellSpacing = 0;
		this.tblcpt.width = '100%';
		this.tblcpt.style.border = '1px none black';
		setCommonDesign (this.tblcpt, this.itemDesign.normDesign.classText);
		this.trtxt = this.tblcpt.insertRow(0);
		this.objtxt =  this.trtxt.insertCell(0);
		this.objtxta = this.doc.createElement ('A');
		//if (isIE) {this.objtxta.href = '#none';}
	        this.objtxta.href = '#none';
        	this.objtxta.onclick = function (e) {return false;}
		this.objtxta.style.cursor = 'default';
		this.objtxta.style.textDecoration = 'none';
		this.objtxta.style.color = this.itemDesign.normDesign.classText;
		this.objtxta.onfocus = function (e) {this.blur()};
		this.objtxta.innerHTML = '&nbsp;'+this.caption+'&nbsp;&nbsp;';
		setCommonDesign (this.objtxta, this.itemDesign.normDesign.classText);
		this.objtxt.appendChild (this.objtxta);
		this.objtdtxt.appendChild (this.tblcpt);
	}
	if (this.roditel.type == 'TMenuPanel') {
		this.objhb = this.trtxt.insertCell(this.trtxt.cells.length);
		this.objhb.innerHTML = '&nbsp;';
		if (this.hotButton) {this.objhb.innerHTML = this.hotButton};

		this.objst = this.trtxt.insertCell(this.trtxt.cells.length);
		this.objst.innerHTML = '&nbsp;';
		if (this.menuPanel) {this.objst.innerHTML = '>';}
		this.objst.width = '10px';
	}
	
	if (this.hint) {
		this.obj.title = this.hint;
	}
	
	this.redesign(this.itemDesign.normDesign); 
	// Podgruzka ostal'nih kartinok
	if (this.disabledImg) {podgruzka_kartinki (this.doc, this.obj, this.disabledImg)};
	if (this.hoverImg) {podgruzka_kartinki (this.doc, this.obj, this.hoverImg)};
	if (this.activeImg) {podgruzka_kartinki (this.doc, this.obj, this.activeImg)};
	
    	if (this.disabled) {
    		this.disable()
    	}
	else {
		this.enable();
	}
	
   	if (this.menuPanel) {
            this.menuPanel.panel = this.panel;
            this.menuPanel.roditel = this;
            this.menuPanel.itemDesign = this.menuPanel.itemDesign ? this.menuPanel.itemDesign : this.roditel.itemDesign;
            this.menuPanel.imgWidth = this.menuPanel.imgWidth ? this.menuPanel.imgWidth : this.roditel.imgWidth;
            this.menuPanel.imgHeight = this.menuPanel.imgHeight ? this.menuPanel.imgHeight : this.roditel.imgHeight;
            this.menuPanel.draw(this.roditel.doc);
    	}	
	return 1;
}

TItem.prototype.redesign = function(newDesign) {
	if (newDesign) {
		if (this.objtxta) {
			if (newDesign.classText.color) {this.objtxta.style.color = newDesign.classText.color};	
		}
		setDesign (this.objtdtxt, newDesign.classText);
		setDesign (this.objtdimg, newDesign.classImage);
	}
}


function setDesign (elem, cl) {
	if (cl) {
		if (cl.backgroundColor) {elem.style.backgroundColor = cl.backgroundColor};		
		if (cl.border) {elem.style.border = cl.border};
		
		
		if (cl.borderBottom) {elem.style.borderBottom = cl.borderBottom};
		
		if (cl.borderTop) {elem.style.borderTop = cl.borderTop};
		
		if (cl.borderLeft) {elem.style.borderLeft = cl.borderLeft};
	
		if (cl.borderRight) {elem.style.borderRight = cl.borderRight};
		
		if (cl.color) {elem.style.color = cl.color};
	//	if (cl.font) {elem.style.font = cl.font};
		//if (cl.fontWeight) {elem.style.fontWeight = cl.fontWeight};
//		if (cl.fontSize) {elem.style.fontSize = cl.fontSize};
		/*if (cl.fontFamily) {elem.style.fontFamily = cl.fontFamily};
//		if (cl.borderWidth) {elem.style.borderWidth = cl.borderWidth};
//		if (cl.borderStyle) {elem.style.borderStyle = cl.borderStyle};
//		if (cl.borderColor) {elem.style.borderColor = cl.borderColor};

		if (cl.fontWeight) {elem.style.fontWeight = cl.fontWeight};
		if (cl.height) {elem.style.height = cl.height};*/
	}
/*	if (cl) {
		if (cl.height) {elem.style.heigth = cl.height};
		if (cl.width) {elem.style.width = cl.width};
		if (cl.cursor) {elem.style.cursor = cl.cursor};
		
		if (cl.color) {elem.style.color = cl.color};
		if (cl.backgroundColor) {elem.style.backgroundColor = cl.backgroundColor};
		if (cl.backgroundImage) {elem.style.backgroundImage = cl.backgroundImage};
		
		if (cl.textAlign) {elem.style.textAlign = cl.textAlign};
		if (cl.font) {elem.style.font = cl.font};
		if (cl.fontWeight) {elem.style.fontWeight = cl.fontWeight};
		if (cl.fontSize) {elem.style.fontSize = cl.fontSize};
		if (cl.fontFamily) {elem.style.fontFamily = cl.fontFamily};
		if (cl.fontWeight) {elem.style.fontWeight = cl.fontWeight};
		if (cl.fontColor) {elem.style.fontColor = cl.fontColor};
		
		if (cl.border) {elem.style.border = cl.border};
		if (cl.borderWidth) {elem.style.borderWidth = cl.borderWidth};
		if (cl.borderStyle) {elem.style.borderStyle = cl.borderStyle};
		if (cl.borderColor) {elem.style.borderColor = cl.borderColor};
		
		
		if (cl.borderBottom) {elem.style.borderBottom = cl.borderBottom};
		if (cl.borderBottomWidth) {elem.style.borderBottomWidth = cl.borderBottomWidth};
		if (cl.borderBottomStyle) {elem.style.borderBottomStyle = cl.borderBottomStyle};
		if (cl.borderBottomColor) {elem.style.borderBottomColor = cl.borderBottomColor};
		
		if (cl.borderTop) {elem.style.borderTop = cl.borderTop};
		if (cl.borderTopWidth) {elem.style.borderTopWidth = cl.borderTopWidth};
		if (cl.borderTopStyle) {elem.style.borderTopStyle = cl.borderTopStyle};
		if (cl.borderTopColor) {elem.style.borderTopColor = cl.borderTopColor};
		
		if (cl.borderLeft) {elem.style.borderLeft = cl.borderLeft};
		if (cl.borderLeftWidth) {elem.style.borderLeftWidth = cl.borderLeftWidth};
		if (cl.borderLeftStyle) {elem.style.borderLeftStyle = cl.borderLeftStyle};
		if (cl.borderLeftColor) {elem.style.borderLeftColor = cl.borderLeftColor};

		if (cl.borderRight) {elem.style.borderRight = cl.borderRight};
		if (cl.borderRightWidth) {elem.style.borderRightWidth = cl.borderRightWidth};
		if (cl.borderRightStyle) {elem.style.borderRightStyle = cl.borderRightStyle};
		if (cl.borderRightColor) {elem.style.borderRightColor = cl.borderRightColor};
	}*/
}


function setCommonDesign (elem, cl) {
	if (cl.font) {elem.style.font = cl.font;};
}

TItem.prototype.activate = function () {
	if (this.roditel.activeItem) {
		this.roditel.activeItem.deactivate();
	}
	this.roditel.activeItem = this;
	this.active = true;
	if (this.activeImg) {this.objimg.src = this.activeImg;this.notNormalImg=false;}
	this.redesign(this.itemDesign.activeDesign);
    	if (this.menuPanel) {
            this.menuPanel.showInMenu();	
            _FrameMouseOver();
        }
}

TItem.prototype.deactivate = function () {
	if (this.menuPanel) {
		if (this.menuPanel.activeItem) {
			this.menuPanel.activeItem.deactivate()
		}
		this.menuPanel.hide();
	}
	this.roditel.activeItem = null;
	this.active = false;
	this.toNormal();
}

TItem.prototype.toNormal = function () {
	if (this.notNormalImg) {this.objimg.src = this.img; this.notNormalImg=false;}
	this.redesign(this.itemDesign.normDesign);
}

TItem.prototype.hoverate = function () {
	if (this.roditel.activeItem) {this.roditel.activeItem.deactivate();}
	if (this.hoverImg) {this.objimg.src = this.hoverImg;this.notNormalImg=true;}
	this.redesign(this.itemDesign.hoverDesign);
}



TItem.prototype.execute = function () {
	if (!this.menuPanel) {
		docclick();
	}
	if (this.command) {eval (this.command);}
}

TItem.prototype.disable = function() {
	if (this.disabledImg) {this.objimg.src = this.disabledImg;this.notNormalImg=true;}
    	this.disabled = true;
    	this.obj.onclick = null;
	this.obj.onmousedown = null;	

	this.redesign(this.itemDesign.disabledDesign);
}

TItem.prototype.enable = function() {
	this.disabled = false;
    	this.obj.onclick = function(event) {_MouseClick(event, this.scrObj)};
	//this.obj.onmouseout = function(event) {_MouseOut(event, this.scrObj)};
	this.obj.onmousedown = function(event) {_MouseDown(event, this.scrObj)};
	this.obj.onmouseup = function(event) {_MouseUp(event, this.scrObj)};
	this.redesign(this.itemDesign.normDesign); 
}


var executing = false;

function _MouseClick (e, obj) {
	    	if (!e) {e = obj.obj.document.parentWindow.event};
    		e.cancelBubble = true;
    		if (!executing) {
    			if (obj.menuPanel) {
    				if (obj.active) {
					obj.deactivate();
					obj.hoverate();
				}
				else {
					obj.activate();
				}
			}
		}
	    	return true;
}


function _MouseOver (e, obj) {
	if (!obj.disabled) {
	if (obj.menuPanel) {
		if (obj.active) {
			_FrameMouseOver (e);
			return true;
		}
		if ((obj.roditel.activeItem)||(obj.roditel.type=='TMenuPanel')) {
			obj.activate();
		}
		else {
			obj.hoverate();
		}
		return true;
	}
	}
	else {
		if (obj.roditel.activeItem) {obj.roditel.activeItem.deactivate();}
		if (obj.roditel.type=='TPanel') {return;}
	}
	obj.hoverate();
}



function _MouseOut (e, obj) {
	//alert('Mouse out');
	if (obj.disabled) {
		//obj.redesign (obj.itemDesign.disabledDesign);
		obj.disable();
	}
	else {
		if (!obj.active) {
			obj.toNormal();
		};
	}
}

function _MouseUp (e, obj) {
	if (!e) {e = obj.obj.document.parentWindow.event};
	if (!executing) {
		if (e.button == __LEFT_BUTTON__) {
			if (obj.roditel.type!='TMenuPanel') {
				obj.execute();
			}
        	
			if (! obj.menuPanel) {
				obj.deactivate();
				obj.hoverate();
			}
		}
	}
	executing = false;
	return true;
}

function _MouseDown (e, obj) {
	if (!e) {e = obj.obj.document.parentWindow.event};
	if (e.button == __LEFT_BUTTON__) {
		if (! obj.menuPanel) {obj.activate()};
		if (obj.roditel.type=='TMenuPanel') {
			executing = true;
			obj.execute();
		}
	}
	return true;
}

// ******************* Object TItemClass ********************************
// classy

function TItemClass() {
	this.type = 'TItemClass';
}

// ******************* Object TItemDesign *******************************
// dizayn komand menu

function TItemDesign(classText, classImage) {
    this.type = 'TItemDesign';
    this.classText = classText;
    this.classImage = classImage ? classImage : classText;
}


// ******************* Object TItemDesigns ******************************
// konteyner vseh dizaynov komandy menu

function TItemDesigns (normDesign, hoverDesign, activeDesign, disabledDesign) {
	this.normDesign = normDesign;
	this.hoverDesign = hoverDesign;
	this.activeDesign = activeDesign;
	this.disabledDesign = disabledDesign;
}


// ******************* Object TMenuPanel *******************************
// Paneli menu

function TMenuPanel(Width, pClass, itemDesign, imgWidth, imgHeight) {
    this.type = 'TMenuPanel';
    this.Width = Width;
    this.pClass = pClass;  // Class dl'a vsego ifreima
    this.itemDesign = itemDesign; // Osobiy dizayn vseh elementov paneli
    this.imgWidth = imgWidth;
    this.imgHeight = imgHeight; // Osobie razmery kartinki dl'a vseh elementov paneli
    
    this.items = new Array();
    this.activeItem = null;
    this.objid = '_MenuPanel_'+menPanId++;
    this.doc = null;
    this.panel = null;
    all_menu_panels[menId++] = this;
}

TMenuPanel.prototype.insert = function(obj, pos) {
    obj.Width = '100%';
    _insertItem(this, obj, pos);
    return true;
}

TMenuPanel.prototype.remove = function(pos) {
    _removeItem (this, pos);
    return false;
}

// Spasibo Dmitry Koterov iz foruma www.xpoint.ru !!! SUPER!!!!!!!!!
TMenuPanel.prototype.draw = function(doc) {
        this.doc = doc;
        this.imageWidth = this.imageWidth ? this.imageWidth : this.roditel ? this.roditel.imageWidth : '';
    	var el = this.doc.createElement ('SPAN');
    	if (this.panel) {
    		this.panel.obj.appendChild(el);
    	}
	else {
		this.doc.body.appendChild(el);
	}
	el.innerHTML += '<iframe height=30 frameborder=0 scrolling=no width='+this.Width+' id='+this.objid+' style="visibility: HIDDEN; position: absolute; top:-1000; z-index:'+z_Index+'"></iframe>';
        this.parObj = this.doc.getElementById(this.objid);
        this.parObj.scrObj = this;
        
    	if ((this.doc.frames)&&(this.doc.frames[this.objid])) {
       		this.obj =  this.doc.frames[this.objid].document;
    	}
    	else if (this.doc.getElementById(this.objid)) {
        	this.obj = this.doc.getElementById(this.objid).contentDocument;
    	}
    	
        this.obj.open();
        this.obj.write('<BODY topMargin=0 bottomMargin=0 leftMargin=0 rightMargin=0 marginWidth=0 marginHeight=0 oncontextmenu="return false"><TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 id=MAINTABLE border=1 style="cursor:default"></TABLE></BODY>');
        this.obj.close();

       
	setStyles(this.doc, this.obj);
    	this.docIn = this.obj;
    	
    	setDesign (this.docIn.getElementById('MAINTABLE'), this.pClass);
    	this.docIn.onmouseover = function(event) {_FrameMouseOver(event)};
//	this.docIn.onmousemove = function(event) {_FrameMouseOver(event)};
//	this.docIn.onmouseout = function(event) {_FrameMouseOut(event)};
    	this.parObj.onmouseover = function(event) {_FrameMouseOver(event)};
    	this.parObj.onmousemove = function(event) {_FrameMouseOver(event)};
    	this.docIn.onmousemove = function(event) {_FrameMouseOver(event)};
//	this.docIn.onmouseout = function(event) {_FrameMouseOut(event)};
	this.parObj.onmouseout = function(event) {_FrameMouseOut(event)};
//	this.parObj.onblur = function(event) {_FrameMouseOut(event)};
//	this.parObj.onfocus = function(event) {_FrameMouseOver(event)};

    
    	for (var i=0; i<this.items.length; i++) {
        	this.items[i].panel = this.panel;
        	this.items[i].roditel = this;
        	this.items[i].draw();
    	}
    	return true;
}


function _FrameMouseOut (e) {
	//window.status = 'out';
	top.vis = null;
	window.setTimeout ("hideVisiblePanel()", 350);
	//setTimeOut(); //alert(obj.panel.type);
}


function _FrameMouseOver (e) {
	//window.status = 'over';
	top.vis = top.visible_panel;
	//setTimeOut(); //alert(obj.panel.type);
}

function hideVisiblePanel() {
	if (!top.vis && top.visible_panel) {
		top.visible_panel.rollout();
	}
}

TMenuPanel.prototype.showInMenu = function() {
      
      var tp = 0;
      var lf = 0;
      
      var up = this.roditel.roditel;
      
      if (up.type == 'TPanel') {
      		tp = getTop(up.obj)+up.obj.offsetHeight-2;
      		lf = getLeft(this.roditel.obj);
      		//alert (this.roditel.obj.outerHTML);
      }
      else if (up.type == 'TMenuPanel') {
		tp = getTop(up.parObj) + getTop(this.roditel.obj);
		//alert ('par='+getTop(up.parObj)+' th='+getTop(this.roditel.obj));
		lf = getLeft (up.parObj)+ up.parObj.offsetWidth-3;
		//alert ('getLeft(up.parObj)='+getLeft (up.parObj)+'  up.parObj.offsetWidth='+up.parObj.offsetWidth);
      }
      




      //alert ('lf='+lf+'  tp='+tp);
      this.show (lf, tp);
}



TMenuPanel.prototype.show = function(posX, posY) {
      // Vichisl'ayem, vilazit li menu za predeli ekrana, esli da, top podvigaem...
      var w = isIE ? (this.doc.body.scrollLeft + this.doc.body.clientWidth) : (this.doc.defaultView.innerWidth+this.doc.defaultView.pageXOffset-20);
      var h = isIE ? (this.doc.body.scrollTop + this.doc.body.clientHeight) : (this.doc.defaultView.innerHeight+this.doc.defaultView.pageYOffset-20);
      
      if ((posY+this.parObj.offsetHeight)>h) {
      	posY = h-this.parObj.offsetHeight;
      }
      
      if ((posX+this.parObj.offsetWidth)>w) {
      	if ((rod = this.roditel)&&(rod.roditel.type == 'TMenuPanel')) {
      			//posX = w-this.parObj.offsetWidth;
			var lp = getLeft (rod.roditel.parObj);
			if (lp - this.parObj.offsetWidth > 0) {
				posX = lp-this.parObj.offsetWidth+5;
			}
      		}
      		
	else  {
		posX = w-this.parObj.offsetWidth;
	}
      }






      if ((!this.roditel)||(this.roditel.roditel.type == 'TPanel')) {
      	if (top.visible_panel) {
      		top.visible_panel.hide();
      		top.visible_panel = null;
      	}
      }
      this.parObj.height = 0;
      var h = isIE ? this.obj.body.scrollHeight : this.obj.body.offsetHeight;
      this.parObj.height = h;
      this.parObj.style.left = posX;
      this.parObj.style.top = posY;
      this.parObj.style.visibility = "VISIBLE";
      //alert (this.parObj.ownerDocument.body.innerHTML);

      if (!top.visible_panel) {top.visible_panel=this;}
      //alert ('a');
}


TMenuPanel.prototype.hide = function() {
	var i=0;
	while (i<this.items.length) {
		if (this.items[i].menuPanel) {this.items[i].menuPanel.hide()}
		i++;
	}
	this.parObj.style.visibility = "HIDDEN";
	this.parObj.style.top = -1000;	
	//this.parObj.style.top = 20;
	//this.parObj.style.left = 10;
}



TMenuPanel.prototype.view = function() {
    alert (this.obj.body.innerHTML);
}

TMenuPanel.prototype.rollout = function () {
	if (this.roditel) {
		this.roditel.deactivate();
	}
	else {
		if (this.activeItem) {
			this.activeItem.deactivate();
		}
	}
	this.hide();
}


// ******************* Object THorzSeparator *******************************
// Gorizontal'nyi separator

function THorzSeparator (design) {
	this.design = design;
}

THorzSeparator.prototype.draw = function() {
	var init = this.roditel.obj.getElementById('MAINTABLE');
	this.obj = init.insertRow(init.rows.length);
	this.obj.onselectstart = function(event) {return false};
	this.obj.onmousemove = function(event) {return false};
	
	this.objtdimg = this.obj.insertCell(this.obj.cells.length);
	setDesign (this.objtdimg, this.roditel.itemDesign.normDesign.classImage);
	
	this.objtdtxt = this.obj.insertCell(this.obj.cells.length);
	setDesign (this.objtdtxt, this.roditel.itemDesign.normDesign.classText);
	
	this.objtblimg = this.roditel.obj.createElement ('TABLE');
	this.objtblimg.width = "100%";
	this.objtblimg.cellPadding = 0;
	this.objtblimg.cellSpacing = 0;
	setDesign (this.objtblimg, this.design.classImage);
	this.objtblimg.insertRow(0).insertCell(0);
	this.objtdimg.appendChild(this.objtblimg);
	
	
	this.objtbltxt = this.roditel.obj.createElement ('TABLE');
	this.objtbltxt.width = "100%";
	this.objtbltxt.cellPadding = 0;
	this.objtbltxt.cellSpacing = 0;
	setDesign (this.objtbltxt, this.design.classText);
	this.objtbltxt.insertRow(0).insertCell(0).style.height = '1px';
	this.objtdtxt.appendChild(this.objtbltxt);
}

// ******************* Object TVertSeparator *******************************
// Vertikal'nyi separator

function TVertSeparator (design, align) {
	this.design = design;
	this.align = align ? align : 'left';
}

TVertSeparator.prototype.draw = function() {
	this.doc = this.panel.docIn;
	this.obj = this.doc.createElement('TABLE');
	this.objtd = this.obj.insertRow(0).insertCell(0);
	this.objdiv = this.doc.createElement('DIV');
	this.objdiv.className = this.design;
	this.obj.style.display = 'inline';
	this.objdiv.style.display = 'inline';
	this.objtd.appendChild (this.objdiv);
   	var io;
   	if (this.align=='left') {
   		io = this.panel.objLa
   	}
	else if (this.align=='right') {
		io = this.panel.objRa
	}
    	io.appendChild(this.obj);
}


// ******************* Object TSelectObjecy*********************************
// Item v vide SELECT

function TSelectObject(design, align, disabled) {
	this.type = 'TSelectObject';
	this.design = design;
	this.align = align ? align : 'left';
	this.items = new Array();
	this.disabled = disabled ? disabled : false;
}

TSelectObject.prototype.insert = function (cpt, cmd, pos) {
	it = new TSelectItem (cpt, cmd);
	_insertItem (this, it, pos);
	it.roditel = this;
	if (this.obj) {
		it.draw();
	}
}

TSelectObject.prototype.remove = function (pos) {
	// Дописать процедуру удаления итема из селекта...
	this.items[pos].removeNode(true);
	_removeItem (this, pos);
}



TSelectObject.prototype.draw = function() {
	this.doc = this.roditel.doc;
	this.objtbl = this.doc.createElement('TABLE');
	this.objtd = this.objtbl.insertRow(0).insertCell(0);
	this.obj = this.doc.createElement('SELECT');
	this.obj.className = this.design;
	this.objtbl.style.display = 'inline';
	this.obj.style.display = 'inline';
	
	this.objtd.appendChild (this.obj);
   	var io;
   	if (this.align=='left') {
   		io = this.panel.objLa
   	}
	else if (this.align=='right') {
		io = this.panel.objRa
	}
    	io.appendChild(this.objtbl);
	
	for (var i=0; i<this.items.length; i++) {
		this.items[i].panel = this.panel;
		this.items[i].roditel = this;
		this.items[i].draw();
	}
	this.obj.onchange = function () {eval(this.options[this.selectedIndex].cmd)}
	if (this.disabled) {
    		this.disable()
    	}
	else {
		this.enable();
	}
}

TSelectObject.prototype.disable = function() {
	this.obj.disabled = true;
}


TSelectObject.prototype.enable = function() {
	this.obj.disabled = false;
	
}

// Vspom. object TSelectItem, Itemy selecta
function TSelectItem (cpt, cmd) {
	this.type = 'TSelectItem';
	this.cpt = cpt;
	this.cmd = cmd;
}

TSelectItem.prototype.draw = function () {
	this.doc = this.roditel.doc;
	this.obj = this.doc.createElement('OPTION');
	this.obj.innerHTML=this.cpt;
	this.obj.cmd = this.cmd;
	this.roditel.obj.appendChild (this.obj);
}

// *************************** Object TLabel ******************************
// Vse, chto ugodno
function TLabel (htmlText, align) {
	this.htmlText = htmlText;
//	this.pClass = pClass;
	this.align = align ? align : 'left';
}

TLabel.prototype.draw = function () {
	this.doc = this.roditel.doc;
	this.objtbl = this.doc.createElement('TABLE');
	this.objtd = this.objtbl.insertRow(0).insertCell(0);
	this.obj = this.doc.createElement('SPAN');
	this.obj.className = this.design;
	this.objtbl.style.display = 'inline';
	
	this.objtd.appendChild (this.obj);
   	var io;
   	if (this.align=='left') {
   		io = this.panel.objLa
   	}
	else if (this.align=='right') {
		io = this.panel.objRa
	}
    	io.appendChild(this.objtbl);
	this.obj.innerHTML = this.htmlText;	
}
//**************************************************************************
// Vspomogatel'nye funkcii
//**************************************************************************

// Vstavliaet noviy element
function _insertItem(into, item, pos) {
    pos --;
    var p = pos ? pos : into.items.length ? into.items.length : 0;
    if (p>=into.items.length) {
        item.numpp = into.items.length;
        into.items[item.numpp] = item;
    }
    else {
        for (var i=into.items.length; i>p; i--) {
            into.items[i-1].numpp++;
            into.items[i] = into.items[i-1];
        }
        item.numpp = p;
        into.items[item.numpp] = item;
    }
    return true;
}


function _removeItem (obj, pos) {
    for (var i=pos-1; i<obj.items.length-2; i++) {
	obj.items[i].numpp--;
        obj.items[i] = obj.items[i+1];
    }
    obj.items.length = obj.items.length - 1;
    return true;	
}

// Funkciya vozvraschayuschaya polniy put' k obyektu
/*function getPath (obj, str) {
        if (!str) {
            str = '';
        }
        if (obj.type=='TItem') {
            str = '.items['+obj.numpp+']'+str;
        }
        else if (obj.type == 'TMenuPanel') {
            str = '.menuPanel'+str;
        }
        else if (obj.type == 'TPanel') {
            str = obj.perem+str;
        }
        if (obj.roditel) {
            str = getPath (obj.roditel,str);
        }
        return str;
} */   

function getLeft (o) {
	var sum = 0;
	while (o.tagName != 'BODY') {
		//alert (o.tagName + '=' + o.offsetLeft);
		if (o.offsetLeft>0) {
			if (o.tagName != 'TBODY') {if (o.tagName!='SPAN') {sum += o.offsetLeft?o.offsetLeft:0}} else {sum -= (o.offsetTop?o.offsetTop:0)};
			
			//alert (o.tagName+'='+o.offsetLeft+' sum='+sum);
		}
		o = o.parentNode;
	}
	//window.status = o.contentWindow.pageXOffset;
	//sum += isIE ? o.document.body.scrollLeft : o.ownerDocument.contentWindow.pageXOffset;
	return sum;
}



function getTop (o) {
	var sum = 0;
	while (o.tagName != 'BODY') {
//		alert (o.tagName + '=' + o.offsetTop);
		if (o.offsetTop>0) {
			if (o.tagName != 'TBODY') {sum += o.offsetTop?o.offsetTop:0} else {sum -= (o.offsetTop?o.offsetTop:0)};
		}
		//if ((o.tagName == 'IFRAME')&&(o.parentNode.tagName=='SPAN')) {o = o.parentNode.parentNode};
		//if (o.tagName == 'IFRAME') {break();};
		if (o.tagName == 'IFRAME') {
				break;
		};
		if ((o.tagName == 'TD')&&(o.parentNode.tagName=='TR')) {o = o.parentNode};		
		o = o.parentNode;
	}
	//sum += isIE ? o.document.body.scrollTop : o.ownerDocument.contentWindow.pageYOffset;
	return sum;
}

// Spasibo Vladimir Palant!!! (iz foruma www.xpoint.ru)
function setStyles (from, to) {
	for (var i=0;i<from.styleSheets.length;i++){
		if (to.createStyleSheet)
		{
			var from_style = from.styleSheets(i);
			var in_style = to.createStyleSheet();
			for (var j=0;j<from_style.rules.length;j++) {
				try {
					in_style.addRule(from_style.rules(j).selectorText,from_style.rules(j).style.cssText);
				}
				catch (e) {}
			}
		}
		else
		{
			var from_style = from.styleSheets[i];
			var in_style = to.createElement('style');
			in_style.setAttribute('type','text/css');
			for (var j=0;j<from_style.cssRules.length;j++)
				in_style.appendChild(document.createTextNode(from_style.cssRules[j].cssText));
			if (to.getElementsByTagName('head').length)
				to.getElementsByTagName('head')[0].appendChild(in_style);
		}
	}
}

function podgruzka_kartinki (doc, obj, sour) {
	var tmpimg = doc.createElement('IMG');
	tmpimg.style.position = 'absolute';
	tmpimg.src = sour;
	tmpimg.style.top = -1000;
	obj.appendChild (tmpimg);
}




function setOnclick (func) {
	
/*	setInFrames (top.document, func);
	
	function setInFrames (doc, func) {
		doc.oldclick = doc.onclick;
		doc.newclick = func;
		// thanks to VRussian
		if (doc.oldclick){
			doc.onclick = function () {doc.oldclick(); doc.newclick();}
		}	
		else {
			doc.onclick = function () {doc.newclick();}
		}
		
		//doc.onclick = function () {if (doc.oldclick) {doc.oldclick();} doc.newclick();}
		var frms = new Array();
		if (doc.frames) {
			frms = doc.frames;
		}
		else {
			frms = frms.concat (doc.getElementsByTagName ('FRAME'));
			frms = frms.concat (doc.getElementsByTagName ('IFRAME'));
		}
		
		for (var i=0; i<frms.length; i++) {
			var d = frms[i].contentDocument ? frms[i].contentDocument : frms[i].document;
			setInFrames (d, func);
		}
	}*/
}

function setOncontext (func) {
	/*setInFrames2 (top.document, func);*/
}

function setInFrames2 (doc, func) {
   /*top.window.status = doc;
   if (!doc.body) {
   	window.myDoc = doc;
   	window.myFunc = func;
	window.setTimeout ('setInFrames2(window.myDoc, window.myFunc)', 1000);
   }
   else {
	doc.body.oldcontext = doc.body.oncontextmenu;
	doc.body.newcontext = func;
	doc.body.oncontextmenu = function () {doc.body.newcontext(); if (doc.body.oldcontext) {doc.body.oldcontext()}; return false;}
	var frms = new Array();
	if (doc.frames) {
		frms = doc.frames;
	}
	else {
		frms = frms.concat (doc.getElementsByTagName ('FRAME'));
		frms = frms.concat (doc.getElementsByTagName ('IFRAME'));
	}
	
	for (var i=0; i<frms.length; i++) {
		var d = frms[i].contentDocument ? frms[i].contentDocument : frms[i].document;
		setInFrames2 (d, func);
	}
   }*/
}