/*
    SiteComponents version:
    6.8.0.1, tag SC_6_8_0_1, created Fri Aug 20 11:18:33 +0200 2010

    Disclaimer
    
    While we make every effort to ensure that this code is fit for its intended
    purpose, we make no guarantees as to its functionality. CoreTrek AS will
    accept no responsibility for the loss of data or any other damage or
    financial loss caused by use of this code.


    Copyright
    
    This programming code is copyright of CoreTrek AS. Permission to run this
    code is given to approved users of CoreTrek's publishing system CorePublish.
    
    This source code may not be copied, modified or otherwise repurposed for use
    by a third party without the written permission of CoreTrek AS.
    
    Contact webmaster@coretrek.com for information.
    
*/

/*jslint laxbreak: true, sub: true, white: false, browser: true,
onevar: false, nomen: false, noindent: true, eqeqeq: false, plusplus: false,
forin: true */
/*global siteComponentsConfig: false, getSiteComponentsConfig: false,
Ajax: false, $$: false, $: false, Element: false, window: false, Class: false,
Effect: false, lightbox: false, PeriodicalExecuter: false, Event: false,
CtCookie: false, cpKeywords: false, CtTooltip: false, Prototype: false,
cpWriteMediaObject: false, getThemeName: false, Hash: false, $H: false,
$break: false */

/*

    ============================================================================
    IMPORTANT! This javascript is dependent on Prototype.
    ============================================================================

    SiteComponents suggestiontile.js

    Enhancement of the AppbaseSuggestionTile
    
	The tile is enhanced with Ajax submit
*/

var SuggestionTile = Class.create({
	
	initialize: function(element) {
		this.element = $(element);
		this.form = this.element.select('form').first();
		
		this.form.observe('submit', this.formSubmitListener.bindAsEventListener(this));
	},
	
	formSubmitListener: function(event) {
		event.stop();
		
		new Ajax.Request(this.form.readAttribute('action'), {
			parameters: this.form.serialize(),
			onSuccess: function(req) {
                var obj = req.responseText.evalJSON();
                alert(obj['message']);
                if(!obj['isError']) {
					lightbox.hide();
                }
            }.bind(this)
		});
	}
	
});
