// JavaScript Document
var pointModel = new DynamicOptionList("countrylist","startpoint");

pointModel.forValue("Austria").addOptionsTextValue("Wien Flughafen (VIE)","5758","Salzburg Flughafen (SZG)","5759");
pointModel.forValue("Austria").setDefaultOptions("5758");

pointModel.forValue("Belgium").addOptionsTextValue("Brussel Flughafen (BRU)","4993","Brussel South Charleroi Flughafen (CRL)","4994");
pointModel.forValue("Belgium").setDefaultOptions("4993");

pointModel.forValue("Bulgaria").addOptionsTextValue("Sofia Flughafen (SOF)","8386");
pointModel.forValue("Bulgaria").setDefaultOptions("8386");

pointModel.forValue("Romania").addOptionsTextValue("Bukarest Baneasa Flughafen (BBU)","8553","Bukarest Otopeni Flughafen (OTP)","8554");
pointModel.forValue("Romania").setDefaultOptions("8553");

pointModel.forValue("Serbia").addOptionsTextValue("Belgrad Flughafen (BEG)","8633");
pointModel.forValue("Serbia").setDefaultOptions("8633");

pointModel.forValue("Croatia").addOptionsTextValue("Dubrovnik Flughafen (DBV)","6052","Osijek Flughafen (OSI)","6057","Split Flughafen (SPU)","6055","Zadar Flughafen (ZAD)","6054","Zagreb Flughafen (ZAG)","6056","Dubrovnik Hafen","6053");
pointModel.forValue("Croatia").setDefaultOptions("6052");

pointModel.forValue("Cyprus").addOptionsTextValue("Larnaca Flughafen (LCA)","3","Paphos Flughafen (PFO)","6","Limassol Hafen","5");
pointModel.forValue("Cyprus").setDefaultOptions("3");

pointModel.forValue("Israel").addOptionsTextValue("Tel Aviv Flughafen (LCA)","7620");
pointModel.forValue("Israel").setDefaultOptions("7620");

pointModel.forValue("Egypt").addOptionsTextValue("Kairo Flughafen (CAI)","15","Hurghada Flughafen (HRG)","11","Marsa Alam Flughafen (RMF)","13","Sharm El-Sheikh Flughafen (SSH)","12");

pointModel.forValue("Egypt").setDefaultOptions("12");

pointModel.forValue("France").addOptionsTextValue("Beauvais Flughafen (BVA)","2","Charles de Gaulle Flughafen (CDG)","1","Nizza Flughafen (NCE)","1368","Orly Flughafen (ORY)","3");
pointModel.forValue("France").setDefaultOptions("1");

pointModel.forValue("Germany").addOptionsTextValue("Berlin Tegel Flughafen (TXL)","7510","Berlin Schoenefeld Flughafen (SFX)","7496","Dusseldorf Flughafen (DUS)","6490","Frankfurt Flughafen (FRA)","7014","Hamburg Flughafen (HAM)","Hannover Flughafen(HAJ)","7735","6700","Munchen Flughafen (MUC)","6333","Stuttgart Flughafen (STR)","6820");
pointModel.forValue("Germany").setDefaultOptions("7510");

pointModel.forValue("Greece").addOptionsTextValue("Alexandroupolis Flughafen (AXD)","4528","Athen Flughafen (ATH)","1604","Chania Flughafen (CHQ)","1616","Chios Flughafen (JKH)","4500","Korfu Flughafen (CFU)","2172","Heraklion Flughafen (HER)","1","Kefalonia Flughafen (EFL)","3221","Kos Flughafen (KGS)","3522","Mykonos Flughafen (JMK)","4658","Mytilene Flughafen (MJT)","1809","National Araxos Flughafen (GPA)","1692","Paros Flughafen (PAS)","4430","Rhodos Flughafen (RHO)","1610","Samos Flughafen (SMI)","4475","Santorin Flughafen (JTR)","4230","Thessaloniki Macedonia Flughafen (SKG)","1606","Zakynthos Flughafen (ZTH)","2983","Agios Nikolaos Hafen","1663","Chania Souda Hafen","1684","Chios Hafen","4659","Korfu Hafen","2173","Heraklion Hafen","1617","Kos Hafen","3523","Mykonos Neuer Hafen Tourlos","4647","Mykonos Alter Hafen Chora","4648","Mytilene Hafen","1810","Patras Hafen","1620","Piraeus Hafen","1618","Rethymno Hafen","1685","Rhodos Hafen","1683","Samos Hafen","4660","Santorin Hafen","4231","Paros Hafen Parikia","4429","Thessaloniki Hafen","1619","Zakynthos Hafen","2984");
pointModel.forValue("Greece").setDefaultOptions("1604");

