//*********************************************** New Code For Ajax Page *************************************	


function showLists(id, opt, depdate, region, resort, dep)
{
	if (opt != "inbouund/outbound")
	{
		//overwrite the children's number
		//comment by LJ
		//document.getElementById('searchChildren').options[0].selected = true;
		//document.getElementById('searchInfants').options[0].selected = true;
		//alert('check show list ' + document.getElementById("searchChildren").value);
		updateChildAges('searchChildren', 'searchInfants');
		
	}
	
	// Updated by Shuliang - Job 46659
	// Add all destinations search condition
	// if (id != "---" && region != "---")
		var htmlResponse;
		$.Tache.Get({
			url: "/includes/Sun_Holidays_PopulateLists.asp",
			data: "id=" + id + "&selection=" + opt + "&Departdate=" + depdate + "&region=" + region + "&resort=" + resort + "&dep=" + dep + "&sunSkiSwitcher=" + $("#sunSkiSwitcher").val(),
			async: false,
			success: function(data){
				htmlResponse = data;
			}
		});
		
		
		//Add by LJ -- Guard Condition depend on the departure airport
		if (opt == 'dep')
		{
			$("#txtResort").html("<select class='form-dropdownlist-city' style='width:130px'  id='txtRes'   name='txtRes'><option value='---'  selected >Select Resort</option>          </select>");

			$("#txtRegions").html("<select class='form-dropdownlist-city ieSFix8'  id='txtRegion' name='txtRegion'><option value='---'  selected >Select Region</option></select>");
			$("#country").html(htmlResponse);
		}		
		else if (opt == 'region')
		{
			if (id != 'any')
			{
				$("#txtResort").html("<select class='form-dropdownlist-city' style='width:130px'  id='txtRes'   name='txtRes'><option value='---'  selected >Select Resort</option>          </select>");
			}
			else
			{
				$("#txtResort").html("<select class='form-dropdownlist-city' style='width:130px'  id='txtRes'   name='txtRes'><option value='---'  selected >All Resorts</option>          </select>");
			}

			$("#txtRegions").html(htmlResponse);
		}
		else
		{
			if (opt == 'resort')
			{
				
				$("#txtResort").html(htmlResponse).change(function(){
					$("#DepartDate").trigger("change");
				});
			}
			else if (opt == "inbouund/outbound")
			{
				$("#txtChkSubmitIO").html(htmlResponse);
			}
			else 
			{
				$("#txtChkSubmit").html(htmlResponse);
			}
		}
}

//Ajax for latest holidays offers
function showListsOffers(id, opt, depdate, region, resort, dep, sunSkiSwitcher)
{
	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "id=" + id + "&selection=" + opt + "&Departdate=" + depdate + "&region=" + region + "&resort=" + resort + "&dep=" + dep + "&sunSkiSwitcher=" + sunSkiSwitcher,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	
	$("#txtChkSubmit").html(htmlResponse);
}

//********************************* End New Code **********************************
//********************************* Code to Extend Child Ages and Infant Ages Boxes *************

function buildChildYears(minChildAge, maxChildAge)
{
	var childAgesArray = [];
	var infantAges = [];
	for (var i = 0; i < minChildAge; i++)
	{
		infantAges.push(i);
	}
	childAgesArray[0] = infantAges;
	var childAges = [];
	for (var j = minChildAge; j <= maxChildAge; j++)
	{
		childAges.push(j);
	}
	childAgesArray[1] = childAges;
	return childAgesArray;
}


function updateChildAges(childSelectName, infantSelectName, childAgesArray)
{

	var chkSubmit = $('#optSubmit').val();
	
	if (chkSubmit == "Submit_Go4Go")
	{
		var defaultChildAges = [[0, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]];
	}
	else
	{
		var defaultChildAges = [[0, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]];
	}
	
	if (childAgesArray == null)
	{
		childAgesArray = defaultChildAges;
	}
	var childSelect = document.getElementById(childSelectName);
	var infantSelect = document.getElementById(infantSelectName);
	var childAgeHeading = document.getElementById("ChildAgeTextCell");
	if (childSelect != null && infantSelect != null)
	{
		var childCount = (childSelect.value - 0) + (infantSelect.value - 0);
		if (childAgeHeading != null)
		{
			if (childCount > 0)
			{
				childAgeHeading.style.display = "";
				$("#lblChild").css("display", "block");
			}
			else 
			{
				childAgeHeading.style.display = "none";
				$("#lblChild").css("display", "none");
			}
		}
		for (i = 0; i < 100; i++)
		{
			var title = document.getElementById("childAgeTitle" + i);
			var select = document.getElementById("childAgeSelect" + i);
			
			if (title == null && select == null)
			{
				break;
			}
			if (i < childCount)
			{
				if (title != null) 
					title.style.display = "";
				if (select != null) 
					select.style.display = "";
				updateAgeSelect(select, i < (childSelect.value - 0) ? childAgesArray[1] : childAgesArray[0]);
			}
			else {
				if (title != null) 
					title.style.display = "none";
				if (select != null) 
					select.style.display = "none";
			}
		}
	}
}

function updateAgeSelect(selectElement, ageArray){
	var currentItem = selectElement[selectElement.selectedIndex].value;
	selectElement.length = 0;
	var i = 0;
	for (var i = 0; i < ageArray.length; i++) {
		selectElement.options[selectElement.options.length] = new Option(ageArray[i] + " Years", ageArray[i]);
		if (currentItem == ageArray[i]) {
			selectElement.selectedIndex = i;
		}
	}
}

//winter time checking func
//ajax by LJ
function chkWinterTime(depDate, retDate, dep, region)
{

	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "selection=chkWinterTime&depDate=" + depDate + "&region=" + region + "&retDate=" + retDate + "&dep=" + dep,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	$('#chkWinter').html(htmlResponse);
}

