 function SubmitDest(p)
 { 
  if (document.MyVacation.DestCode.options[document.MyVacation.DestCode.selectedIndex].value=="")
  {
   alert("Please select a destination.")
  }
  else
  {
	document.MyVacation.action=p;
 	document.MyVacation.target="_parent";
	document.MyVacation.submit();
  }
 }

function setSearchToolValues(level)
{
  var hiddenForm = document.searchToolForm;
  var vacationForm = document.MyVacation;
  var roomTwoObject;
  var bottomForm;
  var dtCurrent = new Date();
  
  if (document.layers) { //Check to see if this is the NS4 version of the form
    roomTwoObject = document.layers['rm2Layer'].document.frmRoom2;
    bottomForm = document.bottom;
  }
  else{
    roomTwoObject = vacationForm;
    bottomForm = vacationForm;
  }  
  
  //Departure Dates
  hiddenForm.dMonth.value = vacationForm.dMonth.options[vacationForm.dMonth.selectedIndex].value;
  hiddenForm.dDay.value = vacationForm.dday.options[vacationForm.dday.selectedIndex].value;
  if (hiddenForm.dMonth.value < dtCurrent.getMonth() + 1){
    hiddenForm.dYear.value = dtCurrent.getFullYear()+1;
  }
  else {
    hiddenForm.dYear.value = dtCurrent.getFullYear();
  } 
  
  //Arrival Dates
  hiddenForm.aMonth.value = vacationForm.aMonth.options[vacationForm.aMonth.selectedIndex].value;	
  hiddenForm.aDay.value = vacationForm.aday.options[vacationForm.aday.selectedIndex].value;  
  if (hiddenForm.aMonth.value < dtCurrent.getMonth() + 1){
    hiddenForm.aYear.value = dtCurrent.getFullYear()+1;
  }
  else {
   hiddenForm.aYear.value=dtCurrent.getFullYear();
  } 
  if ( level != "advanced" ) 
  { 
    //Departure City = Vacation Packages Search
    if( !vacationForm.dCity.disabled ){ 
        hiddenForm.dCity.value = vacationForm.dCity.options[ vacationForm.dCity.selectedIndex ].value;
        hiddenForm.dCityDescription.value = vacationForm.dCity.options[ vacationForm.dCity.selectedIndex ].text;
        hiddenForm.airtype.value = "1"; //Include Air
        hiddenForm.airrequestType.value = "BV";
        //Set Times 
        hiddenForm.dTime.value = vacationForm.dTime.options[vacationForm.dTime.selectedIndex].value;
        hiddenForm.aTime.value = vacationForm.aTime.options[vacationForm.aTime.selectedIndex].value;    
    }
    else { //Land Only
        hiddenForm.dCity.value = "NYC";
        hiddenForm.dCityDescription.value = "New York - All Airports";
        hiddenForm.airtype.value = "3"; //Include Air
        hiddenForm.airrequestType.value = "BV";  
        //Set Times 
        hiddenForm.dTime.value = "0600";
        hiddenForm.aTime.value = "1500"; 
    }
  }
  else
  {
    //Departure City = Vacation Packages Search
    if( !vacationForm.dCity.disabled ){ 
        hiddenForm.dCity.value = vacationForm.dCity.options[ vacationForm.dCity.selectedIndex ].value;
        hiddenForm.airtype.value = "1"; //Include Air
        hiddenForm.airrequestType.value = "BV";
        //Set Times 
        hiddenForm.dTime.value = vacationForm.dTime.options[vacationForm.dTime.selectedIndex].value;
        hiddenForm.aTime.value = vacationForm.aTime.options[vacationForm.aTime.selectedIndex].value;    
    }
    else { //Land Only
        hiddenForm.airtype.value = "3";
        hiddenForm.airrequestType.value = "BV";  
        //Set Times 
        hiddenForm.dTime.value = "0600";
        hiddenForm.aTime.value = "1500"; 
    }    
  }
  //Set Arrival City Info
  hiddenForm.aCity.value = vacationForm.aCity.options[ vacationForm.aCity.selectedIndex ].value;				  
  hiddenForm.aCityDescription.value = vacationForm.aCity.options[ vacationForm.aCity.selectedIndex ].text;				

  //Set Room 1 Values
  hiddenForm.Rm1Adults.value = vacationForm.Rm1Adults.options[vacationForm.Rm1Adults.selectedIndex].value;
  hiddenForm.Rm1Ch1Age.value = vacationForm.Rm1Ch1Age.value;
  hiddenForm.Rm1Ch2Age.value = vacationForm.Rm1Ch2Age.value;
  hiddenForm.Rm1Ch3Age.value = vacationForm.Rm1Ch3Age.value;
  hiddenForm.Rm1Ch4Age.value = vacationForm.Rm1Ch4Age.value;
  hiddenForm.Rm1Ch5Age.value = vacationForm.Rm1Ch5Age.value;
  
  //Get the number of rooms 
  hiddenForm.NumRooms.value = vacationForm.NumRooms.options[vacationForm.NumRooms.selectedIndex].value;
  
  //Set the Room 2 Values
  if ( parseInt(hiddenForm.NumRooms.value) == 2  ){
    hiddenForm.Rm2Adults.value = roomTwoObject.Rm2Adults.options[roomTwoObject.Rm2Adults.selectedIndex].value;    
    hiddenForm.Rm2Ch1Age.value = roomTwoObject.Rm2Ch1Age.value;
    hiddenForm.Rm2Ch2Age.value = roomTwoObject.Rm2Ch2Age.value;
    hiddenForm.Rm2Ch3Age.value = roomTwoObject.Rm2Ch3Age.value;
    hiddenForm.Rm2Ch4Age.value = roomTwoObject.Rm2Ch4Age.value;
    hiddenForm.Rm2Ch5Age.value = roomTwoObject.Rm2Ch5Age.value;  
  }
  else {
    hiddenForm.Rm2Adults.value = "";    
    hiddenForm.Rm2Ch1Age.value = "";
    hiddenForm.Rm2Ch2Age.value = "";
    hiddenForm.Rm2Ch3Age.value = "";
    hiddenForm.Rm2Ch4Age.value = "";
    hiddenForm.Rm2Ch5Age.value = "";
  }  

  var output = "";
  for(var hf = 0; hf < hiddenForm.elements.length; hf++ ){
    output += ("\n"+hiddenForm.elements[hf].name+" = "+hiddenForm.elements[hf].value);
  }
}

