
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_opera  = (agt.indexOf("opera") != -1);
var is_gecko  = (navigator.product == "Gecko");


function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function showHide(i) {
    var obj = $(i).style;
    if (obj.display == "none" || obj.display == "" || obj == false) {
        obj.display = "block";
    } else {
        obj.display = "none";
    }
}

function gt(url){
	window.location=url;
}

function toUrl(url){
	var actUrl = window.location.href;
	var pageUrl = actUrl.split('/');

	if (pageUrl[pageUrl.length - 1] == 'editor') {
		if (confirm("Le modifiche se non salvate andranno perse. Vuoi abbandonare?")) {
			window.location = url;
		}
	} else {
		window.location = url;
	}
}

function yetToBeDone(){
	new Widget.popup({
		width: 450,
		height: 350,
		content: '<h1 style=color:#666>Questa sezione è in fase di sviluppo</h1>',
		title: 'Coming soon...'
	});
}

function Class() {
	return function() {}
}

function checkEmail(fields) {
    var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
    var str = "";
    for (var i = 0; i < fields.length; i++) {
        str += "!emailRegExp.test($('" + fields[i] + "').value) ||";
    }
    if (eval(str.slice(0, str.length - 3))) {
        return false;
    } else {
        return true;
    }
}

function maxChar(field){
	if ($(field).value.length > 4000) {

		$(field).value = $(field).value.substr(0,4000);
		systemOut({
			cont: 'partecipate_systemOut',
			text: 'Puoi scrivere un massimo di 4\'000 caratteri.'
		});
		$(field).focus();
	}else{
		return true;
	}
}

function checkDate(field){

	var x = $(field).value.split('-');
	if (!x[0] || !x[1] || !x[2]) {
		return false;
	}else if(x[0].length > 2 || x[0].length < 2 || x[0] > 31 || x[1].length > 2
			|| x[1] > 12 || x[1].length < 2 || x[2].length > 4 || x[2].length < 4
			|| x[2] < 1900  || x[2] > 2100){
		return false;
	}else {
		return true;
	}
}

function isInteger(field) {
	var value = $(field).value;
    var digits = "1234567890";
    for (var i = 0; i < value.length; i++) {
        if (digits.indexOf(value.charAt(i)) == -1) {
            return false;
        }
    }
    return true;
}

function checkBox(fields) {

    var str = "";
    for (var i = 0; i < fields.length; i++) {
        str += "($('" + fields[i] + "').checked == false) ||";
    }
    if (eval(str.slice(0, str.length - 3))) {
        return false;
    } else {
        return true;
    }
}

function required(fields) {
    var str = "";
    for (var i = 0; i < fields.length; i++) {
        str += "$('" + fields[i] + "').value == '' || ";
    }
    if (eval(str.slice(0, str.length - 3))) {
        return false;
    } else {
        return true;
    }
}

function GetBodySize() {

	var body = $T('body')[0];
	var w,h;

	if( typeof( window.innerWidth ) == 'number' ) {
	    w = window.innerWidth;
	    h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    w = document.documentElement.clientWidth;
	    h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    w = document.body.clientWidth;
	    h = document.body.clientHeight;
	}
	// if body is bigger
	if(body.offsetHeight > h){
		h = body.offsetHeight;
	}
	return { width:w,height:h }
}

function elementSize(element){

    var element = $(element);
    var width, height;
    if (!is_ie) {
        width = element.offsetWidth;
        height = element.offsetHeight;
    } else {
        var e = element.style;
        width = parseInt(e.borderLeftWidth || 0) + parseInt(e.borderRightWidth || 0) + element.offsetWidth;
        height = parseInt(e.borderTopWidth || 0) + parseInt(e.borderBottomWidth || 0) + element.offsetHeight;
    }
    return {width:width, height:height};
}

var KeyE = {
	BACKSPACE: 8, TAB: 9, RETURN: 13, ESC: 27, LEFT: 37, UP: 38,
	RIGHT: 39, DOWN: 40, DELETE: 46, HOME: 36, END: 35, PAGEUP: 33, PAGEDOWN: 34
}

Number.prototype.NaN0 = function(){return isNaN(this)?0:this;}

Array.prototype.foreach = function(func) {
	if(typeof func == "function") {
		for(var i=0;i<this.length;i++) {
			func(this[i]);
		}
	}
}

Array.prototype.remove = function(e){
	for (var i in this){
		if ( this[i] == e )this.splice( i, 1 ); return;
	}
}

