var today = getToday();
var noDaysperMonth = [31,0,31,30,31,30,31,31,30,31,30,31];
var dayList = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday'];
var monthList = ['January','February','March','April','May','June','July','August','September','October','November','December'];

var dimUnit = "px";
var opera = (navigator.appName.indexOf("Opera") >= 0);
var mozilla = (navigator.appName.indexOf('Netscape') >= 0);
var internetExplorer = (navigator.appName.indexOf('Microsoft Internet Explorer') >= 0);

if(typeof(window.external) != 'undefined')
{
	document.getElementsByName = function(name, tag)
	{
		if(!tag){tag = '*';}
		var elems = document.getElementsByTagName(tag);
		var res = []
		for(var i=0;i<elems.length;i++)
		{
			att = elems[i].getAttribute('name');
			if(att == name)
			{
				res.push(elems[i]);
			}
		}

		return res;
	}
}

function addElement(element, parent, tagname, before_element)
{
	var object;

	if(isObject(document) && isObject(parent) && typeof(element) == "string" && typeof(tagname) == "string")
	{
		var id = parent.id + ((parent.id == '') ? '' : '_') + tagname;
		object = getObject(id);
		if(!isObject(object))
		{
//			if(typeof(name) == "string" && name != ''){element = "<" + element + " NAME='" + name + "'>";}
			object = document.createElement(element);
			object.id = id;
			if(isObject(before_element)){parent.insertBefore(object, before_element);}
			else{parent.appendChild(object);}
//debug(id);
		}
	}

	return object;
}

//==========================================
// Check all or uncheck all?
//==========================================

/*
function toggleCheckbox(fmobj) 
{
	var setTo = ($(fmobj).All.checked) ? true : false;
	
	for (i = 0; i < $(fmobj).list.length; i++)
		$(fmobj).list[i].checked = setTo;

	
	$(fmobj).Hotel.checked= setTo;
	$(fmobj).BedAndBreakfast.checked= setTo;
	$(fmobj).Guesthouse.checked= setTo;
	$(fmobj).Campsite.checked= setTo;
	$(fmobj).Apartment.checked= setTo;
	$(fmobj).Cottage.checked= setTo;
	$(fmobj).Lodge.checked= setTo;
	$(fmobj).Villa.checked= setTo;
	$(fmobj).Resort.checked= setTo;
}
*/

function formatnumfordate(nVal)
{
	if(nVal < 10)
	{
		nVal = '0' + nVal;
	}
	
	return nVal;

}



function toggleCheckbox() 
{
	var setTo = false;
	
	if(jQuery('#All').is(':checked'))
	{
		setTo = true;
	}
	else
	{
		setTo = false;
	}
	
	jQuery('#Hotel').attr('checked', setTo);
	jQuery('#Hostel').attr('checked', setTo);
	jQuery('#Motel').attr('checked', setTo);
	jQuery('#GuesthouseAndBedAndBreakfast').attr('checked', setTo);
	jQuery('#Campsite').attr('checked', setTo);
	jQuery('#ApartmentAndVilla').attr('checked', setTo);
	jQuery('#Resort').attr('checked', setTo);
	
}

function addTable(parent)
{
	var object;
	var table = addElement('table', parent, 'Table');

	if(table)
	{
		table.setAttribute('cellPadding', 0);
		table.setAttribute('cellSpacing', 0);
		table.setAttribute('border', 0);
			
		object = addElement('tbody', table, 'Tbody');
	}

	return object;
}

function addCombo(parent, id, color, bgcolor, main_object)
{
	var object = addElement('div', parent, id)

	if(object)
	{
		object.value = 0;

		var oCombo = addElement('div', object, 'Combo')

		if(oCombo)
		{
			var width = oCombo.offsetWidth;
			setOverflow(oCombo, 'hidden');
			setSize(oCombo, 4.5, null, 'em');
			setSize(oCombo, oCombo.offsetWidth + (-3 * 2));

			var oSelect = addElement('select', oCombo, 'Select');

			if(isObject(oSelect))
			{
				var margin = -3;
				setFontSize(oSelect, 9);
				setColor(oSelect, color);
				setBgColor(oSelect, bgcolor);
				setMargin(oSelect, margin, margin, margin, margin);
				setSize(oSelect, 4.5, null, 'em');
				setSize(oCombo, oSelect.offsetWidth + (margin * 2));
				setSize(object, object.offsetWidth + (oCombo.offsetWidth - width));

				oSelect.onchange = function()
				{
					var object = this.parentNode.parentNode;
					this.parentNode.parentNode.value = convertToInt(this.value);
					if(typeof(main_object.selectCombo) == "function"){main_object.selectCombo(object);}
				}
			}
		}
	}
	
	return object;
}

