// JavaScript Document
// <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

isNS = (navigator.appName == 'Netscape');
isIE = (navigator.appName.indexOf('Microsoft') != -1);
isOP = (navigator.appName == 'Opera');
ns4 = (document.layers);
ie4 = (document.all && !document.getElementById);
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function xGetElementById(e) {
	if(typeof(e)!='string') return e;
	if(document.getElementById) e=document.getElementById(e);
	else if(document.all) e=document.all[e];
	else e=null;
	return e;
}
function xInnerHtml(e,h){
	if(!(e=xGetElementById(e)) || !xStr(e.innerHTML)) return null;
	var s = e.innerHTML;
	if (xStr(h)) {e.innerHTML = h;}
	return s;
}
function xStr(s){
	for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
	return true;
}

// main menu stuff ===================================================================
/*
var vMenu = new Object();
vMenu.IDs = [];
vMenu.URIs = [];
*/
var nWait = new Number();
var timerId;
var timerHide;
var active;

function findCmd(ID) {
	var i = 0; for (i in vMenu.IDs) { if (vMenu.IDs[i] == ID) return i; }
	return i;
}

function menuCmd(ID, p) {
	var id = Number(ID);
	var _cmd = findCmd(ID);
	var _tStr = vMenu.URIs[_cmd];
	var _parseURI = _tStr.split(' : ');
	var _url = (_parseURI[2] == '#') ? '#' : _parseURI[2];
	var _targ = (_parseURI[3] == undefined) ? '' : _parseURI[3];
//	var _path = (p == undefined) ? '' : './';
	var a = (id%100 == 0) ? '' : '&a=' + ID;
	var href = ' href="' + _url + a + '" target="' + _targ +'"';
	var menu = [_parseURI[0], _parseURI[1], href];
	return menu;
}

function content(ID, what) { // layer id and content
	if (ie5 || ns6 || isOP) document.getElementById(ID).innerHTML = what;  
} 


function addItem(ID) {
	var actChk = '';
	var tmp = '';
	var id = Number(ID);
	var mnu = menuCmd(ID);
	if (id%100 == 0) {
		actChk = (ID==active) ? 'active' : mnu[0];
		tmp = '<div class="vmenu-nav-'+actChk+'"><a '+mnu[2]+' onMouseDown="doIt('+ID+'); this.blur(); return false"><div class="vmenu-nav-title">'+mnu[1]+'</div><div class="vmenu-nav-bullet"><img src="/pictures/prazen.gif" width="187" height="22" border="0"></div></a></div>';
	} else {
		tmp = '<div class="vmenu-sub"><a '+mnu[2]+' onMouseDown="doIt('+ID+'); this.blur(); return false"><div class="vmenu-nav-title-sub">'+mnu[1]+'</div><div class=""><img src="/pictures/prazen.gif" width="187" height="22" border="0"></div></a></div>';
	}
	return tmp;
}

//function addSubMenus(ID) {
function addSubMenus() {
	var ID = active;
	var tmp = '';
	var id = Number(ID);
	var i = 0;
	var iTmp = 0;

	//clearTimeout(nWait);
	window.clearTimeout(timerId);	
	for (i in vMenu.IDs) {
		if (Math.round(id/100) == Math.floor(Number(vMenu.IDs[i])/100)) {
			tmp += addItem(vMenu.IDs[i]);
		} else {
			if (Number(vMenu.IDs[i])%100 == 0) tmp += addItem(vMenu.IDs[i]);
		}
	}
	xInnerHtml('vmenu', tmp);
	
	o++;
}

var o = 0;
function doIt(ID) {
	if (active == ID) {
		doHide();
	} else {
		active = ID;
		if (timerId != undefined) {
			window.clearTimeout(timerId);
		}
		timerId = window.setTimeout("addSubMenus()", 350);
	}
}

