  var showAgeSelRmTitles = true;
  var size = 1;

  var active_des = false;
  var active_dep = false;
	
  var noSupportedRooms = 3;
  var alphabet = "abcdefghijklmnopqrstuvwxyz";
  var maxChildrenPerRoom = 4;


  function flights_only() {
	return(document.forms[0].vacation_type.value == "AO");  
  }

  function hotel_only() {
	return(document.forms[0].vacation_type.value == "LO");  
  }

  function flights_and_hotel() {
	return(document.forms[0].vacation_type.value == "LA");  
  }
  
  function packages() {
	return(document.forms[0].vacation_type.value == "SP");  
  }
  
  function update_tabs(radio_obj) {

	document.forms[0].vacation_type.value = radio_obj;
	
  	if (flights_and_hotel()) {
		setDisplay("SPON", "none");  	
		setDisplay("SPOFF", "block");  	
		setDisplay("LAON", "block");  	
		setDisplay("LAOFF", "none");  					
		setDisplay("AOON", "none");  	
		setDisplay("AOOFF", "block");  	
		setDisplay("LOON", "none");  	
		setDisplay("LOOFF", "block");  							
  	} 
  	else if (flights_only()) {
		setDisplay("SPON", "none");  	
		setDisplay("SPOFF", "block");  	
		setDisplay("LAON", "none");  	
		setDisplay("LAOFF", "block");  					
		setDisplay("AOON", "block");  	
		setDisplay("AOOFF", "none");  	
		setDisplay("LOON", "none");  	
		setDisplay("LOOFF", "block");    	
  	}
  	else if (hotel_only()) {
		setDisplay("SPON", "none");  	
		setDisplay("SPOFF", "block");  	
		setDisplay("LAON", "none");  	
		setDisplay("LAOFF", "block");  					
		setDisplay("AOON", "none");  	
		setDisplay("AOOFF", "block");  	
		setDisplay("LOON", "block");  	
		setDisplay("LOOFF", "none");    	
  	}
  	else {
		setDisplay("SPON", "block");  	
		setDisplay("SPOFF", "none");  	
		setDisplay("LAON", "none");  	
		setDisplay("LAOFF", "block");  					
		setDisplay("AOON", "none");  	
		setDisplay("AOOFF", "block");  	
		setDisplay("LOON", "none");  	
		setDisplay("LOOFF", "block");    	
  	}
  }
	
  function update_des() {
    if ((!NS4 && !IE4 && !NS6) || NS4MAC) return;
    var field = document.forms[0].prefix_des;
    var list = document.forms[0].destination_city_code;
    field.value = list.options[list.selectedIndex].value;
    
    //account for destination changing from cun/mbj to something else
    //or from something else to cun/mbj if not Flights Only
    updateResortAreas();
  }

  function updateResortAreas() {
    var field = document.forms[0].prefix_des;
	
	if (flights_only()) {
		hideResortAreas();
	} else if (field.value == "CUN") {
		showResortAreas();
	    setDisplay("resort_cun", "block");
    } else if (field.value == "MBJ") {
   		showResortAreas();
	    setDisplay("resort_mbj", "block");         		
   	} else {
    	hideResortAreas();
    }
  }

  function hideResortAreas() {
    setDisplay("resort_area_row", "none");
  }

  function showResortAreas() {
    setDisplay("resort_area_row", "block");
    setDisplay("resort_cun", "none");
    setDisplay("resort_mbj", "none");      

  }
    
  function update_dep() {
    if ((!NS4 && !IE4 && !NS6) || NS4MAC) return;
    var field = document.forms[0].prefix_dep;
    var list = document.forms[0].departure_city_code;
    field.value = list.options[list.selectedIndex].value;
  }

  function select(list, i) {
    if (list.selectedIndex != i) list.selectedIndex = i;
  }

  function checkKey() {

    var field;
    var list;
  
    if (active_dep) {
      field = document.forms[0].prefix_dep;
      list = document.forms[0].departure_city_code;
    }
    else {
      if (active_des) {
        field = document.forms[0].prefix_des;
        list = document.forms[0].destination_city_code;
      }
      else return;
    }
  
    var str = field.value.toLowerCase();
    if (str == "") {
      select(list, 0);
      return;
    }
    
    //changed to search all codes first
    for (var i = 0; i < list.options.length; ++i) {

      if (list.options[i].value.toLowerCase().indexOf(str) == 0) {
        select(list, i);
        return;

      }
    }    
    //if no match on codes, check city names    
    for (var i = 0; i < list.options.length; ++i) {
      if (list.options[i].text.toLowerCase().indexOf(str) == 0) {
        select(list, i);
        return;
      }
    }

  }
  
  // -- Room functions  
  function showRooms() {
    showAgeSelRmTitles = true;    
    setDisplay("RoomTitle1", "block");
    setDisplay("num_of_rooms", "block");
    showHideAgeSelects(parseInt(document.forms[0].num_of_rooms.value)); 
    showRoomDetail();
  }
  
  function hideRooms() {
	document.forms[0].num_of_rooms.value = 1; //flights_only
    showAgeSelRmTitles = false;
    setDisplay("RoomTitle1", "none");
    setDisplay("num_of_rooms", "none");    
    showHideAgeSelects(1);
    showRoomDetail();
  }
  
  function showHideAgeSelects(n) {
	
	var obj = null;
	n = (!flights_only()) ? parseInt(n) : 1;
	for (var i=0; i < noSupportedRooms; i++) {
	  if (i< n ) d="block";
	  else d="none";
	  setDisplay("ageSel" + i, d);
	}
    ShowAges();
  }
	
  function ShowAges() {
	
	var Total1=document.forms[0].num_of_children1.value;
	var Total2=document.forms[0].num_of_children2.value;
	var Total3=document.forms[0].num_of_children3.value;
	var total=0;
	var rooms = (!flights_only()) ? parseInt(document.forms[0].num_of_rooms.value) : 1;
	if (rooms==1)
	  total = parseInt(Total1);
	else if (rooms==2)
	  total = parseInt(Total1) + parseInt(Total2);
	else  
	  total = parseInt(Total1) + parseInt(Total2) + parseInt(Total3);

	if(total==0) {
	  setDisplay("ageFrame", "none");
	}
	else {
	  ShowAgeSelects();
	  if(getDisplay("ageFrame")=="none") {
	    setVisibility("ageFrame", false);
	    setDisplay("ageFrame", "block");
	  }
	  setVisibility("ageFrame", true);
	}
  }
	  
  function ShowAgeSelects() {
    
    // -- for each room
    for (var i=0; i < ((!flights_only()) ? noSupportedRooms : 1); i++) {
		  
	  // -- For each room, get unique prefix char, e.g. "a", "b", etc.
      var roomPrefix = alphabet.substr(i, 1);
	  var numChildrenInRoom = parseInt(eval("document.forms[0].num_of_children" + (i + 1).toString() + ".value"));
			
      if (numChildrenInRoom > 0) {

        // -- This is the "Room 1", etc. title for the age selects
        setVisibility("r" + i.toString(), !flights_only());
				
		// -- for each child's age selection, up to max #
		//if (!flights_only()) {
		  for (var j=0; j < maxChildrenPerRoom; j++) {
		    setVisibility("ageSel" + roomPrefix + j.toString(), ((j < numChildrenInRoom) ? true : false));
		  }
		//}		 
      } else {			
        setVisibility("r" + i.toString(), false);
		for (var j=0; j < maxChildrenPerRoom; j++) {
		  setVisibility("ageSel" + roomPrefix + j.toString(), false);
		}        
	  }	
	}
	
	// set initial display for infant lap/seat choice here.
	// elsewhere the display can change as ages get changed
	ShowInfantLapSeat(); 
  }

  function ShowInfantLapSeat() {

	// called initially by ShowAgeSelects, then onChange for all child ages
	// only show infant in seats or laps selection 
	// if !hotel_only && at least one child has age = 1 (under 2)

  	var show_infant_lap = false;
  	
	if (!hotel_only()) {

		// check all rooms, all children: if any one of them is an infant, 
		// show the lap/seat choice	
	    // -- for each room
	    for (var i=0; i < ((!flights_only()) ? noSupportedRooms : 1); i++) {

		  var numChildrenInRoom = parseInt(eval("document.forms[0].num_of_children" + (i + 1).toString() + ".value"));
				
	      if (numChildrenInRoom > 0) {
			  // -- For each room, get unique prefix char, e.g. "a", "b", etc.
		      var roomPrefix = alphabet.substr(i, 1);					

			  // -- for each child's age selection, up to max #
			  for (var j=0; j < maxChildrenPerRoom; j++) {
				age_name = "document.forms[0]." + roomPrefix + j.toString();
				age_test = eval( age_name + "[" + age_name + ".selectedIndex" + "].value");
				if (age_test == '1') {
					show_infant_lap = true;
					break;
				}

			  }
      
		  }	
		} //for
	
	} //if !hotel_only

	setVisibility("infants", show_infant_lap); 
  
  }
	
  function showRoomDetail() {
    if (parseInt(document.forms[0].num_of_rooms.value) == 1 || flights_only() ) {
	  setDisplay("Rm2","none");
	  setDisplay("Rm3","none");
	  setDisplay("RoomsRm1Title", "none");
	}
	else if (parseInt(document.forms[0].num_of_rooms.value) == 2) {
	  setDisplay("Rm2","block");
	  setDisplay("Rm3","none");
	  setDisplay("RoomsRm1Title", "block");
	}
	else if (parseInt(document.forms[0].num_of_rooms.value) == 3) {
	  setDisplay("Rm2","block");
	  setDisplay("Rm3","block");
	  setDisplay("RoomsRm1Title", "block");
	}
  }          

  function ShowIS(d,s) {
    if(s==1) setDisplay("infant","block");
	else setDisplay("infant","none");
  }
										
  function showWarnInLaps() {
    setDisplay("warnInLaps", "block");
  }
  
  function hideWarnInLaps() {
    setDisplay("warnInLaps", "none");
  }
  // -- End Room functions


	// -- Flag to enable/disable buttons
	this.checked = false;

  function processPage() {
	if (this.checked) {
		window.alert("We are processing your previous request.");
		return;
	}  
	this.checked = true;
  	document.forms[0].submit();
  }	
//------------------------------------------------------------------
//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)
