﻿
// -----------------------------------------------------
// --CORE.JS--------------------------------------------
// -----------------------------------------------------


/* Fix ie6 background image caching
-------------------------------------------------------------------------*/
try 
{
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


/* Shortcut functions
-------------------------------------------------------------------------*/
// shortcut for document.getElementById;
function $id(name) 
{
	return document.getElementById(name);
}

// returns the elements with the supplied classname and optional tagname as childs of the supplied parent
function $class(name,parent,tag) 
{
	var selElements = [];
	var parent = typeof(parent) != "undefined" ? parent : document;
	var tag = typeof(tag) != "undefined" ? tag : "*";
	var elements = $tag(tag,parent);
	for (var i=elements.length-1;i>=0;i--) 
	{
		if (Element.Class.Contains(elements[i],name)) 
		{
			selElements.push(elements[i]);
		}
	}
	return selElements;
}

// returns the elements with the supplied tagname as childs of the supplied parent
function $tag(name,parent) 
{
	return parent ? parent.getElementsByTagName(name) : document.getElementsByTagName(name);
}

// creates a dom element, optional text param, if supplied a textnode is added
function $createDom(tag,text) 
{
	var element = null;
	
	if (typeof(document.createElementNS) != 'undefined') 
	{
		//Better to use html: before the tag, but in that case items could not be found
		element = document.createElementNS('http://www.w3.org/1999/xhtml', tag);  
	}
	else
	{
		element = document.createElement(tag);
	}
		
	if (typeof(text) != "undefined") 
	{
	        var tmpText = text;
	        try
	        {
                if (tag.toLowerCase() == "p")
                { 		    
		            tmpText =  text.replace(/<p>/g,"").replace(/<\/p>/g,"<br />");
		        }
		    }
		    catch(err)
		    {
		        var errorText = "";
		    }
			element.innerHTML = tmpText; 
	} 
	
	//	element.appendChild(document.createTextNode(text));}
	return element;
}

// returns the first parent element matching the given tag name
function $parent(tag,obj) 
{
	if(!obj) { return null; }
	if (obj.parentNode) 
	{
		while(obj = obj.parentNode) 
		{
			if (tag === obj.nodeName.toLowerCase()) 
			{
				return obj;
			}
		}
	}
	return null;
}



/* Element related 
-------------------------------------------------------------------------*/
Element = 
{
	// remove element, if removeObservers is true all observers on this element and its subnodes are removed
	Remove:function(obj,removeObservers) 
	{		
		if(obj.parentNode)
		{			
			if (typeof(removeObservers) != "undefined" && removeObservers) 
			{
				var elements = $tag("*",obj);
				
				for(var i=0;i<elements.length;i++) 
				{
					Event.RemoveBoundTo(elements[i]);
				}
			}
			obj.parentNode.removeChild(obj);
		}
	},
	
	// removes all the children nodes of an element
	RemoveChildren:function(obj,removeObservers) 
	{
		var elements = $tag("*",obj);//obj.childNodes;
		
		for (var i=elements.length-1;i>=0;i--) 
		{
			Element.Remove(elements[i],removeObservers);
		}
	},
	
	// checks if the child is a subnode of the parent
	IsChild:function(parent,child) 
	{
		if (child.parentNode) 
		{
			while(child = child.parentNode) 
			{
				if (parent === child) 
				{
					return true;
				}
			}
		}
		return false;
	},
	// find a specific element as a child of the supplied parent
	FindElement:function(parent,name)
	{
		if(!parent || !name) { return false; }
		return Element.SearchChildren(parent,name);
	},
	// Recursive function:
	// Check if this element is the needed one.
	// if not, check all child elements.
	SearchChildren:function(parent,name)
	{
		if(parent.id == name) { return parent; }
		if(parent.hasChildNodes()) {
			for(var i=0; i<parent.childNodes.length; i++) {
				if(parent.childNodes[i]) {
					var obj = Element.SearchChildren( parent.childNodes[i], name );
					if(obj) { return obj; }
				}
			}
		}
	},
	
	SearchParent:function(tag,element)
	{
		if(element.nodeName.toLowerCase() === tag) { return element; }
		if(element.parentNode) {
			var obj = Element.SearchParent( tag, element.parentNode );
			if(obj) { return obj; }
		}
	},
	
	//Functions for altering the style classes of an element
	Class:
	{
		// adds a classname to the supplied obj classes
		Add:function(obj,name) 
		{
			if (!Element.Class.Contains(obj,name)) 
			{
				if(obj)
				{
					obj.className += " " + name;
				}
			}
		},
		// checks wether an obj contains a certain class
		Contains:function(obj,name) 
		{
			if(!obj) { return false; }
			return (obj.className.indexOf(name)!=-1);
		},
		// removes the class name from the obj
		Remove:function(obj,name) 
		{
			if(obj) {
				obj.className = obj.className.replace(name,"");
			}
		}
	},
	
	// returns the position of the element
	Position:function(obj) 
	{
  		var pos = {x:0,y:0};
  		if (obj.offsetParent) 
  		{
  			pos.x = obj.offsetLeft;
  			pos.y = obj.offsetTop;
  			
  			while(obj = obj.offsetParent) 
  			{
  				pos.x += obj.offsetLeft;
  				pos.y += obj.offsetTop;
  			}
  			
  		}
  		return pos;
	},
	//Set the focus on an element
	Focus:function(obj)
	{
	    obj.focus();
	},
	//Toggle visibility for an element
	Visibility:
	{
		//Hide the specified element
		Hide:function(obj) 
		{
			if (obj.style) 
			{
				obj.style.display = "none";
			}
		},
		//Show the specified element
		Show:function(obj) 
		{
			if (obj.style) 
			{
				obj.style.display = "";
			}
		},
		//Toggle the specified elements visibility
		Toggle:function(obj) 
		{
			if (obj.style) 
			{
				obj.style.display = obj.style.display == "none" ? "" : "none";
			}
		},
		//Set the visibility to a certain type
		Set:function(obj,setting) 
		{
			if (obj.style) 
			{
				obj.style.display = setting;
			}
		},
		//Check the visibility of a certain element
		IsVisible:function(obj)
		{
			if (obj.style) 
			{
				return obj.style.display != "none";
			}
			return true;
		}
	},
	
	// returns the dimension {width:0,height:0} of the supplied obj
	Dimensions:function(obj) 
	{
  		var dim = {width:0,height:0};
  		dim.width = obj.offsetWidth || 0;
  		dim.height = obj.offsetHeight || 0;
  		return dim;
	}
}

//Handler for page operations
PageHandler = 
{
	// returns the dimension {width:0,height:0} of the current window
	Dimensions:function() 
	{
  		var dim = {width:0,height:0};
	  	
  		if (window.innerHeight) 
  		{
  			dim.height = window.innerHeight;
  			dim.width = window.innerWidth;
  		}
  		else if (document.documentElement) 
  		{
  			dim.height = document.documentElement.clientHeight;
  			dim.width = document.documentElement.clientWidth;
  		}
  		else if (document.body) 
  		{
  			dim.height = document.body.clientHeight;
  			dim.width = document.body.clientWidth;
  		}
	  	
  		return dim;
	},
	//Functions for working with flash elements
	Flash:
	{
		//IE blocks flash activation
		//By rewriting the innerHTML we will fix this!
		IEFlashActivation:function()
		{
			if(Browser.IsModern() && !$IS_IE) { return ; }

			PageHandler.Flash.SwapFlashObjects();
		},
		SwapFlashObjects:function()
		{
			//An array of ids for flash detection
			var stripQueue = [];
			//Get a list of all ActiveX objects
			var objects = $tag('object');
			for (var i=0; i<objects.length; i++){			
				var o = objects[i];	
				var h = o.outerHTML;
				//The outer html omits the param tags, so we must retrieve and insert these separately
				var params = "";
				var hasFlash = true;
				for (var j = 0; j<o.childNodes.length; j++) {
					
					var p = o.childNodes[j];
					if (p.tagName == "param" || p.tagName=="PARAM")
					{			
						params += p.outerHTML;		       
					}
				}	
					
				//Get the tag and attributes part of the outer html of the object
				var tag = h.split(">")[0] + ">";			
				//Add up the various bits that comprise the object:
				//The tag with the attributes, the params and it's inner html
				var newObject = tag + params + o.innerHTML + " </object>";	
				
				//And rewrite the outer html of the tag 
				o.outerHTML = newObject;
				
				/*o.style.display = "block";*/
				
				$id("flashHiderItem").disabled = true; 
				//Element.Remove($id("flashHiderItem"),true);
			}
			//Strip flash objects
			if (stripQueue.length) {
				PageHandler.Flash.StripFlashObjects(stripQueue)
			}
		},
		//Loop through an array of ids to strip
		//Replace the object by a div tag containing the same innerHTML.
		//To display an alternative image, message for the user or a link to the flash installation page, place it inside the object tag.  
		//For the usual object/embed pairs it needs to be enclosed in comments to hide from gecko based browsers.
		StripFlashObjects:function(stripQueue){
			for (var i=0; i<stripQueue.length; i++){
				var o = document.getElementById(stripQueue[i]);
				var newHTML = o.innerHTML;	
				//Strip the comments
				newHTML = newHTML.replace(/<!--\s/g, "");
				newHTML = newHTML.replace(/\s-->/g, "");
				//Neutralise the embed tag
				newHTML = newHTML.replace(/<embed/gi, "<span");		
				//Create a new div element with properties from the object
				var d = document.createElement("div");
				d.innerHTML = newHTML;
				d.className = o.className;
				d.id = o.id;
				//And swap the object with the new div
				o.parentNode.replaceChild(d, o);
			}
		}
	},	
	//Functions for altering dropdowns 
	SelectBoxes: 
	{
		//Show all the dropdown boxes
		Show:function() 
		{
			var selectBoxes = $tag("select");
			for (var i=0;i<selectBoxes.length;i++) 
			{
				selectBoxes[i].style.visibility = "";
			}
		},
		//Hide the dropdowns on the screen
		Hide:function(type) 
		{
			var selectBoxes = $tag("select");
			//iterate through the selectboxes
			for (var i=0;i<selectBoxes.length;i++) 
			{
				//If the type that opened is calender check if some items should stay displayed
				if(type=="calendar")
				{
					//Traveltype hiding gives a weird look
					if(selectBoxes[i].id.indexOf("travelType") > -1) { continue; }
				}
				selectBoxes[i].style.visibility = "hidden";
			}
		},
		//Hide the dropdowns, but not the items within a certain element
		HideAllExceptChildrenOf:function(element,type) 
		{
			//Hide all
			this.Hide(type);
			//Add for the items embedded in element set the visibility on true
			if(element)
			{
				var selectBoxes = $tag("select",element);			
				for(var i=0;i<selectBoxes.length;i++) 
				{
					selectBoxes[i].style.visibility = "";
				}
			}
		}
	}
}


/* Event related 
-------------------------------------------------------------------------*/
$OBSERVERS_LIST = [];

//Functions for eventhandling
Event = 
{
	// returns the correct event
	GetEvent:function(e) 
	{
		return e || window.event;
	},
	// stop the event propagation from event e
	Stop:function(e) 
	{
		if(!e) { return false; }
		var e = Event.GetEvent(e);
		e.cancelBubble = true;
		if (e.preventDefault) {e.preventDefault();}
		if (e.stopPropagation) {e.stopPropagation();}
	},
	// returns the element that fired the event e
	GetElement:function(e,name) 
	{
		if(!e) { return null; }
		var e = Event.GetEvent(e);
		var obj = !e.target ? e.srcElement : e.target;
		
		if (typeof(name) != "undefined") 
		{
			while(obj.parentNode && obj.nodeName.toLowerCase() != "label") 
			{
				obj = obj.parentNode;
			}
		}
		return obj;
	},
	// attaches an event listener to an element obj
	Observe:function(obj,name,func,capture) 
	{
		var success = false;
		if (obj.addEventListener) 
		{
			obj.addEventListener(name,func,capture); 
			success = true;
		}
		if (obj.attachEvent) 
		{
			obj.attachEvent("on" + name,func); 
			success = true;
		}
		if (success) 
		{
			$OBSERVERS_LIST.push({Object:obj,Name:name,Function:func,Capture:capture});
			return true;
		}
		return false;
	},
	// removes an event listener from element obj and removes it from the observer list
	Remove:function(obj,name,func,capture) 
	{
		Event.Detach(obj,name,func,capture);
		Event.RemoveFromEventList(obj,name,func,capture);
	},
	//Detach an event listener from an element
	Detach:function(obj,name,func,capture) 
	{
		if(func == null) { return true; }
		if (obj.removeEventListener) 
		{
			obj.removeEventListener(name,func,capture); 
			return true; 
		}
		if (obj.detachEvent) 
		{
			return (obj.detachEvent("on" + name,func));
		}
		return false;
	},
	// removes an event from the event list
	RemoveFromEventList:function(obj,name,func,capture) 
	{
		for (var i=$OBSERVERS_LIST.length-1;i>=0;i--) 
		{
			if (obj == $OBSERVERS_LIST[i].Object && name == $OBSERVERS_LIST[i].Name && func == $OBSERVERS_LIST[i].Function && capture == $OBSERVERS_LIST[i].Capture) 
			{
				$OBSERVERS_LIST.splice(i,1);
			}
		}
	},
	// removes all event listeners
	RemoveAll:function() 
	{
		for (var i=$OBSERVERS_LIST.length-1;i>=0;i--) 
		{
			Event.Detach($OBSERVERS_LIST[i].Object,$OBSERVERS_LIST[i].Name,$OBSERVERS_LIST[i].Function,$OBSERVERS_LIST[i].Capture);
			$OBSERVERS_LIST.splice(i,1);
		}
	},
	// removes all event listeners bound to children of the supplied element
	RemoveIn:function(obj) 
	{
		for (var i=$OBSERVERS_LIST.length-1;i>=0;i--) 
		{
			if (Element.IsChild(obj,$OBSERVERS_LIST[i].Object)) 
			{
				Event.Detach($OBSERVERS_LIST[i].Object,$OBSERVERS_LIST[i].Name,$OBSERVERS_LIST[i].Function,$OBSERVERS_LIST[i].Capture);
				$OBSERVERS_LIST.splice(i,1);
			}
		}
	},
	// removes all event listeners bound to the supplied element
	RemoveBoundTo:function(obj) 
	{
		for (var i=$OBSERVERS_LIST.length-1;i>=0;i--) 
		{
			if (obj == $OBSERVERS_LIST[i].Object) 
			{
				Event.Detach($OBSERVERS_LIST[i].Object,$OBSERVERS_LIST[i].Name,$OBSERVERS_LIST[i].Function,$OBSERVERS_LIST[i].Capture);
				$OBSERVERS_LIST.splice(i,1);
			}
		}
	},
	// get the key code
	Key:function(e) 
	{
		var e = Event.GetEvent(e);
		if (typeof(e.keyCode) == "number") 
		{
			return e.keyCode; 
		}
		else if (typeof(e.which) == "number") 
		{
			return e.which; 
		}
		else if (typeof(e.charCode) == "number") 
		{
			return e.charCode; 
		}
		return null;
	},	
	// get key name
	KeyName:function(e) 
	{
		var keyCode = Event.Key(e);
		return (keyCode != null ? String.fromCharCode(keyCode) : null);
	},	
	// mouse properties
	Mouse:
	{
		// get position
		Position:function(e) 
		{
		  var e = Event.GetEvent(e);
			var pos = {x:0,y:0};
			
    		if (e.pageX || e.pageY)	
    		{
    			pos.x = e.pageX;
    			pos.y = e.pageY;
    		}
    		else if (e.clientX || e.clientY) 	
    		{
    			pos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    			pos.y = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
    		}
			return pos;
		},
		// get pressed button 
		Button:function(e) 
		{
			var e = Event.GetEvent(e);
		}
	}
}

/* Functions for form Handling 
-------------------------------------------------------------------------*/
FormHandler = 
{
	DisableEnter:function(e)
	{
		if(e) {
			var key = Event.Key(e);
			if(key == 13) {
				Event.Stop(e);
				return false;
			} else {
				return true;
			}
		}
		return false;
	},

	//Handlers for selectboxes
	SelectBox: 
	{
		//Set a certain value in the selectbox
		SetValue : function(element,value) 
		{
			if(!element || !element.options) { return; }
			
			for(var optionCounter = 0; optionCounter < element.options.length; optionCounter++)
			{
				if(element.options[optionCounter].value == value)
				{
					element.options[optionCounter].selected = true;
					return;
				}
			} 		
		},
		//Get the value of a dropdown (default value will be given is none is selected)
		GetValue:function(element,defaultValue)
		{
			if(!element || !element.options) { return defaultValue; }
			try
			{
				
				if(element.options[element.selectedIndex].value!=null && element.options[element.selectedIndex].value.length && element.options[element.selectedIndex].value.length > 0)
				{
					return element.options[element.selectedIndex].value;
				}
				else if(element.options[element.selectedIndex].text!=null && element.options[element.selectedIndex].text.length && element.options[element.selectedIndex].text.length > 0)
				{
					return element.options[element.selectedIndex].text;
				}
				else
				{
					return defaultValue;
				}
			}
			catch(ex)
			{
				return defaultValue;
			}
		}
	}
}


/* Bind function from prototype library
-------------------------------------------------------------------------*/
//Bind the THIS scope to a function
Function.prototype.bind = function(obj) 
{
	var method = this;
	temp = function() 
	{
		return method.apply(obj, arguments);
	};
	return temp;
} 


/* IsModern browser check
-------------------------------------------------------------------------*/

Browser = 
{
	//Check if the browser is modern
	IsModern:function() 
	{
		return (typeof(document.body.style.maxHeight) != "undefined");
	}
}


/* String extensions
-------------------------------------------------------------------------*/
//Get the width of a string
String.prototype.GetWidth = function() 
{
	var span = $createDom("span",this);
		span.style.visibility = "hidden";
	$tag("body")[0].appendChild(span);
	var width = span.offsetWidth;
	span.parentNode.removeChild(span);
	return width;
}

String.prototype.StripNumbers = function()
{
	var numbers = "0123456789";
	var s = "";
	for(var i=0; i<this.length; i++)
	{
		if( numbers.indexOf(this[i]) < 0)
		{
			s += this[i];
		}
	}
	return s;
}

//Encode the url
String.prototype.URLEncode = function()
{
    return escape(this);
}

// Shorten the string by looking at the size (Slow!)
String.prototype.ShortenByWidth = function(width,useDots) 
{
	var shortStr = new String();
	if (this.GetWidth() > width) 
	{		
		shortStr = this.substr(0,Math.floor(this.length - (this.length/4)));		
		while(shortStr.GetWidth() > width) 
		{
			shortStr = shortStr.substr(0,Math.floor(shortStr.length - (shortStr.length/4)));
		}
		return shortStr.Trim() + (useDots?"..":"");
	}
	return this;
}

//The chars is the maximum amount of characters to be displayed (including ..)
String.prototype.Shorten = function(chars,useDots) 
{
	return (this.length>chars ? (this.substring(0,chars-2) + "..") : this);
}

//Trim a string
String.prototype.Trim = function() 
{
	var str = this;
	var i = 0;
	var j = str.length-1;
	while(str.charAt(i) == " ")	{ i++;}
	while(str.charAt(j) == " ")	{ j--;}
	if (i > 0 || j > 0)	{ str = str.substring(i,j+1); }
	return str;
}


/* Date extension
-------------------------------------------------------------------------*/
var $MONTHNAMES = new Array();
var $MONTHSHORTNAMES = new Array(); 
var $DAYSHORTNAMES = new Array(); 
var $DAYNAMES = new Array(); 

function InitilizeDateTexts ()
{
	//Get the names of the months and days from the multilang util
		$MONTHNAMES =	[
							"Januari",
							"Februari",
							"Maart",
							"April",
							"Mei",
							"Juni",
							"Juli",
							"Augustus",
							"September",
							"October",
							"November",
							"December"
						];
	$MONTHSHORTNAMES =	[
							"JAN",
							"FEB",
							"MAR",
							"APR",
							"MEI",
							"JUN",
							"JUL",
							"AUG",
							"SEP",
							"OCT",
							"NOV",
							"DEC"
						];
	$DAYSHORTNAMES =	[
							"Zo",
							"Ma",
							"Di",
							"Wo",
							"Do",
							"Vr",
							"Za"
						];
	$DAYNAMES =		[
							"Zondag",
							"Maandag",
							"Dinsdag",
							"Woensdag",
							"Donderdag",
							"Vrijdag",
							"Zaterdag"
						];

}

//Initialize day texts
InitilizeDateTexts();


//Get the day index of the date
Date.prototype.getFirstDay = function() 
{
	var day = new Date(this.getFullYear(),this.getMonth(),1);
	var dayNr = day.getDay();	
	return (dayNr == 0 ? 7 : dayNr);
}

//Get the total number of days available in the mont/year combination (if left empty the month/year of the date object is fetched)
Date.prototype.getTotalDays = function(month,year) 
{
	if(month == null)
	{
		month = this.getMonth();
	}
	if(year == null)
	{
		year = this.getFullYear();	
	}
	
	if(month == 6) { return 31; }
	else if(month == 1) { return (this.isLeapYear(year) ? 29 : 28) }
	else
	{
		if(month >= 7)
		{
			return (month%2==0 ? 30 : 31);
		}
		else
		{
			return (month%2==0 ? 31 : 30);
		}
	}
}

//Check if the selected year is a leapyear
Date.prototype.isLeapYear = function(year) 
{
	if(year == null)
	{
		year = this.getFullYear();
	}
	return ((year %4 == 0) || (year %400==0 && year %100==0));
}

//Get the amount of weeks in a month
Date.prototype.getWeeksInMonth = function() 
{
	return Math.ceil((this.getFirstDay + this.getTotalDays)/7);
}

//Increase the month count with 1
Date.prototype.addMonth = function() 
{
	var month = this.getMonth();
	var year = this.getFullYear();
	
	if (month==11) 
	{
		year++;
		month=0;
	} 
	else 
	{
		month++;
	}
	
	return new Date(year,month,1);
}

//Increase the current with with # days
Date.prototype.addDays = function(days) 
{
    var currentDate = this;
    while (days != 0)
    {
        if (days > 0)
        {
            var totalDays = currentDate.getTotalDays();
            var currentDay = currentDate.getDate();
            
            if (currentDay+1 > totalDays)
            {
                currentDate.setDate(1);
                currentDate = currentDate.addMonth();
            }
            else
            {
                currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDay + 1);
            }
            days = days - 1;
        }    
	}
	return currentDate;
}


