function setDestination(city) {
	var dpform = document.getElementById("tripPackageHotelFlightSearchForm");
	dpform.selectedIndex = 1;
	dpform.destination.selectedIndex = city;
}

////////////////////////////////////////////////////////////////
// as per baseline below
////////////////////////////////////////////////////////////////
rightnow = new Date();
//write dates to dropdown
function month(i,name) {
	var thisyear = rightnow.getFullYear();
	var nextyear = thisyear + 1;
	var a = "<option value=\"";
	(i<rightnow.getMonth()) ? a +=nextyear : a +=thisyear;
	(i<9) ? a += "0"+(i+1) : a +=(i+1);
	a += "\">"+name+" ";
	(i<rightnow.getMonth()) ? a +=(nextyear) : a +=(thisyear);
	a += "</option>\n";
	this.option = a;
}														
var months = new Array(new month(0,"Jan"), new month(1,"Feb"),new month(2,"Mar"),new month(3,"Apr"),new month(4,"May"), new month(5,"Jun"), new month(6,"Jul"), new month(7,"Aug"), new month(8,"Sep"), new month(9,"Oct"), new month(10,"Nov"), new month(11,"Dec"));
var mDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)	
	function calcDay(frm,nm,nm2){
 dateVal = document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;
 monthVal = document.forms[frm].elements[nm2].options[document.forms[frm].elements[nm2].selectedIndex].value;
 var isLeapYear = (((monthVal.substr(0,4) % 4 == 0) && (monthVal.substr(0,4) % 100 != 0)) || (monthVal.substr(0,4) % 400 == 0));
 mDays[1] = (isLeapYear)?29:28;
 if(dateVal > mDays[monthVal.substr(4,2)-1]){
  setDDValue(document.forms[frm].elements[nm],mDays[monthVal.substr(4,2)-1]);
  dateVal = document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;
  }
 }
function setDDValue(oDropDown, sValue){
 for(var iIndex=0; iIndex<oDropDown.options.length; ++iIndex){
  if(oDropDown.options[iIndex].value == sValue){
   oDropDown.selectedIndex = iIndex;
   break;
   }
  }
 }

function frmCheckSubmit(){
	var f1 = document.frm
	//var f2 = document.frm
	monthYear = f1.outboundDateMonthYear.options[f1.outboundDateMonthYear.selectedIndex].value;
	dayVal = f1.outboundDateDate.options[f1.outboundDateDate.selectedIndex].value;
	monthVal= monthYear.substr(4,2);
	yearVal = monthYear.substring(0,4);
				
	secMonthYear = f1.returnDateMonthYear.options[f1.returnDateMonthYear.selectedIndex].value;
	secDayVal = f1.returnDateDate.options[f1.returnDateDate.selectedIndex].value;
	secMonthVal = secMonthYear.substr(4,2);
	secYearVal = secMonthYear.substring(0,4);
	
	var date = new Date(yearVal, monthVal-1, dayVal);
	var secdate = new Date(secYearVal, secMonthVal-1, secDayVal);
	var theDate = date.getDate();
	var theSecDate = secdate.getDate();
	var DCity = f1.originInput.value;
	var ACity = f1.destination.value;
	
			if (DCity==0) {
				alert("Please enter a destination (From) name");
				f1.originInput.focus();
				return false;
			}
			if (ACity==0) {
				alert("Please enter a destination (To) name");
				f1.destination.focus();
				return false;
			}
	
	
			if (!((rightnow.valueOf() < date.valueOf()) && (date.valueOf() < secdate.valueOf()))) {
				alert("Please enter valid return and departure dates");
				return false;			
			} else {
				f1.submit();
				return false;	
			}
 }
	
function opodoInit() {
		var f1 = document.frm
		tomorrow = new Date(rightnow.getTime()+(604800000));
		for(d=0;d<31;d++) f1.outboundDateDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
		for(d=0;d<31;d++) f1.returnDateDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
		f1.outboundDateDate.selectedIndex = tomorrow.getDate()-1;
		if(tomorrow.getDate()-1 >6){f1.outboundDateMonthYear.selectedIndex = 0}
		else{f1.outboundDateMonthYear.selectedIndex = 1}
		then = new Date(tomorrow.getTime()+(604800000));
		f1.returnDateDate.selectedIndex = then.getDate()-1;
		if(then.getDate()-1 >13){f1.returnDateMonthYear.selectedIndex = 0}
		else{f1.returnDateMonthYear.selectedIndex = 1}
		stopMouseWheel()
}

function generateInfantRoomAllocation(){
	var searchForm = document.forms['frm'];
	if (searchForm == null){
		searchForm = document.forms['frm'];
	}
	var inputName = 'roomAllocations[0].adultQuantity';
	var infantRoomAllocation = 'roomAllocations[0].infantQuantity';
	var totalTravellers=parseInt(searchForm[inputName].value);
	generateOption(searchForm[infantRoomAllocation], parseInt(searchForm[inputName].value));
}
function generateOption(elem, num){
	var prevSelectedVal = elem.value;

	elem.length = 0;
	for (var i=0; i<=num; i++){
		var option = document.createElement('option');
		option.value = i;
		option.innerHTML = i;
		if (i==prevSelectedVal){
			option.selected = "true";
		}
		elem.appendChild(option);
		if (prevSelectedVal < elem.length){
			elem.selectedIndex = prevSelectedVal;
		} else {
			elem.selectedIndex = elem.length - 1;
		}
	}
}

function stopMouseWheel(){
if (window.attachEvent && document.getElementsByTagName) {
	var  sel = document.getElementsByTagName("select");
	for (i=0; i<sel.length; ++i) {
			sel[i].attachEvent('onmousewheel', function() {return false;});
		}
	}
}
function copyDestinationName() {
	var destinationList = document.getElementById('destination');
	var destElement = document.getElementById('destinationInput');
	var toCopy = destinationList.options[destinationList.selectedIndex];
	destElement.value = toCopy.innerHTML;
}
