/**
 * Quicksearch 2.15 - final
 *
 * Dit bestand niet op uw eigen server zetten i.v.m. eventuele code updates in de toekomst
 * Gebruik liever een javascript src naar http://www.atp.nl/javascript/quicksearch.js en stel de settings in
 *
 *
 * versie overzicht:
 *
 * 2.15, 22 okt 2003, Jef    - final versie 2 met kleine code clean up (compile ready)
 * 2.14, 17 okt 2003, Jef    - selected_departure en engine_host support toegevoegd aan de QS_Setup; QS_setup["width"] is deprecated (zie stylesheet opties)
 * 2.13, 18 sep 2003, Jef    - Bugfix : jaar bij vertrek en aankomst datums werd verkeert weergegeven op mozilla (netscape) platform en andere OS (2003 werd 103). Was probleem met verschil in telling vanaf het jaar (jaar 0 of 1900)
 * 2.12, 17 sep 2003, Jef    - target naar self opgenoment voor de submit knop om conflicten met html base targets tegen te gaan
 * 2.11, 12 sep 2003, Jef    - frameuri en frametarget voor frame support toegevoegt met statements rond de <form> tag voor afwijkende post in dit geval
 * 2.10, 11 aug 2003, Jef    - selected_destination toegevoegt aan de setup
 * 2.09, 14 jul 2003, Jef    - Character Encoding bug tijdelijk opgelost door in de bestemmingen array de e acute te vervangen voor een normale e
 * 2.08, 08 apr 2003, Jef    - Action prefix toegevoegd
 * 2.07, 07 apr 2003, Jordy  - CSS declaration variabelen fix
 * 2.06, 07 jan 2003, Jef    - QS_md2 functie (2.03 fix) nu als QS_md gezet
 * 2.05, 06 jan 2003, Ronald - Bug gefixed die niet de juiste maand / jaar combinatie selecteerde
 * 2.04, 03 jan 2003, Jef    - Target variabele toegevoegd zodat Quicksearch naar andere vensters kan posten
 * 2.03, ?? dec 2002, Jef    - Functie om maanden te genereren (QS_md) en de html output (QS_html) waren bugged. Is nu gefixed.
 * 2.02, ?? dec 2002, Jef    - Default settings toegevoegd
 * 2.01, ?? nov 2002, Jef    - Quicksearch volledig herschreven
 */

// default main setup

var QS_setup = Array();
QS_setup["width"]                = 280;
QS_setup["engine_code"]          = 'ATPNLQS';
QS_setup["engine_host"]          = "online.atp.nl";
QS_setup["dayoffset"]            = 7;
QS_setup["dayoffset_retour"]     = 14;
QS_setup["monthnames"]           = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"];
QS_setup["field_descriptions"]   = ["", "", "", ""];
QS_setup["submitbutton_imgsrc"]  = "http://www.atp.nl/home/includes/opening/images/nu_zoeken.gif"
QS_setup["footer"]               = 'Meer bestemmingen? <a href="' + QS_setup["engine_host"] + '/tc.dll?rs=' + QS_setup["engine_code"] + '">klik hier!</a>';
QS_setup["target"]               = "_self";
QS_setup["action_prefix"]        = "";
QS_setup["selected_departure"]   = "AMS";
QS_setup["selected_destination"] = false;
QS_setup["frameuri"]             = false;
QS_setup["frametarget"]          = "externalframeset";

// default style

var QS_style = Array();
QS_style["table"]                = "background-color : #FFDF7B";
QS_style["options"]              = "background-color : #FFFFFF";
QS_style["text"]                 = "font-family : arial; font-size : 11px; color : #000000";


// alle bestemmingen ondersteund door de quicksearch

