function initNav1() {
	if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }
	document.onmousemove = nav1draw;
}

function getXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		$posx = e.pageX;
		$posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		$posx = e.clientX + document.body.scrollLeft;
		$posy = e.clientY + document.body.scrollTop;
	}
}

function getPath($root) {
	var $temp	= $root;
	var $path	= new Array();
	var $x		= 0;
	while (($temp != null) && ($temp.tagName != "BODY")) {
		$path[$x]	= $temp.tagName+"."+$temp.id;
		$x++;
	    $temp = $temp.parentElement;
	}
	return $path.join("/");
}
	
function getReal($el, $type, $value) {
	var $temp = $el;
	while (($temp != null) && ($temp.tagName != "BODY")) {
		if (eval("$temp."+$type) == $value) {
			return $temp;
	    }
	    $temp = $temp.parentNode;
	}
	return false;
}



/* [ NAV 1 ] */
var $currDiv	= false;
var $actDiv		= false;
var $allDiv		= new Array();
var $downDiv	= new Array();
var $upDiv		= new Array();
var $fogDelay	= 35;
var $fogStep	= 15;
var $inNav	= false;

var $watches, $posx, $posy;

function nav1draw($e) {
	if (!$e) { var $e = window.event; }
	getXY($e);
	$watches	= document.getElementById("watches");
	
	if (!$e.srcElement) {
		var $node = $e.target;
		while ($node.nodeType != 1) { $node = $node.parentNode; }
		var $srcElement = $node;
	} else {
		var $srcElement = $e.srcElement;
	}
	
	// $container	= getReal($srcElement, "className", "nav1");
	var $path	= getPath($srcElement);
	$inNav		= getReal($srcElement, "id", "nav1container");
	
	if ($inNav) { 
		refreshNav(); 
	} else { 
		hideAll(); 
	}
	
	// $from	= $e.relatedTarget ? $e.relatedTarget : $e.fromElement;
	/*
	$watches.style.display	= "";
	$watches.innerHTML 		= "["+$inNav+"]<br>X: "+findPosX($this)+"; Y: "+findPosY($this)+"<br>";
	$watches.innerHTML 		+= "W: "+$this.clientWidth+"; H: "+$this.clientHeight+"<br>";
	$watches.innerHTML 		+= "state: "+getOpacities()+"<br>down: "+$downDiv.join(";")+"<br>up: "+$upDiv.join(";")+"<br>";
	$watches.innerHTML 		+= "active: "+$actDiv+"; current: "+$currDiv;
	$watches.style.left		= ($posx-20)+"px";
    $watches.style.top		= ($posy+40)+"px";
	*/
}

function fogOn() {
	// "prjachem" -------------------------------
	var $div		= false;
	var $opacity	= false;
	for (var $id in $downDiv) {
		$opacity	= $downDiv[$id];
		$div		= document.getElementById("nav"+$id);
		$divX		= document.getElementById("navX"+$id);
		
		$div.style.opacity	= $opacity / 100;
		$div.style.filter	= "alpha(opacity="+$opacity+");";
		$divX.style.opacity	= $opacity / 100;
		$divX.style.filter	= "alpha(opacity="+$opacity+");";
		
		if ($opacity < 0) {
			$div.style.display	= "none";
			$divX.style.display = "none";
			removeFromArray($id, $downDiv);
		} else {
			$downDiv[$id]		= $opacity - $fogStep;
			window.setTimeout("fogOn()", $fogDelay);
		}
			
	}
	return false;
}

function fogOff() {
	// "pokazivajem" ----------------------------
	
	var $div		= false;
	var $divX		= false;
	var $opacity	= false;
	
	for (var $id in $upDiv) {
		$opacity	= $upDiv[$id];
		$div		= document.getElementById("nav"+$id);
		$divX		= document.getElementById("navX"+$id);
		$div.style.opacity	= $opacity / 100;
		$div.style.filter	= "alpha(opacity="+$opacity+");";
		$divX.style.opacity	= $opacity / 100;
		$divX.style.filter	= "alpha(opacity="+$opacity+");";
		
		if ($opacity > 100) {
			removeFromArray($id, $upDiv);
		} else {
			if ($div.style.display != "") {
				$div.style.display	= "";
				$divX.style.display	= "";
			}
			$upDiv[$id]			= $opacity + $fogStep;
			window.setTimeout("fogOff()", $fogDelay);
		}
	}
	return false;
}

