Index: trunk/expressoCalendar/js/calendar_functions.js
===================================================================
--- trunk/expressoCalendar/js/calendar_functions.js	(revision 665)
+++ trunk/expressoCalendar/js/calendar_functions.js	(revision 696)
@@ -10,4 +10,6 @@
 	this.previousView;
 	this.uid = calUid;
+	this.cat = '';
+	this.currentTime = new Date();
 }
 
@@ -73,6 +75,18 @@
 
 }
-Calendar.prototype.getView = function(idEl, type, data)
+Calendar.prototype.getView = function(idEl, type, viewTime)
 {
+	if (typeof(type) == 'undefined')
+		return false;
+	if (typeof(viewTime) == 'undefined')
+		viewTime = calendar.currentTime.getTime();
+	if (type == 'Year'){
+		var handler = function (data) {
+			var div_main = document.getElementById('div_main');
+			div_main.innerHTML = data;
+		}
+		cExecute('../index.php?menuaction=calendar.uicalendar.year&plain=True',handler);
+		return;
+	}
 	this.idEl = idEl;
 	var _this = this;
@@ -82,29 +96,29 @@
 	{
 			_this.parseView(XMLdata,type);
-
+			calendar.currentTime.setTime(id2timeStamp(document.getElementById('day').firstChild.id));
+			var dayMS = (60*60*24*1000);
 			if (viewType == "Week"){
-				var Today = new Date;
-				Today.setTime(id2timeStamp(document.getElementById('day').firstChild.id));
-				var lastWeek = new Date;
-				lastWeek.setTime(Today.getTime()-(60*60*24*7*1000));
-				this.previousView = (lastWeek.getYear()+1900)+normDec(lastWeek.getDate()-7)+normDec(lastWeek.getMonth()+1);
-				Today.setTime(Today.getTime()+(60*60*24*8*1000));
-				this.nextView = (Today.getYear()+1900)+normDec(Today.getDate())+normDec(Today.getMonth()+1);
+				var previousWeek = new Date;
+				previousWeek.setTime(calendar.currentTime.getTime()-(dayMS*7));
+				this.previousView = previousWeek.getTime();
+				var nextWeek = new Date;
+				nextWeek.setTime(calendar.currentTime.getTime()+(dayMS*8));
+				this.nextView =	nextWeek.getTime();
 			}
 			if (viewType == "Day"){
-				var Today = new Date;
-				Today.setTime(id2timeStamp(document.getElementById('day').firstChild.id));
-				this.previousView = (Today.getYear()+1900)+normDec(Today.getDate()-1)+normDec(Today.getMonth()+1);
-				Today.setDate(Today.getDate()+1);
-				this.nextView = (Today.getYear()+1900)+normDec(Today.getDate())+normDec(Today.getMonth()+1);
+				this.previousView = calendar.currentTime.getTime()-dayMS;
+				this.nextView = calendar.currentTime.getTime()+dayMS;
 			}
 			if (viewType == 'Month'){
-				var Today = new Date;
-				Today.setTime(id2timeStamp(document.getElementById('day').firstChild.id));
-				this.previousView = (Today.getYear()+1900)+normDec(Today.getDate())+normDec(Today.getMonth());
-				Today.setMonth(Today.getMonth()+1);
-				this.nextView = (Today.getYear()+1900)+normDec(Today.getDate())+normDec(Today.getMonth()+1);
+				var previousMonth = new Date;
+				previousMonth.setTime(calendar.currentTime.getTime());
+				previousMonth.setMonth(calendar.currentTime.getMonth()-1);
+				this.previousView = previousMonth.getTime();
+				var nextMonth = new Date;
+                                nextMonth.setTime(calendar.currentTime.getTime());
+				nextMonth.setMonth(calendar.currentTime.getMonth()+1);
+				this.nextView = nextMonth.getTime();
 			}
-			document.getElementById("l_date").innerHTML =  "<a href=\"javascript:calendar.getView('div_main','"+viewType+"','&time='+this.previousView);\">\<\<&nbsp;</a>";
+			document.getElementById("l_date").innerHTML =  "<a href=\"javascript:calendar.getView('div_main','"+viewType+"',this.previousView);\">\<\<&nbsp;</a>";
 			if (viewType == "Week")
 				document.getElementById("l_date").innerHTML += calendar.parseWeek(id2timeStamp(document.getElementById('day').firstChild.id));
@@ -113,5 +127,5 @@
 			if (viewType == "Month")
 				document.getElementById("l_date").innerHTML += calendar.parseMonth(id2timeStamp(document.getElementById('day').firstChild.id));
-			document.getElementById("l_date").innerHTML += "<a href=\"javascript:calendar.getView('div_main','"+viewType+"','&time='+this.nextView);\">&nbsp;\>\></a>";
+			document.getElementById("l_date").innerHTML += "<a href=\"javascript:calendar.getView('div_main','"+viewType+"',this.nextView);\">&nbsp;\>\></a>";
 
 		var getEventsDay = function (data)
@@ -125,5 +139,5 @@
 		}
 	        XMLTools.__RETURN_MODE__ = 'XML';
-		XMLTools.request('$this.uicalendar.getEvents'+type+(data?data:'')+'&uid='+calendar.uid, 'GET', getEventsDay);
+		XMLTools.request('$this.uicalendar.getEvents'+type+"&time="+timeStamp2id(calendar.currentTime.getTime())+'&uid='+calendar.uid+'&cat='+calendar.cat, 'GET', getEventsDay);
 
 	};