function setCombo(object, min, max, defaultvalue)
{
	if(isObject(object))
	{
		var select = getObject(object.id + '_Combo_Select');

		if(isObject(select))
		{
			var i=0;

			while(select.options.length + (min - 1) != max)
			{
				if(max > select.options.length + (min - 1)){select.options[i] = new Option(i + min, i + min);}
				else{select.options[select.options.length -1] = null;}
				i++;
			}

			select.value = Math.min(select.options.length + (min - 1), defaultvalue);
			object.value = convertToInt(select.value);
		}
	}
}

function addClearFloat(object)
{
	var object = addElement('div', object, 'Clear');
	setClassName(object, 'clearit');
}

function removeElement(object)
{
	if(isObject(object) && isObject(object.parentNode))
	{
		object.parentNode.removeChild(object);
	}
}

function centerScreen(object)
{
	var top = (screen.availHeight - object.offsetHeight) / 2;
	var left = (screen.availWidth - object.offsetWidth) / 2;
	if(object)
	{
		setScreenPosition(object, top, left)
	}
}

function clearElements(object)
{
//	if(object){debug('clear: '+ object.id);}
	setHtml(object, '');
}

//---- Functions to set different visual properties -----------------------------------------// 

function clearStyle(object)
{
	if(isObject(object)){object.style.cssText = '';}
}

function setAlign(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.align = value;}
}

function setBgColor(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.backgroundColor = value;}
}

function setBorder(object, style, color, top, right, bottom, left)
{
	if(isObject(object) && typeof(style) == 'string'){object.style.borderStyle = style;}
	if(isObject(object) && typeof(color) == 'string'){object.style.borderColor = color;}

	if(isObject(object) && typeof(top) == 'number'){object.style.borderTopWidth = Math.abs(top) + getUnit();}
	if(isObject(object) && typeof(right) == 'number'){object.style.borderRightWidth = Math.abs(right) + getUnit();}
	if(isObject(object) && typeof(bottom) == 'number'){object.style.borderBottomWidth = Math.abs(bottom) + getUnit();}
	if(isObject(object) && typeof(left) == 'number'){object.style.borderLeftWidth = Math.abs(left) + getUnit();}
}

function setClassName(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.className = value;}
}

function setColor(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.color = value;}
}

function setCursor(object, value)
{
	if(isObject(object)){object.style.cursor = ((typeof(value) == 'string') ? value : ((mozilla) ? "pointer" : "hand"));}
}

function setDisable(object, value)
{
	if(isObject(object) && typeof(value) == 'boolean'){object.disabled = value;}
}

function setDisplay(object, value, delay)
{
	if(isObject(object) && getObject(object.id) && typeof(value) == 'boolean')
	{
		if(value){object.style.display = '';}
		else
		{
			value = 'none';
			delay = (typeof(delay) == 'number') ? delay : 400;
			if(internetExplorer){window.setTimeout(object.id  + ".style.display = 'none'", delay);}
			else{object.style.display = value;}
//object.style.display = value;
		}
//		window.setTimeout(object.id  + ".style.display = '" + value + "'", ((typeof(delay) == 'number') ? delay : 800));
	}
}

function setFloat(object, value)
{
	if(isObject(object) && typeof(value) == 'string')
	{
		object.style.cssFloat = value;
		object.style.styleFloat = value;
	}
}

function setFontFamily(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.fontFamily = value;}
}

function setFontSize(object, value, unit)
{
	if(isObject(object) && typeof(value) == 'number' && value > 0){object.style.fontSize = value + getUnit(unit);}
}

function setFontWeight(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.fontWeight = value;}
}

function setHtml(object, value, add)
{
	if(isObject(object)) // && typeof(value) == 'string')
	{
		object.innerHTML = ((add) ? object.innerHTML : '') + value;
	}
}

