var W3CDOM = (document.createElement && document.getElementsByTagName);
window.onload = all;
var timerID;


function all()
{
	if (!W3CDOM) return;
	// funkce
	new_window_link();
	goSearch();

	if (typeof(calc) != 'undefined')
	{
		calc.init();
	}

	if (typeof(smallcalc) != 'undefined')
	{
		smallcalc.init();
	}

	if (typeof(tooltip) != 'undefined')
	{
		tooltip.init();
	}
}

function goSearch(){

  if(document.getElementById('search')){
  document.getElementById('search').onclick = noValue;
  }
}

  function noValue(){
  document.getElementById('search').value = '';
  }

function new_window_link() {

var path_to_icon 		= '/images/exlink.gif';
var link_alt_text 		= 'Otevřít odkaz v novém okně';
var link_title_text 	= 'Otevřít odkaz v novém okně';

	if (!document.getElementById || !document.createTextNode || !document.domain || !document.getElementById('content')) return;
	var text = document.getElementById('content');
	var linx = text.getElementsByTagName('a');
	for (var i = 0; i < linx.length; i++)
	{
		// just for off-site links
		if (linx[i].href.length > 0)
		{
			if((linx[i].protocol == 'http:')||(linx[i].protocol == 'https:'))
			{

      	if ((linx[i].href.split('/')[2].replace(/www\./, '') != document.domain.replace(/www\./, '')||(linx[i].href.split('out.php')[1]))
				&& !linx[i].getAttribute('target')
				&& !linx[i].parentNode.id.match(/^copy/)
        && (linx[i].childNodes[0].tagName != 'IMG')
        )
				{
				linx[i].setAttribute('target', '_blank');
					// create new elements
					var nwl = document.createElement('a');
          var nwl_image = document.createElement('img');
					var space = document.createTextNode(' ');
					// setup image attributes
				nwl_image.setAttribute('src', path_to_icon);
				nwl_image.setAttribute('alt', link_alt_text);
				nwl_image.setAttribute('title', link_title_text);
				nwl_image.style.border = 'none';
				nwl_image.style.marginRight = '0.5em';
				// set link attributes
				nwl.setAttribute('href', linx[i].getAttribute('href'));
				nwl.setAttribute('target', '_blank');
				nwl.setAttribute('title', link_title_text);
				nwl.className = 'new_window_link';
				// append new elements
				nwl.appendChild(nwl_image);
				linx[i].parentNode.insertBefore(space, linx[i].nextSibling);
				linx[i].parentNode.insertBefore(nwl, linx[i].nextSibling.nextSibling);
				}
			}
		}
	}
}

