var nazwa_klasy_menu='';

function $$(e) {
  return document.getElementById(e);
} 
function wlacz_menu(e) {
	for (var i=1;i<=9;i++) {
		if (e.id=='menu'+i) {
			//wlacz
			if (!$('#menu'+i).hasClass('over')) {
				$('#menu'+i).addClass('over');
			}
		} else {
			//wylacz
			if ($('#menu'+i).hasClass('over')) {
				$('#menu'+i).removeClass('over');
			}
		}
	}
}
function wylacz_menu(e) {
  if ($('#'+e).hasClass('over')) {
    $('#'+e).removeClass('over');
  }
}

function zmien_przezroczystosc(e, stan) {
  if (stan==1) {
    e.className='nieprzezroczysty';
  } else {
    e.className='przezroczysty';
  }
}

function zmien_polecane(rodzaj) {
	if (rodzaj=='noclegi') {
		var obj='polecane_noclegi_zmiana';
		var zrodlo=polecane_noclegi_panel;
		if (polecane_noclegi_i>polecane_noclegi_max-1) {
			polecane_noclegi_i=0;
		}
		var i=polecane_noclegi_i;
		
		//alert(obj);
	} else if (rodzaj=='oferty') {
		var obj='polecane_oferty_zmiana';
		var zrodlo=polecane_oferty;
		if (polecane_oferty_i>polecane_oferty_max-1) {
			polecane_oferty_i=0;
		}
		var i=polecane_oferty_i;
		//alert(obj);
	}
	if (!is_object(zrodlo[i])) return;
	//alert(zrodlo[i]);
	$("#"+obj+">div>h3").html("<A href=\""+zrodlo[i].link+"\">"+zrodlo[i].nazwa+"</a>");
	$("#"+obj+">div>div>a>img").attr('src',zrodlo[i].zdjecie);
	//$("#polecane_noclegi_zmiana>div>div>a>img").attr('src',zrodlo[i].zdjecie);
	$("#"+obj+">div>div>a").attr('href',zrodlo[i].link);
	$("#"+obj+">div>a").html(zrodlo[i].tytul_krainy);
	$("#"+obj+">div>a").attr('href',zrodlo[i].link_krainy);
	if (zrodlo[i].cena_od) {
		$("#"+obj+">div>b").html("Ceny od "+zrodlo[i].cena_od+" PLN");
	} else {
		$("#"+obj+">div>b").html("");
	}
	//$("#"+obj+">div>h3").html(zrodlo[i].link);
	if (rodzaj=='noclegi') {
		polecane_noclegi_i++;
	} else if (rodzaj=='oferty') {
		polecane_oferty_i++;
	}
}

function is_object (mixed_var) {
    if (mixed_var instanceof Array) {
        return false;
    } else {
        return (mixed_var !== null) && (typeof(mixed_var) == 'object');
    }
}

function SendRequest_ocena(id, rodzaj) {
	var dane="";
  dane+="&id="+id;
  dane+='&rodzaj='+rodzaj;
  dane+='&wyniki=1';
	$.ajax({  
    type: "POST",  
    url: global_link+"ajax/ocena.php",  
    data: dane,  
    success: function(response){
    	//alert(response);
      //alert("ocena_ok_"+rodzaj+"_"+id);
      if ($$("container_raty_"+id+"_"+rodzaj)) {
				$$("container_raty_"+id+"_"+rodzaj).innerHTML=response;
			}
    }  
  });  
}

function SendRequest_polecane(id, rodzaj, dodaj) {
	var dane="";
  dane+="dodaj="+dodaj;
  dane+="&id="+id;
  dane+='&rodzaj='+rodzaj;
  
	$.ajax({  
    type: "POST",  
    url: global_link+"ajax/polecane.php",  
    data: dane,  
    success: function(response){
    	//alert(response);
      //alert("ocena_ok_"+rodzaj+"_"+id);
      if ($$("odp_dodaj_do_polecanych")) {
				$$("odp_dodaj_do_polecanych").innerHTML=response;
			}
			if (response=='OK') {
				if ($$("polecane_odp_"+rodzaj+"_"+id)) {
					if (dodaj==1) {
						var srcn=global_link+"style/"+global_styl+"/ik/star.png";
					} else {
						var srcn=global_link+"style/"+global_styl+"/ik/star-empty.png";
					}
					$$("polecane_odp_"+rodzaj+"_"+id).src=srcn;
				}
			}
    }  
  });  
}

