// JavaScript Document

function show_more(showhide)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style1 = document.getElementById("show_more_options").style;
		var style2 = document.getElementById("more_options").style;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style1 = document.all["show_more_options"].style;
		var style2 = document.all["more_options"].style;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style1 = document.layers["show_more_options"].style;
		var style2 = document.layers["more_options"].style;
	}
	if (showhide == "show") {
		style1.display = "none";
		style2.display = "block";
	} else {
		style1.display = "block";
		style2.display = "none";
	}
}


function uncheck_all(form){
	form.anchorage.checked = false;
	form.denali.checked = false;
	form.seward.checked = false;
	form.talkeetna.checked = false;
	form.fairbanks.checked = false;
	showhide(form);
}

function uncheck_no_preference(form){
	form.all_towns.checked = false;
	showhide(form);
}	

function sort_tours(sort_by,asc_desc){
	form = document.tour_search
	show_updating()
	form.sort_by.value = sort_by
	form.asc_desc.value = asc_desc
	form.submit()
}

function showhide(form){
	show_updating()
	display_tours(form)
	setTimeout("hide_updating()",400);
}

function showhideinitial(form){
	//alert ("Triggered");
	display_tours(form)
}

function show_updating(){
	var updating_message = document.getElementById("updating_message");
	updating_message.style.display = "";
}

function hide_updating(){
	var updating_message = document.getElementById("updating_message");
	updating_message.style.display = "none";
}

function wait(milliseconds)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < milliseconds);
} 


function display_tours(form){
	var trip_length_min = eval(form.trip_length_min.options[form.trip_length_min.selectedIndex].value)
	var trip_length_max = eval(form.trip_length_max.options[form.trip_length_max.selectedIndex].value)

	var rows = document.getElementsByTagName("tr");
	var visible_results = 0;
	var city_code = "";  
	if (form.anchorage.checked){
		city_code += "A";
	}
	if (form.denali.checked){
		city_code += "D";
	}
	if (form.fairbanks.checked){
		city_code += "F";
	}
	if (form.seward.checked){
		city_code += "S";
	}
	if (form.talkeetna.checked){
		city_code += "T";
	}
	city_code = "-"+city_code+"-";
	
	for (var i = 0; i < rows.length; i++) {//
		var row = rows[i];
		if (row.id.indexOf('tour',0) > -1){

			// check trip length
			trip_length = false;
			n = eval(row.id.substring(row.id.lastIndexOf("N") + 1,row.id.lastIndexOf("N") + 2))
			if (trip_length_min <= n && trip_length_max >= n){
				trip_length = true;
				//alert("true:"+ eval(trip_length_min <= n)+"-"+eval(trip_length_max >= n))
			} else {
				//alert("false:"+ eval(trip_length_min <= n)+"-"+eval(trip_length_max >= n))
			}
			// check destinations
			destinations = false;	
			if (row.id.indexOf(city_code) > 0){
				destinations = true;
			}
			if (form.all_towns.checked > 0){
				destinations = true;
			}
			//alert(row.id+" "+dest_anc +" "+ dest_sew +" "+ dest_den +" "+ dest_tkt +" "+ dest_fai)

		// check style
			style = false;
			if (form.rental_car.checked && row.id.indexOf("C1") >= 0){
				style = true;
			} else if (form.coach_rail.checked && row.id.indexOf("C2") >= 0){
				style = true;
			} else if (form.group.checked && row.id.indexOf("C3") >= 0){
				style = true;
			} else if (form.small_group.checked && row.id.indexOf("C4") >= 0){
				style = true;
			} else if (form.pre_post.checked && row.id.indexOf("C5") >= 0){
				style = true;
			} 
			
			
		// check arrival
			arrival = false;
			if (form.arrive_air_anchorage.checked && row.id.indexOf("B1") >= 0){
				arrival = true;
			} else if (form.arrive_air_fairbanks.checked && row.id.indexOf("B2") >= 0){
				arrival = true;
			} else if (form.arrive_cruise_whittier.checked && row.id.indexOf("B3") >= 0){
				arrival = true;
			} else if (form.arrive_cruise_seward.checked && row.id.indexOf("B4") >= 0){
				arrival = true;
			}
			
		// check departure
			departure = false;
			if (form.depart_air_anchorage.checked && row.id.indexOf("E1") >= 0){
				departure = true;
			} else if (form.depart_air_fairbanks.checked && row.id.indexOf("E2") >= 0){
				departure = true;
			} else if (form.depart_cruise_whittier.checked && row.id.indexOf("E3") >= 0){
				departure = true;
			} else if (form.depart_cruise_seward.checked && row.id.indexOf("E4") >= 0){
				departure = true;
			} 
		
		// determine whether this tour meets criteria to be displayed
			if (trip_length && destinations && style && arrival && departure){
				row.style.display = "";
				visible_results++;
			} else {
				row.style.display = "none";
	  		}
			//if (i < 10){
			//	alert(trip_length +" "+ destinations  +" "+  style  +" "+  arrival  +" "+  departure)
			//}
		}
	}
	//alert(visible_results)
	if (visible_results < 1){
		row.style.display = "";
	} else {
		row.style.display = "none";
	}

}