function ZmenaStatu(poradi_statu, caller) {
	if(poradi_statu == 0) {
		document.getElementById('form_city').length = 0;
		document.getElementById('form_city').options[0] = new Option("choose a city");
		document.getElementById('form_city').options[0].value = '0';
	}
	else {
		if (caller.id == 'form_country') ZmenMesta(poradi_statu, 'form_city');
		if (caller.id == 'form_country2') ZmenMesta(poradi_statu, 'form_city2');
		if (caller.id == 'form_country3') ZmenMestaFestivaly(poradi_statu, 'form_city3');
	}
}
	
	
function ZmenMesta(poradi_statu, box) {
	document.getElementById(box).length = arrMesta[poradi_statu].length + 1;
	document.getElementById(box).options[0] = new Option("choose a city");
	document.getElementById(box).options[0].value = '0';
			
	for(n=0; n<arrMesta[poradi_statu].length; n++) {
		document.getElementById(box).options[n + 1] = new Option(arrMesta[poradi_statu][n].nazev);
		document.getElementById(box).options[n + 1].value = arrMesta[poradi_statu][n].id_mesta;
	}
	document.getElementById(box).selectedIndex = 0;
}
function ZmenMestaFestivaly(poradi_statu, box) {
	document.getElementById(box).length = arrMestaFestivaly[poradi_statu].length + 1;
	document.getElementById(box).options[0] = new Option("choose a city");
	document.getElementById(box).options[0].value = '0';
			
	for(n=0; n<arrMestaFestivaly[poradi_statu].length; n++) {
		document.getElementById(box).options[n + 1] = new Option(arrMestaFestivaly[poradi_statu][n].nazev);
		document.getElementById(box).options[n + 1].value = arrMestaFestivaly[poradi_statu][n].id_mesta;
	}
	document.getElementById(box).selectedIndex = 0;
}


function PopImage(id_hostelu, image, base_url) {
	var scrWidth = screen.width;
	var scrHeight = screen.height;
	
	var bodyWidth = 540;
	var bodyHeight = 572;
	
	var posLeft = (scrWidth - bodyWidth) / 2;
	var posTop = (scrHeight - bodyHeight) / 2;

	showpic = window.open(base_url + 'picture-detail.asp?id=' + id_hostelu + '&image=' + image, 'showpic', 'toolbar=no,location=no,status=no,resizable=no,width=' + bodyWidth + ',height=' + bodyHeight + ',scrollbars=yes,top=' + posTop + ',left=' + posLeft);
	showpic.window.focus();
}

function PopImageFestival(image, base_url) {
	var scrWidth = screen.width;
	var scrHeight = screen.height;
	
	var bodyWidth = 280;
	var bodyHeight = 400;
	
	var posLeft = (scrWidth - bodyWidth) / 2;
	var posTop = (scrHeight - bodyHeight) / 2;

	showpic = window.open(base_url + 'picture-detail-festival.asp?image=' + image, 'showpic', 'toolbar=no,location=no,status=no,resizable=no,width=' + bodyWidth + ',height=' + bodyHeight + ',scrollbars=yes,top=' + posTop + ',left=' + posLeft);
	showpic.window.focus();
}

function PopTerms() {
	var scrWidth = screen.width;
	var scrHeight = screen.height;
	
	var bodyWidth = 400;
	var bodyHeight = 600;
	
	var posLeft = (scrWidth - bodyWidth) / 2;
	var posTop = (scrHeight - bodyHeight) / 2;

	showpic = window.open('/terms.asp', 'showterms', 'toolbar=no,location=no,status=no,resizable=no,width=' + bodyWidth + ',height=' + bodyHeight + ',scrollbars=yes,top=' + posTop + ',left=' + posLeft);
	showpic.window.focus();
}

function PopCCV(base_url) {
	var scrWidth = screen.width;
	var scrHeight = screen.height;
	
	var bodyWidth = 300;
	var bodyHeight = 320;
	
	var posLeft = (scrWidth - bodyWidth) / 2;
	var posTop = (scrHeight - bodyHeight) / 2;

	showpic = window.open(base_url + 'ccv-info.asp', 'showccv', 'toolbar=no,location=no,status=no,resizable=no,width=' + bodyWidth + ',height=' + bodyHeight + ',scrollbars=yes,top=' + posTop + ',left=' + posLeft);
	showpic.window.focus();
}

function SearchFocus() {
	var l = document.getElementById('search_name');
	if(l.value == ' type your search here') l.value = '';
}

function SearchBlur() {
	var l = document.getElementById('search_name');
	if(l.value == '') l.value = ' type your search here';
}