function SendRequest_sprawdzone(id, rodzaj, dodaj) {
	var dane="";
  dane+="dodaj="+dodaj;
  dane+="&id="+id;
  dane+='&rodzaj='+rodzaj;
  
	$.ajax({  
    type: "POST",  
    url: global_link+"ajax/sprawdzone.php",
    data: dane,  
    success: function(response){  
      //alert(response);
			$$("odp_sprawdzone"+id).innerHTML=response;
    }  
  });  
}

function potwierdz(delUrl, txt) {
  if (confirm(txt)) {
    document.location = delUrl;
  }
}
function tapeciarz(image) {
window.open("http://tapeciarz.mobile.net.pl/imageuploader-partner.xhtml?sid=332&img="+image,"Tapeciarz","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=745, height=425")
 }

function SendRequest_ocena_ok(id, rodzaj, dodaj, brak_glosowania) {
  var dane="";
  dane+="rodzaj="+rodzaj;
  dane+="&id="+id;
  if (dodaj==true) dane+='&dodaj=1';
  if (brak_glosowania==true) dane+='&brak_glosowania=1';
  
  $.ajax({  
    type: "POST",  
    url: global_link+"ajax/ocena_ok.php",  
    data: dane,  
    success: function(response){  
      //alert("ocena_ok_"+rodzaj+"_"+id);
      //alert(response);
      if ($$("ocena_ok_" + rodzaj + "_" + id)) {
        $$("ocena_ok_" + rodzaj + "_" + id).innerHTML = response;
        if (hs) {
          var expander = hs.getExpander();
          if (expander) {
            //alert(expander.caption.innerHTML);
            //alert(id);
            expander.caption.innerHTML=$$('caption_' + rodzaj + '_' + id).innerHTML;
            //expander.caption.getElementsByTagName('span')[0].innerHTML = xmlHttp.responseText + ' votes for this image';
            //alert('l');
            //hs_expander_do_podmiany = $('caption_' + rodzaj + '_' + id).innerHTML;
            //expander.aktualizacja();
          }
        }
      }
      else 
        $$("ocena_ok").innerHTML = response;
      
      //alert(hs);
      if ($$("kom_ocena_ok") && dodaj) {
        $$("kom_ocena_ok").innerHTML='';
      }
    }  
  });  
  return true;  
}
/*
function SendRequest_ocena_ok_old(id, rodzaj, dodaj, brak_glosowania) {
    var req = mint.Request();
    req.OnSuccess = function() {
		//alert("ocena_ok_"+rodzaj+"_"+id);
		if ($("ocena_ok_" + rodzaj + "_" + id)) {
			$("ocena_ok_" + rodzaj + "_" + id).innerHTML = this.responseText;
			if (hs) {
				var expander = hs.getExpander();
				if (expander) {
					//alert(expander.caption.innerHTML);
					//alert(id);
					expander.caption.innerHTML=$('caption_' + rodzaj + '_' + id).innerHTML;
					//expander.caption.getElementsByTagName('span')[0].innerHTML = xmlHttp.responseText + ' votes for this image';
					//alert('l');
					//hs_expander_do_podmiany = $('caption_' + rodzaj + '_' + id).innerHTML;
					//expander.aktualizacja();
				}
			}
		}
		else 
			$("ocena_ok").innerHTML = this.responseText;
		
		//alert(hs);
		if ($("kom_ocena_ok") && dodaj) {
			$("kom_ocena_ok").innerHTML='';
		}
    }
    req.AddParam('rodzaj',rodzaj);
	req.AddParam('id',id);
	if (dodaj==true) req.AddParam('dodaj',true);
	if (brak_glosowania==true) req.AddParam('brak_glosowania',true);
	req.Send(global_link+"ajax/ocena_ok.php");
	
   // var adres="ajax/ocena_ok.php?rodzaj="+rodzaj+"&id="+id;
    
    //alert(adres);
    //req.Send(adres);
}

function SendRequest_wyc_polecane(id, dodaj) {
    var req = mint.Request();
    req.OnSuccess = function() {
		$("odp_dodaj_do_polecanych").innerHTML=this.responseText;
    }
    req.AddParam('dodaj',dodaj);
	req.AddParam('id',id);
	req.Send("ajax_wyc_polecane.php");
}
function SendRequest_zdj_polecane(id, dodaj) {
    var req = mint.Request();
    req.OnSuccess = function() {
		$("odp_dodaj_do_polecanych_"+id).innerHTML=this.responseText;
    }
    req.AddParam('dodaj',dodaj);
	req.AddParam('id',id);
	req.AddParam('rodzaj','zdj');
	req.Send("ajax_wyc_polecane.php");
}
*/
function toggle(item2, stan) {
	var item = document.getElementById(item2);
	if (stan==1) item.style.display = '';
	else if (stan==2) item.style.display = 'none';
	else {
		if (item.style.display == '') {
			item.style.display = 'none';
		} else {
			item.style.display = '';
		}
	}
}

