// Function added because of job 13625
function checkAirportCodeCalendar()
{
	
	var numDays = 1;
	
	if (document.MainForm.pax_adult.value==0 && document.MainForm.pax_stud.value==0)
	{
		alert('You must enter at least 1 Passenger to proceed');
		return false;
	}
	
	if (document.MainForm.pax_adult.value!=0)
	{
		document.MainForm.pax.value = document.MainForm.pax_adult.value;
	}
	else
	{
		document.MainForm.pax.value = document.MainForm.pax_stud.value;
	}
	
	if (document.MainForm.onewayswitch[0].checked)
	{
		createCookie('onewayswitch', 1, numDays);
		document.oz_form.TickType.value = 1;
	}
	else
	{
		createCookie('onewayswitch', 0, numDays);
		document.oz_form.TickType.value = 0;
	}

	if (document.MainForm.other.value=='')
	{
		if (document.MainForm.to_list.value == 'U/L' || document.MainForm.to_list.value == '0') 
		{
			alert('Please choose a destination before proceeding');
			return false;
		}
		else
		{
			document.MainForm.to.value = document.MainForm.to_list.value;
		}
	}
	else
	{
		if (document.MainForm.other.value.length == 3)
		{
			document.MainForm.to.value = document.MainForm.other.value;
		}
		else if (document.MainForm.other.value.length < 6)
		{
			alert('Specify 3 letter city code or click on "Other cities"!');
			return false;
		}
		else 
		{
			s = document.MainForm.other.value;
			
			if (s.substr(s.length-1,1) != ')' || s.substr(s.length-5,1) != '(')
			{
				alert('Specify 3 letter city code or click on "Other cities"!');
				return false;
			}
			
			document.MainForm.to.value = s.substr(s.length-4,3);
		}
	}
	
	if (document.MainForm.onewayswitch[0].checked){
		createCookie('cheapFlightSearchOneWaySwitch', 1, numDays);
		document.oz_form.TickType.value = 1;
	}else{
		createCookie('cheapFlightSearchOneWaySwitch', 0, numDays);
		document.oz_form.TickType.value = 0;
	}
	
	if (document.MainForm.tarif_klasse[0].checked){
		createCookie('cheapFlightSearchTarifKlasse', document.MainForm.tarif_klasse[0].value, numDays)
	}else{
		createCookie('cheapFlightSearchTarifKlasse', document.MainForm.tarif_klasse[1].value, numDays)
	}
		
	createCookie('cheapFlightSearchPax', document.MainForm.pax.value, numDays)
	createCookie('cheapFlightSearchPaxChd', document.MainForm.pax_chd[document.MainForm.pax_chd.selectedIndex].value, numDays)
	createCookie('cheapFlightSearchPaxInf', document.MainForm.pax_inf.value, numDays)
	createCookie('cheapFlightSearchPaxAdult', document.MainForm.pax_adult[document.MainForm.pax_adult.selectedIndex].value, numDays)
	createCookie('cheapFlightSearchFrom', document.MainForm.from.value, numDays)
	createCookie('cheapFlightSearchDestination', document.MainForm.to.value, numDays)
	createCookie('cheapFlightSearchOther', document.MainForm.other.value, numDays)
	createCookie('cheapFlightSearchToList', document.MainForm.to_list.value, numDays)
	createCookie('cheapFlightSearchDepartDate', document.MainForm.DepartDate.value, numDays)
	createCookie('cheapFlightSearchReturnDate', document.MainForm.ReturnDate.value, numDays)
	
	//if this iz OZ destination then
	//redirect to OZ site
	// -------- currently disabled
	// if you don't need it just delete this 'if'
	if (OzDest(document.MainForm.to.value))
	{
		// alert ('OZ Destination');
		document.oz_form.ArrAptCode.value = document.MainForm.to.value;
		document.oz_form.DepDay.value = document.MainForm.Day.value;
		document.oz_form.RetDay.value = document.MainForm.RetDay.value;
		document.oz_form.DepMonthYear.value = document.MainForm.month_1.value;
		document.oz_form.RetMonthYear.value = document.MainForm.month_2.value;
		document.oz_form.ADT.value = document.MainForm.pax.value;
		document.oz_form.CHD.value = document.MainForm.pax_chd.value;
		//document.oz_form.INFANTS.value = document.MainForm.pax_inf.value;
		

		document.oz_form.submit();
		return false;
	}

	return true;
}