function hideSubMenu() {
	var i=0;
	var id=0;
	var tmp='';
	active = 'NONE';
	if (timerHide != undefined) { window.clearTimeout(timerHide) }
	for (i in vMenu.IDs) {
		id = Number(vMenu.IDs[i]);
		// alert(id);
		if (id%100 == 0) tmp += addItem(id);
	}
	xInnerHtml('vmenu', tmp);
}

function doHide() {
	if (timerHide != undefined) { window.clearTimeout(timerHide) }
	timerHide = window.setTimeout("hideSubMenu()", 150);
}

function getVars(varName) {
	var _i;
	var _srch = window.location.search.substr(1);
	var _vars = _srch.split("&");
	for (_i in _vars) {
		var _v = _vars[_i].split("=");
		if (_v[0] == varName) {
			return _v[1];
			break;
		}
	}
	return "NONE";
}

var imageList=new Array(); 

function initMenu () {
	var tmp = '';
	var id = 0;
	var i = 0;
	var actChk = '';
	var images=new Array('vm_main_1.gif','vm_main_2.gif','vm_bullet.gif','vm_sub.gif'); 

	for (i in images) {  // preloading imgs
  		imageList[i] = new Image(); 
  		imageList[i].src = images[i]; 
  	} 
	
	active = getVars("a");
	if (active == "NONE") {
		for (i in vMenu.IDs) {
			id = Number(vMenu.IDs[i]);
			if (id%100 == 0) tmp += addItem(id);
		}
		xInnerHtml('vmenu', tmp);
	} else {
		actChk = active.substr(0,active.length-2) + '00';
		doIt(actChk);
		//this.timerId = window.setTimeout("addSubMenus()", 200);
	}
}

// end of main menu stuff ==============================================================

// --- Window functions -------------------------
function openWindow(url, name) {
  popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=no,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=770,height=500')
}

//example: openSizedWindow('http://www.mysite.com','myName','400','500');
function openSizedWindow(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=yes,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}

function openSizedWindowPlain(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=no,resizable=no,status=no,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}

function openSizedWindowUI(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=yes,personal=no,menubar=yes,location=yes,toolbar=yes,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}
// --- Window functions -------------------------


// still unused
function swap_img(img_src, img_txt) {
  var obj = document.getElementById('snimka');
  var obj2 = document.getElementById('img_tåxt');
	obj.src = img_src;
	obj2.innerHTML = img_txt; 
}

function crawler() {
	if (window.name!='sredna' && !((self.innerHeight == 0) && (self.innerWidth == 0))) top.location.replace('/');
}
function calcHeight_admin(koi) {
	var the_height=document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function calcHeight(koi) {
	crawler();
	var the_height=document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function sh_div(what) {
	 var i=0;
	 var coll = [];
	 while (document.getElementById('d'+ i)) {
	  coll[i] = document.getElementById('d'+ i);
		i++;
	 }
	obj = document.getElementById(what);
	var i=0;
	if (obj.className == 'off') {
		while (coll[i]) {
			coll[i].className = 'off';
			i++;
		} 
		obj.className = 'on';
	} else {
		obj.className = 'off';
	}
//	calcHeight('main_content');
}

// show pics
nSkladPics = 8; // br na kartinkite
nOfisPics = 8; // br na kartinkite
oWin = 0; // id na otv proz

function picShow2 (ID, what, lang) {
	var obekt = (what == undefined) ? 'ofis' : what;
	switch (obekt) {
		case 'ofis':	nPics = 11; break;
		case 'sklad':	nPics = 8; break;
		case 'tv':	nPics = 10; break;
		default:;
	}
	var l = (lang =='en') ? '_'+lang : '';
	if (oWin == 0 || this[obekt+ID].closed) {
		this[obekt+ID] = window.open ('show.htm?o='+obekt+'&amp;np='+nPics+'&amp;c='+ID+'&amp;l='+lang, obekt+ID, 'width=580, height=470, scrollbars=no');
	}
}

// fixing ifreme height in ie6
ie6 = (navigator.appVersion.indexOf('6.0') != -1);
function fixHeight() {
	var the_height= (ie6) ? 325 : 306;
	var obj = document.getElementById('main_content');
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}