Array.prototype.replace = function(OldE, NewE){
    var i=this.indexOf(OldE);
    if (i!=-1) this.splice(i,1,NewE);
}

String.prototype.toDate = function (format){
    return this.toDateEx("/",":",format);
}
String.prototype.toLower= function (){
    return this.toLowerCase();
}

String.prototype.toUpper= function (){
    return this.toUpperCase();
}

try{
	Node.prototype.swapNode = function(node) {
		var nextSibling = this.nextSibling;
		var parentNode = this.parentNode;
			if(node.parentNode) node.parentNode.replaceChild(this, node);
		parentNode.insertBefore(node, nextSibling);
	};
}
catch(e){}

Object.extend = function(destination, source){
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

function remove(element) {
	element = $(element);
	element.parentNode.removeChild(element);
	return element;
}

function $E(element) {
	if (typeof element == 'string') {
		return document.createElement(element);
	}
}

function $(element){
	if (typeof element == 'object' || typeof element == 'function') {
		return element;
	} else if(typeof element == 'string') {
		return document.getElementById(element);
	}
}

function $Ga(element,attribute){
	var el = $(element);
	return el.getAttribute(attribute);
}

function GetChildren(element){
	var children = [];
	var child = element.firstChild;
	while (child){
		if (child.nodeType == 1)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
}

function $T(element){
	if (typeof element == 'string') {
		return document.getElementsByTagName(element);
	}
}

function AddEvent(element,eventType,handler,capture) {
	try {
		if (element.addEventListener) {
			element.addEventListener(eventType, handler, capture);
		}
		else if (element.attachEvent) {
			element.attachEvent('on' + eventType, handler);
		}
	}
	catch (e) {}
}

function RemoveEvent(obj,evt,fn) {

	if (obj.removeEventListener) {
		obj.removeEventListener(evt,fn,false);

	} else if (obj.detachEvent) {
		obj.detachEvent('on'+ evt,fn);
	}
}

function expiryDate(nodays){
	var UTCstring;
	Today = new Date;
	NoMilli = Date.parse(Today);
	Today.setTime(NoMilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setCookie(name, value, Duration) {
    CookieString = name + "=" + escape(value) + ";EXPIRES=" + expiryDate(Duration);
    document.cookie = CookieString;
}

function getCookie(CookieName) {
    var CookieString = "" + document.cookie;
    var index1 = CookieString.indexOf(CookieName);
    if (index1 == -1 || CookieName == "") {
        return "";
    }
    var index2 = CookieString.indexOf(";", index1);
    if (index2 == -1) {
        index2 = CookieString.length;
    }
    return unescape(CookieString.substring(index1 + CookieName.length + 1, index2));
}

function deleteCookie(name) {
    this.setCookie(name, "", -360);
}

function RandomLetter() {
    return String.fromCharCode(97 + Math.round(Math.random() * 25));
}

function RandomNumber() {
    return String(Math.floor(Math.random(10) * 11));
}

function elementPosition(e){
    var left = 0;
    var top = 0;
    while (e.offsetParent) {
        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);
        e = e.offsetParent;
    }

    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);
    top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

    return { x: left, y: top }

}

function mouseCoords(ev){
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY }
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    }
}

function getMouseOffset(target, ev){
    ev = ev || window.event;

    var docPos = elementPosition(target);
    var mousePos = mouseCoords(ev);
    return {
        x: mousePos.x - docPos.x,
        y: mousePos.y - docPos.y
    }
}

function ifthis(v,v1){
	if(v)return v;
	else return v1;
}

function wSize() {

    var w, h;

	if (is_ie) {
		w = (document.documentElement.offsetWidth + document.documentElement.scrollLeft) -21;
		h = (document.documentElement.offsetHeight + document.documentElement.scrollTop) + 10;
	} else {
		w = (window.innerWidth + document.body.scrollLeft) -17;
		h = (window.innerHeight + document.body.scrollTop) + 10;
	}
    return {width:w, height:h};
}

function fixPng(src){
	if (is_ie) {
		return 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + HTTP_PATH + src + ');background:none;';
	} else {
		return 'background:url('+ HTTP_PATH + src + ');';
	}
}
HTTP_PATH = "http://www.agendalugano.ch/";
if(!Ajax)var Ajax = Class();