function zmien_img(img, plik) {
  $$(img).src=plik;
}

/*Zakladki*/
function zmien_zakladke(prefix, ktory, max, zmien_tez) {
	for (var i=1;i<=max;i++) {
		var e = document.getElementById("z_"+prefix+i);
		if (e!=null) {
			if (i==ktory) {
				e.className='zakladka';
				$('#'+prefix+i).slideDown('fast');
				if (zmien_tez) {
				  $('#pomoc_'+prefix+i).slideDown('fast');
				}
			} else {
				e.className='zakladka zakladka_off';
				$('#'+prefix+i).slideUp('fast');
				if (zmien_tez) {
          $('#pomoc_'+prefix+i).slideUp('fast');
        }
			}
			//toggle(prefix+i, stan);
		}
	}
}

/*Strona glowna*/

/*Wycieczki*/
var wyc_akt_rodzaj=0;
var wyc_akt_item=0;
var wyc_s;

function zmien_newsy_wyc(rodzaj, item, wylacz) {
	if (wylacz==1) {
		window.clearInterval(wyc_s);
	}
	wyc_akt_rodzaj=rodzaj;
	wyc_akt_item=item;
	for (var i=0;i<1;i++) {
		var e = document.getElementById("zakladka_wyc_"+i);
		if (e!=null) {
			if (i==rodzaj) {
				stan=1;
				e.className='zakladka';
			} else {
				stan=2;
				e.className='zakladka zakladka_off';
			}
			toggle("okno_wyc_"+i, stan);
		}
	}
	
	for (var i=0;i<13;i++) {
		var e = document.getElementById("numery_wyc_"+rodzaj+"_"+i);
		if (e!=null) {
			if (i==item) {
				stan=1;
				e.className='miniatura miniatura_on';
			} else {
				stan=2;
				e.className='miniatura';
			}
			toggle("okno_wyc_"+rodzaj+"_"+i, stan);
		}
	}
}
function uruchom_newsy_wyc() {
	wyc_s = window.setInterval("zmien_newsy_czas_wyc();", 10000);
	zmien_newsy_wyc(wyc_akt_rodzaj, wyc_akt_item);
}
function zmien_newsy_czas_wyc() {
	if (wyc_max[wyc_akt_rodzaj]>wyc_akt_item) {
		wyc_akt_item++;
	} else {
		if (wyc_akt_rodzaj==0) {wyc_akt_rodzaj=0;}
		else {wyc_akt_rodzaj++;}
		wyc_akt_item=0;
	}
	zmien_newsy_wyc(wyc_akt_rodzaj, wyc_akt_item);
}

/*Newsy*/
var akt_rodzaj=0;
var akt_item=0;
var s;