function getOpacities() {
	var $div	= false;
	var $divX	= false;
	var $state	= "";
	var $opacity= 0;
	for (var $id in $allDiv) {
		$div	= document.getElementById("nav"+$allDiv[$id]);
		$state	+= $allDiv[$id]+": "+$div.style.opacity+"; ";
	}
	return $state;
}

function refreshNav() {
	// nado pokazatj currDiv, jelsi vne navigacii - pokazatj actDiv
	// fogOn -> downDiv; prjacem;
	// fogOff -> upDiv; pokazivajem;
	// for (var $id in $allDiv) { $downDiv[$allDiv[$id]] = "0"; }
	/*
	*/
	// "sverim" chasi
	var $div		= false;
	var $opacity	= false;
	for (var $id in $allDiv) {
		$div = document.getElementById("nav"+$allDiv[$id]);
		$divX = document.getElementById("navX"+$allDiv[$id]);
		// if ($div.style.display != "none") {
			if ($allDiv[$id] == $currDiv) {
				// $upDiv[$allDiv[$id]] = $div.style.opacity * 100;
				// removeFromArray($allDiv[$id], $downDiv);
				$div.style.display	= "";
				$divX.style.display	= "";
			} else {
				// $downDiv[$allDiv[$id]] = $div.style.opacity * 100;
				// removeFromArray($allDiv[$id], $upDiv);
				$div.style.display	= "none";
				$divX.style.display	= "none";
			}
		// }
		// }
	}
	// fogOff();
	// fogOn();
}

function hideAll() {
	// gasim vse, krome $actDiv
	var $div	= false;
	for (var $id in $allDiv) {
		$div 	= document.getElementById("nav"+$allDiv[$id]);
		$divX 	= document.getElementById("navX"+$allDiv[$id]);
		if ($allDiv[$id] == $actDiv) {
			if ($actDiv) {
				// $upDiv[$actDiv]		= $div.style.opacity * 100;
				$div.style.display	= "";
				$divX.style.display	= "";
				// removeFromArray($actDiv, $downDiv);
			}
		} else {
			$div.style.display	= "none";
			$divX.style.display	= "none";
			/*
			$div = document.getElementById("nav"+$allDiv[$id]);
			if ($div.style.display != "none") {
				$downDiv[$allDiv[$id]] = $div.style.opacity * 100;
			}
			*/
		}
	}
	/*
	fogOff();
	fogOn();
	*/
}

function showMe($this, $id, $dx, $dy) {
	if ($currDiv) { 
		$downDiv[$currDiv] = document.getElementById("nav"+$currDiv).style.opacity * 100;
	}
	if ($actDiv && $id!=$actDiv) 	{ 
		$downDiv[$actDiv] = document.getElementById("nav"+$actDiv).style.opacity * 100; 
	}
	
	$currDiv	= $id;
	
	var $div	= document.getElementById("nav"+$id);
	var $divX	= document.getElementById("navX"+$id);
	var	$x		= 0;
	var	$y		= 0;
	$x	= findPosX($this)-$dx;
	$y	= findPosY($this)-$dy;
	
	
	$div.style.left		= $x+"px";
    $div.style.top		= $y+"px";
	$div.style.left		= $x+"px";
	$divX.style.left	= $x+"px";
    $divX.style.top		= $y+"px";
	
    $div.style.display	= "";
    $divX.style.display	= "";
	
	$dx					= ($div.clientWidth - $this.clientWidth)/2;
	$div.style.left		= $x-$dx+"px";
	$divX.style.left	= $x-$dx+"px";
	// alert($dx);
	// $upDiv[$currDiv]	= "0";
}

