/**
 * addEvent
 */
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
	 obj.addEventListener(evType, fn, false); 
	 return true; 
 } else if (obj.attachEvent){ 
	 var r = obj.attachEvent("on"+evType, fn); 
	 return r; 
 } else { 
	 return false; 
 } 
}

/**
 * Replaces content of all the Tags with ID='ir-X' with image at 'images/X.png'
 */
function replace_titles()
{
	// Check for DOM support
	if (!(document && document.implementation && document.implementation.hasFeature))	return;

	// Check for image support
	if (!document.images)	return;
	
	var pattern = new RegExp('ir-\w?');
	var els = document.getElementsByTagName('*');
	var elsLen = els.length;
	var tags = new Array();	

	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].id) ) {
			tags[j] = els[i];
			j++;
		}
	}	

	for (var i = 0; i < tags.length; i++)	{
		if (tags[i].id) {
			var image = document.createElement('img');
			image.src = 'images/' + tags[i].id.replace('ir-','') + '.png';
			image.alt = tags[i].firstChild.nodeValue;
			image.title = tags[i].firstChild.nodeValue;
			tags[i].replaceChild(image,tags[i].firstChild);
		}
	}
}

addEvent(window, 'load', replace_titles);

/** 
 * external links
 * sets \target="_blank"\ for all the links with \rel="ext"\
*/
function external_links() {
  if (!document.body.getElementsByTagName) return false;
  var as = document.body.getElementsByTagName('a');
  for(var i=0; i<as.length; i++)
    if (as[i].getAttribute('rel') == 'ext')
      as[i].setAttribute('target','_blank');
  return true;
}

addEvent(window, 'load', external_links);

function przelicznik_walut() {
  var ilosc = parseInt(document.getElementById('f-ilosc').value);
  var waluta_z = parseInt(document.getElementById('f-waluta_z').value);
  var waluta_na = parseInt(document.getElementById('f-waluta_na').value);
  var wynik = ((waluta_z / waluta_na) * ilosc).toFixed(2);
  alert('Wynik kalkulacji: ' + wynik);
}

function change_iframe(){
  var page = document.getElementById('page-content');
  var iframe = document.getElementById('page-iframe');
  page.style.display = 'none';
  iframe.style.display = 'block';
  
}

function change_search(id) {
  var btn_1 = document.getElementById('ir-btn-wycieczki_lotnicze');
  var btn_2 = document.getElementById('ir-btn-dojazd_wlasny');
  var item_1 = document.getElementById('wycieczki_lotnicze');
  var item_2 = document.getElementById('dojazd_wlasny');
  if (id == 'dojazd_wlasny') {
    item_1.style.display = 'none';
    item_2.style.display = 'block';
    btn_1.className = '';
    btn_2.className = 'active';
  }
  if (id == 'wycieczki_lotnicze') {
    item_1.style.display = 'block';
    item_2.style.display = 'none';
    btn_1.className = 'active';
    btn_2.className = '';
  }
}

function pop(hib_url)
{
    if(typeof(hib_width) == 'undefined') hib_width=610;
    if(typeof(hib_height) == 'undefined') hib_height=465;
    var infowin = window.open(hib_url,'popup',"width="+hib_width+",height="+hib_height+",scrollbars=yes");
    infowin.focus();
}

function win_pop(url, width, height)
{
    if(typeof(width) == 'undefined') width=610;
    if(typeof(height) == 'undefined') height=465;
    var pop = window.open(url,'popup',"width="+width+",height="+height+",scrollbars=no");
    pop.focus();
}