var QS_countries = [
	["AMS", "Amsterdam"],
	["ABZ", "Aberdeen"],
	["ABJ", "Abidjan"],
	["AUH", "Abu Dhabi"],
	["ACC", "Accra"],
	["ADL", "Adelaide"],
	["ALC", "Alicante"],
	["ALA", "Almaty"],
	["AMM", "Amman"],
	["ANR", "Antwerpen"],
	["AUA", "Aruba"],
	["ATH", "Athene"],
	["ATL", "Atlanta"],
	["AKL", "Auckland"],
	["BAH", "Bahrein"],
	["BKK", "Bangkok"],
	["BCN", "Barcelona"],
	["BSL", "Basel"],
	["BJS", "Beijing"],
	["BEY", "Beiroet"],
	["BGO", "Bergen"],
	["BER", "Berlijn"],
	["BRN", "Bern"],
	["BLL", "Billund"],
	["BHX", "Birmingham"],
	["BUH", "Boekarest"],
	["BOG", "Bogota"],
	["BLQ", "Bologna"],
	["BON", "Bonaire"],
	["BOD", "Bordeaux"],
	["BOS", "Boston"],
	["BRE", "Bremen"],
	["BNE", "Brisbane"],
	["BRS", "Bristol"],
	["BRU", "Brussel"],
	["BUD", "Budapest"],
	["BUE", "Buenos Aires"],
	["CNS", "Cairns"],
	["CAI", "Cairo"],
	["CCU", "Calcutta"],
	["CUN", "Cancun"],
	["CWL", "Cardiff"],
	["CAS", "Casablanca"],
	["CTA", "Catania"],
	["CPT", "Cape Town"],
	["CCS", "Caracas"],
	["CMF", "Chambery"],
	["CHI", "Chicago"],
	["CHC", "Christchurch"],
	["CMB", "Colombo"],
	["ORK", "Cork"],
	["CUR", "Curacao"],
	["DKR", "Dakar"],
	["DFW", "Dallas"],
	["DAM", "Damascus"],
	["DMM", "Damman"],
	["DAR", "Dar Es Salaam"],
	["DRW", "Darwin"],
	["DEL", "Delhi"],
	["DPS", "Denpasar"],
	["DEN", "Denver"],
	["DTT", "Detroit"],
	["DOH", "Doha"],
	["DXB", "Dubai"],
	["DUB", "Dublin"],
	["DUS", "Dusseldorf"],
	["EMA", "East Midlands"],
	["EDI", "Edinburgh"],
    ["YEG", "Edmonton"],
	["EIN", "Eindhoven"],
	["FAO", "Faro"],
	["FLR", "Florence"],
	["FRA", "Frankfurt"],
	["FNC", "Funchal"],
	["GVA", "Geneve"],
	["GLA", "Glasgow"],
	["GOT", "Gothenborg"],
    ["GRQ", "Groningen"],
	["GUA", "Guatemala"],
	["GYE", "Guayaquil"],
	["HAM", "Hamburg"],
	["HAJ", "Hannover"],
	["HAN", "Hanoi"],
	["HAV", "Havana"],
	["HEL", "Helsinki"],
	["HER", "Heraklion"],
	["SGN", "Ho Chi Minh"],
	["HOG", "Holguin"],
	["HKG", "Hong Kong"],
	["HNL", "Honolulu"],
	["HOU", "Houston"],
	["HUY", "Humberside"],
	["INN", "Innsbruck"],
	["IST", "Istanbul"],
	["JKT", "Jakarta"],
	["JNB", "Johannesburg"],
	["KAN", "Kano"],
	["KTM", "Kathmandu"],
	["CGN", "Keulen"],
	["IEV", "Kiev"],
	["JRO", "Kilimanjaro"],
	["CCU", "Kolkata"],
	["CPH", "Kopenhagen"],
	["KUL", "Kuala Lumpur"],
	["KWI", "Kuwait"],
	["LOS", "Lagos"],
	["LPB", "La Paz"],
	["LCA", "Larnaca"],
	["LPA", "Las Palmas"],
	["LBA", "Leeds"],
	["LIM", "Lima"],
	["LNZ", "Linz"],
	["LIS", "Lissabon"],
	["LCY", "London City"],
	["LGW", "London Gatwick"],
	["LHR", "London Heathrow"],
	["LTN", "London Luton"],
	["STN", "London Stansted"],
	["LAX", "Los Angeles"],
	["LUX", "Luxemburg"],
	["LYS", "Lyon"],
	["MST", "Maastricht"],
	["MAD", "Madrid"],
	["AGP", "Malaga"],
	["MAN", "Manchester"],
	["MNL", "Manila"],
	["MRS", "Marseille"],
	["MEL", "Melbourne"],
	["MEM", "Memphis"],
	["MEX", "Mexico City"],
	["MIA", "Miami"],
	["MIL", "Milaan"],
	["MSP", "Minneapolis"],
	["YUL", "Montreal"],
	["MOW", "Moskou"],
	["BOM", "Mumbai"],
	["MUC", "Munchen"],
	["MCT", "Muscat"],
	["NBO", "Nairobi"],
	["NAP", "Napels"],
	["NCL", "Newcastle"],
	["JFK", "New York JFK"],
	["EWR", "New York EWR"],
	["NCE", "Nice"],
	["NWI", "Norwich"],
	["NUE", "Nuremberg"],
	["OPO", "Oporto"],
	["MCO", "Orlando"],
	["KIX", "Osaka"],
	["OSL", "Oslo"],
	["PMI", "Palma"],
	["PFO", "Paphos"],
	["PBM", "Paramaribo"],
	["CDG", "Parijs CDG"],
	["ORY", "Parijs Orly"],
	["PER", "Perth"],
	["PSA", "Pisa"],
	["PRG", "Praag"],
	["POP", "Puerto Plata"],
	["PUJ", "Punta Cana"],
	["UIO", "Quito"],
	["KEF", "Reykjavik"],
	["RHO", "Rhodos"],
	["GIG", "Rio de Janeiro"],
	["ROM", "Rome"],
	["RTM", "Rotterdam"],
	["SXM", "St Maarten"],
	["SZG", "Salzburg"],
    ["SAN", "San Diego"],
	["SFO", "San Francisco"],
	["SCL", "Santiago de Chile"],
	["SJO", "San Jose"],
	["SDQ", "Santa Domingo"],
	["SAO", "Sao Paolo"],
	["SEA", "Seattle"],
	["SEL", "Seoul"],
	["SVQ", "Seville"],
	["SHA", "Shanghai"],
	["SIN", "Singapore"],
	["SOF", "Sofia"],
	["LED", "St. Petersburg"],
	["SVG", "Stavanger"],
	["STO", "Stockholm"],
	["STR", "Stuttgart"],
	["SYD", "Sydney"],
	["TPE", "Taipei"],
	["MME", "Teesside"],
	["THR", "Teheran"],
	["TLV", "Tel Aviv"],
	["TCI", "Tenerife"],
	["SKG", "Thessaloniki"],
	["TYO", "Tokyo"],
	["TLS", "Toulouse"],
	["YTO", "Toronto"],
	["TIP", "Tripoli"],
    ["TRD", "Trondheim"],
	["TUN", "Tunis"],
	["TRN", "Turijn"],
	["VLC", "Valencia"],
	["YVR", "Vancouver"],
    ["YYC", "Calgary"],
	["VRA", "Varadero"],
	["VCE", "Venetie"],
	["VNO", "Vilnius"],
	["WAW", "Warschau"],
	["WAS", "Washington"],
	["WLG", "Wellington"],
	["VIE", "Wenen"],
    ["ZAG", "Zagreb"],
	["ZRH", "Zurich"]
];


