// JavaScript Document



function resetdrops(){
		step2.length = 0;
		months.length = 0;
		step3.length = 0;
		locations.length = 0;
		temploc = "";
		ClearOptions("pickdate");
		ClearOptions("pickloc");
		ClearOptions("pickridetype");
		
		addOption(document.getElementById("pickridetype"), "Choose a Ride Type", "x");
		addOption(document.getElementById("pickridetype"), "Cross Country", "xcountry");
		addOption(document.getElementById("pickridetype"), "Downhill", "downhill");
		addOption(document.getElementById("pickridetype"), "Both XC and DH", "both");
		addOption(document.getElementById("pickridetype"), "Any Ride Type", "any");
		
		document.getElementById("pickdate").style.display = "none";
		document.getElementById("pickloc").style.display = "none";
			}
			
			function toflash1(arg1, arg2) {
				if(arg2.value != "x"){
  					var swf = document.getElementById("terminalboard");
  					swf.flboard(arg1,arg2.value);
				}
			}
			
			function toflash2() {
  					var swf = document.getElementById("terminalboard");
  					swf.flboard2(document.getElementById('pickridetype').value, (document.getElementById('pickdate').value));
			}
			
			function toflash3() {
  					var swf = document.getElementById("terminalboard");
  					swf.flboard3(document.getElementById('pickridetype').value, document.getElementById('pickdate').value, document.getElementById('pickloc').value);
			}
			
			function enableresetbut() {
				document.getElementById("resetbut").disabled = false;
				document.getElementById("disableresetbut").style.display = "none";
			}
			
			function disableresetbut() {
				document.getElementById("resetbut").disabled = true;
				document.getElementById("disableresetbut").style.display = "block";
			}
			
			function enablegotobut() {
				document.getElementById("gotobut").disabled = false;
				document.getElementById("disablegotobut").style.display = "none";
			}
			
			function disablegotobut() {
				document.getElementById("gotobut").disabled = true;
				document.getElementById("disablegotobut").style.display = "block";
			}

var hols = new Array();
var months = new Array();
var step2 = new Array();
var step3 = new Array();
var locations = new Array();

function extrauber(whichbut){
	var d = document.getElementById(whichbut);
	d.className = "uberlink";	
}

function jsAlert(message){
	document.getElementById("poptest").style.display = "block";
	//TINY.box.show('tinybox/advanced.html',1,800,600,1);
}

function showpop(myname){
	document.getElementById(myname).style.display = "block";
	if(myname == "tripplan"){
		resetdrops();	
	}
}

function hidepop(myname){
	document.getElementById(myname).style.display = "none";
}

function jsHide(){
	document.getElementById("poptest").style.display = "none";
}

function loadextsite(whichurl){
	document.getElementById("extpopcontent").src = whichurl;
}

function ClearOptions(id){
	document.getElementById(id).options.length = 0;
}

function getmonthname(monthnum){
	
	switch(monthnum)
{
case '01':
  return "January";
  break;
case '02':
  return "February";
  break;
case '03':
  return "March";
  break;
case '04':
  return "April";
  break;
case '05':
  return "May";
  break;
case '06':
  return "June";
  break;
case '07':
  return "July";
  break;
case '08':
  return "August";
  break;
case '09':
  return "September";
  break;
case '10':
  return "October";
  break;
case '11':
  return "Novemeber";
  break;
case '12':
  return "December";
  break;s
}
	
/*	var monthnames = new Array();
   	monthnames[1]  = "January";
	monthnames[2]  = "February";
	monthnames[3]  = "March";
	monthnames[4]  = "April";
	monthnames[5]  = "May";
	monthnames[6]  = "June";
	monthnames[7]  = "July";
	monthnames[8]  = "August";
	monthnames[9]  = "September";
	monthnames[10]  = "October";
	monthnames[11] = "November";
	monthnames[12] = "December";
	return monthnames[monthnum];*/
}

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function sortASC(a, b){ return (a-b); }

Array.prototype.unique = function () {
	var r = new Array();
	o:for(var i = 0, n = this.length; i < n; i++)
	{
		for(var x = 0, y = r.length; x < y; x++)
		{
			if(r[x]==this[i])
			{
				continue o;
			}
		}
		r[r.length] = this[i];
	}
	return r;
}