pointModel.forValue("Italy").addOptionsTextValue("Alghero Flughafen (AHO)","1","Bergamo Flughafen (BGY)","9","Cagliari Elmas Flughafen (CAG)","2","Ciampino Flughafen (CIA)","5","Fiumicino Flughafen (FCO)","4","Milano Linate Flughafen (LIN)","7","Milano Malpensa Flughafen (MXP)","8","Olbia Costa Smeralda Flughafen (OLB)","3","Venedig Flughafen Marco Polo (VCE)","2122","Venedig Flughafen Treviso (TSF)","2116","Verona Flughafen (VRN)","2137");
pointModel.forValue("Italy").setDefaultOptions("4");

pointModel.forValue("Malta").addOptionsTextValue("Malta Flughafen (MLA)","14");
pointModel.forValue("Malta").setDefaultOptions("14");

pointModel.forValue("Hungary").addOptionsTextValue("Budapest Flughafen Ferihegy (BUD)","5282");
pointModel.forValue("Hungary").setDefaultOptions("5282");

pointModel.forValue("CzechRepublic").addOptionsTextValue("Flughafen Prag Ruzyne (PRG)","4221");
pointModel.forValue("CzechRepublic").setDefaultOptions("4221");

pointModel.forValue("Morocco").addOptionsTextValue("Marrakech Menara Flughafen (RAK)","16","Casablanca Mohammed V Flughafen (CMN)","3124","Agadir Al Massira Flughafen (AGA)","3123");
pointModel.forValue("Morocco").setDefaultOptions("16");

pointModel.forValue("Russia").addOptionsTextValue("Moskau Domodedovo Flughafen (DME)","7869","Moskau Sheremetevo Flughafen (SVO)","7868","Moskau Vnukovo Flughafen (VKO)","7870", "Sankt Petersburg Flughafen (LED)", "8147");
pointModel.forValue("Russia").setDefaultOptions("7869");

pointModel.forValue("Tunisia").addOptionsTextValue("Tunis Karthago Flughafen (TUN)","17","Monastir Flughafen (MIR)","18","Enfidha Flughafen (TUN)","19");
pointModel.forValue("Tunisia").setDefaultOptions("17");

pointModel.forValue("Netherlands").addOptionsTextValue("Amsterdam Flughafen Schiphol (AMS)","10");
pointModel.forValue("Netherlands").setDefaultOptions("10");

pointModel.forValue("Poland").addOptionsTextValue("Warschau Flughafen (WAW)","9545");
pointModel.forValue("Poland").setDefaultOptions("9545");

pointModel.forValue("Portugal").addOptionsTextValue("Faro Flughafen (FAO)","3673","Lissabon Portela Flughafen (LIS)","3544","Madeira Flughafen (FNC)","3332","Porto Flughafen (OPO)","3788","Faro Hafen","3674","Lisbon Hafen","3545","Madeira Funchal Hafen","3789");
pointModel.forValue("Portugal").setDefaultOptions("3673");

pointModel.forValue("UK").addOptionsTextValue("Edinburgh Flughafen (EDI)","4769","Gatwick Flughafen (LGW)","2739","Heathrow Flughafen (LHR)","2738","London City Flughafen (LCY)","2741","Luton Flughafen (LTN)","2742","Manchester Flughafen (MAN)","4543","Stansted Flughafen (STN)","2740");
pointModel.forValue("UK").setDefaultOptions("2739");

pointModel.forValue("Slovakia").addOptionsTextValue("Bratislava Flughafen (BTS)","4775");
pointModel.forValue("Slovakia").setDefaultOptions("4775");