function setArrays( rm ){
  if ( rm == 1 ){
    var r1Arr = new Array(5);
    r1Arr [0] = document.MyVacation.Rm1Ch1Age;
    r1Arr [1] = document.MyVacation.Rm1Ch2Age;
    r1Arr [2] = document.MyVacation.Rm1Ch3Age;
    r1Arr [3] = document.MyVacation.Rm1Ch4Age;
    r1Arr [4] = document.MyVacation.Rm1Ch5Age;
    return r1Arr;
  }
  else {
    if (document.layers) { //Check to see if this is the NS4 version of the form
      roomTwoFrm = document.layers['rm2Layer'].document.frmRoom2;
    }
    else{
      roomTwoFrm = document.MyVacation;
    }  
    var r2Arr = new Array(5);  
    r2Arr [0] = roomTwoFrm.Rm2Ch1Age;
    r2Arr [1] = roomTwoFrm.Rm2Ch2Age;
    r2Arr [2] = roomTwoFrm.Rm2Ch3Age;
    r2Arr [3] = roomTwoFrm.Rm2Ch4Age;
    r2Arr [4] = roomTwoFrm.Rm2Ch5Age;  
    return r2Arr;
  }
  return;
}

function setBlank( roomNum, count ){
  var inputArray = setArrays( roomNum );
  for(var i = 0; i < inputArray.length; i++){
    if ( count < (i + 1) ){
      inputArray[i].value = "";
    }
  }
}

function isValidChild ( eventObject, element, index, count  ){
  if ( index <= count ){
    var key;
    if (window.event) { //IE
      key = window.event.keyCode;
    }
    else { //Mozilla
      key = eventObject.which; 
    }

    var keychar = String.fromCharCode(key); //obtain a number from the char code
    //window.status = keychar;  
    if ( (key==0) || (key==8) || (key==9) || (key==27) || (key==127)) {
      return true;
    }   
  
    if ( ( ("0123456789").indexOf(keychar) > -1) ) {
      return true;
    } 
    else {
      return false;
    }
  }
  alert("Please enter the number of children traveling.");
  return false;
}

