var charterDestArray = new Array("AUA,Aruba",  "CUN,Cancun", "CZM,Cozumel", "LRM,La Romana", "PUJ,Punta Cana", "PLA,Riviera Maya");

var fitDestArray = new Array("ANU,Antigua", "AUA,Aruba", "BZE,Belize", "BGI,Barbados", "BDA,Bermuda", "CUN,Cancun",  "SJO,Costa Rica", "LIR,Costa Rica North Pacific", "CZM,Cozumel", "FPO,Grand Bahama Islands", "ZIH,Ixtapa", "OCH,Jamaica-Ocho Rios", "MBJ, Jamaica-Montego Bay", "WHI,Jamaica-South Coast", "NEG,Jamaica-Negril", "SDQ,Juan Dolio/Boca Chica", "LRM,La Romana", "SJD,Los Cabos", "NAS,Nassau", "POP,Puerto Plata", "SJU,Puerto Rico", "PVR,Puerto Vallarta", "PUJ,Punta Cana", "PLA,Riviera Maya", "SKB,St.Kitts",	"SLU,St.Lucia", "SXM,St.Martin/St.Maarten", "STX,St Croix", "STT,St. Thomas/St. John", "PLS,Turks & Caicos" );


var currDivObj = null;


//----------------------------------------------------------------------
   function changeDIV(selObj) {

        var divObj;

        selValue = selObj.value;
	//alert(selObj.value);
	// ----If Hotel Only then treat it as FIT----
        selValue = selObj.value;
        //alert("selValue : " + selValue);

        {
        	//alert("FIT value 2 selected");
        	document.myForm.Gateway.options.length = 1;
        	addFITGateway();
     //   	document.myForm.Gateway.options[19].selected=true;
        	document.myForm.TourType.options.length = 1;
        	loadFitPkg();
        	document.myForm.TourType.options[1].selected=true;
        	setFitMealPlan(myForm);
        }
        
        
    }
    
//-------------------------------------
function loadDefaultDate(){

	
    date = new Date();
    date = new Date(date.getTime() + (2*24*60*60*1000));
    day = date.getDate();
    year = date.getFullYear();
    month = date.getMonth();
    //document.myForm.CA_DEP_DAY.selectedIndex  = day + 1;
    document.myForm.CA_DEP_DAY.selectedIndex  = day;
    document.myForm.CA_DEP_MONTH.selectedIndex = month+1 ;
    document.myForm.CA_DEP_YEAR.value  = year ;
 /*   
    document.myForm.CA_DEP_DAY.value = day + 1;
    document.myForm.CA_DEP_MONTH.selectedIndex = month+1 ;
    document.myForm.CA_DEP_YEAR.value = year ;
 */ 
    
    
}
//-------------------------------------
function loadFITDefaultDate(){
//alert("Hi");
	ShowFIT();
    date = new Date()
    day = date.getDate();
    year = date.getFullYear();
    month = date.getMonth();
    document.myForm.CA_DEP_DAY.selectedIndex  = day + 1;
    document.myForm.CA_DEP_MONTH.selectedIndex = month+1 ;
    document.myForm.CA_DEP_YEAR.value  = year ;
 /*   
    document.myForm.CA_DEP_DAY.value = day + 1;
    document.myForm.CA_DEP_MONTH.selectedIndex = month+1 ;
    document.myForm.CA_DEP_YEAR.value = year ;
 */ 
    
    
}

function ShowCharter()
{
	document.myForm.QQ_TYPE[2].checked=true;
	 document.myForm.Gateway.options.length = 0;
	 addCharterGateway();
	 //addGateway("--------Select Origin------","null");
    // addGateway("Boston, MA","BOS");
     //addGateway("New York(JFK)","JFK");
     //document.myForm.Gateway.options[1].selected=true;
     document.myForm.TourType.options.length = 1;
     loadCharterPkg();
     document.myForm.TourType.options[1].selected=true;
     	
}

