// 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 classType = new Array();
var catsIndex = -1;
var classIndex = -1;
var itemsIndex = -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 ONLY_BOARD_POINT_DEPARTURE_CITIES = 0;
var ALL_DEPARTURE_CITIES = 1;


// changes the outbound departure cities for Employee make reservation
function switchCitiesLists(depCityLists){
 
	switch(depCityLists){
		
		case ONLY_BOARD_POINT_DEPARTURE_CITIES : {
			refreshList(document.getElementById("origin") , document.getElementById("originCopy") );
		    clearCatsAndItems();
			initPage();
			onChangeCity(0);
			break;
			
		}
		case ALL_DEPARTURE_CITIES : {
			 refreshList(document.getElementById("origin") , document.getElementById("allOrigin") );
			 refreshList(document.getElementById("destination") , document.getElementById("destinationCopy") ); // refresh outbound dest list
			 refreshList(document.getElementById("retDestinations") , document.getElementById("retDestinationsCopy") );// refresh inbound dest list
		 	 copyDepCityToRetDestCity(); // copy return destination city from outbound departure city
			 
			 clearCatsAndItems();
			 initAllCities();
			 break;
		}
	}
	 
	 


}

// Clear all city relations arrays
function clearCatsAndItems(){
	cats.length = 0;
	catsIndex = -1;
    itemsIndex = -1;
}

function hideShowElem(elemId , isShow){
	document.getElementById(elemId).style.display = isShow ? "" : "none";
}




<!------------------------------------------------------------------------------------------------>
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 , cityType) {
    this.name = name;
    this.url = url;
    this.cityType = cityType;
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function arrivalPoint(name, url , cityType) {
    itemsIndex++;
    cats[catsIndex][itemsIndex] = new makeItem(name, url , cityType);
    cats[catsIndex].length++;
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function makeCat(name, url , cityType) {
    this.name = name;
    this.url = url;
    this.cityType = cityType;
    this.length = 0;  
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>
function departurePoint(name, url, cityType) {
    catsIndex++;
    itemsIndex = -1;    
    cats[catsIndex] = new makeCat(name, url , cityType ); 
    
    
}
<!------------------------------------------------------------------------------------------------>

<!------------------------------------------------------------------------------------------------>

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.getElementById("getSpecialFares").origin');
    var destinationList = eval('document.getElementById("getSpecialFares").destination');
   
    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.getElementById("getSpecialFares").destination;
  
   
     //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;
      

      if(cats[index].cityType == cats[index][j].cityType){
      	destinationList.options[itemIndex] = new Option(name,url);
      	
      	 if(cats[index][j].cityType == SUNDOR_CITY){
      		destinationList.options[itemIndex].className = "sundorCity";
 	 	 }
 	 	 itemIndex++;  
      }
      // For sundor destination color the option in orange
      
  	  
    }
    sortListByName(destinationList);
    
   
     	
}
<!------------------------------------------------------------------------------------------------>
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;
				var tmpClassName = list.options[j+1].className;
				list.options[j] = new Option(list.options[j+1].text, list.options[j+1].value);
				list.options[j+1] = new Option(name,code);
				list.options[j+1].className = list.options[j].className;
				list.options[j].className = tmpClassName;
				
				
			}
		}
}
<!------------------------------------------------------------------------------------------------>
function sortListByName( list )
{
	for (i=0; i<list.options.length; i++)
		for (j=0; j < list.options.length-i-1; j++) 
		{
			if (list.options[j].text > list.options[j+1].text)
			{				
				name = list.options[j].text;
				code = list.options[j].value;
				var tmpClassName = list.options[j+1].className;
				list.options[j] = new Option(list.options[j+1].text, list.options[j+1].value);
				list.options[j+1] = new Option(name,code);
				list.options[j+1].className = list.options[j].className;
				list.options[j].className = tmpClassName;
				
				
			}
		}
}
<!------------------------------------------------------------------------------------------------>

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 changeOptionClass(listId , value , newClassName){
		
	   var list = document.getElementById(listId);	
      for (var i = 0; i < list.length; i++)
		{
			if (list.options[i].value == value)
			{
				 list.options[i].className = newClassName;
			}			
		}
      
	
	}