function getAirportCode(dest)
{
	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "selection=getIataCode&dest=" + dest,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	return htmlResponse;
}

function getCountryName(dest, country, region)
{
	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "selection=getCountryName&dest=" + dest + "&country=" + country + "&region=" + region,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	return htmlResponse;
}

function getCountryType(dest)
{
	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "selection=getCountryType&dest=" + dest,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	return htmlResponse;
}
//********************************* End Ages Code ***********************************************
//********************************* Code for Page Validation ************************************

function ValidateFields()
{

	var 	chkDat;
	chkDat  = new Date();
	var matDat;
    chkDat = chkDat.getDay();
	if ( (chkDat == 0) || (chkDat == 1)  || (chkDat == 2) )
	{
	matDat = 4;
	}
	else if ( (chkDat == 3) || (chkDat == 4)  || (chkDat == 5) )
	{
	matDat = 4;
	}
	else
	{
	matDat = 4;
	}

	document.getElementById("ReturnDate").value = '';
	document.getElementById("process").value = 0;
	missinginfo = "";
	if (document.getElementById('dep').value == 'any')
	{
		missinginfo += '\n     -  Please select Depart From option';
		document.getElementById('dep').focus();
	}
	if (document.getElementById('desti').value == '---')
	{
		missinginfo += '\n     -  Please select Country';
		document.getElementById('desti').focus();
	}
	if (document.getElementById('txtRegion').value == '---' && document.getElementById('desti').value != "any")
	{
		missinginfo += '\n     -  Please select Region';
		document.getElementById('txtRegion').focus();
	}
	if (document.getElementById('txtRes').value == '---' && document.getElementById('desti').value != "any")
	{
		missinginfo += '\n     -  Please select Resort';
		document.getElementById('txtRes').focus();
	}
	if (document.getElementById('DepartDate').value == '')
	{
		missinginfo += '\n     -  Please enter Departure Date';
		document.getElementById('DepartDate').focus();
	}
	else 
	{
		
		if (isDate(document.getElementById('DepartDate').value) == false)
		{
			missinginfo += '\n     -  Enter valid Departure Date (dd/mm/yyyy)';
			document.getElementById("dur").readOnly = true;
			document.getElementById('DepartDate').focus();
			
		}
		else  if (chkDate(document.getElementById('DepartDate').value,matDat) == false)
		{
			missinginfo += '\n     -  Departure date cannot be within '+matDat+' days of the current date!';
			$('#dur').val('');
			//document.getElementById("dur").readOnly = true;
			document.getElementById('DepartDate').value = '';
			document.getElementById('DepartDate').focus();
				
		}
		/*Code below has been commented by Manuel as this we dont need this restriction according to Donna. 05/01/2011*/
		/*else  if (chkDateFixAlltria(document.getElementById('DepartDate').value))
		{
			missinginfo += '\n     -  Departure date cannot be after the 31st of August 2011!';
			$('#dur').val('');
			//document.getElementById("dur").readOnly = true;
			document.getElementById('DepartDate').value = '';
			document.getElementById('DepartDate').focus();
				
		}*/
		else
		{
			document.getElementById("dur").readOnly = false;
		}
	}
	if (($('#dur').val() == '') || (isNaN($('#dur').val())))
	{
		missinginfo += '\n     -  Please enter No. of Nights (numeric value only)';
	}
	
	if (missinginfo != "") 
	{
		missinginfo = "\nYou must fill in the following fields correctly:\n" +
		missinginfo +
		"\n\nPlease re-enter your information and submit it again. Thank You!";
		alert(missinginfo);
		return;
	}
	else
	{

		showLists(document.getElementById('dur').value,'chk_Submit',document.getElementById('DepartDate').value,document.getElementById('txtRegion').value,document.getElementById('txtRes').value, document.getElementById('dep').value);
		
		FillReturnDate(document.getElementById('dur').value);
		FillReturnDate(document.getElementById('dur').value);
		
		var splitDate = document.getElementById('DepartDate').value;
		var DayMonth = splitDate.split("/");
		document.getElementById("ReturnDate").value = ReturnDate(DayMonth[1] + "/" + DayMonth[0] + "/" + DayMonth[2], $('#dur').val());
		document.getElementById('checkInDateDay').value = DayMonth[0];
		if (DayMonth[1] < 10)
		{
			document.getElementById('checkInDateMonth').value = DayMonth[1].replace(/0/i, "");
		}
		else
		{
			document.getElementById('checkInDateMonth').value = DayMonth[1];
		}
		document.getElementById('checkInDateYear').value = DayMonth[2];
		document.getElementById('duration').value = $('#dur').val();
		document.getElementById('departureOutLocation').value = document.getElementById('dep').value;
		document.getElementById("holiday_date_day").value = splitDate.substring(0, 2);
		document.getElementById("holiday_date_month").value = splitDate.substring(3, 5);
		document.getElementById("holiday_date_year").value = splitDate.substring(6, 10);
		var displayBoth = document.getElementById("displayBoth").value;
		//alert(displayBoth);
		var chkID = $('#resid').val();
		document.getElementById("resort.id").value = chkID;
		// Add by Shuliang Job Id. 46656
		// Add the infants to passengers
		
		document.getElementById("pax").value = document.getElementById("adults").value + "," + document.getElementById("searchChildren").value;
		
		//disable depart from SNN, ORK dual search
		//By LJ
/*		var destArr = new Array('ADB',
								'AGP',
								'ALC',
								'BJV',
								'FAO',
								'LPA',
								'MIR',
								'REU',
								'TFS'
								);
		//alert(displayBoth);
		//alert(document.getElementById('dest').value);
		for (x in destArr)
		{
			//alert(x + ' ' + displayBoth);
			if (document.getElementById('dest').value == destArr[x] && document.getElementById('dep').value == 'SNN')
			{
				displayBoth = 'False';
			}
		}
		
		var destArr2 = new Array('ADB',
								'ALC',
								'BJV',
								'MIR',
								'REU',
								'TFS'
								);
		//alert(displayBoth);
		//alert(document.getElementById('dest').value);
		for (x in destArr2)
		{
			//alert(x + ' ' + displayBoth);
			if (document.getElementById('dest').value == destArr2[x] && document.getElementById('dep').value == 'ORK')
			{
				displayBoth = 'False';
			}
		}*/
		
		//alert(displayBoth);
		
		//Check Winter dates
		//Edit by LJ
		var destCode = document.getElementById('dest').value;
		var depDate = new Date();
		depDate.setFullYear(DayMonth[2], DayMonth[1]-1, DayMonth[0]);
		
		var todayDate = new Date();
		
		var winterDateBg = new Date();
		winterDateBg.setFullYear(todayDate.getFullYear(), 9, 7);
		var winterDateEd = new Date();
		winterDateEd.setFullYear(todayDate.getFullYear()+1, 4, 28);
		//alert(depDate);
		//alert(winterDateBg+" "+winterDateEd);
		if (depDate > winterDateBg && depDate < winterDateEd)
		{
			chkWinterDate = false;
			
			chkWinterTime($('#DepartDate').val(), $('#ReturnDate').val(), $('#dep').val(), $('#txtRegion').val());
			//alert($('#winterTrigger').val());
			if($('#winterTrigger').val() == 'true') 
			{
				chkWinterDate = true;
			}
			
			if(document.getElementById('desti').value == 'any')
			{
				chkWinterDate = true;
			}
			
		}else{ var chkWinterDate = true; }
		
		//alert(document.URL);
		if (chkWinterDate)
		{
			/*if (document.URL == "http://budget/index.asp" || document.URL == "http://budget/" || document.URL == "http://www.budgettravel.ie/index.asp" || document.URL == "http://www.budgettravel.ie/")
			{*/
				dualSearchSubmit(displayBoth);
			/*}
			else
			{
				singleSearchSubmit();
			}*/
		}
		else
		{
			//alert('** PLEASE NOTE **\nWe do not fly to your requested destination at the time of year you have selected.\nWhy not try searching again for one of our popular Winter Destinations..\nPortugal – Algarve\nPortugal - Madeira\nSpain – Tenerife\nSpain – Gran Canaria\nSpain – Lanzarote\nSpain – Fuerteventura\nSpain – Costa Del Sol\nSpain – Benidorm\nMalta\nEgypt\nClick \"OK\" to search again. ')
			$(function() {
				// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
				//$("#dialog").dialog("destroy");
				
				//added by rongchen jia
				//to ensure always pop up the window
				//if the old window still has focus, let the new window gain focus
				//date 14th Feb 2011
				newwindow = window.open("/sun-holidays-cheap-flights-special-packages/tabs/pop-ups/winterTime.asp","WinterTime","width=444,height=600");
				// var jToolkit = java.awt.Toolkit.getDefaultToolkit();
				 //var jScreenSize = jToolkit.getScreenSize();
				 //screenW = jScreenSize.width;
				 //screenH = jScreenSize.height;
				 screenW = screen.width;
				 screenH  = screen.height;
				if (window.focus) {
					
					newwindow.focus();
					newwindow.moveTo((screenW-444)/2, (screenH - 600)/2);
					}

				//alert($("#dialog-winterTimeMsg").html());
/*				$("#dialog-winterTimeMsg").dialog({
					modal: true,
					width: 500, 
					buttons: {
						'Search Again': function() {
							$(this).dialog('close');
						}
					}
				});*/
			});

		}
		
	}
	
}

