/*
* A Soft Idiom date picker.
*/

function init_datePicker(){
	var node = document.getElementById('DatePicker');
	document.datepicker = new DatePicker();
}

/*
* Constructor: DatePicker
* Parameters:
*   objectDefinition - the definition object for this embedded object.
* Returns:
*   An instance of this class.
*/
//---------------------------------------------------------------------------
DatePicker = function() {
  this.init();
}
DatePicker.prototype = {
	bottom:       0,      // calendar bottom position.
	calendar:     null,   // the calendar node.
	calTable:     null,   // the calendar table node.
	container:    null,   // the calendar container node.
	dayChars:     1,      // number of characters in day names abbreviation
	dayNames:     null,   // names of week days.
	daysInMonth:  null,   // the days in the month.
	format:       'mm/dd/yyyy', // string format.
	isShowing:    false,  // true if showing.
	left:         0,      // calendar left position.
	monthNames:   null,   // names of months.
	monthSel:     null,   // months select node.
	node:         null,   // the text node.
	now:          null,   // the date today.
	nowDay:       null,   // the day today.
	nowMonth:     null,   // the month today.
	nowYear:      null,   // the year today.
	right:        0,      // calendar right position.
	startDay:     7,      // 1 = week starts on Monday, 7 = week starts on Sunday
	then:         null,   // the orginal node date.
	thenDay:      null,   // the original day.
	thenMonth:    null,   // the original month.
	thenYear:     null,   // the original year.
	timerKey:     null,   // the timeout key.
	top:          0,      // calendar top position.
	windowClickSubscription: null, // subscription for window clicks.
	yearBack:     null,   // move year back node.
	yearForward:  null,   // move year forward node.
	yearOrder:    'asc',  // ascending or descending years.
	yearRange:    16,     // number of years to show.
	yearSel:      null,   // years select node.
	yearShown:    8,     // the shown selected year.

	CONTAINER_CLASS:  'DatePickerContainer',
	CALENDAR_CLASS:   'DatePickerCalendar',
	DAYS_CLASS:       'DatePickerDays',
	CELL_CLASS:       'DatePickerCell',
	CELL_OVER_CLASS:  'DatePickerCellOver',
	SELECTED_CLASS:   'DatePickerSelected',
	TODAY_CLASS:      'DatePickerToday',
	DROP_DOWN_CLASS:  'DatePickerDropDown',
	BUTTON_CLASS:     'DatePickerButton',
	BUTTON_IN_CLASS:  'DatePickerButton DatePickerButtonIn',
	CANCEL_CLASS:	  'DatePickerCancel',
	TITLE_CLASS:	  'DatePickerTitle',
	TIMEOUT:          2000,
  
	/*
	 * Function: init
	 */
	init: function(node){
		// Set today.
		this.now = new Date();
		this.nowYear = this.now.getFullYear();
		this.nowMonth = this.now.getMonth();
		this.nowDay = this.now.getDate();
		
		// create the container.
		this.container = this.createElement('div', document.body, {
			style:{position:"absolute",visibility:"hidden"},
			className:this.CONTAINER_CLASS,
			datepicker_object: this
		});
		
		// setup the properties.
		this.dayChars = 1;
		this.format = 'dd/mm/yyyy';
		this.startDay = 7;
		this.yearOrder = 'asc';
		this.yearRange = 48;
		this.yearShown = 24;
		this.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		this.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
		this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	},
	/*
	 * Function: destroy
	 * Called to destroy the object and free up any resources used.
	 */
	destroy: function() {
		this.unbuild();
		if (this.container.parentNode != null) { this.container.parentNode.removeChild(this.container); }
		this.container = null;
		this.monthNames = null;
		this.dayNames = null;
		this.daysInMonth = null;
	},
  
	//----------------------------- show/hide functions ------------------------
  
	/*
	 * Function: show
	 * Parameters:
	 *   node - the text node that is using the picker.
	 */
	show: function(node){
		if (this.isShowing) { return; }
		this.node = node;

		// Get the entered date.
		this.then = this.getDateFromString(this.node.value, this.format);
		this.thenYear = this.then.getFullYear();
		this.thenMonth = this.then.getMonth();
		this.thenDay = this.then.getDate();

		// build the calendar.
		this.build(this.thenYear, this.thenMonth);

		// position the calendar and make it visible.
		this.top = this.getNodeTopPosition(this.node) + this.getNodeHeight(this.node) + 2;
		this.left = this.getNodeLeftPosition(this.node);
		var calendarHeight = this.getNodeHeight(this.calendar);
		var calendarWidth = this.getNodeWidth(this.calTable);

		var windowRight = this.getBrowserWidth();
		var windowBottom = this.getBrowserHeight();

		if (this.left + calendarWidth > windowRight) {
			// we need to move the calendar left into the window.
			this.left = windowRight - calendarWidth - 10;
		}
		if (this.top + calendarHeight > windowBottom) {
			// we need to move the calendar up above the text field.
			this.top = this.getNodeTopPosition(this.node) - calendarHeight - 2;
		}
		this.bottom = this.top + calendarHeight;
		this.right = this.left + calendarWidth;

		this.calendar.style.width = calendarWidth+'px';

		this.container.datepicker = this;
		this.container.onmouseout = this.oncalendarmouseout;
		this.container.onmouseover = this.oncalendarmouseover;

		this.container.style.top = this.top+'px';
		this.container.style.left = this.left+'px';
		this.container.style.width = calendarWidth+'px';
		this.container.style.height = calendarHeight+'px';
		this.container.style.zIndex = 999;
		this.container.style.visibility = 'visible';

		this.isShowing = true;
	},    
	/*
	 * Function: hide
	 */
	hide: function() {
		if (!this.isShowing) { return; }
		this.container.style.visibility = 'hidden';
		this.isShowing = false;
		this.unbuild();
	},
	/*
	 * Function: build
	 */
	build: function(year, month){
		// setup the date object.
		var date = new Date();
		if (year != null && month != null) {
			date.setFullYear(year, month, 1);
		} 
		else {
			month = date.getMonth();
			year = date.getFullYear();
			date.setDate(1);
		}
		if (year % 4 == 0) { this.daysInMonth[1] = 29; }
		else { this.daysInMonth[1] = 28; }

		// start creating calendar.
		this.calendar = this.createElement('div', this.container, {className:this.CALENDAR_CLASS});
		this.calTable = this.createElement('table', this.calendar, {});
		var calTableThead = this.createElement('thead', this.calTable, {});
		var calSelRow = this.createElement('tr', calTableThead, {});
		var calSelCell = this.createElement('th', calSelRow, {colSpan:'7',noWrap:'true'});

		// create the month select.
		this.monthSel = this.createElement('select', calSelCell, {
			className: this.DROP_DOWN_CLASS,
			datepicker_object: this
		});
		for (var j = 0; j < this.monthNames.length; j++){
			this.monthSel.options[j] = new Option(this.monthNames[j], j);
			if (j == month) this.monthSel.options[j].selected = true;
		}
		this.monthSel.onchange = this.onchangemonthyear;

		// create the year select nodes.
		this.yearBack = this.createElement('div', calSelCell, {
			className: this.BUTTON_CLASS,
			onclick: this.onyearback,
			datepicker_object: this
		});
		this.yearBack.style.backgroundImage = "url('/QuakerCamp/images/left.gif')";
		this.createElement('a', this.yearBack, {
			className: this.TITLE_CLASS,
			title: 'move year backwards',
			innerHTML: '&nbsp;',
			onclick: this.onyearback,
			datepicker_object: this
		});

		this.yearSel = this.createElement('select', calSelCell, {
			className:this.DROP_DOWN_CLASS,
			datepicker_object: this
		});
		var i = 0;
		if (this.yearOrder == 'desc'){
			var yearStart = year + this.yearShown;
			for (var j = yearStart; j > (yearStart - this.yearRange - 1); j--){
				this.yearSel.options[i] = new Option(j, j);
				if (j == year) { this.yearSel.options[i].selected = true; }
				i++;
			}
		} 
		else {
			var yearStart = year - this.yearShown;
			for (var j = yearStart; j < (yearStart + this.yearRange + 1); j++){
				this.yearSel.options[i] = new Option(j, j);
				if (j == year) { this.yearSel.options[i].selected = true; }
				i++;
			}
		}
		this.yearSel.onchange = this.onchangemonthyear;

		this.yearForward = this.createElement('div', calSelCell, {
			className: this.BUTTON_CLASS,
			onclick: this.onyearforward,
			datepicker_object: this
		});
		this.yearForward.style.backgroundImage = "url('/QuakerCamp/images/right.gif')";
		this.createElement('a', this.yearForward, {
			className: this.TITLE_CLASS,
			title: 'move year forward',
			innerHTML: '&nbsp;',
			onclick: this.onyearforward,
			datepicker_object: this
		});

		this.clear = this.createElement('div', calSelCell, {
			className: this.CANCEL_CLASS,
			onclick: this.onclear,
			datepicker_object: this
		});
		this.clear.style.backgroundImage = "url('/QuakerCamp/images/clear.gif')";
		this.createElement('a', this.clear, {
			className: this.TITLE_CLASS,
			title: 'clear the date',
			innerHTML: '&nbsp;',
			onclick: this.onclear,
			datepicker_object: this
		});

		this.cancel = this.createElement('div', calSelCell, {
			className: this.CANCEL_CLASS,
			onclick: this.oncancel,
			datepicker_object: this
		});
		this.cancel.style.backgroundImage = "url('/QuakerCamp/images/cancel.gif')";
		this.createElement('a', this.cancel, {
			className: this.TITLE_CLASS,
			title: 'cancel',
			innerHTML: '&nbsp;',
			onclick: this.oncancel,
			datepicker_object: this
		});

		/* create day names */
		var calTableTbody = this.createElement('tbody', this.calTable, {});
		var calDayNameRow = this.createElement('tr', calTableTbody, {});
		for (var j = 0; j < this.dayNames.length; j++) {
			calDayNameCell = this.createElement('td', calDayNameRow, {className:this.DAYS_CLASS});
			var text = this.dayNames[(this.startDay+j)%7].substr(0, this.dayChars);
			this.createTextElement(text, calDayNameCell);
		}

		/* create the day cells */
		var day = (1 - (7+date.getDay() - this.startDay) % 7);
		while (day <= this.daysInMonth[month]) {
			var calDayRow = this.createElement('tr', calTableTbody, {});
			for (var j = 0; j < 7; j++){
				var calDayCell;
				if ((day <= this.daysInMonth[month]) && (day > 0)) {
					calDayCell = this.createElement('td', calDayRow, {
						className: this.CELL_CLASS,
						datepicker_class: this.CELL_CLASS,
						datepicker_over_class: this.CELL_OVER_CLASS,
						datepicker_year: year,
						datepicker_month: month,
						datepicker_day: day,
						datepicker_object: this
					});
					this.createTextElement(''+day, calDayCell);
					calDayCell.onmouseover = this.onmouseover;
					calDayCell.onmouseout = this.onmouseout;
					calDayCell.onclick = this.onclick;
				} 
				else {
					calDayCell = this.createElement('td', calDayRow, {className:'node_empty'});
					this.createTextElement(' ', calDayCell);
				}
				if (day == this.thenDay && month == this.thenMonth && year == this.thenYear) {
					// set class for the selected day.
					calDayCell.className = this.SELECTED_CLASS;
					calDayCell.datepicker_class = this.SELECTED_CLASS;
				}
				else if (day == this.nowDay && month == this.nowMonth && year == this.nowYear) {
					// set class for today.
					calDayCell.className = this.TODAY_CLASS;
					calDayCell.datepicker_class = this.TODAY_CLASS;
				}
				day++;
			}
		}
	},
	/*
	 * Function: unbuild
	 */
	unbuild: function() {
		if (this.calendar.parentNode != null) { this.calendar.parentNode.removeChild(this.calendar); }
		this.calendar = null;
		this.monthSel = null;
		this.yearSel = null;
		this.timerKey = null
	},

	//----------------------------- event functions -----------------------------

	/*
	 * Function: onmouseover
	 */
	onmouseover: function() {
		this.className = this.datepicker_over_class;
	},
	/*
	 * Function: onmouseout
	 */
	onmouseout: function() {
		this.className = this.datepicker_class;
	},
	/*
	 * Function: onclick
	 */
	onclick: function() {
		var self = this.datepicker_object;
		self.node.value = self.getStringFromFields(this.datepicker_year, this.datepicker_month+1, this.datepicker_day, self.format);
		if (self.node.onchange != null) { self.node.onchange(); }
		self.node.focus();
		self.hide();
	},
	/*
	 * Function: onchangemonthyear
	 */
	onchangemonthyear: function() {
		var self = this.datepicker_object;
		var month = self.monthSel.options[self.monthSel.selectedIndex].value * 1;
		var year = self.yearSel.options[self.yearSel.selectedIndex].value * 1;
		self.unbuild();
		self.build(year, month);
	},
	/*
	 * Function: onyearback
	 */
	onyearback: function() {
		var self = this.datepicker_object;
		var month = self.monthSel.options[self.monthSel.selectedIndex].value * 1;
		var year = (self.yearSel.options[self.yearSel.selectedIndex].value * 1) - self.yearRange;
		self.unbuild();
		self.build(year, month);
	},
	/*
	 * Function: onyearforward
	 */
	onyearforward: function() {
		var self = this.datepicker_object;
		var month = self.monthSel.options[self.monthSel.selectedIndex].value * 1;
		var year = (self.yearSel.options[self.yearSel.selectedIndex].value * 1) + self.yearRange;
		self.unbuild();
		self.build(year, month);
	},
	/*
	 * Function: onclear
	 */
	onclear: function() {
		var self = this.datepicker_object;
		self.node.value = "";
	},
	/*
	 * Function: oncancel
	 */
	oncancel: function() {
		var self = this.datepicker_object;
		self.node.focus();
		self.hide();
	},
	/*
	 * Function: oncalendarmouseover
	 */
	oncalendarmouseover: function() {
		var self = this.datepicker_object;
	},
	/*
	 * Function: oncalendarmouseout
	 * Parameters:
	 *   event - the event.
	 */
	oncalendarmouseout: function(event) {
		var self = this.datepicker_object;
		var eventObj = new EventObject(event);
		// check if mouse outside calendar.
		if (eventObj.pageX < self.left || eventObj.pageX > self.right || 
				eventObj.pageY < self.top || eventObj.pageY > self.bottom) {
			// setup a timeout to hide the calendar.
		}
	},
	
	//------------------- node builder functions -------------------------------
	
	/**
	 * Function: createElement
	 * Create a node in the DOM.
	 * Properties:
	 *   type - the type of node.
	 *   parentNode - the parent node.
	 *   properties - a collection of node properties.
	 * Returns:
	 *   The node.
	 */
	createElement: function(type, parentNode, properties) {
		var element = document.createElement(type);
		if (properties != null) {
			for ( var property in properties) {
				if (property == "style") {
					for ( var styleProperty in properties.style) {
						element.style[styleProperty] = properties.style[styleProperty];
					}
				}
				else {
					element[property] = properties[property];
				}
			}
		}
		if (parentNode != null) {
			parentNode.appendChild(element);
		}
		return element;
	},
	/**
	 * Function: replaceTextElement
	 * Replace a text node in the DOM.
	 * Properties:
	 *   text - the text for the node.
	 *   parentNode - the parent node.
	 *   checkAcceleratorKeys - if true then check for accelerator key codes.
	 */
	replaceTextElement: function(text, parentNode, checkAcceleratorKeys) {
		if (parentNode == null) { return; }
		for ( var j = parentNode.childNodes.length - 1; j >= 0; j--) {
			parentNode.removeChild(parentNode.childNodes[j]);
		}
		if (text != null) {
			this.createTextElement(text, parentNode, checkAcceleratorKeys);
		}
	},
	/**
	 * Function: createTextElement
	 * Create a text node in the DOM.
	 * Properties:
	 *   text - the text for the node.
	 *   parentNode - the parent node.
	 *   checkAcceleratorKeys - if true then check for accelerator key codes.
	 */
	createTextElement: function(text, parentNode, checkAcceleratorKeys) {
		if (text == null || parentNode == null) { return; }

		// look in text for accelerator keys and new lines.
		text = text.replace(/\r/g, "");
		text = text.replace(/\n/g, "<proiv-br>");
		text = text.replace(/&amp;/g, "&");
		while (true) {
			var matches = (checkAcceleratorKeys) ? text.match(/(^.*?)(&[^\s]|<proiv-br>)(.*$)/i): text.match(/(^.*?)(<proiv-br>)(.*$)/i);
			if (matches != null && matches.length > 0) {
				parentNode.appendChild(document.createTextNode(matches[1]));
				if (matches[2].substr(0, 1) == "&") {
					// an accelerator string.
					var element = this.createElement("span", parentNode, {
						className: "proiv-accelerator"
					});
					element.appendChild(document.createTextNode(matches[2].substr(1, 1)));
					text = matches[3];
				}
				else if (matches[2] == "<proiv-br>") {
					// new line code.
					this.createElement("br", parentNode);
					text = matches[3];
				}
			}
			else {
				parentNode.appendChild(document.createTextNode(text));
				break;
			}
		}
	},

	//------------------- node layout function ---------------------------------
	
	/*
	 * Function: getNodeLeftPosition
	 * Parameters:
	 *   node - the node object.
	 * Returns:
	 *   The left pixel position of the node in the page.
	 */
	getNodeLeftPosition: function (node) {
		var left = 0;
		if (node.offsetParent) {
			while (node.offsetParent) {
				left += node.offsetLeft;
				node = node.offsetParent;
			}
		}
		else if (node.x) { left += node.x; }
		return left;
	},
	/*
	 * Function: getNodeTopPosition
	 * Parameters:
	 *   node - the node object.
	 * Returns:
	 *   The top pixel position of the node in the page.
	 */
	getNodeTopPosition: function (node) {
		var top = 0;
		if (node.offsetParent) {
			while (node.offsetParent) {
				top += node.offsetTop;
				node = node.offsetParent;
			}
		}
		else if (node.y) { top += node.y; }
		return top;
	},
	/*
	 * Function: getNodeWidth
	 * Parameters:
	 *   node - the node object.
	 * Returns:
	 *   The current width of the node in the page.
	 */
	getNodeWidth: function (node) {
		return node.offsetWidth;
	},
	/*
	 * Function: getNodeHeight
	 * Parameters:
	 *   node - the node object.
	 * Returns:
	 *   The current height of the node in the page.
	 */
	getNodeHeight: function (node) {
		return node.offsetHeight;
	},
	/*
	 * Function: getBrowserWidth
	 * Returns:
	 *   The current width of the browser window.
	 */
	getBrowserWidth: function () {
		if (typeof(window.innerWidth) == 'number') {
			return window.innerWidth;
		} 
		else if(document.documentElement && document.documentElement.clientWidth) {
			return document.documentElement.clientWidth;
		} 
		else if(document.body && document.body.clientWidth) {
			return document.body.clientWidth;
		}
	},
	/*
	 * Function: getBrowserHeight
	 * Returns:
	 *   The current height of the browser window.
	 */
	getBrowserHeight: function () {
		if (typeof(window.innerWidth) == 'number') {
			return window.innerHeight;
		} 
		else if(document.documentElement && document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} 
		else if(document.body && document.body.clientHeight) {
			return document.body.clientHeight;
		}
	},
	
	//------------------- date format functions --------------------------------
	
	/**
	 * Function: formatConversion
	 * Parameters:
	 *   dateString - the date as a string.
	 *   currentFormat - the current date format.
	 *   newFormat - the new date format.
	 * Returns:
	 *   A string in the new date format.
	 */
	formatConversion: function(dateString, currentFormat, newFormat) {
		if (currentFormat == null) {
			currentFormat = this.config.DatePicker.format;
			if (currentFormat.length == 0) { currentFormat = 'mm/dd/yyyy'; }
		}
		if (newFormat == null) {
			newFormat = this.config.DatePicker.format;
			if (newFormat.length == 0) { newFormat = 'mm/dd/yyyy'; }
		}
		var fields = this.getFieldsFromString(dateString, currentFormat);
		return this.getStringFromFields(fields.year, fields.month, fields.day, newFormat);
	},
	/**
	 * Function: getDateFromString
	 * Parameters:
	 *   dateString - the date as a string.
	 *   format - the date format.
	 * Returns:
	 *   A date object.
	 */
	getDateFromString: function(dateString, format) {
		var fields = this.getFieldsFromString(dateString, format);
		if (fields.year == -1 || fields.month == -1 || fields.day == -1) { return new Date(); }
		return new Date(fields.year, fields.month - 1, fields.day, 12, 0, 0, 0);
	},
	/**
	 * Function: getFieldsFromString
	 * Parameters:
	 *   dateString - the date as a string.
	 *   format - the date format.
	 * Returns:
	 *   A date fields object.
	 */
	getFieldsFromString: function(dateString, format) {
		var yearIndex = format.indexOf('yyyy');
		var monthIndex = format.indexOf('mm');
		var dayIndex = format.indexOf('dd');
		var year = (yearIndex > -1 && dateString.length >= yearIndex + 4) ? dateString.substr(yearIndex, 4) * 1: -1;
		var month = (monthIndex > -1 && dateString.length >= monthIndex + 2) ? dateString.substr(monthIndex, 2) * 1: -1;
		var day = (dayIndex > -1 && dateString.length >= dayIndex + 2) ? dateString.substr(dayIndex, 2) * 1:  -1;
		if (isNaN(year)) { year = -1; }
		if (isNaN(month)) { month = -1; }
		if (isNaN(day)) { day = -1; }
		return {
			year: year,
			month: month,
			day: day
		};
	},
	/**
	 * Function: getStringFromFields
	 * Parameters:
	 *   year - the year.
	 *   month - the month.
	 *   day - the day.
	 *   format - the date format.
	 * Returns:
	 *   A string in the correct date format.
	 */
	getStringFromFields: function(year, month, day, format) {
		if (year == -1 || month == -1 || day == -1) { return ""; }

		var stringYear = '' + year;
		var stringMonth = (month < 10) ? '0' + month: '' + month;
		var stringDay = (day < 10) ? '0' + day: '' + day;

		var dateStr = format.replace(/yyyy/i, stringYear);
		dateStr = dateStr.replace(/mm/i, stringMonth);
		dateStr = dateStr.replace(/dd/i, stringDay);

		return dateStr;
	}
};

