﻿function Hashtable()
{
    this.hashtable 	= new Array();
}
Hashtable.prototype.clear = function()
{
    this.hashtable = new Array();
}
Hashtable.prototype.containsKey = function (key)
{
    var exists = false;

    for (var i in this.hashtable)
    {
        if (i == key && this.hashtable[i] != null)
        {
            exists = true;
            break;
        }
    }
    return exists;
}
Hashtable.prototype.containsValue = function(value)
{
    var contains = false;

    if (value != null)
    {
        for (var i in this.hashtable)
        {
            if (this.hashtable[i] == value)
            {
                contains = true;
                break;
            }
        }
    }

    return contains;
}
Hashtable.prototype.get = function(key)
{
    return this.hashtable[key];
}
Hashtable.prototype.isEmpty = function()
{
    return (this.size == 0) ? true : false;
}
Hashtable.prototype.keys = function()
{
    var keys = new Array();

    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
            keys.push(i);
    }
    return keys;
}
Hashtable.prototype.put = function(key, value)
{
    if (key == null || value == null)
    {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }
    else
    {
        this.hashtable[key] = value;
    }
}
Hashtable.prototype.remove = function(key)
{
    var rtn = this.hashtable[key];

    this.hashtable[key] = null;

    return rtn;
}
Hashtable.prototype.size = function()
{
    var size = 0;

    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
            size ++;
    }

    return size;
}
Hashtable.prototype.values = function()
{
    return this.hashtable;
}
Hashtable.prototype.toArray = function()
{
	var array = new Array();

	for (var i in this.hashtable )
		array[array.length] = this.hashtable[i];

	return array;
}
///////////////////////////////////////////////////////////////////////////////////

function isDate(p_Expression){
	return !isNaN(new Date(p_Expression));		// <<--- this needs checking
}

// REQUIRES: isDate()
function dateAdd(p_Interval, p_Number, p_Date){
	if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	if(isNaN(p_Number)){return "invalid number: '" + p_Number + "'";}	

	p_Number = new Number(p_Number);
	var dt = new Date(p_Date);
	switch(p_Interval.toLowerCase()){
		case "yyyy": {// year
			dt.setFullYear(dt.getFullYear() + p_Number);
			break;
		}
		case "q": {		// quarter
			dt.setMonth(dt.getMonth() + (p_Number*3));
			break;
		}
		case "m": {		// month
			dt.setMonth(dt.getMonth() + p_Number);
			break;
		}
		case "y":		// day of year
		case "d":		// day
		case "w": {		// weekday
			dt.setDate(dt.getDate() + p_Number);
			break;
		}
		case "ww": {	// week of year
			dt.setDate(dt.getDate() + (p_Number*7));
			break;
		}
		case "h": {		// hour
			dt.setHours(dt.getHours() + p_Number);
			break;
		}
		case "n": {		// minute
			dt.setMinutes(dt.getMinutes() + p_Number);
			break;
		}
		case "s": {		// second
			dt.setSeconds(dt.getSeconds() + p_Number);
			break;
		}
		case "ms": {		// second
			dt.setMilliseconds(dt.getMilliseconds() + p_Number);
			break;
		}
		default: {
			return "invalid interval: '" + p_Interval + "'";
		}
	}
	return dt;
}


var month_name = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var day_name = new Array("Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat");

function fill_monthyear_list(){
	var sel_dept_date_monthyear = document.getElementById("dept_date_monthyear");
	var todayDate = new Date();
	var defaultDate = new Date(); 
	defaultDate = dateAdd("m",1,todayDate);
					
	for (i=0;i<12;i++){		
	    	
	    if (todayDate.getDate() >= 29){todayDate = dateAdd("d",-10,todayDate);}

		if (i>0){todayDate = dateAdd("m",1,todayDate);}

		var month = todayDate.getMonth();
		var year = todayDate.getFullYear();
		
		var val = month_name[month]+' '+year;
		var key = month+'-'+year;
		
		sel_dept_date_monthyear.options[i] = new Option(val,key);
	}
	sel_dept_date_monthyear.options[1].selected=true;
}