function ShowFIT()
{
	document.myForm.QQ_TYPE[0].checked=true;
	 document.myForm.Gateway.options.length = 0;
	 //alert("adding gateway");
	 addFITGateway();
   //  document.myForm.Gateway.options[18].selected=true;
     document.myForm.TourType.options.length = 1;
     loadFitPkg();
    // document.myForm.TourType.options[1].selected=true;
     	
}
function checkDate(){
    

if(document.myForm.Gateway.value == "null")
{
  alert("Please select the Departure City");
  document.myForm.Gateway.focus();
  return false;
}	 
 
 if(document.myForm.MealPlan != null){  
	if( document.myForm.MealPlan.value == "null")
	    {
	alert("Please select the Meal Plan");
	 document.myForm.MealPlan.focus();
	return false;
	}	
 }
if( document.myForm.TourType.value == "null")
    {
alert("Please select the Tour type");
 document.myForm.TourType.focus();
return false;
}	
 
 currentDate = new Date();
    date2 = new Date(document.myForm.CA_DEP_YEAR.value,document.myForm.CA_DEP_MONTH.value-1,document.myForm.CA_DEP_DAY.value);
    date2value = date2.getTime();
    current2value = currentDate.getTime();
    //alert(date2value );
    //alert(current2value);
   if(date2value >= current2value)
    return true
    else{
        alert("Please select date later than current date");
        return false
    }    


    
 }
 //------------------------------------------------------------------------------
 function checkFitDate(){
    

if(document.myForm.Gateway.value == "null")
{
  alert("Please select the Departure City");
  document.myForm.Gateway.focus();
  return false;
}	 
	
if( document.myForm.TourType.value == "null")
    {
alert("Please select the Tour type");
 document.myForm.TourType.focus();
return false;
}	
 
 currentDate = new Date();
    date2 = new Date(document.myForm.CA_DEP_YEAR.value,document.myForm.CA_DEP_MONTH.value-1,document.myForm.CA_DEP_DAY.value);
    date2value = date2.getTime();
    current2value = currentDate.getTime();
    //alert(date2value );
    //alert(current2value);
   if(date2value >= current2value)
   {
   	 formReturnDay();
    	return true
   }
    else{
        alert("Please select date later than current date");
        return false
    }    
   
     if(!check330Fit())
   		return false
   	else
   		return true;
   		

 }
 //------------------------------------------------------------------------------
 function formReturnDay(){

	//if(! checkValidDays())
		//return false;
	depYear = document.myForm.CA_DEP_YEAR.value;
	depMonth = document.myForm.CA_DEP_MONTH.selectedIndex-1;
	depDay = document.myForm.CA_DEP_DAY.selectedIndex;
			
	numDays = document.myForm.TourType.value;
			//alert(numDays);
			//alert(depMonth + ":" + depDay + ":" + depYear);

	date2 = new Date(depYear,depMonth,depDay,0,0,0,0);
	date2Time = date2.getTime();
				//added 1hr to compensate daylight savings
			   d = new Date(date2Time + (numDays*24*60*60*1000) + (60*60*1000) );
			  //     d = new Date(date.getTime()) ;
			 // alert(d);
	day = d.getDate();
	year = d.getFullYear();
	month = d.getMonth();

	document.myForm.CA_RET_DAY.value = day;
	document.myForm.CA_RET_MONTH.value = month+1 ;
	document.myForm.CA_RET_YEAR.value = year ;

}
 //------------------------------------------------------------------------------
 function postForm2(type)
 {
//if(type==2){
//var type = document.myForm.CA_HOTEL_COMPONENT.value;
//alert(type);
    document.myForm.action="/AvailabilityGeneralInfo?type=gateway"; 
    document.myForm.submit();
 //   }
}
//-------------------------------------------------------
function addPkg(text, value) {
   try{
   var option =
	  document.createElement("OPTION");
   option.text = text;
   option.value = value;
   manufacturer=navigator.appName;

   if (manufacturer.indexOf('Microsoft')>=0)
	document.myForm.TourType.add(option);
   else if (manufacturer.indexOf('Netscape')>=0)
	document.myForm.TourType.appendChild(option);
   }catch(e){alert("Exception in pkg type");}
}

//----------
function loadCharterPkg()
{
	//alert("Charter Pkg");
	//alert(document.myForm.Gateway.value);
	addPkg("7 nights","07");
	destSpecificLoadCharterPkg();
}

//-------------------------------------------------------
function destSpecificLoadCharterPkg()
{
	try
	{
		if (document.myForm.QQ_TYPE[2].checked) 
		{
		  if (document.myForm.Gateway.value =="BOS") 
		  {
		   if ((document.myForm.Destination.value =="PUJ") || (document.myForm.Destination.value =="LRM"))
				  PUJ_LRM_loadCharterPkg();
	  	 else if (document.myForm.Destination.value =="BDA")
	  	 	  BDA_loadCharterPkg();
	  	 else
	    		document.myForm.TourType.options.length = 2;
	  	 }
	   }
  }
  catch(E)
  {	
  }
}
//-----------------------------------------
//-------------------------------------------------------
function PUJ_LRM_loadCharterPkg()
{
	try
	{
		if (document.myForm.QQ_TYPE[2].checked) 
		{
		  if ((document.myForm.Gateway.value =="BOS") && ((document.myForm.Destination.value =="PUJ") || (document.myForm.Destination.value =="LRM")))
		 	{
				//alert("Also available: 6 Night packages departing 12/26/06 and 01/01/07");
				document.myForm.TourType.options.length = 2;
	  		addPkg("6 Nights","06");
	  		document.myForm.TourType.options.length = 3;
	  	}
	  	else
	    {
	    	document.myForm.TourType.options.length = 2;
	  	}
	  
	   }
  }
  catch(E)
  {	
  }
	
}

