//Flight SearchEngine

function fValidateSearch(which) //
{
	
	var TotalPax,Adult,Child,Infant
	TotalPax=parseInt(which.FAdult.value,10)+parseInt(which.FChild.value,10)+parseInt(which.FInfant.value,10);
	Adult=parseInt(which.FAdult.value,10)
	Child=parseInt(which.FChild.value,10);
	Infant=parseInt(which.FInfant.value,10)
	if (Infant > Adult) 
		{
		alert("Number of infants should be equal to or less then number of adults")
		return false;
		}
	if(TotalPax>9)
	{
	alert("Total no of person should not be more than 9")
	return false;
	}
	if(fDateValidation(which)==false)
	{
	return false;
	}
return true;
}
function fDateValidation(which)
{

	var currDate=new Date(parseInt(which.CurrDate.value.substr(4,4),10),parseInt(parseInt(which.CurrDate.value.substr(2,2),10)-1,10),parseInt(which.CurrDate.value.substr(0,2),10))
	//var DptDate= new Date(parseInt(which.FDptMMYear.value.substr(2,4),10),parseInt(parseInt(which.FDptMMYear.value.substr(0,2),10)-1,10),parseInt(which.FDptDate.value,10));
	
	var DptDateTemp= which.FDptDateDDMMYY.value.replace("/", "")
	DptDateTemp= DptDateTemp.replace("/", "")	
	var DptDate= new Date(parseInt(DptDateTemp.substr(4,6),10),parseInt(parseInt(DptDateTemp.substr(2,2),10)-1,10),parseInt(DptDateTemp.substr(0,2),10));
	if(new Date(currDate.getFullYear(),currDate.getMonth(),currDate.getDate()+1)>=DptDate)
	{
		  alert("If DEPARTURE IS WITHIN 48 HOURS, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
		  return false;
	}

	if(which.FJrnType.value!="1")
	   {
	//var RetDate= new Date(parseInt(which.FRetMMYear.value.substr(2,4),10),parseInt(parseInt(which.FRetMMYear.value.substr(0,2),10)-1,10),parseInt(which.FRetDate.value,10));
	var RetDateTemp= which.FRetDateDDMMYY.value.replace("/", "")
	RetDateTemp= RetDateTemp.replace("/", "")	
	var RetDate= new Date(parseInt(RetDateTemp.substr(4,6),10),parseInt(parseInt(RetDateTemp.substr(2,2),10)-1,10),parseInt(RetDateTemp.substr(0,2),10));
	
	if(document.getElementById("FareOnly").value=="1")
		{		
		var one_day=1000*60*60*24;
		var strdiff=Math.ceil((RetDate.getTime()-DptDate.getTime())/(one_day))
	      if(strdiff<6) 
			  {
			  alert("The minimum diffenrence between the dates should be 6 days.If you want to search less than 6 days,please uncheck the 'My dates are flexible'")
			  return false;
			  } 
		}
	if(new Date(currDate.getFullYear(),currDate.getMonth()+11,currDate.getDate())<RetDate)
			{
			  alert("Return date should be within 11 month after current date, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
			  return false;
			}
		if(DptDate>=RetDate)
			{
				  alert("Departure date cannot be greater than or equal return date");
				  return false;
			}
	   }
	   else
	   {
		if(new Date(currDate.getFullYear(),currDate.getMonth()+11,currDate.getDate())<DptDate)
			{
			alert("Departure date should be within 11 month after current date, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
			return false;
			}
		
	   }
	return true;
}

//End or FLight Search Engine


//Flight+Hotel Search Engine

function fhValidateSearch(which) //
{
	
	var TotalPax,Adult,Child,Infant
	TotalPax=parseInt(which.FHAdult.value,10)+parseInt(which.FHChild.value,10)+parseInt(which.FHInfant.value,10);
	Adult=parseInt(which.FHAdult.value,10)
	Child=parseInt(which.FHChild.value,10);
	Infant=parseInt(which.FHInfant.value,10)
	if (Infant > Adult) 
		{
		alert("Number of infants should be equal to or less then number of adults")
		return false;
		}
	if(TotalPax>9)
	{
	alert("Total no of person should not be more than 9")
	return false;
	}
	if(fhDateValidation(which)==false)
	{
	return false;
	}
	if(paxRoomFHValidation(which)==false)
	{
	return false;
	}	
return true;
}
function fhDateValidation(which)
{

	var currDate=new Date(parseInt(which.FHCurrDate.value.substr(4,4),10),parseInt(parseInt(which.FHCurrDate.value.substr(2,2),10)-1,10),parseInt(which.FHCurrDate.value.substr(0,2),10))
	
	
	//var DptDate= new Date(parseInt(which.FHDptMMYear.value.substr(2,4),10),parseInt(parseInt(which.FHDptMMYear.value.substr(0,2),10)-1,10),parseInt(which.FHDptDate.value,10));
	//var RetDate= new Date(parseInt(which.FHRetMMYear.value.substr(2,4),10),parseInt(parseInt(which.FHRetMMYear.value.substr(0,2),10)-1,10),parseInt(which.FHRetDate.value,10));
	
	var DptDateFH= which.FHDptDateDDMMYY.value.replace("/", "")
	DptDateFH= DptDateFH.replace("/", "")	
	
	var RetDateFH= which.FHRetDateDDMMYY.value.replace("/", "")
	RetDateFH= RetDateFH.replace("/", "")
	
	var DptDate= new Date(parseInt(DptDateFH.substr(4,6),10),parseInt(parseInt(DptDateFH.substr(2,2),10)-1,10),parseInt(parseInt(DptDateFH.substr(0,2),10),10));
	var RetDate= new Date(parseInt(RetDateFH.substr(4,6),10),parseInt(parseInt(RetDateFH.substr(2,2),10)-1,10),parseInt(parseInt(RetDateFH.substr(0,2),10),10));

	if(new Date(currDate.getFullYear(),currDate.getMonth(),currDate.getDate()+1)>=DptDate)
	{
		  alert("IF DEPARTURE IS WITHIN 48 HOURS, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
		  return false;
	}
	
//	if(new Date(currDate.getFullYear()+1,currDate.getMonth(),currDate.getDate())<RetDate)
//	{
//		  alert("If return date after one year of current date, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
//		  return false;
//	}

	if(DptDate>=RetDate)
	{
		  alert("Departure date cannot be greater than or equal return date");
		  return false;
	}
	return true;
}


function paxRoomFHValidation(which)  //return for flthtlsearch.aspx 
{
		var adValue,twValue,doValue,siValue,triValue,total;
		adValue=new Number(which.FHAdult.value);
		chValue=new Number(which.FHChild.value);
		invalue=new Number(which.FHInfant.value);
		siValue=new Number(which.FHSngRoom.value);
		twValue=new Number(which.FHTwnRoom.value);
		doValue=new Number(which.FHDblRoom.value);
		triValue=new Number(which.FHTplRoom.value);
		
		twValue=twValue*2
		doValue=doValue*2
		triValue=triValue*3
		total=(twValue+doValue+siValue+triValue)
		if(adValue == 0)
			{
			alert("Invalid Room Selection.")
			which.FHAdult.focus();
			return false;
			}
			else if (chValue==0 && invalue==0)
			{
			if(total!=adValue)
				{
				if(which.FHDblRoom.value==adValue && which.FHTplRoom.value ==0 && which.FHTwnRoom.value ==0 && which.FHSngRoom.value ==0)
					{
					return true;
					}
				else if(which.FHDblRoom.value==0 && which.FHTplRoom.value ==0 && which.FHTwnRoom.value ==adValue && which.FHSngRoom.value ==0)
					{
					 return true;
					}
					 else
					{
					 alert("Invalid Room Selection.")
					 which.FHAdult.focus();
					 return false;
					}
                 }
			 }
			else if (chValue>0 && invalue==0)
			{ 
			var adchtotal=chValue+adValue
				if (adchtotal>9)
  				{
				alert("Total no of person should not be more than 9")
				which.FHAdult.focus();
				return false;
				}
				
				if ((doValue==adValue || twValue==adValue || (twValue+doValue)==adValue || total==adValue ) && chValue<=adValue/2 )
				{
				if (total!=adValue )
					{
					alert("Invalid Room Selection.")
					which.FHAdult.focus();
					return false;
					}
				}
				else if (total!=adchtotal)
 	 			{
				alert("Invalid Room Selection.")
				which.FHAdult.focus();
				return false;
    	     	}
			}
			else if (chValue==0 && invalue>0)
			{
			var inadtotal=invalue+adValue
  			if (inadtotal>9)
  				{
				alert("Total no of person should not be more than 9")
				which.FHAdult.focus();
				return false;
  				}

				if (invalue>adValue)
			  	{
				alert("Number of infants should be equal to or less then number of adults")
				which.FHAdult.focus();
				return false;
			  	}
				else if(total!=adValue)
				{
				alert("Invalid Room Selection.")
				which.FHAdult.focus();
				return false;
				}
			}
			else if (chValue>0 && invalue>0)
			{
			var chinadtotal=invalue+adValue+chValue
			if (chinadtotal>9)
  				{
				alert("Total no of person should not be more than 9")
				which.FHAdult.focus();
				return false;
               }
			   
			if (invalue>adValue)
  				{
				alert("Number of infants should be equal to or less then number of adults")
				which.FHAdult.focus();
				return false;
  				}


			if ((doValue==adValue || twValue==adValue || (twValue+doValue)==adValue || total==adValue) && chValue<=adValue/2 && invalue<=adValue)
				{
				if (total!=adValue )
					{
					alert("Invalid Room Selection.")
					which.FHAdult.focus();
					return false;
					}
				}

		 if(total!=adValue+chValue)
				{
				alert("Invalid Room Selection.")
				which.FHAdult.focus();
				return false;
				}
		}	
		
		//
		//suman
		
return true;
}

//Hotel Search Engine

function hValidateSearch(which) //
{
	var sngRoom,twnRoom,dblRoom,tplRoom,total;
	sngRoom=new Number(document.getElementById("HSingle").value);
	twnRoom=new Number(document.getElementById("HTwin").value);
	dblRoom=new Number(document.getElementById("HDouble").value);
	tplRoom=new Number(document.getElementById("HTriple").value);
	total=(twnRoom+dblRoom+sngRoom+tplRoom)
	if(hDateValidation(which)==false)
	{
	return false;
	}

	if(total<1)
	{
	alert("Please select a room type.")
	document.getElementById("HSingle").focus();
	return false;
	}
return true;
}
function hDateValidation(which)
{

	var currDate=new Date(parseInt(which.HCurrDate.value.substr(4,4),10),parseInt(parseInt(which.HCurrDate.value.substr(2,2),10)-1,10),parseInt(which.HCurrDate.value.substr(0,2),10));
//	var DptDate= new Date(parseInt(which.HDptMMYear.value.substr(2,4),10),parseInt(parseInt(which.HDptMMYear.value.substr(0,2),10)-1,10),parseInt(which.HDptDate.value,10));
//	var RetDate= new Date(parseInt(which.HRetMMYear.value.substr(2,4),10),parseInt(parseInt(which.HRetMMYear.value.substr(0,2),10)-1,10),parseInt(which.HRetDate.value,10));

	var DptDateH= which.HDptDateDDMMYY.value.replace("/", "")
	DptDateH= DptDateH.replace("/", "")	
	
	var RetDateH= which.HRetDateDDMMYY.value.replace("/", "")
	RetDateH= RetDateH.replace("/", "")	
		
	var DptDate= new Date(parseInt(DptDateH.substr(4,6),10),parseInt(parseInt(DptDateH.substr(2,2),10)-1,10),parseInt(DptDateH.substr(0,2),10));
	var RetDate= new Date(parseInt(RetDateH.substr(4,6),10),parseInt(parseInt(RetDateH.substr(2,2),10)-1,10),parseInt(RetDateH.substr(0,2),10));
		
	
	if(new Date(currDate.getFullYear(),currDate.getMonth(),currDate.getDate()+1)>=DptDate)
	{
		  alert("IF Check in IS WITHIN 48 HOURS, PLEASE CONTACT OUR RESERVATIONS DEPARTMENT ON 0208 518 1010");
		  return false;
	}
	
	if(DptDate>=RetDate)
	{
		  alert("Checkin date cannot be greater than or equal checkout date");
		  return false;
	}
	return true;
}

function setFareType()
{
	if(document.getElementById("FlexID").checked==true)
		{
			document.getElementById("FareOnly").value="1"
		}
		else
		{
			document.getElementById("FareOnly").value="0"
		}
}