function fill_day_list(changed){	
	var sel_dept_date_monthyear = document.getElementById("dept_date_monthyear");
	var sel_dept_date_day = document.getElementById("dept_date_day");		
	var monthyear = sel_dept_date_monthyear.options[sel_dept_date_monthyear.selectedIndex].value;
	
	if (monthyear != ""){
		var todayDate = new Date();			
		var defaultDate = new Date(); 
		var arr = monthyear.split("-");
		
		var month = arr[0];
		var year = arr[1];
		
		var dt = new Date();
		dt.setDate(1);
		dt.setMonth(month);
		dt.setFullYear(year);		
		
		if (changed == true){				
			defaultDate.setDate(sel_dept_date_day.options[sel_dept_date_day.selectedIndex].value);
			defaultDate.setMonth(month);
			defaultDate.setFullYear(year);	
		}else{	
			defaultDate = dateAdd("m",1,todayDate);	
		}
		
		var current_month = month				
		var x = dt.getMonth();
		var i =0;
		while (x == current_month){
			if (i>0){dt = dateAdd("d",1,dt);}										
			x = dt.getMonth();
			
			if (x == current_month){
				var thisDay = dt.getDay();
				var val = day_name[thisDay]+' '+dt.getDate();
				var key = dt.getDate();
								
				sel_dept_date_day.options[i] = new Option(val,key);		
			}
			i++;
		}		
		sel_dept_date_day.options[defaultDate.getDate()-1].selected=true;
	}
}

function fill_departure_list(){	
	var sel_dept_codes = document.getElementById("dept_codes");
	var x = 0;
	
	sel_dept_codes.options[x] = new Option("Select UK Airport","");
	x++;
	sel_dept_codes.options[x] = new Option("---------------------","");
	x++;
	sel_dept_codes.options[x] = new Option("","");
	x++;
	
	for (var i in arr_main_dept_codes.keys()){
		var key = arr_main_dept_codes.keys()[i];
		var val = arr_main_dept_codes.values()[key];
				
		sel_dept_codes.options[x] = new Option(val,key);
		sel_dept_codes.options[x].style.backgroundColor = '#E4E4E4'; 		
		x++;
		
		var s = "";
		s = arr_sub_dept_codes.values()[key];
		
		var arr_1 = s.split(",");			
		var j;
		
		for (j=0;j<arr_1.length;j++){
			var arr_2 = arr_1[j].split("||");
			
			sel_dept_codes.options[x] = new Option(arr_2[1],arr_2[0]);
			x++;
		}
		
		sel_dept_codes.options[x] = new Option("","");
		x++;		
	}
}

function fill_destination_list(){
	var sel_dest_codes = document.getElementById("dest_codes");
	var x = 0;
	
	sel_dest_codes.options[x] = new Option("Please Select","");
	x++;	
	sel_dest_codes.options[x] = new Option("","");
	x++;
	
	for (var i in arr_main_dest_codes.keys()){
		var key = arr_main_dest_codes.keys()[i];
		var val = arr_main_dest_codes.values()[key];
				
		sel_dest_codes.options[x] = new Option(val,key);
		sel_dest_codes.options[x].style.backgroundColor = '#E4E4E4'; 		
		x++;
		
		var s = "";
		s = arr_sub_dest_codes.values()[key];
		
		var arr_1 = s.split(",");			
		var j;
		
		for (j=0;j<arr_1.length;j++){
			var arr_2 = arr_1[j].split("||");
			
			sel_dest_codes.options[x] = new Option(arr_2[1],arr_2[0]);
			x++;
		}
		
		sel_dest_codes.options[x] = new Option("","");
		x++;		
	}
}

