function getID(id,doc)
{
	if (!doc) doc = document;
	if (document.all) return doc.all[id];
	else return doc.getElementById(id);
}
function stopBubble(e)
{
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
}
function stopDefault(e)
{
	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}
/* opens window and cancels the event if successfull */
function openAWin(path,width,height,ev,namewin,scrollbar, menubar, widgets) 
{
	if (!ev) ev = window.event;
	if (!ev) { alert("No event in openAWin"); return false; }
	if (!openWin(path,width,height,namewin,scrollbar, menubar, widgets)) return null;
	stopDefault(ev); stopBubble(ev);
	return false;
}

function openWin(path,width,height,namewin,scrollbar, menubar, widgets)
{
	if(window.anewWin)
		window.anewWin.close();
	if(!namewin) namewin = 'nove_okno';
//    if(!width || !height) anewWin = window.open(path,namewin,'menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');

	if(widgets == "none") {
		anewWin = window.open(path,namewin,"width="+width+",height="+height+",toolbar=0,directories=0,location=0,menubar=0,status=0,scrollbars=" + (scrollbar ? scrollbar : 0) + ",resizable=yes");
	}
	else if(scrollbar && menubar)  {
		anewWin = window.open(path,namewin,"width="+width+",height="+height+",menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes");
	}
	else if(scrollbar)  {
		anewWin = window.open(path,namewin,"width="+width+",height="+height+",toolbar=0,directories=0,menubar=0,status=0,scrollbars=1,resizable=yes");
	// bez scrollbaru a menu baru
	}
	else {
		anewWin = window.open(path,namewin,"width="+width+",height="+height+",toolbar=0,directories=0,location=0,menubar=0,status=0,scrollbars=0,resizable=yes");
	}
	anewWin.focus();
	return anewWin;
}

function confirm_delete(id,alert_text)
{
	  var el = getID(id);
	  if(el.checked)
			return confirm(alert_text);
}

function confirm_delete_checkbox (id, alert_text)
{
	var el = getID(id);
	for (var i = 0; i < el.elements.length; i++) {
		if(el.elements[i].checked)
			return confirm(alert_text);
	}
	return true;
}

// nepouziju, pac to kontrolovat ve woknech je humus - mezery v nazvech adersaru ...
function check_file_nazev (id, alert_text)
{
	var el = getID(id);
	var el_id = new Array();
	for (var i = 0; i < el.elements.length; i++) {
		el_id[i] = getID(el.elements[i].id);
		if(el.elements[i].id.substr(0,8) == "userfile" && el.elements[i].value)
			if(!zkontroluj_nazvy_souboru(el.elements[i].value))
				alert(el.elements[i].value + " " + alert_text)
	}
//	return true;
}
// nepouziju, pac to kontrolovat ve woknech je humus - mezery v nazvech adersaru ...
function zkontroluj_nazvy_souboru(nazev_souboru)
{
	re = /^[a-z|A-Z|0-9| |\-|_|.|\/|:|\\]*$/;
	return nazev_souboru.search(re) == 0;
}

function zkontroluj_email(adresa)
{
	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
	return adresa.search(re) == 0;
}

function myConfirm(alert_text) {
	return confirm(alert_text);
}

function printpage() {
	window.print();  
}

function checkcaptchafill(c, ct, alert_text, date_check)
{
	var c_id = getID(c);
	var ct_id = getID(ct);
//	alert (MD5(ct_id.value));
	if(date_check == "date_from_to" )
		testDate('date_from', 'date_to');
	if(!trim(ct_id.value)) {
		alert(alert_text);
		ct_id.focus();
		return false;
	}

	if(MD5(trim(ct_id.value)) != c_id.value) {
		alert(alert_text);
		ct_id.focus();
		return false;
	}
	return true;
}

function trim(s)
{
  return rtrim(ltrim(s));
}

function ltrim(s)
{
  var l=0;
  while(l < s.length && s[l] == ' ')
  {	l++; }
  return s.substring(l, s.length);
}

function rtrim(s)
{
  var r=s.length -1;
  while(r > 0 && s[r] == ' ')
  {	r-=1;	}
  return s.substring(0, r+1);
}

function changebg(id)
{
	var idbg = getID(id);	
	var content = getID("art_content");
	var mainid = getID('main');
	var setbg = "white url('photos/" + id + ".jpg') no-repeat 171px 155px";
	mainid.style.background=setbg;
	content.innerHTML = "";
	return false;
}

function switchscroll(idscroll, idswitcher)
{
	var scroll = getID(idscroll);	
	var switcher = getID(idswitcher);	
	if(scroll.style.display == "none")  {
		scroll.style.display="block";
		if(idswitcher)
			switcher.src = "img/switcher.gif";
	}
	else {
		scroll.style.display="none";
		if(idswitcher)
			switcher.src = "img/switcher-on.gif";
	}
	return false;
}