function zmien_newsy(rodzaj, item, wylacz) {
	if (wylacz==1) {
		window.clearInterval(s);
	}
	akt_rodzaj=rodzaj;
	akt_item=item;
	for (var i=0;i<4;i++) {
		var e = document.getElementById("zakladka_"+i);
		if (e!=null) {
			if (i==rodzaj) {
				stan=1;
				e.className='zakladka';
			} else {
				stan=2;
				e.className='zakladka zakladka_off';
			}
			toggle("okno_"+i, stan);
		}
	}
	
	for (var i=0;i<5;i++) {
		var e = document.getElementById("numery_"+rodzaj+"_"+i);
		if (e!=null) {
			if (i==item) {
				stan=1;
				e.className='numer numer_on';
			} else {
				stan=2;
				e.className='numer';
			}
			toggle("okno_"+rodzaj+"_"+i, stan);
		}
	}
}
function uruchom_newsy() {
	s = window.setInterval("zmien_newsy_czas();", 10000);
	zmien_newsy(akt_rodzaj, akt_item);
}
function zmien_newsy_czas() {
	if (max[akt_rodzaj]>akt_item) {
		akt_item++;
	} else {
		if (akt_rodzaj==3) {akt_rodzaj=0;}
		else {akt_rodzaj++;}
		akt_item=0;
	}
	zmien_newsy(akt_rodzaj, akt_item);
}


/** OG�LNE **/

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function odwroc_zaznaczenie_checkboxy(form) {
   var checkboxy = document.getElementById(form).getElementsByTagName('input');
   for (i = 0; i < checkboxy.length; i++) 
   	if (checkboxy[i].type == 'checkbox') {
   		if (checkboxy[i].checked==true) {
			checkboxy[i].checked = false;
		} else {
			checkboxy[i].checked = true;
		}
	}
}
function zaznacz_checkboxy(form) {
   var checkboxy = document.getElementById(form).getElementsByTagName('input');
   for (i = 0; i < checkboxy.length; i++) 
   	if (checkboxy[i].type == 'checkbox') {
   		checkboxy[i].checked = true;
	}
}


/*Najnowsze wycieczki*/
var nart_akt_rodzaj=0;
var nart_akt_item=0;
var nart_s;

function zmien_newsy_nart(rodzaj, item, wylacz){
  if (wylacz == 1) {
    window.clearInterval(nart_s);
  }
  nart_akt_rodzaj = rodzaj;
  nart_akt_item = item;
  for (var i = 0; i < 1; i++) {
    var e = document.getElementById("zakladka_nart_" + i);
    if (e != null) {
      if (i == rodzaj) {
        stan = 1;
        //e.className = 'zakladka zakladka_on';
      }
      else {
        stan = 2;
        //e.className = 'zakladka';
      }
      toggle("okno_nart_" + i, stan);
    }
  }
  
  for (var i = 0; i <=nart_max[nart_akt_rodzaj]; i++) {
    //alert(i);
    var e = document.getElementById("numery_nart_" + rodzaj + "_" + i);
    //alert(e+' '+"numery_nart_" + rodzaj + "_" + i);
    if (e != null) {
      if (i == item) {
        stan = 1;
        e.className = 'miniatura miniatura_on';
      }
      else {
        stan = 2;
        e.className = 'miniatura';
      }
      toggle("okno_nart_" + rodzaj + "_" + i, stan);
    }
  }
}
function uruchom_newsy_nart() {
  nart_s = window.setInterval("zmien_newsy_czas_nart();", 10000);
  zmien_newsy_nart(nart_akt_rodzaj, nart_akt_item);
}
function zmien_newsy_czas_nart() {
  if (nart_max[nart_akt_rodzaj]>nart_akt_item) {
    nart_akt_item++;
  } else {
    if (nart_akt_rodzaj==0) {nart_akt_rodzaj=0;}
    else {nart_akt_rodzaj++;}
    nart_akt_item=0;
  }
  zmien_newsy_nart(nart_akt_rodzaj, nart_akt_item);
}


/*Najnowsze krainy*/
var nkra_akt_rodzaj=0;
var nkra_akt_item=0;
var nkra_s;

