/* CarFlightSearchValidator object */
function CarFlightSearchValidator(earliestBookingDate,formId,departCalendar,returnCalendar,dataContainer,departTime,returnTime){
	this.earliestBookingDate=earliestBookingDate;
	this.formId=formId;
	this.departCalendar=departCalendar;
	this.returnCalendar=returnCalendar;
	this.dataContainer = dataContainer;
	this.departTime = departTime;
	this.returnTime = returnTime;
	this.invalidLocationOptions=['','select a city','Select a City','selectacity','separator'];
}

CarFlightSearchValidator.prototype.validateLocations=function(){

	for(var i=0;i<this.invalidLocationOptions.length;++i){
		if(this.from.value==this.invalidLocationOptions[i]){
			alert('Please select a departure location.');
			this.from.focus();
			return false;
		}

	}
	for(var i=0;i<this.invalidLocationOptions.length;++i){
		

		if(this.to.value==this.invalidLocationOptions[i]){
			alert('Please select an arrival location.');
			this.to.focus();
			return false;
		}
	}
	return true
}

CarFlightSearchValidator.prototype.validateDates=function(){
	/*if(this.departCalendar.getDate().getTime()<this.earliestBookingDate.getTime()){
		alert('Online bookings must be made for flights departing after '+this.earliestBookingDate.format('DDDD D mmmm YYYY HH:00')+'.\nDeparture date needs to be on or after this date.');
		this.departCalendar.monthYearField.focus();
		return false;
	}*/

	var carDepartTime = this.departCalendar.getDate().format('YYYYmmDD')+(this.departTime).value +"00";
	var carReturnTime = this.returnCalendar.getDate().format('YYYYmmDD')+(this.returnTime).value +"00";

	if(carDepartTime > carReturnTime){
		alert('Return date cannot be before depart date.');
		this.returnCalendar.monthYearField.focus();
		return false;
	}

	return true;
}

CarFlightSearchValidator.prototype.internationalInitialise=function(){
	
	var form=document.getElementById(this.formId);
	this.from=form.carPickUp;
	this.to=form.carDropOff;
	this.carVendor = form.carCompanyVendor;
	this.departTime = form.carDepartTime;
	//this.departTime = document.getElementById(this.carDepartTime);
	//this.returnTime = document.getElementById(this.returnTime);
	this.returnTime = form.carReturnTime;
}



CarFlightSearchValidator.prototype.internationalSetSelections=function(){
	this.setSelections(false);
}

CarFlightSearchValidator.prototype.internationalValidateAndSubmit=function(isFFLoggedIn,submitForm){
	this.internationalInitialise();
	
	// The order these validate methods are called in is important.
	if(!this.validateLocations()){return false;}
	if(!this.validateDates()){return false;}
		//Commented for the CQ14917
		//document.carForm.submit();
		return true;
}


