/************************************************************************************************************************************
			AirWorld Tours (Powered By: Pound Saver London. PSL LTD. www.pslwebsol.co.uk)

			Page Name      : searchonline.php
			Developer Name : Ghulam Murtaza
			Develop Date   : 15-Jul-2006

************************************************************************************************************************************/

function verifyForm()
{
	if (document.FrmBooking.cboCountry.value == 0)
	{
		alert("Please Select Country");
		document.FrmBooking.cboCountry.focus();			
	}
	else if (document.FrmBooking.cboDest.value == 0)
	{
		alert("Please Select Destination");
		document.FrmBooking.cboDest.focus();			
	}
	else if (checkDate(document.FrmBooking.cboArrivalDays.value,document.FrmBooking.cboArrivalMonths.value,document.FrmBooking.cboArrivalYears.value,1))
	{
		alert("Invalid Arrival Date");
	}
	else if(checkDate(document.FrmBooking.cboDepartureDays.value,document.FrmBooking.cboDepartureMonths.value,document.FrmBooking.cboDepartureYears.value,1))
	{
		alert("Invalid Departure Date");
	}
	else
	{
		document.FrmBooking.hdnCountryName.value=document.FrmBooking.cboCountry[document.FrmBooking.cboCountry.selectedIndex].text;
		document.FrmBooking.hdnDestName.value=document.FrmBooking.cboDest[document.FrmBooking.cboDest.selectedIndex].text;
		document.FrmBooking.hdnZoneName.value=document.FrmBooking.cboZone[document.FrmBooking.cboZone.selectedIndex].text;				
		document.FrmBooking.hdnZone.value=document.FrmBooking.cboZone.value;
		document.FrmBooking.submit();
	}
}

function verifyForm2()
{
	if(checkDate(document.FrmBooking.elements['cboArrivalDays'].value,document.FrmBooking.elements['cboArrivalMonths'].value,document.FrmBooking.elements['cboArrivalYears'].value,1))
	{
		alert("Invalid Arrival Date");
	}
	else if(checkDate(document.FrmBooking.cboDepartureDays.value,document.FrmBooking.cboDepartureMonths.value,document.FrmBooking.cboDepartureYears.value,1))
	{
		alert("Invalid Departure Date");
	}
	else
		document.FrmBooking.submit();
}

function changeDate()
{
	var numDays = document.getElementById('FrmBooking').cboNights.value;
	if (numDays.charAt(0) == "0")
		numDays = parseInt(numDays.substring(1));
	else
		numDays = parseInt(numDays);
	if(checkDate(document.getElementById('FrmBooking').elements['cboArrivalDays'].value,document.getElementById('FrmBooking').elements['cboArrivalMonths'].value,document.getElementById('FrmBooking').elements['cboArrivalYears'].value,1))
	{
		alert("Invalid Date Selected");
		return false;
	}
	adddayss(document.getElementById('FrmBooking').elements['cboArrivalYears'].value,document.getElementById('FrmBooking').elements['cboArrivalMonths'].value,document.getElementById('FrmBooking').elements['cboArrivalDays'].value,numDays);
}

/*change date when combo value of accountopendate change*/
function changeArrivalDate()
{
	strDays=document.getElementById('FrmBooking').cboArrivalDays.value;
	strMonths=document.getElementById('FrmBooking').cboArrivalMonths.value;
	strYears=document.getElementById('FrmBooking').cboArrivalYears.value;
	if(strYears==0)
		strReviewYears=0;
	else
		strReviewYears=(parseInt(strYears));			
	strDate=(strYears)+"-"+(strMonths)+"-"+(strDays);
	document.getElementById('FrmBooking').txtArrivalDate.value=strDate;
	changeDate();
}