function onfilm(id, film) {
	var content = getID(id);
	if (!film)
//		var film = "download/bpwinterinvasion2007.flv";
		var film = "download/HNTO_60er_1mb_HR.flv";
	var str = "<div id=\"movie\"><div class=\"switchmovie\"><a href=\"\" onclick=\"return offfilm('movie')\">";
	str += "<img src=\"img/switcher.gif\"></a></div>";
	str += "<div class='swf_files movie' >\n";
//	str += "<object width='447' height='305' type='application/x-shockwave-flash' data='download/bpwinterinvasion2007.swf'>\n";
//	str += "<param name='movie' value='download/bpwinterinvasion2007.swf'><param name='quality' value='high'></object>\n";
	str += "<object width='447' height='366' type='application/x-shockwave-flash' data='video-player.swf?videoURL=" + film + "'>\n";
	str += "<param name='movie' value='video-player.swf?videoURL=" + film + "'>\n";
	str += "<param name='quality' value='high'></object>\n";
	str += "</div>\n";
	str += "<p><a href=\"http://www.globalwatch.com/bwi\" onclick=\"return openAWin(this.href, 500, 400, event, 'new_window', 1)\">www.globalwatch.com/bwi</a></p>\n";
	str += "</div>\n";
	content.style.margin = 0;
	content.style.padding = 0;
	content.innerHTML = str;
	var mainid = getID('main');
//	mainid.style.background="#5193c6";
	mainid.style.background="#000000";
	var movie = 5;
	return false;
}

function offfilm(id) {
	var content = getID(id);
	content.innerHTML = "";
	var mainid = getID('main');
	mainid.style.background="url('photos/kozepe.jpg') no-repeat 171px 155px";
	return false;
}

function winH() {
	if (window.innerHeight)
	  /* NN4 a kompatibilní prohlížeče */
	  return window.innerHeight;
	else if
	  (document.documentElement &&
	   document.documentElement.clientHeight)
		/* MSIE6 v std. režimu - Opera a Mozilla
		   již uspěly s window.innerHeight */
		return document.documentElement.clientHeight;
	else if
	  (document.body && document.body.clientHeight)
		/* starší MSIE + MSIE6 v quirk režimu */
		return document.body.clientHeight;
	else
	  return null;
}

function winW() {
	if (window.innerWidth)
	  /* NN4 a kompatibilní prohlížeče */
	  return window.innerWidth;
	else if
	  (document.documentElement &&
	   document.documentElement.clientWidth)
		/* MSIE6 v std. režimu - Opera a Mozilla
		   již uspěly s window.innerWidth */
		return document.documentElement.clientWidth;
	else if
	  (document.body && document.body.clientWidth)
		/* starší MSIE + MSIE6 v quirk režimu */
		return document.body.clientWidth;
	else
	  return null;
}

// vraci souradnice stredu stranky
function getCenterPage (e) {
	var pagecenter = {x:0, y:0};
	var de = document.documentElement;
	var b = document.body;
	pagecenter.x = (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0) + winW() / 2;
	pagecenter.y = (de.scrollTop || b.scrollTop) - (de.clientTop || 0) + winH() / 2;
	return pagecenter;
//	return pagecenter;
}

// nastavi div na stred stranky
function CenterIt(id, e)
{
	pagecenter = getCenterPage(e);
	id = getID(id);
	if(id) {
		id.style.top = pagecenter.y - id.offsetHeight / 2 + "px";
		id.style.left = pagecenter.x - id.offsetWidth / 2 + "px";
		id.style.margin = 0;
	}
//	alert(id.style.top + " | " +  id.style.left);
//	return false;
}


/* -- bubliny -- */