function ValidateForm( level ){
  var errMsg ="Please enter the correct values for:\n"
  var errors = 0;
  var r1Array, r2Array; 
  var rm1Count = 0;
  var rm2Count = 0;
  var myForm = document.MyVacation;
  if (document.layers){
    var myForm2 = document.layers['rm2Layer'].document.frmRoom2;
  }
  else{
    var myForm2 = myForm;
  }
  if ( level != "advanced" )
  {
    if ( !myForm.dCity.disabled )
    {
        if ( myForm.dCity.options[myForm.dCity.selectedIndex].value == "" )
        {
            errors++;
            errMsg += "City you are leaving from\n"
        }
    }
    
    if ( myForm.aCity.options[myForm.aCity.selectedIndex].value == "" )
    {
        errors++;
        errMsg += "City you are going to\n"
    }
  }
  r1Array = new Array(5);
  r1Array [0] = myForm.Rm1Ch1Age;
  r1Array [1] = myForm.Rm1Ch2Age;
  r1Array [2] = myForm.Rm1Ch3Age;
  r1Array [3] = myForm.Rm1Ch4Age;
  r1Array [4] = myForm.Rm1Ch5Age;
  
  for(var i = 0; i < r1Array.length; i++){
    if( r1Array[i].value.length > 0 ) {
      rm1Count++;
    }
  }

  if (rm1Count != parseInt(myForm.Rm1Children.options [myForm.Rm1Children.selectedIndex].value ) ) {	     
     errors++;
     errMsg +="Room 1 Number of Children\n"
  } //end room1 if
  else {   
    room1:
    for(var i = 0; i < parseInt(myForm.Rm1Children.options [myForm.Rm1Children.selectedIndex].value); i++ ){ 
      if( !isValidAge( r1Array[i].value ) ){
         errors++;
         errMsg +="Room 1 Child Ages\n"         
         break room1;       
      }//end if
    }//end for
  }//end room 1 else

  if ( parseInt(myForm.NumRooms.options[ myForm.NumRooms.selectedIndex].value) == 2 ){
    r2Array = new Array(5);  
    r2Array [0] = myForm2.Rm2Ch1Age;
    r2Array [1] = myForm2.Rm2Ch2Age;
    r2Array [2] = myForm2.Rm2Ch3Age;
    r2Array [3] = myForm2.Rm2Ch4Age;
    r2Array [4] = myForm2.Rm2Ch5Age;  
    
    for(var i = 0; i < r2Array.length; i++){
      if( r2Array[i].value.length > 0 ) {
        rm2Count++;
      }
    }    
    if (rm2Count != parseInt(myForm2.Rm2Children.options [myForm2.Rm2Children.selectedIndex].value) ){
      errors++;   
      errMsg +="Room 2 Number of Children\n"                    
    } //end room 2 if
    else{
      room2:
      for(var i = 0; i < parseInt(myForm2.Rm2Children.options [myForm2.Rm2Children.selectedIndex].value); i++ ){ 
        if ( !isValidAge( r2Array[i].value )  ){
          errors++;   
          errMsg +="Room 2 Child Ages\n"                   
          break room2;      
        }//end if
      } //end for
    }//end room 2 else
  } //end rooms
  
  if (errors > 0){
    alert(errMsg);
    return false;
  }//end if
  else { 
    return true; 
  } //end else

}//end function

function isValidAge( age ){
  var maxChildAge = 21;
  var minChildAge = 0;
  if( minChildAge < age && age < maxChildAge ){
    return true;
  }
  return false;
}

function SubmitPackage(p) {
  if ( ValidateForm('') && checkDates(document.MyVacation) ){
	setSearchToolValues('');
	document.searchToolForm.action = p;
    document.searchToolForm.target = "_parent"; 
    document.searchToolForm.submit();
  }
}

function AdvancedSearch(p)
{
    var lvl = "advanced";
    if ( ValidateForm(lvl) )
    {  
        setSearchToolValues( lvl );  
	    document.searchToolForm.action = p;
        document.searchToolForm.target = "_parent"; 
        document.searchToolForm.submit();
    }
}

function getAgeCount ( childrenArray, selectableElement ) {
  var numberOfChildren = 0; 
  for(var i = 0; i < childrenArray.length; i++){
    if( trim(childrenArray[i].value) != '' ) {
       numberOfChildren++;
    }
  }

  return numberOfChildren;
}

/**
*  DHTML functions chages images for search tool tabs
*  IE 5.5 +
*  Mozilla 6.0 +
*/

var out = new makeImageArray();
var onn = new makeImageArray();
var headerImages = new Array();

/*out[0].src = "/images/searchtool/st_vacoff.gif";
out[1].src = "/images/searchtool/st_hoteloff.gif";
out[2].src = "/images/searchtool/st_destoff.gif";
out[3].src = "/images/searchtool/st_topoff.gif";

onn[0].src = "/images/searchtool/st_vacon.gif";
onn[1].src = "/images/searchtool/st_hotelon.gif";
onn[2].src = "/images/searchtool/st_deston.gif";  
onn[3].src = "/images/searchtool/st_topon.gif";  
*/
function loadImages(){
  headerImages[0] = document.getElementById("book");
  headerImages[1] = document.getElementById("hotels");  
  headerImages[2] = document.getElementById("Destination");
  
  headerImages[3] = document.getElementById("specials");
  return;
}      
function makeImageArray() {
   this.length = 4;
   for (var i = 0; i < 4; i++) {
     this[i] = new Image();
    } 
  return this;
}

