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  	= "yes";
	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=1";
    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 "printNow": 
			documentWrite	= '<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">function startPrint() { var pr=(window.print)?1: 0; if (pr) { window.print(); } else { alert("Can\'t Print"); } }</SCRIPT>'
			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);
	if (documentWrite.length>0) {
		$window	= openPopup;
		self.setTimeout('printPageDistant()', 2000);
	}
	
    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 initWidth() {
	var $left;
	var $center;
	var $right;
	
	var $colWidth;
	var $newPercent;
	var $newPercentSide;
	
	$left	= document.getElementById("ifMoreLeft");
	$center	= document.getElementById("ifMoreFix");
	$right	= document.getElementById("ifMoreRight");
	
	$width 		= (document.all) ? document.body.offsetWidth : window.innerWidth;
	$colWidth	= $width*0.86;
	
	if ($colWidth>1024) {
		$newPercent		= 86*1024/$colWidth;
		$newPercentSide	= (100-$newPercent)/2;
		
		$left.width 	= $newPercentSide+"%";
		$center.width	= $newPercent+"%";
		$right.width 	= $newPercentSide+"%";
	}
}



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;
}
