function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}


var mystyle=new Array();
var myid=new Array();
var myid2=new Array();
var myinterval=new Array();
var firefox=false;
var _ieVer=getInternetExplorerVersion();

var heights=new Array();
//var color
var realinterval=0;
ieHover = function() {
  slideEffect(['enewsblock', 'pressrelblock', 'speechesblock']);
  slideEffect(['ndnews0', 'ndnews1', 'ndnews2', 'ndnews3', 'ndnews4']);
  if((!(document.all)&&(!window.opera))||(_ieVer>7))
  {
    firefox=true;
  }
  if(window.dostosuj_dymek)
    dostosuj_dymek();
	var myul=document.getElementById('menubar')
	var ieULs = myul.getElementsByTagName('ul');
	var ieMat=0;
  if((_ieVer<8)&&(_ieVer>-1))
	{
    if (!window.XMLHttpRequest)
        document.body.onscroll=myscroller;
		for (j=0; j<ieULs.length; j++)
    {
    		ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe><div></div>' + ieULs[j].innerHTML);
  			ieMat = ieULs[j].childNodes[0];
				ieMat.style.width=ieULs[j].offsetWidth+"px";
				ieMat.style.height=ieULs[j].offsetHeight+"px";	
		}
		var sel=document.getElementsByTagName('select');
		if(sel.length>0)
		{
		  for(j=0; j<sel.length; j++)
		  {
		    var span=document.createElement('span');
		    sel[j].parentNode.insertBefore(span,sel[j]);
		    span.style.position='relative';
		  }
		}
  }
	for (j=0; j<ieULs.length; j++)
  {
  		ieULs[j].innerHTML = (ieULs[j].innerHTML+'<div id="ulid_'+j+'"></div>');
 			ieMat = document.getElementById('ulid_'+j);
			ieMat.style.width=(ieULs[j].offsetWidth-2)+"px";
      if((_ieVer<8)&&(_ieVer>-1))
			{
  			if(ieULs[j].offsetHeight>=18)
  			   ieMat.style.height=(ieULs[j].offsetHeight-18)+"px";
  			else
  			   ieMat.style.height=0;
  		}
  		else
  			ieMat.style.height=(ieULs[j].offsetHeight-2)+"px";
			ieMat.style.backgroundColor="#ffffff";
			ieMat.style.opacity="0.8";
			ieMat.style.filter="alpha(opacity=80)";
			ieMat.style.position="absolute";
			ieMat.style.top=0;
			ieMat.style.left=0;
			ieMat.style.zIndex=-1;
			ieMat.style.borderTop="solid 1px #eee";
			ieMat.style.borderLeft="solid 1px #eee";
			ieMat.style.borderBottom="solid 1px #ddd";
			ieMat.style.borderRight="solid 1px #ddd";
			ieULs[j].style.zIndex="99";
	}
	if(firefox)
	{
  	for (j=0; j<ieULs.length; j++)
  		ieULs[j].style.display="none";
	}
  var roznica=myul.parentNode.clientWidth-myul.clientWidth;
  if(roznica>0)
  {
    var ile=0;
    var test='';
    for(j=0;j<myul.childNodes.length;j++)
    {
//        test+=' '+myul.childNodes[j].style.width;
      if(myul.childNodes[j].nodeName.toLowerCase()=='li')
      {
        ile++;
      }
    }
    var poile=Math.floor(roznica/ile);
    var reszta=roznica%ile;
    for(j=0;j<myul.childNodes.length;j++)
      if(myul.childNodes[j].nodeName.toLowerCase()=='li')
      {
        myul.childNodes[j].style.paddingLeft=(Math.ceil(poile/2)+5)+'px';
        myul.childNodes[j].style.paddingRight=(Math.floor(poile/2)+5+((reszta>j) ? 1 : 0 ))+'px';
      }
  }
	var ieLIs = myul.getElementsByTagName('li');
  var ulid='';
  var alerted=0;
  var jakid=0;
	for (var i=0; i<ieLIs.length; i++) if (ieLIs[i])
  {
    ulid=ieLIs[i].id;
    ulid=ulid.replace(/^(.*?)_/,'_');
    var cn=ieLIs[i].className;
    if(cn.match(/menubar.*/))
      jakid=0;
    else
      jakid=1;
    ieLIs[i].jakid=jakid;
    ieLIs[i].i=0;
    ieLIs[i].maxi=5;
    if(jakid==0)
    {
      ieLIs[i].scolor='230,230,230';
      ieLIs[i].ecolor='0,0,0';
    } else
    {
      ieLIs[i].scolor='255,255,255';
      ieLIs[i].ecolor='195,213,239';
      ieLIs[i].maxi=1;
    }
    ieLIs[i].interval=false;
    ieLIs[i].zapalone=false;
    if(document.getElementById('menu'+ulid))
    {
      ieLIs[i].onmouseover=function() { if(!this.zapalone) { this.zapalone=true; this.interval=setTimeout('zapal("'+this.id+'")',10); } highlight(this,'menu'+this.id.replace(/^(.*?)_/,'_'),this.jakid); }
      ieLIs[i].onmouseout=function() { if(this.zapalone) { this.zapalone=false; this.interval=setTimeout('zgas("'+this.id+'")',10); } nohighlight(this,'menu'+this.id.replace(/^(.*?)_/,'_')); }
    } else
    {
      if(alerted==0)
      {
//        alert(ieLIs[i]);
        alerted=1;
      }
      ieLIs[i].onmouseover=function() { if(!this.zapalone) { this.zapalone=true; this.interval=setTimeout('zapal("'+this.id+'")',10); } highlight(this); }
      ieLIs[i].onmouseout=function() { if(this.zapalone) { this.zapalone=false; this.interval=setTimeout('zgas("'+this.id+'")',10); } nohighlight(this); }
    }
  }
  var leftmain=document.getElementById('leftmain');
  if(leftmain)
  {
  	var ieDIVs = leftmain.getElementsByTagName('div');
  	for(j=0;j < ieDIVs.length; j++)
  	{
      if(ieDIVs[j].className.match(/infofloater/))
      {
        if(ieDIVs[j].firstChild.offsetHeight>100)
        {
          ieDIVs[j].style.overflow='hidden';
          ieDIVs[j].id='scrolldivinfo'+j;
          ieDIVs[j].cnter=0;
          ieDIVs[j].style.height=100+'px';
          ieDIVs[j].clearit=setInterval('scrollinfo("'+ieDIVs[j].id+'")',100);
          ieDIVs[j].onmouseover=function() { clearInterval(this.clearit); }
          ieDIVs[j].onmouseout=function() { try { clearInterval(this.clearit); } catch(e) {} this.clearit=setInterval('scrollinfo("'+this.id+'")',100); }
          var clone=ieDIVs[j].firstChild.cloneNode(true);
          var p=document.createElement('p');
          p.style.margin='0';
          p.style.padding='5px 0px 5px 0px';
          p.style.textAlign='center';
          p.innerHTML='* * *';
          ieDIVs[j].appendChild(p);
          ieDIVs[j].appendChild(clone);
          ieDIVs[j].appendChild(p.cloneNode(true));
        }
      }
  	}
  }
  var div=document.getElementById('textndnews');
  if(div)
  {
    charcounter(div,290);
  }
  div=document.getElementById('whitepage');
  if(div)
  {
    var print=document.createElement('img');
    print.src='/images/printer.jpg';
    print.width='25';
    print.height='26';
    with(print.style)
    {
      //position='relative';
      margin='-13px 0 -13px -10px';
      display='block';
    }
    print.onclick=function() { window.print(); }
    div.insertBefore(print,div.firstChild);
  }
}