function setMargin(object, top, right, bottom, left, unit)
{
	if(isObject(object) && typeof(top) == 'number'){object.style.marginTop = top + getUnit(unit);}
	if(isObject(object) && typeof(right) == 'number'){object.style.marginRight = right + getUnit(unit);}
	if(isObject(object) && typeof(bottom) == 'number'){object.style.marginBottom = bottom + getUnit(unit);}
	if(isObject(object) && typeof(left) == 'number'){object.style.marginLeft = left + getUnit(unit);}
}

function setOpacity(object, value)
{
	if(isObject(object) && typeof(value) == 'number')
	{
		if(internetExplorer){object.filters.alpha.opacity = value;}
		if(mozilla){object.style.MozOpacity = value/100;}
	}
}

function setOverflow(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.overflow = value;}
}

function setPadding(object, top, right, bottom, left)
{
	if(isObject(object) && typeof(top) == 'number'){object.style.paddingTop = Math.abs(top) + getUnit();}
	if(isObject(object) && typeof(right) == 'number'){object.style.paddingRight = Math.abs(right) + getUnit();}
	if(isObject(object) && typeof(bottom) == 'number'){object.style.paddingBottom = Math.abs(bottom) + getUnit();}
	if(isObject(object) && typeof(left) == 'number'){object.style.paddingLeft = Math.abs(left) + getUnit();}
}

function setPosition(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.position = value;}
}

function setScreenPosition(object, top, left, unit)
{
	if(isObject(object) && typeof(top) == 'number'){object.style.top = Math.abs(top) + getUnit(unit);}
	if(isObject(object) && typeof(left) == 'number'){object.style.left = Math.abs(left) + getUnit(unit);}
}

function setSize(object, width, height, unit)
{
	if(isObject(object))
	{
		object.style.width = '';
		object.style.height = '';

		if(typeof(width) == 'number' && width > 0){object.style.width = Math.abs(width) + getUnit(unit);}
		if(typeof(height) == 'number' && height > 0){object.style.height = Math.abs(height) + getUnit(unit);}
	}
}

function setStyle(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.cssText = value;}
}

function setText(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.textTransform = value;}
}

function setTextAlign(object, value)
{
	if(isObject(object) && typeof(value) == 'string'){object.style.textAlign = value;}
}

function setValue(object, value)
{
	if(isObject(object)){object.value = value;}
}

function setVisibility(object, visible)
{
	if(object)
	{
		object.style.visibility = (visible) ? 'visible' : 'hidden';
		object.style.display = (visible) ? 'block' : 'none';
	}
}

function checkUncheck(id)
{
	var obj = getObject(id);
	if(obj){obj.checked = !obj.checked;}
}

function toCapitalise(text)
{
	return (text.length > 0) ? text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase() : text;
}

function getUnit(unit)
{
	return (typeof(unit) == 'string') ? unit : 'px';
}

function disableSelection(id)
{
	object = getObject(id);
	if(object)
	{
//		object.onfocus = function(){object.selectionStart = '0'; object.selectionEnd = '0';};
		object.onselectstart = function(){return false;};
		object.unselectable = "on";
		object.style.MozUserSelect = "none";
//		object.style.cursor = "default";
	}
}

function isNumberKey(evt)
{
	var bReturn = true;
	var charCode = (evt.which) ? evt.which : evt.keyCode;

	if(charCode > 31 && (charCode < 48 || charCode > 57) && 
		!(charCode >= 36 && charCode <= 40) && charCode != 46 &&
		!(evt.ctrlKey && charCode == 118))
	{
		bReturn = false;
	}

	return bReturn;
}


//---- Functions to set different visual properties -----------------------------------------// 

function getBorderWidth(object)
{
	var width = 0;

	if(isObject(object))
	{
		width = convertToInt(object.style.borderLeftWidth) + convertToInt(object.style.borderRightWidth);
	}

	return width;
}

function getMaximumWidth(object1, object2)
{
	var width = null;

	if(isObject(object1))
	{
		width = object1.offsetWidth - convertToInt(object1.style.paddingLeft) - convertToInt(object1.style.paddingRight) - getBorderWidth(object1);
		if(isObject(object2)){width -= getMaximumWidth(object2);}
	}

	return width;
}

function getAbsoluteTop(object)
{
	var value = 0;

	if(isObject(object) && object.tagName != 'BODY')
	{
		var marginTop = (object.style) ? convertToInt(object.style.marginTop) : 0;
		var top = object.offsetTop + ((mozilla && object.style) ? convertToInt(object.style.borderTopWidth) : 0);
		value += top - (marginTop + object.scrollTop);
//alert(count + ' ' + object.tagName + ' top:' + value);
		value += getAbsoluteTop(object.offsetParent);
//debug(object.id + " offsetTop=" + top + ' ' + object.style.position);
	}

	return value;
}