function getPosition(e) {
  e = e || window.event;
  var cursor = {x:0, y:0};
  if (e.pageX || e.pageY) {
	cursor.x = e.pageX;
	cursor.y = e.pageY;
  } 
  else {
	var de = document.documentElement;
	var b = document.body;
	cursor.x = e.clientX + 
	  (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	cursor.y = e.clientY + 
	  (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
  }
  return cursor;
}

function move_position(evnt) {
  var bubl = getID('bubl');
  cursor = getPosition(evnt);
  cursor.x = cursor.x+5;
  cursor.y = cursor.y-25;
  
  bubl.style.left = cursor.x +'px';
  bubl.style.top = cursor.y + 'px';
  return true;
}

function visible_div(evnt,textik,move) {
	var bubl = getID('bubl');
	var p = "";
//	bubl.style.visibility="visible";
	bubl.style.display="block";
	if(!move) move_position(evnt);
	if(textik) bubl.innerHTML = textik;
}
function hidden_div() {
	var bubl = getID("bubl");
	bubl.style.display="none";
}

function ShowDivByID(id_div, disp_val)
{
	if(!getID(id_div))
		return false;
	var id_div = getID(id_div);
	if(disp_val) {
		// IE error table-row -> nahradim display block
		if(disp_val == "table-row" && navigator.appName == "Microsoft Internet Explorer")
			var disp_val = "block";
		id_div.style.display = disp_val;
		return;
	}
	id_div.style.display = "block";
}

// pro jednu id!
function HideDivByID(id) {
	return hiddenDivById(id);
}
function hiddenDivById(id) {
	if(!getID(id))
		return ;
	var div = getID(id);
	div.style.display="none";
}

// nastavi display none u vsech prvku s id jako argumenty fce
function hiddenArgsDivById(id) {
		for (i=0; i < arguments.length; i++) {	
			if(!getID(arguments[i])) continue;
			getID(arguments[i]).style.display="none";
		}
}


/* -- /bubliny -- */


// hide children element html_ent (div for example) by id = div_off
// show div by id = div_on
function switchChildrenDiv(div_on,div_off,html_ent)
{
	var id_on = getID(div_on);
	var id_off = getID(div_off);
	for(i in id_off.childNodes) {
		if(id_off.childNodes[i].nodeName == html_ent.toUpperCase()) {
//			alert(id_off.childNodes[i].id);
			div_off = getID(id_off.childNodes[i].id);
			div_off.style.display = "none";
		}
	}
	if(id_on.id) {
		div_on = getID(id_on.id);
		div_on.style.display = "block";
	}
}



/* -- swap image --*/
function preloadImages() {
	var d=document;
	if(d.images){
		if(!d.p) d.p=new Array();
		var i,j=d.p.length,a=pics;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){
				d.p[j]=new Image;
				d.p[j++].src=a[i];
			}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


/* -- /swap image --*/

function isIE()
{
	/* window.opera identifikuje prohlizec Opera ikdyz je
	   nastaven tak, aby se identifikoval jako Explorer */
	if(window.opera) return false;
	return (navigator.appName == 'Microsoft Internet Explorer');
}

function isIEless7()
{
	/* window.opera identifikuje prohlizec Opera ikdyz je
	   nastaven tak, aby se identifikoval jako Explorer */
	if(window.opera) return false;
	return (navigator.appName == 'Microsoft Internet Explorer' && (navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE"),7) == "MSIE 6." || navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE"),7) == "MSIE 5."));
}

// hideclass = nazev class, ktere se ma schovat
function hideSelects(hideclass)
{
	if (!isIEless7()) return;
	if (hselects == null)
		var hselects = document.getElementsByTagName('SELECT');
	if(!hideclass)
		var hideclass = "hselect";

	if (!hselects || !hselects.length) return;
	for (var i = 0; i < hselects.length;i++) {
		var s = hselects[i];
/*		var spn = getID(s.id);
		if(!spn || spn && spn.id.substr(0,"hselectspan".length) != "hselectspan") continue;
		spn.style.visibility = 'hidden';
*/		if(hselects[i].className.indexOf(hideclass) >= 0)
			hselects[i].style.visibility='hidden';
	}
}

// hideclass = nazev class, ktere se ma ukazat
function showSelects(hideclass)
{
	if (!isIEless7()) return;
	if (hselects == null)
		var hselects = document.getElementsByTagName('SELECT');
	if (!hselects || !hselects.length) return;

	if(!hideclass)
		var hideclass = "hselect";
	for (var i = 0; i < hselects.length;i++) {
		var s = hselects[i];
/*		var spn = getID(s.id);
		if(!spn || spn && spn.id.substr(0,"hselectspan".length) != "hselectspan") continue;
		spn.style.visibility='visible';
*/		if(hselects[i].className.indexOf(hideclass) >= 0)
			hselects[i].style.visibility='visible';
	}
}

/* displays popup div and positions it under given ID */
/* please, use hideSelects() and showSelects() if you use popup */
function popup(div,under,x,y)
{
	var d = getID(div);
	var u = getID(under);
	if(!x) var x = 0;
	if(!y) var y = 0;
	off = totalOffset(u);
	d.style.left = x+off.x+'px';
	d.style.top = y+(off.y+u.offsetHeight)+'px';
	d.style.display = "block";
}

function totalOffset(o)
{
	var off = {x:0,y:0};
	var s = "";
	while (o.offsetParent) {
		off.x += o.offsetLeft;
		off.y += o.offsetTop;
		s += " "+o.tagName+" "+o.offsetTop;
		o = o.offsetParent;
	}
	//      print(s+" "+o.tagName+" "+off.y); 
	return off;     
}

// ocheckuje vsechny pole formulare zadane jako string id v argumentech fce
function checkform(frm) {
	// kontrola zadani cen pouze pro zajezdy s pevnymi terminy pro volitelne nezadavame ceny!
	var str = "";
	if(!text_field)	
		var alert_test_field = 'Field';
	if(!text_required)	
		var alert_test_is_required = 'is required';
	var frstpovinne = false;
	for (i=1; i < arguments.length; i++) {
		if(frm[arguments[i]] && trim(frm[arguments[i]].value) == '') {
			if(!frstpovinne)
				frstpovinne = arguments[i];
			str += alert_test_field + '"+ arguments[i+1] +"' + alert_test_is_required + ".\n";
		}
	}
	// vystup alert
	if(str) {
		frm[frstpovinne].focus();
		alert(str);
		return false;
	}
	// TODO: pridat check formatu telefonu a emailu
	return true;
 }
// zkontroluje captcha + povinne polozky formulare 5,7,8,... (liche parametry) nazvu pole 6,9,10,... (sude parametry) nazvu pole
function CheckFormCaptchaFill(c, ct, alert_text,frm)
{
	if(!checkcaptchafill(c, ct, alert_text)) {
		ct.focus();
		return false;
	}
	if(arguments.length > 3)
		 return CheckFormTestReq(frm,arguments);
}
// zkontroluje povinne polozky po predani argumentu
function CheckFormTestReq(frm,arg)
{
	var str="";
	var frstpovinne = false;
	if(!text_field)	
		var alert_test_field = 'Field';
	if(!text_required)	
		var alert_test_is_required = 'is required';

	for (i=0; i < arg.length; i++) {
		if(frm[arg[i]] && trim(frm[arg[i]].value) == '' && arg[i] != "ct") {
			if(!frstpovinne)
				frstpovinne = arg[i];
//			str += "Field"+ arg[i+1] +"is required\n";
			str += alert_test_field + "'"+ arg[i+1] +"'" + alert_test_is_required +">.\n";
		}
	}
	// vystup alert
	if(str) {
		frm[frstpovinne].focus();
		alert(str);
		return false;
	}
}

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "")
};

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) 
		return false;
	return true;
}