function doSearch(affiliateSiteID){
	//open window to henoo	
		
	var dept_point;
	var arrv_point;
	var dept_date;
	var duration;
	var flexibilty;	
	var price;
	
	//get departure code
	var dept_point = document.getElementById("dept_codes").value;
	
	if (dept_point == ""){
		alert("Please select where you would like to depart from.");
		document.getElementById("dept_codes").focus();
		return false;
	}
		
	//get destination code
	var arrv_point = document.getElementById("dest_codes").value;
	
	if (arrv_point == ""){
		alert("Please select where you would like to travel to.");
		document.getElementById("dest_codes").focus();
		return false;
	}
	
	//build departure date
	var monthyear = document.getElementById("dept_date_monthyear").value;
	var day = document.getElementById("dept_date_day").value;		
		
	var arr = monthyear.split("-");		
	var month = month_name[arr[0]];
	var year = arr[1];		
	dept_date = day+'-'+month+'-'+year
	
	//get duration
	var sel_duration = document.getElementById("duration");
	var duration;
	if (sel_duration == null){
		duration = '1-30';
	}
	else {
		duration = sel_duration.options[sel_duration.selectedIndex].value;
	}
	
	//get flexibility
	var sel_flexibility = document.getElementById("flexibility");		
	var flexibility;	
	if (sel_flexibility == null){
		flexibility = '7';
	}
	else{
		flexibility = sel_flexibility.options[sel_flexibility.selectedIndex].value;	
	}	
	
	//get price range
	var sel_price = document.getElementById("price_range");
	var price;
	if (sel_price == null ){
		price = '1-10000';
	}
	else {
		price = sel_price.options[sel_price.selectedIndex].value;
	}
	
	var affiliateRef = document.getElementById("hs_affiliateRef").value;
	var textColor = document.getElementById("hs_textColor").value;
	var bgColor = document.getElementById("hs_bgColor").value;
	
	var url;	
	//url = 'http://www.travelsearchresults.com/results.aspx';
	url = 'http://v1.travelsearchresults.com/results.aspx';
			
	var qs;	
	qs = '?dp='+dept_point+'&ap='+arrv_point+'&p='+price+'&dd='+dept_date+'&d='+duration+'&f='+flexibility+'&a=51806&as=false&custom=true&a2='+affiliateSiteID+'&aRef='+affiliateRef+'&tc='+textColor+'&bc='+bgColor;
	
	url = url + qs
	
	window.open(url,'henoo_banner_search');		
}

var arr_main_dept_codes = new Hashtable();
var arr_sub_dept_codes = new Hashtable();

arr_main_dept_codes.put ("LON", "London, Any");
arr_main_dept_codes.put ("SOUTHEAST", "South East, Any");
arr_main_dept_codes.put ("MIDLANDS", "Midlands, any");
arr_main_dept_codes.put ("NORTHWEST", "North West, any");
arr_main_dept_codes.put ("NORTHEAST", "North East, any");
arr_main_dept_codes.put ("NWI", "East Anglia, any");
arr_main_dept_codes.put ("SCOTLAND", "Scotland, any");
arr_main_dept_codes.put ("CWL", "Wales, any");
arr_main_dept_codes.put ("NORTHERNIRELAND", "Northern Ireland, any");
arr_main_dept_codes.put ("IOM", "Isle of Man, any");
arr_main_dept_codes.put ("CHANNELISLANDS", "Channel Islands, any");

arr_sub_dept_codes.put ("LON", "LGW||London Gatwick (LGW),LHR||London Heathrow (LHR),LTN||London Luton (LTN),LCY||London City (LCY),STN||London Stansted (STN)");
arr_sub_dept_codes.put ("SOUTHEAST", "BCH||Bournemouth (BCH),SOU||Southampton (SOU),BRS||Bristol (BRS),PLH||Plymouth (PLH),NQY||Newquay (NQY),EXT||Exeter (EXT)");
arr_sub_dept_codes.put ("MIDLANDS", "BHX||Birmingham (BHX),CVT||Coventry (CVT),EMA||East Midlands (EMA)");
arr_sub_dept_codes.put ("NORTHWEST", "BLK||Blackpool (BLK),LPL||Liverpool (LPL),MAN||Manchester (MAN)");
arr_sub_dept_codes.put ("NORTHEAST", "HUY||Humberside (HUY),NCL||Newcastle (NCL),LBA||Leeds Bradford (LBA),MME||Teesside (MME)");
arr_sub_dept_codes.put ("NWI", "NWI||Norwich (NWI)");
arr_sub_dept_codes.put ("SCOTLAND", "GLA||Glasgow (GLA),EDI||Edinburgh (EDI),PIK||Prestwick (PIK),ABZ||Aberdeen (ABZ),INV||Inverness (INV)");
arr_sub_dept_codes.put ("CWL", "CWL||Cardiff (CWL)");
arr_sub_dept_codes.put ("NORTHERNIRELAND", "BFS||Belfast (BFS),BHD||Belfast City (BHD)");
arr_sub_dept_codes.put ("IOM", "IOM||Isle of Man (IOM)");
arr_sub_dept_codes.put ("CHANNELISLANDS", "GCI||Guernsey (GCI),JER||Jersey (JER)");
 