function getOffsetTop(object)
{
	var value = 0;

	if(isObject(object) && object.tagName != 'BODY')
	{
		var marginTop = (object.style) ? convertToInt(object.style.marginTop) : 0;
		var top = object.offsetTop + ((mozilla && object.style) ? convertToInt(object.style.borderTopWidth) : 0);
		value += top - (marginTop + object.scrollTop);
		value += getOffsetTop(object.parentNode);
//debug(object.id + " offsetTop=" + top + ' ' + object.style.position);
	}

	return value;
}

function getAbsoluteLeft(object)
{
	var value = 0;

	if(isObject(object) && object.tagName != 'BODY')
	{
		var marginLeft = (object.style) ? convertToInt(object.style.marginLeft) : 0;
		var left = object.offsetLeft + ((mozilla && object.style) ? convertToInt(object.style.borderLeftWidth) : 0);
		value += left - (marginLeft + object.scrollLeft);
		value += getAbsoluteLeft(object.offsetParent);
//debug(object.id + " offsetLeft=" + left);
	}

	return value;
}

function getOffsetLeft(object)
{
	var value = 0;

	if(isObject(object) && object.tagName != 'BODY')
	{
		var marginLeft = (object.style) ? convertToInt(object.style.marginLeft) : 0;
		var left = object.offsetLeft + ((mozilla && object.style) ? convertToInt(object.style.borderLeftWidth) : 0);
		value += left - (marginLeft + object.scrollLeft);
		value += getOffsetLeft(object.parentNode);
//debug(object.id + " offsetLeft=" + left);
	}

	return value;
}

//---- Functions to set different visual properties -----------------------------------------// 

function isObject(object)
{
	return (object && typeof(object) == 'object');
}

function getObject(id)
{
	return (document.getElementById) ? document.getElementById(id) : null;
}

function getParent(object)
{
	return (isObject(object)) ? object.Parent : null;
}

function getGrandParent(object)
{
	return (isObject(getParent(object))) ? getParent(object).Parent : null;
}

function getGreatGrandParent(object)
{
	return (isObject(getGrandParent(object).Parent)) ? getGrandParent(object).Parent : null;
}

function getObjectValue(id)
{
	obj = getObject(id);
	return (obj) ? obj.value : '';
}

function getRequestString(searchfor)
{
	var strRequestString = "";

	searchfor += '=';
	strLocation = location.search;
	nPos = strLocation.indexOf(searchfor);

	if(nPos >= 0)
	{
		nPos = nPos + searchfor.length;
		nPos2 = strLocation.substring(nPos, strLocation.length).indexOf("&");
		if(nPos2 < 0)
		{
			nPos2 = strLocation.substring(nPos, strLocation.length).indexOf("%26");
		}

		nLength = (nPos2 < 0) ? strLocation.length : nPos + nPos2;
		strRequestString = strLocation.substring(nPos, nLength);
	}

	strRequestString = strRequestString.replace('%20', ' ');

	return strRequestString;
}

function randomNumber(from, to)
{
	var generator = Math.random()*(to - from);
	return Math.round(from + generator);
}

//-Apply and Play filters----------------------------------------------------------------------//

function setFilter(object)
{
	if(internetExplorer && isObject(object))
	{
		applyFilter(object);
		setHtml(object, object.innerHTML);	
		playFilter(object);
	}
}
function applyFilter(object)
{
	if(internetExplorer && isObject(object) && hasFilter(object))
	{
		setVisibility(object, false);
		object.filters[0].Apply();
	}
}

function playFilter(object)
{
	if(internetExplorer && isObject(object) && hasFilter(object))
	{
		setVisibility(object, true);
		object.filters[0].Play();
	}
}

function hasFilter(object)
{
	return object && typeof(object.filters) == "object" && typeof(object.filters[0]) == "object";
}

//---- Convert functions --------------------------------------------------------------------// 

function convertToBoolean(value)
{
	return (value == null || value == 'false') ? false : true;
}

function convertToFloat(value)
{
	return (value == null || value == '' || isNaN(parseFloat(value))) ? 0 : parseFloat(value);
}