function checkAirportCode()
{
	if (document.MainForm.pax_adult.value==0 && document.MainForm.pax_stud.value==0)
	{
		alert('You must enter at least 1 Passenger to proceed');
		return false;
	}
	
	if (document.MainForm.pax_adult.value!=0)
		document.MainForm.pax.value = document.MainForm.pax_adult.value 
	else
		document.MainForm.pax.value = document.MainForm.pax_stud.value 
	
	if (document.MainForm.onewayswitch[0].checked)
	{
		createCookie('cheapFlightSearchOneWaySwitch', 1, numDays);
		document.oz_form.TickType.value = 1;
	}
	else
	{
		createCookie('cheapFlightSearchOneWaySwitch', 0, numDays);
		document.oz_form.TickType.value = 0;
	}

	if (document.MainForm.other.value=='')
	{
		if (document.MainForm.to_list.value == 'U/L' || document.MainForm.to_list.value == '0') 
		{
			alert('Please choose a destination before proceeding');
			return false;
		}
		else
		{
			document.MainForm.to.value = document.MainForm.to_list.value;
		}
	}
	else
	{
		
		if ( (document.MainForm.other.value).length == 3 )
		{
			document.MainForm.to.value = document.MainForm.other.value;
		}
		else if ( (document.MainForm.other.value).length < 6 )
		{
			alert('Specify 3 letter city code or click on "Other cities"!');
			return false;
		}
		else 
		{
			s = document.MainForm.other.value;
			if (s.substr(s.length-1,1) != ')' || s.substr(s.length-5,1) != '(')
			{
				alert('Specify 3 letter city code or click on "Other cities"!');
				return false;
			}
			document.MainForm.to.value = s.substr(s.length-4,3);
		}
	}
	
	if (!CheckDate()) {
		return false;
	}

	if ((document.MainForm.month_1.selectedIndex*31 + document.MainForm.Day.selectedIndex) > (document.MainForm.month_2.selectedIndex*31 + document.MainForm.RetDay.selectedIndex)) {
		alert('Return date is before departure date.\nPlease correct and try again.');
		return false;
	}
	
	createCookie('cheapFlightSearchTarifKlasse', document.MainForm.tarif_klasse.value, numDays)
	createCookie('cheapFlightSearchPax', document.MainForm.pax.value, numDays)
	createCookie('cheapFlightSearchPaxChd', document.MainForm.pax_chd[document.MainForm.pax_chd.selectedIndex].value, numDays)
	//createCookie('pax_inf', document.MainForm.pax_inf[document.MainForm.pax_inf.selectedIndex].value, numDays)
	createCookie('cheapFlightSearchPaxStudent', document.MainForm.pax_stud.value, numDays)
	createCookie('cheapFlightSearchPaxAdult', document.MainForm.pax_adult[document.MainForm.pax_adult.selectedIndex].value, numDays)
	createCookie('cheapFlightSearchFrom', document.MainForm.DepAptCode.value, numDays)
	createCookie('cheapFlightSearchDestination', document.MainForm.to.value, numDays)
	// createCookie('DestinationDisplay', document.MainForm.txtArrAptCode.value, numDays)
	// createCookie('DestinationHidden', document.MainForm.ArrAptCode.value, numDays)
	createCookie('DepDay', document.MainForm.Day.value, numDays)
	createCookie('DepMonYr', document.MainForm.month_1.value, numDays)
	createCookie('RetDay', document.MainForm.RetDay.value, numDays)
	createCookie('RetMonYr', document.MainForm.month_2.value, numDays)
	createCookie('cheapFlightSearchOther', document.MainForm.other.value, numDays)
	createCookie('cheapFlightSearchToList', document.MainForm.to_list.value, numDays)
	
	//if this iz OZ destination then
	//redirect to OZ site
	// -------- currently disabled
	// if you don't need it just delete this 'if'
	if (OzDest(document.MainForm.to.value))
	{
		// alert ('OZ Destination');
		document.oz_form.ArrAptCode.value = document.MainForm.to.value;
		document.oz_form.DepDay.value = document.MainForm.Day.value;
		document.oz_form.RetDay.value = document.MainForm.RetDay.value;
		document.oz_form.DepMonthYear.value = document.MainForm.month_1.value;
		document.oz_form.RetMonthYear.value = document.MainForm.month_2.value;
		document.oz_form.ADT.value = document.MainForm.pax.value;
		document.oz_form.CHD.value = document.MainForm.pax_chd.value;
		//document.oz_form.INFANTS.value = document.MainForm.pax_inf.value;
		

		document.oz_form.submit();
		return false;
	}

	return true;
}

//==============================================================================
// THIS SECTION GETS CURRENT DATE VALUES AND BUILDS ARRAY OF DATES FOR 12 MONTHS
//==============================================================================

dateToday = new Date();
thisYear   = dateToday.getFullYear();
thisMonth = dateToday.getMonth() + 1;
thisDate   = dateToday.getDate();
//tomorrowDate = dateToday.getDate()+14;

var MonthArray = new Array();

function openpopupDest(){
window.open('/includes/selectdest.asp','new1','toolbar=no,location=no,statusbar=no,menubar=no,resizable=yes,width=400,height=220,top=220,left=220');
//document.MainForm.to_list.value='U/L';
}

