	
	function loadChat(chatId,chatType){
		if(chatType == "admin"){
			timeInput  = 'updateIdUsers';
		} else {
			timeInput  = 'updateId';
		}

		if(document.getElementById(timeInput).value == ""){
			//timeReset(chatType);
			loadChatContent(chatId,'',chatType);
		} else {
			lastUpdate = document.getElementById(timeInput).value;
			loadChatContent(chatId,lastUpdate,chatType);
			//timeReset(chatType);
		}
	}

	function scrollDown(elem){
		scrollDiv = document.getElementById(elem);
		scrl = document.getElementById('scroll'+elem).value;

		if(scrl == 'true'){
			scrollDiv.scrollTop = scrollDiv.scrollHeight;
		}
	}

	var scrollingIndex = 0;

	function checkScrolling(elem){

		scrollingIndex = (scrollingIndex+1);

		if(elem == "usersChatBox"){
			divHeight = 148;
		} else {
			divHeight = 248;
		}


		if(scrollingIndex > 50){
			scrollDiv = document.getElementById(elem);
			scrl = document.getElementById('scroll'+elem);

			if((scrollDiv.scrollTop+divHeight) == scrollDiv.scrollHeight){
				scrl.value = 'true';
			} else {
				scrl.value = 'false';
			}
		//	window.status = 'scrolled:'+(scrollDiv.scrollTop+divHeight)+' == height:'+scrollDiv.scrollHeight;
		}
	}

/*
	function timeReset(chatType){
		if(chatType == "admin"){
			timeInput  = 'updateIdUsers';
		} else {
			timeInput  = 'updateId';
		}
		actDate = new Date();
		document.getElementById(timeInput).value = actDate.getTime();
		lastUpdate = document.getElementById(timeInput).value;
	}
*/
	  var chatRow = '';

	  function loadChatContent(chatId,lastUpdate,chatType) {

        $.getJSON("/chat/chat.ajax.php",
          { action: "getChat", 
            cId: chatId, lUpdate: lastUpdate, cType: chatType },
          function(data, status) {
			$.each(data, function() {


				if(chatType == "admin"){
					chatRow += '<span class="date">['+this.date+'</span>';
					chatRow += '&nbsp;<span class="user">'+this.user+']</span>&nbsp;';
					chatRow += this.txt;
					
					$("<div/>").attr("class", "chatRow").html(chatRow).appendTo("#usersChatBox");
					if(this.lastId!=""){
						document.getElementById("updateIdUsers").value = this.lastId;
					}
				} else {
					chatRow += '<span class="date">['+this.date+'</span>';
					chatRow += '&nbsp;<span class="user">'+this.user+']</span>&nbsp;';
					chatRow += this.txt;
					
					$("<div/>").attr("class", "chatRow").html(chatRow).appendTo("#regularChatBox");
					if(this.lastId!=""){
						document.getElementById("updateId").value = this.lastId;
					}
				}

				chatRow = '';

//	if(this.type == "regular"){
	//	alert(chatRow);
//		cBox.innerHTML += chatRow;
//	}

/*
		chatRow = '<div class="chatRow">'+"\n";
		chatRow += '<span class="dat">'+this.date+'</span><span class="usr">'+this.user+'</span>'+this.text+"\n"; // +''+this.type
		chatRow += '</div>'+"\n";
*/

				
//				alert('should add TO:'+cBox.id+cBox.innerHTML);

	//			cBox.innerHTML += chatRow;


			});
          }
		);
		
		
	  
	  }


	function sendChat(chatId,chatType){

		if(chatType == ""){
			editor = 'chatEdit';
			chatUser = document.getElementById('loggedUser').value;
		} else {
			editor = 'userChatEdit';
			chatUser = document.getElementById('loggedAdmin').value;
		}

		var oEditor = FCKeditorAPI.GetInstance(editor);

		chatText = oEditor.EditorDocument.body.innerHTML;

		

		if(chatText!=""){

			$.getJSON("/chat/chat.ajax.php",
			  { action: "saveChat", 
				cType: chatType, cId: chatId, cText: chatText, cUser: chatUser },
			  function(data, status) {
				$.each(data, function() {
				
				oEditor.EditorDocument.body.innerHTML = '';
				oEditor.EditorDocument.body.focus();

				loadChat(chatId,chatType);

				});
			  }
			);

		}

	}