function convertToInt(value)
{
	return (value == null || value == '' || isNaN(parseInt(value))) ? 0 : parseInt(value);
}

function convertBooleanToString(bool)
{
	return (bool) ? 'true' : 'false';
}

function convertDateToString(date, type)
{
	var strDate = "";

	if(date)
	{
		var nDay = date.getDate();
		var nMonth = date.getMonth() + 1;
		var nDayInWeek = date.dayOfWeek();

		switch(type)
		{
			case "month":
				strDate = monthList[nMonth-1] + " " + date.getFullYear();
				break;
			case "short":
				strDate = nDay + " " + monthList[nMonth-1].substr(0, 3);
				break;
			case "long":
				strDate = nDay + " " + monthList[nMonth-1] + " " + date.getFullYear();
				break;
			case "extralong":
				var sup = 'th';
				if(nDay == 1 || nDay == 21 || nDay == 31){sup = 'st';}
				else if(nDay == 2 || nDay == 22){sup = 'nd';}
				else if(nDay == 3 || nDay == 23){sup = 'rd';}

				strDate = dayList[nDayInWeek - 1] + ', ' + nDay + '<sup>' + sup + '</sup> of ' + monthList[nMonth-1] + ' ' + date.getFullYear();
				break;
			default:
				strDate = ((nDay < 10) ? "0" : "") + nDay + "/" + ((nMonth < 10) ? "0" : "") + nMonth + "/" + date.getFullYear();
				break;
		}
	}
	
	return strDate;
}

function convertPriceToString(value, symbol)
{
	value = value.toString();

	switch(value.indexOf('.'))
	{
		case -1:
			value = value + '.00';
			break;
		case value.length - 2:
			value = value + '0';
			break;
		default:
			value = value.substring(0, value.indexOf('.') + 3);
			break;
	}	

	return symbol + value;
}

//-Xml functions-------------------------------------------------------------------------------//

function addXmlElement(xmldoc, element, object, name)
{
	if(xmldoc && element && object && object[name])
	{
		var elt = xmldoc.createElement(name);
		var value;

		switch(object[name])
		{
			case true:
				value = "1";
				break;
			case false:
				value = "0";
				break;
			default:
				value = object[name];
				break;
		}
		
		elt.appendChild(xmldoc.createTextNode(value));
		element.appendChild(elt);
	}
}

function appendXmlElement(xmldoc, root, elt)
{
	if(root){root.appendChild(elt);}
	else{xmldoc.appendChild(elt);}
}

function saveFile(xmldoc, filename)
{
	try
	{
		var f = new ActiveXObject("Scripting.FileSystemObject");
		var s = f.CreateTextFile(filename, true);
		s.WriteLine(xmldoc.xml);
		s.Close();
	}
	catch(e)
	{
		alert(e.message);
	}
}

//-Cookies functions-----------------------------------------------------------------------------------------//

function createCookie(name, value, days)
{
	var expires = "";
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	}

	if(value){document.cookie = name + "=" + value + expires;}
}

function readCookie(name)
{
	var value = null;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0; ca[i]; i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ')
		{
			c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) == 0)
		{
			value = c.substring(nameEQ.length,c.length);
		}
	}

	return value;
}

function eraseCookie(name)
{
	createCookie(name, "" , -1);
}

//-add new function to arrays--------------------------------------------------------------------------------//

if(!Array.prototype.Copy)
{
	Array.prototype.Copy = function()
	{
		var copy = new Array()
		var i = this.length;
		while(i--){copy[i] = this[i];}
		return copy;
	};
}

if(!Array.prototype.Exists)
{
	Array.prototype.Exists = function(id)
	{
		elt = null;
		var v_regexp = new RegExp(id + "$","gi")

		for(x=0; x < this.length; x++)
		{
			if(this[x])
			{
				if(v_regexp.test(this[x].Type + this[x].Id))
				{
					elt = this[x];
					break;
				}
			}
		}

		return elt;
	}
}

if(!Array.prototype.checkPoint)
{
	Array.prototype.checkPoint = function(point)
	{
		bReturn = false;

		if(point)
		{
			for(var i=0; this[i]; i++)
			{
				if(this[i].equals(point))
				{
					bReturn = true;
					break;
				}
			}
		}

		return bReturn;
	}
}