function showDivFast($href, $id, $dx, $dy) {
	$this		= document.getElementById($href);
	var $div	= document.getElementById("nav"+$id);
	var $divX	= document.getElementById("navX"+$id);
	// var $href	= document.getElementById("href"+$id);
	var	$x		= 0;
	var	$y		= 0;
	$x	= findPosX($this)-$dx;
	$y	= findPosY($this)-$dy;
	$div.style.left		= $x+"px";
    $div.style.top		= $y+"px";
	$divX.style.left	= $x+"px";
    $divX.style.top		= $y+"px";
	/*
	$div.style.opacity	= "1.0";
	$div.style.filter	= "alpha(opacity=100);";
	$divX.style.opacity	= "1.0";;
	$divX.style.filter	= "alpha(opacity=100);";
	*/
	$divX.style.display	= "";
	$div.style.display	= "";
	return false;
}

// get coordinates 
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) { 
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}


/* [ NAV 2 ] */
function nav2detect($this) {
	var $cn		= $this.className;
	var	$size	= (($this.clientHeight - 16) / 14) + 1;
	var $class	= "size" + Math.round($size);
	switch ($cn.length>0) {
		case true: $this.className = $this.className + " " + $class; break;
		default: $this.className = $class; break;
	}
}

function nav2release($this) {
	var $cn	= $this.className;
	switch ($cn.length) {
		case 5: $this.className		= ""; break;
		default: $this.className	= "act"; break;
	}
}

/* [ MAIN WIDTH DETERMINITION ] */
function getWidth($this) {
	// return false;
}

function init() {
	if (window.initNav1) { initNav1(); }
	var $maxWidth	= 1030;
	// var $width	= (document.all) ? document.body.offsetWidth : window.innerWidth;
	var $width 		= (document.all) ? document.body.offsetWidth : window.innerWidth;
	var $width 		= $width - 20;
	// var $width	= self.screen.availWidth - 20;
	
	// rasporki
	var $o1	= document.getElementById("o1");
	var $o2	= document.getElementById("o2");
	var $o3	= document.getElementById("o3");
	var $o4	= document.getElementById("o4");
	/*
	if ($o1) { $o1.width = 197; }
	if ($o2) { $o2.width = 209; }
	if ($o3) { $o3.width = 421; }
	if ($o4) { $o4.width = 197; }
	*/
	/*
	if ($width > $maxWidth) {
		if ($o1) { $o1.width = 197; }
		if ($o2) { $o2.width = 209; }
		if ($o3) { $o3.width = 421; }
		if ($o4) { $o4.width = 197; }
	} else {
		var $k1		= 209/($maxWidth-197*2);
		var $k2		= 421/($maxWidth-197*2);
		var $mc1	= Math.round(($width - 197*2)*$k1);
		var $mc2	= Math.round(($width - 197*2)*$k2);
		if ($o1) { $o1.width = 197; }
		if ($o2) { $o2.width = $mc1; }
		if ($o3) { $o3.width = $mc2; }
		if ($o4) { $o4.width = 197; }
	}
	*/
	/* [ activate levels ] */
	if (window.nav1activate) 	{ nav1activate(); }
	if (window.nav2activate) 	{ nav2activate(); }
	if (window.formError) 		{ formError(); }
	if (window.formCV) 			{ formCV(); }
	
	/* [ input fields ]*/
	var $in		= document.getElementsByTagName('INPUT');
	var $parent	= false;
	for (var $i=0;$i<$in.length;$i++) {
		$parent1	= $in[$i].parentNode.parentNode;
		$parent2	= $in[$i].parentNode.parentNode.parentNode;
		if ($parent1 && $parent2 && $parent1.tagName=="DIV" && $parent2.tagName=="TD" && $parent2.className=="text1") {
			$in[$i].parentDiv	= $parent1;
			$in[$i].onfocus 	= function () {	this.parentDiv.className = "focus"; }
			$in[$i].onblur 		= function () {	this.parentDiv.className = ""; }
		}
	}
	/* [ textareas fields ]*/
	var $in		= document.getElementsByTagName('TEXTAREA');
	var $parent	= false;
	for (var $i=0;$i<$in.length;$i++) {
		$parent1	= $in[$i].parentNode;
		$parent2	= $in[$i].parentNode.parentNode;
		if ($parent1 && $parent2 && $parent1.tagName=="DIV" && $parent2.tagName=="TD" && $parent2.className=="text2") {
			$in[$i].parentTD	= $parent2;
			$in[$i].onfocus 	= function () {	this.parentTD.className = "text2 focus"; }
			$in[$i].onblur 		= function () {	this.parentTD.className = "text2"; }
		}
	}
	/* [ input file fields ]*/
	var $in		= document.getElementsByTagName('INPUT');
	var $parent	= false;
	for (var $i=0;$i<$in.length;$i++) {
		$parent1	= $in[$i].parentNode.parentNode;
		$parent2	= $in[$i].parentNode.parentNode.parentNode;
		if ($parent1 && $parent2 && $parent1.tagName=="DIV" && $parent2.tagName=="TD" && $parent2.className=="text1 text3") {
			$in[$i].parentDiv	= $parent1;
			$in[$i].onfocus 	= function () {	this.parentDiv.className = "focus"; }
			$in[$i].onblur 		= function () {	this.parentDiv.className = ""; }
		}
	}
}