pointModel.forValue("Spain").addOptionsTextValue("Alicante Flughafen (ALC)","2745","Barcelona Flughafen (BCN)","2635","Fuerteventura Flughafen (FUE)","1609","Gran Canaria Las Palmas Flughafen (LPA)","1231","Ibiza Flughafen (IBZ)","2018","Lanzarote Flughafen (ACE)","1698","Madrid Barajas Flughafen (MAD)","2243","Malaga Flughafen (AGP)","2912","Menorca Flughafen (MAH)","551","Palma de Mallorca Flughafen (PMI)","1","Teneriffa Nord Los Rodeos Flughafen (TFN)","807","Teneriffa Sued Reina Sofia Flughafen (TFS)","806","Fuerteventura Hafen Morro Jable","1610","Ibiza Hafen Eivissa","2017","Lanzarote Hafen Playa Blanca","1699","Las Palmas Hafen","1207","Mallorca Palma Hafen","2","Menorca Hafen Mahon","552","Teneriffa Hafen Los Cristianos","809","Teneriffa Hafen Santa Cruz","808");
pointModel.forValue("Spain").setDefaultOptions("1609");

pointModel.forValue("Turkey").addOptionsTextValue("Antalya Flughafen (AYT)","4","Ataturk Istanbul Flughafen (IST)","432","Bodrum Flughafen (BJV)","2","Dalaman Flughafen (DLM)","3","Esenboga Ankara Flughafen (ESB)","434","Izmir Flughafen (ADB)","1","Sabiha Gokcen Flughafen (SAW)","433","Bodrum Hafen","869","Cesme Hafen","911","Izmir Alsancak Hafen","858","Karakoy Hafen Istanbul","857","Kusadasi Hafen","859","Marmaris Hafen","875","Salipazari Hafen","1060");
pointModel.forValue("Turkey").setDefaultOptions("432");

pointModel.forValue("Ukraine").addOptionsTextValue("Donetsk Flughafen (DOK)","8243","Kiew Boryspil Flughafen (KBP)","8244","Kiew Zhuliany Flughafen (IEV)","8245","Odessa Flughafen (ODS)","8246","Simferopol Flughafen (SIP)","8247","Odessa Hafen","9417","Sevastopol Hafen","9418");
pointModel.forValue("Ukraine").setDefaultOptions("8243");

pointModel.forValue("UAE").addOptionsTextValue("Dubai Flughafen (DXB)","4690","Abu Dhabi Flughafen (AUH)","4691","Dubai Hafen Rashid","4692");
pointModel.forValue("UAE").setDefaultOptions("4690");

pointModel.forValue("USA").addOptionsTextValue("New York John F Kennedy Flughafen (JFK)","9089","New York LaGuardia Flughafen (LGA)","9090","New York Newark Flughafen (EWR)","9091","Reagan National Flughafen (DCA)","9320","Dulles International Flughafen (IAD)","9319","Baltimore Washington International Flughafen (BWI)","9318");
pointModel.forValue("USA").setDefaultOptions("9089");


function submitform (pa) {
    var countrybox = document.getElementById("countrylist");
    var startpointbox = document.getElementById("startpoint");
        if (pa==1){
                var endpointbox = document.getElementById("selendpoint");
        }else{
                var endpointbox = document.getElementById("arealist");
        }

        if (countrybox.selectedIndex<0) {
                alert("Please select country");
                return false;
        }

        if (endpointbox.selectedIndex<0) {
                alert("Please select destination");
                return false;
        }

        if (startpointbox.selectedIndex<0) {
                alert("Please select airport or port");
                return false;
        }else{

                document.getElementById("endpoint").value=endpointbox.value;
				var spointl = document.getElementById("startpoint");
				//change start and end point based on direction
				if (dirflag==1){
					document.getElementById("endpoint").value=endpointbox.value;
				}else{
					document.getElementById("endpoint").value=document.getElementById("startpoint").value;
					spointl.options[spointl.selectedIndex].value=endpointbox.value;
				}
				
                var countryurl="";

                switch (countrybox.options[countrybox.selectedIndex].value) {
					    case "Cyprus": countryurl = "http://www.cyprustaxireservations.com";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
                        case "France": countryurl = "http://www.francetaxireservations.com";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
						case "Greece": countryurl = "http://www.taxireservations.gr";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
                        case "Spain": countryurl = "http://www.spaintaxireservations.com";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
						case "Turkey": countryurl = "http://www.turkeytaxireservations.com";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
						case "UK": countryurl = "http://www.taxireservations.co.uk";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
						default: countryurl = "http://www.bookyourtransfer.com";document.getElementById("usercode").value="bytrge4";document.getElementById("showhome").value="no"; break;
                }
                document.formpoint.action =     countryurl + "/sdp.action";
        }


        document.formpoint.submit();
}