if(!Array.prototype.RemoveElement)
{
	Array.prototype.RemoveElement = function(index)
	{
		for(var i=index; this[i]; i++)
		{
			this[i] = (this[i+1]) ? this[i+1] : null;
		}
	}
}

//-add new function to the date object-----------------------------------------------------------------------//

function getToday()
{
	var today = new Date();
	return new Date(today.getFullYear(), today.getMonth(), today.getDate());
}
function getNumberOfDaysPerMonth(month, year)
{
	return (month == 1) ? ((((year % 100 != 0) && (year % 4 ==0)) || (year % 400 == 0)) ? 29 : 28) : noDaysperMonth[month];
}

if(!Date.prototype.Equals)
{
	Date.prototype.Equals = function(date)
	{
		return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && (this.getDate() == date.getDate()));
	}
}

if(!Date.prototype.dayOfWeek)
{
	Date.prototype.dayOfWeek = function()
	{
		return (this.getDay() == 0) ? 7 : this.getDay()
	}
}

if(!Date.prototype.numberOfDaysPerMonth)
{
	Date.prototype.numberOfDaysPerMonth = function()
	{
		return getNumberOfDaysPerMonth(this.getMonth(), this.getFullYear())
	}
}

if(!Date.prototype.addDay)
{
	Date.prototype.addDay = function()
	{
		var nYear, nMonth, nDay;

		if(this.getDate() + 1 > this.numberOfDaysPerMonth())
		{
			nYear = (this.getMonth() == 11) ? this.getFullYear() + 1 : this.getFullYear();
			nMonth = (this.getMonth() == 11) ? 0 : this.getMonth() + 1;
			nDay = 1;
		}
		else
		{
			nYear = this.getFullYear();
			nMonth = this.getMonth();
			nDay = this.getDate() + 1;
		}

		return new Date(nYear, nMonth, nDay);
	}
}

if(!Date.prototype.removeDay)
{
	Date.prototype.removeDay = function()
	{
		var nYear, nMonth, nDay;

		if(this.getDate() - 1 == 0)
		{
			nYear = (this.getMonth() == 0) ? this.getFullYear() - 1: this.getFullYear();
			nMonth = (this.getMonth() == 0) ? 11 : this.getMonth() - 1;
			nDay = getNumberOfDaysPerMonth(nMonth, nYear);
		}
		else
		{
			nYear = this.getFullYear();
			nMonth = this.getMonth();
			nDay = this.getDate() - 1;
		}

		return new Date(nYear, nMonth, nDay);
	}
}

if(!Date.prototype.addDays)
{
	Date.prototype.addDays = function(nbDays)
	{
		var date = this;

		for(var i=1; i <= Math.abs(nbDays); i++)
		{
			date = (nbDays >= 0) ? date.addDay() : date.removeDay();
		}

		return date;
	}
}

if(!Date.prototype.nextWeek)
{
	Date.prototype.nextWeek = function()
	{
		var date = this;
		var dow = date.dayOfWeek();
		
		for(var i=dow; i < 8; i++)
		{
			date = date.addDay();
		}
		return date;
	}
}

if(!Date.prototype.lastWeek)
{
	Date.prototype.lastWeek = function()
	{
		var date = this;
		var dow = date.dayOfWeek();

		for(var i=1; i < dow + 7; i++)
		{
			date = date.removeDay();
		}

		return date;
	}
}

if(!Date.prototype.nextMonth)
{
	Date.prototype.nextMonth = function()
	{
		var nYear = (this.getMonth() == 11) ? this.getFullYear() + 1 : this.getFullYear();
		var nMonth = (this.getMonth() == 11) ? 0 : this.getMonth() + 1;

		return new Date(nYear, nMonth, 1);
	}
}

if(!Date.prototype.lastMonth)
{
	Date.prototype.lastMonth = function()
	{
		var nYear = (this.getMonth() == 0) ? this.getFullYear() - 1 : this.getFullYear();
		var nMonth = (this.getMonth() == 0) ? 11 : this.getMonth() - 1;

		return new Date(nYear, nMonth, 1);
	}
}

//-String functions----------------------------------------------------------------------------//

function searchString(text, txtsearch)
{
	var string = text;
	
	if(txtsearch.length > 0)
	{
		var txt = text.toLowerCase();
		var nPos = txt.indexOf(txtsearch.toLowerCase());
		
		string = (nPos < 0) ? text : (text.substr(0, nPos) + "<span class='Found'>" + text.substr(nPos, txtsearch.length) + "</span>" + 
									searchString(text.substr(nPos + txtsearch.length), txtsearch));
	}

	return string;
}