var arr_main_dest_codes	= new Hashtable();
var arr_sub_dest_codes = new Hashtable();

arr_main_dest_codes.put ("BGI", "Barbados, any");
arr_main_dest_codes.put ("BRAZIL", "Brazil, any");
arr_main_dest_codes.put ("BULGARIA", "Bulgaria, any");
arr_main_dest_codes.put ("CANARYISLANDS", "Canary Islands, any");
arr_main_dest_codes.put ("CARIBBEAN", "Caribbean, any");
arr_main_dest_codes.put ("CHINA", "China, Any");
arr_main_dest_codes.put ("CROATIA", "Croatia, any");
arr_main_dest_codes.put ("CUBA", "Cuba, any");
arr_main_dest_codes.put ("CYPRUS", "Cyprus, any");
arr_main_dest_codes.put ("DOMINICANREP", "Dominican Rep, any");
arr_main_dest_codes.put ("EGYPT", "Egypt, any");
arr_main_dest_codes.put ("GREECE", "Greece, any");
arr_main_dest_codes.put ("INDIA", "India, any");
arr_main_dest_codes.put ("ISRAEL", "Israel");
arr_main_dest_codes.put ("ITALY", "Italy, any");
arr_main_dest_codes.put ("JAMAICA", "Jamaica");
arr_main_dest_codes.put ("JAPAN", "Japan");
arr_main_dest_codes.put ("GAMBIA", "Gambia");
arr_main_dest_codes.put ("KENYA", "Kenya, any");
arr_main_dest_codes.put ("MADERIA", "Maderia");
arr_main_dest_codes.put ("MLE", "Maldives");
arr_main_dest_codes.put ("MLA", "Malta");
arr_main_dest_codes.put ("MEXICO", "Mexico");
arr_main_dest_codes.put ("MOROCCO", "Morocco, any");
arr_main_dest_codes.put ("PORTUGAL", "Portugal");
arr_main_dest_codes.put ("OLB", "Sardinia");
arr_main_dest_codes.put ("CTA", "Sicily");
arr_main_dest_codes.put ("SOUTHAFRICA", "South Africa, any");
arr_main_dest_codes.put ("ESP", "Spain, any");
arr_main_dest_codes.put ("CMB", "Sri Lanka");
arr_main_dest_codes.put ("SWEDEN", "Sweden, any");
arr_main_dest_codes.put ("TUNISIA", "Tunisia, any");
arr_main_dest_codes.put ("TURKEY", "Turkey, any");
arr_main_dest_codes.put ("UAE", "United Arab Emirates");
arr_main_dest_codes.put ("USA", "USA, any");