function ToggleAC(act) {
	location.hash = 'addcomment';
	f = document.getElementById('acform');
	if (act == 'hide') {
		f.style.display = 'none';
		document.getElementById('ac-hide-a').style.display = 'none';
		document.getElementById('ac-hide-s').style.display = 'inline';
		document.getElementById('ac-show-a').style.display = 'inline';
		document.getElementById('ac-show-s').style.display = 'none';
	}
	else {
		f.style.display = 'block';
		document.getElementById('ac-hide-a').style.display = 'inline';
		document.getElementById('ac-hide-s').style.display = 'none';
		document.getElementById('ac-show-a').style.display = 'none';
		document.getElementById('ac-show-s').style.display = 'inline';
	}
}

function ToggleRC(act) {
	location.hash = 'ratings';
	f = document.getElementById('rc-data');
	if (act == 'hide') {
		f.style.display = 'none';
		document.getElementById('rc-hide-a').style.display = 'none';
		document.getElementById('rc-hide-s').style.display = 'inline';
		document.getElementById('rc-show-a').style.display = 'inline';
		document.getElementById('rc-show-s').style.display = 'none';
	}
	else {
		f.style.display = 'block';
		document.getElementById('rc-hide-a').style.display = 'inline';
		document.getElementById('rc-hide-s').style.display = 'none';
		document.getElementById('rc-show-a').style.display = 'none';
		document.getElementById('rc-show-s').style.display = 'inline';
	}
}

function ToggleMP(act) {
	location.hash = 'map';
	f = document.getElementById('mp-data');
	if (act == 'hide') {
		f.style.display = 'none';
		document.getElementById('mp-hide-a').style.display = 'none';
		document.getElementById('mp-hide-s').style.display = 'inline';
		document.getElementById('mp-show-a').style.display = 'inline';
		document.getElementById('mp-show-s').style.display = 'none';
	}
	else {
		f.style.display = 'block';
		document.getElementById('mp-hide-a').style.display = 'inline';
		document.getElementById('mp-hide-s').style.display = 'none';
		document.getElementById('mp-show-a').style.display = 'none';
		document.getElementById('mp-show-s').style.display = 'inline';
	}
}

function ToggleFH(act) {
	location.hash = 'search';
	f = document.getElementById('menu-line2h');
	f2 = document.getElementById('menu-line2f');
	if (act == 'hide') {
		f.style.display = 'none';
		f2.style.display= 'block';
		document.getElementById('fh-hide-a').style.display = 'none';
		document.getElementById('fh-hide-s').style.display = 'inline';
		document.getElementById('fh-show-a').style.display = 'inline';
		document.getElementById('fh-show-s').style.display = 'none';
		document.getElementById('button-f-off').style.display = 'none';
		document.getElementById('button-f-on').style.display = 'inline';
		document.getElementById('button-h-off').style.display = 'inline';
		document.getElementById('button-h-on').style.display = 'none';
	}
	else {
		f.style.display = 'block';
		f2.style.display = 'none';
		document.getElementById('fh-hide-a').style.display = 'inline';
		document.getElementById('fh-hide-s').style.display = 'none';
		document.getElementById('fh-show-a').style.display = 'none';
		document.getElementById('fh-show-s').style.display = 'inline';
		document.getElementById('button-f-off').style.display = 'inline';
		document.getElementById('button-f-on').style.display = 'none';
		document.getElementById('button-h-off').style.display = 'none';
		document.getElementById('button-h-on').style.display = 'inline';
    }
}

function itemTags(classN) {
 aTags = document.getElementsByTagName('a');
 for (var aI = 0; aI < aTags.length; aI++) {
 if (aTags[aI].parentNode.className == classN) {
 aTags[aI].parentNode.href = aTags[aI].href
 aTags[aI].parentNode.className += ' jsClick';
 aTags[aI].parentNode.onclick = function() { window.location = this.href; }
 }
 }
}

window.onload = function()
{ 
	itemTags('places');
	itemTags('places-cities');
}

window.onunload = function()
{ 
	GUnload();
}

//Google map scripts
 var map = null;
 var geocoder = null;
 var zoom = null;
 var counter = 0;
 
function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GSmallMapControl());
	geocoder = new GClientGeocoder();	
  }
}

function load2() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map_big"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GSmallMapControl());
	geocoder = new GClientGeocoder();	
  }
}

function showAddress(address,street,city,country)
{	
	if (geocoder) 
	{
		geocoder.getLatLng(
		address,
		function(point)
		{
			if (!point) 
			{
				counter++;
				checkValidation(street,city,country)
			}else 
			{
				map.setCenter(point,zoom);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				//marker.openInfoWindowHtml(address);
			}
		}
		);
	}
}