function getPoint(searchp,box) {

        var pointname = searchp.value;
        var countrybox = document.getElementById("countrylist");

		//pass initial airport selection
		var selsrcpointbox=document.getElementById("startpoint");
		if (selsrcpointbox.selectedIndex<0){
			alert("Please select start location");
			return false;
		}
		
          dojo.io.bind({
          // URL -  destination you want to send your request
          url: "reqinfo.php?action=searchpoint&startpointid="+selsrcpointbox.options[selsrcpointbox.selectedIndex].value +"&cid="+ countrybox.options[countrybox.selectedIndex].value+"&pointname=" + pointname ,

          // Callback function that will be invoked asynchronously
          load: function(type, data, evt){ processRequest(data,box);},
          // Type of data you want to receive
          mimetype: "text/xml"
    });

}

function processRequest(data,box) {

            //var message = dojo.dom.textContent(data.getElementsByTagName("fare")[0]);
                        document.getElementById("nopoint").innerHTML="";
                        var points = data.getElementsByTagName('id').length;
                        box.length=0;
                        for (i=0;i<points;i++){
                                var root_node = data.getElementsByTagName('id')[i];
                                var nameTextNode = root_node.childNodes[0];

                                var descNode=data.getElementsByTagName('description')[i];
                                var desc = descNode.childNodes[0];
                                box.options[box.options.length] = new Option(desc.nodeValue,nameTextNode.nodeValue);
                        }
                        if (points==0){
                                document.getElementById("nopoint").innerHTML="Bitte Entschuldigen Sie - Das von Ihnen eingegebene Ziel kann nicht gefunden werden. <br>Bitte versuchen es erneut mit einem anderen Kriterium ( nur Name des Hotels wie z.B Hilton - nicht Hilton Hotel) <br> ODER <br> benutzen Sie den Bezirk, rechts zu finden als Ihr Ziel. <br>Alternativ schicken Sie uns eine <a href='mailto:support@bookyourtransfer.com'>Email</a> mit Ihren Anforderungen und wir antworten Ihnen so schnell wie moeglich.";
                                document.getElementById("pointinfodesc").innerHTML="";
                                document.getElementById("pointnfodiv").innerHTML="";
                        }



}

function processFareRequest(data,v1,v2) {

            var fare = dojo.dom.textContent(data.getElementsByTagName("price")[0]);
                        if (fare>0){

                                //document.forms["selectdestpointform"].submit();
                                //output the link http://www.taxireservations.co.uk/SelectDestPoint.action?lang=en&usercode=lndt1&startpoint=2738&endpoint=2739&regions=1&showhome=2
                                document.getElementById("mytextlink").value ="http://www.bookyourtransfer.com/sdp.action?lang=en&usercode="+ document.getElementById("usercode").value +"&startpoint="+ v1 +"&endpoint="+ v2 +"&showhome=2&aid=" + document.getElementById("aid").value ;

                        }else{
                                alert("The route is not supported");
                        }

}

function getAreas(searchp,box) {

        var pointid = searchp.value;
    var countrybox = document.getElementById("countrylist");

          dojo.io.bind({
          // URL -  destination you want to send your request
          url: "reqinfo.php?action=getareas&cid="+ countrybox.options[countrybox.selectedIndex].value+"&startpointid=" + pointid ,
                 
          // Callback function that will be invoked asynchronously
          load: function(type, data, evt){ processAreaRequest(data,box);},
          // Type of data you want to receive
          mimetype: "text/xml"
    });

}

function processAreaRequest(data,box) {

            //var message = dojo.dom.textContent(data.getElementsByTagName("fare")[0]);
                        var points = data.getElementsByTagName('id').length;
                        box.length=0;
                        for (i=0;i<points;i++){
                                var root_node = data.getElementsByTagName('id')[i];
                                var nameTextNode = root_node.childNodes[0];

                                var descNode=data.getElementsByTagName('description')[i];
                                var desc = descNode.childNodes[0];
                                box.options[box.options.length] = new Option(desc.nodeValue,nameTextNode.nodeValue);
                        }

}

function pointinfo(box) {
	
	var countrybox = document.getElementById("countrylist");
	var pointsel = box.options[box.selectedIndex].value;
	
	dojo.io.bind({
          // URL -  destination you want to send your request
          url: "reqinfo.php?action=pointinfo&cid="+ countrybox.options[countrybox.selectedIndex].value+"&endpointid=" + pointsel ,
                 
          // Callback function that will be invoked asynchronously
          load: function(type, data, evt){ processPointIRequest(data);},
          // Type of data you want to receive
          mimetype: "text/xml"
    });
	
}