Ajax.Request = function(url, options) {

	this.url = url;
	this.xhr = this.checkVersion();

	this.contentType = (options && options.contentType) ? options.contentType : "application/x-www-form-urlencoded";
	this.method = (options && options.method) ? options.method : false;
	this.params = (options && options.params) ? options.params : false;
	this.timeOut = (options && options.timeOut) ? options.timeOut : 200;

	if (options && options.targetid) {
		this.container = $(options.targetid);
		this.container.innerHTML = (options.wmsg) ? options.wmsg : '<img src="' + HTTP_PATH + 'images/loading.gif" />';
	}

	this.xhr.onreadystatechange = function(){ this.Reponse; }

	try {
		if(this.method == "post") {
			this.xhr.open('POST', this.url, false);
			this.xhr.setRequestHeader("Content-type", this.contentType);
			this.xhr.setRequestHeader("Content-length", this.params.length);
			this.xhr.setRequestHeader("Connection", "close");
			this.xhr.send(this.params);
		} else {
			this.xhr.open('GET', this.url, false);
			this.xhr.send(null);
		}
	} catch(l) {
		if (this.container) {
			while (this.container.firstChild) {
				this.container.removeChild(this.container.firstChild);
				this.container.appendChild(document.createTextNode("Errore"));
			}
		}
	}
}

Ajax.Request.prototype.checkVersion = function(){

	try {
		this.xhr = new XMLHttpRequest();
	} catch(e){

		var XMLHttp_versions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
					    		"MSXML2.XMLHttp","Microsoft.XMLHttp"];

		for (var i=0; i<XMLHttp_versions.length; i++) {
			try {
				this.xhr = new ActiveXObject(XMLHttp_versions[i]);
				}
			 catch(e){
			 		if(i == 5) {
						alert("Il tuo browser &egrave; obsoleto.");
				}
			}
		}
	}
	return this.xhr;
}

Ajax.Request.prototype.Reponse = function(){

	if (this.xhr.readyState != 4)return;

	var serverReponse = (this.xhr.status == 200 || this.xhr.status == 0)
						 ? this.xhr.responseText
						 : "Errore: " + this.xhr.status + " " + this.xhr.statusText;

	if (this.container) {
		var self = this;
		setTimeout(function(){
			self.container.innerHTML = serverReponse;
		}, this.timeOut);

	} else {
		return serverReponse;
	}
}

HTTP_PATH = "http://www.agendalugano.ch/";if(!Effects) var Effects = new Class();
if(!Effects.animation)Effects.animation = new Class();
if(!Effects.Opacity) Effects.Opacity = new Class();

Effects.animation = function(element, options){

	this.element = $(element);
	(this.animator) ? this.animator.stop() : null;
	(options.y) ? element.style.position = "absolute" : null;

	var nw = (options.x) ? options.x : options.width; // x or width
	var nh = (options.y) ? options.y : options.height; // y or height
	var cw = (options.x) ? elementPosition(this.element).x : elementSize(this.element).width; // original width / x
	var ch = (options.y) ? elementPosition(this.element).y : elementSize(this.element).height; // orginal height / y

	if (cw != nw || ch != nh) {
		var self = this;
		this.animator = new Effects.Animator(this.element, cw, ch, nw, nh, {
			method: (options.x || options.y) ? 'move' : 'resize',
			duration: options.duration
		});
		this.animator.start();
	}
}

Effects.Opacity = function(element, from, to, options){
	var options = (options) ? options : {};
	if (this.animator)
		this.animator.stop();
	if (from != to) {
		options.method = 'fade';
		this.animator = new Effects.Animator($(element), from, false, to, false, options);
		this.animator.start();
	}
}

Effects.Animator = function(element, curValueOne, curValueTwo, destValueOne, destValueTwo, options){

	this.element = element;
	this.curValueOne = curValueOne;
	this.curValueTwo = curValueTwo;
	this.destValueOne = destValueOne;
	this.destValueTwo = destValueTwo;
	this.fps = (options.fps)?options.fps:80;
	this.duration = (options.duration)?options.duration:1000;
	this.transition = this.defaultTransition;
	this.method = options.method;
	this.startTime = 0;
	this.timerID = 0;

	var self = this;
	this.intervalFunc = function() { self.step(); }
	this.interval = 1000 / this.fps;

}

Effects.Animator.prototype.defaultTransition = function(time, begin, finish, duration) {
	time /= duration; return begin + ((2 - time) * time * finish);
}