// code

function QS_html()
{
	var o = '';
	if (QS_setup['frameuri']) o += '<form method="post" name="ATPQS" action="' + QS_setup["action_prefix"] + 'http://www.atp.nl/quicksearch.php?TID=' + QS_setup["engine_code"] + '&target=' + QS_setup["frametarget"] + '&uri=' + QS_setup["frameuri"] + '" target="' + QS_setup["target"] + '">';
    else o += '<form method="post" name="ATPQS" action="' + QS_setup["action_prefix"] + 'http://' + QS_setup["engine_host"] + '/tc.dll?ac=search&st=fares&TID=' + QS_setup["engine_code"] + ':XXH" target="' + QS_setup["target"] + '">';
	o += QS_inputhidden("trip", "return");
	o += QS_inputhidden("no", "9");
	o += QS_inputhidden("NSC", 0);
	o += QS_inputhidden("NSI", 0);
	o += QS_inputhidden("TD1", "Anytime");
	o += QS_inputhidden("TD2", "Anytime");
	o += QS_inputhidden("CX", "");
	o += QS_inputhidden("CL", "N");
	o += QS_inputhidden("hold", "AirStep2");
	o += QS_inputhidden("proc", "ProcessAirStep2.htm");
	o += QS_inputhidden("DFP", 0); 
	o += '<table cellpadding="0" cellspacing="0" width="' + QS_setup["width"] + '" style="' + QS_style["table"] + '"><tr><td>';
	o += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
	o += '<tr>';
	o += '<td colspan="4" height="2"></td>';
	o += '</tr>';
	o += '<tr valign="center">';
	o += '<td nowrap><p align="left" style="' + QS_style["text"] + '">&nbsp;' + QS_setup["field_descriptions"][0] + '&nbsp;</p></td>';
	o += '<td><p align="left" style="' + QS_style["text"] + '">' + QS_select("CD1", QS_countries, QS_setup["selected_departure"]) + '</p></td>';
	o += '<td nowrap><p align="left" style="' + QS_style["text"] + '">&nbsp;' + QS_setup["field_descriptions"][2] + '&nbsp;</p></td>';
	o += '<td><p align="right" style="' + QS_style["text"] + '"><table cellspacing="0" cellpadding="0"><tr><td><p>' + QS_dd("DD1", QS_setup["dayoffset"]) + '</p></td><td><p>' + QS_md("MD1", QS_setup["dayoffset"]) + '&nbsp;</p></td></tr></table></p></td>';
	o += '</tr>';
	o += '<tr valign="center">';
	o += '<td nowrap><p align="left" style="' + QS_style["text"] + '">&nbsp;' + QS_setup["field_descriptions"][1] + '&nbsp;</p></td>';
	o += '<td><p align="left" style="' + QS_style["text"] + '">' + QS_select("CA1", QS_countries, QS_setup["selected_destination"]) + '</p></td>';
	o += '<td nowrap><p align="left" style="' + QS_style["text"] + '">&nbsp;' + QS_setup["field_descriptions"][3] + '&nbsp;</p></td>';
	o += '<td><p align="right" style="' + QS_style["text"] + '"><table cellspacing="0" cellpadding="0"><tr><td><p>' + QS_dd("DD2", QS_setup["dayoffset_retour"]) + '</p></td><td><p>' + QS_md("MD2", QS_setup["dayoffset_retour"]) + '&nbsp;</p></td></tr></table></p></td>';
	o += '</tr>';
	o += '<tr>';
	o += '<td colspan="4">';
	o += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td><p style="' + QS_style["text"] + '">&nbsp;Flexibele data? Ja <input type="checkbox" name="DVR" value="1" checked></td><td align="right"><p style="' + QS_style["text"] + '">&nbsp;aantal volwassen <select name="NSA" style="' + QS_style["options"] + '"><option selected value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select>&nbsp;</td></tr></table>';
	o += '</td>';
	o += '</tr>';
	o += '<tr>';
	o += '<td colspan=4">';
	o += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr height="20"><td align="left"><p style="' + QS_style["text"] + '">' + QS_setup["footer"] + '</p></td><td align="center"><p style="' + QS_style["text"] + '"><a href="javascript:QS_submit()" target="_self"><img src="' + QS_setup["submitbutton_imgsrc"] + '" border="0"></a></p></td></tr></table>';
	o += '</td>';
	o += '</tr>';
	o += '</table>';
	o += '</td>';
	o += '</tr>';
	o += '</table>';
	o += '</form>';
	return o;
}

