var monthInYear = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");var dayInWeek = new Array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday");var calendar = new Calendar();function Calendar(){	this.elementId = "";	this.element = null;	this.weekday = 0;	this.day = 0;	this.month = 0;	this.year = 0;	this.cday = 0;	this.cmonth = 0;	this.cyear = 0;	this.cyear2 = 0;	this.mappingArray = new Array();	this.cal = document.getElementById("cal");	this.cald = document.getElementById("cald");}function initCalendar(date){	// PICKED DATE	calendar.weekday = date.getDay();	calendar.day = date.getDate();	calendar.month = date.getMonth() +1;	calendar.year = date.getFullYear();	//DATE ON DISPLAY	calendar.cday = calendar.day;	calendar.cmonth = calendar.month;	calendar.cyear = calendar.year;	calendar.cday = calendar.day;		//CURRENT DATE	myDate=new Date();	currentdate=myDate.getDate();	currentmonth=myDate.getMonth()+1;	currentyear=myDate.getFullYear();}function hideCalendar(){	calendar.cal.style.visibility = "hidden";	calendar.cald.style.visibility = "hidden";}function displayCalendar(id){	calendar = new Calendar();	var i;	var element;	for (i=0 ; i<4 ; i++)	{		element = document.getElementById("cal_m_0" + i);	}	for (i=0 ; i<4 ; i++)	{		element = document.getElementById("cal_y_0" + i);	}	element = document.getElementById("cal_c");	calendar.elementId = "";	calendar.element = document.getElementById(id);		var dateValue = calendar.element.value;	if (dateValue != "")	{		var s = dateValue.split("/");		var d;		var m;		var y;		var validDate = true;		if (s.length == 3)		{			d = s[0];			if (d.charAt(0) == "0")			{				d = d.substr(1);			}			m = s[1];			if (m.charAt(0) == "0")			{				m = m.substr(1);			}			y = s[2];		}		else		{			validDate = false;		}		if (validDate)		{			initCalendar(new Date(y, m-1, d));		}		else		{			initCalendar(new Date());		}	}	else	{		initCalendar(new Date());	}	fillCalendar();	//show calendar	calendar.cal.style.visibility = "visible";	calendar.cald.style.visibility = "visible";}function fillCalendar(){	//if((calendar.cyear>currentyear)&&(calendar.cmonth<11)&&(calendar.cmonth>4)){ 		//calendar.cmonth=11;	//}	//else if ((calendar.cyear==currentyear)&&(calendar.cmonth<11)){		//calendar.cmonth=11;	//}	document.getElementById("cal_m_02").innerHTML = getStringMonth(calendar.cmonth);		document.getElementById("cal_y_02").innerHTML = calendar.cyear;	var element;	var i = 0;	var j = 0;	for (i=0 ; i<6 ; i++)	{		for (j=0 ; j<7 ; j++)		{			element = document.getElementById("cal_d_" + i + j);			element.innerHTML = "";			element.onclick = "";		}	}	i = 0;	j = (new Date(calendar.cyear, calendar.cmonth-1, 1)).getDay();	j = (j + 6) % 7;	var count = 1;	var days = getMonthLastDay();	while (count <= days) //as long as the counter is smaller than the number of days in the current month	{		element = document.getElementById("cal_d_" + i + j);		element.innerHTML = count;			if ((count <= currentdate+2)  && (calendar.cmonth <= currentmonth) && (calendar.cyear <= currentyear))				 {				element.className = 'nosel';				element.onclick = selectionno;				}			else				{				element.className = 'sel';				element.onclick = selectDay;				}			//if ((count < 11)  && (count > 4) && (calendar.cmonth ==12) && (calendar.cyear ==2007))				 //{				//element.className = 'booked';				//element.onclick = booked;				//}		calendar.mappingArray[10 * i + j] = count;		j++;				if (j == 7)		{			i++;			j = 0;		}				count++;	}}function booked(){	alert('Sorry, fully booked for these dates');}function selectionno(){	alert('Smashed! Surfaris run from 15th of November until the 30th of April');}function selectDay(){	var id = event.srcElement.id;	calendar.cday = calendar.mappingArray[parseInt(id.substr(id.length - 2))];	calendar.cal.style.visibility = "hidden";	calendar.cald.style.visibility = "hidden";	var d = calendar.cday;	var m = calendar.cmonth;	var y = calendar.cyear;	window.status = d + " - " + m + " - " + y;	calendar.element.value = (d < 10 ? "0" : "") + d + "/" + (m < 10 ? "0" : "") + m + "/" + y;}		function incrementMonth(){ 	if (calendar.cmonth>11){		calendar.cyear = calendar.cyear + 1;		calendar.cmonth = 1;	}	else {	calendar.cmonth = calendar.cmonth + 1;	}	fillCalendar();}function decrementMonth(){		if ((calendar.cmonth==1)&&(calendar.cyear>currentyear)){ // If month > 5 ( April) and year on display is actual year +1		calendar.cmonth=12;		calendar.cyear=calendar.cyear-1;	}	else if((calendar.cmonth>currentmonth))	{		calendar.cmonth = calendar.cmonth - 1;	}		fillCalendar();}function getMonthLastDay(){	var testDate = new Date(calendar.cyear, calendar.cmonth-1, 29);	if (testDate.getDate() == 29)	{		testDate.setDate(30);		if (testDate.getDate() == 30)		{			testDate.setDate(31);			if (testDate.getDate() == 31)			{				return 31			}			else			{				return 30;displayCalendar('w0')			}		}		else		{			return 29;		}	}	else	{		return 28;	}}function getStringWeekDay(index){	return dayInWeek[index];}function getStringMonth(index){	return monthInYear[index - 1];}