function update_calendar( month, year ){
	new Ajax.Updater(
		'calendar',
		'calendar.php',
		{
			parameters: "m=" + month + "&y=" + year,
			onFailure : function(resp) { 
				alert("Oops, there's been an error."); 
			},
			onSuccess: function(req)
			{
				$('calendar').innerHTML = req.responseText;
				new Effect.Highlight('calendar');
			}
			
		}
	);
}






// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll2(){
  if(self.pageYOffset)
    return self.pageYOffset;

  if(document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
    return document.documentElement.scrollTop;
  if(document.body) // all other Explorers
    return document.body.scrollTop;

}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize2(){

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {  
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  } 

  // for small pages with total height less then height of the viewport
  pageHeight = Math.max(windowHeight, yScroll);

  // for small pages with total width less then width of the viewport
  pageWidth = Math.max(windowWidth, xScroll);

  return { page: { width: pageWidth, height: pageHeight }, window: { width: windowWidth, height: windowHeight } };
}





var DialogBox = Class.create();
DialogBox.prototype = {
  initialize: function(message, options) {
    this.message = message;
    this.options = Object.extend({
      divOuterClass:   '',
      divInnerClass:   '',
      dialogClass:     '',
      okayText:        "Ok",
      cancelText:      "Cancel",
      okayImage:       '../images/ui/save.gif',
      cancelImage:     '../images/ui/cancel.gif',
      messageTemplate: "<div>Are you sure you wish to proceed?</div>",
      onOkay:   function() {return true},
      onCancel: function() {return false}
    }, options);
  },

  create: function() {
    if($('dialog')) return;
    var dialog      = document.createElement('div');
    var dialog_box  = document.createElement('div');
    var tmpl        = new Template(this.options.messageTemplate);
    dialog.setAttribute('id', 'dialog');
    dialog_box.setAttribute('id', 'dialog_box');
    dialog_box.innerHTML = tmpl.evaluate({message: this.message});
    dialog_box.appendChild(this.create_buttons());
    Element.setStyle(dialog,     {zIndex: 100});
    Element.setStyle(dialog_box, {zIndex: 101, display:'none'});
    [dialog, dialog_box].each(function(d) { d.className = this.options.dialogClass; }.bind(this));
    document.body.appendChild(dialog);

    if((this.options.divOuterClass != '') && (this.options.divInnerClass != '')) {
      var wrapper = document.createElement('div');
      wrapper.className = this.options.divOuterClass;
      wrapper.setAttribute('id', 'dialog_box_wrapper');
      Element.addClassName(dialog_box, this.options.divInnerClass);
      wrapper.appendChild(dialog_box);
      document.body.appendChild(wrapper);
    } else {
      document.body.appendChild(dialog_box);
    }

    this.layout();
    new Effect.Appear(dialog_box, {duration:0.4});
    DialogBox.resizeObserver = this.layout.bind(this);
    Event.observe(window, 'resize', DialogBox.resizeObserver);
    Event.observe(window, 'scroll', DialogBox.resizeObserver);
  },

layout: function() {
	var pg_dimensions = getPageSize2();
	var elHeight, elWidth;
	if (window.ActiveXObject) {
		elHeight = $('dialog_box').clientHeight;
		elWidth = $('dialog_box').clientWidth;
	}
	else {
		var el_dimensions = Element.getDimensions('dialog_box');
		elHeight = el_dimensions.height;
		elWidth = el_dimensions.width;
	}

	var scrollY = getPageScroll2();

	Element.setStyle('dialog', {
		position:'absolute', top:0, left:0,
		width: pg_dimensions.page.width  + 'px',
		height:pg_dimensions.page.height + 'px'
	});

	Element.setStyle('dialog_box', {
		position:'absolute',
		top:  scrollY + ((pg_dimensions.window.height - elHeight) / 2) + 'px',
		left: ((pg_dimensions.page.width - elWidth) / 2) + 'px'
	})
  },

  create_buttons: function() {
    var buttons             = document.createElement('p');
    buttons.className       = 'buttons';

    var okay_button         = document.createElement('a');
    okay_button.onclick     = function() { this.options.onOkay(); }.bind(this);
    okay_button.className   = 'okay';
    okay_button.setAttribute('href', '#');
    if(this.options.okayImage == '') {
      okay_button.innerHTML = this.options.okayText;
    } else {
      var okay_image        = document.createElement('img');
      okay_image.src        = this.options.okayImage;
      okay_image.setAttribute('alt', this.options.okayText);
      okay_button.appendChild(okay_image);
    }
    
    var cancel_button       = document.createElement('a');
    cancel_button.onclick   = function() { DialogBox.close(); this.options.onCancel(); }.bind(this);
    okay_button.className   = 'cancel';
    cancel_button.setAttribute('href', '#');
    if(this.options.cancelImage == '') {
      cancel_button.innerHTML = this.options.cancelText;
    } else {
      var cancel_image      = document.createElement('img');
      cancel_image.src      = this.options.cancelImage;
      cancel_image.setAttribute('alt', this.options.cancelText);
      cancel_button.appendChild(cancel_image);
    }
    
    buttons.appendChild(okay_button);
    buttons.appendChild(cancel_button);
    return buttons;
  }
};

DialogBox.create = function(message, options) {
  var d = new DialogBox(message, options);
  d.create();
}

DialogBox.close = function() {
  if (!DialogBox.resizeObserver) return;

  new Effect.Fade('dialog_box', {duration: 0.2, afterFinish: function() {
    Element.remove('dialog');
    Element.remove('dialog_box');
    Element.remove('dialog_box_wrapper');
  }});
    
  Event.stopObserving(window, 'resize', DialogBox.resizeObserver);
  Event.stopObserving(window, 'scroll', DialogBox.resizeObserver);
  DialogBox.resizeObserver = null;
}