arr_sub_dest_codes.put ("BGI", "BGI||Bridgetown");
arr_sub_dest_codes.put ("BRAZIL", "SSA||Salvador");
arr_sub_dest_codes.put ("BULGARIA", "BOJ||Bourgas,PDV||Plodiv,VAR||Varna");
arr_sub_dest_codes.put ("CANARYISLANDS", "FUE||Fuerteventura,LPA||Gran Canaria - Las Palmas,TFS||Tenerife - Reina Sofia,TFN||Tenerife - Norte Los Rodeos,ACE||Lanzarote - Arrecife");
arr_sub_dest_codes.put ("CARIBBEAN", "TAB||Tobago,ANU||Antigua,BGI||Barbados,NAS||Bahamas,MBJ||Jamaica,GND||Grenada,UVF||St. Lucia");
arr_sub_dest_codes.put ("CHINA", "PVG||Shanghai,HKG||Hong Kong");
arr_sub_dest_codes.put ("CROATIA", "DBV||Dubrovnik,PUY||Pula,SPU||Split");
arr_sub_dest_codes.put ("CUBA", "CCC||Cayo Coco,HOG||Holguin,VRA||Varadero,HAV||Havana,SNU||Santa Clara");
arr_sub_dest_codes.put ("CYPRUS", "LCA||Larnaca,PFO||Paphos");
arr_sub_dest_codes.put ("DOMINICANREP", "POP||Puerto Plata,PUJ||Punta Cana,LRM||La Romana");
arr_sub_dest_codes.put ("EGYPT", "HRG||Hurghada,LXR||Luxor,RMF||Marsa Alam,SSH||Sharm El Sheikh,TCP||Taba");
arr_sub_dest_codes.put ("GREECE", "ATH||Athens,CFU||Corfu,CHQ||Crete - Chania,HER||Crete - Heraklion,SKG||Halkidiki - Thessalonika,KGS||Kos/Kalymnos,EFL||Kefalonia/Ithaca,KVA||Kavala,PVK||Lefkas/Meganissi/Parga,LXS||Limnos,MJT||Lesvos,KLX||Peloponnese - Kalamata,RHO||Rhodes/Symi,SMI||Samos,JTR||Santorini - Thira,JSI||Skiathos/Alonissos/Skopelos,ZTH||Zakynthos");
arr_sub_dest_codes.put ("INDIA", "GOI||Goa - Dabolim,TRV||Kerala - Trivandrum,DEL||Delhi");
arr_sub_dest_codes.put ("ISRAEL", "VDA||Eilat");
arr_sub_dest_codes.put ("ITALY", "SUF||Lamezia,NAP||Naples,RMI||Rimini,VCE||Venice,VRN||Verona");
arr_sub_dest_codes.put ("JAMAICA", "MBJ||Montego Bay");
arr_sub_dest_codes.put ("JAPAN", "NRT||Tokyo");
arr_sub_dest_codes.put ("GAMBIA", "BJL||Banjul");
arr_sub_dest_codes.put ("KENYA", "MBA||Mombasa,NBO||Nairobi");
arr_sub_dest_codes.put ("MADERIA", "FNC||Funchal");
arr_sub_dest_codes.put ("MLE", "MLE||Male");
arr_sub_dest_codes.put ("MLA", "MLA||Malta");
arr_sub_dest_codes.put ("MEXICO", "CUN||Cancun");
arr_sub_dest_codes.put ("MOROCCO", "AGA||Agadir,FEZ||Fez,RAK||Marrakech,TNG||Tangiers");
arr_sub_dest_codes.put ("PORTUGAL", "FAO||Algarve - Faro");
arr_sub_dest_codes.put ("OLB", "OLB||Olbia");
arr_sub_dest_codes.put ("CTA", "CTA||Catania");
arr_sub_dest_codes.put ("SOUTHAFRICA", "JNB||Johannesburg,CPT||Cape Town");
arr_sub_dest_codes.put ("ESP", "LEI||Costa Almeria - Almeria,ALC||Costa Blanca - Alicante,GRO||Costa Brava - Gerona,AGP||Costa del Sol - Malaga,REU||Costa Dorada - Reus,IBZ||Ibiza/Formentera,XRY||Jerez De La Frontera,ACE||Lanzarote - Arrecife,PMI||Majorca - Palma,	MAH||Menorca - Mahon");
arr_sub_dest_codes.put ("CMB", "CMB||Colombo");
arr_sub_dest_codes.put ("SWEDEN", "OSD||Ostersund");
arr_sub_dest_codes.put ("TUNISIA", "DJE||Djerba,MIR||Monastir,TUN||Tunis");
arr_sub_dest_codes.put ("TURKEY", "AYT||Turkey - Antalya,BJV||Turkey - Bodrum,DLM||Turkey - Dalaman,ADB||Turkey - Izmir");
arr_sub_dest_codes.put ("UAE", "DXB||Dubai");
arr_sub_dest_codes.put ("USA", "SFB||Florida - Sanford,MCO||Florida - Orlando,LAS||Las Vegas,BOS||Boston,LAX||Los Angeles,SFO||San Francisco,MIA||Miami,IAD||Washington,NEWYORK||New York");


fill_departure_list()	
fill_destination_list()
fill_monthyear_list()
fill_day_list(false)