//-------------------------------------------------------
function BDA_loadCharterPkg()
{
	try
	{
		if (document.myForm.QQ_TYPE[2].checked) 
		{
		  if ((document.myForm.Gateway.value =="BOS") && (document.myForm.Destination.value =="BDA"))
		 	{
				//alert("Also available: 6 Night packages departing 12/26/06 and 01/01/07");
				document.myForm.TourType.options.length = 2;
	  		addPkg("3 Nights","03");
	  		addPkg("4 Nights","04");
	  		document.myForm.TourType.options.length = 4;
	  	}
	  	else
	    {
	    	document.myForm.TourType.options.length = 2;
	  	}
	  
	   }
  }
  catch(E)
  {	
  }
	
}

//----------
function loadFitPkg()
{
	//alert("Fit Pkg");
	addPkg("7 nights","07");
	addPkg("1 night","01");
	addPkg("2 nights","02");
	addPkg("3 nights","03");
	addPkg("4 nights","04");
	addPkg("5 nights","05");
	addPkg("6 nights","06");
	addPkg("8 nights","08");
	addPkg("9 nights","09");
	addPkg("10 nights","10");
	addPkg("11 nights","11");
	addPkg("12 nights","12");
	addPkg("13 nights","13");
	addPkg("14 nights","14");
	addPkg("15 nights","15");
	addPkg("16 nights","16");
	addPkg("17 nights","17");
	addPkg("18 nights","18");
	addPkg("19 nights","19");
	addPkg("20 nights","20");
	addPkg("21 nights","21");
}
//------------------------------------------------------------------------------

function addGateway(text, value) {
   try{
   var option =
	  document.createElement("OPTION");
   option.text = text;
   option.value = value;
   manufacturer=navigator.appName;

   if (manufacturer.indexOf('Microsoft')>=0)
	document.myForm.Gateway.add(option);
   else if (manufacturer.indexOf('Netscape')>=0)
	document.myForm.Gateway.appendChild(option);
   }catch(e){alert("Exception in Charter Gateway");}
}

//-----------------------------------------------------------------------------


//---------------------
/*
//Modified on 4/9/04
function postForm()
 {

alert("selection " + document.myForm.QQ_TYPE[0].value);
    //if(!document.myForm.QQ_TYPE[0].checked)
    if(document.myForm.QQ_TYPE[0].value != 1)
    {
	if(checkFitDate()){
		setFitMealPlan(myForm);
	    	document.myForm.action="CM_AirHotel"; 
	    	//document.myForm.action="CM_ErrorPage?msg=Service Temporarily Not Available, Please Try Again Later.";
	    	document.myForm.submit();
	}
    }
    else
    {
    	if(checkDate()){
    		//setCharterMealPlan(myForm);
	    	document.myForm.action="PortalInterface"; 
	    	document.myForm.submit();
	}
    }
    
  

}

*/