function alltriaTargetDetect(desti)
{
	var country_section = getCountryType(desti);
	//alert(desti);
	//alert($('#resid').val())
	//alert(document.getElementById("resort.id").value)
	if(country_section == "1")
	{
	  return "http://www.budgettravel.ie/BT/holiday/Search.do;jsessionid=895D4BDC857DFD393069191B64146CE1.CT1";
	}
	else
	{
		return "http://www.budgettravel.ie/BT2/holiday/Search.do;jsessionid=895D4BDC857DFD393069191B64146CE1.CT1";
	}
}
//Submit holiday search form on the budget index page
//By LJ
function dualSearchSubmit(displayBoth)
{
	var chkSubmit = $('#optSubmit').val();
	var CompanyName = document.getElementById('CompanyName').value;
	if (chkSubmit == "Submit_Allteria")
	{
		//alert($('#resort.id').val());
		showLists(document.getElementById('dep').value, "inbouund/outbound", document.getElementById('DepartDate').value, document.getElementById('ReturnDate').value, document.getElementById('txtRegion').value)
		
		var msg = "";
		var opt = $('#opt').val();
		var msgg = $('#mesg').val();
		var In = $('#In').val();
		if (((opt != "") && (In != ""))) 
		{
			if ((opt == "N") && (In == "N"))
			{
				msg = "There are no Flights available for the Departure/Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			if ((opt == "N") && (In == "Y"))
			{
				msg = "There are no Flights available for the Departure date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			if ((opt == "Y") && (In == "N"))
			{
				msg = "There are no Flights available for the Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			alert(msg);
			$('#dur').val('');
		}
		else 
		{		
			
			if (msgg != "No Found" || alltriaTargetDetect($('#desti').val()).indexOf("BT2") > 0)
			{
				postSearch(CompanyName);
				setCookies();
				document.search_form.action = alltriaTargetDetect($('#desti').val());
				document.getElementById("process").value = 1;
				if (chkIsOutEngine())
				{
					document.search_form.target='_blank';
				}
				document.search_form.submit();
				if (displayBoth == 'True')
				{
					//var txtAlways = $('#txtAlways').val();
					if ($('#dur').val() < 11)
					{
					$('#dur').val(7);
					}
					else if($('#dur').val() > 10)
					{
					$('#dur').val(14);	
					}
					openWindow(alltriaTargetDetect($('#desti').val()), 'BTPopupWinG4GO', 800, 600);
					document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary";
					document.search_form.target='BTPopupWinG4GO';
					document.search_form.submit()
				}
			}
		}
		
	}
	//submit g4go
	else {
		if (document.getElementById("process").value == 0)
		{
			var txtAlways = $('#txtAlways').val();
			if ((txtAlways != "") && ($('#dur').val() < 11)) 
			{
			$('#dur').val(7);
			}
			else if((txtAlways != "") && ($('#dur').val() > 10))
			{
			$('#dur').val(14);	
			}
								
			postSearch(CompanyName);
			setCookies();
			
			//ski search add the iata code to parameters 
			//remove 'dest' value
			//added by LJ
			if (document.getElementById('dest').value != "any")
			{
				document.getElementById('iata_code').value = getAirportCode(document.getElementById('dest').value);
				//alert(document.getElementById('dest').value);
				if (document.getElementById('sunSkiSwitcher').value == 'ski')
				{
					document.getElementById('dest').value = getCountryName(document.getElementById('dest').value, document.getElementById('desti').value, document.getElementById('txtRegion').value);
				}
				//alert(document.getElementById('dest').value);
			}
			
			document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary"
			document.getElementById("process").value = 1;
			if (chkIsOutEngine())
			{
				document.search_form.target='_blank';
			}
			document.search_form.submit();
			
			if (displayBoth == 'True')
			{
				showLists(document.getElementById('dep').value, "inbouund/outbound", document.getElementById('DepartDate').value, document.getElementById('ReturnDate').value, document.getElementById('txtRegion').value)
		
				var msg = "";
				var opt = $('#opt').val();
				var msgg = $('#mesg').val();
				var In = $('#In').val();
				if (((opt != "") && (In != ""))) 
				{
					if ((opt == "N") && (In == "N"))
					{
						msg = "There are no Flights available for the Departure/Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
					}
					if ((opt == "N") && (In == "Y"))
					{
						msg = "There are no Flights available for the Departure date you have selected.\nFlights operate on " + msgg + " - Please try again.";
					}
					if ((opt == "Y") && (In == "N"))
					{
						msg = "There are no Flights available for the Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
					}
					//alert(msg);
					$('#dur').val('');
				}
				else 
				{	
				
					openWindow('/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary', 'BTPopupWinAlr', 800,600);
					
					document.search_form.action = alltriaTargetDetect($('#desti').val());
					document.search_form.target='BTPopupWinAlr';
					if (msgg != "No Found" || alltriaTargetDetect($('#desti').val()).indexOf("BT2") > 0)
						document.search_form.submit();
				}
			}
		}
		else
		{
			alert('Your request is being processed.');
		}
	}
}

function singleSearchSubmit()
{
	var chkSubmit = $('#optSubmit').val();
	var CompanyName = document.getElementById('CompanyName').value;
	
	if (chkSubmit == "Submit_Allteria")
	{
	
		//alert($('#resort.id').val());
		showLists(document.getElementById('dep').value, "inbouund/outbound", document.getElementById('DepartDate').value, document.getElementById('ReturnDate').value, document.getElementById('txtRegion').value)
		
		var msg = "";
		var opt = $('#opt').val();
		var msgg = $('#mesg').val();
		var In = $('#In').val();
		if (((opt != "") && (In != ""))) 
		{
			if ((opt == "N") && (In == "N"))
			{
				msg = "There are no Flights available for the Departure/Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			if ((opt == "N") && (In == "Y"))
			{
				msg = "There are no Flights available for the Departure date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			if ((opt == "Y") && (In == "N"))
			{
				msg = "There are no Flights available for the Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
			}
			alert(msg);
			$('#dur').val('');
		}
		else 
		{		
			if (document.getElementById("process").value == 0)
			{
				postSearch(CompanyName);
				setCookies();
				
				//ski search add the iata code to parameters 
				//remove 'dest' value
				//added by LJ
				if ($('#sunSkiSwitcher') == 'ski')
				{
					document.getElementById('iata_code').value = getAirportCode(document.getElementById('dest').value);
					if (document.getElementById('sunSkiSwitcher').value == 'ski')
					{
						document.getElementById('dest').value = getCountryName(document.getElementById('dest').value);
					}
				}
				
				document.search_form.action = alltriaTargetDetect($('#desti').val());
				document.getElementById("process").value = 1;
				document.search_form.target='_blank';
				document.search_form.submit();
			}
			else 
			{
				alert('Your request is being processed.');
			}
		}
		
	}
	//submit g4go
	else 
	{
		if (document.getElementById("process").value == 0)
		{
			var txtAlways = $('#txtAlways').val();
			if ((txtAlways != "") && ($('#dur').val() < 11)) 
			{
			$('#dur').val(7);
			}
			else if((txtAlways != "") && ($('#dur').val() > 10))
			{
			$('#dur').val(14);	
			}
								
			postSearch(CompanyName);
			setCookies();
			
			//ski search add the iata code to parameters 
			//remove 'dest' value
			//added by LJ
			document.getElementById('iata_code').value = getAirportCode(document.getElementById('dest').value);
			
			if (document.getElementById('sunSkiSwitcher').value == 'ski')
			{
				document.getElementById('dest').value = getCountryName(document.getElementById('dest').value);
			}
			
			document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary"
			document.getElementById("process").value = 1;
			document.search_form.target='_blank';
			document.search_form.submit();
			
		}
		else
		{
			alert('Your request is being processed.');
		}
	}
}
		
function openWindow(url, wname, width, height) 
{
	popupWin = window.open(url, wname, "height=" + height + ",width=" + width + "location = 0, status = 1, resizable = 0, scrollbars=1, toolbar = 0");
	popupWin.opener.focus();
}

function setCookies()
{
	var duration = 1;
	var sunSkiSwitcher = document.getElementById('sunSkiSwitcher').value;
	
	if (sunSkiSwitcher == 'ski')
	{
		$.cookie("depSki", $("#dep").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("destiSki", $("#desti").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("txtRegionSki", $("#txtRegion").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("txtResSki", $("#txtRes").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("DepartDateSki", $("#DepartDate").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("durSki", $("#dur").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("prcSki", $("#prc").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("adultsSki", $("#adults").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("searchChildrenSki", $("#searchChildren").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("searchInfantsSki", $("#searchInfants").val(), {
			path: '/',
			expires: duration
		});
	}
	else
	{
		$.cookie("dep", $("#dep").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("desti", $("#desti").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("txtRegion", $("#txtRegion").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("txtRes", $("#txtRes").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("DepartDate", $("#DepartDate").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("dur", $("#dur").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("prc", $("#prc").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("adults", $("#adults").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("searchChildren", $("#searchChildren").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("searchInfants", $("#searchInfants").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect0", $("#childAgeSelect0").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect1", $("#childAgeSelect1").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect2", $("#childAgeSelect2").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect3", $("#childAgeSelect3").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect4", $("#childAgeSelect4").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect5", $("#childAgeSelect5").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect6", $("#childAgeSelect6").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect7", $("#childAgeSelect7").val(), {
			path: '/',
			expires: duration
		});
		$.cookie("childAgeSelect8", $("#childAgeSelect8").val(), {
			path: '/',
			expires: duration
		});
	}
	
}

function getCookies()
{
	var sunSkiSwitcher = document.getElementById('sunSkiSwitcher').value;
	if (sunSkiSwitcher == 'ski')
	{
		if ($.cookie("depSki") != null && $.cookie("depSki") != "") 
			$("#dep").val($.cookie("depSki")).trigger("change");
		if ($.cookie("destiSki") != null && $.cookie("destiSki") != "") 
			$("#desti").val($.cookie("destiSki")).trigger("change");
		if ($.cookie("txtRegionSki") != null && $.cookie("txtRegionSki") != "") 
			$("#txtRegion").val($.cookie("txtRegionSki")).trigger("change");
		if ($.cookie("txtResSki") != null && $.cookie("txtResSki") != "" && $.cookie("txtResSki") != "---") {
			$("#txtRes").val($.cookie("txtResSki")).trigger("change");
			if ($.cookie("DepartDateSki") != null && $.cookie("DepartDateSki") != "") 
				$("#DepartDate").val($.cookie("DepartDateSki")).trigger("change");
			if ($.cookie("durSki") != null && $.cookie("durSki") != "") 
				$("#dur").val($.cookie("durSki")).trigger("keyup").trigger("change");
			if ($.cookie("prcSki") != null && $.cookie("prcSki") != "") 
				$("#prc").val($.cookie("prcSki")).trigger("change");
		}
		if ($.cookie("adultsSki") != null && $.cookie("adultsSki") != "") 
			$("#adults").val($.cookie("adultsSki")).trigger("change");
		if ($.cookie("searchChildrenSki") != null && $.cookie("searchChildrenSki") != "") 
			$("#searchChildren").val($.cookie("searchChildrenSki")).trigger("change");
		if ($.cookie("searchInfantsSki") != null && $.cookie("searchInfantsSki") != "") 
			$("#searchInfants").val($.cookie("searchInfantsSki")).trigger("change");
	}
	else
	{
		if ($.cookie("dep") != null && $.cookie("dep") != "") 
			$("#dep").val($.cookie("dep")).trigger("change");
		if ($.cookie("desti") != null && $.cookie("desti") != "") 
			$("#desti").val($.cookie("desti")).trigger("change");
		if ($.cookie("txtRegion") != null && $.cookie("txtRegion") != "") 
			$("#txtRegion").val($.cookie("txtRegion")).trigger("change");
		if ($.cookie("txtRes") != null && $.cookie("txtRes") != "" && $.cookie("txtRes") != "---") {
			$("#txtRes").val($.cookie("txtRes")).trigger("change");
			if ($.cookie("DepartDate") != null && $.cookie("DepartDate") != "") 
				$("#DepartDate").val($.cookie("DepartDate")).trigger("change");
			if ($.cookie("dur") != null && $.cookie("dur") != "") 
				$("#dur").val($.cookie("dur")).trigger("keyup").trigger("change");
			if ($.cookie("prc") != null && $.cookie("prc") != "") 
				$("#prc").val($.cookie("prc")).trigger("change");
		}
		if ($.cookie("adults") != null && $.cookie("adults") != "") 
			$("#adults").val($.cookie("adults")).trigger("change");
		if ($.cookie("searchChildren") != null && $.cookie("searchChildren") != "") 
			$("#searchChildren").val($.cookie("searchChildren")).trigger("change");
		if ($.cookie("searchInfants") != null && $.cookie("searchInfants") != "") 
			$("#searchInfants").val($.cookie("searchInfants")).trigger("change");
		if ($.cookie("childAgeSelect0") != null && $.cookie("childAgeSelect0") != "") 
			$("#childAgeSelect0").val($.cookie("childAgeSelect0")).trigger("change");
		if ($.cookie("childAgeSelect1") != null && $.cookie("childAgeSelect1") != "") 
			$("#childAgeSelect1").val($.cookie("childAgeSelect1")).trigger("change");
		if ($.cookie("childAgeSelect2") != null && $.cookie("childAgeSelect2") != "") 
			$("#childAgeSelect2").val($.cookie("childAgeSelect2")).trigger("change");
		if ($.cookie("childAgeSelect3") != null && $.cookie("childAgeSelect3") != "") 
			$("#childAgeSelect3").val($.cookie("childAgeSelect3")).trigger("change");
		if ($.cookie("childAgeSelect4") != null && $.cookie("childAgeSelect4") != "") 
			$("#childAgeSelect4").val($.cookie("childAgeSelect4")).trigger("change");
		if ($.cookie("childAgeSelect5") != null && $.cookie("childAgeSelect5") != "") 
			$("#childAgeSelect5").val($.cookie("childAgeSelect5")).trigger("change");
		if ($.cookie("childAgeSelect6") != null && $.cookie("childAgeSelect6") != "") 
			$("#childAgeSelect6").val($.cookie("childAgeSelect6")).trigger("change");
		if ($.cookie("childAgeSelect7") != null && $.cookie("childAgeSelect7") != "") 
			$("#childAgeSelect7").val($.cookie("childAgeSelect7")).trigger("change");
		if ($.cookie("childAgeSelect8") != null && $.cookie("childAgeSelect8") != "") 
			$("#childAgeSelect8").val($.cookie("childAgeSelect8")).trigger("change");
	}
}

function postSearch(CompanyName)
{
	var depFrom, country, region, resort, depDate, retDate, type;
	
	depFrom = $("#dep option:selected").text();
	country = $("#desti option:selected").text();
	region = $("#txtRegion option:selected").text();
	resort = $("#txtRes option:selected").text();
	depDate = $("#DepartDate").val();
	retDate = $("#ReturnDate").val();
	type	= "sunHoliday"
	
	$.ajax({
			url: "/includes/saveSearch.asp",
			data: "depFrom=" + depFrom + "&country=" + country + "&region=" + region + "&resort=" + resort + "&depDate=" + depDate + "&retDate=" + retDate + "&CompanyName=" + CompanyName + "&type=" + type,
			async: false
	});	
}

function isNumeric(value)
{
	if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) 
		return false;
	return true;
}

// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2200;

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) 
			return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) 
			returnString += c;
	}
	return returnString;
}

function daysInFebruary(year)
{
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i == 4 || i == 6 || i == 9 || i == 11)
		{
			this[i] = 30
		}
		if (i == 2)
		{
			this[i] = 29
		}
	}
	return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1 = dtStr.indexOf(dtCh)
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
	var strDay = dtStr.substring(0, pos1)
	var strMonth = dtStr.substring(pos1 + 1, pos2)
	var strYear = dtStr.substring(pos2 + 1)
	strYr = strYear
	if (strDay.charAt(0) == "0" && strDay.length > 1) 
		strDay = strDay.substring(1)
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) 
		strMonth = strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0) == "0" && strYr.length > 1) 
			strYr = strYr.substring(1)
	}
	month = parseInt(strMonth)
	day = parseInt(strDay)
	year = parseInt(strYr)
	if (pos1 == -1 || pos2 == -1)
	{
		return false
	}
	if (strMonth.length < 1 || month < 1 || month > 12)
	{
		return false
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) 
	{
		return false
	}
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
	{
		return false
	}
	if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false)
	{
		return false
	}
	return true
}

function ReturnDate(dat, days)
{
	var d = new Date(dat);
	var ddd;
	var mm = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
	var ddays = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09']
	var dd = new setday(d);
	var tomor = new Date(dd.y, dd.m, dd.d + parseInt(days));
	if (tomor.getDate() < 10)
	{
		ddd = ddays[tomor.getDate()];
	}
	else
	{
		ddd = tomor.getDate();
	}
	return ddd + "/" + (mm[tomor.getMonth() + 1]) + "/" + tomor.getFullYear();
}

function setday(obj){
	this.y = obj.getFullYear();
	this.m = obj.getMonth();
	this.d = obj.getDate();
}

function EnableDuration()
{
	
	if (document.getElementById('txtRes').value == '---' && document.getElementById('desti').value != "any")
	{
		alert('Select Resort-Area First');
		document.getElementById('DepartDate').value = '';
		document.getElementById("ReturnDate").value = '';
	}
	else 
		if (document.getElementById('DepartDate').value != '')
		{
			document.getElementById("dur").readOnly = false;
		}
}

function FillReturnDate(vall){
	if (document.getElementById('txtRes').value == '---' && document.getElementById('desti').value != "any") {
		alert('Please select a resort before you continue');
		$('#dur').val('');
		document.getElementById("txtRes").focus();
	}
	else 
		// Updated by Shuliang - Job 46659
		//if (document.getElementById('txtRes').value != '---')
		if (document.getElementById('txtRes').value != '---' || document.getElementById('desti').value == "any")
		{
			var splitDate = document.getElementById('DepartDate').value;
			var DayMonth = splitDate.split("/");
			if ($('#dur').val() == "" || isNaN($('#dur').val()))
			{
				document.getElementById("ReturnDate").value = "";
			}
			else
			{
				document.getElementById("ReturnDate").value = ReturnDate(DayMonth[1] + "/" + DayMonth[0] + "/" + DayMonth[2], vall);
			}
		}
}


function NewSubmit(dep, desti, region, resort, fromDate, duration, fromPrice, adults, sunSkiSwitcher)
{
	/*var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "id=" + duration + "&selection=chk_Submit" + "&Departdate=" + fromDate + "&region=" + region + "&resort=" + resort + "&dep=" + dep,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	$("#txtChkSubmit").html(htmlResponse);*/
	showListsOffers(duration, 'chk_Submit', fromDate, region, resort, dep, sunSkiSwitcher);
	
	var splitDate = fromDate;
	var DayMonth = fromDate.split("/");
	//var DepartDate = DayMonth[1] + "/" + DayMonth[0] + "/" + DayMonth[2];
	var RDate = ReturnDate(DayMonth[1] + "/" + DayMonth[0] + "/" + DayMonth[2], duration);
	document.getElementById('checkInDateDay').value = DayMonth[0];
	if (DayMonth[1] < 10)
	{
		document.getElementById('checkInDateMonth').value = DayMonth[1].replace(/0/i, "");
	}
	else
	{
		document.getElementById('checkInDateMonth').value = DayMonth[1];
	}
	document.getElementById("checkInDateYear").value = splitDate.substring(6, 10);
	document.getElementById('duration').value = duration;
	document.getElementById('departureOutLocation').value = dep;
	document.getElementById("holiday_date_day").value = splitDate.substring(0, 2);
	document.getElementById("holiday_date_month").value = splitDate.substring(3, 5);
	document.getElementById("holiday_date_year").value = splitDate.substring(6, 10);
	document.getElementById("pax").value = adults + "," + document.getElementById("searchChildren").value;
	document.getElementById("adults").value = adults;
	var displayBoth = document.getElementById("displayBoth").value;
	document.getElementById('DepartDate').value = fromDate;
	document.getElementById('ReturnDate').value = RDate;
	
	//document.getElementById("resort.id").value = resort;
	
	fromPrice = parseInt(fromPrice);
	document.getElementById("prc").value = 'any';/*fromPrice + (100-(fromPrice%100));*/
	
	//if (document.getElementById("dep").value == '')
	//{
		document.getElementById("dep").value = dep;
	//}
	
	//dualSearchSubmit(displayBoth);
	if ($('#optSubmit').val() == "Submit_Go4Go")
	{
		document.getElementById('txtRegion').value = region;
		/*var chkID = $('#resid').val();*/
		document.getElementById("resort.id").value = $('#resid').val();
		document.getElementById('dur').value = duration;
		
		document.getElementById('iata_code').value = getAirportCode(document.getElementById('dest').value);
		//alert(document.getElementById('dest').value);
		if (sunSkiSwitcher == 'ski')
		{
			document.getElementById('dest').value = getCountryName(document.getElementById('dest').value);
			document.getElementById('choice').value = 'ski';
		}
		else
		{
			document.getElementById('choice').value = 'pack';
		}
		
		document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary"
		document.getElementById("process").value = 1;
		document.search_form.submit();
		
		if (displayBoth == 'True') 
		{	
			showLists(document.getElementById('dep').value, "inbouund/outbound", fromDate, RDate, region)
	
			var msg = "Please click 'OK' to go through.";
			var opt = $('#opt').val();
			var msgg = $('#mesg').val();
			var In = $('#In').val();
			if ((opt != "") && (In != ""))
			{
				if ((opt == "N") && (In == "N"))
				{
					msg = "There are no Flights available for the Departure/Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
				}
				if ((opt == "N") && (In == "Y"))
				{
					msg = "There are no Flights available for the Departure date you have selected.\nFlights operate on " + msgg + " - Please try again.";
				}
				if ((opt == "Y") && (In == "N"))
				{
					msg = "There are no Flights available for the Return date you have selected.\nFlights operate on " + msgg + " - Please try again.";
				}
				alert(/*fromDate+', '+RDate+', '+region*/msg);
				$('#dur').val('');
			}
			else 
			{	
				//alert('open!');
				openWindow('/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary', 'BTPopupWinAlr', 800,600);
				
				document.search_form.action = alltriaTargetDetect(desti);
				document.search_form.target='BTPopupWinAlr';
				document.search_form.submit();
			}
		}
		else{
			//alert(displayBoth);
		}
		
	}
	else
	{
		if ($('#optSubmit').val() == "Submit_Allteria")
		{	
			var chkID = $('#resid').val();
			document.getElementById("resort.id").value = chkID;
			document.search_form.action = alltriaTargetDetect(desti);
			document.getElementById("process").value = 1;
			document.search_form.submit();
			
			if (displayBoth == 'True')
			{
				//var txtAlways = $('#txtAlways').val();
				if ($('#dur').val() < 11)
				{
				$('#dur').val(7);
				}
				else if($('#dur').val() > 10)
				{
				$('#dur').val(14);	
				}
				
				openWindow(alltriaTargetDetect(desti), 'BTPopupWinG4GO', 800, 600);
				document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary";
				document.search_form.target='BTPopupWinG4GO';
				document.search_form.submit();
			}
		}
	}
}

function NewSubmitChild(dep, desti, region, resort, fromDate, duration, fromPrice, adults, children)
{
	var htmlResponse;
	$.Tache.Get({
		url: "/includes/Sun_Holidays_PopulateLists.asp",
		data: "id=" + duration + "&selection=chk_Submit" + "&Departdate=" + fromDate + "&region=" + region + "&resort=" + resort + "&dep=" + dep,
		async: false,
		success: function(data){
			htmlResponse = data;
		}
	});
	$("#txtChkSubmit").html(htmlResponse);
	var splitDate = fromDate;
	var DayMonth = fromDate.split("/");
	document.getElementById("ReturnDate").value = ReturnDate(DayMonth[1] + "/" + DayMonth[0] + "/" + DayMonth[2], duration);
	document.getElementById('checkInDateDay').value = DayMonth[0];
	if (DayMonth[1] < 10)
	{
		document.getElementById('checkInDateMonth').value = DayMonth[1].replace(/0/i, "");
	}
	else
	{
		document.getElementById('checkInDateMonth').value = DayMonth[1];
	}
	document.getElementById("checkInDateYear").value = splitDate.substring(6, 10);
	document.getElementById('duration').value = duration;
	document.getElementById('departureOutLocation').value = dep;
	document.getElementById("holiday_date_day").value = splitDate.substring(0, 2);
	document.getElementById("holiday_date_month").value = splitDate.substring(3, 5);
	document.getElementById("holiday_date_year").value = splitDate.substring(6, 10);
	document.getElementById("pax").value = adults + "," + children;
	document.getElementById("adults").value = adults;
	
	fromPrice = parseInt(fromPrice);
	document.getElementById("prc").value = 'any';/*fromPrice + (100-(fromPrice%100));*/
	
	if (document.getElementById("dep").value == '')
	{
		document.getElementById("dep").value = dep;
	}
	
	if ($('#optSubmit').val() == "Submit_Go4Go")
	{
		document.getElementById('dur').value = duration;
		document.search_form.action = "/sun-holidays-cheap-flights-special-packages/sun-holidays-cheap-flights-special-packages-search.asp?fuseaction=home.results_summary"
		document.getElementById("process").value = 1;
		document.search_form.submit();
	}
	else 
		if ($('#optSubmit').val() == "Submit_Allteria")
		{
			var chkID = $('#resid').val();
			document.getElementById("resort.id").value = chkID;
			document.search_form.action = alltriaTargetDetect(desti);
			document.getElementById("process").value = 1;
			document.search_form.submit();
		}
}

function NewSubmitFamily(dep, desti, region, resort, fromDate, duration, fromPrice, adults, children){
    //var chk = false;
	if (children != 0)
	{
		document.getElementById("searchChildren").value = children;
		
		var popupHtmlStr = '<form>';
		
		for(i=0; i<=(children-1); i++)
		{				 
			 popupHtmlStr = popupHtmlStr + '<p id="popUpChild">Child ' + (i+1) + '\'s Age: <select id="childAge' + i + '"><option value="2">2 Years</option><option value="3">3 Years</option><option value="4">4 Years</option><option value="5">5 Years</option><option value="6">6 Years</option><option value="7">7 Years</option><option value="8">8 Years</option><option value="9">9 Years</option><option value="10">10 Years</option><option value="11">11 Years</option></select>';
		}
		
		popupHtmlStr = popupHtmlStr + '</form>';

		var $dialog = $('<div title="Please enter the age of the child/children">')
			.html(popupHtmlStr)		
			.dialog({
				autoOpen: true,
				height: 300,
				width: 350,
				modal: true,
				buttons: {
					'Submit': function() {
						var selectOptions = "";
						for(i = 0; i<=(children-1); i++)
						{
							//window.opener.document.getElementById('childAgeSelect'+i).value = $("#childAge"+i).val();							
				
							selectOptions += '<option value="' + $("#childAge"+i).val() + '" selected=""selected"">'+$("#childAge"+i).val()+' Years</option>';
							
							$("#childAgeSelect"+i).html(selectOptions);
						}
						
						//alert($('#childAgeSelect0').val());
						NewSubmitChild(dep, desti, region, resort, fromDate, duration, fromPrice, adults, children);
					},
					
					Cancel: function() {
						$(this).dialog('close');
					}
				}
			});
		
		/*$('.opener').click(function() {
			$dialog.dialog('open');
			// prevent the default action, e.g., following a link
		});	*/
	}
	else{NewSubmit(dep, desti, region, resort, fromDate, duration, fromPrice, adults, 'sun');}
	
}

function pad(number, length) 
{
  if (number < length)
  {
        number = '0' + number;
   }
   return number;
}

function chkDate(dat,matDat)
{
	
	var curDat = new Date();
	curDat.setDate(curDat.getDate()+ matDat);
	//alert(dat);
	var newDat = dat.split("/");
	var curYear = curDat.getYear();

	if (curYear >= 100 && curYear <= 1999)
	{
		curYear=curYear + 1900;
	}
	else
	{
		curYear=curYear;
	}

	chkDat = curYear.toString()+pad(curDat.getMonth()+1,10)+pad(curDat.getDate(),10);
	//alert(chkDat);
	//alert(newDat[2] + newDat[1] + newDat[0]);
	/*chkDat = curYear + '/' + pad(curDat.getMonth()+1,10) + '/' + pad(curDat.getDate(),10);*/	
	if (newDat[2] + newDat[1] + newDat[0] < chkDat ) {
		return false;
	}
}

function chkDateFixAlltria(dat){
	try{
		var curDateArray = dat.split("/");
		var curDate = new Date(curDateArray[2], (parseInt(curDateArray[1]) - 1), curDateArray[0]); 
		var dateLimit = new Date(2011, 7, 31); //Month is 0-11 in JavaScript
		if(curDate > dateLimit){
			return true;	
		}else{
			return false;	
		}
	
	}catch(e){
		return true;
	}
}

function changeDepDate()
{
	document.getElementById('searchChildren').options[0].selected = true;
	document.getElementById('searchInfants').options[0].selected = true;
	updateChildAges('searchChildren', 'searchInfants');
	EnableDuration();
	if ($("#dur").val() != null && $("#dur").val() != "") 
	{
		$("#dur").trigger("keyup").trigger("change");
	}
}

// function to check if the search is on budget site or outside
// Cuz u can't do a search inside the iframe
// By LJ
function chkIsOutEngine()
{
	if (document.URL == "http://budget/sun-holidays-cheap-flights-special-packages/sun-holidays-search-tabs-ind.asp" || document.URL == "http://www.budgettravel.ie/sun-holidays-cheap-flights-special-packages/sun-holidays-search-tabs-ind.asp" || document.URL == "http://budget/inc-travel-portal/itimes.asp" || document.URL == "http://www.budgettravel.ie/inc-travel-portal/itimes.asp" )//|| document.URL == "http://budget/eircom_portal/index.asp" || document.URL == "http://www.budgettravel.ie/eircom_portal/index.asp")
	{
		return true;
	}
	else
	{
		return false;
	}
}

//********************************* End Page Validation ************************************