function QS_inputhidden(iName, iValue)
{
	return '<input type="hidden" name="' + iName + '" value="' + iValue + '">';
}

function QS_option(oValue, oText, isSelected)
{
	var o = '<option style="' + QS_style["options"] + '" value="' + oValue + '"';
	if (isSelected) o += " selected";
	o += '>' + oText + '</option>';
	return o;
}

function QS_select(sName, sOptions, oSelected)
{
	var o = '<select name="' + sName + '" style="' + QS_style["options"] + '">';
	if (!oSelected) o += QS_option("", "- Bestemming -", true);
	for (c = 0; c < sOptions.length; c++)
	{
		if (sOptions[c][0] == oSelected) o += QS_option(sOptions[c][0],sOptions[c][1],true);
		else o +=QS_option(sOptions[c][0],sOptions[c][1],false);
	}
	o += '</select>';
	return o;
}

var g_intDay, g_strMonthYear;

function QS_dd(strID, intDaysOffset)
{
	GenerateDate(intDaysOffset);

	var o = ('<select name="' + strID + '" onSubmit="CheckDate()" style="' + QS_style["options"] + '">');
	
	var intCount;
	for(intCount=1; intCount <= 31; intCount++)
	{
		o += ('<option value="' + intCount + '"');
		if (g_intDay == intCount)
			o += (' selected');
		o += ('>' + intCount + '</option>');
	}
	
	o += ('</select> ');
	return o;
}