function checkValidation(street,city,country)
{
	if(country=="Scotland")
	{
		country="United Kingdom"
	}
	if(counter==0)
	{
		zoom = 15;
		showAddress(street,street,city,country);
		//alert(street);
	}
	if(counter==1)
	{
		var place = city + " " + country;
		zoom = 9;
		showAddress(place,street,city,country);
		//alert(place);
	}
	if(counter==2)
	{
		zoom = 5;
		showAddress(country,street,city,country);
		//alert(country);
	}
	if(counter == 3)
	{
		map.setCenter(new GLatLng(49.181703,12.568359),2);
	}
}

// end of google map scripts



// availability table scripts
function AvailChangeRoom(id_room, pocet_noci) {
	if (document.getElementById('select_' + id_room).checked) AvailCheckRoom(id_room, pocet_noci);
	AvailCountRoom(id_room, pocet_noci);
	AvailSwitchRoom(id_room, pocet_noci);
	AvailTotalRecount();
}


function AvailCheckRoom(id_room, pocet_noci) {
	var obsazena = true;
	var nevybrana = true;
	for(n = 1; n <= pocet_noci; n++) {
		if (document.getElementById('beds_' + id_room + '_' + n).value != '0') nevybrana = false;
		if (!document.getElementById('beds_' + id_room + '_' + n).disabled) obsazena = false;
	}
	if (obsazena) {
		alert('You cannot book room with no available beds.');
		document.getElementById('select_' + id_room).checked = false;
	} else {
		if (nevybrana) {
			alert('You cannot book room with no selected beds.');
			document.getElementById('select_' + id_room).checked = false;
		}
	}
}


function AvailCountRoom(id_room, pocet_noci) {
	var cena_celkem = 0;
	for(n = 1; n <= pocet_noci; n++) {
		cena_celkem += parseFloat(document.getElementById('price_' + id_room + '_' + n).value) * parseInt(document.getElementById('beds_' + id_room + '_' + n).value);
	}
	document.getElementById('total_' + id_room).innerHTML = FormatCena(Math.round(cena_celkem * 100) / 100);
	
	if (document.getElementById('select_' + id_room).checked) {
		document.getElementById('hidden_total_' + id_room).value = Math.round(cena_celkem * 100) / 100;
	} else {
		document.getElementById('hidden_total_' + id_room).value = 0;
	}
}


function AvailSwitchRoom(id_room, pocet_noci) {
	if (document.getElementById('select_' + id_room).checked) {
		for(n = 1; n <= pocet_noci; n++) {
			if(document.getElementById('beds_' + id_room + '_' + n).value != '0') {
				document.getElementById('img_' + id_room + '_' + n).className = 'box selected';
			} else {
				if(document.getElementById('img_' + id_room + '_' + n).className != 'box full') document.getElementById('img_' + id_room + '_' + n).className = 'box empty';
			}
		}
	} else {
		for(n = 1; n <= pocet_noci; n++) {
			if(document.getElementById('beds_' + id_room + '_' + n).value != '0') {
				document.getElementById('img_' + id_room + '_' + n).className = 'box empty';
			} else {
				if(document.getElementById('img_' + id_room + '_' + n).className == 'box selected') document.getElementById('img_' + id_room + '_' + n).className = 'box empty';
			}
		}
	}
}


function FormatCena(cena) {
	var leva_strana, prava_strana, leva_strana_puvodni, n
	var cena2 = cena.toString();
	
	if(cena2.indexOf('.') != -1) {
		leva_strana = cena2.substring(0, cena2.indexOf('.'));
		prava_strana = cena2.substring(cena2.indexOf('.') + 1, cena2.length);
		if(prava_strana.length == 1) prava_strana += '0';
		if(prava_strana.length != 0 ) prava_strana = ',' + prava_strana;
	} else {
		leva_strana = cena2;
		prava_strana = '';
	}
	
	return leva_strana + prava_strana;
}


function AvailValidate(str_pole) {
	var re = /,/;
	var pole = str_pole.split(re);
	
	var chyba = true;
	for (i = 0; i < pole.length; i++) {
		if (document.getElementById('select_' + pole[i]).checked) chyba = false;
	}
	if (chyba) {alert('Please select room for booking.'); return false;} else {return true;}
}


function GetRoomTotal(id_room) {
	return parseFloat(document.getElementById('hidden_total_' + id_room).value);
}
// end of availability table scripts