function calculateScore(text, txtsearch)
{
	var cnt = 0;

	if(txtsearch.length > 0)
	{
		var txt = text.toLowerCase();
		var nPos = txt.indexOf(txtsearch.toLowerCase());

		var nBonus = 0;
		var nPosBonus = text.indexOf(txtsearch);
		nBonus += ((nPosBonus < 0) ? 0 : 3) + ((txt == txtsearch.toLowerCase()) ? 3 : 0) + ((text == txtsearch) ? 5 : 0);

		cnt += (nPos < 0) ? 0 : (1 + calculateScore(text.substr(nPos + 1), txtsearch) + nBonus);
	}
	
	return cnt;
}

function readFile(file)
{
	var string = '';
	var fso = new ActiveXObject("Scripting.FileSystemObject");

	if(fso)
	{
		if(fso.FileExists(file))
		{
			ts = fso.OpenTextFile(file, 1);
			string = ts.ReadLine();
			ts.Close();
		}
	}

	return string;
}

function resizeToFixedHeight(object, height, size)
{
	size = (size) ? size : .7;
	setFontSize(object, size, 'em');

	if(object && object.offsetHeight < height){resizeToFixedHeight(object, height, size + 0.05);}
	else{setFontSize(object, size - 0.05, 'em');}
}

function setFocus(object)
{
	if(isObject(object) && object.style.visibility != 'hidden')
	{
		object.focus();
	}
}

//-Color functions-----------------------------------------------------------------------------//

var RGB = new Array();
var hex = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

for(var i = 0; i < 16; i++)
{
	for(var j = 0; j < 16; j++)
	{
		RGB[RGB.length] = hex[i] + hex[j];
	}
}

function convertColor(coeff, max)
{
	var color = '';
	var r = 255;
	var b = 100;
	var g = 224;

	if(coeff > 1)
	{
		r += Math.floor((255 - r) * ((coeff - 1)/max));
		b += Math.floor((255 - b) * ((coeff - 1)/max));
		g += Math.floor((255 - g) * ((coeff - 1)/max));
	}

	if(RGB.length > 0){color = "#" + RGB[r] + RGB[g] + RGB[b];}

	return color;
}

//-Different Icons-------------------------------------------------------------------------------------------//