/*
function QS_md(strID, intDaysOffset)	// herschreven - 2.03
{
	var o = ('<select name="' + strID + '" onSubmit="CheckDate()" style="' + QS_style["options"] + '">');
	var now = new Date();
    
    // year fix - 2.13
    if (now.getYear() < 1900) fixedyear = now.getYear() + 1900;
    else fixedyear = now.getYear();
    
	var curMonth = new Date(fixedyear,now.getMonth(),(now.getDate() + intDaysOffset));
    
    
	var monthNumber = 0;
	var strCurMonthYearValue = 0;
	for (intCount = 0; intCount < 13; intCount++)
	{
    	monthNumber = (curMonth.getMonth()) + intCount;
        
        yearNumber = (curMonth.getFullYear());
        
        
         if (monthNumber > 11)
		{
			monthNumber = 0;
			yearNumber++;
		}
        
		if (monthNumber < 9) strCurMonthYearValue = "0";
		else strCurMonthYearValue = "";
		strCurMonthYearValue += "" + (monthNumber+1) + "" + yearNumber + "";
		o += '<option value="' + strCurMonthYearValue + '"';

		if (monthNumber == now.getMonth() && yearNumber == now.getYear()) o += ' selected="selected"';

		o += ">" + QS_setup["monthnames"][monthNumber] + " " + yearNumber + "</option>";
        
       
	}
	o += ('</select>');
	return o;
}
*/


function QS_md(strID, intDaysOffset)
{
    var boolDesc = true;
    
    var o = ('<select name="' + strID + '">');
    
    var now = new Date();
    
    if (now.getYear() < 1900) fixedyear = now.getYear() + 1900;
    else fixedyear = now.getYear();
    
   
   
	var curMonth = new Date(fixedyear,now.getMonth(),(now.getDate() + intDaysOffset));
    
    if (curMonth.getYear() < 1900) curMonthYearFixed = curMonth.getYear() + 1900;
    else curMonthYearFixed = curMonth.getYear();
    
    
    
	var monthNumber = 0;
	var strCurMonthYearValue = 0;
     
    for (intCount = 0; intCount < 13; intCount++)
    {
        monthNumber = (now.getMonth()) + intCount;
        yearNumber = (now.getFullYear());
        
        if (monthNumber > 11)
        {
            monthNumber = monthNumber -= 12;
            yearNumber+=1;
        }
        
        if (monthNumber < 9) strCurMonthYearValue = "0";
        else strCurMonthYearValue = "";
        strCurMonthYearValue += "" + (monthNumber+1) + "" + yearNumber + "";
        
        o += '<option value="' + strCurMonthYearValue + '"';

        if (monthNumber == curMonth.getMonth() && yearNumber == curMonthYearFixed)
        {
            o += ' selected="selected"';
        }

        o += ">" + QS_setup["monthnames"][monthNumber] + " " + yearNumber + "</option>";
    }
    o += ('</select>');
    return o;
}


function QS_submit()
{
	document.forms["ATPQS"].submit();
}

function GenerateDate(intDaysOffset)
{
	var currentDate = new Date;
	g_intDay = currentDate.getDate() + intDaysOffset;
	currentDate.setDate(g_intDay);
	g_intDay = currentDate.getDate();
	g_strMonthYear = QS_setup["monthnames"][currentDate.getMonth()] + " " + currentDate.getFullYear();
	return currentDate;
}

preload_IMG('http://online.atp.nl/atpnl/images/wait_ani.gif',0)
preload_IMG('http://online.atp.nl/img/wachtscherm/image1.jpg',0)
preload_IMG('http://online.atp.nl/img/wachtscherm/image2.jpg',0)
preload_IMG('http://online.atp.nl/img/wachtscherm/image3.jpg',0)
preload_IMG('http://online.atp.nl/img/wachtscherm/image4.jpg',0)
preload_IMG('http://online.atp.nl/img/wachtscherm/image5.jpg',0)

function preload_IMG(imgname,dbgmode)
{
	try {
		plaatjes.length=plaatjes.length+1		
	} catch(e) {
		plaatjes = new Array()
	}
	plaatje=new Image()
	plaatje.src=imgname
	if (dbgmode) {
		// Document.write if for debugging purpose only
		document.write("<pre>Preloaded "+imgname+" in cache #"+plaatjes.length+"</pre>")
	}
}