var newEntry = true;
var actPage = 1;
var hotelID = 1;

function showNewEntryForm() 
{
		if ( newEntry == true)
	{
  	$('#newEntry').slideDown('slow');
    newEntry = false;
	} else {
  	$('#newEntry').slideUp('slow');
    newEntry = true;
	}
}

function loadEntries(count) {
	
	var d = new Date();
	var t = d.getTime();
	var thetimestring = t.toString(10);
		
	var dataString = "hotelID=" + hotelID + "&count=" + count + "&time=" + thetimestring;
	$.ajax({
		type: "POST",
		url: "/guestbook/loadComments.php5",
		data: dataString,
		cache: false,
		success: function(html){
			$(".paging" + actPage).css("fontWeight", "normal");
			$(".paging" + actPage).css("textDecoration", "underline");
			$(".paging" + actPage).css("color", "A9000A");
			$(".paging" + count).css("fontWeight", "bold");
			$(".paging" + count).css("textDecoration", "none");
			$(".paging" + count).css("color", "000000");
			
			actPage = count;
		
			$("#entries").html(html);
		}
	});
}

$(function() {
$(".saveComment").click(function() {

    var name     = $("#name").val(); 
    var city     = $("#city").val();
    var comments = $("#comment").val(); 
 		var capt     = $("#capt").val();
 		var defCapt  = $("#defCapt").val();
 		
 		if (capt != defCapt)
 			alert("Falscher Sicherheitscode");
 		else
	    if (name.length > 0 && comments.length > 0) 
	    {
    		var dataString = "name=" + name + "&city=" + city + "&comment=" + comments + "&hotelID=" + hotelID;
    		
    		$.ajax({
					type: "POST",
					url: "/guestbook/saveComment.php5",
					data: dataString,
					cache: false,
					success: function(date){
						
						loadEntries(1);
						var newText = "<div class='entry'>";
						
						newText += "<div class='entryLeft'>";
						newText += name + "<br />aus " + city + "<br />am " + date;
						newText += "</div>";
						
						newText += "<div class='entryRight'>";
						newText += comments;
						newText += "</div></div>";
						newText += "<div style='clear:both'></div>";
						
						$("#entries").prepend(newText);
						
						$("#name").val("");
						$("#city").val("");
						$("#comment").val("");
						showNewEntryForm();		
					}
				});
    	} 
    	else
    		alert(unescape("Bitte f%FCllen Sie alle Felder aus%21"));
	}); 
});