function subGPoints(a,b)
{ 
  return new GPoint(a.x-b.x, a.y-b.y); 
}
/*
if(typeof(GIcon) != "undefined" && iconFolder)
{

	var smallBookedHostelIcon = new GIcon();
	if(smallBookedHostelIcon)
	{
		smallBookedHostelIcon.image = iconFolder + "icon_hostel_small_booked.png";
		smallBookedHostelIcon.iconSize = new GSize(36, 36);
		smallBookedHostelIcon.shadow = iconFolder + "icon_shadow_small.png";
		smallBookedHostelIcon.shadowSize = new GSize(36, 36);
		smallBookedHostelIcon.iconAnchor = new GPoint(12, 36);
		smallBookedHostelIcon.infoWindowAnchor = new GPoint(5, 2);
	}
	
	var bigBookedHostelIcon = new GIcon();
	if(bigBookedHostelIcon)
	{
		bigBookedHostelIcon.image = iconFolder + "icon_hostel_big_booked.png";
		bigBookedHostelIcon.iconSize = new GSize(48, 48);
		bigBookedHostelIcon.shadow = iconFolder + "icon_shadow_big.png";
		bigBookedHostelIcon.shadowSize = new GSize(48, 48);
		bigBookedHostelIcon.iconAnchor = new GPoint(16, 48);
		bigBookedHostelIcon.infoWindowAnchor = new GPoint(5, 2);
	}


	var smallHostelIcon = new GIcon();
	if(smallHostelIcon)
	{
		smallHostelIcon.image = iconFolder + "icon_hostel_small.png";
		smallHostelIcon.iconSize = new GSize(36, 36);
		smallHostelIcon.shadow = iconFolder + "icon_shadow_small.png";
		smallHostelIcon.shadowSize = new GSize(36, 36);
		smallHostelIcon.iconAnchor = new GPoint(12, 36);
		smallHostelIcon.infoWindowAnchor = new GPoint(5, 2);
	}

	var bigHostelIcon = new GIcon();
	if(bigHostelIcon)
	{
		bigHostelIcon.image = iconFolder + "icon_hostel_big.png";
		bigHostelIcon.iconSize = new GSize(48, 48);
		bigHostelIcon.shadow = iconFolder + "icon_shadow_big.png";
		bigHostelIcon.shadowSize = new GSize(48, 48);
		bigHostelIcon.iconAnchor = new GPoint(16, 48);
		bigHostelIcon.infoWindowAnchor = new GPoint(5, 2);
	}

	var smallBookedActivityIcon = new GIcon();
	if(smallBookedActivityIcon)
	{
		smallBookedActivityIcon.image = iconFolder + "icon_activity_small_booked.png";
		smallBookedActivityIcon.iconSize = new GSize(36, 36);
		smallBookedActivityIcon.shadow = iconFolder + "icon_shadow_small.png";
		smallBookedActivityIcon.shadowSize = new GSize(36, 36);
		smallBookedActivityIcon.iconAnchor = new GPoint(12, 36);
		smallBookedActivityIcon.infoWindowAnchor = new GPoint(5, 2);
	}
	
	var bigBookedActivityIcon = new GIcon();
	if(bigBookedActivityIcon)
	{
		bigBookedActivityIcon.image = iconFolder + "icon_activity_big_booked.png";
		bigBookedActivityIcon.iconSize = new GSize(48, 48);
		bigBookedActivityIcon.shadow = iconFolder + "icon_shadow_big.png";
		bigBookedActivityIcon.shadowSize = new GSize(48, 48);
		bigBookedActivityIcon.iconAnchor = new GPoint(16, 48);
		bigBookedActivityIcon.infoWindowAnchor = new GPoint(5, 2);
	}

	var smallActivityIcon = new GIcon();
	if(smallActivityIcon)
	{
		smallActivityIcon.image = iconFolder + "icon_activity_small.png";
		smallActivityIcon.iconSize = new GSize(36, 36);
		smallActivityIcon.shadow = iconFolder + "icon_shadow_small.png";
		smallActivityIcon.shadowSize = new GSize(36, 36);
		smallActivityIcon.iconAnchor = new GPoint(12, 36);
		smallActivityIcon.infoWindowAnchor = new GPoint(5, 2);
	}

	var bigActivityIcon = new GIcon();
	if(bigActivityIcon)
	{
		bigActivityIcon.image = iconFolder + "icon_activity_big.png";
		bigActivityIcon.iconSize = new GSize(48, 48);
		bigActivityIcon.shadow = iconFolder + "icon_shadow_big.png";
		bigActivityIcon.shadowSize = new GSize(48, 48);
		bigActivityIcon.iconAnchor = new GPoint(16, 48);
		bigActivityIcon.infoWindowAnchor = new GPoint(5, 2);
	}

}
*/

function createIcon(filename, big)
{
	var size = (big) ? 48 : 36;

	var icon = new GIcon();
	icon.image = iconsFolder + "" + filename;
	icon.iconSize = new GSize(size, size);
	icon.shadow = iconsFolder + "icon_shadow_" + ((big) ? "big.png" : "small.png");
	icon.shadowSize = new GSize(size, size);
	icon.iconAnchor = new GSize(size/3, size);
	icon.infoWindowAnchor = new GPoint(5, 2);

	return icon;
}

//-Debug-----------------------------------------------------------------------------------------------------//

function debug(html)
{
	html = (html && typeof(html) != 'undefined') ? '<div>' + html + '</div>' : '';
	var add = (html == '') ? false : true;
	setHtml(getObject('debug'), html, add);
}

//-Timing Functions------------------------------------------------------------------------------------------//

function getCurrentTime()
{
	return new Date().getTime();
}

function startTiming()
{
	return getCurrentTime();
}

function endTiming(startTime)
{
	var time = getCurrentTime() - startTime;

	return (time > 0) ? 'Elpase time:' + time + 'ms' : 'No time!';
}

function isValidSearch()
{
	var searchcontent = document.getElementById('txtSearch').value;
	
	if((searchcontent == 'no suggestions found..., ') || (searchcontent == ''))
	{
		//alert('false!');
		//document.getElementById('btnSearch').style.visibility='hidden';
		return false;
	}
	else
	{
		//alert('true!');
		//document.getElementById('btnSearch').style.visibility='visible';
		return true;
	}
	
}