function zmien_newsy_nkra(rodzaj, item, wylacz){
  if (wylacz == 1) {
    window.clearInterval(nkra_s);
  }
  nkra_akt_rodzaj = rodzaj;
  nkra_akt_item = item;
  for (var i = 0; i < 1; i++) {
    var e = document.getElementById("zakladka_nkra_" + i);
    if (e != null) {
      if (i == rodzaj) {
        stan = 1;
        //e.className = 'zakladka zakladka_on';
      }
      else {
        stan = 2;
        //e.className = 'zakladka';
      }
      toggle("okno_nkra_" + i, stan);
    }
  }
  
  for (var i = 0; i <=nkra_max[nkra_akt_rodzaj]; i++) {
    //alert(i);
    var e = document.getElementById("numery_nkra_" + rodzaj + "_" + i);
    //alert(e+' '+"numery_nkra_" + rodzaj + "_" + i);
    if (e != null) {
      if (i == item) {
        stan = 1;
        e.className = 'miniatura miniatura_on';
      }
      else {
        stan = 2;
        e.className = 'miniatura';
      }
      toggle("okno_nkra_" + rodzaj + "_" + i, stan);
    }
  }
}
function uruchom_newsy_nkra() {
  nkra_s = window.setInterval("zmien_newsy_czas_nkra();", 10000);
  zmien_newsy_nkra(nkra_akt_rodzaj, nkra_akt_item);
}
function zmien_newsy_czas_nkra() {
  if (nkra_max[nkra_akt_rodzaj]>nkra_akt_item) {
    nkra_akt_item++;
  } else {
    if (nkra_akt_rodzaj==0) {nkra_akt_rodzaj=0;}
    else {nkra_akt_rodzaj++;}
    nkra_akt_item=0;
  }
  zmien_newsy_nkra(nkra_akt_rodzaj, nkra_akt_item);
}


/*Najnowsze atrakcje*/
var natr_akt_rodzaj=0;
var natr_akt_item=0;
var natr_s;

function zmien_newsy_natr(rodzaj, item, wylacz){
  if (wylacz == 1) {
    window.clearInterval(natr_s);
  }
  natr_akt_rodzaj = rodzaj;
  natr_akt_item = item;
  for (var i = 0; i < 1; i++) {
    var e = document.getElementById("zakladka_natr_" + i);
    if (e != null) {
      if (i == rodzaj) {
        stan = 1;
        //e.className = 'zakladka zakladka_on';
      }
      else {
        stan = 2;
        //e.className = 'zakladka';
      }
      toggle("okno_natr_" + i, stan);
    }
  }
  
  for (var i = 0; i <=natr_max[natr_akt_rodzaj]; i++) {
    //alert(i);
    var e = document.getElementById("numery_natr_" + rodzaj + "_" + i);
    //alert(e+' '+"numery_natr_" + rodzaj + "_" + i);
    if (e != null) {
      if (i == item) {
        stan = 1;
        e.className = 'miniatura miniatura_on';
      }
      else {
        stan = 2;
        e.className = 'miniatura';
      }
      toggle("okno_natr_" + rodzaj + "_" + i, stan);
    }
  }
}
function uruchom_newsy_natr() {
  natr_s = window.setInterval("zmien_newsy_czas_natr();", 10000);
  zmien_newsy_natr(natr_akt_rodzaj, natr_akt_item);
}
function zmien_newsy_czas_natr() {
  if (natr_max[natr_akt_rodzaj]>natr_akt_item) {
    natr_akt_item++;
  } else {
    if (natr_akt_rodzaj==0) {natr_akt_rodzaj=0;}
    else {natr_akt_rodzaj++;}
    natr_akt_item=0;
  }
  zmien_newsy_natr(natr_akt_rodzaj, natr_akt_item);
}
/*Artykuly*/
var art_akt_rodzaj=0;
var art_akt_item=0;
var art_s;

