
/*
	Source: classbehaviours.fader.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// COMMON FADER FUNCTIONS
		// create the utilities child object if it doesn't already exist
		if(typeof(classBehaviours.fader)=='undefined') classBehaviours.fader = {
			getFade : function(node){
				var fadeValue = null;
				if(node!=null){
					// get the fade value using the proper method
					if(typeof(node.style.MozOpacity)!='undefined') fadeValue = Math.round(parseFloat(node.style.MozOpacity)*100);
					if(typeof(node.filters)!='undefined') if(typeof(node.filters.alpha)!='undefined') fadeValue = parseInt(node.filters.alpha.opacity);
					if(typeof(node.style.opacity)!='undefined')	fadeValue = Math.round(parseFloat(node.style.opacity)*100);
				}
				// return the value
				return (isNaN(fadeValue)) ? null : fadeValue;
			},
			setFade : function(node, amount){
				if(node!=null){
					// set the fade value using the proper method
					if(typeof(node.style.MozOpacity)!='undefined') node.style.MozOpacity = amount/100;
					if(typeof(node.filters)!='undefined') if(typeof(node.filters.alpha)!='undefined') node.filters.alpha.opacity = amount;
//					if(typeof(node.style.filter)!='undefined') if(typeof(node.style.filter.alpha)!='undefined') node.style.filter = "alpha(opacity=" + amount + ")";
					if(typeof(node.style.opacity)!='undefined') node.style.opacity = amount/100;
				}
				//	filter:alpha(opacity=50);	imageobject.filters.alpha.opacity=opacity
				//	-moz-opacity: 0.5;			imageobject.style.MozOpacity=opacity/100
				//	opacity: 0.5;
				//	-khtml-opacity: 0.5;
			},
			getSize : function(node){
				// measure the height of the container
				var nodeWidth = node.offsetWidth;
				var nodeHeight = node.offsetHeight;
				// measure the height of all the childnodes of the container
				var totalWidth = 0;
				var totalHeight = 0;
				var contents = node.childNodes;
				for(var a=0; a<contents.length; a++){
					totalWidth += (contents[a].offsetWidth) ? contents[a].offsetWidth : 0 ;
					totalHeight += (contents[a].offsetHeight) ? contents[a].offsetHeight : 0 ;
				}
				// pass back the largest number
				return new Array(nodeWidth, nodeHeight, totalWidth, totalHeight);
			},
			setSize : function(node, xAmount, yAmount){
				if(xAmount!=null) node.style.width = xAmount + 'px';
				if(yAmount!=null) node.style.height = yAmount + 'px';
			},
			fade : function(id, start, end, step, delay, acceleration, evalOnEnd){
				var cf = classBehaviours.fader;
				// get the target node
				var target = (typeof(id)=='string') ? document.getElementById(id) : id ;
				// get the start value if missing
				if(start==null) start = cf.getFade(target);
				if(end==null) end = 100;
				if(step==null) step = 1;
				if(delay==null) delay = 10;
				if(acceleration==null) acceleration = 1;
				if(evalOnEnd==null) evalOnEnd = '';
				// calculate the new value
				if(start<end) {value = (start+step>end) ? end : start+step ;}
				else if(start>end) {value = (start-step<end) ? end : start-step ;}
				// set the fade
				cf.setFade(target, value);
				// order the next step
				var timeOut;
				if(value!=end){
					timeOut = setTimeout(function(){
						classBehaviours.fader.fade(id, value, end, step+acceleration, delay, acceleration, evalOnEnd);
					}, delay);
				}else {
					if(typeof(evalOnEnd)=='string'){
						eval(evalOnEnd);
					}else{
						evalOnEnd();
					}
				}
				// return a way of cancelling the animation
				return timeOut;
			},
			size : function(id, start, end, step, delay, acceleration, evalOnEnd){
				var cf = classBehaviours.fader;
				// get the target node
				var target = (typeof(id)=='string') ? document.getElementById(id) : id ;
				// get the start value if missing
				if(start==null) start = cf.getSize(target)[1];
				if(end==null) end = cf.getSize(target)[3];
				if(step==null) step = 10;
				if(delay==null) delay = 10;
				if(acceleration==null) acceleration = 10;
				if(evalOnEnd==null) evalOnEnd = '';
				// calculate the new value
				if(start<end) {value = (start+step>end) ? end : start+step ;}
				else if(start>end) {value = (start-step<end) ? end : start-step ;}
				// set the fade
				cf.setSize(target, null, value);
				// order the next step
				var timeOut;
				if(value!=end) {
					var nextTarget = target;
					var nextValue = value;
					var nextEnd = end;
					var nextStep = step+acceleration;
					var nextDelay = delay;
					var nextAcceleration = acceleration;
					var nextEvalOnEnd = evalOnEnd;
					timeOut = setTimeout(function(){
						classBehaviours.fader.size(nextTarget, nextValue, nextEnd, nextStep, nextDelay, nextAcceleration, nextEvalOnEnd);
					}, delay);
				}else {
					if(typeof(evalOnEnd)=='string'){
						eval(evalOnEnd);
					}else{
						evalOnEnd();
					}
				}
				// return a way of cancelling the animation
				return timeOut;
			},
			// START: legacy wrappers
			fadeIn : function(id, step, delay, evalOnEnd, acceleration){
				fade(id, 0, 100, step, delay, acceleration, evalOnEnd);
			},
			fadeOut : function(id, step, delay, evalOnEnd, acceleration){
				fade(id, 100, 0, step, delay, acceleration, evalOnEnd);
			},
			crossFade : function(idIn, idOut, amount, step, delay, evalOnEnd, acceleration){
				fade(idIn, 0, 100, step, delay, acceleration, evalOnEnd);
				fade(idOut, 100, 0, step, delay, acceleration, '');
			},
			grow : function(id, step, delay, evalOnEnd, acceleration){
				size(id, 1, null, step, delay, acceleration, evalOnEnd);
			},
			shrink : function(id, step, delay, evalOnEnd, acceleration){
				size(id, null, 1, step, delay, acceleration, evalOnEnd);
			}
			// END: legacy wrappers
		}

/*
	Source: classbehaviours.utilities.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// COMMON UTILITY FUNCTIONS
		// create the utilities child object if it doesn't already exist
		if(typeof(classBehaviours.utilities)=='undefined') classBehaviours.utilities = {
			// returns all nodes of the same class
			getElementsByClassName : function(className, node){
				// use the whole body if no target was provided
				var target = (node!=null) ? node : document ;
				// make an empty array for the results
				var foundNodes = new Array();
				// make a regular expression to recognise the class name
				var wantedClass = new RegExp('\\b'+className+'\\b');
				// for all elements in the parent node
				var allNodes = (target.all) ? target.all : target.getElementsByTagName("*");
				for(var a=0; a<allNodes.length; a++){
					// if the classname was found add it to the results
					if(wantedClass.test(allNodes[a].className)) foundNodes[foundNodes.length] = allNodes[a];
				}
				// return the list
				return foundNodes;
			},
			// gets the value of a parameter from a className
			getClassParameter : function(targetNode, paramName, defaultValue){
				if(targetNode!=null){
					var parameterValue = (targetNode.className.indexOf(' ' + paramName + '_')>-1) ?
						targetNode.className.split(' ' + paramName + '_')[1].split(' ')[0] :
						defaultValue ;
					return (isNaN(defaultValue) || defaultValue==null || defaultValue=='' || typeof(defaultValue)!='string') ?
						parameterValue :
						parseFloat(parameterValue.replace('D','.'));
				}else{
					return defaultValue;
				}
			},
			// sets the value of a parameter from a className
			setClassParameter : function(targetNode, paramName, newValue){
				if(targetNode!=null){
					// create a default value, if there isn't one
					if(targetNode.className==null) targetNode.className = '';
					if(targetNode.className.indexOf(' ' + paramName + '_')<0) targetNode.className += ' ' + paramName + '_0';
					// get the old value
					oldValue = this.getClassParameter(targetNode, paramName, null);
					// replace the old value
					if(oldValue!=null) targetNode.className = targetNode.className.replace(paramName+'_'+oldValue, paramName+'_'+newValue);
				}
			},
			// get the next node without worrying about text nodes
			nextNode : function(targetNode, count){
				var testNode = targetNode;
				if(count==null) count = 1;
				for(var a=0; a<count; a++){
					do {
						testNode = (testNode.nextSibling!=null) ? testNode.nextSibling : targetNode ;
					}while(testNode.nodeName.indexOf('#text')>-1);
				}
				return testNode;
			},
			// get the previous node without worrying about text nodes
			previousNode : function(node, count){
				testNode = node;
				if(count==null) count = 1;
				// look for the previous html node
				for(var a=0; a<count; a++){
					do {
						testNode = testNode.previousSibling;
						if(testNode==null) testNode = node;
					}while(testNode.nodeName.indexOf('#text')>-1);
				}
				// return it
				return testNode;
			},
			// find the parent node with the given classname
			findParentNode : function(node, rootTag, rootId, rootClass){
				// try parent nodes until you find the one which meets the conditions
				rootFound = false;
				while(!rootFound && node.nodeName!='BODY'){
					rootFound = (rootTag && node.nodeName) ? (node.nodeName.indexOf(rootTag)>-1) : rootFound ;
					rootFound = (rootId && node.id) ? (node.id.indexOf(rootId)>-1) : rootFound ;
					rootFound = (rootClass && node.className) ? (node.className.indexOf(rootClass)>-1) : rootFound ;
					node = (!rootFound) ? node.parentNode : node;
				}
				// pass it back
				return node;
			},
			// gracefully add an event handler
			addEvent : function(node, eventName, eventHandler){
				if('addEventListener' in node){
					node.addEventListener(eventName, eventHandler, false);
				}else if('attachEvent' in node){
					node.attachEvent('on'+eventName, function(event){eventHandler(event)});
				}else{
					node['on'+eventName] = eventHandler;
				}
				return true;
			},
			// trigger an event handler manually
			triggerEvent : function(node, eventName){
				if('fireEvent' in node){
					node.fireEvent('on' + eventName);
				}else if('dispatchEvent' in node){
					var evt = document.createEvent('HTMLEvents');
					evt.initEvent(eventName, false, true);
					node.dispatchEvent(evt);
				}else{
					eval('node.on' + eventName + '()');
				}
				return true;
			},
			// trim whitespace from around a string
			trim : function(string){
				var cu = classBehaviours.utilities;
				return cu.rtrim(cu.ltrim(string));
			},
			ltrim : function(string){
				var left = 0;
				while(left < string.length && string[left] == ' '){
					left++;
				}
				return string.substring(left, string.length);
			},
			rtrim : function(string){
				var right = string.length - 1;
				while(right > 0 && string[right] == ' '){
					right -= 1;
				}
				return string.substring(0, right + 1);
			}
		}

/*
	Source: classbehaviours.parser.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

 		// COMMON PARSER FUNCTIONS
		// create the utilities child object if it doesn't already exist
		if(typeof(classBehaviours.parser)=='undefined') classBehaviours.parser = {
			// timeout constant
			interval : null,
			// verify the state of the object
			start : function(){
				var cp = classBehaviours.parser;
				// check if enough of the DOM was loaded
				if(/interactive|loaded|complete/i.test(document.readyState)){
					// cancel the interval
					clearInterval(cp.interval);
					// start the parser
					setTimeout(function(){cp.parseDocument()}, 100);
				// else if we're not already waiting for another test
				}else if(cp.interval==null){
					// test again
					cp.interval = setInterval(cp.start, 100);
				}
			},
			// scan the whole document
			parseDocument : function(){
				// pass the document object to the parser
				classBehaviours.parser.parseNode(document);
				// return the status
				return false;
			},
			// recursive version of the same function
			parseNode : function(node){
				// process the node
				parseChildNodes = (node.className!=null) ? this.processNode(node) : true ;
				// parse any childnodes
				if(parseChildNodes) for(var a=0; a<node.childNodes.length; a++) this.parseNode(node.childNodes[a]);
			},
			// process the classnames of the node
			processNode : function(node){
				// for all class behaviours
				var wantedClass;
				for(b in classBehaviours.handlers){
					// define the search based on the handler's expected classn ame
					wantedClass = new RegExp('\\b'+classBehaviours.handlers[b].name+'\\b');
					// if the behaviour name is in the className tested node
					if(wantedClass.test(node.className)){
						// apply its respective behaviour
						classBehaviours.handlers[b].start(node);
					}
				}
				// decide if to continue parsing deeper into this branch
				return (node.className.indexOf('doNotParse')<0);
			}
		}

		// initialise the parser manually if jQuery isn't used
		if(typeof(jQuery)=='undefined') classBehaviours.parser.start();

/*
	Source: classbehaviours.handlers.datepicker.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// CLASSNAME BEHAVIOUR FUNCTIONS
		// create the handlers child object if it doesn't already exist
		if(typeof(classBehaviours.handlers)=='undefined') classBehaviours.handlers = {}

			// Enrich a calendar control
			classBehaviours.handlers.datePicker = {
				// properties
				name: 'datePicker',
				dateHtml: '<div class="dateBorder">'
					+ '	<ul class="controls">'
					+ '		<li class="control"><button class="previous"><span>&lt;</span></button></li>'
					+ '		<li class="control">'
					+ '			<select class="month dropDownzzzSelector">'
					+ '				<option value="0">Jan</option>'
					+ '				<option value="1">Feb</option>'
					+ '				<option value="2">Mar</option>'
					+ '				<option value="3">Apr</option>'
					+ '				<option value="4">May</option>'
					+ '				<option value="5">Jun</option>'
					+ '				<option value="6">Jul</option>'
					+ '				<option value="7">Aug</option>'
					+ '				<option value="8">Sep</option>'
					+ '				<option value="9">Oct</option>'
					+ '				<option value="10">Nov</option>'
					+ '				<option value="11">Dec</option>'
					+ '			</select>'
					+ '		</li>'
					+ '		<li class="control">'
					+ '			<select class="year dropDownzzzSelector">'
					+ '				<option value="2011" selected="selected">2011</option>'
					+ '				<option value="2012" selected="selected">2012</option>'
					+ '				<option value="2013" selected="selected">2013</option>'
					+ '				<option value="2014" selected="selected">2014</option>'
					+ '				<option value="2015" selected="selected">2015</option>'
					+ '				<option value="2016" selected="selected">2016</option>'
					+ '				<option value="2017" selected="selected">2017</option>'
					+ '				<option value="2018" selected="selected">2018</option>'
					+ '				<option value="2019" selected="selected">2019</option>'
					+ '				<option value="2020" selected="selected">2020</option>'
					+ '			</select>'
					+ '		</li>'
					+ '		<li class="control"><button class="next"><span>&gt;</span></button></li>'
					+ '	</ul>'
					+ '	<table class="dateTable">'
					+ '		<thead>'
					+ '			<tr>'
					+ '				<th scope="col">sun</th>'
					+ '				<th scope="col">mon</th>'
					+ '				<th scope="col">tue</th>'
					+ '				<th scope="col">wed</th>'
					+ '				<th scope="col">thu</th>'
					+ '				<th scope="col">fri</th>'
					+ '				<th scope="col">sat</th>'
					+ '			</tr>'
					+ '		</thead>'
					+ '		<tbody>'
					+ '			<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>'
					+ '			<tr><td>{7}</td><td>{8}</td><td>{9}</td><td>{10}</td><td>{11}</td><td>{12}</td><td>{13}</td></tr>'
					+ '			<tr><td>{14}</td><td>{15}</td><td>{16}</td><td>{17}</td><td>{18}</td><td>{19}</td><td>{20}</td></tr>'
					+ '			<tr><td>{21}</td><td>{22}</td><td>{23}</td><td>{24}</td><td>{25}</td><td>{26}</td><td>{27}</td></tr>'
					+ '			<tr><td>{28}</td><td>{29}</td><td>{30}</td><td>{31}</td><td>{32}</td><td>{33}</td><td>{34}</td></tr>'
					+ '			<tr><td>{35}</td><td>{36}</td><td>{37}</td><td>{38}</td><td>{39}</td><td>{40}</td><td>{41}</td></tr>'
					+ '		</tbody>'
					+ '	</table>'
					+ '</div>',
				index: 0,
				// methods
				start: function(node){
					// if the node isn't a node, it may be an id
					if(node==null) node = document.getElementById(node);
					// if the classname is on an input element
					if(node.nodeName=='INPUT' || node.nodeName=='SELECT'){
						// give this node an id if it doesn't have one yet
						this.index += 1;
						node.id = (node.id) ? node.id : this.name + this.index ;
						// create a button
						var newPickerButton = document.createElement('button');
						newPickerButton.className = this.name;
						// create a label in the button
						var newPickerWrapper = document.createElement('span');
						newPickerWrapper.innerHTML = 'Pick a date';
						newPickerButton.appendChild(newPickerWrapper);
						// add the button after the input element
						if(node.nextSibling!=null){
							node.parentNode.insertBefore(newPickerButton, node.nextSibling);
						}else{
							node.parentNode.appendChild(newPickerButton);
						}
						// remove the classname from the input element
						node.className = node.className.replace('this.name', '');
						// add the toggle event to the button
						newPickerButton.className += ' toggleNextNode';
						classBehaviours.handlers.toggleNextNode.start(newPickerButton);
						// create the calendar container
						calendarContainer = document.createElement('DIV');
						calendarContainer.className = 'hideThisNode dateCalendar';
						// check if past dates are allowed
						classBehaviours.utilities.setClassParameter(calendarContainer, 'past',
							classBehaviours.utilities.getClassParameter(node, 'past', 'yes')
						);
						// add the calendar to the label
						if(newPickerButton.nextSibling!=null){
							newPickerButton.parentNode.insertBefore(calendarContainer, newPickerButton.nextSibling);
						}else{
							newPickerButton.parentNode.appendChild(calendarContainer);
						}
						// process the template for the calendar
						this.build(null, calendarContainer, this.dateHtml);
						// set the event handlers
						newPickerButton.onmousedown = this.open;
					}
				},
				set: function(calendarNode, date){
					dpr = classBehaviours.handlers.datePicker;
					// get the next and previous buttons
					calendarNode.getElementsByTagName('button')[0].onclick = dpr.previous;
					calendarNode.getElementsByTagName('button')[1].onclick = dpr.next;
					// get the peferences
					allowPast = (classBehaviours.utilities.getClassParameter(calendarNode, 'past', 'yes')=='yes');
					// set the month dropdown
					monthNode = calendarNode.getElementsByTagName('select')[0];
					monthNode.selectedIndex = date.getMonth();
					monthNode.onchange = dpr.update;
					// set the year dropdown
					yearSelect = calendarNode.getElementsByTagName('select')[1];
					yearOptions = yearSelect.getElementsByTagName('option');
					currentYear = date.getFullYear();
					if(yearOptions.length==1){
						yearOption = yearOptions[0].cloneNode(true);
						for(var a=currentYear-100; a<currentYear+10; a++ ){
							yearOption = yearSelect.getElementsByTagName('option')[0].cloneNode(true);
							yearOption.value = a;
							yearOption.selected = (a==currentYear) ? 'selected' : '' ;
							yearOption.text = a;
							yearSelect.appendChild(yearOption);
						}
						yearSelect.removeChild(yearSelect.getElementsByTagName('option')[0]);
						yearSelect.onchange = dpr.update;
					}else{
						for(var a=0; a<yearOptions.length; a++) yearOptions[a].selected = (yearOptions[a].value==currentYear) ? 'selected' : '' ;
					}
					// clear out the previous month
					daySlots = calendarNode.getElementsByTagName('td');
					for(var a=0; a<daySlots.length; a++){
						daySlots[a].className = "empty";
						daySlots[a].innerHTML = "z";
						daySlots[a].onclick = null;
					}
					// fill the new month
					currentDay = new Date(date.getFullYear(), date.getMonth(), 1);
					nextDay = new Date(date.getFullYear(), date.getMonth(), 2);
					startWeekDay = currentDay.getDay() - 1;
					if(startWeekDay>6) startWeekDay -= 7;
					do{
						// put the date on the weekday cell
						daySlots[currentDay.getDate()+startWeekDay].innerHTML = currentDay.getDate();
						// if this is the current day
						if(
							currentDay.getFullYear() == (new Date()).getFullYear() &&
							currentDay.getMonth() == (new Date()).getMonth() &&
							currentDay.getDate() == (new Date()).getDate()
						){
							// apply a style to the day
							daySlots[currentDay.getDate()+startWeekDay].className = "current";
							// set the event handler to pick the date
							daySlots[currentDay.getDate()+startWeekDay].onclick = dpr.pick;
						// else if this is a day in the past
						}else if(
							currentDay.getTime() < (new Date()).getTime()
						){
							// apply a style to the day
							daySlots[currentDay.getDate()+startWeekDay].className = "past";
							// set the event handler to pick the date
							if(allowPast) daySlots[currentDay.getDate()+startWeekDay].onclick = dpr.pick;
						// else if this is a day in the future
						}else{
							// apply a style to the day
							daySlots[currentDay.getDate()+startWeekDay].className = "";
							// set the event handler to pick the date
							daySlots[currentDay.getDate()+startWeekDay].onclick = dpr.pick;
						}
						// next date
						currentDay = new Date(currentDay.getFullYear(), currentDay.getMonth(), currentDay.getDate() + 1);
						nextDay = new Date(nextDay.getFullYear(), nextDay.getMonth(), nextDay.getDate() + 1);
					}while(currentDay.getDate()!=1);
				},
				build: function(buildXml, buildNode, builtTxt){
					// clean the imported xhtml
					buildNode.innerHTML = builtTxt;
					// apply the events
					classBehaviours.parser.parseNode(buildNode);
				},
				// events
				open: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var dpr = classBehaviours.handlers.datePicker;
					// close all other calendars
					dpr.close();
					// OBJECTS
					calendar = classBehaviours.utilities.nextNode(objNode);
					// STARTING DATE
					// get the input from the field
					targetFields = calendar.parentNode.getElementsByTagName('input');
					targetFields = (targetFields.length==0) ? calendar.parentNode.getElementsByTagName('select') : targetFields ;
					if(targetFields.length>2){
						dayField = parseInt(targetFields[0].value);
						monthField = parseInt(targetFields[1].value);
						yearField = parseInt(targetFields[2].value);
					}else{
						targetFieldsValue = targetFields[0].value.split('-');
						dayField = (targetFieldsValue.length>0) ? parseInt(targetFieldsValue[0]) : '' ;
						monthField = (targetFieldsValue.length>1) ? parseInt(targetFieldsValue[1]) : '' ;
						yearField = (targetFieldsValue.length>2) ? parseInt(targetFieldsValue[2]) : '' ;
					}
					// turn it into a date
					startDate = new Date(yearField, monthField-1, dayField);
					// if the result is a date use it as a start date, else take the current date
					theDate = (!isNaN(startDate)) ? startDate : new Date();
					// CONSTRUCT THE CALENDAR AT THE GIVEN DATE
					dpr.set(calendar, theDate);
					// POSITION THE CALENDAR
					// get the position
					screenXpos = (navigator.userAgent.indexOf('MSIE')>-1) ? event.x : that.layerX ;
					screenYpos = (navigator.userAgent.indexOf('MSIE')>-1) ? event.y : that.layerY ;
					// if the position is too close to the edge
					calendarWidth = calendar.firstChild.offsetWidth;
					screenWidth = (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth ;
					scrolledWidth = (typeof(document.documentElement.scrollLeft)!='undefined') ? document.documentElement.scrollLeft : window.pageXOffset ;
					if(screenXpos+calendarWidth > screenWidth+window.pageXOffset) screenXpos -= calendarWidth;
					// if the position is too close to the bottom
					calendarHeight = calendar.firstChild.offsetHeight;
					screenHeight = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight ;
					scrolledHeight = (typeof(document.documentElement.scrollTop)!='undefined') ? document.documentElement.scrollTop : window.pageYOffset ;
					if(screenYpos+calendarHeight+10 > screenHeight+scrolledHeight) screenYpos -= calendarHeight;
					// set the position
					calendar.style.left = screenXpos + 'px';
					calendar.style.top = screenYpos + 'px';
					// SHOW THE CALENDAR
					// hide all the select elements in internet explorer
					if(navigator.userAgent.indexOf('MSIE 6')>-1){
						var allSelects = document.getElementsByTagName('SELECT');
						for(var a=0; a<allSelects.length; a++){
							if(allSelects[a].parentNode.className!='control') allSelects[a].style.visibility = 'hidden';
						}
					}
					// classBehaviours.handlers.toggleNextNode.toggle(objNode, null);
					// prepare to close the calendar
					calendar.onmouseover = dpr.cancel;
					calendar.onmouseout	= dpr.wait;
					return false;
				},
				wait: function(){
					closeCalendarTimeout = setTimeout('classBehaviours.handlers.datePicker.close()',1024);
				},
				cancel: function(){
					if(typeof(closeCalendarTimeout)!='undefined') clearTimeout(closeCalendarTimeout);
				},
				close: function(){
					// show all the select elements in internet explorer
					if(navigator.userAgent.indexOf('MSIE 6')>-1){
						var allSelects = document.getElementsByTagName('SELECT');
						for(var a=0; a<allSelects.length; a++){
							allSelects[a].style.visibility = 'visible';
						}
					}
					// get all buttons that might have open calendars
					allButtons = document.getElementsByTagName('button');
					for(var a=0; a<allButtons.length; a++){
						if(allButtons[a].className.indexOf('datePicker')>-1){
							if(classBehaviours.utilities.nextNode(allButtons[a]).className.indexOf('showThisNode')>-1){
								classBehaviours.handlers.toggleNextNode.toggle(allButtons[a], null);
							}
						}
					}
				},
				update: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var dpr = classBehaviours.handlers.datePicker;
					// get the calendar
					calendar = classBehaviours.utilities.findParentNode(objNode, null, null, 'dateCalendar');
					// get both selectors from the parent node
					selectors = objNode.parentNode.getElementsByTagName('select');
					// get the month
					month = parseInt(selectors[0].value);
					// get the year
					year = parseInt(selectors[1].value);
					// make a date out of it
					theDate = new Date(year, month, 1);
					// update the calendar
					dpr.set(calendar, theDate);
				},
				next: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var dpr = classBehaviours.handlers.datePicker;
					// get the calendar
					calendar = classBehaviours.utilities.findParentNode(objNode, null, null, 'dateCalendar');
					// get the displayed date
					month = parseInt(calendar.getElementsByTagName('select')[0].value);
					year = parseInt(calendar.getElementsByTagName('select')[1].value);
					// add a month
					theDate = new Date(year,month+1,1);
					// build the calendar
					dpr.set(calendar, theDate);
					return false;
				},
				previous: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var dpr = classBehaviours.handlers.datePicker;
					// get the calendar
					calendar = classBehaviours.utilities.findParentNode(objNode, null, null, 'dateCalendar');
					// get the displayed date
					month = parseInt(calendar.getElementsByTagName('select')[0].value);
					year = parseInt(calendar.getElementsByTagName('select')[1].value);
					// subsctract a month
					theDate = new Date(year,month-1,1);
					// build the calendar
					dpr.set(calendar,theDate);
					return false;
				},
				pick: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var cu = classBehaviours.utilities;
					// get the selected day
					dayValue = objNode.innerHTML;
					dayText = ((dayValue+'').length==1) ? '0' + dayValue  : dayValue;
					// get the selected month
					calendar = classBehaviours.utilities.findParentNode(objNode, null, null, 'dateCalendar');
					calendarTitle = calendar.getElementsByTagName('ul')[0];
					month = calendarTitle.getElementsByTagName('select')[0];
					// monthValue = month[month.selectedIndex].innerHTML;
					monthValue = parseInt(month.value) + 1;
					monthText = ((monthValue+'').length==1) ? '0' + monthValue : monthValue;
					// get the selected year
					year = calendarTitle.getElementsByTagName('select')[1];
					yearValue = year[year.selectedIndex].innerHTML;
					yearText = yearValue;
					// put it in the input field
					targetFields = calendar.parentNode.getElementsByTagName('input');
					targetFields = (targetFields.length==0) ? calendar.parentNode.getElementsByTagName('select') : targetFields ;
					if(targetFields[0].nodeName=='SELECT'){
						// find the day in the day selector
						for(var a=0; a<targetFields[0].length; a++) if(parseInt(targetFields[0][a].value)==parseInt(dayValue) || parseInt(targetFields[0][a].text)==parseInt(dayValue)) targetFields[0].selectedIndex = a;
						// find the month in the month selector
						for(var a=0; a<targetFields[1].length; a++) if(parseInt(targetFields[1][a].value)==parseInt(monthValue) || parseInt(targetFields[1][a].text)==parseInt(monthValue)) targetFields[1].selectedIndex = a;
						// find the year in the year selector
						for(var a=0; a<targetFields[2].length; a++) if(parseInt(targetFields[2][a].value)==parseInt(yearValue) || parseInt(targetFields[2][a].text)==parseInt(yearValue)) targetFields[2].selectedIndex = a;
					}else if(targetFields.length>2){
						targetFields[0].value = dayText;
						targetFields[1].value = monthText;
						targetFields[2].value = yearText;
						// remove any input format template
						targetFields[0].className = targetFields[0].className.replace(' passive_yes', ' passive_no');
						targetFields[1].className = targetFields[1].className.replace(' passive_yes', ' passive_no');
						targetFields[2].className = targetFields[2].className.replace(' passive_yes', ' passive_no');
					}else{
						targetFields[0].value = dayText + '-' + monthText + '-' + yearText;
						// trigger any onchange event there
						cu.triggerEvent(targetFields[0], 'change');
						// remove any input format template
						targetFields[0].className = targetFields[0].className.replace(' passive_yes', ' passive_no');
					}
					// close the calendar
					calendarButton = objNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('button')[0];
					classBehaviours.handlers.toggleNextNode.toggle(calendarButton, null);
				}
			}

	// JQUERY WRAPPER
	if(typeof(jQuery)!='undefined'){
		(function($){
			var methods = {
				init : function(options) {
					return this.each(function(){
						classBehaviours.handlers.datePicker.start($(this).context);
					});
				}
			};
			$.fn.datePicker = function(method){
				if(methods[method]) {
					return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
				}else if(typeof method === 'object' || !method){
					return methods.init.apply(this, arguments);
				}else{
					$.error('Method ' +  method + ' does not exist on jQuery.datePicker');
				}
			};
		})(jQuery);

		// JQUERY EVENTS
		$(document).ready(function() {
			$(".datePicker").datePicker();
		});
	}

/*
	Source: classbehaviours.handlers.togglenextnode.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// CLASSNAME BEHAVIOUR FUNCTIONS
		// create the handlers child object if it doesn't already exist
		if(typeof(classBehaviours.handlers)=='undefined') classBehaviours.handlers = {}

			// open or close a container object
			document.writeln("<style>.toggleNextNode{cursor:pointer;}</style>");
			classBehaviours.handlers.toggleNextNode = {
				// properties
				name: 'toggleNextNode',
				step: 10,
				acceleration: 10,
				extra: 0,
				delay: 50,
				index: 0,
				// methods
				start: function(node){
					var t2n = classBehaviours.handlers.toggleNextNode;
					var cu = classBehaviours.utilities;
					// set the event handlers for the source node
					if(node.nodeName=='INPUT' || node.nodeName=='TEXTAREA' || node.nodeName=='SELECT'){
						cu.addEvent(node, 'focus', function(event){t2n.toggle(node, event)});
						cu.addEvent(node, 'blur', function(event){t2n.toggle(node, event)});
					}else{
						cu.addEvent(node, 'click', function(event){t2n.toggle(node, event)});
					}
					// give this node an id if it doesn't have one yet
					node.id = (node.id) ? node.id : t2n.name + t2n.index++ ;
					// is this node marked as "auto", order it to open on a timeout
					autoDelay = cu.getClassParameter(node, 'auto', null);
					if(autoDelay){
						t2n.index++
						node.id = (node.id) ? node.id : t2n.name + t2n.index ;
						setTimeout(function(){
							classBehaviours.handlers.toggleNextNode.toggle(node);
						}, autoDelay);
					}
				},
				findContainer: function(targetLabel, targetRecursion){
					var t2n = classBehaviours.handlers.toggleNextNode;
					var cu = classBehaviours.utilities;
					// if there was a target recursion, recurse parent nodes
					if(targetRecursion) for(var a=0; a<parseInt(targetRecursion); a++) targetLabel = targetLabel.parentNode;
					// get the next sibling of the label, which should be the container
					targetObject = cu.nextNode(targetLabel);
					// give it an ID for reference
					targetObject.id = (targetObject.id) ? targetObject.id : t2n.name + 'Target' + t2n.index++;
					// pass it back
					return targetObject;
				},
				positionContainer: function(targetContainer, screenXpos, screenYpos){
					if(targetContainer.firstChild!=null){
						// if the position is too close to the edge
						targetContainerWidth = targetContainer.firstChild.offsetWidth;
						screenWidth = (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth ;
						scrolledWidth = (typeof(document.documentElement.scrollLeft)!='undefined') ? document.documentElement.scrollLeft : window.pageXOffset ;
						if(screenXpos+targetContainerWidth > screenWidth+window.pageXOffset) screenXpos -= targetContainerWidth;
						// if the position is too close to the bottom
						targetContainerHeight = targetContainer.firstChild.offsetHeight;
						screenHeight = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight ;
						scrolledHeight = (typeof(document.documentElement.scrollTop)!='undefined') ? document.documentElement.scrollTop : window.pageYOffset ;
						if(screenYpos+targetContainerHeight+10 > screenHeight+scrolledHeight) screenYpos -= targetContainerHeight;
						// set the position
						targetContainer.style.left = screenXpos + 'px';
						targetContainer.style.top = screenYpos + 'px';
					}
				},
				// events
				toggle: function(node, event){
					var objNode = node;
					var t2n = classBehaviours.handlers.toggleNextNode;
					var cu = classBehaviours.utilities;
					// get all information on this node
					targetLabel = objNode;
					targetAnchor = (targetLabel.getAttribute('href')!=null) ? (targetLabel.getAttribute('href').indexOf('#')>-1) ? targetLabel.getAttribute('href').split('#')[1] : null : null ;
					targetContainerId = cu.getClassParameter(targetLabel, 'id', targetAnchor);
					targetRecursion = cu.getClassParameter(targetLabel, 'parent', null);
					targetClosable = (cu.getClassParameter(targetLabel, 'closable', 'yes') == 'yes');
					targetAtMouse = (cu.getClassParameter(targetLabel, 'atmouse', 'no') == 'yes');
					targetContainer = (targetContainerId!=null) ? document.getElementById(targetContainerId) : t2n.findContainer(targetLabel, targetRecursion) ;
					// if the target container is not marked for hiding or showing, mark it now
					if(targetContainer.className.indexOf('hideThisNode')<0 && targetContainer.className.indexOf('showThisNode')<0) targetContainer.className += ' showThisNode' ;
					// call for the node to grow or shrink
					targetGrows = (targetContainer.className.indexOf('hideThisNode')>-1);
					if(!targetGrows && targetClosable || targetGrows) t2n.update(targetLabel.id, targetGrows);
					// position the node at the mouse' position if needed
					if(targetAtMouse && targetGrows){
						// get the position
						screenXpos = (typeof(event)!='undefined' && document.all) ? event.x : that.layerX ;
						screenYpos = (typeof(event)!='undefined' && document.all) ? event.y : that.layerY ;
						// set the position
						t2n.positionContainer(targetContainer, screenXpos, screenYpos);
					}
					// cancel the click
					if(event!=null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
				},
				update: function(id, grows){
					var t2n = classBehaviours.handlers.toggleNextNode;
					var cu = classBehaviours.utilities;
					// get all information on this node
					var targetLabel = document.getElementById(id);
					var targetAnchor = (targetLabel.getAttribute('href')!=null) ? (targetLabel.getAttribute('href').indexOf('#')>-1) ? targetLabel.getAttribute('href').split('#')[1] : null : null ;
					var targetContainerId = cu.getClassParameter(targetLabel, 'id', targetAnchor);
					var targetFamily = cu.getClassParameter(targetLabel, 'family', null);
					var targetRecursion = cu.getClassParameter(targetLabel, 'parent', null);
					var targetContainer = (targetContainerId!=null) ? document.getElementById(targetContainerId) : t2n.findContainer(targetLabel, targetRecursion) ;
					// TARGET NODE
					// prepare the container
					targetContainer.style.overflow = 'hidden';
					targetContainer.style.visibility = 'visible';
					// open or close the container
					if(!grows){
						classBehaviours.fader.size(targetContainer, null, 1, t2n.step, t2n.delay, t2n.acceleration, function(){classBehaviours.handlers.hideThisNode.start(targetContainer)});
					}else{
						classBehaviours.fader.size(targetContainer, 1, null, t2n.step, t2n.delay, t2n.acceleration, function(){classBehaviours.handlers.showThisNode.start(targetContainer)});
					}
					// activate the link
					targetLabel.className = (!grows) ? targetLabel.className.replace('active', 'link') : targetLabel.className.replace('link', 'active');
					// PEER NODES
					// get all nodes of this class
					var allNodes = cu.getElementsByClassName(t2n.name);
					// for every node in the node-list
					for(var a=0; a<allNodes.length; a++){
						// get its properties
						var peerLabel = allNodes[a];
						var peerAnchor = (peerLabel.getAttribute('href')!=null) ? (peerLabel.getAttribute('href').indexOf('#')>-1) ? peerLabel.getAttribute('href').split('#')[1] : null : null ;
						var peerContainerId = cu.getClassParameter(peerLabel, 'id', peerAnchor);
						var peerFamily = cu.getClassParameter(peerLabel, 'family', null);
						var peerRecursion = cu.getClassParameter(peerLabel, 'parent', null);
						var peerContainer = (peerContainerId!=null) ? document.getElementById(peerContainerId) : t2n.findContainer(peerLabel, peerRecursion) ;
						// if this node belongs to the same family and is open but has a different id
						if(peerFamily==targetFamily && peerFamily!=null && peerContainer.className.indexOf('hideThisNode')<0 && peerContainer!=targetContainer){
							// prepare the container
							peerContainer.style.overflow = 'hidden';
							peerContainer.style.visibility = 'visible';
							var peerTarget = peerContainer;
							// close the container
							classBehaviours.fader.size(peerContainer, null, 1, t2n.step ,t2n.delay, t2n.acceleration, function(){classBehaviours.handlers.hideThisNode.start(peerTarget)});
							// de-activate the link
							peerLabel.className = peerLabel.className.replace('active', 'link');
						}
					}
				}
			}

			// hide the "hideThisNode" class behaviour by default
			document.writeln("<style>.hideThisNode{overflow:hidden; visibility:hidden; height:1px;}</style>");
			classBehaviours.handlers.hideThisNode = {
				// properties
				name: 'hideThisNode',
				// methods
				start: function(node){
					node.style.overflow = 'hidden';
					node.style.visibility = 'hidden';
					node.style.height = '1px';
					node.className = node.className.replace('showThisNode', 'hideThisNode');
				}
			}

			// explicit opposite of a hidden node
			document.writeln("<style>.ShowThisNode{overflow:visible; visibility:visible; height:auto;}</style>");
			classBehaviours.handlers.showThisNode = {
				// properties
				name: 'showThisNode',
				// methods
				start: function(node){
					node.style.overflow = 'visible';
					node.style.visibility = 'visible';
					node.style.height = 'auto';
					node.className = node.className.replace('hideThisNode', 'showThisNode');
				}
			}

	// JQUERY WRAPPER
	if(typeof(jQuery)!='undefined'){
		(function($){
			var methods = {
				init : function(options) {
					return this.each(function(){
						classBehaviours.handlers.toggleNextNode.start($(this).context);
					});
				},
				hideThisNode : function(){
					return this.each(function(){
						classBehaviours.handlers.hideThisNode.start($(this).context);
					});
				},
				showThisNode : function(){
					return this.each(function(){
						classBehaviours.handlers.showThisNode.start($(this).context);
					});
				}
			};
			$.fn.toggleNextNode = function(method){
				if(methods[method]) {
					return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
				}else if(typeof method === 'object' || !method){
					return methods.init.apply(this, arguments);
				}else{
					$.error('Method ' +  method + ' does not exist on jQuery.togglenextnode');
				}
			};
		})(jQuery);

		// JQUERY EVENTS
		$(document).ready(function() {
			$(".toggleNextNode").toggleNextNode();
			$(".hideThisNode").toggleNextNode('hideThisNode');
			$(".showThisNode").toggleNextNode('showThisNode');
		});
	}

/*
	Source: classbehaviours.handlers.inputformat.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// CLASSNAME BEHAVIOUR FUNCTIONS
		// create the handlers child object if it doesn't already exist
		if(typeof(classBehaviours.handlers)=='undefined') classBehaviours.handlers = {}

			// keeps a formatting template of an input field
			classBehaviours.handlers.inputFormat = {
				// properties
				name: 'inputFormat',
				// methods
				start: function(node){
					// set event handlers
					node.onfocus = this.clear;
					node.onmousedown = this.clear;
					node.onblur = this.restore;
			//		node.onchange = this.restore;
					classBehaviours.utilities.addEvent(node, 'change', this.restore);
					// remember if this was a password field
					if(node.type=='password') classBehaviours.utilities.setClassParameter(node, 'type', 'password');
					// invoke initial state
					this.restore(node);
				},
				// events
				clear: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var lip = classBehaviours.handlers.inputFormat;
					// clear the field and make it active
					if(objNode.value == objNode.getAttribute('placeholder')){
						objNode.value = '';
						classBehaviours.utilities.setClassParameter(objNode, 'passive', 'no');
						inputType = classBehaviours.utilities.getClassParameter(objNode, 'type', 'text');
						if(inputType=='password' && objNode.type=='text') objNode.type = 'password';
					}
					// turn the password into *******
					if(objNode.getAttribute('type')=='text' && objNode.className.indexOf('type_password')>-1){
						if(navigator.userAgent.indexOf('MSIE')<0){
							objNode.setAttribute('type', 'password');
						}else{
							targetId = objNode.id;
							targetParent = objNode.parentNode;
							targetParent.innerHTML = targetParent.innerHTML.replace(' placeholder=', ' type="password" placeholder=');
							setTimeout('document.getElementById("'+targetId+'").focus()',100);
						}
					}
					// focus the input element
					objNode.focus();
				},
				restore: function(that){
					var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
					var lip = classBehaviours.handlers.inputFormat;
					// insert the title as a format template and mark the field as passive (until clicked)
					if(objNode.value == '' || objNode.value == objNode.getAttribute('placeholder')){
						objNode.value = objNode.getAttribute('placeholder');
						classBehaviours.utilities.setClassParameter(objNode, 'passive', 'yes');
						inputType = classBehaviours.utilities.getClassParameter(objNode, 'type', 'text');
						if(inputType=='password' && objNode.type=='password') objNode.type = 'text';
					}
					// turn the password into tekst
					if(objNode.getAttribute('type')=='password' && objNode.className.indexOf('type_password')>-1 && objNode.getAttribute('placeholder')==objNode.value){
						if(navigator.userAgent.indexOf('MSIE')<0){
							objNode.setAttribute('type', 'text');
						}else{
							targetParent = objNode.parentNode;
							targetParent.innerHTML = targetParent.innerHTML.replace('type="password"', 'type="text"');
						}
					}
				}
			}

	// JQUERY WRAPPER
	if(typeof(jQuery)!='undefined'){
		(function($){
			var methods = {
				init : function(options) {
					return this.each(function(){
						classBehaviours.handlers.inputFormat.start($(this).context);
					});
				}
			};
			$.fn.inputFormat = function(method){
				if(methods[method]) {
					return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
				}else if(typeof method === 'object' || !method){
					return methods.init.apply(this, arguments);
				}else{
					$.error('Method ' +  method + ' does not exist on jQuery.inputFormat');
				}
			};
		})(jQuery);

		// JQUERY EVENTS
		$(document).ready(function() {
			$(".inputFormat").inputFormat();
		});
	}

