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 heights=new Array();
var realinterval=0;
var _ieVer=getInternetExplorerVersion();

ieHover = function() {
 	var myul=document.getElementById('menubar')
	var ieULs = document.getElementById('menubar').getElementsByTagName('ul');
	if(window.attachEvent)
	{
		for (j=0; j<ieULs.length; j++)
    {
    		ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
  			var ieMat = ieULs[j].firstChild;
				ieMat.style.width=ieULs[j].offsetWidth+"px";
				ieMat.style.height=ieULs[j].offsetHeight+"px";	
				ieULs[j].style.zIndex="99";
		}
  }
	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-14)+"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 2px #ddd";
			ieMat.style.borderRight="solid 2px #ddd";
			ieULs[j].style.zIndex="99";
	}
  var roznica=myul.parentNode.offsetWidth-myul.clientWidth;
  if(roznica>0)
  {
    var ile=0;
    var test='';
    for(j=0;j<myul.childNodes.length;j++)
    {
      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';
      }
    myul.style.width=myul.parentNode.offsetWidth+"px";
  }
		var as=document.getElementsByTagName('a');
		if(as.length>0)
		{
		  for(j=0; j<as.length; j++)
		  {
		    if((as[j].className=='button')||(as[j].className=='button2'))
		    {
		      as[j].onfocus=as[j].onmousedown=function() { this.style.border="inset 2px"; }
		      as[j].onmouseup=as[j].onmouseout=as[j].onblur=function() { this.style.border="outset 2px"; }
		    }
		  }
		}
	var ieLIs = document.getElementById('menubar').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(/^(.*?)_/,'_');
    if(ieLIs[i].className.match(/menubar.*/))
      jakid=0;
    else
      jakid=1;
    if(document.getElementById('menu'+ulid))
    {
      ieLIs[i].jakid=jakid;
      ieLIs[i].onmouseover=function() {eval("highlight(this,'menu'+this.id.replace(/^(.*?)_/,'_'),this.jakid)");}
      ieLIs[i].onmouseout=function() {eval("nohighlight(this,'menu'+this.id.replace(/^(.*?)_/,'_'))");}
    } else
    {
      if(alerted==0)
      {
//        alert(ieLIs[i]);
        alerted=1;
      }
      ieLIs[i].onmouseover=function() {eval("highlight(this)");}
      ieLIs[i].onmouseout=function() {eval("nohighlight(this)");}
    }
  }

}

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;
	}
	var oilew=200;
	var oileh=20;
	if(navigator.userAgent.indexOf('MSIE')!=-1)
	{
		oilew=200;
		oileh=20;
	}
	if(explore)
	{
		e=document.getElementById(explore);
		addnohide(explore);
		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.offsetWidth)+'px';
			else
				e.style.left=(e.parentNode.offsetLeft+e.clientWidth)+'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";
		}
	}
}

function getfile(path,type,id,control)
{
  var div=document.createElement('div');
  if(document.getElementById('uploadmyfile'))
    document.getElementById('uploadmyfile').parentNode.removeChild(document.getElementById('uploadmyfile'));
  div.id='uploadmyfile';
  with(div.style)
  {
    width='400px';
    position='absolute';
    zIndex='99';
    border='solid 3px #000';
    background='#e5e5e5';
  }
  div.myvars=new Array();
  div.myvars[0]=path;
  div.myvars[1]=type;
  div.myvars[2]=id;
  div.myvars[3]=control;
  div.innerHTML='<iframe style="border: none;" border="0" width="390" height="400" src="/getfile.php?path='+path+'&type='+type+'&control='+control+'&curfile='+document.getElementById(control).value+'"></iframe>';
  id.parentNode.appendChild(div);
}

function db_prj_addorg(id,showdiv,donor,orgid)
{
  var tdid=document.getElementById('td_'+id);
  var selid=document.getElementById(id);
  if(orgid)
  {
  } else
    orgid=0;
  if(showdiv==1)
  {
    var divid=document.getElementById('div_'+id+'org');
    divid.style.display='block';
  }
  if(donor!=1)
    donor=0;
  var iframeid=document.getElementById('iframe_'+id);
  if(!iframeid)
  {
    iframeid=document.createElement('iframe');
    iframeid.id='iframe_'+id;
    iframeid.style.width='100%';
    iframeid.style.height='320px';
    iframeid.style.border='solid 1px #000';
    tdid.appendChild(iframeid);
  }
  iframeid.style.display="block";
  iframeid.src="/admin.php?method=database&dbs=organizations&method2=addiframe&elid="+id+"&donor="+donor+"&orgid="+orgid;
}

function db_prj_addperson(id)
{
  var tdid=document.getElementById('td_'+id);
  var selid=document.getElementById(id);
  var divid=document.getElementById('div_'+id+'org');
  divid.style.display='block';
  var iframeid=document.getElementById('iframe_'+id);
  if(!iframeid)
  {
    iframeid=document.createElement('iframe');
    iframeid.id='iframe_'+id;
    iframeid.style.width='100%';
    iframeid.style.height='320px';
    iframeid.style.border='solid 1px #000';
    tdid.appendChild(iframeid);
  }
  iframeid.style.display="block";
  iframeid.src="/admin.php?method=database&dbs=people&method2=addiframe&elid="+id;
}

function in_array(igla,arry)
{
  for(j=0;j<arry.length;j++)
    if(arry[j]==igla)
      return true;
  return false;   
}

function change_amount_type(number)
{
  switch(number)
  {
    case 2:
        var inputs=document.getElementsByTagName('input');
        for(i=0;i<inputs.length;i++)
        {
          inp=inputs[i];
          if(inp.id.match(/ndphs_area_price/))
            inp.disabled=false;
          else if(inp.id.match(/price/))
            inp.disabled=true;
        }
        document.getElementById('globalamount').disabled=true;
      break;
    case 3:
        var inputs=document.getElementsByTagName('input');
        for(i=0;i<inputs.length;i++)
        {
          inp=inputs[i];
          if(inp.id.match(/country_price/))
            inp.disabled=false;
          else if(inp.id.match(/price/))
            inp.disabled=true;
        }
        document.getElementById('globalamount').disabled=true;
      break;
    case 4:
        var inputs=document.getElementsByTagName('input');
        var countries=new Array();
        var tmpid;
        for(i=0;i<inputs.length;i++)
        {
          inp=inputs[i];
          if(inp.id.match(/region_price/))
          {
            inp.disabled=false;
            tmpid=inp.id.match(/region_price_(\d+)_/);
            if(tmpid)
            {
              if(!in_array(tmpid[1],countries))
                countries.push(tmpid[1]);
            }
          }
          else if(inp.id.match(/country_price/))
            inp.disabled=false;
          else if(inp.id.match(/price/))
            inp.disabled=true;
        }
        for(i=0;i<countries.length;i++)
          document.getElementById('country_price_'+countries[i]).disabled=true;
        document.getElementById('globalamount').disabled=true;
      break;
    default:
        var inputs=document.getElementsByTagName('input');
        for(i=0;i<inputs.length;i++)
        {
          inp=inputs[i];
          if(inp.id.match(/price/))
            inp.disabled=true;
        }
        document.getElementById('globalamount').disabled=false;
      break;
  }
}

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;
}
if (window.attachEvent) window.attachEvent('onload', ieHover);
if (window.addEventListener) window.addEventListener('load', ieHover,false);


