
var weekStartsOnSunday = true;  // true = Start the week on Sunday, false = start the week on Monday

// Format of current day at the bottom of the calendar
// [dayString] = day of week (examle: mon, tue, wed...)
// [UCFdayString] = day of week (examle: Mon, Tue, Wed...) ( First letter in uppercase)
// [day] = Day of month, 1..31
// [monthString] = Name of current month
// [year] = Current year
var pathToImages = "/tridion/images/";  // Relative to your HTML file
var calendar_offsetTop = 0;   // Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendar_offsetLeft = 0;  // Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendarDiv;
var calendarId;
var calendarToCloseId;
// represents the input date field
var inputField;
var noDateToDisplay;
var triedToSetReturnDateToDepartDate = false;
var notChangeReturnDate = false;
var wasBefore;
/**
 * The first active date of the current calendar.
 */
var startDate;
/**
 * The last active date of the current calendar.
 */
var endDate;
var MSIE = false;
var Opera = false;
//For userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/522.15.5 (KHTML, like Gecko) Version/3.0.3 Safari/522.15.5
var Safari = false; 
//For userAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419.2 (KHTML, like Gecko) Safari/419.3
//For useAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.5.1 (KHTML, like Gecko) Safari/312.3.1
var Safari_Macintosh = false;
if (navigator.userAgent.indexOf("MSIE") >= 0 && navigator.userAgent.indexOf("Opera") < 0) {
	MSIE = true;
}
if (navigator.userAgent.indexOf("Opera") >= 0) {
	Opera = true;
}
if (navigator.userAgent.indexOf("Safari/522.15.5") >= 0) {
	Safari = true;
}
if (navigator.userAgent.indexOf("Safari/312") >= 0 || navigator.userAgent.indexOf("Safari/417") >= 0 || navigator.userAgent.indexOf("Safari/419") >= 0) {
	Safari_Macintosh = true;
}
var monthArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var dayArray = ["M", "T", "W", "T", "F", "S", "S"];
var closeText = "Close";
if (weekStartsOnSunday) {
	var tempDayName = dayArray[6];
	for (var theIx = 6; theIx > 0; theIx--) {
		dayArray[theIx] = dayArray[theIx - 1];
	}
	dayArray[0] = tempDayName;
}
var daysInMonthArray = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var currentMonth;
var currentYear;
var tmpDay;
var calendarContentDiv;
var returnDateTo = "mm/dd/yyyy";
var returnFormat;
var regionalFormat;
var activeSelectBoxMonth;
var activeSelectBoxYear;
var iframeObj = false;
//// fix for EI frame problem on time dropdowns 09/30/2006
var iframeObj2 = false;
function EIS_FIX_EI1(where2fixit) {
	if (!iframeObj2) {
		return;
	}
	iframeObj2.style.display = "block";
	iframeObj2.style.height = document.getElementById(where2fixit).offsetHeight + 1;
	iframeObj2.style.width = document.getElementById(where2fixit).offsetWidth;
	iframeObj2.style.left = getleftPos(document.getElementById(where2fixit)) + 1 - calendar_offsetLeft;
	iframeObj2.style.top = getTopPos(document.getElementById(where2fixit)) - document.getElementById(where2fixit).offsetHeight - calendar_offsetTop;
}
function EIS_Hide_Frame() {
	if (iframeObj2) {
		iframeObj2.style.display = "none";
	}
}
//// fix for EI frame problem on time dropdowns 09/30/2006
var inputYear;
var inputMonth;
var inputDay;
var calendarDisplayTime = false;
var selectBoxMovementInProgress = false;
function cancelCalendarEvent() {
	return false;
}
function isLeapYear(inputYear) {
	if (inputYear % 400 == 0 || (inputYear % 4 == 0 && inputYear % 100 != 0)) {
		return true;
	}
	return false;
}
/*
 *Verifies if one of the calendar's arrows should not be displayed. This means that 
 will be no navigation to the previous month if the left arrow is not displayed.
 */
