var guestBook = Class.create();
guestBook.prototype = {
	url: '/back/guestbook.php',
	entries: [],
	guestbookContent: "",
    totalNumberOfEntries: 0,
    initialize: function () {
	},
	buildGuestBook: function(){
		//Kind of facade method to build the guestbook.
		this.getAllEntries();
		//this.getGuestbookForm();
        this.updatePage();
		//3. glue it together and return result
	},
    addEntryAndBuild: function(theForm){
        this.addEntryToGuestbook(theForm);
		this.getAllEntries();
		this.getGuestbookForm();        
    },
    getAllEntries: function(){
       // alert("getting entries");
        //var showEntries = this.showEntries.bind(this);
		//var reportError = this.reportError.bind(this);
		var pars   = 'action=' + 'selectAll';
		var myAjax = new Ajax.Updater( "storyContainer", this.url,
            {method: 'get',
                parameters: pars,
                onFailure:  reportError
			}
        );
	},
	getGuestbookForm: function(){
       // alert("getting entries");
        //var showEntries = this.showEntries.bind(this);
		//var reportError = this.reportError.bind(this);
		var url    = '/back/guestbook.php';
		var pars   = 'action=' + 'getForm';
		var myAjax = new Ajax.Updater("storyContainer",  this.url,
            {
				method: 'get',
                parameters: pars,
				insertion: Insertion.Bottom,
                onFailure: reportError
			});	
	},
	addEntryToGuestbook: function(theForm)	{
        //alert("Sending form with values: " + Form.serialize("guestbookForm"));
        var url = '/back/guestbook.php';
        var pars = 'action=' + 'addEntry&' + Form.serialize("guestbookForm");
        var myAjax = new Ajax.Request(url, 
		{
			method: 'get', 
			parameters: pars
		});
	},
    updatePage: function(){

        $("main_wrapper").style.visibility = "visible";
        $("main_wrapper_images").style.visibility = "hidden"; 	
        $("permaLinkClick").style.visibility = "visible";
    
        document.getElementById("storyTitle").innerHTML = "Gastenboek";
        document.getElementById("storyDate").innerHTML = "";
        document.getElementById("bookMark").innerHTML = "<a href='javascript:buildGuestBook()' >Bookmark Gastenboek </a>";
        $("linkTitle").innerHTML = "Gastenboek";   	
        $("linkUrl").innerHTML = "http://www.zwoeledromen.nl";
        publishImage(17);
    },
    reportError: function (request)	{
		alert('Error: ' + request.responseText);
	}
	
};
function sendGuestbooEntry () {
	var url = '/back/guestbook.php';
	var pars = 'action=' + 'addEntry&' + Form.serialize('frm');
	var myAjax = new Ajax.Request( url, 
		{
			method: 'get', 
			parameters: pars, 
			onLoading: showLoad, 
			onComplete: showResponse} 
		);
}

//alert("guestbook.js")
var gBook = new guestBook();
