function validDate(day, month, year)
{
	//Adj month: 0=Jannuary and so on
	month = month - 1;
	if (month < 0)
		//Invalid month
		return false;
		
	//Convert datePart to date
	var dDate = new Date(year, month, day, "23", "59", "59")

	//Check Valid Date: Valid only when dateparts do not modify by creating date
	if (dDate.getDate() != day)
		//day in DateObject not equale with day: invalid date
		return false;

	if (dDate.getMonth() != month)
		//month in DateObject not equale with day: invalid date
		return false;

	if (dDate.getFullYear() != year)
		//year in DateObject not equale with day: invalid date
		return false;

	//Check date in past
	//getNow
	var dNow = new Date();

	if (dDate.valueOf() < dNow.valueOf())
		return false;
	
	return true;
}

function setDateToToday(foDay,foMonth,foYear) {
	// get the date from server if we can.
	var now;
	now = new Date();
	var index_year = now.getFullYear();
	var index_month = now.getMonth(); // in Javascript, months are zero-based
	var index_day = now.getDate();
	var index_checkin = new Date(index_year, index_month, index_day);
	oneDayInMillisec =  24 * 3600 * 1000;
	checkinMillis = index_checkin.getTime() + oneDayInMillisec;
	chin = new Date( checkinMillis );
	var oneDayInMillisecAdjusted = (24 * 3600 * 1000) + (3600 * 1000);

	if(chin.getDate() == index_checkin.getDate()) {
		while(chin.getDate() == index_checkin.getDate()) {
			chin = new Date(index_checkin.getTime() + oneDayInMillissecAdjusted);
			oneDayInMillissecAdjusted += 3600;
		}
	}
	
	var index_y = getYearIdx(index_year);
	var index_m = parseInt(chin.getMonth(), 10 ) +1;
	var index_days = parseInt(chin.getDate(), 10 )-1;  		
	//alert("year= " + index_year + " month= " + index_month + " day= " + index_day);
	//alert("year= " + [index_y-1] + " month= " + index_m + " day= " + index_days);

	foYear.options[0].selected = true;
	foMonth.options[index_m-1].selected = true;
	//alert(index_days)
	foDay.options[index_days].selected = true;
}


function getYearIdx(y) {
  	year = y.toString();
	//alert(parseInt(stripZero(year.slice(2)) ,10))
    return parseInt( stripZero(year.slice(2)) ,10) ;
}

// (cancella) strip leading zero, if any.
function stripZero(s) {
   if(s.charAt(0) == '0')
      s = s.substr(1);
   return s;
}


/*======================   CALENDAR SETUP   ==========================*/
function OpenCalendar(lang) {
  //alert("");
  var OP = ((ind1 = navigator.userAgent.indexOf("Opera")) > -1) ? 1 : 0; 
  var IE = ((ind2 = navigator.appVersion.indexOf("MSIE")) > -1 && !OP) ? 1 : 0;
	var sTop = (screen.availWidth-165)/2
	var sLeft = (screen.availHeight-236)/2
	var oInput = AMonth.options[AMonth.selectedIndex].value + "/" + ADay.options[ADay.selectedIndex].value + "/" + AYear.options[AYear.selectedIndex].value
	document.getElementById('popcaldate').value = oInput
	myFloater = window.open('','NewCalendar','scrollbars=no,status=no,width=195,height=200,top='+sTop+',left='+sLeft+',resizable=no');
	if ( myFloater.opener == null )    myFloater.opener = self;
	if(!IE)
    myFloater.location.href = "../ReservationEngine/SearchForms/Calendar_PopUp.asp?Language="+lang;
  else 
    myFloater.location.href = "ReservationEngine/SearchForms/Calendar_PopUp.asp?Language="+lang;
	
}

function setDate(mn,dy,yr) {	
	selectInList(AMonth, mn);
	selectInList(ADay, dy);
	selectInList(AYear, yr);
}
		
function selectInList(inList, val){
	var Counter = 0;
	for (Counter=0 ; Counter < inList.length; Counter++ )	{ 
		if (inList.options[Counter].value == val){
			inList.options[Counter].selected = true;
			break;
		}
	}
}