function OzDest(strDest)
{
	// remove this line if you want to redirect to Australian Holidays
	// for specific destinations
	return false;
		
	if (strDest=='ADL') return true;
	if (strDest=='ASP') return true;
	if (strDest=='AKL') return true;
	if (strDest=='DPS') return true;
	if (strDest=='BKK') return true;
	if (strDest=='BOS') return true;
	if (strDest=='BNE') return true;
	if (strDest=='CNS') return true;
	if (strDest=='CHC') return true;
	if (strDest=='DEW') return true;
	if (strDest=='HKG') return true;
	if (strDest=='HNL') return true;
	if (strDest=='KUL') return true;
	if (strDest=='LAX') return true;
	if (strDest=='MEL') return true;
	if (strDest=='NYC') return true;
	if (strDest=='PER') return true;
	if (strDest=='SIN') return true;
	if (strDest=='SYD') return true;
	if (strDest=='WLG') return true;
	return false;
}

function ClearDests()
{
	var objOption
	
	for(var i = document.search_form.elements["dest"].length; i >= 1; i--)
	{
		document.search_form.elements["dest"].options[i] = null
	}
	addElements(document.search_form.choice.value)
}

function addElements(strType){

if (strType == 'ski'){
	var strSki = new Array
	strSki[0] = 'ANDORRA-any#Andorra'
	strSki[1] = 'AUSTRIA-any#Austria'
	strSki[2] = 'FRANCE-any#France'
	strSki[3] = 'ITALY-any#Italy'
	strSki[4] = 'NORWAY-any#Norway'
	strSki[5] = 'SLOVENIA-any#Slovenia'
	strSki[6] = 'SWITZERLAND-any#Switzerland'
	strSki[7] = 'ANDORRA-any#Andorra'
	for(i=0;i<strSki.length;i++)
	{
		arTemp = strSki[i].split("#")
		InsertOption(arTemp[0], arTemp[1])
	}	
}

if (strType == 'pack'){
	var strPack = new Array
	
	strPack[0] = 'FAO#Algarve, Portugal'
	strPack[1] = 'ALC#Alicante, Spain'
	strPack[2] = 'BGI#Barbados, Caribbean'
	strPack[3] = 'BOJ#Bulgaria (Bourgas)'
	strPack[4] = 'VAR#Bulgaria (Varna)'
	strPack[5] = 'ALC#Costa Blanca, Spain'
	strPack[6] = 'GRO#Costa Brava, Spain'
	strPack[7] = 'AGP#Costa del Sol, Spain'
	strPack[8] = 'LEI#Costa de Almeria, Spain'
	strPack[9] = 'REU#Costa Dorada, Spain'
	strPack[10] = 'HER#Crete, Greece'
	strPack[11] = 'DBV#Croatia'
	strPack[12] = 'LCA#Cyprus'
	strPack[13] = 'POP#Dominican Republic'
	strPack[14] = 'FUE#Fuerteventura, Canaries'
	strPack[15] = 'NCE#French Riveria'
	strPack[16] = 'LPA#Gran Canaria, Canaries'
	strPack[17] = 'IBZ#Ibiza, Spain'
	strPack[18] = 'EFL#Kefalonia, Greece'
	strPack[19] = 'ACE#Lanzarote, Canaries'
	strPack[20] = 'LIS#Lisbon, Portugal'
	strPack[21] = 'FNC#Madeira, Portugal'
	strPack[22] = 'PMI#Majorca, Spain'
	strPack[23] = 'MLA#Malta'
	strPack[24] = 'DBV#Montenegro'
	strPack[25] = 'AGA#Morocco'
	strPack[26] = 'MAH#Menorca, Spain'
	strPack[27] = 'RHO#Rhodes, Greece'
	strPack[28] = 'VAR#Romania'
	strPack[29] = 'REU#Salou, Spain'
	strPack[30] = 'AHO#Sardinia, Italy'
	strPack[31] = 'CTA#Sicily, Italy'
	strPack[32] = 'TFS#Tenerife, Canaries'
	strPack[33] = 'MIR#Tunisia'
	strPack[34] = 'AYT#Turkey (Antalya)'
	strPack[35] = 'BJV#Turkey (Bodrum)'
	strPack[36] = 'ADB#Turkey (Izmir)'
	strPack[37] = 'VRN#Verona, Italy'
	strPack[38] = 'ZTH#Zakinthos, Greece'
	for(i=0;i<strPack.length;i++)
	{
		arTemp = strPack[i].split("#")
		InsertOption(arTemp[0], arTemp[1])
	}		
}

}

function InsertOption(strValue, strText)
{
	var	objOption = new Option
				
	objOption.value = strValue
	objOption.text = strText
					
	document.search_form.elements["dest"].add(objOption)
}


function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}
var numDays = addDays(new Date(),5)

function createCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



function checkSunHotelsFields(){
	//validate user input
	var missinginfo = "";
	if (document.book.tempArea.value == ""){
		missinginfo += "\n     -  You must select a Destination";	   
	}	
	if (document.book.tempBoardCategory.value == "-"){
		missinginfo += "\n     -  You must select a Board Option";	   
	}
	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 document.book.submit();
}
// * hand all instances of the Date object to this function for "repairs"

// -->

