<!--

debug = "";

function getvarsdate(){
	dodates();
	
	offset = 4;
	
	daysarray = new Array("",31,28,31,30,31,30,31,31,30,31,30,31);
	
	leaparray = new Array("",31,29,31,30,31,30,31,31,30,31,30,31);

	months = new Array("Jan|1","Feb|2","Mar|3","Apr|4","May|5","Jun|6","Jul|7","Aug|8","Sep|9","Oct|10","Nov|11","Dec|12");
	
	y = 2004;
	
	while(y < todaysyear){
		y = y + 4;
	}
	
	nextleap = y;
		
	initialdate = todaysdate + offset;
		
	if(nextleap == todaysyear){
		initialarray = leaparray;
	}else{
		initialarray = daysarray;
	}
	
	if(initialdate > initialarray[todaysmonth]){
		initialmonth = todaysmonth+1;
		
		if(initialmonth > 12){
			initialyear = todaysyear+1;
			initialmonth = 1;
		}else{
			initialyear = todaysyear;
		}
		
		initialdate = (initialdate - initialarray[todaysmonth]);
				
	}else{
		initialmonth = todaysmonth;
		initialyear = todaysyear;
	}
}

function domonthsr(){
	getvarsdate();
	
	getmonth = document.fos.monthr;	
	getdate = document.fos.dater;
	
	getdate.options.length = 0;	
	
	if(nextleap == todaysyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}	
	
	n = (getmonth.options.selectedIndex+1);
	
	for (i = 1; i <= populatearray[n]; i++){
		getdate.options[getdate.options.length] = new Option(i, i, false, false);
	}
}

function doyearsr(selectedyear){
	getvarsdate();
	
	getyear = document.fos.yearr;

	getdate = document.fos.dater;

	getdate.options.length = 0;	
	
	if(nextleap == selectedyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}	

	n = (getmonth.options.selectedIndex+1);
	
	for (i = 1; i <= populatearray[n]; i++){
		getdate.options[getdate.options.length] = new Option(i, i, false, false);
	}	
}

function domonthso(){
	getvarsdate();
	
	getmonth = document.fos.montho;	
	getdate = document.fos.dateo;
	
	getdate.options.length = 0;	
	
	if(nextleap == todaysyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}	
	
	n = (getmonth.options.selectedIndex+1);
	
	for (i = 1; i <= populatearray[n]; i++){
		getdate.options[getdate.options.length] = new Option(i, i, false, false);
	}
	
	getmonthr = document.fos.monthr;
	getdater = document.fos.dater;
	
	if(getmonthr != getmonth){
		getmonthr.options.selectedIndex = getmonth.options.selectedIndex;
	}
	
	getdater.options.length = 0;	
	
	n = (getmonthr.options.selectedIndex+1);
	
	for (i = 1; i <= populatearray[n]; i++){
		getdater.options[getdater.options.length] = new Option(i, i, false, false);
	}
}

function doyearso(selectedyear){
	getvarsdate();
	
	getdate = document.fos.dateo;
	
	getyear = document.fos.yearo;
	
	getdate.options.length = 0;	
	
	if(nextleap == selectedyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}	

	n = (getmonth.options.selectedIndex+1);
	
	for (i = 1; i <= populatearray[n]; i++){
		getdate.options[getdate.options.length] = new Option(i, i, false, false);
	}	
}


function popdatesr(){
	getvarsdate();
	
	getmonth = document.fos.monthr;	
	
	getmonth.options.length = 0
	
	for(i = 0; i < months.length; i++){
		
		if(initialmonth == (i+1)){
			getmonth.options[getmonth.options.length] = new Option(months[i].split("|")[0], months[i].split("|")[1], false, true);
		}else{
			getmonth.options[getmonth.options.length] = new Option(months[i].split("|")[0], months[i].split("|")[1], false, false);
		}
	}
	
	getdate = document.fos.dater;
	
	getdate.options.length = 0

	if(nextleap == initialyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}

	for(i = 1; i <= populatearray[initialmonth]; i++){
		if(initialdate == i){
			getdate.options[getdate.options.length] = new Option(i, i, false, true);
		}else{
			getdate.options[getdate.options.length] = new Option(i, i, false, false);
		}
	}	
	
	getyear = document.fos.yearr;
	
	getyear.options.length = 0;
	
	for(i = 0; i < maxyears; i++){
		if(initialyear == (initialyear + i)){
			getyear.options[getyear.options.length] = new Option((initialyear+i), (initialyear+i), false, true);
		}else{
			getyear.options[getyear.options.length] = new Option((initialyear+i), (initialyear+i), false, false);
		}
	}
}

