var PlaceCalendar =
{
	X : 0,
	Y : 0,
	
	init : function()
	{
		if (!document.getElementsByTagName) {
			return;
		}
		
		var a = document.getElementsByTagName('a');
		var i = 0;
		var dim = a.length;
		for (i = 0; i < dim; i++) {
			if (a[i].className.match('opencalendar')) {
				a[i].onclick = function()
				{
					var f = null;
					var homepage = false;
					var branchdetails = false;
					var start = false;
					var end = false;
					var b = null;
					var xoffset = 0;
					var yoffset = 0;					
					
					if (this.className.match('startdate')) {
						start = true;
					} else {
						end = true;
					}
					
					if (this.className.match('homecalendar')) {
						f = document.forms['homePageForm'];
						homepage = true;
					} else if (this.className.match('worldlocationcalendar')) {
						f = document.forms['worldLocationCreateResForm'];
						homepage = true;
					} else if (this.className.match('branchdetailscalendar')) {
						f = document.forms['branchDetailsForm'];
						branchdetails = true;
					}
					
					var o = null;
					
					if (start == true) {
						o = document.getElementById('startCalendar');
					} else if (end == true) {
						o = document.getElementById('endCalendar');
					} else {
						o = null;
					}
					
					if (o == null) {
						return;
					}
					
					if (document.all) {
						if (homepage == true) {
							calX = PlaceCalendar.X + 125;
							calY = PlaceCalendar.Y;
						}
						if (branchdetails == true) {
							calX = PlaceCalendar.X - 40;
							calY = PlaceCalendar.Y + (start==true?-180:18);
						}
						if (document.compatMode && document.compatMode != "BackCompat") {
							b = document.documentElement;
						} else {
							b = document.body;
						}
						xoffset = b.scrollLeft;
						yoffset = b.scrollTop;
					} else {
						xoffset = pageXOffset;
						yoffset = pageYOffset;
					}
					
					calX += xoffset;
					calY += yoffset;
					
					if (start == true) {
						open_cal(f.startDateMonth, f.startDateInput, f.endDateMonth, f.endDateInput);
					} else if (end == true) {
						open_cal(f.endDateMonth, f.endDateInput);
					}
				}
			}
		}
	},
	
	trackMouse : function(arg)
	{
		PlaceCalendar.X = 50;
		PlaceCalendar.Y = 50;
		
		if (arg) {
			if (arg.pageX) {
				PlaceCalendar.X = arg.pageX;
				PlaceCalendar.Y = arg.pageY;
			} else if (arg.clientX) {
				PlaceCalendar.X = arg.clientX;
				PlaceCalendar.Y = arg.clientY;
			}
		}
	}
}


addEvent(window, 'load', PlaceCalendar.init);
addEvent(window , 'resize', PlaceCalendar.init);
addEvent(document, 'mousemove', PlaceCalendar.trackMouse);