//Substract a month
Date.prototype.subtractMonth = function() 
{
	var month = this.getMonth();
	var year = this.getFullYear();
		
	if (month==0) 
	{
		year--;
		month=11;
	} 
	else 
	{
		month--;
	}
	
	return new Date(year,month,1);
}

//Add a number of months to the date
Date.prototype.addMonths = function(amount) 
{
	var month = this.getMonth();
	var year = this.getFullYear();
	
	for (var i=0;i<amount;i++) 
	{
		if (month==11) 
		{
			year++;
			month=0;
		} 
		else 
		{
			month++;
		}
	}
	return new Date(year,month,this.getDate());
}

//Check if the provided parameters match the date
Date.prototype.matches = function(year,month,day) 
{
	return (year == this.getFullYear() && month == this.getMonth() && day == this.getDate());
}

//Format a date for displaying
Date.prototype.format = function(str) 
{
	str = str.replace(/%mmmm/,$MONTHNAMES[this.getMonth()]);
	str = str.replace(/%mmm/,$MONTHSHORTNAMES[this.getMonth()]);
	str = str.replace(/%mm/,((this.getMonth()+1)<10?"0"+(this.getMonth()+1):this.getMonth()+1));
	str = str.replace(/%m/,this.getMonth()+1);
	str = str.replace(/%dd/,(this.getDate()<10?"0"+this.getDate():this.getDate()));
	str = str.replace(/%d/,this.getDate());
	str = str.replace(/%wwww/,$DAYNAMES[this.getDay()]);
	str = str.replace(/%www/,$DAYSHORTNAMES[this.getDay()]);
	str = str.replace(/%yyyy/,this.getFullYear());
	str = str.replace(/%yy/,this.getFullYear().toString().substr(2,2));
	return str;
}

//Check if the date object is earlier then the parameter
Date.prototype.earlierThen = function(date) 
{
	return (parseInt(this.format("%yyyy%mm%dd")) < parseInt(date.format("%yyyy%mm%dd")));
}
//Check if the date object is earlier then or equal to the parameter
Date.prototype.earlierThenOrEqual = function(date) 
{
	return (parseInt(this.format("%yyyy%mm%dd")) <= parseInt(date.format("%yyyy%mm%dd")));
}
//Check if the date is equal (time is ignored)
Date.prototype.equals = function(date)
{
	return (parseInt(this.format("%yyyy%mm%dd")) == parseInt(date.format("%yyyy%mm%dd")));
}

Date.fromDDMMYYYY = function(date)
{
	date = "" + date;
	if(date.indexOf("-") > 0)
	{
		var tempDate = new Date();
			tempDate.setFullYear(date.split('-')[2]*1, date.split('-')[1]*1 - 1, date.split('-')[0]*1 );
		return tempDate;
	}
	return false;
}