/* [ ARRAY TOOLS ] */
function addUniqToArray($val, $array) {
	if (!isInArray($val, $array)) {
		$array.push($val);
	}
}

function removeFromArray($key, $array) {
	// predpolagajetsa chto elementi unikaljnije
	for (var $i in $array) {
		if ($i==$key) { $array.splice($i, 1); } 
	}
}

function isInArray($val, $array) {
	// function to avoid duplicates
	var n = $array.length;
	while (n--) { if ($array[n]==$val) { return true; } }
	return false;
}

/* [ VACANCIES ] */
function switchLead($this, $id) {
	var $div = document.getElementById("doc"+$id);
	
	if ($allDoc && $div.style.display == "none") {
		for (var $i in $allDoc) {
			document.getElementById("doc"+$allDoc[$i]).style.display 		= "none";
			document.getElementById("foldhref"+$allDoc[$i]).style.fontWeight= "normal";
		}
	}	
	$this.style.fontWeight	= $div.style.display=="none" ? "bold" : "";
	$div.style.display = $div.style.display=="none" ? "" : "none";
	return false;
}

function switchRadio($id, $type) {
	var $radio	= document.getElementById($id);
	var $hive	= document.getElementById("h"+$id);	
	$radio.checked	= $hive.value==1 ? null : 'checked';
	$hive.value		= $hive.value==1 ? 0 : 1;
	//return false;
}

function setButton($state, $button) {
	/*
	var $class	= $state==1 ? "button act" : "button";
	$button.className	= $class;
	*/
}
// function for popup ---------------------------
function advOpen(openUrl, openWidth, openHeight, openSwitch) {
    var srw = screen ? (screen.width-50)    : 750;
    var srh = screen ? (screen.height-36)   : 564;
    var openScroll  	= "0";
	var documentWrite	= "";
	var	openParameters	= "";
    if ((openWidth>srw) || (openHeight>srh)) {
        openScroll  = "1";
        if (openHeight>srh) { openWidth  = openWidth+16; openHeight = srh-50; }
        if (openWidth>srw)  { openHeight = openHeight+16; openWidth = srw-50; }
    }
    
    srw     = (srw - openWidth)/2;
    srh     = (srh - openHeight)/5;
    
  	var UTCstring;
  	Today = new Date();
  	UTCstring = Today.getUTCHours()*Today.getUTCMinutes()*Today.getUTCSeconds();
	
	var openName;
	openName        = "openPopup"+UTCstring;
    openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars="+openScroll+",titlebar=1,resizable=0";
    switch(openSwitch) {
        case "print":   openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0,menubar=1"; break;
        case "scroll":  openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0"; break;
    }
    var openPopup   = open(openUrl, openName, openParameters);
    return false;
}

function printPage() {
  var pr = (window.print) ? 1 : 0;
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // muut
    alert("Can't Print");
}