function displayArrows() {
	var d = new Date();
	var left = document.getElementById("leftLink" + calendarId);
	var right = document.getElementById("rightLink" + calendarId);
	var leftImg = document.getElementById("leftImg" + calendarId);
	var rightImg = document.getElementById("rightImg" + calendarId);
	if (((currentYear / 1) > (d.getFullYear() / 1 + 1)) || ((currentYear / 1) == (d.getFullYear() / 1 + 1) && currentMonth + 1 >= d.getMonth())) {
   // rightImg.style.visibility = 'hidden';
    //right.style.display = 'none';
		rightImg.style.visibility = "visible";
		right.style.display = "inline";
	} else {
		rightImg.style.visibility = "visible";
		right.style.display = "inline";
	}
	if (((currentYear / 1) < startDate.getFullYear()) || (currentMonth <= startDate.getMonth() && currentYear == startDate.getFullYear())) {
		leftImg.style.visibility = "hidden";
		left.style.display = "none";
	} else {
		leftImg.style.visibility = "visible";
		left.style.display = "inline";
	}
}
/*
 * Called when the calendar's left arrow is pressed. Goes back with a month
 */
function switchMonthLeft() {
	var d = new Date();
	if (currentMonth >= 0) {
		if ((currentMonth == 0)) {
			currentMonth = 11;
			currentYear = currentYear / 1 - 1;
		} else {
			currentMonth = currentMonth - 1;
		}
	}
	writeCalendarContent();
	displayArrows();
}
/*
 * Called when the calendar's right arrow is pressed. Goes ahead with a month
 */
function switchMonthRight() {
	var d = new Date();
	if (currentMonth >= 0) {
		if ((currentMonth < 11)) {
			currentMonth = currentMonth + 1;
		} else {
			currentMonth = 0;
			currentYear = currentYear / 1 + 1;
		}
	}
	writeCalendarContent(calendarId);
	displayArrows();
}
/**
 * Close calendar
 */
function closeCalendar(calendarToClose) {
	if (calendarToClose) {
		calendar = document.getElementById("calendarDiv" + calendarId);
		if (calendar) {
      //In this case we have the other calendar opened and we will close it
			calendar.style.display = "none";
		}
	} else {
		if (calendarDiv) {
			calendarDiv.style.display = "none";
		}
	}
	if (iframeObj) {
		iframeObj.style.display = "none";
    //// //// fix for EI frame problem on time dropdowns 09/30/2006
		EIS_Hide_Frame();
	} 
  //Without this check, on Safari the calendar doesn't close anymore
	if (!Safari) {
		if (!inputField.disabled) {
			inputField.focus();
		}
	}
}
/**
 * Closes the calendar with the id given as parameter.
 */