Effects.Animator.prototype.start = function(){
	this.stop();
	this.startTime = (new Date()).getTime();
	this.timerID = setTimeout(this.intervalFunc, this.interval);
}

Effects.Animator.prototype.stop = function(){
	if (this.timerID) clearTimeout(this.timerID);
	this.timerID = 0;
}

Effects.Animator.prototype.step = function(){

	var elapsedTime = (new Date()).getTime() - this.startTime;
	var done = elapsedTime >= this.duration;
	var x, y, opacity;

	if (done){
		x = this.curValueOne = this.destValueOne;
		y = this.curValueTwo = this.destValueTwo;
	} else {
		x = this.transition(elapsedTime, this.curValueOne, this.destValueOne - this.curValueOne, this.duration);
		y = this.transition(elapsedTime, this.curValueTwo, this.destValueTwo - this.curValueTwo, this.duration);
	}

	if(this.method == 'fade'){
		if (done){
			opacity = this.curValueOne = this.destValueOne;
		}else{
			opacity = this.transition(elapsedTime, this.curValueOne, this.destValueOne - this.curValueOne, this.duration);
		}
		new Effects.setOpacity(this.element,opacity);
	} else {
		eval('this.element.style.' + ((this.method == 'move') ? 'left' : 'width') + ' ="' + x + 'px";');
		eval('this.element.style.' + ((this.method == 'move') ? 'top' : 'height') + ' ="' + y + 'px";');
	}

	if (!done) {
		this.timerID = setTimeout(this.intervalFunc, this.interval);
	} else {
		if (this.finish) this.finish();
	}
}

Effects.setOpacity = function(obj,opacity) {
	var obj = $(obj).style;
	    obj.opacity = (opacity / 100);
	    obj.filter = "alpha(opacity=" + opacity + ")";
}

Effects.getOpacity = function(el) {
	this.element = $(el);
	if(is_ie){
		var x = this.element.style.filter.split('=');
		this.opacity = (parseInt(x[1]))?(parseInt(x[1])):100;
	}else{
		this.opacity = (this.element.style.opacity)?((this.element.style.opacity) * 100):100;
	}
	return this.opacity;
}

Effects.FadeIn = function(element,duration,options){
	new Effects.Opacity(element,0,100,options)
}

Effects.FadeOut = function(element,duration,options){
	new Effects.Opacity(element,100,0,options);
}

HTTP_PATH = "http://www.agendalugano.ch/";
var calendar = function(options){
	this.init(options);
	this.nextMonth(); //holy hack
	this.precMonth(); //holy hack
}

calendar.prototype.init = function (options){

	this.monthLongArray = ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'];
	this.monthArray = ['Gen','Feb','Mar','Apr','Mag','Giu','Lugl','Ago','Set','Ott','Nov','Dic'];
	this.dayLongNames = ['Luned&igrave;','Marted&igrave;','Mercold&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica'];
	this.monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	this.dayNames = ['Lu','Ma','Me','Gi','Ve','Sa','Do'];
	this.year = options.year;
	this.month = options.month;
	this.callback = options.callback;
	this.events = (options.events)?options.events:false;
	this.cnt = $(options.cnt);
	this.calendarCnt = $E('div');
	this.n = "\n";
	this.column = 0;

	this.fillCalendar();
	this.listener()

}

calendar.prototype.listener = function(){
	var self = this;
	AddEvent($('backMonth'),'click',function(){
		self.precMonth();
	});
	AddEvent($('nextMonth'),'click',function(){
		self.nextMonth();
	});
}