function postForm()
 {

//alert("selection " + document.myForm.QQ_TYPE[0].value);
  
   if(!check330Fit())
   		return false;
// alert( check330Fit());  		
  
    if(document.myForm.QQ_TYPE[0].value != 1)
    { 
    	//Condition when destination in non-charter 
    	// so only nationwide and hotel-only available
		if(checkFitDate()){
			setFitMealPlan(myForm);
		    	//document.myForm.action="CM_AirHotel"; 
		    	document.myForm.action="CM_modAirHotel"; 
		    	//document.myForm.action="CM_ErrorPage?msg=Service Temporarily Not Available, Please Try Again Later.";
/*
							//----Check Bermuda HotelOnly
							if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BDA"){
								alert("Sorry, Bermuda Hotel only option is not available on web, \n Please see you your travel agent for pricing/booking");
								return false;
							}

							//----Check single adult not allowed for Bermuda	
							if(document.myForm.QQ_TYPE[0].checked && document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1){
									alert("Sorry, 1 Passenger option for Bermuda not available on web, \n Please call 1-888-468-6846");
								return false;
							}
							if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1){
									alert("Sorry, 1 Passenger option for Bermuda not available on web, \n Please call 1-888-468-6846");
								return false;
							}

							if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1){
									alert("Sorry, 1 Passenger option for Bermuda not available on web, \n Please call 1-888-468-6846");
								return false;
							}
*/
							if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BGI" ){
								alert("Sorry, Barbados Hotel only option is not available on web, \n Please call 1-800-650-3612 for pricing/booking");
								return false;
							}

				//----Block PUJ Landonly because of CC fraud ----
/*					if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="PUJ"){
		   			alert("Please Call 1-800-650-3612 to book Hotel Only at Punta Cana");
		   			return false;
					}

*/

		    	document.myForm.submit();
		    	
		}
    }
    else
    {  
    	//Condition when destination in charter 
    	// so all 3 selections available
    	if(!document.myForm.QQ_TYPE[0].checked)
    	{  
    	
			if(checkFitDate()){
				setFitMealPlan(myForm);
		    		//document.myForm.action="CM_modAirHotel"; 
		    		document.myForm.action="CM_modAirHotel"; 
		    		//document.myForm.action="CM_ErrorPage?msg=Service Temporarily Not Available, Please Try Again Later.";


				/*
				//----Check Bermuda HotelOnly
				if(document.myForm.QQ_TYPE[2].checked && document.myForm.Destination.value=="BDA"){
					alert("Sorry, Bermuda Hotel only option is not available on web, \n Please see you your travel agent for pricing/booking");
					return false;
				}
			
				//----Check single adult not allowed for Bermuda	
				if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1){
					alert("Sorry, 1 Passenger option not available for Bermuda");
					return false;
				}
			*/
					if(document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1){
					alert("Sorry, 1 Passenger option not available for Bermuda");
					return false;
				}


					//alert("2");
		    		document.myForm.submit();
			}
    	}
    	else
    	{  
    		if(checkDate()){
    			//setCharterMealPlan(myForm);
    			var hotelAvail = document.myForm.HOTEL_AVAIL.value;
    			//alert(hotelAvail);
    			//if(hotelAvail == "false")
    			//	document.myForm.action="QuickQuoteProcess";
    			//else
	    		//	document.myForm.action="PortalInterface"; 
	    					document.myForm.action="CM_modAirHotel";
	    		document.myForm.submit();
			}
    	}
    }
    
  

}
//-----------------------------

function setCharterMealPlan(myForm)
{
	//alert("Charter full MealPlan : " + document.myForm.MealPlan.value);
	var fullmealplan = document.myForm.MealPlan.value;
	if(fullmealplan != null){
		var mealplan = fullmealplan.split("-");
		//alert("Charter MealPlan : " + mealplan[0]);
		document.myForm.MealPlan.value = mealplan[0];
	}
}

//-----------------------------

function setFitMealPlan(myForm)
{
	var fullmealplan = document.myForm.MealPlan.value;
	if(fullmealplan != null){

	//	alert("Fit MealPlan : " + document.myForm.MealPlan.value);
		var fullmealplan = document.myForm.MealPlan.value;
		var mealplan = fullmealplan.split("-");
		//alert("Charter MealPlan : " + mealplan[1]);
		var hotelcode = mealplan[1];
		var fullHotelCode = document.myForm.CA_HOTEL_COMPONENT.value;
		var newHotelCode = fullHotelCode.substring(0,8);
		//alert("newHotelCode " + newHotelCode);
		document.myForm.CA_HOTEL_COMPONENT.value = newHotelCode + hotelcode;
		//alert("new full HotelCode " + document.myForm.CA_HOTEL_COMPONENT.value);
	}
}
//------------------------------------------------------------------
    function check330Fit(){
			depYear =  document.myForm.CA_DEP_YEAR.value;
			depMonth = document.myForm.CA_DEP_MONTH.selectedIndex-1;
			depDay = document.myForm.CA_DEP_DAY.selectedIndex;
			
			//alert("numDays:" +numDays);
			//alert(depMonth + ":" + depDay + ":" + depYear);
				date1 = new Date();
				date1Time = date1.getTime();
				dayOfWeek = date1.getDay();
				hourOfDay = date1.getHours();
				//alert("Day:" + dayOfWeek);
				//alert("hourOfDay:" + hourOfDay);
				date2 = new Date(depYear,depMonth,depDay,0,0,0,0);
				date2Time = date2.getTime();
			   d = (date2Time - date1Time);
			   days=d/(24*60*60*1000);
			 // alert("Days:" + days); 

			   if( days > 330){
			   	alert("Sorry, Cannot book Air beyond 330 days");
			   	return false;
				}
				
			   	if((days <= 3 && dayOfWeek == 5 && hourOfDay > 17)){
			   		alert("For booking Please call 1-800-262-0123 on  Monday");
			   		return false;
				}
			   else if( days <= 2 && dayOfWeek == 6 ){//Saturday can book Tuesday
			   		alert("For booking Please call 1-800-262-0123 on  Monday");
			   		return false;
				}
			  else if( days <= 1 && dayOfWeek == 0 ){//Sunday can book Tuesday
			   		alert("For booking Please call 1-800-262-0123 on  Monday");
			   		return false;
				}
			
			else if((days <=1 )&& (dayOfWeek == 1|| dayOfWeek ==2 || dayOfWeek == 3 || dayOfWeek == 4)){
				alert("There should be atleast one business day for your departure");	
				return false;
			}
 	return true;
} 