/*
* Constructor: EventObject
* Parameters:
*   event - a browser event object.
*/
EventObject = function(event) {
  this.getEventInfo(event);
}
EventObject.prototype = {
	altKey:     false,  // true if Alt key pressed.
	capsLock:   false,  // the current capsLock state.
	ctrlKey:    false,  // true if Ctrl key pressed.
	consumed:   false,  // true if the event has been consumed.
	event:      null,   // the event object.
	isIE:       false,  // true if this is an IE event.
	keyCode:    0,      // the code of the key pressed.
	pageX:      0,      // the mouse X position.
	pageY:      0,      // the mouse Y position.
	shiftKey:   false,  // true if Shift key pressed.
	target:     null,   // the event target node.
  
	/*
	 * Function: getEventInfo
	 * This function handles the different event objects supplied by different browsers.
	 * Parameters:
	 *   event - a browser event object.
	 * Returns:
	 *   this object.
	 */
	getEventInfo: function (event) {
		if (event == null && window.event != null) {
			// IE event.
			this.isIE     = true; 
			this.event    = window.event;
			this.target   = window.event.srcElement;
			this.keyCode  = window.event.keyCode;
			this.ctrlKey  = window.event.ctrlKey;
			this.shiftKey = window.event.shiftKey;
			this.altKey   = window.event.altKey;
			this.pageX    = window.event.clientX;
			this.pageY    = window.event.clientY;
		}
		else if (event != null) {
			// other browsers. 
			this.isIE     = false; 
			this.event    = event;
			this.target   = event.target;
			this.keyCode  = event.keyCode;
			this.ctrlKey  = event.ctrlKey;
			this.shiftKey = event.shiftKey;
			this.altKey   = event.altKey;
			this.pageX    = event.pageX;
			this.pageY    = event.pageY;
		}
		else {
			this.event = {};
		}
		return this;
	},
	/*
	 * Function: consumeEvent
	 * Tries to stop this event from doing anything else.
	 */
	consumeEvent: function () {
		this.preventDefault();
		this.stopPropagation();
		this.consumed = true;
	},
	/*
	 * Function: preventDefault
	 * Tries to stop this event from performing its default action.
	 */
	preventDefault: function () {
		if (this.event.preventDefault != null) { this.event.preventDefault(); }
		if (this.isIE) {
			try { this.event.returnValue = false; }
			catch (e) {}
		}
	},
	/*
	 * Function: stopPropagation
	 * Tries to stop this event from propagating.
	 */
	stopPropagation: function () {
		if (this.event.stopPropagation != null) { this.event.stopPropagation(); }
		if (this.isIE && this.event.preventBubble != null) { this.event.preventBubble(); }
		try { this.event.cancelBubble = true; }
		catch (e) {}
	}
};