//--- obarveni radek tabulky podle tridy v table dle css -- //
function stripeTable(t) {
	var i,colwidth,part_class,odd = true;
	for (i=0; i<t.rows.length; i++) {
		t.rows[i].className += odd ? ' odd' : ' even';
		odd = !odd;
		if(i==0)
			for (j=0; j<t.rows[0].cells.length; j++) {
				if(j==0 && t.className.substr(t.className.length-5, 4) == "cols") {
					var cols = t.className.substr(t.className.length-1,1);
					// nastaveni sirky 1. sloupcu tabulek dle class "col{2-6}"
					switch(cols) {
						case '6': colwidth = 33; break;
						case '5': colwidth = 37; break;
						case '4': colwidth = 31; break;
						case '3': colwidth = 45; break;
						case '2': colwidth = 54; break;
					}
					t.rows[0].cells[j].style.width = colwidth+'%';
				}
			}
	}
}

function stripeTableById(id)
{
	var t = document.getElementById(id);
	if (t) stripeTable(t);
}

function stripeAllTables()
{
	var t = document.getElementsByTagName('TABLE');
	for (var i=0; i<t.length; i++) {
		if(t[i].className) {
			stripeTable(t[i]);
		}
	}
}

function initjs() {
	
}

//--- obarveni radek tabulky podle tridy v table -- //


// nastaveni obsahu prvku dle hodnoty formulare
// elfrm -zvoleny element formulare
// elinner - prvek kam se vlozi hodnota elementu formulare
function SetInnerHtml (elfrm, elinner)
{
	var idinner = getID(elinner);
	var elfrm = getID(elfrm);
	idinner.innerHTML = "[ " + elfrm.value + " ]";
}

// smaze obsah prvku elinner
function DeleteInnerHtml(elinner)
{
	var idinner = getID(elinner);
	idinner.innerHTML = "";
}

// nastaveni obsahu prvku dle 2 paramteru
// elfrm -zvoleny element
// inner_value - nova hodnota
function SetNewInnerHtml (elfrm, inner_value)
{
	var idinner = getID(elinner);
	var elfrm = getID(elfrm);
	idinner.innerHTML = inner_value;
}


// nastavi ve formulari prvek id na hodnotu val
function setValueByID (id, val)
{
	var el = getID(id);
	el.value = val;
}

// nastavi ve formulari radio prvek name=nazev na unchecked
function UncheckByName (nazev)
{
	var el = document.getElementsByName(nazev);
	for (var i=0; i < el.length; i++) {
		el[i].checked = false;
	}
}

function CheckByName(nazev, value)
{
	var el = document.getElementsByName(nazev);
	for (var i=0; i < el.length; i++) {
		if(el[i].value == value)
			el[i].checked = true;
//		alert(el[i].value + " | " + value);
	}
}

function CheckRadio(nazev)
{
	var el = document.getElementsByName(nazev);
	for (var i=0; i < el.length; i++) {
		if(el[i].checked == true)
			return true;
	}
	return false;
}

function SetBackColor(id, color)
{
	SetColor(id, color);
}

function SetColor(id, backcolor, fontcolor)
{
	var id = getID(id);
	id.style.background = backcolor;
	if(fontcolor) id.style.color = fontcolor;
	id.style.cursor = 'pointer';
}