function do_sitemap(id)
{
  var sitemap=document.getElementById(id);
  if(sitemap)
  {
  	var ieULs = sitemap.getElementsByTagName('ul');
  	for(j=0;j < ieULs.length; j++)
  	 ieULs[j].style.display='none';
  	var ieIMGs = sitemap.getElementsByTagName('img');
  	for(j=0;j < ieIMGs.length; j++)
  	{
        if(ieIMGs[j].src.match(/\/images\/_tree_corn_/))
          ieIMGs[j].src='/images/_tree_corn_in.gif';
        else
          ieIMGs[j].src='/images/_tree_in.gif';
  	   ieIMGs[j].onclick=function() { sitemapopclose(this); }
  	}
  }
}

function scrollinfo(id)
{
  var div=document.getElementById(id);
  if(div)
  {
    if(div.cnter>(-(div.firstChild.offsetHeight+div.childNodes[1].offsetHeight)))
      div.cnter--;
    else
      div.cnter=5;
    div.firstChild.style.marginTop=div.cnter+'px';
  }
}

function sitemapopclose(id)
{
  var li=id.parentNode;
  for(i=0;i<li.childNodes.length;i++)
  {
    if(li.childNodes[i].nodeName.toLowerCase()=='ul')
    {
      if(li.childNodes[i].style.display=='none')
      {
        if(id.src.match(/\/images\/_tree_corn_/))
          id.src='/images/_tree_corn_out.gif';
        else
          id.src='/images/_tree_out.gif';
        li.childNodes[i].style.display='block';
      }
      else
      {
        if(id.src.match(/\/images\/_tree_corn_/))
          id.src='/images/_tree_corn_in.gif';
        else
          id.src='/images/_tree_in.gif';
        li.childNodes[i].style.display='none';
      }
      break;
    }
  }
}