/*change date when combo value of creditreviewdate change*/
function changeDepartureDate()
{	
	strDays=document.getElementById('FrmBooking').cboDepartureDays.value;
	strMonths=document.getElementById('FrmBooking').cboDepartureMonths.value;		
	strYears=document.getElementById('FrmBooking').cboDepartureYears.value;
	if(checkDate(document.getElementById('FrmBooking').cboDepartureDays.value,document.getElementById('FrmBooking').cboDepartureMonths.value,document.getElementById('FrmBooking').cboDepartureYears.value,1))
	{
		alert("Invalid Date Selected");
		return false;
	}
	strDate=(strYears)+"-"+(strMonths)+"-"+(strDays);
	document.getElementById('FrmBooking').txtDepartureDate.value=strDate;
	
	//Check wither check out date is greater than or less than check in date	
	strCheckInDays=document.getElementById('FrmBooking').cboArrivalDays.value;
	strCheckInMonths=document.getElementById('FrmBooking').cboArrivalMonths.value;
	strCheckInYears=document.getElementById('FrmBooking').cboArrivalYears.value;
	
	var objCheckInDate=new Date(strCheckInYears,strCheckInMonths,strCheckInDays);
	strCheckInDate=(objCheckInDate.getTime());		
	
	strCheckOutDays=(document.getElementById('FrmBooking').elements['cboDepartureDays'].value);
	strCheckOutMonths=(document.getElementById('FrmBooking').elements['cboDepartureMonths'].value);	
	strCheckOutYears=(document.getElementById('FrmBooking').elements['cboDepartureYears'].value);
	
	var objCheckOutDate=new Date(strCheckOutYears,strCheckOutMonths,strCheckOutDays);
	strCheckOutDate=(objCheckOutDate.getTime());		
	if(strCheckOutDate < strCheckInDate)
	{
		changeDate();
		alert("Departure Date Should Be Equal Or Greater than Arrival Date");
		return false;
	}
	var Diff = strCheckOutDate - strCheckInDate;
	var NoOfNights = Diff / (24*60*60*1000);
	if(NoOfNights<10)
		NoOfNights = "0"+NoOfNights;
	document.getElementById('FrmBooking').cboNights.value = NoOfNights;	
}

function adddayss(numYears,numMonths,numDays,addDays2)
{
	var AddDays = parseInt(addDays2);
	numMonths = numMonths - 1;
	TDate = new Date(numYears,numMonths,numDays);
	TDay = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	TMonth = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	MonthDays = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
	
	CurYear = TDate.getYear();
	if (CurYear < 2000)
		CurYear = CurYear + 1900;
	CurMonth = TDate.getMonth();
	CurDayOw = TDate.getDay();
	CurDay = TDate.getDate();
	CurMonth = CurMonth + 1;
	if(CurMonth == 0)
		CurMonth = 12;		

	CurMonth = CurMonth-1;
	month = TMonth[CurMonth];
	if (month == 'February')
	{
		if (((CurYear % 4)==0) && ((CurYear % 100)!=0) || ((CurYear % 400)==0))
			MonthDays[1] = 29;
		else
			MonthDays[1] = 28;
	}
	days = MonthDays[CurMonth];
	CurDay += AddDays;
	while (CurDay > days)
	{
		if (CurMonth == 11)
		{
			CurMonth = 0;
			month = TMonth[CurMonth+1];
			if(CurMonth != 0)
				CurMonth = CurMonth + 1;
			CurYear = CurYear + 1;
		}
		else
		{
			month = TMonth[CurMonth+1];
			CurMonth = CurMonth + 1;				

		}
		CurDay = CurDay - days;
		days = MonthDays[CurMonth];
	}
	CurMonth = CurMonth + 1;
	CurDayOw += AddDays;
	adjustDay(CurDayOw);
	TheDate  = CurDayOw + ', ';
	TheDate += month + ' ';
	TheDate += CurDay + ', ';
	if (CurYear<100) CurYear="20" + CurYear;
		TheDate += CurYear;
	if(parseInt(CurDay)<10)
		CurDay = "0"+CurDay;
	if(parseInt(CurMonth)<10)
		CurMonth = "0"+CurMonth;
	document.getElementById('FrmBooking').elements['cboDepartureDays'].value   = CurDay;
	document.getElementById('FrmBooking').elements['cboDepartureMonths'].value = CurMonth;
	document.getElementById('FrmBooking').elements['cboDepartureYears'].value  = parseInt(CurYear);
	strDays=document.getElementById('FrmBooking').cboDepartureDays.value;
	strMonths=document.getElementById('FrmBooking').cboDepartureMonths.value;		
	strYears=document.getElementById('FrmBooking').cboDepartureYears.value;
	strDate=(strYears)+"-"+(strMonths)+"-"+(strDays);
	document.getElementById('FrmBooking').txtDepartureDate.value=strDate;
	//alert(document.getElementById('FrmBooking').elements['cboReviewDays'].value+" - "+document.getElementById('FrmBooking').elements['cboReviewMonths'].value+" - "+document.getElementById('FrmBooking').elements['cboReviewYears'].value);
}
function adjustDay (cday)
{
	if (cday > 6)
	{
		cday -= 6;
		CurDayOw = TDay[cday-1];
		adjustDay(cday-1);
	}
	else
	{
		CurDayOw = TDay[cday];
		return true;	
	}
}	