function SetClass(id, myclass)
{
	var id = getID(id);
	if(id.className.substr(id.className.length-myclass.length) != myclass) 
		id.className = id.className + " " + myclass;
	id.style.cursor = 'pointer';
}

function UnSetClass(id, myclass)
{
	var id = getID(id);
	if(id.className.substr(id.className.length-myclass.length) == myclass) {
		id.className = id.className.substr(0,id.className.length-myclass.length);
	}
}


function checkdate( month, day, year ) {
  // http://kevin.vanzonneveld.net
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +   improved by: Pyerre
  // *     example 1: checkdate(12, 31, 2000);
  // *     returns 1: true
  // *     example 2: checkdate(2, 29, 2001);
  // *     returns 2: false
  // *     example 3: checkdate(03, 31, 2008);
  // *     returns 3: true
  // *     example 4: checkdate(1, 390, 2000);
  // *     returns 4: false

  var myDate = new Date();
  myDate.setFullYear( year, (month - 1), day );

  return ((myDate.getMonth()+1) == month && day<32); 
}

/*--------GOOGLE maps----------------*/
function loadG(lat,lng,lang) {
	var map;
	var	svOverlay;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById('map'));
		centermap = new GLatLng(lat, lng);
	//	map.addControl(new GSmallMapControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.setCenter(centermap, 17);
/*
		var myPano = new GStreetviewPanorama(document.getElementById("pano"));
		GEvent.addListener(myPano, "error", handleNoFlash);  
		svOverlay = new GStreetviewOverlay();
		map.addOverlay(svOverlay);
		GEvent.addListener(map,"click", function(overlay,latlng) {
		  myPano.setLocationAndPOV(latlng);
		  });
*/		  
//		map.setUIToDefault();
	//	bound mapy
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		function searchLocationsNear(center, radius, searchUrl) {
			var radius = radius ? radius : 2;
			GDownloadUrl(searchUrl, function(data) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName('marker');
			// smazne vsechny markery
			//	  map.clearOverlays();
			  
				// SIDEBAR
				/*
				var sidebar = document.getElementById('sidebar');
				sidebar.innerHTML = '';
				*/
			/*	  if (markers.length == 0) {
				sidebar.innerHTML = 'No results found.';
				map.setCenter(new GLatLng(40, -100), 4);
				return;
				}
			*/	  
				if (markers.length == 0) 
					return;

				var bounds = new GLatLngBounds();
				for (var i = 0; i < markers.length; i++) {
					var icon_img = 'other';
					var importance = 1;
					var name = markers[i].getAttribute('name');
					var address = markers[i].getAttribute('address');
					var urlh = markers[i].getAttribute('urlh');
					var distance = parseFloat(markers[i].getAttribute('distance'));
					var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
					  parseFloat(markers[i].getAttribute('lng')));
					if(markers[i].getAttribute('lat') == lat && markers[i].getAttribute('lng') == lng) {
						var icon_img = 'main';	
						importance = 2;
					}

					var marker = createMarker(icon_img, point, name, address, urlh);
				
//					marker.openInfoWindowHtml.noCloseOnClick = true;

					marker.importance = importance;
					map.addOverlay(marker);

					// SIDEBAR
					/*
					var sidebarEntry = createSidebarEntry(marker, name, address, distance, urlh);
					sidebar.appendChild(sidebarEntry);
					bounds.extend(point);
					*/
				}

			//	  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
			//		map.getBoundsZoomLevel(bounds);
			//	  map.setCenter(bounds.getCenter());
			});
		}

		function importanceOrder (marker,b) {
			return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
		}


		function createMarker(icon_img, point, name, address, urlh) {
			var baseIcon = new GIcon(G_DEFAULT_ICON);
//			baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			baseIcon.shadow = "http://www.detske-ctyrkolky.com/xtra/layout/marker_shadow.png";
			baseIcon.iconSize = new GSize(21, 25);
			baseIcon.shadowSize = new GSize(23, 25);
			baseIcon.iconAnchor = new GPoint(9, 25);
			baseIcon.shadowAnchor = new GSize(80, 34);
//			baseIcon.infoWindowAnchor = new GPoint(10, 25);
			baseIcon.infoWindowAnchor = new GPoint(9, 2);
			baseIcon.maxHeight = 200;

			var myIcon = new GIcon(baseIcon);
			markerOptions = { icon:myIcon, zIndexProcess:importanceOrder };
			myIcon.image = "http://www.detske-ctyrkolky.com/xtra/layout/marker_" + icon_img + ".png";

			var marker = new GMarker(point, markerOptions);
			var html = '<b>' + name + '</b> <br/>' + address + '<br />';
			html += '<a href="' + urlh + '">' + gmap_link_hotel_page + '</a>';

			GEvent.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(html);
				marker.openInfoWindowHtml.noCloseOnClick = true;
				});
		  /*  
			GEvent.addListener(marker, 'mouseover', function() {
				marker.openInfoWindowHtml(html);
				});
			GEvent.addListener(marker, 'mouseout', function() {
				marker.closeInfoWindow();
				});
		  */	  

			return marker;
		}

		function createSidebarEntry(marker, name, address, distance) {
		  var div = document.createElement('div');
		  var html = '' + name + ' (' + distance.toFixed(1) + ') ' + address;
		  div.innerHTML = html;
		  div.style.cursor = 'pointer';
		  div.style.marginBottom = '50px';
		  GEvent.addDomListener(div, 'click', function() {
			  GEvent.trigger(marker, 'click');
			  });
		  GEvent.addDomListener(div, 'mouseover', function() {
			  div.style.backgroundColor = '#eee';
			  });
		  GEvent.addDomListener(div, 'mouseout', function() {
			  div.style.backgroundColor = '#fff';
			  });
		  return div;
		}


		function refreshMarkers() {
			centermap = map.getCenter();
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();
	//		alert(centermap);
	//		alert(southWest);
	//		map.setCenter(centermap, 13);

			searchLocationsNear(centermap, false, 'xtra/phpsqlsearch_genxml.php?swlat=' + southWest.lat() + '&swlng=' + southWest.lng() + '&nwlat=' + northEast.lat() + '&nwlng=' + northEast.lng()  + '&zoom=' + map.getZoom() + '&lat=' + lat + '&lng=' + lng+ '&lang=' + lang);
	//		searchLocationsNear(centermap);
	//	    document.getElementById("message").innerHTML = center.toString();
		};
	//	searchLocationsNear(centermap);
		searchLocationsNear(centermap, false, 'xtra/phpsqlsearch_genxml.php?swlat=' + southWest.lat() + '&swlng=' + southWest.lng() + '&nwlat=' + northEast.lat() + '&nwlng=' + northEast.lng()  + '&zoom=' + map.getZoom() + '&lang=' + lang);
		var noupdate = false;
		GEvent.addListener(map, "infowindowopen", function() { noupdate=true; });
		GEvent.addListener(map, "infowindowclose", function() { noupdate=false; });
		GEvent.addListener(map, "dragend", function() {
			map.clearOverlays();
		});
		GEvent.addListener(map, "zoomend", function() {
			map.clearOverlays();
		});
		GEvent.addListener(map, "moveend", function() {
			if(!noupdate) {
				map.clearOverlays();
				refreshMarkers();
				map.addOverlay(svOverlay);
			}
		});