function closeCalendarById(calendarToClose) {
	if (calendarToClose) {
		if (calendarToClose == calendarId) {
			closeCalendar(calendarToClose);
		}
	}
}
/*
Function used to create the top bar which containd the left arrow, month and year and right arrow
*/
function writeTopBar(calendarId) {
	var topBar = document.createElement("TABLE");
	topBar.className = "boxCopy tableIndent";
	topBar.id = "topBar";
	topBar.width = "100%";
	calendarDiv.appendChild(topBar);
	var topBody = document.createElement("TBODY");
	topBar.appendChild(topBody);
	var row = topBody.insertRow(-1);
	row.style.width = "100%";
  // Left arrow
	var leftDiv = row.insertCell(-1);
	leftDiv.id = "leftArrow" + calendarId;
	leftDiv.align = "left";
	leftDiv.style.width = "15%";
	leftDiv.style.marginLeft = "1px";
	var leftLink = document.createElement("A");
	leftLink.id = "leftLink" + calendarId;
	leftLink.className = "calLink";
	leftLink.href = "javascript:switchMonthLeft()";
	var img = document.createElement("IMG");
	img.id = "leftImg" + calendarId;
 // img.src ='./calendar/special_offer_arrow_left_tcm4-10335.gif';
	img.src = "./calendar/left-arrow.gif";
	img.style.height = "10px";
	img.style.width = "17px";
	leftLink.appendChild(img);
	leftDiv.appendChild(leftLink);
	if (Opera) {
		leftDiv.style.width = "34px";
	}
  
  //Month field 
	var monthDiv = row.insertCell(-1);
	monthDiv.id = "monthSelect" + calendarId;
	monthDiv.className = "monthSpan";
	monthDiv.style.width = "70%";
	var span = document.createElement("SPAN");
	span.id = "calendar_month_txt" + calendarId;
	monthDiv.appendChild(span);
  
  // Right arrow
	var rightDiv = row.insertCell(-1);
	rightDiv.id = "rightArrow" + calendarId;
	rightDiv.align = "right";
	rightDiv.style.width = "15%";
	rightDiv.style.marginRight = "1px";
	rightDiv.style.paddingRight = "8px";
	var rightLink = document.createElement("A");
	rightLink.id = "rightLink" + calendarId;
	rightLink.className = "calLink";
	rightLink.href = "javascript:switchMonthRight()";
	var imgRight = document.createElement("IMG");
	imgRight.id = "rightImg" + calendarId;
  //imgRight.src ='./calendar/special_offer_arrow_right_tcm4-10336.gif';
	imgRight.src = "./calendar/right-arrow.gif";
	imgRight.style.height = "10px";
	imgRight.style.width = "17px";
	rightLink.appendChild(imgRight);
	rightDiv.appendChild(rightLink);
	if (Opera) {
		rightDiv.style.width = "34px";
	}
}
/*
* Creates the table with the calendar content
*/
function writeCalendarContent() {
	var calendarContentDivExists = true;
	calendarContentDiv = document.getElementById("content" + calendarId);
	if (!calendarContentDiv) {
		calendarContentDiv = document.createElement("DIV");
		calendarContentDiv.id = "content" + calendarId;
		calendarDiv.appendChild(calendarContentDiv);
		calendarContentDivExists = false;
	}
	var d = new Date();
	d.setHours(0, 0, 0, 0);
	if (!currentYear) {
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
	} else {
		var extendedStartDate = new Date(startDate.getFullYear(), startDate.getMonth(), 1);
		var firstCalendarDate = new Date(currentYear, currentMonth, 1);
		if ((firstCalendarDate - extendedStartDate < 0) || (endDate - firstCalendarDate < 0)) {
    //  currentMonth = startDate.getMonth();
     // currentYear = startDate.getFullYear();  	
		}
	}
	currentMonth = currentMonth / 1;
	d.setDate(1);
	d.setMonth(currentMonth);
	d.setFullYear(currentYear);
	var dayStartOfMonth = d.getDay();
	if (!weekStartsOnSunday) {
		if (dayStartOfMonth == 0) {
			dayStartOfMonth = 7;
		}
		dayStartOfMonth--;
	}
	document.getElementById("calendar_month_txt" + calendarId).innerHTML = monthArray[currentMonth] + " " + currentYear;
	var existingTable = calendarContentDiv.getElementsByTagName("TABLE");
	if (existingTable.length > 0) {
		calendarContentDiv.removeChild(existingTable[0]);
	}
	var calTable = document.createElement("TABLE");
	calTable.className = "calTablePopup boxContainer borderPurple";
	calTable.width = "100%";
	calTable.cellSpacing = "0";
	calTable.cellpadding = "3";
	calendarContentDiv.appendChild(calTable);
	var calTBody = document.createElement("TBODY");
	calTable.appendChild(calTBody);
  
  //Insert the first row of the table, the one with the week days letters
	var row = calTBody.insertRow(-1);
	row.className = "boxPurple copyWhiteBold";
	for (var no = 0; no < dayArray.length; no++) {
		var cell = row.insertCell(-1);
		cell.innerHTML = dayArray[no];
	}
	var row = calTBody.insertRow(-1);
	row.className = "boxGrey";
	for (var no = 0; no < dayStartOfMonth; no++) {
		var cell = row.insertCell(-1);
		cell.innerHTML = "&nbsp;";
	}
	var colCounter = dayStartOfMonth;
	var daysInMonth = daysInMonthArray[currentMonth];
	if (daysInMonth == 28) {
		if (isLeapYear(currentYear)) {
			daysInMonth = 29;
		}
	}
	var rowNo = 0;
	for (var no = 1; no <= daysInMonth; no++) {
		d.setDate(no);
		if (colCounter > 0 && colCounter % 7 == 0) {
			row = calTBody.insertRow(-1);
			if (rowNo % 2 == 0) {
				row.className = "boxWhite";
			} else {
				row.className = "boxGrey";
			}
			rowNo++;
		}
		var cell = row.insertCell(-1);
		if ((d - startDate >= 0) && (endDate - d >= 0)) {
			var cellLink = document.createElement("A");
			cellLink.innerHTML = no;
			cellLink.href = "javascript:closeCalendar()";  //change
			cellLink.title = no;
			cellLink.onclick = pickDateAndClose;
			cell.appendChild(cellLink);
		} else {
			cell.innerHTML = no;
		}
		colCounter++;
	}
  //Add the remaining empty cells
	while (colCounter % 7 != 0) {
		var cell = row.insertCell(-1);
		cell.innerHTML = "&nbsp;";
		colCounter++;
	}
	if (!document.all) {
		if (calendarContentDiv.offsetHeight) {
			document.getElementById("topBar").style.top = calendarContentDiv.offsetHeight + document.getElementById("topBar").offsetHeight - 1 + "px";
		} else {
			document.getElementById("topBar").style.top = "";
			document.getElementById("topBar").style.bottom = "0px";
		}
	}
	if (iframeObj) {
		if (!calendarContentDivExists) {
			setTimeout("resizeIframe()", 350);
		} else {
			setTimeout("resizeIframe()", 10);
		}
	}
}
function resizeIframe() {
	iframeObj.style.width = calendarDiv.offsetWidth + "px";
	iframeObj.style.height = calendarDiv.offsetHeight + "px";
}
/*
 *Verifies if the date field is the default value
 */