function splitAccountOpenDate()
{			
	strArrivalDate=document.getElementById('FrmBooking').txtArrivalDate.value;		
	var objArrivalDate = new String(strArrivalDate);
	strSplitArrivalDate=objArrivalDate.split("-");		//split date

	numArrivalYear=strSplitArrivalDate[0];				//Year		
	numArrivalMonth=strSplitArrivalDate[1];				//Month
	numArrivalDay=strSplitArrivalDate[2];				//Days		

	document.getElementById('FrmBooking').cboArrivalDays.value=numArrivalDay;			//AccountOpenDate Day
	document.getElementById('FrmBooking').cboArrivalMonths.value=numArrivalMonth;		//AccountOpenDate Month		
	document.getElementById('FrmBooking').cboArrivalYears.value=numArrivalYear;		//AccountOpenDate Year

	numArrivalYear=(parseInt(numArrivalYear));		//Increment in year of accountopendate	

	document.getElementById('FrmBooking').cboDepartureDays.value=numArrivalDay;				//CreditReview Day		
	document.getElementById('FrmBooking').cboDepartureMonths.value=numArrivalMonth;			//CreditReview Month		
	document.getElementById('FrmBooking').cboDepartureYears.value=numArrivalYear;			//CreditReview Year
	
	numDepartureYear=((numArrivalYear));						//ReviewDate year
	
	strDate=(numDepartureYear)+"-"+(numArrivalMonth)+"-"+(numArrivalDay);  //reviewdate
	document.getElementById('FrmBooking').txtDepartureDate.value=strDate;		
	
	if(document.getElementById('FrmBooking').txtArrivalDate.value=="")
	{
		document.getElementById('FrmBooking').cboDepartureDays.value='<?print(date("d"));?>';
		document.getElementById('FrmBooking').cboDepartureMonths.value='<?print(date("m"));?>';		
		document.getElementById('FrmBooking').cboDepartureYears.value='<?print(date("Y"));?>';							
	}
}

