//GOOGLE MAP FUNCTIONS
	
	function addMarkers (lat,lng,ico,ids,whatshow){
		
			var i;
			for (i=0; i<lat.length; i=i+1) 
			{
				addMarker(lat[i],lng[i],ico[i],ids[i],whatshow);
			}
	}
	
	
	
	function addMarker(lat,lng,ico,id,whatshow){
		
		var center = new GLatLng(lat, lng);

		// Create our "tiny" marker icon
		var customIcon = new GIcon(G_DEFAULT_ICON);
		
		//need to differenciate between places and accomodations
		//so know that accom is h0 ( default ) or h1 ( faded )

		if( ico == 'h0' || ico == 'h1' ){
			customIcon.image  = web_site_path+"images/googlemap_icons/type_places/" + ico +".png";
			customIcon.shadow = web_site_path+"images/googlemap_icons/type_places/" + ico + "shadow.png";
		}else{
			customIcon.image  = web_site_path+"images/googlemap_icons/type_places/" + ico +".png";
			customIcon.shadow = web_site_path+"images/googlemap_icons/type_places/" + ico + "shadow.png";
		}
		
		// Set up our GMarkerOptions object
		markerOptions = { icon:customIcon };
		marker = new GMarker(center, markerOptions);
		
		//addlistner
		GEvent.addListener(marker, "click", function() {
				showPlaceOnMap(id, whatshow);
		});
		
		map.addOverlay(marker);
	}

	
	
	function showMarker(){
		if(document.m.dragged.value == 1){
			var tempcent = map.getCenter();
			marker.setLatLng(tempcent);
		}
	}
	
	
	

	function showPlaceOnMap(id, placeoraccom){
		
		var lat    = document.getElementById('lat_'+placeoraccom+'_'+id).value;
		var lng    = document.getElementById('lng_'+placeoraccom+'_'+id).value;
		var name   = document.getElementById('name_'+placeoraccom+'_'+id).value;
		var folder = document.getElementById('folder_'+placeoraccom+'_'+id).value;
		var address = document.getElementById('address_'+placeoraccom+'_'+id).value;
		var imglink = document.getElementById('imglink_'+placeoraccom+'_'+id).value;
		var whatshow = document.getElementById('whatshow_'+placeoraccom+'_'+id).value;		
		var s;
		
		if(whatshow == 'showplace') var whatshow2 = 'miejsce';
		else var whatshow2 = 'nocleg';
		
		s = "<div style=\"font-size:10px;\"><a href='"+web_site_path+whatshow2+","+folder+","+name+".html'>"+name+"</a>";
		
		s = s + "<hr width='200px'><table width='200px'><tr><td><p class='txt'" + address +"</p></td><td><a href='"+web_site_path+whatshow2+","+folder+","+name+".html'><img alt=\"Link\" src='" + imglink + "' width='75px' border='0'></a></td></tr></table></div>";

		
		//s = "<a href='"+web_site_path+whatshow2+","+folder+","+escape(name)+".html'>"+name+"</a>";
		//s = s + "<hr width='200px'><table width='200px'><tr><td><p class='txt'" + address +"</p></td><td><a href='"+web_site_path+whatshow2+","+folder+","+escape(name)+".html'><img src='" + imglink + "' width='75px' border='0'></a></td></tr></table>";

		if(zoom2point) {var zoom = 12;}
		else {var zoom = map.getZoom();}
		
		var center = new GLatLng(lat, lng);
		map.setCenter(center, zoom);
		map.openInfoWindowHtml(center, s);
	}

	
	
	
	function zoom(v,ptk){
		var z = map.getZoom();
		var tempcent = marker.getLatLng();
		
		if(ptk == 1) map.setCenter(tempcent);
		
		if((z + v)<0){ z=0;} else {z = z + v;};
		map.setZoom(z);
		document.m.zoom.value = z;
	}
	
	
	function setCountry(){
		country = document.m.place_country.options[document.m.place_country.selectedIndex].value;
		
		if(document.m.place_country.options[document.m.place_country.selectedIndex].value == 'pl'){
			showDiv('district');
		}else{
			hideDiv('district');
			district = "";
			document.m.place_district.options.selectedIndex = 0;
		};
	};

	
	//GENERAL FUNCTIONS
	
	function checkNrChars(id, com_id, max_char){
		var area = document.getElementById(id);
		var p = document.getElementById(com_id);
		//var max_char = 150;
		
		p.innerHTML = '<span>Maksymalna ilość znaków '+area.value.length+' / '+max_char+'</span>';
		
		if(area.value.length > max_char){p.className="txt_smallR_error";}else{p.className="txt_smallR";};
		
	}
	
	
	function expand_div(id, flexcroll){
		var div = document.getElementById(id);
		if(div.className == 'hidden') div.className = 'visible'; else div.className = 'hidden';
		
		//need to re-draw the div
		updateFlexcroll( flexcroll );
	}
	
	
	function expand_comment(){
		var div = document.getElementById('add_comment');
		if(div.className == 'hidden') {showDiv('add_comment');}
		else {hideDiv('add_comment')};
		return false;
	}
	
	function expand_addpic( divid ){
		var div = document.getElementById( divid );
		if(div.className == 'hidden') {showDiv( divid );}//'add_pic'
		else {hideDiv( divid )};
		return false;
	}
	
	
	function showDiv(id){
		if( document.getElementById(id) ) document.getElementById(id).className = 'visible';
	}
	
	function hideDiv(id){
		if( document.getElementById(id) ) document.getElementById(id).className = 'hidden';
	}
	
	function showMore(div_id, hidden_id, val){
		if( document.getElementById(div_id) ) 
			if(val == 1) {document.getElementById(div_id).className = 'visible';}
			else{document.getElementById(div_id).className = 'hidden';};
			
		if( document.getElementById(hidden_id) ) document.getElementById(hidden_id).value = val;
	
		return false;
	}
	
	function confirm2(){ return confirm("Usunąć to miejsce?"); }
	

	
	function selectListItemByValue (list, v){
		var index;
		var i;
		for (i=0; i<list.length; i=i+1) 
		{
			if (list.options[i].value == v) {index = i;};
		}
		list.options.selectedIndex = index;
	}
	
	
	function setDistrict(){district = document.m.place_district.options[document.m.place_district.selectedIndex].text;};
	
	function countrySetMapCenter(country_val){
		//var country_code = document.m.place_country.options[document.m.place_country.selectedIndex].value;
		//alert(d);


		if(geocoder){
		  geocoder.getLatLng(
			 country_val,
		    function(point) {
			  if (!point) {
			    map.openInfoWindowHtml(map.getCenter(), "Nie znaleziono kraju " + country_val);
			  } else {
				map.setCenter(point, 5);
				showMarker();
			  }
		    }
		  );
	    }	
	};

	function districtSetMapCenter(){
		district = document.m.place_district.options[document.m.place_district.selectedIndex].text;
		//alert(district+' , '+country);
		
		if(geocoder){
		  geocoder.getLatLng(
		    district + ',' + country,
		    function(point) {
			  if (!point) {
			    map.openInfoWindowHtml(map.getCenter(), "Nie znaleziono województwa " + district);
			  } else {
				map.setCenter(point, 7);
				showMarker();
			  }
		    }
		  );
	    }
	};
	
	
	function showAddressOnMap(){
		var address = document.m.place_country.options[document.m.place_country.selectedIndex].text + ',' +
		document.m.place_city.value + ',' + document.m.place_street.value;

		//alert(district+' , '+country);
		
		if(geocoder){
		  geocoder.getLatLng(
		    address,
		    function(point) {
			  if (!point) {
				  map.closeInfoWindow();
				  map.openInfoWindowHtml(map.getCenter(), "<p class='txt'>Nie znaleziono podanego adresu: " + address + "</p>");
			  } else {
				map.closeInfoWindow();
				map.setCenter(point, 7);
				showMarker();
			  }
		    }
		  );
	    }
	};
	
	
	function districtSetMapCenter2(){
		var district = document.getElementById('zoom2distric').options[document.getElementById('zoom2distric').selectedIndex].text;
		if(geocoder){
		  geocoder.getLatLng(
		    district ,
		    function(point) {
			  if (!point) {
			    map.openInfoWindowHtml(map.getCenter(), "Nie znaleziono województwa " + district);
			  } else {
				map.setCenter(point, 7);
				showMarker();
			  }
		    }
		    );
	    };
	};	
	
	function citySetMapCenter(){
		var city = document.m.place_city.value;
		
		if(city != "" && geocoder){
		  geocoder.getLatLng(
		    city + ',' + country,
		    function(point) {
			  if (!point) {
			    map.openInfoWindowHtml(map.getCenter(), "Nie znaleziono miasta " + city + ', w ' + country);
			  } else {
				map.setCenter(point, 12);
				showMarker();
			  }
		    }
		  );
	    }
	};

	function lat(s){var n = s.split(",");var temp = n[0];return temp.substring(1,temp.length);}
	function lng(s){var n = s.split(",");var temp = n[1];return temp.substring(0,temp.length-1);}	

	//function showPlaceOnMap(lat,lng){
	//	var center = new GLatLng(lat,lng);
	//	map.setCenter(center, 12);
	//};
	
	
	function gps_setOnMap(){
		//marking from gps position on map, and setting up variables
		var lat,lng;
		
		lat = document.m.gps_lat.value;
		lng = document.m.gps_lng.value;
		
		var center = new GLatLng(lat,lng);
		map.setCenter(center, 12);
		showMarker();
		document.m.markerlatlng.value = marker.getLatLng();
		document.m.dragged.value = 1;
	};
	
	
	function AdjustDivPicPosition(){
 	 	// Move the content into view
  		//parent['mainFrame'].document.getElementById('dispPix').style.top = parent['mainFrame'].document.body.scrollTop+5;
		var b = document.body;
		document.getElementById('map_canvas').style.top = b.scrollTop+0;
	}
	
	function addCommentRating(){
		//if search form, then copy search values to commnet form
		if(document.f_search){
			document.f_com.place_country.value  = document.f_search.place_country.value;
			document.f_com.place_district.value = document.f_search.place_district.value;
			document.f_com.place_city.value     = document.f_search.place_city.value;
			document.f_com.place_keyword.value  = document.f_search.place_keyword.value;
			document.f_com.expand.value         = document.f_search.expand.value;

			var f = document.f_com.place_type;
			var chk = document.f_search.place_type;
			
			f.value = "";
			for (i = 0; i < chk.length; i++)
				if(chk[i].checked) f.value = f.value +","+ chk[i].value;
		}

		document.f_com.submit();
	}
	
	
	function checkboxesvalues(chk){//alert('@');
		var f = document.f_search.test;
		f.value = "";
		for (i = 0; i < chk.length; i++)
			if(chk[i].checked){ 
					if (f.value == "") f.value = ""+chk[i].value;
						else f.value = f.value +","+ chk[i].value;
			};
	}
	
	
	function sellectAll(sell_all, chk){
		var s;
		if(sell_all.checked){s=1;}else{s=0;};
		
		for (i = 0; i < chk.length; i++)
			chk[i].checked=s;
	}


	function submitenter(myfield,e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		
		if (keycode == 13)
		   {
		   myfield.form.submit();
		   return false;
		   }
		else
		   return true;
	}
	
	
	
	//FUNCTIONS TO SIMULATE BEHAVIOUR OF IMG AS BUTTONS
	//this functions will be replacing images 
	//the trick is in the file name of the images:
	//xxxxx_1.gif - the mouse is over
	//xxxxx_0.gif - the mouse is out
	
	function over(e){
		var img,src;
		if(e.target) img=e.target;else img=event.srcElement;
		
		var fileInfo = getFileInfo(img.src);
		
		var basenameindex = fileInfo[2].lastIndexOf("_");
		var basename = fileInfo[2].substring(0,basenameindex+1);
		//ABOVE WORKS, NEED TO DECIDE HOW TO SEPARATE THE INFO ABOUT OVER/OUT IMAGES
		src = fileInfo[1] + basename + "1."  + fileInfo[3];
		img.src = src;
	}
	
	
	function out(e){
		var img,src;
		if(e.target) img=e.target;else img=event.srcElement;
		
		var fileInfo = getFileInfo(img.src);
		
		var basenameindex = fileInfo[2].lastIndexOf("_");
		var basename = fileInfo[2].substring(0,basenameindex+1);
		//ABOVE WORKS, NEED TO DECIDE HOW TO SEPARATE THE INFO ABOUT OVER/OUT IMAGES
		src = fileInfo[1] + basename + "0."  + fileInfo[3];
		img.src = src;		
	}
	
	function out2(img){
		//used to iterate through elements
		//need to pickup spacers
		var img,src,postfix;
		//if(e.target) img=e.target;else img=event.srcElement;
		
		var fileInfo = getFileInfo(img.src);

		if(fileInfo[2] != "spacer" && fileInfo[2] != "Gpusty"){
			var basenameindex = fileInfo[2].lastIndexOf("_");
			var basename = fileInfo[2].substring(0,basenameindex+1);
			//ABOVE WORKS, NEED TO DECIDE HOW TO SEPARATE THE INFO ABOUT OVER/OUT IMAGES
			if(img.id=='active' || img.id=='sub_active') postfix = '1.'; else postfix = '0.';
			
			src = fileInfo[1] + basename + postfix  + fileInfo[3];
			img.src = src;
		}
	}
	
	function out3(){
		var par_div = document.getElementById('main_menu_container');
		travel(par_div);
	}
	
	function getFileInfo(fileAndPath){
		//find the index of the last "\"
		var lastPathDelimiter = fileAndPath.lastIndexOf("/");
		
		//get everything after the last "\"
		var fileNameFull = fileAndPath.substring(lastPathDelimiter+1);
		var pathFull = fileAndPath.substring(0,lastPathDelimiter+1);
		
		//separating extension and name
		var _temp = fileNameFull.split(".");
		var fileExtension = _temp[1];
		var fileName = _temp[0];
		
		var fileInfo = new Array(4)
		
		fileInfo[0] = fileNameFull;
		fileInfo[1] = pathFull;
		fileInfo[2] = fileName;
		fileInfo[3] = fileExtension;
		
		//alert(fileInfo[0]);
		
		return fileInfo;
	}
	
	
	function jump(cancel_ref_page){
		
		if(cancel_ref_page=='back'){history.go(-1);}
		else{
			window.location.href = cancel_ref_page;
		}
	}
	

	function showReg(){
		OpenWin = this.open("reg.htm", "RegulaminWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=550,height=450");
		return false;
	}
	
	function showDataProcess(){
		OpenWin = this.open("daneosobowe.htm", "DaneOsoboweWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=550,height=450");
		return false;
	}

	function showAccomReg(){
		OpenWin = this.open("accomreg.htm", "RegulaminWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=550,height=450");
		return false;
	}
	
	function showplace(place2show){
		
		window.location.href = "?showplace="+place2show;
	}

	function showByTags(tag_text){
		document.f_tag_search.place_keyword.value = tag_text;
		document.f_tag_search.submit();
	}
	

	/* SUB MENU/MENU items */
	function showsubmenu(sub_menu_id, e){
		hidesubmenu();
		
		var par_div = document.getElementById(sub_menu_id);
		if(par_div) par_div.className = 'sub_menu_visible';
		
		/*var img,src;
		if(e.target) img=e.target;else img=event.srcElement;
		sub_menu_visible
		alert(img.offsetTop);
		*/
	};


	function hidemainmenu(){
		// id=\"sub_menu_container\"
		//iterate all divs in the sub_menu_cont and off them
		var par_div = document.getElementById('main_menu_container');

		
		travel(par_div);
		
		/*if(par_div){
			var img = par_div.firstChild;
			
			while(img){
				//if(img.tagName=='img'){ out2(img);};
				alert(img);
				img = par_div.nextSibling;
			}
		}
		*/
	};		
	
	function hidesubmenu(){
		
		// id=\"sub_menu_container\"
		//iterate all divs in the sub_menu_cont and off them
		var par_div = document.getElementById('sub_menu_container');
		
		hideDivs(par_div.firstChild);
/*
		if(par_div){
			var n = par_div.firstChild;
			
			while(n){
				alert(n);
				n.className = 'sub_menu_hidden';
				n = par_div.nextSibling;
			}
		}
		*/
		
/*
if (n.tagName)
a.push(' tagName: '+n.tagName+ ' id: '+ n.id)
if (n.firstChild)
travel(n.firstChild)
if (n.nextSibling)
travel(n.nextSibling)
*/		
	};
	
	
	
	function setActiveSubmenu(){
		// id=\"sub_menu_container\"
		//iterate all divs in the sub_menu_cont and off them
		
		hidesubmenu();
		if(document.getElementById(active_menu_item))
			document.getElementById(active_menu_item).className = 'sub_menu_visible';
	};
	
	function travel(n){
		if (n.tagName) {
			//alert(' tagName: '+n.tagName+ ' id: '+ n.id)
			if(n.tagName == 'IMG'){ 
				out2(n);
				//alert(' src: '+n.src);
			};
		}
		
		if (n.firstChild) travel(n.firstChild)
		if (n.nextSibling) travel(n.nextSibling)
	}	


	function hideDivs(n){
		if (n.firstChild) hideDivs(n.firstChild)
		if (n.nextSibling) hideDivs(n.nextSibling)
		
		if (n.tagName) {
			//alert(' tagName: '+n.tagName+ ' id: '+ n.id)
			if(n.tagName == 'DIV'){ 
				n.className = 'sub_menu_hidden';
				//alert(' src: '+n.src);
			};
		}
		

	}


	function fadeActiveItem(){
		var img = document.getElementById('active');
		if(img) {
			
			var fileInfo = getFileInfo(img.src);

			var basenameindex = fileInfo[2].lastIndexOf("_");
			var basename = fileInfo[2].substring(0,basenameindex+1);
			//ABOVE WORKS, NEED TO DECIDE HOW TO SEPARATE THE INFO ABOUT OVER/OUT IMAGES
			postfix = '2.';
			
			src = fileInfo[1] + basename + postfix  + fileInfo[3];
			img.src = src;	
		}
	}
	
	/* automated return to sytuation zero for main menu */
	var timeOut;
	
	function setBasicMenu(what)
	{
		if(what=='timer') timeOut = setTimeout("hidemainmenu(); setActiveSubmenu();",2000);
		if(what=='instant') {clearTimeout(timeOut); hidemainmenu(); setActiveSubmenu();};
	}

	function cancelTimer()
	{
		clearTimeout(timeOut);
	}
	

	function clearDefPicCom(comment_pic_id){
		var baseline="Dodaj komentarz...";
		var com = document.getElementById(comment_pic_id);
		if(com.value == baseline) com.value = "";
	}
	
	function putDefPicCom(comment_pic_id){
		var baseline="Dodaj komentarz...";
		var com = document.getElementById(comment_pic_id);
		if(com.value == "") com.value = baseline;
	}
	
	

	//Flexcroll
	
	//need to re-draw the div
	function updateFlexcroll( id ){
		var flexcroll = document.getElementById(id);
		if( flexcroll != null ) flexcroll.scrollUpdate();
	}
	
	
	//COMMENTS OVERFLOW
	function expanddescr(e){
		if( e.target ) var div=e.target;else var div=event.srcElement;
		if( div && div.tagName == 'DIV' ) {div.style.width = '160px'; trueheigh = div.scrollHeight; div.style.overflow="visible"; div.style.height = trueheigh+'px'; /*_pc_set_zindex( div, '100' );*/ _pc_display_div(div,1);}
	}

	function hidedescr(e){
		if( e.target ) var div=e.target;else var div=event.srcElement;
		if( div && div.tagName == 'DIV' ) {div.style.overflow="hidden"; div.style.width = '65px'; div.style.height = '18px'; /*_pc_set_zindex( div, '1' );*/ _pc_display_div(div,-1); }
	}
	
	
	function _pc_set_zindex( div, zindex ){
		//this function may not work as the 3rd element may not be set up
		div.style.zIndex = zindex;
		
		//and now the main container
		var n = div.id.split("_");
		var id = n[2];
		var maindiv = document.getElementById( 'main_pc_container_' + id );//main_pc_container_    div.innerHTML=id;
		if(maindiv) {maindiv.style.zIndex = zindex;};
	}

	
	function _pc_display_div( div, dir ){
		if(dir==1){
			var newParent = document.body;
			var _t_div = div;
			var zindex = 100;
			
			var top = left = 0;
			while( _t_div != null ) {
				left += _t_div.offsetLeft;
				top += _t_div.offsetTop;
				_t_div = _t_div.offsetParent;
			}
			
			
		}else{
			//back to original position
			var n = div.id.split("_");
			var id = n[2];
			var newParent = document.getElementById( 'main_pc_container_' + id );//main_pc_container_    div.innerHTML=id;
			var left=0; var top=70; var zindex = 1;
		}
		
		newParent.appendChild(div);
		div.style.left = left+'px';
		div.style.top = top+'px';
		div.style.zIndex = zindex;
	}
	
	
	function highlitediv(e){
		if( e.target ) var div=e.target;else var div=event.srcElement;
		if( div && div.tagName == 'DIV' ) { div.style.backgroundColor = 'white'; div.style.border='1px solid grey'; }
	}
	
	function dehighlitediv(e){
		if( e.target ) var div=e.target;else var div=event.srcElement;
		if( div && div.tagName == 'DIV' ) { div.style.backgroundColor = ''; div.style.border='none'; }
	}
	
