
function DateToArray2(dateStr){
	// From D-M-Y to Y-M-D

	var dtArray = dateStr.split('-');
	
  return dtArray;
}




function GetTimeTable(){

 	var d1 = DateToArray2(document.f1.date1.value);
 	var d2 = DateToArray2(document.f1.date2.value);

	var myDateA = new Date(d1[2], d1[1]-1, d1[0], 12, 0);
 	var myDateB = new Date(d2[2], d2[1]-1, d2[0], 12, 0);

	thedayA = myDateA.getDay()
	thedayB = myDateB.getDay()
 	
//alert(myDateA +' : '+ myDateB);


	var routetype  = document.f1.routetype.value;
	var journeydir = document.f1.journeytype.value;

	routeArrayOut = new Array();
	routeArrayIn  = new Array();
	
	timeStrArrayA = new Array();
	timeStrArrayB = new Array();

	var timeStrArray = new Date();


	var routepoint = 4; // this determines at what point the route directions (select list) switch over (reverse direction)


	if(routetype>routepoint){
		journeydir = 1 
		
		// Swap route dates due to direction change
		var buff = thedayA;
		thedayA = thedayB;
		thedayB = buff;
		
		routetype = (routetype - routepoint)-1;
	}else
		journeydir = 0;


 //alert(routetype +' : '+ journeydir);
 
 //alert(thedayA +' : '+ thedayB);
 
 //alert(myDateA +' : '+ myDateB);
 



	switch(thedayA){ // OUTBOUND TIMETABLES
	

		default: // MAINLY MIDWEEK DAYS - Timetables
		
			// Dover - Boulogne  
			routeArrayOut[0]='0415,0745,1230,1645,1900,2215';
		
			// Portsmouth - Le Havre
  			routeArrayOut[1]='1200,2300';
  			
  			// Rosslare to Cherbourg
  			routeArrayOut[2]='-Saturdays only-';
  			
  			// Rosslare - Le Havre 
  			routeArrayOut[3]='-Saturdays only-';

  			// Newhaven to Dieppe
  			routeArrayOut[4]='0930,2230';
  		break;


		case 5: // Friday - Timetables
		
		 	// Dover - Boulogne  
			routeArrayOut[0]='0415,0745,1230,1645,1900,2215';
			
			// Portsmouth - Le Havre
  			routeArrayOut[1]='1200,2300';

  			// Rosslare to Cherbourg
  			routeArrayOut[2]='-Saturdays only-';
  			
  			// Rosslare - Le Havre 
  			routeArrayOut[3]='-Saturdays only-';
  			
  			// Newhaven to Dieppe
  			routeArrayOut[4]='0930,2230';
  		break;


  		case 6: // Saturday - Timetables
  		
  			// Dover - Boulogne  
			routeArrayOut[0]='0745,1045,1230,1900,2215';
  			
  			// Portsmouth - Le Havre
  			routeArrayOut[1]='1115,2300';
  			
  			// Rosslare to Cherbourg
  			routeArrayOut[2]='1800';
  			
  			// Rosslare - Le Havre 
  			routeArrayOut[3]='1745';
  			
  			// Newhaven to Dieppe
  			routeArrayOut[4]='0930';
  		break;


  		case 0: // Sunday - Timetables
  		
  			// Dover - Boulogne
			routeArrayOut[0]='0745,1045,1230,1900,2215';
			
			// Portsmouth - Le Havre
  			routeArrayOut[1]='2300';
  			
  			// Rosslare to Cherbourg
  			routeArrayOut[2]='-Saturdays only-';
  			
  			// Le Havre - Rosslare
			routeArrayOut[3]='-Sunday not available-';

  			// Newhaven to Dieppe
  			routeArrayOut[4]='0800,2230';
  		break;
  	}



	
	switch(thedayB){ // INBOUND TIMETABLES
	

		default: // MAINILY MIDWEEK DAYS - Timetables
		
			// Boulogne - Dover  
			routeArrayIn[0]='0430,0700,1045,1700,2030,2230';
			
			// Le Havre - Portsmouth
			routeArrayIn[1]='1700,2300';
			
  			// Cherbourg to Rosslare
  			routeArrayIn[2]='-Fridays only-';
			
			// Le Havre - Rosslare
  			routeArrayIn[3]='-Fridays only-';
  			
  			// Dieppe to Newhaven
  			routeArrayIn[4]='0500,1800';
  		break;


		case 5: // Friday - Timetables
		
			// Boulogne - Dover  
			routeArrayIn[0]='0430,0700,1045,1700,2030,2230';
  			
  			// Le Havre - Portsmouth
			routeArrayIn[1]='1700';
  			
  			// Cherbourg to Rosslare
  			routeArrayIn[2]='2200';

  			// Le Havre - Rosslare 
  			routeArrayIn[3]='2000';

  			// Dieppe to Newhaven
  			routeArrayIn[4]='0500,1800';
  		break;


  		case 6: // Saturday - Timetables
  		  			
			// Dover - Boulogne  
			routeArrayIn[0]='0900,1045,1700,2030,2230';
  			
  			// Le Havre - Portsmouth
			routeArrayIn[1]='1700,2300';

  			// Cherbourg to Rosslare
  			routeArrayIn[2]='-Fridays only-';

  			// Le Havre - Rosslare
  			routeArrayIn[3]='-Fridays only-';

  			// Dieppe to Newhaven
  			routeArrayIn[4]='0500,2000';
  		break;


  		case 0: // Sunday - Timetables
  		
  			// Dieppe - Newhaven
  			routeArrayIn[0]='0800,2230';
  			
  			// Le Havre - Portsmouth
			routeArrayIn[1]='1600,2300';

  			// Cherbourg to Rosslare
  			routeArrayIn[2]='-Fridays only-';

			// Le Havre - Rosslare
  			routeArrayIn[3]='-Fridays only-';

 			// Dieppe to Newhaven
  			routeArrayIn[4]='1800';
		break;
	}




//alert(theday + ': '+ routetype + ' = '+ routeArrayOut[routetype]);

if(journeydir=='0'){
	timeStrArrayA = routeArrayOut[routetype].split(',');
	timeStrArrayB = routeArrayIn[routetype].split(',');
}

if(journeydir=='1'){
	timeStrArrayB = routeArrayOut[routetype].split(',');
	timeStrArrayA = routeArrayIn[routetype].split(',');
}

	
var sizeA = timeStrArrayA.length;
var sizeB = timeStrArrayB.length;

document.f1.time1.options.length = 0;

for(i=0; i<sizeA; i++) {
    document.f1.time1.options[i] = new Option(timeStrArrayA[i], timeStrArrayA[i]);
    }

document.f1.time2.options.length = 0;

for(j=0; j<sizeB; j++) {
    document.f1.time2.options[j] = new Option(timeStrArrayB[j], timeStrArrayB[j]);
    }

}
