var RightContext = {TYPE_MENU: 0,TYPE_TEXT: 1,TYPE_TEXT_EXT: 2,TYPE_SEPERATOR:3,TYPE_ATTRIBUTES:4,browser: null,menuTriggerEvent: "MOVE",mousePos: {x:0, y:0},rightOffset: 5,killMenuTimeout: 25, allowedContexts: ["a","div","span","strong"],menuCollection: new Object(),contextMenu: null,isShowing: false,abortKill: false,images: new Object(),req: null,initialize: function () {this.browser = RightContext.detectBrowser();this.attachContextEvents();   },addMenu: function (n, m) { this.menuCollection[n] = m;},getMenu: function (n) {return this.menuCollection[n];},attachContextEvents: function () {var tagContext, thisTag;for (var t=0; t<this.allowedContexts.length; t++) {tags = document.getElementsByTagName(this.allowedContexts[t]);for (e=0; e<tags.length; e++) {thisTag = tags[e];tagContext = thisTag.getAttribute("context");if (tagContext!=null && tagContext != "undefined") {this.bindEvent('mousemove', tags[e], function(e) { return RightContext.locateMousePos(e); });if (this.menuTriggerEvent=="RIGHT") {tags[e].oncontextmenu = function() {   return RightContext.render(this);   }; } else if (this.menuTriggerEvent=="LEFT") {tags[e].onclick = function(e) { RightContext.killBubble(e); return RightContext.render(this)};tags[e].onmouseout = function(e) { setTimeout("RightContext.killMenu()", 5000);};} else if (this.menuTriggerEvent=="MOVE") {if (!document.all) {this.bindEvent('mouseover', tags[e], function(e) { RightContext.locateMousePos(e); return RightContext.render(this); });this.bindEvent('mouseout',  tags[e], function(e) { setTimeout("RightContext.killMenu()", RightContext.killMenuTimeout); });} else {tags[e].onmouseover =  function(e) { RightContext.locateMousePos(e); return RightContext.render(this); };tags[e].onmouseout = function(e) { setTimeout("RightContext.killMenu()", RightContext.killMenuTimeout); };}}}}}},killBubble: function(e) {if (!e) var e = window.event;e.cancelBubble = true;if (e.stopPropagation) e.stopPropagation();},bindEvent: function (evt, obj, act, bubble) {if (!bubble) bubble = false;if (obj.addEventListener) {obj.addEventListener(evt, act, bubble);} else if (obj.attachEvent) {obj.attachEvent('on'+evt, act);}},render: function (caller, name) {var url, title;var name = name || caller.getAttribute("context");var thisMenu = this.getMenu(name);var attributes = thisMenu["attributes"].split(',');   var items = thisMenu.items;var objMap = this.buildAttributeMap(attributes, caller);this.killMenu();this.buildMenu(caller);tbl = document.createElement("TABLE");tbl.id = "rcRightContextTable";for (var m=0; m<items.length; m++) {switch (items[m]["type"]) {case this.TYPE_MENU:if (this.isDisplayed(items[m], objMap)) {this.addMenuItem(items[m], objMap, tbl);}break;case this.TYPE_TEXT:text = this.transform(items[m]["text"], objMap);cell = this.addTableCell(tbl, "rcMenuItemText", text);break;case this.TYPE_TEXT_EXT:cell = this.addTableCell(tbl, "rcMenuItemTextExt");url = this.transform(items[m]["url"], objMap);this.request(url, function() { if (RightContext.req.readyState == 4 && RightContext.req.status == 200) { cell.innerHTML = RightContext.req.responseText } });break;case this.TYPE_SEPERATOR:cell = this.addTableCell(tbl);cell.appendChild(this.getSeparator());break;default:break;}}this.contextMenu.appendChild(tbl);this.repositionMenu();if (this.menuTriggerEvent=="MOVE") {this.bindEvent('mouseout',  this.contextMenu, function(e) { RightContext.abortKill = false; setTimeout("RightContext.killMenu()", RightContext.killMenuTimeout); });this.bindEvent('mouseover', this.contextMenu, function(e) { RightContext.abortKill = true;  });} else if (this.menuTriggerEvent=="LEFT" || this.menuTriggerEvent=="RIGHT") {this.bindEvent('click', document.body, function(e) { setTimeout("RightContext.killMenu();", RightContext.killMenuTimeout); }, false);} this.isShowing = true;return false;},isDisplayed : function(item, objMap) {var reqVar, reqVal;var shown = true;if (item["requires"] != null && item["requires"] != "undefined") {reqVar = item["requires"][0];reqVal = item["requires"][1];if (objMap[reqVar] != null && objMap[reqVar] != "undefined") {if (objMap[reqVar] != reqVal) {shown = false;    }} else {shown = false;}}return shown;},repositionMenu: function() {var mPos = this.findPosition(this.contextMenu);var mDim = this.getDimensions(this.contextMenu);var winHeight = this.getWindowHeight();  var winWidth = window.innerWidth || document.body.clientWidth;if (mPos.y + mDim.height > winHeight-30 ) {this.position(this.contextMenu, mPos.x, mPos.y - mDim.height);mPos = this.findPosition(this.contextMenu);} if (mPos.x + mDim.width > winWidth - 30 ) {this.position(this.contextMenu, mPos.x-mDim.width, mPos.y);} },getSeparator: function () {var sep = document.createElement("HR");sep.className = "rcMenuSeparator";return sep;},addTableCell: function (table, className, content) {row = table.insertRow(-1);cell = row.insertCell(0);if (className) { cell.className = className;if (content) {cell.innerHTML = content;}}return cell;},addMenuItem: function (item, objMap, tbl) {var title = this.transform(item["text"], objMap);if (title != "undefined" && title != ""){var url, frame, img, imgAlign, itemSrc, tmp, itemAction; var cell = this.addTableCell(tbl, "rcMenuItem", title); cell.style.cursor = document.all?'hand':'pointer';this.bindEvent('mouseover', cell, function(e) { cell.className="rcMenuItemHover";});this.bindEvent('mouseout',  cell, function(e) { cell.className="rcMenuItem";     });if (item["image"]!=null && item["image"]!="undefined") {imgAlign = (item["align"]!=null && item["align"]!="undefined") ? item["align"] : "absmiddle";if (this.images[item["image"]] != null && this.images[item["image"]] != "undefined") {img = this.images[item["image"]];} else {img = this.loadImage(item["image"]);}img.align=imgAlign;cell.insertBefore(this.images[item["image"]], cell.childNodes[0]);}if (item["url"]!=null && item["url"] != "undefined") {url   = this.transform(item["url"],  objMap);frame = false;if (item["frame"] != null && item["frame"] != "undefined") {frame = item["frame"];}cell.onclick = function () { RightContext.redirect(url, frame); }} else {itemAction = item["onclick"]; try {itemSrc = item["onclick"].toString();if (itemSrc.indexOf('[')>-1) {itemSrc = this.transform(itemSrc, objMap);eval('itemAction = ' + itemSrc);}} catch (e) {}cell.onclick=itemAction;}}},transform: function (str, map) {var tStr, tmp;tStr = str;for (p in map) {tmp = "[" + p + "]";while (tStr.indexOf(tmp) > -1) {tStr = tStr.replace(tmp, map[p]);}}return tStr;},getMenuAttributeArray: function (menu) {for (var i=0; i<menu.length; i++) {if (menu[i].type == this.TYPE_ATTRIBUTES) {return menu[i]["attributes"].split(',');}}return new Array(0);},buildAttributeMap: function (attribs, obj) {var thisAttr, thisValue;var attrMap = new Object();for (var a=0; a<attribs.length; a++) {thisAttr = attribs[a];thisValue = obj.getAttribute(attribs[a]);if (typeof thisValue != "undefined") {attrMap[thisAttr] = thisValue;}}return attrMap;},findPosition: function (obj) {var lft = 0;var top = 0;if (obj.offsetParent) {lft = obj.offsetLeft;top = obj.offsetTop;while (obj = obj.offsetParent) {lft += obj.offsetLeft;top += obj.offsetTop;}}return {x:lft,y:top};},getWindowHeight: function() {if (this.browser.khtml || this.browser.safari) {return this.innerHeight;} else if (this.browser.opera) {return document.body.clientHeight;} else {return document.documentElement.clientHeight;}},getDimensions: function(obj) {var objStyle = obj.style;var originalVisibility = objStyle.visibility;var originalPosition = objStyle.position;var originalDisplay = objStyle.display;objStyle.visibility = 'hidden';objStyle.position = 'absolute';objStyle.display = 'block';var originalWidth = obj.clientWidth;var originalHeight = obj.clientHeight;objStyle.display = originalDisplay;objStyle.position = originalPosition;objStyle.visibility = originalVisibility;return {width: originalWidth, height: originalHeight};},position: function (obj, x, y) {obj.style.left = x + 'px';obj.style.top  = y + 'px';},buildMenu: function (parent) {var pos, dim, tbl;this.contextMenu = document.createElement("DIV");this.contextMenu.id = "rcRightContext";this.contextMenu.className = 'rcMenuContainer';pos = this.findPosition(parent);dim = this.getDimensions(parent);this.position (this.contextMenu, this.mousePos.x + this.rightOffset, pos.y+dim.height);if (this.menuTriggerEvent == "RIGHT") {this.contextMenu.oncontextmenu = function () { return false; };}document.body.appendChild(this.contextMenu);},killMenu: function () {if (!this.abortKill && this.isShowing) {try {rc = this.contextMenu;document.body.removeChild(rc);} catch (e) {}this.contextMenu = null;this.isShowing = false;this.abortKill = false;}},locateMousePos: function(e) {var posx = 0, posy =0;if(e==null) e=window.event;if(e.pageX || e.pageY) {posx=e.pageX; posy=e.pageY;} else if (e.clientX || e.clientY) {if(document.documentElement.scrollTop){posx=e.clientX+document.documentElement.scrollLeft;posy=e.clientY+document.documentElement.scrollTop;} else {posx=e.clientX+document.body.scrollLeft;posy=e.clientY+document.body.scrollTop;}}this.mousePos = {x:posx , y:posy};},redirect: function (u, frame) {if (!frame) {document.location = u;  } else {if (frame=="_blank") {w = window.open(u, 'w');} else {window.frames[frame].document.location = u;}}},request: function (url, callBack) {if (window.XMLHttpRequest) {this.req = new XMLHttpRequest();this.req.onreadystatechange =  callBack; this.req.open("GET", url, true);this.req.send(null);} else if (window.ActiveXObject) {this.req = new ActiveXObject("Microsoft.XMLHTTP");if (this.req) { this.req.onreadystatechange =   callBack;this.req.open("GET", url, true);this.req.send();}}},loadImage: function (url) {var img = new Image();img.src = url; img.className = "rcImage";this.images[url] = img;return img;},detectBrowser: function() {var ua = navigator.userAgent.toUpperCase();var up = navigator.platform.toUpperCase().substr(0,3);var isSafari  = (ua.indexOf("SAFARI"   )>0);var isKHTML   = (ua.indexOf("KONQUEROR")>0 || isSafari);var isFirefox = (ua.indexOf("FIREFOX"  )>0); var isOpera   = (ua.indexOf("OPERA"    )>=0);return { safari: isSafari, khtml: isKHTML, opera: isOpera, firefox: isFirefox, platform: up }}};
																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																 