function zapal(id)
{
  idz=document.getElementById(id);
  if(idz.zapalone)
  {
    if(idz.interval)
      clearTimeout(idz.interval);
    if(idz.i<idz.maxi)
    {
      var tmps=idz.scolor.split(",");
      var tmpe=idz.ecolor.split(",");
      var r=Math.floor(((parseInt(tmpe[0])-parseInt(tmps[0]))/idz.maxi)*idz.i)+parseInt(tmps[0]);
      var g=Math.floor(((parseInt(tmpe[1])-parseInt(tmps[1]))/idz.maxi)*idz.i)+parseInt(tmps[1]);
      var b=Math.floor(((parseInt(tmpe[2])-parseInt(tmps[2]))/idz.maxi)*idz.i)+parseInt(tmps[2]);
      if(idz.jakid==0)
        idz.style.color='rgb('+r+','+g+','+b+')';
      else
        idz.style.backgroundColor='rgb('+r+','+g+','+b+')';
      idz.interval=setTimeout('zapal("'+id+'")',10);
      idz.i++;
    } else
    {
      idz.i=idz.maxi;
      if(idz.jakid==0)
        idz.style.color='rgb('+idz.ecolor+')';
      else
        idz.style.backgroundColor='rgb('+idz.ecolor+')';
      clearTimeout(idz.interval);
    }
  }
}

function zgas(id)
{
  idz=document.getElementById(id);
  if(!idz.zapalone)
  {
    if(idz.interval)
    clearTimeout(idz.interval);

    if(idz.i>0)
    {
      var tmps=idz.scolor.split(",");
      var tmpe=idz.ecolor.split(",");
      var r=Math.floor(((parseInt(tmpe[0])-parseInt(tmps[0]))/idz.maxi)*idz.i)+parseInt(tmps[0]);
      var g=Math.floor(((parseInt(tmpe[1])-parseInt(tmps[1]))/idz.maxi)*idz.i)+parseInt(tmps[1]);
      var b=Math.floor(((parseInt(tmpe[2])-parseInt(tmps[2]))/idz.maxi)*idz.i)+parseInt(tmps[2]);
      if(idz.jakid==0)
        idz.style.color='rgb('+r+','+g+','+b+')';
      else
        idz.style.backgroundColor='rgb('+r+','+g+','+b+')';
      idz.interval=setTimeout('zgas("'+id+'")',10);
      idz.i--;
    } else
    {
      idz.i=0;
      if(idz.jakid==0)
        idz.style.color='rgb('+idz.scolor+')';
      else
        idz.style.backgroundColor='transparent';
      clearTimeout(idz.interval);
    }
  }
}