/*		GEvent.addListener(map, "load", function() {
			map.clearOverlays();
			refreshMarkers();
		});
*/

	}
}

function handleNoFlash(errorCode) {
	if (errorCode == FLASH_UNAVAILABLE) {
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	}
}

// TODO: odstranit select boxy a pak zase vratit! :)
// a dodelat zavreni mapy!
function createmapcontainer(underdiv, lat, lng, posunx, posuny, lang)
{
	closeGmap();
	if(!x) var x = 0;
	if(!posunx) var posunx = 0;
	if(!posuny) var posuny = 0;
	var main = getID('main');
	if(getID('map'))	
		getID('map').parentNode.removeChild(getID('map'));
    if(getID('mapshadow'))	
		getID('mapshadow').parentNode.removeChild(getID('mapshadow'));
    if(getID('mapclosercontainer'))	
		getID('mapclosercontainer').parentNode.removeChild(getID('mapclosercontainer'));

	// map container
	var map = document.createElement("div");
	map.setAttribute('id', 'map') ;
	main.appendChild(map);

	// map shadow
	var mapshadow = document.createElement("div");
	mapshadow.setAttribute('id', 'mapshadow') ;
	main.appendChild(mapshadow);

/* PANO
	// map pano
	var pano = document.createElement("div");
	pano.setAttribute('id', 'pano') ;
	main.appendChild(pano);
*/
	// closer container
	var mapclosercontainer = document.createElement("div");
	mapclosercontainer.setAttribute('id', 'mapclosercontainer') ;
	main.appendChild(mapclosercontainer);

	// text closer
/*	var newLink = document.createElement("a");
	newLink.id = "mapcloserhref";
	var linkText = document.createTextNode(gmap_link_text_zavrit_mapu);
	newLink.setAttribute('href', 'javascript:void closeGmap();') ;
	newLink.setAttribute('class', 'nopreloader') ;
//	IE ignore!	
//	newLink.setAttribute('style', 'color: #ffffff; background: red') ;
	newLink.appendChild(linkText);
	getID("mapclosercontainer").appendChild(newLink);
*/
	var link_close = "<a href=\"javascript:void closeGmap();\">" + gmap_link_text_zavrit_mapu + "</a>";

	// info text
	var infoPanel = document.createElement("p");
	infoPanel.id = "map_infoPanel";
	getID("mapclosercontainer").appendChild(infoPanel);
	var current_hotel_image = "<img src=\"http://www.detske-ctyrkolky.com/xtra/layout/marker_main.png\">";
	var other_hotel_image = "<img src=\"http://www.detske-ctyrkolky.com/xtra/layout/marker_other.png\">";
	$("#map_infoPanel").html("<span>" + current_hotel_image + " " + gmap_info_text_icons_hotel_current + "</span><span class=\"other_hotel\">" + other_hotel_image + " " + gmap_info_text_icons_hotel_other + "</span>" + link_close);

	popup("mapclosercontainer",underdiv,posunx,posuny);
	popup("map",underdiv,posunx,50+posuny);
	popup("mapshadow",underdiv,posunx-10,20+posuny);
// 	
//	popup("pano",underdiv,posunx-10,680+posuny);
	loadG(lat, lng, lang);
	hideSelects();
}