function verifyIfDefaultDate(elementId) {
	var field = document.getElementById(elementId);
	if (field.value == regionalFormat.toUpperCase()) {
		return true;
	} else {
		return false;
	}
}
function pickDateAndClose(e, inputDate) {
	if (!inputDate && this) {
		day = this.innerHTML;
	} else {
		day = inputDate;
	}
	pickDate(day);
	closeCalendar();
}
function pickDate(day) {
	var month = currentMonth / 1 + 1;
	if (month < 10) {
		month = "0" + month;
	}
	if (day / 1 < 10) {
		day = "0" + day;
	}
	if (returnFormat) {
		returnFormat = returnFormat.replace("dd", day);
		returnFormat = returnFormat.replace("mm", month);
		var displayYear = "" + currentYear;
		if (displayYear.length == 4) {
      //In this case the date is selected from the calendar
			returnFormat = returnFormat.replace("yyyy", displayYear.substring(0));
		} else {
      //In this acse the date is typed
			returnFormat = returnFormat.replace("yyyy", currentYear);
		}
		returnDateTo.value = returnFormat;
		try {
			returnDateTo.onchange();
		}
		catch (e) {
		}
		if (calendarToCloseId == "returnDate") {
			var departureDate = parseDateFromString(returnDateTo.value);
			if ((departureDate != null) && (departureDate - startDate >= 0) && (departureDate - endDate <= 0)) {
				var returnDateSpan = document.getElementById("calendar_month_txt" + calendarToCloseId);
				if (!returnDateSpan && (!notChangeReturnDate || verifyIfDefaultDate("returnDate"))) {
					var returnDateField = document.getElementById(calendarToCloseId);
					if (!returnDateField.disabled) {
						returnDateField.value = returnFormat;
					}
				}
			}
		}
	}
}
function writeCloseBar(calendarDiv) {
	var closeDiv = document.createElement("DIV");
	closeDiv.id = "closeBar";
  //closeDiv.style.position = 'absolute';
  //closeDiv.style.margin-bottom = '0px';
	closeDiv.className = "boxCopy";
	var link = document.createElement("A");
	link.href = "javascript:closeCalendar()";
	link.className = "buttonPos boxLink";
	link.innerHTML = closeText;
	closeDiv.appendChild(link);
	calendarDiv.appendChild(closeDiv);
}
function getTopPos(inputObj) {
	var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
	while ((inputObj = inputObj.offsetParent) != null) {
		returnValue += inputObj.offsetTop;
	}
	return returnValue + calendar_offsetTop;
}
function getleftPos(inputObj) {
	var returnValue = inputObj.offsetLeft;
	while ((inputObj = inputObj.offsetParent) != null) {
		returnValue += inputObj.offsetLeft;
	}
	return returnValue + calendar_offsetLeft;
}
function positionCalendar(inputObj, calendarDiv) {
	calendarDiv.style.left = getleftPos(inputObj) + "px";
	calendarDiv.style.top = getTopPos(inputObj) + "px";
	if (iframeObj) {
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top = calendarDiv.style.top;
    //// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top = calendarDiv.style.top;
	}
}
function initCalendar(calendarId) {
	if (MSIE) {
		iframeObj = document.createElement("IFRAME");
		iframeObj.style.filter = "alpha(opacity=0)";
		iframeObj.style.position = "absolute";
		iframeObj.border = "0px";
		iframeObj.style.border = "0px";
		iframeObj.style.backgroundColor = "#FF0000";
    //// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2 = document.createElement("IFRAME");
		iframeObj2.style.position = "absolute";
		iframeObj2.border = "0px";
		iframeObj2.style.border = "0px";
		iframeObj2.style.height = "1px";
		iframeObj2.style.width = "1px";
    //// fix for EI frame problem on time dropdowns 09/30/2006
    // Added fixed for HTTPS
		iframeObj2.src = "/images/spacer.gif";
		iframeObj.src = "/images/spacer.gif";
		document.body.appendChild(iframeObj2);  // gfb move this down AFTER the .src is set
		document.body.appendChild(iframeObj);
	}
	calendarDiv = document.createElement("DIV");
	calendarDiv.id = "calendarDiv" + calendarId;
	calendarDiv.className = "calendarDiv";
	calendarDiv.style.zIndex = 1000;
	document.body.appendChild(calendarDiv);
	writeTopBar(calendarId);
	writeCalendarContent();
	writeCloseBar(calendarDiv);
	displayArrows();
}
function calendarSortItems(a, b) {
	return a / 1 - b / 1;
}
function displayCalendar(inputFieldVar, format, buttonObj, calendarId1, calendarToClose, notChangeReturnDateVar) {
	inputField = inputFieldVar;
	regionalFormat = format;
	triedToSetReturnDateToDepartDate = false;
	if (notChangeReturnDateVar) {
		notChangeReturnDate = notChangeReturnDateVar;
	}
  //If the other calendar is opened, than it must be closed
	closeCalendar(calendarToClose);
	calendarId = calendarId1;
	calendarToCloseId = calendarToClose;
  //determine the last active date displayed in the current calendar
	endDate = new Date();
	endDate.setHours(0, 0, 0, 0);
	endDate.setDate(endDate.getDate() + 1);
	endDate.setMonth(endDate.getMonth() - 1);
	endDate.setYear(endDate.getFullYear() + 100);
  //determine the first active date displayed in the current calendar
	startDate = null;
	if (calendarToCloseId == "departureDate") {
		var departureDateCalendar = document.getElementById(calendarToCloseId);
		var departureDate = parseDateFromString(departureDateCalendar.value);
		var currentDate = new Date();
		currentDate.setHours(0, 0, 0, 0);
		if ((departureDate != null) && (departureDate - currentDate >= 0) && (departureDate - endDate <= 0)) {
			startDate = departureDate;
		}
	}
	if (startDate == null) {
		startDate = new Date();
		startDate.setHours(0, 0, 0, 0);
	}
	createDate(inputField, format);
    
    //This is done for the calendar displaying
	if (currentYear) {
		if (currentYear.length == 2) {
			currentYear = 20 + currentYear;
		}
		if (currentYear.length == 1) {
			currentYear = 200 + currentYear;
		}
	}
	calendarDiv = document.getElementById("calendarDiv" + calendarId);
	if (!calendarDiv) {
		initCalendar(calendarId);
	} else {
		if (calendarDiv.style.display == "block") {
			closeCalendar();
			return false;
		}
		writeCalendarContent();
		displayArrows();
	}
	returnFormat = format;
	returnDateTo = inputField;
	positionCalendar(buttonObj, calendarDiv);
	calendarDiv.style.visibility = "visible";
	calendarDiv.style.display = "block";
	if (iframeObj) {
		iframeObj.style.display = "";
		iframeObj.style.height = "140px";
		iframeObj.style.width = "195px";
		iframeObj2.style.display = "";
		iframeObj2.style.height = "140px";
		iframeObj2.style.width = "195px";
	}
}
/*
* Takes the input data value and creates the data
*/
function createDate(inputFieldVar, format) {
	if (inputFieldVar.value.length > 0) {
		if (!format.match(/^[0-9]*?$/gi)) {
			var items = inputFieldVar.value.split(/[^0-9]/gi);
  //In IE if the date is set the items length is 3, and if the default is "DD/MM/YY" the length is 0
  //In Mozilla if the date is set the items length is 3, and if the default is "DD/MM/YY" the length is 9
			if (items.length == 3) {
				var positionArray = new Array();
				positionArray["m"] = format.indexOf("mm");
				if (positionArray["m"] == -1) {
					positionArray["m"] = format.indexOf("m");
				}
				positionArray["d"] = format.indexOf("dd");
				if (positionArray["d"] == -1) {
					positionArray["d"] = format.indexOf("d");
				}
				positionArray["y"] = format.indexOf("yyyy");
				var positionArrayNumeric = Array();
				positionArrayNumeric[0] = positionArray["m"];
				positionArrayNumeric[1] = positionArray["d"];
				positionArrayNumeric[2] = positionArray["y"];
				positionArrayNumeric = positionArrayNumeric.sort(calendarSortItems);
				var itemIndex = -1;
				for (var no = 0; no < positionArrayNumeric.length; no++) {
					if (positionArrayNumeric[no] == -1) {
						continue;
					}
					itemIndex++;
					if (positionArrayNumeric[no] == positionArray["m"]) {
						currentMonth = items[itemIndex] - 1;
						if (currentMonth) {
							if (currentMonth.length == 1) {
								currentMonth = 0 + currentMonth;
							}
						}
						continue;
					}
					if (positionArrayNumeric[no] == positionArray["y"]) {
						currentYear = items[itemIndex];
						continue;
					}
					if (positionArrayNumeric[no] == positionArray["d"]) {
						tmpDay = items[itemIndex];
						if (tmpDay && tmpDay.length == 1) {
							tmpDay = 0 + tmpDay;
						}
						continue;
					}
				}
				currentMonth = currentMonth / 1;
				tmpDay = tmpDay / 1;
				if (currentYear == 0) {
					noDateToDisplay = true;
				}
    
    //Verify if the date is valid
				if (currentMonth < 12 && currentMonth >= 0 && tmpDay != 0) {
					var daysInMonth = daysInMonthArray[currentMonth];
					if (daysInMonth == 28) {
						if (isLeapYear(currentYear)) {
							daysInMonth = 29;
						}
					}
					if (tmpDay > daysInMonth) {
						setTodaysDate();
						noDateToDisplay = true;
					}
				} else {
					setTodaysDate();
					noDateToDisplay = true;
				}
			} else {
				noDateToDisplay = true;
      //This means that the input value is DD/MM/YY"
				if (calendarToCloseId == "departureDate" && !triedToSetReturnDateToDepartDate) {
					var inputdate = document.getElementById(calendarToCloseId);
					if (!verifyIfDefaultDate(calendarToCloseId)) {
						triedToSetReturnDateToDepartDate = true;
						createDate(inputdate, format);
					}
				}
			}
		} else {
			var monthPos = format.indexOf("mm");
			currentMonth = inputFieldVar.value.substr(monthPos, 2) / 1 - 1;
			var yearPos = format.indexOf("yyyy");
			currentYear = inputFieldVar.value.substr(yearPos, 4);
			var dayPos = format.indexOf("dd");
			tmpDay = inputFieldVar.value.substr(dayPos, 2);
		}
	} else {
		noDateToDisplay = true;
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
		tmpDay = d.getDate();
	}
	inputYear = currentYear;
	inputMonth = currentMonth;
	inputDay = tmpDay / 1;
}
/*
 * This funtion is used to change the return date, if is not set, with the value entered in the departure date field
 */