function buildCal(m, y, cM, cH, cDW, cD, cT, lT, brdr){var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];var dim=[31,0,31,30,31,30,31,31,30,31,30,31];var oD = new Date(y, m-1, 1);oD.od=oD.getDay()+1;var todaydate=new Date();var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0;dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';if(y == minyear && m==minmonth){t+='<td class="'+cH+'">&nbsp;</td>';}else{
	t+='<td class="'+cH+'"><a href="javascript: prev()" class="'+cH+'"><img src="/images/control_rewind_blue.png" alt="&lt;" border="0"></a></td>';
	}t+='<td colspan="5" align="center" class="'+cH+'">'+mn[m-1]+' '+y+'</td>';if(y == maxyear && m==maxmonth){t+='<td class="'+cH+'">&nbsp;</td>';}else{
	t+='<td class="'+cH+'"><a href="javascript: next()" class="'+cH+'"><img src="/images/control_fastforward_blue.png" alt="&gt;" border="0"></a></td>';
	}t+='</tr><tr align="center">';for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';t+='</tr><tr align="center">';for(i=1;i<=42;i++){var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';var xt=(x==scanfortoday)?'<span id="today">'+x+'</span>':x;if(texts[y + '' + m][x] == "" || texts[y + '' + m][x] == null){t+='<td class="'+cD+'">'+xt+'</td>';} else{t+='<td class="'+cD+'"><span class="event_day" context="hover" text1="'+texts[y + '' + m][x][0]+'" link1="'+links[y + '' + m][x][0]+'" text2="'+texts[y + '' + m][x][1]+'" link2="'+links[y + '' + m][x][1]+'" text3="'+texts[y + '' + m][x][2]+'" link3="'+links[y + '' + m][x][2]+'" text4="'+texts[y + '' + m][x][3]+'" link4="'+links[y + '' + m][x][3]+'" text5="'+texts[y + '' + m][x][4]+'" link5="'+links[y + '' + m][x][4]+'">'+xt+'</span></td>';}if ((i>20)&&(i+1-oD.od>=dim[m-1])&&((i)%7==0)) break;if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';}t+='</tr><tr align="center"><td colspan="7" class="'+cT+'"><a href="'+lT+'">BATS diary</a></td>';return t+='</tr></table></div>';}if (document.location.search.indexOf('trigger') > 0) {params = document.location.search.replace('?', '').split('=');RightContext.menuTriggerEvent = params[1].toUpperCase();} hover = { attributes: "link1,text1,link2,text2,link3,text3,link4,text4,link5,text5" ,
	
items: [
		{type:RightContext.TYPE_MENU,text:"[text1]",url:"[link1]" },
		{type:RightContext.TYPE_MENU,text:"[text2]",url:"[link2]" },
		{type:RightContext.TYPE_MENU,text:"[text3]",url:"[link3]" },
		{type:RightContext.TYPE_MENU,text:"[text4]",url:"[link4]" },
		{type:RightContext.TYPE_MENU,text:"[text5]",url:"[link5]" }
		]};RightContext.addMenu("hover", hover);

var texts = new Array();var links = new Array();var todaydate=new Date();var month = 1;var year = 0;var curmonth=todaydate.getMonth() + month;var curyear=todaydate.getFullYear() + year;
function next(){month = month + 1;if(month == 11) {year = year + 1;month = -1;}curmonth=todaydate.getMonth() + month;curyear=todaydate.getFullYear() + year;createCalendar();}
function prev(){month = month - 1;if(month == -2) {year = year - 1;month = 10;}curmonth=todaydate.getMonth() + month;curyear=todaydate.getFullYear() + year;createCalendar();}
function createCalendar() {var divs = document.getElementById("calendar");divs.innerHTML = buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", "title", "/cgi-bin/calendar/eventsdisplay.pl", 1);RightContext.initialize();}
