(function() {
	
	var Dom = YAHOO.util.Dom;
	var Event = YAHOO.util.Event;
	var WELCOME = "welcome.htm";
	
	var clickHandler = function() {

        var form = document.createElement("form");

        //move the submit function to another variable
        //so that it doesn't get over written
        
        form._submit_function_ = form.submit;

        form.setAttribute("method", "post");
        form.setAttribute("action", WELCOME);

        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", this.id);
        hiddenField.setAttribute("value", "yes");

        form.appendChild(hiddenField);
 
        document.body.appendChild(form);
        form._submit_function_(); //call the renamed function

		return false;
	}
	
	Event.onDOMReady(function() {
		
		dwr.engine.setErrorHandler(function(x,y) {			
			document.location = "error.htm";
		});	
		
		dwr.engine.setTextHtmlHandler(function() {
			document.location = "logout.htm";
		});
		
		var links = Dom.getElementsByClassName('catalogue');
		for(var i=0; i<links.length; i++) {
			links[i].onclick = clickHandler;
		}

	});
	
})();