function changeDate(dateField, format) {
  //This check is made for solving the IE issue in order to move cursor in the date field
	if (wasBefore && wasBefore == dateField.value) {
		return;
	}
	wasBefore = dateField.value;
	noDateToDisplay = false;
	currentYear = 0;
	createDate(dateField, format);
	if (!noDateToDisplay) {
		returnFormat = format;
		pickDate(tmpDay);
	}
}
/**
* Sets only the date input field to be selected. This will call the displayCalendar function
*/
function displayCalendarOnClick(inputFieldVar, format, buttonObj, calendarId1, calendarToClose, notChangeReturnDate) {
	inputFieldVar.select();
  //This is a fixed for Safari/419.3(Without this the calendar is not displayed anymore)
  //The check inputFieldVar.value == '' is done to fix the IE issue that when the input field is empty String the calendar is not displayed anymore
	if ((inputFieldVar.value == "") || Safari_Macintosh) {
		displayCalendar(inputFieldVar, format, buttonObj, calendarId1, calendarToClose, notChangeReturnDate);
	}
}
function setTodaysDate() {
	var d = new Date();
	currentMonth = d.getMonth();
	currentYear = d.getFullYear();
	tmpDay = d.getDate();
}
/**
 * Parses the date from the given string. The expected format is DD/MM/YY. Returns null in case the given string 
 * does not contain a valid date.
 */