function closeGmap() {
	hiddenArgsDivById("map","mapshadow","mapclosercontainer","pano");showSelects();
	$("#pano").remove();
}

/*--------/GOOGLE maps----------------*/

/* ----------------------- naseptavac -------------------------*/
function ns_visible(id,st)
{
	if(typeof(id) == 'string')
		var ul = getID(id);
	else
		var ul = id;
	if(st)	{
		/*clearTimeout(self.timer);*/
		ul.style.display='block';
		makeWindowed(document.getElementById('ns-destinace'));
	} else {
		var f = function() {
			ul.style.display='none';
		}
		self.timer = setTimeout(f,400);
	//	ul.style.visibility = 'hidden';
	}
}

function ns_edit(input,output,url)
{
	/* TODO: strlen >= 3; CACHE */
	output = getID(output);
	var value = input.value;
	if(typeof window['encodeURI'] == 'function') {
		value = escape(encodeURI(value));
		value = value.replace(/\+/,"%252B");
	} else {
		value = escape(value);
		value = value.replace(/\+/,"%2B");
	}
	return send_xmlhttprequest(ns_obsluha_edit,[input,output], 'GET', url + value);
}

function ns_stopdefault(e, nameform, output)
{
    var evt = e || window.event;
    var keynum = e.keyCode;
    if(keynum == 38 || keynum == 40 || keynum == 13)
    {
        evt.cancelBubble = true;
        if (evt.stopPropagation) evt.stopPropagation();
        if (e.preventDefault) e.preventDefault();
		var mday1 = getID(nameform.name + "mday1");
		var mday2 = getID(nameform.name + "mday2");
		var year_month1 = getID(nameform.name + "year_month1");
		var year_month2 = getID(nameform.name + "year_month2");
		if(mday1 && mday2 && year_month1 && year_month2) {
			if(keynum == 13 && nameform && mday1.value && mday2.value && year_month1.value && year_month2.value) {
	//			alert(nameform.name + " | " + mday1.id + " | " + mday2.id +" | " + year_month1.id +" | " + year_month2.id);
				output = getID(output);
				hiddenDivById(output.id);
				ShowDivByID('loading-data');
				nameform.submit();
			}
		}
        return false;
    }
    return true;
}

function ns_keyup(input,output,url,e)
{
    var evt = e || window.event;
    var keynum = e.keyCode;
    if(keynum == 38 || keynum == 40 || keynum == 13)
    {
        return false;
    }
    ns_edit(input,output,url);
    return true;
}
function ns_keydown(input,output,e)
{
    var evt = e || window.event;
    var keynum = e.keyCode;
    var ul = getID(output);
    var oznac = 0;
	var	idcountrycode = getID("countrycode");
	var	idtablename = getID("tablename");
	var	idsearchid = getID("searchid");
    if((keynum < 9 || keynum > 45) && keynum < 91) {
//		alert(keynum);
		idcountrycode.value = ""; 
		idtablename.value = ""; 
		idsearchid.value = ""; 
	}

    if(keynum == 38 || keynum == 40 || keynum == 13)
    {
	    if(ul.childNodes.length == 0)
            return false;
        if(keynum == 38) oznac = ul.childNodes.length -1;
        for(var i = 0; i < ul.childNodes.length; i++)
        {
            if(ul.childNodes[i].className.indexOf('hoverclass') != -1)
            {
                if(ul.childNodes[i].className.indexOf('odd') == 0)
                    ul.childNodes[i].className = 'odd';
                else 
                    ul.childNodes[i].className = '';
                if(keynum == 38)
                {
                    if(!i) oznac = ul.childNodes.length-1;
                    else oznac = i-1;
                }
                else if(keynum == 40)
                {
                    oznac = i+1;
                    if(oznac >= ul.childNodes.length) oznac = 0;
                }
                else {
                    input.value = ul.childNodes[i].myval;
					idcountrycode.value = ul.childNodes[i].countrycode; 
					idtablename.value = ul.childNodes[i].tablename; 
					idsearchid.value = ul.childNodes[i].searchid; 
//					alert(ul.childNodes[i].tablename + " | " + ul.childNodes[i].searchid + " | " + ul.childNodes[i].countrycode);
                    ns_visible(output,0);
                    return true;
                }
                break;
            }
        }
        ul.childNodes[oznac].className += ' hoverclass';
        return false;
    }
    return true;
}