function swapImage(num){
  loadImages();
  var a, b,c;

  if (num == 0) {a=1;b=2;c=3;}
  if (num == 1) {a=0;b=2;c=3;}
  if (num == 2) {a=0;b=1;c=3;}
  if (num == 3) {a=0;b=1;c=2;}

  headerImages[a].src = out[a].src;
  headerImages[b].src = out[b].src;
  headerImages[c].src = out[c].src;
  headerImages[num].src = onn[num].src;  
}

/**
* DHTML show/hide second room passenger information 
* Author: D. Dungey
* Date 09.20.2004
*/
function shtype(item) {
    var s_index = item.selectedIndex
    s_index = s_index + 1
    if (s_index == 2 )
    {
	    document.getElementById('rm2').style.visibility='visible';
        document.getElementById('rm2').style.display='block';
	}
    else 
	{
	    document.getElementById('rm2').style.visibility='hidden';
        document.getElementById('rm2').style.display='none';
	}
}    

/**
* DHTML toggles the text based on Air or Land only selection
* Author: D. Dungey
* Date 09.20.2004
*/
function ch_inc() {
    var currentForm = document.MyVacation;
for (counter = 0; counter < currentForm.p_air_htl.length; counter++)
	{
  	if (currentForm.p_air_htl[counter].checked)
		{
  		var str_agr = currentForm.p_air_htl[counter].value;
 		// alert(str_agr);
  		}
	}
if (str_agr == "air") {
        document.getElementById('air_htl').style.color='#003063';
		document.getElementById('dCity').disabled='';

		
		document.getElementById('dTimeDiv').style.visibility='visible';
		document.getElementById('aTimeDiv').style.visibility='visible';
	    document.getElementById('air_htl_in').style.visibility='visible';
        document.getElementById('air_htl_in').style.display='block';
		document.getElementById('air_htl_out').style.visibility='visible';
        document.getElementById('air_htl_out').style.display='block';
		document.getElementById('htl_onl_in').style.visibility='hidden';
		document.getElementById('htl_onl_in').style.display='none';
		document.getElementById('htl_onl_out').style.visibility='hidden';
		document.getElementById('htl_onl_out').style.display='none';
		
	}else if (str_agr == "htl") {

	  document.getElementById('air_htl').style.color='#999966';
	  document.getElementById('dCity').disabled='disabled';
      document.getElementById('dTimeDiv').style.visibility='hidden';
	  document.getElementById('aTimeDiv').style.visibility='hidden';

	  document.getElementById('air_htl_in').style.visibility='hidden';
	  document.getElementById('air_htl_in').style.display='none';
	  document.getElementById('air_htl_out').style.visibility='hidden';
	  document.getElementById('air_htl_out').style.display='none';
	  document.getElementById('htl_onl_in').style.visibility='visible';
      document.getElementById('htl_onl_in').style.display='block';
	  document.getElementById('htl_onl_out').style.visibility='visible';
      document.getElementById('htl_onl_out').style.display='block';
	 }
	else {
	    document.getElementById('air_htl').style.visibility='visible';
        document.getElementById('air_htl').style.display='block';
	    document.getElementById('air_htl_in').style.visibility='visible';
        document.getElementById('air_htl_in').style.display='block';
		document.getElementById('air_htl_out').style.visibility='visible';
        document.getElementById('air_htl_out').style.display='block';
		document.getElementById('htl_onl_in').style.visibility='hidden';
		document.getElementById('htl_onl_in').style.display='none';
		document.getElementById('htl_onl_out').style.visibility='hidden';
		document.getElementById('htl_onl_out').style.display='none';
		
	}
 }
 
 function switchScreens( number ){
  var url = "Default.asp?st_page=" + number;
  window.location = url;
}

/**
* Hides/Shows Times based on parameters
*/
function toggleTime( strTripType )
{
    var display = "none";
    var visibility = "hidden";
    
    if (strTripType == "air" ) 
    {
        display = "block";    
        visibility = "visible";
    }
    else if (strTripType == "htl" ) 
    {
        display = "none";  
        visibility = "hidden";
    }
    document.getElementById('aTimeDiv').style.visibility = visibility;   
    document.getElementById('dTimeDiv').style.visibility = visibility;    
}