<!------------------------------------------------------------------------------------------------>
function makeDepList(index){
     sortCats();
     var destinationList = document.getElementById("getSpecialFares").origin;
    
    
     //clear destinationList;
     for (i=0;i<destinationList.options.length;i++)
     {     	
     	destinationList.options[i] = null;
     }
      destinationList.options.length=0;   

     
    var numOfItems = cats.length;

    var itemIndex = 0;

    for (j = 0 ;  j < numOfItems ;j++){		      
      url = cats[j].url;
      name = cats[j].name;
       
      destinationList.options[itemIndex] = new Option(name,url);
      if(cats[j].cityType == SUNDOR_CITY){
      	destinationList.options[itemIndex].className = "sundorCity";
 	  }
 	    
 	  itemIndex++;  
    }
    
    //sortListByName(destinationList);
    
   
     	
}

function sortCats(){
	tlvIdx = 1;
 	for (i=0; i<cats.length; i++)
		for (j=0; j < cats.length-1; j++) 
		{	//alert(cats[j])
			if (cats[j].name > cats[j + 1].name)
			{	 
				replaceCats(j , j+1);	
				 
			 }
		}
		
		moveCatToIndex(getCatsIndexByCodeAndType('000' , ELAL_CITY), 0);
		moveCatToIndex(getCatsIndexByCodeAndType('TLV' , ELAL_CITY), 1);
		moveCatToIndex(getCatsIndexByCodeAndType('TLV' , SUNDOR_CITY), 2);		
 		remoevCatsByCode('000' , SUNDOR_CITY);
}


function getCatsIndexByCodeAndType(code , cityType){
	
	for (i=0; i<cats.length; i++){
		if(cats[i].url == code && cats[i].cityType == cityType){
			return [i];
		}
	}
	return null;
}

function replaceCats(indexOne , indexTwo){
	if(indexOne == null || indexTwo == null){
		return null;
	}
	var tmpCats = cats[indexOne];
	cats[indexOne] = cats[indexTwo];
	cats[indexTwo] = tmpCats;
}

function moveCatToIndex(formIndex, toIndex) {
	if(formIndex == null || toIndex == null){
		return null;
	}
	var tmpCats = cats[formIndex];
	cats.splice(formIndex , 1);
	cats.splice(toIndex , 0, tmpCats);
}



function remoevCatsByCode(code , cityType){
	for (i=0; i<cats.length; i++){
		if(cats[i].url == code && cats[i].cityType == cityType){
			replaceCats(i , cats.length-1);
			cats.splice(cats.length - 1 , 1)
			cats.length
			return;
			
		}
	}
}
	