calendar.prototype.fillCalendar = function(){

	this.firstDay = new Date(this.year,this.month,1);
	var startDay = this.firstDay.getDay() == 0 ? 7 : this.firstDay.getDay();

	if (((this.year % 4 == 0) && (this.year % 100 != 0)) || (this.year % 400 == 0)) {
		this.monthDays[1] = 29;
	}
	this.today     = new Date();
	this.thisDay   = this.today.getDate();
	this.thisMonth = this.today.getMonth();
	this.thisYear  = this.tonYear(this.today.getYear());

	this.html =  '<table cellspacing="0" cellpadding="0">' + this.n;
	this.html += '<tr>' + this.n +
				 '<td><div id="backMonth" title="Indietro"></div></td>' +
				 '<td style="text-align:center;width:180px; color: #FFF;"><strong>' + this.monthLongArray[this.month] + ' - ' + this.year + '</strong></td>' +
				 '<td><div id="nextMonth" title="Avanti"></div></td>' +
				 '</tr>' + this.n +
				 '</table>'

	for (var i = 0; i < 7; i++) {
		this.html += '<div class="daysNames">' + this.dayNames[i] + '</div>' + this.n;
	}

	if (this.lastMonth == -1) {
		this.lastMonth = 11;
	} else {
		this.lastMonth = this.month - 1;
	}

	for (var i = 1; i < startDay; i++) {
		this.html += '<div class="days_outOfMonth">&nbsp;</div>';
		this.column++;
	}

	var thisDouble = {id:null,rank:null};

	for (var i = 1; i <= this.monthDays[this.month]; i++) {

		for (var e = 0; e < this.events.length; e++) {

			if ((i == this.events[e].day) && (this.month == this.events[e].month) && (this.year == this.events[e].year)) {

				if (thisDouble.day != this.events[e].day) {
					this.html += '<div class="eventDay" style="background-color:#' + this.events[e].catColor + ';" title="' + i + ' ' + this.monthLongArray[this.month] + ' ' + this.year +
					'" alt="' + i + ' ' + this.monthLongArray[this.month] + ' ' + this.year +
					'"><a href="javascript:void(0)" onclick="' + this.callback + '(\'' + (this.year +'-'+ (((this.month +1) <= 9)?('0'+(this.month + 1)):(this.month + 1)) +'-'+ ((this.events[e].day <= 9)? '0'+this.events[e].day:this.events[e].day)) +'\');">' +
					i + '</a></div>' + this.n;
					thisDouble.day = i;
				}

			}

		}
		if (i != thisDouble.day) {
			if ((i == this.thisDay) && (this.month == this.thisMonth) && (this.year == this.thisYear)) {
				this.html += '<div class="currentDay">' + i + '</div>' + this.n;
			} else {
				this.html += '<div class="days">' + i + '</div>' + this.n;
			}
		}

		this.column = this.column == 7 ? 0 : this.column;
		this.column++;
	}

	this.html += '<div class="cl"></div>';
	this.calendarCnt.innerHTML = this.html;
	this.cnt.appendChild(this.calendarCnt);
	this.listener();
}

calendar.prototype.nextMonth = function(){

	if (this.month == 11) {
		this.year++;
		this.month = 0;
		this.fillCalendar();
	} else {
		this.month++;
		this.fillCalendar();
	}

}

calendar.prototype.precMonth = function(){
	if (this.month == 0) {
		this.year--;
		this.month = 11;
		this.fillCalendar();
	} else {
		this.month--;
		this.fillCalendar();
	}
}

calendar.prototype.tonYear = function(n){
  return (n < 1000) ? n + 1900 : n;
}

HTTP_PATH = "http://www.agendalugano.ch/";
if (!Widget) var Widget = new Class();

Widget.roundCorners = function(){

	if (arguments.length > 1) {
		for (var i = 0; i<arguments.length; i++) {
			this.create(arguments[i]);
		}
	} else {
		this.create(arguments[0]);
	}

}

Widget.roundCorners.prototype.create = function(cnt){

	this.container = $(cnt);
	this.container.style.position = "relative";

	this.topLeft = $E("div");
	this.topRight = $E("div");
	this.bottomLeft = $E("div");
	this.bottomRight = $E("div");

	this.topLeft.className = "topLeft";
	this.topRight.className = "topRight";
	this.bottomLeft.className = "bottomLeft";
	this.bottomRight.className = "bottomRight";

	this.container.appendChild(this.topLeft);
	this.container.appendChild(this.topRight);
	this.container.appendChild(this.bottomLeft);
	this.container.appendChild(this.bottomRight);

}

/* PopUp window */

Widget.popup = function(options){

	this.doc = document.body;

	this.wantsBlur = (options.blur) ? false : true;
	this.src = (options.src) ? options.src : false;
	this.innerCnt = (options.content) ? options.content : false;
	this.popupWidth = options.width;
	this.popupHeight = options.height;
	this.popupTitle = options.title;
	this.headHeight = (options.headHeight)?options.headHeight:30;
	this.build();
}

Widget.popup.prototype.build = function(){

	(this.wantsBlur)? this.buildBlur() : '';
	var self = this;
	setTimeout(function(){self.buildContent();},160);
}