function zmien_newsy_art(rodzaj, item, wylacz){
	if (wylacz == 1) {
		window.clearInterval(art_s);
	}
	art_akt_rodzaj = rodzaj;
	art_akt_item = item;
	for (var i = 0; i < 1; i++) {
		var e = document.getElementById("zakladka_art_" + i);
		if (e != null) {
			if (i == rodzaj) {
				stan = 1;
				//e.className = 'zakladka zakladka_on';
			}
			else {
				stan = 2;
				//e.className = 'zakladka';
			}
			toggle("okno_art_" + i, stan);
		}
	}
	
	for (var i = 0; i < 8; i++) {
		var e = document.getElementById("numery_art_" + rodzaj + "_" + i);
		if (e != null) {
			if (i == item) {
				stan = 1;
				e.className = 'miniatura miniatura_on';
			}
			else {
				stan = 2;
				e.className = 'miniatura';
			}
			toggle("okno_art_" + rodzaj + "_" + i, stan);
		}
	}
}
function uruchom_newsy_art() {
	art_s = window.setInterval("zmien_newsy_czas_art();", 10000);
	zmien_newsy_art(art_akt_rodzaj, art_akt_item);
}
function zmien_newsy_czas_art() {
	if (art_max[art_akt_rodzaj]>art_akt_item) {
		art_akt_item++;
	} else {
		if (art_akt_rodzaj==0) {art_akt_rodzaj=0;}
		else {art_akt_rodzaj++;}
		art_akt_item=0;
	}
	zmien_newsy_art(art_akt_rodzaj, art_akt_item);
}




/**
* Returns an XMLHttp instance to use for asynchronous
* downloading. This method will never throw an exception, but will
* return NULL if the browser does not support XmlHttp for any reason.
* @return {XMLHttpRequest|Null}
*/
function createXmlHttpRequest() {
 try {
   if (typeof ActiveXObject != 'undefined') {
     return new ActiveXObject('Microsoft.XMLHTTP');
   } else if (window["XMLHttpRequest"]) {
     return new XMLHttpRequest();
   }
 } catch (e) {
   changeStatus(e);
 }
 return null;
};

/**
* This functions wraps XMLHttpRequest open/send function.
* It lets you specify a URL and will call the callback if
* it gets a status code of 200.
* @param {String} url The URL to retrieve
* @param {Function} callback The function to call once retrieved.
*/
function downloadUrl(url, callback) {
 var status = -1;
 var request = createXmlHttpRequest();
 if (!request) {
   return false;
 }

 request.onreadystatechange = function() {
   if (request.readyState == 4) {
     try {
       status = request.status;
     } catch (e) {
       // Usually indicates request timed out in FF.
     }
     if (status == 200) {
       callback(request.responseXML, request.status);
       request.onreadystatechange = function() {};
     }
   }
 }
 request.open('GET', url, true);
 try {
   request.send(null);
 } catch (e) {
   changeStatus(e);
 }
};
/*
 * posx=0;posy=0;
  var ev=(!e)?window.event:e;//Moz:IE
  if (ev.pageX){posx=ev.pageX;posy=ev.pageY}//Mozilla or compatible
  else if(ev.clientX){
    posx = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
    posy = e.clientY+document.body.scrollTop+document.documentElement.scrollTop;
  }//IE or compatible
  else{return false}//old browsers
 */
function getPageSize(){
  var yScroll;
  yScroll=document.body.scrollTop+document.documentElement.scrollTop;
  /*
  if (window.innerHeight && window.scrollMaxY) {
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = document.body.offsetHeight;
  }
  */
  var windowHeight;
  if (self.innerHeight) { // all except Explorer
    windowHeight = self.innerHeight;
  } else if (document.documentElement &&     document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowHeight = document.body.clientHeight;
  }
  
  var windowWidth;
  if (self.innerWidth) { // all except Explorer
    windowWidth = self.innerWidth;
  } else if (document.documentElement &&     document.documentElement.clientWidth) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
  }
  //alert(parseInt(windowHeight)+' '+yScroll);
  windowHeight=parseInt(windowHeight/2)+parseInt(yScroll);
 
  arrayPageSize = new Array(windowWidth,windowHeight);
  return arrayPageSize;
}

function ustaw_na_srodku_ekranu(obiekt){
  var arrayPageSize = getPageSize();
  //alert(arrayPageSize);
  var obiekt = $$(obiekt);
  //alert(obiekt);
  obiekt.style.position="absolute";
  var szer=obiekt.offsetWidth;
  var wys=obiekt.offsetHeight;
  //szer=szer.replace("px","");
  //wys=wys.replace("px","");
  //alert(szer);
  var x = Math.round((arrayPageSize[1]-(wys/2)));
  var y = Math.round((arrayPageSize[0] - szer) / 2);
  //alert(x);
  obiekt.style.top = x + "px";
  obiekt.style.left = y + "px";
  //alert(obiekt.offsetHeight);
}