//------------------------------------------------------------------

function SetResetHotelDepCity()
{
   //alert("Set/Reset Function");
   
   if(getCookie("DV_SELECT"))
   { 
      readHotelRemember();
      	
   }
   else
   {
   	document.myForm.QQ_TYPE[0].checked=true;
      ShowFIT();
      loadDefaultDate();
   }
			
      //openPopInfo();
			 
   if (document.myForm.destCode.value != "null")
   { 
      document.myForm.Destination.value = document.myForm.destCode.value;
   } 
  resetCharterDestinations();
   loadBookingParams();
     			 
}

//--------------------------------------------------------------------------
//Get booking parameters from Garber, etc. All parameters start with "p_"
function loadBookingParams()
{
	
	 if (document.myForm.p_QQ_TYPE.value != null)
   {
   		if(parseInt(document.myForm.p_QQ_TYPE.value) == 2)
   		{
   			 document.myForm.QQ_TYPE[0].checked = true;
   			 changeDIV(document.myForm.QQ_TYPE[0]);
   		}
   		else if (parseInt(document.myForm.p_QQ_TYPE.value) == 3)
   		{
   			 document.myForm.QQ_TYPE[1].checked = true;
   			 changeDIV(document.myForm.QQ_TYPE[1]);
   		}
   		else if (parseInt(document.myForm.p_QQ_TYPE.value) == 1)
   		{
   			try{
   			 		document.myForm.QQ_TYPE[2].checked = true;
   			 		changeDIV(document.myForm.QQ_TYPE[2]);
   			}catch(E){
   					document.myForm.QQ_TYPE[0].checked = true;
   				  changeDIV(document.myForm.QQ_TYPE[0]);
   			}
   		}
   }

	 if (document.myForm.p_Gateway.value != null)
   {
   		var i = getGatewayIndex(document.myForm.p_Gateway.value);
   		if (i > 0)
  			 document.myForm.Gateway.selectedIndex = i;
	 }
	 	
	 // depdate, if passed, is passed in mmddyyyy form 
	 if ((document.myForm.p_depdate.value != null) && (document.myForm.p_depdate.value.length ==8))
   {
   	  var i = (document.myForm.p_depdate.value).substring(0,2);
   	  
   	  //ran into wierd problem (wouldn't work for aug and sept).
   	  //additional var j seems to solve it.
   	  if (i.substring(0,1) == "0") 
   	  	 		var j = parseInt(i.substring(1,2));
   	  else
   	  		 	var j = parseInt(i.substring(0,2));
   	  
   	  if ((j >=0 ) && (j<13))
      	 document.myForm.CA_DEP_MONTH.selectedIndex = i;
      	 
      i = parseInt((document.myForm.p_depdate.value).substring(2,4));
      if ((i >= 0) && (i<32))
      	 document.myForm.CA_DEP_DAY.selectedIndex = i;
      	 
      i = parseInt((document.myForm.p_depdate.value).substring(4,8));
      if ((i == 2006) || (i==2007))			//Alert, alert: hard-coded values.
      	document.myForm.CA_DEP_YEAR.selectedIndex = getDepYear((document.myForm.p_depdate.value).substring(4,8));
     
   }
	 
	 if (document.myForm.p_TourType.value != null || document.myForm.p_TourType.value != "null")
   { 
   		var i = parseInt(document.myForm.p_TourType.value);
   		
   		if(document.myForm.QQ_TYPE[0].checked || document.myForm.QQ_TYPE[1].checked)
   		{
   			 if (i == 7)
   			 		 document.myForm.TourType.selectedIndex = 1 ;
   			 else if ((i > 0) && (i < 22))
   			 		 document.myForm.TourType.selectedIndex = i;
   		}
   		else	//document.myForm.QQ_TYPE[2].checked is true
   			 document.myForm.TourType.selectedIndex = 1;
   	
   	  
	 }
    		
   if (document.myForm.p_NUM_ADULTS.value != null)
   {
   		if (document.myForm.p_NUM_ADULTS.value == 2)
   				document.myForm.NUM_ADULTS.selectedIndex = 0;
   		else if (document.myForm.p_NUM_ADULTS.value == 1)
   				document.myForm.NUM_ADULTS.selectedIndex = 1;
   		else  
   			{
   			var i = parseInt(document.myForm.p_NUM_ADULTS.value);
   			if (i > 0 && i < 7)
      		 document.myForm.NUM_ADULTS.selectedIndex = i-1;
   			}
   }
   
   if ((document.myForm.p_CHILD_AGE_0.value != null) ||(document.myForm.p_CHILD_AGE_0.value != "na"))
   {
   		var i = parseInt(document.myForm.p_CHILD_AGE_0.value);
   		if (i >=0 && i<19)
      	document.myForm.CHILD_AGE_0.selectedIndex = i + 1;
   }
  	
   if ((document.myForm.p_CHILD_AGE_1.value != null) ||(document.myForm.p_CHILD_AGE_1.value != "na"))
   {
   		var i = parseInt(document.myForm.p_CHILD_AGE_1.value);
   		if (i >=0 && i<19)
      	 document.myForm.CHILD_AGE_1.selectedIndex = i + 1;
   }
   
   if ((document.myForm.p_CHILD_AGE_2.value != null) ||(document.myForm.p_CHILD_AGE_2.value != "na"))
   {
   		var i = parseInt(document.myForm.p_CHILD_AGE_2.value);
   		if (i >=0 && i<19)
      	 document.myForm.CHILD_AGE_2.selectedIndex = i + 1;
   }
   
   if ((document.myForm.p_CHILD_AGE_3.value != null) ||(document.myForm.p_CHILD_AGE_3.value != "na"))
   {
   		var i = parseInt(document.myForm.p_CHILD_AGE_3.value);
   		if (i >=0 && i<19)
      	 document.myForm.CHILD_AGE_3.selectedIndex = i + 1;
   }	   
   
   try{
  // alert("'x" + document.myForm.p_PROMO_CODE.value.length + "x'");
   if ((document.myForm.p_PROMO_CODE.value.length >0 ))
   {
      document.myForm.PROMO_CODE.value = document.myForm.p_PROMO_CODE.value;
   }
  }
  catch(E){}
   
}
//--------------------------------------------------------------------------
function getGatewayIndex(gateway)
{
	for (i = 0; i < document.myForm.Gateway.options.length; i++)
	{
		if (document.myForm.Gateway.options[i].value.toUpperCase() == gateway.toUpperCase())
			return i;
	}
	return 0;
}
//--------------------------------------------------------------------------
function getDepYear(year)
{
	for (i = 0; i < document.myForm.CA_DEP_YEAR.options.length; i++)
	{
		if (document.myForm.CA_DEP_YEAR.options[i].value == year)
			return i;
	}
	return 0;
}
//--------------------------------------------------------------------------

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//----------------------------------------------------------------------
function readHotelRemember(){
    readValue = getCookie("DV_SELECT");
    //alert(readValue);
    var radioButtonChange = "false";
    
	arryVal = readValue.split("^")
	try{ 
	document.myForm.QQ_TYPE[arryVal[0]].checked = true;	
	changeDIV(document.myForm.QQ_TYPE[arryVal[0]]);
	}catch(E){ 
	document.myForm.QQ_TYPE[0].checked = true;
	changeDIV(document.myForm.QQ_TYPE[0]);
	//radio button used to be charter, but is now air_hotel
	radioButtonChange = "true";	
	}	
	
	if (radioButtonChange == "true")
	{ //Do not redo Gateway which has been set to Boston by ChangeDIV
	  //in case radio button changed from charter to air_hotel
	}
	else
	{
	document.myForm.Gateway.selectedIndex = arryVal[1];
	}
	
	document.myForm.Destination.value = arryVal[2];
	
	document.myForm.CA_DEP_MONTH.selectedIndex = arryVal[3];
	document.myForm.CA_DEP_DAY.selectedIndex = arryVal[4];
	document.myForm.CA_DEP_YEAR.selectedIndex = arryVal[5];
	try{
	document.myForm.TourType.selectedIndex = arryVal[6];
	
	}catch(e){
	document.myForm.TourType.selectedIndex = 1;
		
	}
	document.myForm.NUM_ADULTS.selectedIndex = arryVal[7];
	document.myForm.CHILD_AGE_0.selectedIndex = arryVal[8];
	document.myForm.CHILD_AGE_1.selectedIndex = arryVal[9];
	document.myForm.CHILD_AGE_2.selectedIndex = arryVal[10];
		
}
//------------------------------------------------------------------
//-----------------------------------------------------------------
// Given a string such as "CUN", it returns the index of Cancun in 
// fitDestArray, ie, it returns 5.
//-----------------------------------------------------------------
function findFitDestIndex(destCode)
{
	for (i = 0; i < fitDestArray.length; i++)
	{
	   destArray = fitDestArray[i].split(",");  
	   if (destCode.toUpperCase() == destArray[0].toUpperCase())
	   	{
	   	return i;
		}
	}
	return 0; 	//This should not normally occur.
}
//----------------------------------------------------------------------
//-----------------------------------------------------------------
// Given a string such as "CUN", it returns the index of Cancun in 
// charterDestArray, ie, it returns 3.
//-----------------------------------------------------------------
function findCharterDestIndex(destCode)
{
	for (i = 0; i < charterDestArray.length; i++)
	{
	   destArray = charterDestArray[i].split(",");  
	   if (destCode.toUpperCase() == destArray[0].toUpperCase())
	   	{
	   	return i;
		}
	}
	return 0; 	//This should not normally occur.
}