function send_xmlhttprequest(obsluha, data, method, url, content, headers)
{
    var xmlhttp;
	var enc;
 	try {
 	   // Firefox, Opera 8.0+, Safari
	    xmlhttp=new XMLHttpRequest();
	    enc = 'utf8';
	}
	catch (e) {
	    // Internet Explorer
	    enc = 'iso';
	    try {
 		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch (e) {
 		     try {
 		       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		     }
		      catch (e) {
 		//	       alert("Your browser does not support AJAX!");
			        return false;
		     }
	    }
        } 

       if (!xmlhttp)
         return false; 

       if(!(typeof window['encodeURI'] == 'function')) { url= url + '&enc='+enc };
       xmlhttp.open(method, url); 
       xmlhttp.onreadystatechange = function() 
       { 
         obsluha(xmlhttp,data); 
       }; 
       if (headers) { 
         for (var key in headers) 
         { 
           xmlhttp.setRequestHeader(key, headers[key]); 
         } 
       } 
       xmlhttp.send(content);
	return true;
} 

function ns_obsluha_edit(xmlhttp,obj)
{
    if(xmlhttp.readyState != 4) return;
	output = obj[0];
	ul = obj[1];
	while (ul.childNodes.length > 0) {
		ul.removeChild(ul.childNodes[0]);
	}

	var info = xmlhttp.responseXML.getElementsByTagName('info');
	var data = xmlhttp.responseXML.getElementsByTagName('destinace');
	var tablename = xmlhttp.responseXML.getElementsByTagName('tablename');
	var searchid = xmlhttp.responseXML.getElementsByTagName('searchid');
	var countrycode = xmlhttp.responseXML.getElementsByTagName('countrycode');

	for (var i = 0; i < data.length; i++)
	{
		var li = document.createElement("LI");
		li.innerHTML = data[i].firstChild.data;
        if(info[i].firstChild.data)
            li.innerHTML += ' '+info[i].firstChild.data;
		li.myval = data[i].firstChild.data;
		li.tablename = tablename[i].firstChild.data;
		li.searchid = searchid[i].firstChild.data;
		li.countrycode = countrycode[i].firstChild.data;
		ul.appendChild(li);
		li.onclick = function() {
			// prirazeni value 
			var idcountrycode = getID("countrycode");
			var idtablename = getID("tablename");
			var idsearchid = getID("searchid");
//			alert(this.tablename + this.tablename + this.searchid);
			idcountrycode.value = this.countrycode; 
			idtablename.value = this.tablename; 
			idsearchid.value = this.searchid; 

			output.value = this.myval;
			//this.innerHTML;
			//alert(this.innerHTML);
		}
        li.onmouseover = function() 
        {
            this.className += ' hoverclass';
        }
        li.onmouseout = function()
        {
            if(this.className.indexOf('odd') == 0)
                this.className = 'odd';
            else 
                this.className = '';
        }
        if(i % 2) li.className = 'odd';
	}
	if(ul.childNodes.length > 0) 
		ns_visible(ul,1);
	else  
		ul.style.display='none';
		//ns_visible(ul,0);
	// opera hack	
	if(navigator.appName == "Opera")
		ul.className += ' naseptopera';
}

/* ----------------------- /naseptavac -------------------------*/

// make the specified div a windowed control in IE6
// this masks an iframe (which is a windowed control) onto the div,
// turning the div into a windowed control itself
function makeWindowed(p_div)
{
  var is_ie6 =
	document.all && 
	(navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
  if (is_ie6)
  {
	var html =
	  "<iframe style=\"position: absolute; display: block; " +
	  "z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" +
	  "filter: mask(); background-color: #ffffff; \"></iframe>";
	if (p_div) p_div.innerHTML += html;
	// force refresh of div
	var olddisplay = p_div.style.display;
	p_div.style.display = 'none';
	p_div.style.display = olddisplay;
  };
}

function var_dump(obj) {
  if(typeof obj == "object") {
	return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
  } else {
	return "Type: "+typeof(obj)+"\nValue: "+obj;
  }
}//end function var_dump

function set_widget_overlay()
{
  $("body").prepend('<div class="ui-widget-overlay"></div>');
  $("div.ui-widget-overlay").css("height",$(document).height() + 20);
}

function remove_widget_overlay()
{
  $("div.ui-widget-overlay").remove();
}

/**
* zamezeni error hlasky  "console is not defined" pri vypnutem firebug
*/
if (!window.console || !console.firebug)
{
  var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	  "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

  window.console = {};
  for (var i = 0; i < names.length; ++i)
	window.console[names[i]] = function() {}
}