@@ -132,6 +146,6 @@
 	viewType = type;
 	screenTable = new Array();
-	XMLTools.request('$this.uicalendar.getView'+type+(data?data:'')+'&uid='+this.uid, 'GET', handler_getView);  
-};
+	XMLTools.request('$this.uicalendar.getView'+type+"&time="+timeStamp2id(viewTime)+'&uid='+this.uid, 'GET', handler_getView);
+	};
 
 Calendar.prototype.resetView = function()
@@ -312,7 +326,6 @@
 		eventDiv.onmouseover = function () { this.style.height = "auto"; this.style.zIndex = 2;};
 		eventDiv.onmouseout = function () { this.style.height = "20px"; this.style.zIndex = 1; };
-		eventDiv.onclick = function () { calendar.getView('div_main','Day','&time='+timeStamp2id(eventDiv.childNodes[1].id).substr(0,8)); };
-	}
-
+		eventDiv.onclick = function () { calendar.getView('div_main','Day',eventDiv.childNodes[1].id); };
+	}
 	var tdElement = document.getElementById(timeStamp2id(eventDiv.childNodes[0].id));
 
@@ -323,5 +336,5 @@
 		eventDiv.onmouseover = function () { if (this.childNodes[2].length > 9) this.style.width = "auto"; this.style.zIndex = 2; };
 		eventDiv.onmouseout = function () { this.style.width = "60px"; this.style.zIndex = 1; };
-		eventDiv.onclick = function () { calendar.getView('div_main','Day','&time='+timeStamp2id(eventDiv.childNodes[1].id).substr(0,8)); };
+		eventDiv.onclick = function () { calendar.getView('div_main','Day',eventDiv.childNodes[1].id); };
 		eventDiv.style.cursor = "pointer";
 
@@ -333,8 +346,34 @@
 			eventDiv.style.margin = "0 0 0 "+(20+(tdElement.childNodes.length-1)*25);
 	}
-
-	eventDiv.style.top  =  (tdElement.offsetTop + 160) + "px";
-	tdElement.appendChild(eventDiv);
-}
-
-
+	if (tdElement == null)
+	{
+		orphan_table = document.getElementById('orphan_table');
+		if (!orphan_table)
+		{
+			orphan_table = document.createElement('table');
+			orphan_table.id = "orphan_table";
+			orphan_table.className = "table_common";
+			orphan_table.innerHTML = "<tbody></tbody>";
+			document.getElementById('div_main').appendChild(orphan_table);
+
+		}
+		tr_el = document.createElement('TR');
+		td_el = document.createElement('TD');
+		td_el.className = "td_header";
+		td_el.innerHTML = get_lang("Out of table preferences");
+		tr_el.appendChild(td_el);
+		td_el = document.createElement('TD');
+		td_el.className = "td_common";
+		tr_el.appendChild(td_el);
+		eventDiv.style.position = "relative";
+		td_el.appendChild(eventDiv);
+		orphan_table.firstChild.appendChild(tr_el);
+	}
+	else
+	{
+		eventDiv.style.top  =  (tdElement.offsetTop + 160) + "px";
+		tdElement.appendChild(eventDiv);
+	}
+}
+
+