//------------------------------------------------------------------

function postHotelForm()
 {		
    //Condition when destination in non-charter 
    // so only nationwide and hotel-only available
    //if(document.myForm.QQ_TYPE[0].value != 1)
    
    if(document.myForm.QQ_TYPE[0].checked || document.myForm.QQ_TYPE[1].checked)
    {   
    	
    	if(!check330Fit())
   		return false;
   	
   	//alert("selection " + document.myForm.QQ_TYPE[0].value);
  	// alert( check330Fit()); 
  	 
   	//----Check single adult not allowed for Bermuda	
	     if(document.myForm.Destination.value=="BDA" && document.myForm.NUM_ADULTS.value <= 1)
	     {
       	     	alert("Sorry, 1 Passenger option not available for Bermuda");
	 						return false;
	     }
	     
	if(!checkFitDate())
	{
	   return false;
	}	
	else
	{
	   setFitMealPlan(myForm);
	  // document.myForm.action="CM_AirHotel"; 
		    document.myForm.action="CM_modAirHotel"; 	
	   //document.myForm.action="CM_ErrorPage?msg=Service Temporarily Not Available, Please Try Again Later.";
/*
	   //----Check Bermuda HotelOnly
	   if(document.myForm.QQ_TYPE[1].checked && document.myForm.Destination.value=="BDA"){
	   alert("Sorry, Bermuda Hotel only option is not available on web, \n Please see you your travel agent for pricing/booking");
	   return false;
							}
*/
						//----Single not allowed to BGI until7/15/2009 for FIT
						if(document.myForm.Destination.value=="BGI" && document.myForm.NUM_ADULTS.value <= 1){
							date_entered = new Date(document.myForm.CA_DEP_YEAR.value, document.myForm.CA_DEP_MONTH.value - 1, document.myForm.CA_DEP_DAY.value);
					d_date = new Date(2009, 9-1, 1);
					f_date = new Date(2009, 12-1, 18);
					e_time = date_entered.getTime();
					f_time = f_date.getTime();
					d_time = d_date.getTime();
					if ((e_time >= d_time)&&(e_time <= f_time))
							{
							   alert("Call 1-888-468-6846 to book single");
							   return false;
							}
						}
							   
	   setHotelRemember();
	   document.myForm.submit();
		    	
	}
		 if(! checkValidDays())
				return false;
    }
    else
    {  
    	//Condition when destination in charter 
    	// so all 3 selections available
    	if(!document.myForm.QQ_TYPE[2].checked)
    	{  
    	
	   if(!checkFitDate())
	   	return false;
	   else
	   {
	      setFitMealPlan(myForm);
	     // document.myForm.action="CM_AirHotel"; 
	     document.myForm.action="CM_modAirHotel";  
	      //document.myForm.action="CM_ErrorPage?msg=Service Temporarily Not Available, Please Try Again Later.";
	/*
	      //----Check Bermuda HotelOnly
	      if(document.myForm.QQ_TYPE[2].checked && document.myForm.Destination.value=="BDA")
	      {
	      alert("Sorry, Bermuda Hotel only option is not available on web, \n Please see you your travel agent for pricing/booking");
	      return false;
	      }
	*/
	     


	     //alert("2");
	     setHotelRemember();
	     document.myForm.submit();
	   }
    	}
    	else
    	{  
    	   if(!checkDate())
    	      return false;
    	   else
    	   {
    		//setCharterMealPlan(myForm);
    		var hotelAvail = document.myForm.HOTEL_AVAIL.value;
    		//alert(hotelAvail);
   // 		if(hotelAvail == "false")
   // 			document.myForm.action="QuickQuoteProcess";
   // 		else
	  //  		document.myForm.action="PortalInterface"; 
			document.myForm.action="CM_modAirHotel";    	
	    	setHotelRemember();
	    	document.myForm.submit();
	   }
    	}
    	
    	if(! checkValidDays())
				return false;
    }   
}
//------------------------------------------------------------------

