// booking_plan.js

<!-- hide
var selectedOriginIso = "";
var combinedFaresList; // array of combinedFares Flag values
var originChanged = "false;"
var backupFaresList;
var newlySelectedOriginIso;
var fareListText;
var fareListValues;

var returnedCat = "null";
var returnedItem = "null";

var IE4 = (document.all) ? 1 : 0;
var isNS3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3);
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var cats = new Array();
var OpenJawArray = new Array();
var DestOpenJawArray = new Array();
var classType = new Array();
var catsIndex = -1;
var openJawIndex = -1;
var classIndex = -1;
var itemsIndex = -1;
var OpenJawItemIndex = -1;
var classTypeIndex = -1;
var catHeading = '1. Choose your departure point&nbsp;';
var itemHeading = '2. Choose your destination point ';
var betweenHeading = '</td><td width=234 nowrap align=right>';
var hasLoaded = false;
var exist = false;
var bkkOption = null;
var bkkIndex = 0;

<!------------------------------------------------------------------------------------------------>
function addHeadings(item) {
    if (!IE4) {
        origin.addItem(catHeading);
        for (var i = 0; i < cats.length; i++) {
            origin.addItem(cats[i].name);
        }
        origin.listIndex = 0;
    destination.addItem(itemHeading);
        destination.listIndex = 0;
    }
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
 function makeItem(name, url) {
    this.name = name;
    this.url = url;
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
 function makeOpenJawItem(name, url , sundorPoint  , elalPoint) {
    this.name = name;
    this.url = url;
    this.sundorPoint = sundorPoint;
    this.elalPoint = elalPoint;
    this.length = 0;
}
<!------------------------------------------------------------------------------------------------>


<!------------------------------------------------------------------------------------------------>
function arrivalPoint(name, url) {
    itemsIndex++;
    cats[catsIndex][itemsIndex] = new makeItem(name, url);
    cats[catsIndex].length++;
}
<!------------------------------------------------------------------------------------------------>

function OpenJawDestinationPoint(name, url , sundorPoint , elalPoint) {
    OpenJawItemIndex++;
     
    OpenJawArray[openJawIndex][OpenJawItemIndex] = new makeOpenJawItem(name, url , sundorPoint , elalPoint);
    OpenJawArray[openJawIndex].length++;
}
<!------------------------------------------------------------------------------------------------>





<!------------------------------------------------------------------------------------------------>
function makeCat(name, url) {
    this.name = name;
    this.url = url;
    this.length = 0;
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function departurePoint(name, url) {
    catsIndex++;
    itemsIndex = -1;    
    cats[catsIndex] = new makeCat(name, url); 
   
}
<!------------------------------------------------------------------------------------------------>

 function OpenJawdeparturePoint(name, url, sundorPoint , elalPoint) {  
   
    openJawIndex++;
   
    OpenJawItemIndex = -1;    
    OpenJawArray[openJawIndex] = new makeOpenJawItem(name, url, sundorPoint , elalPoint);    
     
    
}
<!------------------------------------------------------------------------------------------------>

 
function initClassType(name, url) {
    classIndex++;    
    classTypeIndex = -1;    
    classType[classIndex] = new makeCat(name, url);
    
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function setTicketClassType(name, url) {
	classTypeIndex++;
	classType[classIndex][classTypeIndex] = new makeItem(name, url);
	classType[classIndex].length++;		
}

<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function checkLegalCity(errorsAlert)
{
	var departuresList = eval('document.booking_request.departures');
    var destinationList = eval('document.booking_request.destinations');
    
    if( departuresList.selectedIndex == 0 ){
  		alert(errorsAlert[0]);
  		//alert ("Please choose departure city");
  		return 0;
    } 
    if( destinationList.length > 1 && destinationList.selectedIndex == 0 ){
  		alert(errorsAlert[1]);
  		//alert ("Please choose destination city");
  		return 0;
    } 
	if(departuresList.options[departuresList.selectedIndex].value == destinationList.options[destinationList.selectedIndex].value)
    {
   		alert(errorsAlert[2]);
   		//alert("Departure city and destination city\n can't be the same!");     	     	
 		return 0;
    }
     
   	return 1;
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function makeDestinationsList(index){
     
     var destinationList = document.booking_request.destinations;//eval('');
    
     //clear destinationList;
     for (i=0;i<destinationList.options.length;i++)
     {     	
     	destinationList.options[i] = null;
     }
      destinationList.options.length=0;   

      

    var numOfItems = cats[index].length;
   
    var itemIndex = 0;
    
    for (j = 0 ;  j < numOfItems ;j++){		      
      url = cats[index][j].url;
      name = cats[index][j].name;
      destinationList.options[itemIndex++] = new Option(name,url);     
    }
   
     	
}

<!------------------------------------------------------------------------------------------------>
function makeOpenJawReturnDeparturesList(index){
     
   
     isSundorPoint = (OpenJawArray[0][index].sundorPoint == "1"); 
     var destinationList = document.booking_request.destinations;//eval('');
     var returnDeparturesCities = document.booking_request.returnDepartureCities;//eval('');
	 
    
     //clear destinationList;
     for (i=0;i<returnDeparturesCities.options.length;i++)
     {     	
      	returnDeparturesCities.options[i] = null;
     }
       returnDeparturesCities.options.length=0;   

    var numOfItems = OpenJawArray[0].length;
   
    var itemIndex = 0;
    
    for (j = 0 ;  j < numOfItems ;j++){		      
      url = OpenJawArray[0][j].url;
      name = OpenJawArray[0][j].name;
        if(OpenJawArray[0][j].sundorPoint == "1" || isSundorPoint){
    	  returnDeparturesCities.options[itemIndex++] = new Option(name,url);     
   		 }
    }
   
     	
}

<!------------------------------------------------------------------------------------------------>
function makeOpenJawDestinationsList(index){
     
   
     isOnlyELALPoint = (OpenJawArray[0][index].sundorPoint == "1"); 
     var destinationList = document.booking_request.destinations;//eval('');
     var returnDeparturesCities = document.booking_request.returnDepartureCities;//eval('');
	 
    
     //clear destinationList;
     for (i=0;i<returnDeparturesCities.options.length;i++)
     {     	
      	returnDeparturesCities.options[i] = null;
     }
       returnDeparturesCities.options.length=0;   

    var numOfItems = OpenJawArray[0].length;
   
    var itemIndex = 0;
    
    for (j = 0 ;  j < numOfItems ;j++){		      
      url = OpenJawArray[0][j].url;
      name = OpenJawArray[0][j].name;
        if(OpenJawArray[0][j].sundorPoint == "1" || !isOnlyELALPoint){
    	  returnDeparturesCities.options[itemIndex++] = new Option(name,url);     
   		 }
    }
   
     	
}





<!------------------------------------------------------------------------------------------------>
function makeOpenJawReturnFromList(index){
     
     var returnFromList = document.booking_request.OpenJawDepartures;//eval('');
    
    		
     //clear destinationList;
     for (i=0;i<returnFromList.options.length;i++)
     {     	
     	returnFromList.options[i] = null;
     }
     
      returnFromList.options.length=0;   

       
    
    var numOfItems = OpenJawArray[index].length;
    var itemIndex = 0;
	 
	// Not Available return cities 
	//alert(OpenJawArray[index][0].name);
	// alert(name = OpenJawArray[index][0].url);
     
	if(j==0){
	
	alert("There are not available cities to return from");
				
	  url =  "Please Choose another departure city" ;
      name = "Please Choose another departure city" ;
      
      returnFromList[itemIndex++] = new Option(name,url);     
      
	}
	 
	
    for (j = 0 ;  j < numOfItems ;j++){	
    	      
      url = OpenJawArray[index][j].url;
      name = OpenJawArray[index][j].name;
      
      returnFromList[itemIndex++] = new Option(name,url);     
      
    }
     	
}
<!------------------------------------------------------------------------------------------------>
function updateClassTypeList(depCityValue, value)
{
	var classTypeList = eval('document.forms[0].classTypes');
	var depCityIndex;
	//loop to find the departure city index in the classTypes array 
	for ( var i=0; i<classType.length; i++)
	{
		if (classType[i].url == depCityValue)
		{
			depCityIndex = i;
			break;
		}
	}

	//save the corrent classType
	//var selectionIndex = findIndex(classTypeList,value);

	//clear the classType option list
	classTypeList.options.length=0;
	var numOfItems = classType[depCityIndex].length;
	var itemIndex = 0;	
	
	for (i=0; i < numOfItems; i++) {
		name = classType[depCityIndex][i].name;
		url = classType[depCityIndex][i].url;		
		classTypeList.options[itemIndex++] = new Option(name,url);				
	}	
		//classTypeList.selectedIndex = selectionIndex;
}
<!------------------------------------------------------------------------------------------------>
function updateClassTypeList1(depCityValue,destCityValue)
{		
	var isSpecialFateAvailable = document.forms[1].isSpecialFareAvailable.value;
	var depCityIndex;
	var destCityIndex;
	//first we find the index of the departure city and the destination city in the classType array
	for ( var i=0; i<classType.length; i++)
	{
		if (classType[i].url == depCityValue)
		{
			depCityIndex = i;
			break;
		}
	}
	
	for ( var i=0; i<classType.length; i++)
	{
		if (classType[i].url == destCityValue)
		{
			destCityIndex = i;
			break;
		}
	}
	
	
	var classTypeList = eval('document.forms[0].classTypes');
	//clear the classType option list
	for (i=0;i<classTypeList.options.length;i++)
     {     	
     	classTypeList.options[i] = null;
     }
	classTypeList.options.length=0;
	
	exist = false;
	k=0;
	//first loop for all the departureCity classType 
	for (i = 0; i < classType[depCityIndex].length; i++)
	{
		exist = false;
		
		// if the class type is "special fare" (code 4) or "Students special fare" (code 8)  
		// and the departure city is TLV - show the class type, regardless the destination city.
		if ( ("true" == isSpecialFateAvailable) && (depCityValue == "TLV") & ((classType[depCityIndex][i].url == "4") || (classType[depCityIndex][i].url == "8")) )
		{
			exist = true;
		}
		else
		{ 
			//second loop to check for each departure city classType, if it exist in the destination city classType list.
			for (j = 0; j < classType[destCityIndex].length; j++)
			{
				
				if (classType[depCityIndex][i].url == classType[destCityIndex][j].url)
					exist = true;						
			}
		}
		//put the class type which exist ob both lists in the options list		
		if (exist == true)
		{
			name = classType[depCityIndex][i].name;
			url = classType[depCityIndex][i].url;
			classTypeList.options[k++] = new Option(name,url);			
		}						
	}
	
	sortListByValue(classTypeList);	
}


<!------------------------------------------------------------------------------------------------>
//depricated from version 1.1

function updateClassTypeList2(depCityValue,destCityValue)
{		
	var depCityIndex;
	var destCityIndex;
	//first we find the index of the departure city and the destination city in the classType array
	for ( var i=0; i<classType.length; i++)
	{
		if (classType[i].url == depCityValue)
		{
			depCityIndex = i;
			break;
		}
	}
	
	for ( var i=0; i<classType.length; i++)
	{
		if (classType[i].url == destCityValue)
		{
			destCityIndex = i;
			break;
		}
	}
	
	
	var classTypeList = eval('document.forms[0].classTypes');
	//clear the classType option list
	for (i=0;i<classTypeList.options.length;i++)
     {     	
     	classTypeList.options[i] = null;
     }
	classTypeList.options.length=0;
	
	exist = false;
	k=0;
	//first loop for all the departureCity classType 
	for (i = 0; i < classType[depCityIndex].length; i++)
	{
		exist = false;
		//second loop to check for each departure city classType, if it exist in the destination city classType list.
		for (j = 0; j < classType[destCityIndex].length; j++)
		{
			
			if (classType[depCityIndex][i].url == classType[destCityIndex][j].url)
				exist = true;						
		}
		//put the class type which exist ob both lists in the options list		
		if (exist == true)
		{
			name = classType[depCityIndex][i].name;
			url = classType[depCityIndex][i].url;
			classTypeList.options[k++] = new Option(name,url);			
		}						
	}
	
	sortListByValue(classTypeList);	
}

<!------------------------------------------------------------------------------------------------>
function sortListByValue( list )
{
	for (i=0; i<list.options.length; i++)
		for (j=0; j < list.options.length-i-1; j++) 
		{
			if (list.options[j].value > list.options[j+1].value)
			{				
				name = list.options[j].text;
				code = list.options[j].value;
				list.options[j] = new Option(list.options[j+1].text, list.options[j+1].value);
				list.options[j+1] = new Option(name,code);
			}
		}
}
<!------------------------------------------------------------------------------------------------>
function findInitSelectedClass()
{
	var economy = 3;
	var numOfTypes = document.forms[0].classTypes.options.length;
	
	for (var i=0; i<numOfTypes; i++)
	{
		if (document.forms[0].classTypes.options[i].value == economy)
			{
				document.forms[0].classTypes.options.selectedIndex = i;
				break;
			}
	}
}
<!------------------------------------------------------------------------------------------------>
<!--------------------------------------------------------------------------------------------------------------------------------------------%>
	function findIndex(list,value)
	{				
		for (var i = 0; i < list.length; i++)
		{
			if (list.options[i].value == value)
			{
				list.selectedIndex = i;							
				return i;
			}			
		}
		return -1;
	}
	
	
	
<!--------------------------------------------------------------------------------------------------------------------------------------------%>
	

	function typeOfTrip(){
	
	
	
	var typeofTrip;
	var selectedIndex = document.getElementById("tripRadioID0");
	
	if (eval(document.getElementById("tripRadioID0").checked) == true) typeofTrip = 0;
	if (eval(document.getElementById("tripRadioID1").checked) == true) typeofTrip = 1;
	if (eval(document.getElementById("tripRadioID2").checked) == true) typeofTrip = 2;
	
	
	switch(typeofTrip) {

            case 0:                 

				  
				  removeBkkFromDestList();
                  document.booking_request.retDaySelect.disabled = true;

                  document.booking_request.retMonthSelect.disabled      =  true;

                  document.booking_request.retYearSelect.disabled       =  true;

                 
                  
                  document.getElementById("retCalendarLink").href    = ("#");

                 // document.booking_request.retCalendarDis.style.display = "none";

                  document.booking_request.tripRadioID0.checked = true; 
                  
                 showOpenJawElements(false)
				
                 	setRoundTripCities();
                 
                   break;

            case 1: 
					if(bkkOption != null){
						returnBKKToList();
					 }
					 
                  document.booking_request.retDaySelect.disabled = false;

                  document.booking_request.retMonthSelect.disabled      = false;

                  document.booking_request.retYearSelect.disabled       = false;
				
				  document.getElementById("retCalendarLink").href     ='javaScript:showCalendarReturn();';
                 
                 // document.booking_request.retCalendar.style.display = "";

                  //document.booking_request.retCalendarDis.style.display =  "";

				  document.booking_request.tripRadioID1.checked = true; 
				  
				 showOpenJawElements(false)
				  
				  setRoundTripCities();
                
                  break;
		// OpenJaw
 		case 2: 
					if(bkkOption != null){
						returnBKKToList();
					 }
					
                  document.booking_request.retDaySelect.disabled = false;

                  document.booking_request.retMonthSelect.disabled      = false;

                  document.booking_request.retYearSelect.disabled       = false;
				
				  document.getElementById("retCalendarLink").href     ='javaScript:showCalendarReturn();';
                 
                  // document.booking_request.retCalendar.style.display = "";

                  //document.booking_request.retCalendarDis.style.display =  "";

				  //document.booking_request.tripRadioID2.checked = true; 
				  showOpenJawElements(true)
				  
				 
				   
				  
				 setOpenJawCities();
                
                  break;        

          

      }

}

function showOpenJawElements(show){
	 
	 for(i = 1 ; i < 7 ; i++){
	 	document.getElementById("OpenJawTr" + i).style.display = show ? "" : "none";
	 			  
	 }
	 document.getElementById("openJawTR").style.display = show ? "" : "none";
		
}

// OpenJaw
function setOpenJawCities(){
	  var departuresList = document.booking_request.departures;//eval('');
	  var destinationList = document.booking_request.destinations;//eval('');
	  var returnDeparturesCities = document.booking_request.returnDepartureCities;//eval('');
	  var returnDestinationCities = document.booking_request.returnDestinationCities;//eval('');
    
     //clear destinationList;
     for (i=0;i<departuresList.options.length;i++)
     {     	
     	departuresList.options[i] = null;
     }
      departuresList.options.length=0; 
      
       for (i=0;i<destinationList.options.length;i++)
     {     	
     	destinationList.options[i] = null;
     }
      destinationList.options.length=0;
      
       
      
        for (i=0;i<returnDeparturesCities.options.length;i++)
     {     	
     	returnDeparturesCities.options[i] = null;
     }
     	returnDeparturesCities.options.length=0;  
      
       for (i=0;i<returnDestinationCities.options.length;i++)
     {     	
     	returnDestinationCities.options[i] = null;
     }
      returnDestinationCities.options.length=0;    

      url = OpenJawArray[0].url;
      name = OpenJawArray[0].name;
      departuresList.options[0] = new Option(name,url); 
      returnDestinationCities.options[0] = new Option(name,url);     
    itemIndex = 0;
     
   for(i = 0 ; i < OpenJawArray[0].length ; i++ ){
  		 url = OpenJawArray[0][i].url;
         name = OpenJawArray[0][i].name;
         destinationList.options[itemIndex++] = new Option(name,url);   
   }
   itemIndex = 0;
   for(i = 0 ; i < OpenJawArray[0].length ; i++ ){
  		 url = OpenJawArray[0][i].url;
         name = OpenJawArray[0][i].name;
         returnDeparturesCities.options[itemIndex++] = new Option(name,url);   
   }

}

// OpenJaw
function setRoundTripCities(){
	  var departuresList = document.booking_request.departures;//eval('');
	  var destinationList = document.booking_request.destinations;//eval('');
	  var returnDeparturesCities = document.booking_request.returnDepartureCities;//eval('');
	  var returnDestinationCities = document.booking_request.returnDestinationCities;//eval('');
    
     //clear destinationList;
     for (i=0;i<departuresList.options.length;i++)
     {     	
     	departuresList.options[i] = null;
     }
      departuresList.options.length=0; 
      
       for (i=0;i<destinationList.options.length;i++)
     {     	
     	destinationList.options[i] = null;
     }
      destinationList.options.length=0;
    tlvIndex = 0;  
    for(i = 0 ; i < cats.length ; i++ ){
  		 
         if(cats[i].url == "TLV"){
         	tlvIndex = i;
         }
         
   }    
      
            
    itemIndex = 0;
     
   for(i = 0 ; i < cats.length ; i++ ){
  		 url = cats[i].url;
         name = cats[i].name;
         departuresList.options[itemIndex++] = new Option(name,url);   
   }
   departuresList.selectedIndex = tlvIndex;
   itemIndex = 0;
   
  for(i = 0 ; i < cats[tlvIndex].length ; i++ ){
  		 url = cats[tlvIndex][i].url;
         name = cats[tlvIndex][i].name;
         destinationList.options[itemIndex++] = new Option(name,url);   
   }
}



<!-------------------------------------------------------------------------------------------------!>

	function removeBkkFromDestList(){
	
	 var destinationList = document.booking_request.destinations;//eval('');
       //clear destinationList;
     for (i=0;i<destinationList.options.length;i++)
     {     	
     		if(destinationList.options[i].value == "BKK"){
     						bkkOption = destinationList.options[i];
     						destinationList.options[i] = null;
     						bkkIndex = i ;
     						bkkExist = true;
    						
    		 }
      }
	
	
}

<!-------------------------------------------------------------------------------------------------!>

	function returnBKKToList(){
      var departureList = eval('document.booking_request.departures');
	  var destinationList = document.booking_request.destinations;//eval('');
	 // alert(destinationList.options[destinationList.selectedIndex].value);	
 	  var cityName = destinationList.selectedIndex;
    
    if(departureList.options[departureList.selectedIndex].value == "TLV"){
	 
    if(bkkExist){
   	  addElement( destinationList  , bkkOption.text , bkkOption.value ,bkkIndex );
   		if(cityName > bkkIndex)
   			destinationList.selectedIndex =  cityName + 1 ; 
  		else 
  			destinationList.selectedIndex =  cityName ; 
   }

	 }
	 
	 
}



<!-------------------------------------------------------------------------------------------------!>

function compareOptionValues(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.value, 36 );  

  var sB = parseInt( b.value, 36 );  

  return sA - sB;

}





// Compare two options within a list by TEXT
<!-------------------------------------------------------------------------------------------------!>

function compareOptionText(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.text, 36 );  

  var sB = parseInt( b.text, 36 );  

  return sA - sB;

}

<!-------------------------------------------------------------------------------------------------!>

function updateCities(depCity , destCity , returnDepCity){
      var departuresList = document.booking_request.departures;//eval('');
	  var destinationList = document.booking_request.destinations;//eval('');
	  var returnDeparturesCities = document.booking_request.returnDepartureCities;//eval('');
	  var returnDestinationCities = document.booking_request.returnDestinationCities;//eval('');
    
    
	 //if(document.booking_request.tripRadioID2.checked){
	 // var index = findIndex(destinationList , destCity); 
     // var index = findIndex(returnDeparturesCities , returnDepCity); 
	 
	
	//}
	 if(document.booking_request.tripRadioID1.checked){
	    onChangeCity(0); 
		
	    findIndex(departuresList , depCity); 
	    findIndex(destinationList , destCity); 
    }
}

var ROUND_TRIP_LEG = '1';
var OPENJAW_LEG = '2';   

function isRareLeg(){
	
	var depCity = document.booking_request.departures.value;
	var destCity = document.booking_request.destinations.value;
	var returnDepCity = document.booking_request.returnDepartureCities.value;
	var returnDestCity = document.booking_request.returnDestinationCities.value;
	var isOpenJaw = document.getElementById("tripRadioID2").checked;
	var depLegRare = false;
	var retLegRare = false;
	for(var i = 0 ; i < rareLegs.length ; i++){
		if(!isOpenJaw){
			if( rareLegs[i].from == depCity && rareLegs[i].to == destCity && rareLegs[i].legType == ROUND_TRIP_LEG   ){
				depLegRare = true;
			}
		} else {
			if( rareLegs[i].from == depCity && rareLegs[i].to == destCity && rareLegs[i].legType == OPENJAW_LEG ){
				depLegRare =  true;
			}
			if( returnDepCity == rareLegs[i].to && returnDestCity == rareLegs[i].from && rareLegs[i].legType == OPENJAW_LEG){
				retLegRare =  true;
			}
		}
		
	}
	return  depLegRare || retLegRare;
}
		 
		 