function popdateso(){
	getvarsdate();
	
	getmonth = document.fos.montho;	
	
	getmonth.options.length = 0
	
	for(i = 0; i < months.length; i++){
		
		if(initialmonth == (i+1)){
			getmonth.options[getmonth.options.length] = new Option(months[i].split("|")[0], months[i].split("|")[1], false, true);
		}else{
			getmonth.options[getmonth.options.length] = new Option(months[i].split("|")[0], months[i].split("|")[1], false, false);
		}
	}
	
	getdate = document.fos.dateo;
	
	getdate.options.length = 0

	if(nextleap == initialyear){ 
		populatearray = leaparray;
	}else{
		populatearray = daysarray;
	}

	for(i = 1; i <= populatearray[initialmonth]; i++){
		if(initialdate == i){
			getdate.options[getdate.options.length] = new Option(i, i, false, true);
		}else{
			getdate.options[getdate.options.length] = new Option(i, i, false, false);
		}
	}	
	
	getyear = document.fos.yearo;
	
	getyear.options.length = 0;
	
	for(i = 0; i < maxyears; i++){
		if(initialyear == (initialyear + i)){
			getyear.options[getyear.options.length] = new Option((initialyear+i), (initialyear+i), false, true);
		}else{
			getyear.options[getyear.options.length] = new Option((initialyear+i), (initialyear+i), false, false);
		}
	}
}

function doway(displayr){	
	if(displayr == 1){
		document.fos.dater.disabled = true;	
		document.fos.monthr.disabled = true;	
		document.fos.yearr.disabled = true;	
	}else{
		document.fos.dater.disabled = false;	
		document.fos.monthr.disabled = false;	
		document.fos.yearr.disabled = false;	
	}
}

function loadup(){
	popdateso();	
	popdatesr();
}

function val(get){
	// Validate form submission
	// passing .this to the get variable in this function to refer to the form as a whole.
	
	// Need to validate the date...

	getvarsdate();

	outboundyear = get.yearo.value;
	outboundmonth = get.montho.value;
	outbounddate = get.dateo.value;
	returnyear = get.yearr.value;
	returnmonth = get.monthr.value;
	returndate = get.dater.value;
	
	fail = 0;
	msg = "";

	if(get.dp.selectedIndex == 0){
		msg = "Please select a departure point";
		fail = 1;
	}
	
	if((get.ds.selectedIndex == 0) && (fail != 1)){
		msg = "Please select a destination";
		fail = 1;
	}	


	if((initialyear == outboundyear) && (fail != 1)){
		if(outboundmonth <= initialmonth){
			if(outbounddate < initialdate){
				msg = "Please check your departure date, it appears incorrect";	
				fail = 1;				
			}
		}
	}
	
	if((initialyear == returnyear) && (fail != 1)){
		if(returnmonth <= initialmonth){
			if(returndate < initialdate){
				msg = "Please check your return date, it appears incorrect";	
				fail = 1;				
			}
		}
	}
		
		
		
	if((get.owy.checked == false) && (fail == 0)){
		if(returnyear < outboundyear){			
			fail = 1;
			msg = "Your return date cannot be before your departure, please correct and try again 1";
		}
		
		if(returnyear == outboundyear){
			// force it to treat the variables as ints as it appears to struggle.
			
			if((12 - outboundmonth) < (12 - returnmonth)){
				fail = 1;
				msg = "Your return date cannot be before your departure, please correct and try again 2";
			}
		}
		
		if((returnyear == outboundyear) && (returnmonth == outboundmonth)){
			if((31 - outbounddate) < (31 - returndate)){				
				fail = 1;
				msg = "Your return date cannot be before your departure, please correct and try again 3";
			}
		}
	}
	
	if(fail == 1){
			alert(msg);
			return false;
	}
}
// -->