function selectrt(whichrt){
	
	if(whichrt.value != "x"){
		
		if(document.getElementById("pickridetype").options[0].value == "x"){
			document.getElementById("pickridetype").remove(0);
		}
	
		step2.length = 0;
		months.length = 0;
		step3.length = 0;
		locations.length = 0;
		temploc = "";
		ClearOptions("pickdate");
		ClearOptions("pickloc");
		
		if(whichrt.value == "both"){
			for (i=0;i<hols.length;i++){
				if((hols[i].dh == "yes") && (hols[i].xc == "yes")){
					step2.push(hols[i]);
				}
			}
		} else if(whichrt.value == "any"){
			for (i=0;i<hols.length;i++){
					step2.push(hols[i]);
			}
		} else if(whichrt.value == "xcountry"){
			for (i=0;i<hols.length;i++){
				if(hols[i].xc == "yes"){
					step2.push(hols[i]);
				}
			}
		} else if(whichrt.value == "downhill"){
			for (i=0;i<hols.length;i++){
				if(hols[i].dh == "yes"){
					step2.push(hols[i]);
				}
			}
		}
		//if(step2.length > 0){
			for(j=0;j<step2.length;j++){
				
				var mytempmonths = step2[j].months.split(",");
				
				for(k=0;k<mytempmonths.length;k++){
					months.push((mytempmonths[k]));
				}
						
				//for(k=step2[j].startmonth;k<=step2[j].endmonth;k++){
				//	months.push(k);
				//}
			}
			
			
			
			months = months.unique();
			months.sort(sortASC);
			
			addOption(document.getElementById("pickdate"), "Choose a Date", "x");
			
			for (i=0; i<(months.length+0);++i){
				//if(months[i] < 10){
				//	zerodmonthnum = "0" + months[i];
				//} else {
				//	zerodmonthnum = months[i];
				//}
				//addOption(document.getElementById("pickdate"), getmonthname(months[i]), ("01/" + zerodmonthnum + "/2009"));
				addOption(document.getElementById("pickdate"), getmonthname(months[i]), months[i]);
			}
			
			addOption(document.getElementById("pickdate"), "Any Date", "any");
			document.getElementById("pickdate").style.display = "inline";
			document.getElementById("pickloc").style.display = "none";
		//}
	}
}

function selectdate(whichmonth){
	
	if(whichmonth.value != "x"){
		
		if(document.getElementById("pickdate").options[0].value == "x"){
			document.getElementById("pickdate").remove(0);
		}
	
		step3.length = 0;
		locations.length = 0;
		temploc = "";
		ClearOptions("pickloc");
		
		if(whichmonth.value == "any"){
			for (i=0;i<step2.length;i++){
					step3.push(step2[i]);
			}
		} else {
			 toflash2();
			//var myalert = "";
			for (i=0;i<step2.length;i++){
				//if((whichmonth.value >= step2[i].startmonth) && (whichmonth.value <= step2[i].endmonth)){
				//	step3.push(step2[i]);
				//}
				
				var strng=step2[i].months + ',';
				var tofind=(parseInt(whichmonth.value)) + ',';
				var post=strng.indexOf(tofind);
				
				//myalert += (strng + " - " + tofind + " - " + post + ' - ' + step2[i].holname + "\n");
				
				if(post >= 0){
					step3.push(step2[i]);
				}
			}
			//alert(myalert);
		}
		
		//if(step3.length > 0){
			
			for(j=0;j<step3.length;j++){
				locations.push(step3[j].location);
				temploc += step3[j].location + ",";
			}
			
			temploc = temploc.substr(0,(temploc.length-1));

			temploc = temploc.replace(" ,", ",");
			temploc = temploc.replace(", ", ",");
			
			locations = temploc.split(",");
			
			locations = locations.unique();
			locations.sort();
			
			if(locations.length > 1){
			addOption(document.getElementById("pickloc"), "Choose a Location", "x");
			}
			
			for (i=0; i<locations.length;++i){
				addOption(document.getElementById("pickloc"), locations[i], locations[i]);
			}

			document.getElementById("pickloc").style.display = "inline";
		//}
	}
}

function selectloc(whichloc){
	
	if(document.getElementById("pickloc").options[0].value == "x"){
		document.getElementById("pickloc").remove(0);
	}
}