/*
        function createMarker(point, index, markerText, markerIcon) { // 

			var baseIcon = new GIcon(G_DEFAULT_ICON);		
			baseIcon.shadow = "/css/images/mapy/shadow.png";
			baseIcon.iconSize = new GSize(16, 16);
			baseIcon.shadowSize = new GSize(20, 20);
			baseIcon.iconAnchor = new GPoint(8, 2);
			baseIcon.infoWindowAnchor = new GPoint(8, 2);

			//var letter = String.fromCharCode("A".charCodeAt(0) + index);
			var letteredIcon = new GIcon(baseIcon);
			if(markerIcon!="" && markerIcon!=null){
				letteredIcon.image = "" + markerIcon + "";
			} else {
				letteredIcon.image = "/css/images/mapy/default.png";
			}

          // Set up our GMarkerOptions object
          markerOptions = { icon:letteredIcon }; // icon:letteredIcon
          var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml( markerText );
          });
          return marker;
        
		
		
		
		}

		function loadOblast(listParams,dontReloadDiv){
			map.clearOverlays();	// zrusi vsechny body
			loadMarkersForBounds(map.getBounds(),listParams,dontReloadDiv);
		}

		function clearObjectList(){
			document.getElementById('listBody').innerHTML = '';
		}

		function loadObjectToDiv(toFill){
			elem = document.getElementById('listBody');
			elem.innerHTML += toFill;
		}

		function loadMultiple(){
			elems = document.getElementsByTagName('input');

			a = 0;
			for(i=0;i<elems.length;i++){
				if(elems[i].className == "oblChbox" && elems[i].checked == true){
					if(a == 0){
						listParams = 'mesto:'+encodeURI(elems[i].value);
					} else {
						listParams = listParams+';mesto:'+encodeURI(elems[i].value);
					}
					a++;
				}
			}
			if(listParams != ""){
				loadOblast(listParams,false);
			} else {
				alert('Nejsou vybrány žádné oblasti!');
			}
		}

	function loadMultipleObjects(){
			elems = document.getElementsByTagName('input');

			a = 0;
			for(i=0;i<elems.length;i++){
				if(elems[i].className == "objChbox" && elems[i].checked == true){
					if(a == 0){
						listParams = 'cislorp:'+elems[i].value;
					} else {
						listParams = listParams+';cislorp:'+elems[i].value;
					}
					a++;
				}
			}

			if(listParams != ""){
				loadOblast(listParams,true);
			} else {
				alert('Nejsou vybrány žádné oblasti!');
			}
	}

    function showTooltip(lat,lon,index,txt) {

//		map.setCenter(new GLatLng(lat, lon), 13);
//		map.addOverlay(createMarker(new google.maps.LatLng(lat, lon), index, txt));
		map.openInfoWindowHtml(new google.maps.LatLng((lat+0.00030), lon), txt );
    }

      function initialize() {
	  // Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.



		map = new google.maps.Map2(document.getElementById("map"));

        map.enableScrollWheelZoom();
		map.addControl(new GScaleControl());
//		map.addControl(new GOverviewMapControl());

		zoom = document.getElementById('mapZoom').value;

		map.setCenter(new google.maps.LatLng(49.852152, 15.644531), parseInt(zoom));
	//	map.setCenter(new google.maps.LatLng(<?php echo $p[centerX]; ?>, <?php echo $p[centerY]; ?>), 12);

		map.addControl(new google.maps.LargeMapControl());
        map.addControl(new google.maps.MapTypeControl());

//		map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));

//		GEvent.addListener(map, 'click', function() {
//			alert("You doubleclicked the map.");
//		});

		params = document.getElementById('id_group').value;

        loadMarkersForBounds(map.getBounds(),params,false);
      }

*/