function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function imgSwap(imgid, imgsrc) {
    document.getElementById(imgid).src = imgsrc;
    return true;
}

function imgObjSwap(imgid, imgobj) {
    document.getElementById(imgid).src = imgobj.src;
    return true;
}

function imgTextSwap(nodeid, text) {
	document.getElementById(nodeid).innerHTML = text;
}

function imgBgSwap(nodeid, imgsrc) {
	document.getElementById(nodeid).style.backgroundImage = 'url('+imgsrc+')';
}

function classSwap(elid, className) {
	if (className) {
		document.getElementById(elid).setAttribute("class", className);
	} else {
		document.getElementById(elid).removeAttribute("class");
	}
}


// ----------------------------------------------
// HINT POPUP -----------------------------------
// ----------------------------------------------

var title;
var link;
var popup;
var $window;

function helpme( node ) {
	popup = document.createElement( 'DIV' );
	document.body.appendChild( popup );
	popup.innerHTML = title = node.getAttribute( 'title' );
	link = node.getAttribute( 'href' );
	if (link!="") addEvent( node, 'click', function() {  window.location = link; } ) ;
	node.removeAttribute( 'href' ); node.removeAttribute( 'title' );
	popup.className = "jsHelp";
	popup.style.position = "absolute";
	
	var bw = window.innerWidth?window.innerWidth:document.body.clientWidth;
	var pw = popup.offsetWidth;
	x = findPosX( node ) + 5;
	y = findPosY( node ) + 15;
	popup.style.left = ((x+pw)>bw?x-pw:x)+"px";
	popup.style.top  = y+"px";
}

function refreshme( node ) {
	if( !node ) return;
		node.setAttribute( 'title', title );
	if(link!="") node.setAttribute( 'href', link );
	if(popup) document.body.removeChild( popup );
}


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			if( obj.offsetParent.tagName == "HTML" ) break;
			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;
}

function addEvent( node, evtType, func ) {
	if( node.addEventListener ) {
		node.addEventListener( evtType, func, false );
		return true;
	} else if( node.attachEvent )
		return node.attachEvent( "on" + evtType, func );
	else
		return false;
}

// 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;
        case "payment":  openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",statusbar=0,scrollbars=1,titlebar=1,resizable=0"; break;
    }
	/*
	document.write(openUrl+"<br>");
	document.write(openName+"<br>");
	document.write(openParameters+"<br>");
	*/
    var openPopup   = open(openUrl, openName, openParameters);
    return false;
}

// functions for layers -------------------------
function layerStyle(layerObject){
  if(layerObject.style) return layerObject.style //доступ через style
  return layerObject //доступ без style
}
function layer(layerName){
  if(document.getElementById) return document.getElementById(layerName)
  if(document.all) return document.all[layerName]
  if(document.layers) return document.layers[layerName]
  return null
}

function printPageDistant() {
    var pr = ($window.print) ? 1 : 0;
    if (pr) { $window.print(); } else { alert("Can't Print"); }
}
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");
}

function openInOpener (url) {
	var $state = window.opener;
	if (window.opener && !window.opener.closed && $state!="null") {
		window.opener.document.location.href=url;
	} else {
		open(url, 'new', '');
	}
	return false;
}

function myDecode(input) {
	var output = input;
	output = output.replace(/</g, "<");
	output = output.replace(/>/g, ">");
	return output;
}

/* [ WATCHES ] ========================================================== */ 

var $watches, $posx, $posy, $hint;

function initFlash($id) {
	var $flashContainer = document.getElementById($id);
	if ($flashContainer) {
		var $flashMovie = document.createElement("div");
		$flashMovie.innerHTML = myDecode($flashContainer.innerHTML);
		$flashContainer.parentNode.insertBefore($flashMovie, $flashContainer);
		$flashContainer.parentNode.removeChild($flashContainer);
	}
}

function initHint($div) {
	$hint = document.getElementById($div);
	if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }
	document.onmousemove = getXY;
}

function initWatches($div) {
	$watches = document.getElementById($div);
	if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }
	document.onmousemove = getXY;
}

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 showInfo($this) {
	$watches.style.display = "";
	$container			= document.getElementById("container");
	$container.innerHTML= $this.getAttribute("alt") + "<br><SPAN>" + $this.getAttribute("title") + "</SPAN>";
	
	$watches.style.left	= ($posx)+"px";
    $watches.style.top	= ($posy-87)+"px";
	return false;
}

function show($this) {
	$watches.style.display = "";
	$watches.innerHTML 	= $this.getAttribute("alt");
//	$watches.innerHTML 	= $this.title+" [posX: "+$posx+"; posY: "+$posy+"]";
	$watches.style.left	= ($posx-3)+"px";
    $watches.style.top	= ($posy-27)+"px";
	return false;
}

function hide(e) {
	$watches.style.display = "none";
}

function showHint($this) {
	$hint.style.display = "";
	$hint.innerHTML 	= "<DIV>" + $this.getAttribute("alt") + "</DIV>";
	$hint.style.left	= ($posx-162)+"px";
    $hint.style.top		= ($posy+24)+"px";
	return false;
}

function hideHint(e) {
	$hint.style.display = "none";
}

/* [ NEIBGOURS ] ========================================================== */ 
var $hintn, $posx, $posy;

function initHintn($div) {
  $hintn = document.getElementById($div);
  if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }
  document.onmousemove = getXYn;
}


function getXYn(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 hiden(e) {
  $watches.style.display = "none";
}

function showHintn($this) {
  if (!$posx) return;
  $hintn.style.display = "";
  $hintn.innerHTML   = "" + $this.getAttribute("alt") + "";
  $hintn.style.left  = ($posx-125)+"px";
  $hintn.style.top    = ($posy-110)+"px";
  return false;
}

function hideHintn(e) {
  if ($hintn) $hintn.style.display = "none";
}