function setHotelRemember()
{
	
	var iCD = "TRUE";
     	try
    	{
	   iCD = document.myForm.isCharterDest.value;
     	}
     	catch(e)
     	{
	   iCD = "TRUE";
     	}
        
	if (qqType = document.myForm.QQ_TYPE[1].checked){
		qqType=1;
		//alert("qqType="+ qqType);
		destination = findFitDestIndex(document.myForm.Destination.value)+1;
	}
	else if (qqType = document.myForm.QQ_TYPE[0].checked){
		qqType=0;
		//alert("document.myForm.Destination is : " + document.myForm.Destination.value);
		//alert("qqType="+ qqType);
		destination = findFitDestIndex(document.myForm.Destination.value)+1;
	}
	else if (iCD.toUpperCase()=="TRUE"){
		if (qqType = document.myForm.QQ_TYPE[2].checked){
		qqType=2;
		//alert("qqType="+ qqType);
		destination = findCharterDestIndex(document.myForm.Destination.value)+1;
		}
	}
	
	//alert("qqType is : " + qqType);
	gateway = document.myForm.Gateway.selectedIndex;
	//alert("gateway=" + gateway);
	//destination = document.myForm.Destination.selectedIndex;
	//myForm.Destination is not a field in a list, but value in a hidden text field.
	
	depDay = document.myForm.CA_DEP_DAY.selectedIndex;
	//alert("depDay=" + depDay);
	depMonth = document.myForm.CA_DEP_MONTH.selectedIndex;
	//alert("depMonth=" + depMonth);
	depYear = document.myForm.CA_DEP_YEAR.selectedIndex;
	//alert("depYear=" + depYear);
	numDays = document.myForm.TourType.selectedIndex;
	
	numAdults= document.myForm.NUM_ADULTS.selectedIndex;
	childAge0= document.myForm.CHILD_AGE_0.selectedIndex;
	childAge1= document.myForm.CHILD_AGE_1.selectedIndex;
	childAge2= document.myForm.CHILD_AGE_2.selectedIndex;
	childAge3= document.myForm.CHILD_AGE_3.selectedIndex;

	var nowDate = new Date();
    	var expires = new Date(nowDate.getTime() + (1*24*60*60*1000));
	//DV_SELECT=qqType^gateway^destination^depMonth^depDay^depYear
	DV_SELECT=qqType +"^" + gateway +"^" + destination +"^" + depMonth +"^" + depDay +"^" + depYear +"^" + numDays +"^" + numAdults +"^" + childAge0 +"^" + childAge1 +"^" + childAge2 +"^" + childAge3; 
	//alert("set cookie=" + DV_SELECT);
	setCookie("DV_SELECT",DV_SELECT,expires);
			
}