function processPointIRequest(data) {
	
			var pointname_node = data.getElementsByTagName('name')[0];				
			var point = pointname_node.childNodes[0].nodeValue; 
			
			var address_node = data.getElementsByTagName('street')[0];
			var street = "";
			var addresschild = address_node.childNodes[0];
			if(addresschild != null){
				street = addresschild.nodeValue;
			}
			var streetno_desc = data.getElementsByTagName('streetno')[0];
			var streetno = "";
			var streetnochild = streetno_desc.childNodes[0];
			if( streetnochild != null){
				streetno = streetnochild.nodeValue;
			}

			if(streetno=="null"){
				streetno="";
			}

			var loc_node = data.getElementsByTagName('postcode')[0];
			var postcode = loc_node.childNodes[0].nodeValue;
			
			var area_desc = data.getElementsByTagName('area')[0];
			var area = "";
			var areachild = area_desc.childNodes[0];
			if(areachild != null){
				area = areachild.nodeValue;
			}

			if(area=="null"){
				area="";
			}

			point+="<br>" + streetno + "&nbsp;" + street + "<br>postcode " + postcode + "&nbsp;" + area;		
			document.getElementById("pointnfodiv").innerHTML=point;
			document.getElementById("pointinfodesc").innerHTML=infdesc;			
	
    
}

function nexta(){
        document.formpoint.secstepb.disabled=true;
        document.formpoint.endpointbt.disabled=true;
        document.formpoint.btareanext.disabled=true;
        document.formpoint.endpointbt.disabled=false;
        document.getElementById("showareas").disabled=false;
		if (dirflag==1){
        	document.getElementById("showareas").src='images/genarea.jpg';
		}else{
			document.getElementById("showareas").src='images/genarear.jpg';
		}

        document.getElementById("pointnfodiv").innerHTML="";
        document.getElementById("pointinfodesc").innerHTML="";
        document.getElementById("destadivinit").className="";
        document.getElementById("destbdivinit").className="";
}

function airchange(){
        document.formpoint.secstepb.disabled=false;
        document.formpoint.endpointbt.disabled=true;
        document.formpoint.btareanext.disabled=true;
        document.formpoint.btpointnext.disabled=true;

        //clear all lists
        document.formpoint.selendpoint.options.length = 0;
        document.formpoint.arealist.options.length = 0;
        document.getElementById("pointnfodiv").innerHTML="";
        document.getElementById("pointinfodesc").innerHTML="";

        document.getElementById("generalareaoffdiv").style.display="block";
        document.getElementById("generalareadiv").style.display="none";
		 
		if (dirflag==1){
			document.getElementById("showareas").src='images/genareaoff.jpg';
		}else{
			document.getElementById("showareas").src='images/genareaoffr.jpg';
		}
		
        document.getElementById("showareas").disabled=true;
        document.getElementById("destadivinit").className="transON";
        document.getElementById("destbdivinit").className="transON";
		document.getElementById("endloc").value="";
		document.getElementById("nopoint").innerHTML="";
}

function gotopoint(){
        document.formpoint.btpointnext.disabled=false;
}

function gotoarea(){
        document.formpoint.btareanext.disabled=false;
}

function setValue(box,sel){

        var val = box.options[box.selectedIndex].value;
        if (sel==1){
                document.getElementById('startpoint').value=val;
        }else{
                document.getElementById('endpoint').value=val;
        }
}

function showgenarea(){

        document.getElementById("generalareaoffdiv").style.display="none";
        document.getElementById("generalareadiv").style.display="block";
        return false;
}


function clicksearch(event) {
                if (typeof event == "undefined"){
                        event = window.event;
                }

                var val = event.keyCode;
                if(val == 13){
                        var s=document.getElementById('endloc');
                        var b=document.getElementById('selendpoint');
                        getPoint(s,b);
                        //document.getElementById('endpointbt').click();
                        return false;
                }

}

function disableEnterKey(e)
{
     var key;

     if(window.event){
          key = window.event.keyCode;     //IE
         }
     else{
          key = e.which;     //firefox
         }

     if(key == 13){
          return false;
         }
     else{
          return true;
         }
}