function splitReviewDate()
{	
	strDepartureDate=document.getElementById('FrmBooking').txtDepartureDate.value;

	var objReviewDate = new String(strDepartureDate);
	strSplitDepartureDate=objReviewDate.split("-");		//split date
			
	numDepartureYear=strSplitDepartureDate[0];				//Year		
	numDepartureMonth=strSplitDepartureDate[1];				//Month
	numDepartureDay=strSplitDepartureDate[2];				//Day

	document.getElementById('FrmBooking').cboDepartureDays.value=numDepartureDay;				// CreditReview Day 
	document.getElementById('FrmBooking').cboDepartureMonths.value=numDepartureMonth;			//CreditReview Month		
	document.getElementById('FrmBooking').cboDepartureYears.value=numDepartureYear;				//CreditReview Year

	if(document.getElementById('FrmBooking').txtDepartureDate.value=="")
	{
		document.getElementById('FrmBooking').cboDepartureDays.value='<?print(date("d"));?>';
		document.getElementById('FrmBooking').cboDepartureMonths.value='<?print(date("m"));?>';		
		document.getElementById('FrmBooking').cboDepartureYears.value='<?print(date("Y"));?>';							
	}		
}
function checkDate(Day,Month,Year,Empty)
{
	if (Day.charAt(0) == "0")
	{
		Day = parseInt(Day.charAt(1));
	}
	if (Month.charAt(0) == "0")
	{
		Month = parseInt(Month.charAt(1));
	}
	Year = parseInt(Year);
	var Flag1 = false;
	var Flag2 = false;
	if (Day == "0" || Month == "0" || Year == "0")
	{
		Flag1 = true;
	}
	if (Day != "0" || Month != "0" || Year != "0")
	{
		Flag2 = true;
	}
	if (Flag1 == true && Flag2 == true)
	{
		return (true);
	}
	else if (Flag1 = true && Flag2 == false)
	{
		if (Empty == 0)
			return (false);
		else
			return (true);
	}
	else if (Flag1 == false && Flag2 == true)
	{
		var Now = new Date(Year,Month-1,Day,0,0,0);
		var NewYear = Now.getYear() % 100;
		NewYear += (NewYear < 38) ? 2000 : 1900;
		if (!(Now.getDate() == Day && Now.getMonth() == Month-1 && NewYear == Year))
		{
			return (true);
		}
	}
	else
		return (true);
}
function GetRooms()
{
	Rooms = document.getElementById('FrmBooking').cboNumRooms.value;
	
	if(Rooms == 1)
	{
		document.getElementById("room2").style.display = "none";
		document.getElementById("room3").style.display = "none";
		document.getElementById("room4").style.display = "none";
	}
	else if(Rooms == 2)
	{
		document.getElementById("room2").style.display = "";
		document.getElementById("room3").style.display = "none";
		document.getElementById("room4").style.display = "none";
	}
	else if(Rooms == 3)
	{
		document.getElementById("room2").style.display = "";
		document.getElementById("room3").style.display = "";
		document.getElementById("room4").style.display = "none";
	}
	else if(Rooms == 4)
	{
		document.getElementById("room2").style.display = "";
		document.getElementById("room3").style.display = "";
		document.getElementById("room4").style.display = "";
	}
}

function DisplayChildAges(room)
{
	if(document.getElementById('FrmBooking').elements['cboChild'+room].value > 0)
		document.getElementById('ChildAges'+room).style.display = "";
	else
		document.getElementById('ChildAges'+room).style.display = "none";

	childNo = document.getElementById('FrmBooking').elements['cboChild'+room].value;
	if(childNo == 1)
	{
		document.getElementById('FrmBooking').elements['cboChild1Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild2Room'+room].style.display = "none";
		document.getElementById('FrmBooking').elements['cboChild3Room'+room].style.display = "none";
		document.getElementById('FrmBooking').elements['cboChild4Room'+room].style.display = "none";				
	}
	else if(childNo == 2)
	{
		document.getElementById('FrmBooking').elements['cboChild1Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild2Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild3Room'+room].style.display = "none";
		document.getElementById('FrmBooking').elements['cboChild4Room'+room].style.display = "none";
	}
	else if(childNo == 3)
	{
		document.getElementById('FrmBooking').elements['cboChild1Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild2Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild3Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild4Room'+room].style.display = "none";
	}
	else if(childNo == 4)
	{
		document.getElementById('FrmBooking').elements['cboChild1Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild2Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild3Room'+room].style.display = "";
		document.getElementById('FrmBooking').elements['cboChild4Room'+room].style.display = "";
	}	
}
function GetCountry(Opener,Type)
{
	if(Type == 2)
	{
		LoadAjax("ajaxwork.php?Type=3&DestinationCode=none","res");
		LoadAjax("ajaxwork.php?Type=2&CountryCode="+document.getElementById('FrmBooking').cboCountry.value,Opener);
	}		
	else if(Type == 3)
		LoadAjax("ajaxwork.php?Type=3&DestinationCode="+document.getElementById('FrmBooking').cboDest.value,Opener);
}