function checkmyid(id)
{
	for(i=0;i<myid.length;i++)
		if(myid[i]==id)
			return true;
	return false;
}
function highlight(id,explore,styl)
{
//	mystyle[id.id]=id.className;//.backgroundColor;
//	id.className=mystyle[id.id]+'highlight';
	aaa=id.parentNode.id;
	while(aaa)
	{
		if(aaa!='menubar')
		{
		addnohide(aaa);
		}
		aaa=document.getElementById(aaa).parentNode.id;
	}
	if(explore)
	{
		e=document.getElementById(explore);
		addnohide(explore);
	  if(firefox)
  		e.style.display="block";
		if(styl==0)
		{
			e.style.top=(e.parentNode.offsetTop+e.parentNode.offsetHeight)+'px';
			var sum=e.parentNode.offsetLeft+e.clientWidth;
			if(sum>document.body.clientWidth)			
			   e.style.left=(document.body.clientWidth-e.offsetWidth-1)+'px';
			else
				e.style.left=e.parentNode.offsetLeft+'px';
		}
		if(styl==1)
		{
			var sum=e.parentNode.parentNode.offsetLeft+e.parentNode.parentNode.offsetWidth+e.offsetWidth;
			e.style.top=(e.parentNode.offsetTop)+'px';
			if(sum>document.body.clientWidth)
				e.style.left=(e.parentNode.offsetLeft-e.parentNode.offsetWidth)+'px';
			else
				e.style.left=(e.parentNode.offsetLeft+e.parentNode.offsetWidth)+'px';
		}
	}
	clearInterval(realinterval);
	realinterval=setInterval('hidemenu()',10);
}
function addnohide(id)
{
	var jest=0;
	var pamiec=-1;
	for(i=0;i<myid.length;i++)
	{
		if(myid[i]==id)
			jest=1;
		if(myid[i]==0)
			pamiec=i;
	}
	v=0
	if(pamiec>-1)
		v=pamiec;
	else
		v=myid.length;
	if(jest==0)
	{
		if(pamiec>-1)
			myid[pamiec]=id;
		else
			myid[myid.length]=id;
	}
	var jest=0;
	for(i=0;i<myid2.length;i++)
	{
		if(myid2[i]==id)
			jest=1;
	}
	if(jest==0)
		myid2[myid2.length]=id;
}
function removenohide(id)
{
		for(i=0;i<myid.length;i++)
			if(myid[i]==id)
				myid[i]=0;
}
function nohighlight(id,explore)
{
	if(id.parentNode.id!='menubar')
		removenohide(id.parentNode.id);
	if(explore)
		removenohide(explore);
//	if(mystyle[id.id])
//	id.className=mystyle[id.id];
	clearInterval(realinterval);
	realinterval=setInterval('hidemenu()',1000);
}
function hidemenu()
{
	for(i=0;i<myid2.length;i++)
	{
		pamiec=-1;
		for(j=0;j<myid.length;j++)
		{
			if(myid[j]==myid2[i])
				pamiec=j;
		}
		if(pamiec==-1)
		{
			document.getElementById(myid2[i]).style.left="-10000px";
		  if(firefox)
  			document.getElementById(myid2[i]).style.display="none";
		}
	}
}