Widget.popup.prototype.buildBlur = function(){

	this.blur = $E('div');
	this.blur.id = 'popupBlur';
	this.blur.style.cssText = "position:absolute;background-color:#000;top:0;left:0;bottom:0;right:0;z-index:100;" +
							  "width:" + (wSize().width) + "px;" + "height:" + (wSize().height) + "px;";
	new Effects.setOpacity(this.blur,0);
	this.doc.appendChild(this.blur);
	new Effects.Opacity(this.blur,0,60,{duration:50});
}

Widget.popup.prototype.fixPng = function(src){
	if (is_ie) {
		return 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + HTTP_PATH + src + ');background:none;';
	} else {
		return 'background:url('+ HTTP_PATH + src + ');';
	}
}

Widget.popup.prototype.buildContent = function(){

	this.popup = $E('div');
	this.header = $E('div');
	this.content = $E('div');
	this.content.id = 'popUpContent';
	this.footer = $E('div');

	this.header.style.cssText = "width:100%;height:30px;border-bottom:1px solid #CCC6AE;float:left;z-index:101;";
	this.header.innerHTML = '<div style="'+ fixPng('images/popups/left_top_r.png') + ';' +
							'height:30px;width:7px;float:left;"></div><div style="height:' + ((is_ie)?30:29) +'px;background:#F5F5EB;' +
							'width:' + (this.popupWidth - 14) + 'px;border-top:1px solid #CCC6AE;float:left;">' +
							'<div style="padding:6px 0 0 0;font-weight:bold;text-indent:10px;color:#666;position:relative;">' + this.popupTitle +
							'<a id="popupsCloseBtn" class="closeBtn" href="javascript:void(0)">&nbsp;</a></div>' +
							'</div><div style="' + fixPng('images/popups/right_top_r.png') + ';' +
							'height:30px;width:7px;float:left;"></div>';

	this.content.style.cssText = "z-index:101;float:left;width:" + (this.popupWidth + ((is_ie)?0:-2)) + "px;border-right:1px solid #CCC6AE;border-left:1px solid #CCC6AE;background:#fafafa;";
	this.content.innerHTML  = 	 (this.src) ? ('<iframe frameborder="0" scrolling="auto" style="float:left;width:' + (this.popupWidth - 4) +
										  	  'px;height:' + (this.popupHeight - (this.headHeight + 1)) +
										  	  'px;" id="pFrame" src="' + this.src + '"></iframe>')
											: '<div style="padding:10px;>' + this.innerCnt + '</div>';

	this.footer.style.cssText = "width:100%;height:7px;float:left;z-index:101;";
	this.footer.innerHTML = '<div style="'+ fixPng('images/popups/left_bottom_r.png') + ';height:7px;width:7px;float:left;"></div>' +
							'<div style="background:#fafafa;height:6px;border-bottom:1px solid #CCC6AE;float:left;width:' + (this.popupWidth - 14) + 'px"></div>' +
							'<div style="' + fixPng('images/popups/right_bottom_r.png') + ';' + 'height:7px;width:7px;float:left;"></div>';

	this.popup.appendChild(this.header);
	this.popup.appendChild(this.content);
	this.popup.appendChild(this.footer);

	this.doc.appendChild(this.popup);

	// Ie is alway a strange things, so we add style after append the child
	this.popup.id = 'popupContent';
	this.popup.setAttribute("dragObj","0");
	this.popup.style.cssText =  "position:absolute;top:" + ((wSize().height / 2) - (this.popupHeight / 2)) + "px;" +
								"left:" + ((wSize().width / 2) - (this.popupWidth / 2)) + "px;" +
								"width:" + this.popupWidth + "px;height:" + this.popupHeight + "px;z-index:101;";

	var self = this;

	AddEvent($('popupsCloseBtn'),'click',function(){self.remove();});

	AddEvent(window,'resize',function(){

		(!this.wantsBlur)?self.blur.style.cssText = "position:absolute;background-color:#000;top:0;left:0;bottom:0;right:0;z-index:1000;" +
								  "width:" + (wSize().width) + "px;" + "height:" +
								  (wSize().height) + "px;":'';

		new Effects.setOpacity(self.blur,20);

		self.popup.style.cssText =  "position:absolute;top:" + ((wSize().height / 2) - (self.popupHeight / 2)) + "px;" +
									"left:" + ((wSize().width / 2) - (self.popupWidth / 2)) + "px;z-index:1001;" +
									"width:" + self.popupWidth + "px;" + "height:" + self.popupHeight + "px;";
	});
}