function zmien_toggle(id) {
  var img=$$('tg_'+id).src;
  $('#'+id).slideToggle('slow');
  if (img.match("up")) img=img.replace("up","down");
  else if (img.match("down")) img=img.replace("down","up");
  zmien_img('tg_'+id, img);
}

/**
 * Parses the given XML string and returns the parsed document in a
 * DOM data structure. This function will return an empty DOM node if
 * XML parsing is not supported in this browser.
 * @param {string} str XML string.
 * @return {Element|Document} DOM.
 */
function xmlParse(str) {
  if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') {
    var doc = new ActiveXObject('Microsoft.XMLDOM');
    doc.loadXML(str);
    return doc;
  }

  if (typeof DOMParser != 'undefined') {
    return (new DOMParser()).parseFromString(str, 'text/xml');
  }

  return createElement('div', null);
}

/**
 * Appends a JavaScript file to the page.
 * @param {string} url
 */
function downloadScript(url) {
  var script = document.createElement('script');
  script.src = url;
  document.body.appendChild(script);
}


// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.


// ***** Popup Control *********************************************************

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  //c.style.visibility = "visible";
  c.style.zIndex	=30000;
  $('#'+child).slideDown('fast');
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  
  wlacz_menu(p);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  
  var nazwa=this["at_parent"];
  
  //var txt="document.getElementById('"+c.id+"').style.visibility = 'hidden'; ";
  var txt="at_hide_aux('"+c.id+"'); ";
  if (nazwa.substring(0,4)=='menu') {
    txt=txt+" wylacz_menu('"+p.id+"');";
  }
  c["at_timeout"] = setTimeout(txt, 333);
}

function at_hide_aux(child) {
   $('#'+child).slideUp('fast');
}
// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  //c.style.visibility = "hidden";
  $('#'+child).hide();

  if (cursor != undefined) p.style.cursor = cursor;

 
  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function document_ready() {
	$(function() {
    $( ".datepicker" ).datepicker({
      changeMonth: true,
      changeYear: true,
      showButtonPanel: true,
      regional:"pl",
      dateFormat:"yy-mm-dd"
    });
  });
  $(function() {
    $( ".draggable" ).draggable();
  });
  $(function() {
  	$(":input").tipTip({
  		activation:"focus",
  		delay:100,
  		defaultPosition:"top"
  	});
  	$(".tt").tipTip({
  		delay:0,
  		defaultPosition:"top"
  	});
  });
	$(function() {
		$( ".podpowiedz_kraine" ).autocomplete({
			source: global_link+"ajax/autocomplete.php?rodzaj=1",
			select: function( event, ui ) {
				if ($$("id_krainy")) {
					$$("id_krainy").value=ui.item.id;
				}
				if ($$("tabela_dodatkow")) {
					toggle("tabela_dodatkow",2);
				}
			},
			search: function(event, ui) {
				if ($$("id_krainy")) {
					$$("id_krainy").value='';
				}
				if ($$("tabela_dodatkow")) {
					toggle("tabela_dodatkow",1);
				}
			}
		});
	});
	function split( val ) {
		return val.split( /,\s*/ );
	}
	function extractLast( term ) {
		return split( term ).pop();
	}
	$(function() {
		$( ".podpowiedz_kilka_krain" )
			.bind( "keydown", function( event ) {
				if ( event.keyCode === $.ui.keyCode.TAB &&
						$( this ).data( "autocomplete" ).menu.active ) {
					event.preventDefault();
				}
			})
			.autocomplete({
				source: function( request, response ) {
						$.getJSON( global_link+"ajax/autocomplete.php?rodzaj=1", {
							term: extractLast( request.term )
						}, response );
				},
				focus: function() {
					// prevent value inserted on focus
					return false;
				},
				select: function( event, ui ) {
					var terms = split( this.value );
					// remove the current input
					terms.pop();
					// add the selected item
					terms.push( ui.item.value );
					// add placeholder to get the comma-and-space at the end
					terms.push( "" );
					this.value = terms.join( ", " );
					return false;
				}
			});
	});
}