function charcounter(id,ile)
{
  id.ile=ile;
  var span=document.createElement('div');
  span.innerHTML=ile;
  span.style.disply='block';
  span.style.textAlign='right';
  span.id='textndnewscounter';
  id.parentNode.appendChild(span);
  id.onchange=id.onkeyup=function()
    {
      if(this.nextSibling)
        this.parentNode.removeChild(this.nextSibling);
      if(this.value.length>this.ile)
      {
        this.value=this.value.substr(0,this.ile);
      }
      var span=document.createElement('div');
      span.innerHTML=this.ile-this.value.length;
      span.style.disply='block';
      span.style.textAlign='right';
      span.id='textndnewscounter';
      this.parentNode.appendChild(span);
    }
}
function setstatuscheckbox(srcid,destid)
{
  var status=document.getElementById(srcid).checked;
  var inputs=document.getElementsByTagName('input');
  for(i=0;i<inputs.length;i++)
    if(inputs[i].id.match(destid))
    {
      inputs[i].checked=status;
    }
}
function computestatuscheckbox(srcid,destid)
{
  var status=false;
  var inputs=document.getElementsByTagName('input');
  for(i=0;i<inputs.length;i++)
    if(inputs[i].id.match(srcid))
    {
      if(inputs[i].checked)
      {
        status=true;
        break;
      }
    }
  document.getElementById(destid).checked=status;
}

function myscroller()
{
  var selekty=document.getElementsByTagName('select');
  for(i=0; i<selekty.length; i++)
  {
    //selekty[i].parentNode.style.height=selekty[i].parentNode.offsetHeight+"px";
    if(selekty[i].getBoundingClientRect().top<134)
      selekty[i].style.visibility="hidden";
    else
      selekty[i].style.visibility="visible";
  }
}

if (window.attachEvent) window.attachEvent('onload', ieHover);
if (window.addEventListener) window.addEventListener('load', ieHover,false);

function createHTTPreq()
{
	var opisik=false;
	try
	{
		opisik = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e)
	{
		try
		{
			opisik = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E)
		{
			opisik = false;
		}
	}

	if (!opisik && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			opisik = new XMLHttpRequest();
		} catch (e)
		{
			opisik=false;
		}
	}
	if (!opisik && window.createRequest)
	{
		try
		{
			opisik = window.createRequest();
		} catch (e)
		{
			opisik=false;
		}
	}
	return opisik;
}

function getcurrencies()
{
	
	var currency=createHTTPreq();
	var inputs=document.getElementsByTagName('input');
	for(var i=0; i<inputs.length; i++)
	{
	   if(inputs[i].id.match(/currency_/)) 
	     inputs[i].value="Wait...";
	}
	if(currency)
	{
  	currency.onreadystatechange=function() {
					if(currency.readyState == 4 && currency.status == 200)
					{
						if(currency.responseXML != null)
						{
						  var cur=currency.responseXML.getElementsByTagName('currency');
						  for(var i=0;i<cur.length;i++)
						  {
						    //alert(cur[i].childNodes[0].childNodes[0].nodeValue);
                document.getElementById('currency_'+cur[i].childNodes[0].childNodes[0].nodeValue).value=cur[i].childNodes[1].childNodes[0].nodeValue;
              }
						} else
						  alert('There were errors while loading currencies');
				 	} else if (currency.readyState == 4 && currency.status != 200)
					{
						  alert('Can not open the currencies page');
					} else
					{
					}
				}
	}
	currency.open("GET", "/?getcurrencies");
	currency.send(null);
}

function setreqfunding(id)
{
  var inputcur;
  var input=document.getElementById(id);
  if((currencies)&&(input))
  {
    for(var i=0;i<currencies.length;i++)
    {
      if((inputcur=document.getElementById(id+'_'+currencies[i]))&&(curvalues[i]))
      {
        var floattmp=parseFloat(input.value);
        if(isNaN(floattmp))
          inputcur.value='Error!';
        else
          inputcur.value=Math.round(floattmp/curvalues[i]);
      }
    }
  }
  if(dostosuj_dymek)
  {
    dostosuj_dymek();
  }
}

function db_prj_addorg(id)
{
/*  var iframe=document.getElementById('iframe_'+id);
  if(iframe)
  {
    iframe.src='/?pipeline,iframe,addorg,'+id;
    iframe.parentNode.style.display="block";
  }*/
}

function db_prj_addperson(id)
{
  /*var iframe=document.getElementById('iframe_'+id);
  if(iframe)
  {
    iframe.src='/?pipeline,iframe,addperson,'+id;
    iframe.parentNode.style.display="block";
  }*/
}
