// JavaScript Document
var pointModel = new DynamicOptionList("countrylist","startpoint");

pointModel.forValue("Cyprus").addOptionsTextValue("Larnaca Airport (LCA)","3","Paphos Airport (PFO)","6","Limassol Port","5");
pointModel.forValue("Cyprus").setDefaultOptions("3");
pointModel.forValue("Egypt").addOptionsTextValue("Hurghada Airport (HRG)","11","Marsa Alam Airport (RMF)","13","Sharm El-Sheikh Airport (SSH)","12");
pointModel.forValue("Egypt").setDefaultOptions("12");
pointModel.forValue("France").addOptionsTextValue("Beauvais Airport (BVA)","2","Charles de Gaulle Airport (CDG)","1","Nice Airport (NCE)","1368","Orly Airport (ORY)","3");
pointModel.forValue("France").setDefaultOptions("1");
pointModel.forValue("Greece").addOptionsTextValue("Athens Airport (ATH)","1604","Chania Airport (CHQ)","1616","Corfu Airport (CFU)","2172","Heraklion Airport (HER)","1"
,"Kefalonia Airport (EFL)","3221","Kos Airport (KGS)","3522","Mytilene Airport (MJT)","1809","National Araxos Airport (GPA)","1692","Rhodes Airport (RHO)","1610","Santorini Airport (JTR)","4230","Thessaloniki Macedonia Airport (SKG)","1606","Zakynthos Airport (ZTH)","2983","Agios nikolaos Port","1663","Chania souda Port","1684","Corfu Port","2173","Heraklion Port","1617","Kos Port","3523","Mytilene Port","1810","Patras Port","1620","Piraeus Port","1618","Rethymno Port","1685","Rhodes Port","1683","Santorini Port","4231","Thessaloniki Port","1619","Zakynthos Port","2984");
pointModel.forValue("Greece").setDefaultOptions("1604");
pointModel.forValue("Italy").addOptionsTextValue("Alghero Airport (AHO)","1","Bergamo Airport (BGY)","9","Cagliari Elmas Airport (CAG)","2","Ciampino airport (CIA)","5","Fiumicino airport (FCO)","4","Milano Linate Airport (LIN)","7","Milano Malpensa Airport (MXP)","8","Olbia Costa Smeralda Airport (OLB)","3");
pointModel.forValue("Italy").setDefaultOptions("4");
pointModel.forValue("Malta").addOptionsTextValue("MALTA AIRPORT (MLA)","14");
pointModel.forValue("Malta").setDefaultOptions("14");
pointModel.forValue("Netherlands").addOptionsTextValue("Amsterdam Airport Schiphol (AMS)","10");
pointModel.forValue("Netherlands").setDefaultOptions("10");
pointModel.forValue("United Kingdom").addOptionsTextValue("Edinburgh Airport (EDI)","4769","Gatwick Airport (LGW)","2739","Heathrow Airport (LHR)","2738","London City Airport (LCY)","2741","Luton Airport (LTN)","2742","Manchester Airport (MAN)","4543","Stansted Airport (STN)","2740");
pointModel.forValue("United Kingdom").setDefaultOptions("4769");
pointModel.forValue("Spain").addOptionsTextValue("Barcelona Airport (BCN)","2635","Fuerteventura Airport (FUE)","1609","Gran Canaria Las Palmas Airport (LPA)","1231","Ibiza Airport (IBZ)","2018","Lanzarote Airport (ACE)","1698","Madrid Barajas Airport (MAD)","2243","Menorca Airport (MAH)","551","Palma de Mallorca Airport (PMI)","1","Tenerife Airport North Los Rodeos (TFN)","807","Tenerife Airport South Reina Sofia (TFS)","806","Fuerteventura Port Morro Jable","1610","Lanzarote Port Playa Blanca","1699","Las Palmas Port","1207","Mallorca Palma Port","2","Menorca Port Mahon","552","Tenerife Port Los Cristianos","809","Tenerife Port Santa Cruz","808");
pointModel.forValue("Spain").setDefaultOptions("1609");
pointModel.forValue("Turkey").addOptionsTextValue("Antalya Airport (AYT)","4","Ataturk Istanbul Airport (IST)","432","Bodrum Airport (BJV)","2","Dalaman Airport (DLM)","3","Esenboga Ankara Airport (ESB)","434","Izmir Airport (ADB)","1","Sabiha Gokcen Airport (SAW)","433","Bodrum port","869","Cesme port","911","Izmir Alsancak port","858","Karakoy port Istanbul","857","Kusadasi port","859","Marmaris port","875","Salipazari port","1060");
pointModel.forValue("Turkey").setDefaultOptions("432");


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 countryurl="";

                switch (countrybox.selectedIndex) {
                        case 1: countryurl = "http://www.cyprustaxireservations.com";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        case 2: countryurl = "http://www.bookyourtransfer.com";document.getElementById("usercode").value="mpyx";document.getElementById("showhome").value=""; break;
                        case 3: countryurl = "http://www.francetaxireservations.com";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        case 4: countryurl = "http://www.taxireservations.gr";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        case 5: countryurl = "http://www.bookyourtransfer.com";document.getElementById("usercode").value="mpyx";document.getElementById("showhome").value=""; break;
                        case 6: countryurl = "http://www.bookyourtransfer.com";document.getElementById("usercode").value="mpyx";document.getElementById("showhome").value=""; break;
						case 7: countryurl = "http://www.bookyourtransfer.com";document.getElementById("usercode").value="mpyx";document.getElementById("showhome").value=""; break;
                        case 8: countryurl = "http://www.spaintaxireservations.com";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        case 9: countryurl = "http://www.turkeytaxireservations.com";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        case 10: countryurl = "http://www.taxireservations.co.uk";document.getElementById("usercode").value="bytr4";document.getElementById("showhome").value="no"; break;
                        default: countryurl = "http://www.bookyourtransfer.com";
                }
                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.selectedIndex+"&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="We apologize - The entered destination cannot be found. <br>You can search again with different criteria (please use only the name eg.Hilton - not Hilton Hotel) <br> OR <br> use an AREA on the right as your destination. <br>Alternatively <a href='mailto:support@bookyourtransfer.com'>email us</a> your travel requirements and we will reply as soon as possible.";
                                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.selectedIndex+"&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.selectedIndex+"&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;
        document.getElementById("showareas").src='images/genarea.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";
        document.getElementById("showareas").src='images/genareaoff.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;
         }
}
