function gid($co) {return document.getElementById($co);}

function init_page()
	{
	var $ee;
	//write_counter($stranka,$verze);
	init_opener();
	// preload_images();
	try{$form_control=new c_form_control();}
	catch($ee){}
	}

function find_class($element,$classnames,$result,$first)
  {
  if(!$first)$first=$element;
  if(!$result)$result=new Array();
  if ($element.nodeType==1)
    {
    var $test_exp=new RegExp("(^| )("+$classnames+")( |$)");
    if($test_exp.test($element.className)) $result[$result.length]=$element;
    }
  if ($element.hasChildNodes()) $result=find_class($element.firstChild,$classnames,$result,$first);
  if ($element.nextSibling && $element!=$first) $result=find_class($element.nextSibling,$classnames,$result,$first);
  return $result;
  }

function preload_images()
	{
	var $i,$img_src,$img=new Array();
	if(navigator.appName=="Microsoft Internet Explorer") $img_src=new Array("/img/dd/ie/drop-down-left.gif","/img/dd/ie/drop-down-right.gif","/img/dd/ie/drop-down-left-aktivni.gif","/img/dd/ie/drop-down-last-left.gif","/img/dd/ie/drop-down-last-left-aktivni.gif","/img/dd/ie/drop-down-last-right.gif");
	else $img_src=new Array("/img/dd/drop-down-left.png","/img/dd/drop-down-right.png","/img/dd/drop-down-left-aktivni.png","/img/dd/drop-down-last-left.png","/img/dd/drop-down-last-left-aktivni.png","/img/dd/drop-down-last-right.png");
	for($i=0;$i<$img_src.length;$i++)
		{
		$img[$i]=new Image();
		$img[$i].src=$img_src[$i];
		}
	}

// counter:

function write_counter(stranka,verze)
	{
	var ee;
	if(stranka)
		{
		var $src='/pocitadlo/counter.php?server=ave-bt&stranka='+stranka+'&verze='+verze+'&referer='+escape(top.document.referrer)+'&rozliseni_x='+screen.width+'&rozliseni_y='+screen.height+'&velikost_okna_x='+(top.innerWidth ? top.innerWidth : top.document.body.clientWidth)+'&velikost_okna_y='+(top.innerHeight ? top.innerHeight : top.document.body.clientHeight);
		try
			{
			counter.innerHTML="<img src='"+$src+"' />";
			}
		catch(ee)
			{
			var c_hory=document.createElement("img");
			with(c_hory)
				{
				id="pocitadlo";
				src=$src;
				alt="";
				width="0";
				height="0"
				}
			gid("counter").appendChild(c_hory);
			}
		}
	}

// new window:

function switch_new_win_stnd(e)
	{
	switch_new_win(e.currentTarget.checked);
	}

function switch_new_win(st)
	{
	document.cookie="neotevirat_v_novem_okne="+(st?"0":"1")+"; path=/";
	}

function get_anchor(el)
	{
	while(el.nodeName!="A") el=el.parentNode;
	return el;
	}

function open_anchor(e)
	{
	if(!e)e=window.event;
	var atarget=e.currentTarget?e.currentTarget:get_anchor(e.srcElement);
	open_new_window=document.getElementById("windowswitch").checked;
	atarget.target=open_new_window?"_blank":"";
	}

function check_anchor(a)
	{
	return false;
	test_exp=new RegExp("^(http(s)?://"+self.location.host+"|mailto:|#)");
	return ((!test_exp.test(a.href) || a.rel=="external" || a.className.indexOf("external")>-1) && a.href);
	}

function init_opener()
	{
	var i,e,open_new_window,anch,test_exp,found_ext_anchors,switchdiv;
	var sdtitle="open links pointing outside of this site in new window - recommended";
	var linktext=" open external links in new window";

	if(document.getElementsByTagName("a"))
		{
		open_new_window=document.cookie?((document.cookie.indexOf("neotevirat_v_novem_okne=1")>-1)?false:true):true;
		anch=document.body.getElementsByTagName("a");
		found_ext_anchors=0;
		for(i=0;i<anch.length;i++)
			{
			if(anch[i].href.indexOf("local-redir")>-1)anch[i].href=unescape("http://"+anch[i].href.substr(7,anch[i].href.substr(7).indexOf("/"))+anch[i].href.substr(anch[i].href.indexOf("=")+1));
			if(check_anchor(anch[i]))
				{
				anch[i].className+=" external";
				try
					{
					anch[i].addEventListener("click",open_anchor,true);
					}
				catch(e){}
				try
					{
					anch[i].onclick=open_anchor;
					}
				catch(e){}
				found_ext_anchors++;
				}
			}
		if(found_ext_anchors)
			{
			switchdiv=document.getElementById("windowopener");
			switchdiv.title=sdtitle;
			try
				{
				switchdiv.innerHTML="<input type='checkbox' id='windowswitch' onchange='switch_new_win(this.checked);' "+(open_new_window?"checked='checked' ":"")+"/>"+linktext;
				}
			catch(e)
				{
				var switchbox=document.createElement("input");
				switchdiv.appendChild(switchbox);
				switchbox.setAttribute("type","checkbox");
				switchbox.setAttribute("id","windowswitch");
				switchbox.addEventListener("change",switch_new_win_stnd,false);
				if(open_new_window) switchbox.checked=true;

				switchdiv.appendChild(document.createTextNode(linktext));
				}
			}
		}
	}