//----------------------------------------------------------------------
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
//----------------------------------------------------------------------
function resetCharterDestinations()
{
//	alert("Hi");
	var destSelected = document.myForm.Gateway.value;
//	alert(destSelected);

}

//------------------------------------------------------------------------
function checkValidDays(){
	  var month = document.myForm.CA_DEP_MONTH.selectedIndex;
	  var day = document.myForm.CA_DEP_DAY.selectedIndex;
		var year = document.myForm.CA_DEP_YEAR.value;

		if(year==2004 && month==02 && day==29){
				//alert("leap Year");
			 return true;
		}
		if(((month==02)) && ((day==29) || (day==30) || (day==31)))
		{
				alert("Please select a valid day for February");
				document.myForm.CA_DEP_MONTH.focus();
				return false;
		}
		if(((month==04)||(month==06))  && (day==31))
		{
				alert("Please select a valid day for this month" );
				document.myForm.CA_DEP_MONTH.focus();
				return false;
		}
		if(((month==09)||(month==11))  && (day==31))
		{
				alert("Please select a valid day for this month" );
				document.myForm.CA_DEP_MONTH.focus();
				return false;
		}

		if(! check330Fit())
				return false;
		else
				return true;
}
//------------------------------------------------------------------------
function changeYear(){
	var month= document.myForm.CA_DEP_MONTH.value;
	//alert(month);
	if( month!=12){
		//alert("change");
		document.myForm.CA_DEP_YEAR.selectedIndex=2;
	}
}