<!--------------------------------------------------------------------------------------------------------------------------------------------%>
	var selectCityIds = new Array("origin" ,"destination" , "retDepartures" , "retDestinations", "viaFrom", "viaTo");
	var selectCityIdsForSend = new Array("origin" ,"destination" , "returnFrom" , "returnTo", "viaFrom", "viaTo");
	var isBeyondSearch = false; // Default show normal select cities
	var DEPARTURE_CITY_1    = 1;
	var DESTINATION_CITY_1  = 2;
	var DEPARTURE_CITY_2    = 3;
	var DESTINATION_CITY_2  = 4;
	var DEPARTURE_CITY_3    = 5;
	var DESTINATION_CITY_3  = 6;
	/*
	/	btnElem - button that fires that function	
	/	show beyond inputs or normal input
	*/
	function showHideBeyond(btnElem){
		  makeBeyond = !isBeyondSearch;
		  isBeyondSearch  = isBeyondSearch ? false  : true;
		  btnElem.value = makeBeyond ? "Elal Flights" : "Elal Beyond"; 
		  for(var i = 0 ; i < selectCityIds.length ; i++){
		 		var element = document.getElementById(selectCityIds[i]);
		 		var elementBeyond = document.getElementById(selectCityIds[i] + "BeyondText")
		 		if (element != null) {
		 			element.style.display = makeBeyond ? "none" : "";
		 		}
		 		if (elementBeyond != null) {
		 			elementBeyond.style.display = makeBeyond ? "" : "none";
		 		}
		 }
		 document.getElementById("systemId").value = makeBeyond ? "10" : "1";
		 
		 //open via line if needed
		 var viaElement = document.getElementById("via");
		 if (viaElement != null) {
		 	viaElement.style.display = makeBeyond ? "" : "none";
		 }
		 
	}
	
	
	function updateBeyondCities(currElement , beyondCityIndex){
		currElement.value = currElement.value.toUpperCase();
		switch(beyondCityIndex){
			
			case DEPARTURE_CITY_1 : {	if(isTLV("originBeyond")){
											emptyTLV("destinationBeyond" , "");
											emptyTLV("retDeparturesBeyond" , "");
											setValue("retDestinationsBeyond" , "TLV");
											
										}else{
											//setValue("destinationBeyond" , "TLV");
										}
										break;	
									 }
			
			case DESTINATION_CITY_1 : {
										if(isTLV("destinationBeyond")){
											emptyTLV("originBeyond" , "");
											setValue("retDeparturesBeyond" , "TLV");
											emptyTLV("retDestinationsBeyond" , "");
										}else{
											//setValue("originBeyond" , "TLV");
										}
										break;	
									 }
			
			case DEPARTURE_CITY_2 : {
										if(isTLV("retDeparturesBeyond")){
											emptyTLV("originBeyond" , "");
											setValue("destinationBeyond" , "TLV");
											emptyTLV("retDestinationsBeyond" , "");
										}else{
											//setValue("retDestinationsBeyond" , "TLV");
										}
										break;	
									 }
			
			case DESTINATION_CITY_2 : {
										if(isTLV("retDestinationsBeyond")){
											setValue("originBeyond" , "TLV");
											emptyTLV("destinationBeyond" , "");
											emptyTLV("retDeparturesBeyond" , "");
										}else{
											//setValue("retDeparturesBeyond" , "TLV");
										}	
										break;
									 }

			case DEPARTURE_CITY_3 : {
										if(isTLV("retDeparturesBeyond")){
											emptyTLV("originBeyond" , "");
											setValue("destinationBeyond" , "TLV");
											emptyTLV("retDestinationsBeyond" , "");
										}else{
											//setValue("retDestinationsBeyond" , "TLV");
										}
										break;	
									 }
									 
			case DESTINATION_CITY_3 : {
										if(isTLV("retDestinationsBeyond")){
											setValue("originBeyond" , "TLV");
											emptyTLV("destinationBeyond" , "");
											emptyTLV("retDeparturesBeyond" , "");
										}else{
											//setValue("retDeparturesBeyond" , "TLV");
										}	
										break;
									 }
									 			
			default : {
			}
		
		}
	}	
	
	function isTLV(elemntId){
		if("TLV" == document.getElementById(elemntId).value){			
			return true;
		}		
		return false;
	}
	// If the city code is TLV this function empty the input
	function emptyTLV(elemntId){
		if(isTLV(elemntId)){
			setValue(elemntId , "");
		}
	}
	function setValue(elemntId , value){
		document.getElementById(elemntId).value = value;
	}
	
function Route(depCode , retCode , returnFromCode , returnToCode , cityType){
	
	this.depCode = depCode;
	this.retCode = retCode;
	this.returnFromCode = returnFromCode;
	this.returnToCode = returnToCode;
	this.cityType = cityType;

}

function getRoute(depCity , retCity){
	for(var i = 0 ; i < routes.length ; i++){
		if( routes[i].depCode == depCity &&  routes[i].retCode == retCity ){
			return routes[i];
		}	
	}
	
}
	
	
function showSundorCities(elem){
    var showSundor = elem.checked ? "TRUE" : "FALSE";
	document.location.href = "elalInit.do?ONLY_SUNDOR_CITIES=" + showSundor + "&systemId=3";
}	
	
	