function parseDateFromString(depDateStr) {
	var items = depDateStr.split(/[^0-9]/gi);
  
  //In IE if the date is set the items length is 3, and if the default is "DD/MM/YY" the length is 0
  //In Mozilla if the date is set the items length is 3, and if the default is "DD/MM/YY" the length is 9
	if (items.length == 3) {
		var dayPosition = regionalFormat.indexOf("dd") / 3;
		var monthPosition = regionalFormat.indexOf("mm") / 3;
		var yearPosition = regionalFormat.indexOf("yyyy") / 3;
		var dateFields = depDateStr.split("/");
		if (dateFields.length != 3) {
  		//invalid date format
			return null;
		}
		if ((dateFields[0] / 1 != dateFields[0]) || (dateFields[1] / 1 != dateFields[1]) || dateFields[2] / 1 != dateFields[2]) {
  		//some of the date fields are not numeric
			return null;
		}
		var day = dateFields[dayPosition] / 1;
		var month = dateFields[monthPosition] / 1 - 1;
		var year = dateFields[yearPosition] / 1;
		if (dateFields[2].length < 4) {
			var tmpDate = new Date();
			var century = tmpDate.getFullYear() - (tmpDate.getFullYear() % 1000);
			year = century + year;
		}
		var result = new Date(year, month, day);
		if ((result.getFullYear() != year) || (result.getMonth() != month) || (result.getDate() != day)) {
  	 //invalid date
			return null;
		}
	} else {
		return null;
	}
	return result;
}