Widget.popup.prototype.remove = function(){
	(this.wantsBlur)?this.doc.removeChild(this.blur):'';
	this.doc.removeChild(this.popup);
}

var selectBox = function(opt){

	this.cnt = $(opt.cnt);
	this.visible = false;

	this.selectCnt = $E('div');
	this.selectCnt.className = "selectBox";
	this.selectCnt.id = opt.nameId + '_selectCnt';

	this.valueCnt = $E('div');
	this.valueCnt.className = "valueBox";
	this.valueCnt.id = opt.nameId + '_valueCnt';
	this.valueCnt.innerHTML = (((opt.defaultValue)?((opt.defaultValue).substr(0,7) + '...'):opt.defaultValue));

	this.optionsCnt = $E('div');
	this.optionsCnt.className = "optionsCnt";

	for (var i = 0; i < opt.options.length; i++) {

		this.optionsLine = $E('a');
		this.optionsLine.innerHTML = opt.options[i].name;
		this.optionsLine.setAttribute("href","javascript:" + opt.callback + opt.options[i].value + "');");
		this.optionsLine.setAttribute("onclick","$('" + this.valueCnt.id + "').innerHTML = '" +
									 (((opt.options[i].name.length > 8)?((opt.options[i].name).substr(0,7) + '...'):opt.options[i].name)) + "';");

		this.optionsCnt.appendChild(this.optionsLine);
	}

	this.selectCnt.appendChild(this.valueCnt);
	this.selectCnt.appendChild(this.optionsCnt);
	this.cnt.appendChild(this.selectCnt);

	var self = this;

	AddEvent(this.valueCnt,'click',function(){
		setTimeout(function(){
			if(!self.visible){ d = 'block'; self.visible = true; } else { d= 'none'; self.visible = false; }
			self.optionsCnt.style.display = d;
		},50);
	});

	AddEvent(this.selectCnt,'blur',function(){
		self.optionsCnt.style.display = 'none';
	});
}

var colorPalette = function(cnt){

	var colors = ['#000000','#000000','#000000','#000000','#003300','#006600','#009900','#00cc00',
				  '#00ff00','#330000','#333300','#336600','#339900','#33cc00','#33ff00','#660000',
				  '#663300','#666600','#669900','#66cc00','#66ff00','#000000','#333333','#000000',
				  '#000033','#003333','#006633','#009933','#00cc33','#00ff33','#330033','#333333',
				  '#336633','#339933','#33cc33','#33ff33','#660033','#663333','#666633','#669933',
				  '#66cc33','#66ff33','#000000','#666666','#000000','#000066','#003366','#006666',
				  '#009966','#00cc66','#00ff66','#330066','#333366','#336666','#339966','#33cc66',
				  '#33ff66','#660066','#663366','#666666','#669966','#66cc66','#66ff66','#000000',
				  '#999999','#000000','#000099','#003399','#006699','#009999','#00cc99','#00ff99',
				  '#330099','#333399','#336699','#339999','#33cc99','#33ff99','#660099','#663399',
				  '#666699','#669999','#66cc99','#66ff99','#000000','#cccccc','#000000','#0000cc',
				  '#0033cc','#0066cc','#0099cc','#00cccc','#00ffcc','#3300cc','#3333cc','#3366cc',
				  '#3399cc','#33cccc','#33ffcc','#6600cc','#6633cc','#6666cc','#6699cc','#66cccc',
				  '#66ffcc','#000000','#ffffff','#000000','#0000ff','#0033ff','#0066ff','#0099ff',
				  '#00ccff','#00ffff','#3300ff','#3333ff','#3366ff','#3399ff','#33ccff','#33ffff',
				  '#6600ff','#6633ff','#6666ff','#6699ff','#66ccff','#66ffff','#000000','#ff0000',
				  '#000000','#990000','#993300','#996600','#999900','#99cc00','#99ff00','#cc0000',
				  '#cc3300','#cc6600','#cc9900','#cccc00','#ccff00','#ff0000','#ff3300','#ff6600',
				  '#ff9900','#ffcc00','#ffff00','#000000','#00ff00','#000000','#990033','#993333',
				  '#996633','#999933','#99cc33','#99ff33','#cc0033','#cc3333','#cc6633','#cc9933',
				  '#cccc33','#ccff33','#ff0033','#ff3333','#ff6633','#ff9933','#ffcc33','#ffff33',
				  '#000000','#0000ff','#000000','#990066','#993366','#996666','#999966','#99cc66',
				  '#99ff66','#cc0066','#cc3366','#cc6666','#cc9966','#cccc66','#ccff66','#ff0066',
				  '#ff3366','#ff6666','#ff9966','#ffcc66','#ffff66','#000000','#ffff00','#000000',
				  '#990099','#993399','#996699','#999999','#99cc99','#99ff99','#cc0099','#cc3399',
				  '#cc6699','#cc9999','#cccc99','#ccff99','#ff0099','#ff3399','#ff6699','#ff9999',
				  '#ffcc99','#ffff99','#000000','#00ffff','#000000','#9900cc','#9933cc','#9966cc',
				  '#9999cc','#99cccc','#99ffcc','#cc00cc','#cc33cc','#cc66cc','#cc99cc','#cccccc',
				  '#ccffcc','#ff00cc','#ff33cc','#ff66cc','#ff99cc','#ffcccc','#ffffcc','#000000',
				  '#ff00ff','#000000','#9900ff','#9933ff','#9966ff','#9999ff','#99ccff','#99ffff',
				  '#cc00ff','#cc33ff','#cc66ff','#cc99ff','#ccccff','#ccffff','#ff00ff','#ff33ff',
				  '#ff66ff','#ff99ff','#ffccff','#ffffff'];

	var cols = 0;
	var table = '<div id="colorPaletteCnt"><div class="row">';

	for (var i = 0; i < colors.length; i++) {
		if (cols == 21) {
			table += '</div><div class="row">' + "\n";
			cols = 0;
		}
		table += '<a style="background-color:' + colors[i] + ';" href="javascript:put(\'' + colors[i] + '\');" onmouseover="displayColor(\''+ colors[i] + '\')"></a>';
		cols++;
	}
	table += '</div></div>';

	$(cnt).innerHTML = table;

}

// sysOut : string => void
// takes a message and display it by using a moving layer (from top to bottom).

var sysOut = function(options){

	this.height = options.height;
	this.container = $E('div');
	this.content = $E('div');
	this.inner = $E('div');
	this.footer = $E('div');

	this.container.style.cssText = "position:absolute;top:-"+(this.height+10)+"px;width:400px;height:"+this.height+"px;left:"+ (((document.documentElement.clientWidth) / 2) - 200) + "px;";
	this.inner.style.cssText = "position:relative;width:100%;height:100%;float:left;padding-bottom:7px;";

	this.content.style.cssText = "z-index:101;float:left;width:100%;height:100%;border-right:1px solid #efefef;border-left:1px solid #efefef;background:#fff;";
	this.content.innerHTML = '<div style="padding:5px 10px 10px 10px;text-align:center;font-size:14px;"><img style="float:left;margin:0 0 0px 20px;" src="images/alert-icon.jpg"'+
							 ' /><div style="padding:10px 5px;color:#666;">' + options.msg + '</div></div>';

	this.footer.style.cssText = "height:10px;float:left;position:absolute;bottom:0;";
	this.footer.innerHTML = '<div style="'+ fixPng('images/popups/left_bottom_r.png') + ';height:7px;width:7px;float:left;"></div>' +
							'<div style="height:9px;border-bottom:1px solid #efefef;float:left;width:386px"></div>' +
							'<div style="' + fixPng('images/popups/right_bottom_r.png') + ';' + 'height:7px;width:7px;float:left;"></div>' +
							'<div style="clear:both;"></div>';

	this.inner.appendChild(this.content);
	this.inner.appendChild(this.footer);
	this.container.appendChild(this.inner);

	document.body.appendChild(this.container);

	window.top;
	this.move('down');
	var self = this;
	setTimeout(function(){self.move('up')},2000);
}

sysOut.prototype.move = function(direction){

	var self = this;
	var pos = parseInt(self.container.style.top);
	var i = 0;

	switch(direction){

		case 'up':
		stopPoint = "(pos + i) < " + (this.height + 10);
		relop = "-";
		break;

		case 'down':
		stopPoint = "(pos + i) < 0";
		relop = "+";
		break;

	}

	var move = setInterval(function(){
		if (eval(stopPoint)) {
			i = i + 5;
			self.container.style.top = eval("(pos "+relop+"  i)") + "px";
		} else {
			clearInterval(move);
			if (direction == 'up') {
				document.body.removeChild(self.container);
			}
		}
	}, 10);

}

HTTP_PATH = "http://www.agendalugano.ch/";