function initvar() {
    /* Variables for reading the input by the users */
    var srcvar = document.getElementById("source")
    var source = srcvar.value
    var sourcestr = srcvar.options[srcvar.selectedIndex].text;

    var destvar = document.getElementById("dest")
    var dest = destvar.value
    var deststr = destvar.options[destvar.selectedIndex].text;

    //Declaring variables

    document.getElementById("op_source").innerHTML = sourcestr + " <b>(" + source + ")</b>"
    document.getElementById("op_dest").innerHTML = deststr + " <b>(" + dest + ")</b>"

    //  Fetch the type of Airport by getting the value from key
    var typeS = type[source];
    var typeD = type[dest];


    //End and start node
    var nodes = [source, dest];
    var node = [];

    //Temp nodes for storing common stations between two airports
    var tempnode1 = [];
    var tempnode2 = [];


    function getNode(from, to) {
        value = priority[from][to];
        return value;
    }

    //  Function to find common airports and generate a route
    function findRoute(source, dest) {
        startArr = priority[source];
        finArr = priority[dest];

        //  Those airports who have a priority for operation at source
        for (var key of Object.keys(startArr)) {
            if (startArr[key] >= typeS) {
                tempnode1.push(key)

            }
        }
        //Those airports who have a priority for operation at destination
        for (var key of Object.keys(finArr)) {

            if (finArr[key] >= typeD) {
                tempnode2.push(key)

            }
        }
        /* The two above loops find out the (n-1) deep airports in the connection */

        //If there exists a direct flight b/w Destination and Source 

        if (startArr[dest] !== -1) {
            node.push(null); //FLAG
            //node = tempnode1.filter(value => tempnode2.includes(value));


        } else {
            //If there exists jumping flights

            //assign common airports here: Find common airports in tempnode1[] and tempnode2[]
            node = tempnode1.filter(value => tempnode2.includes(value));

            if (node.length == 0) { //If there are no common aiports found
                node.push(0); //FLAG
                // Connect one of the values in startarr[] to finArr[] using an existing intermediate value, ie. an International (type 2) flight 
                for (k = 0; k < tempnode1.length; k++) {
                    for (l = 0; l < tempnode2.length; l++) {
                        if (getNode(tempnode1[k], tempnode2[l]) !== -1) {
                            node.push(tempnode1[k], tempnode2[l])
                        }
                    }
                }
            }

        }

        return nodes;
    }

    findRoute(source, dest)

    //  Turnkey function to return absolute distance value from dist_data[] 

    /*function findDist(start, end) {
        dist = dist_data[start][end]; //[start] and [key] are accessing the indice within dist_data[]
        return dist;
    }

    findDist(source, dest)
    
*/
    function findDist(source, dest) {
        /*
        key_dist = dist[source] + dist[dest] - 2;
        return (749*key_dist + 550)*/

        var sdc = dist_code[source]
        var ddc = dist_code[dest]
        return (dist[sdc][ddc]) * 1000

    }

    //  Turnkey function to return fare of a route
    function findFare(dist) {
        const flight = 8; // per km charge
        const miscFee = 750; // miscellaneous aviation fee
        var tax = dist * 0.1; // 5% tax levied on state and central territory
        distCost = (flight * dist + miscFee + tax) //Total fare = 1.1*[(per km charge)*distance] + misc fee
        return distCost;
    }

    //  Turnkey function to return fare of a route without inputting distance
    function fare(start, end) {
        dist = dist_data[start][end];
        const flight = 5;
        const miscFee = 450;
        var tax = dist * 0.1;
        totalCost = (flight * dist + miscFee + tax)
        return totalCost;
    }

    function getAirline(source, dest) {
        search = source + "-" + dest;
        var result = airlines[search]
        return result
    }

    //Generate Flight Number as a random number for *time being*

    //  Output of the stored arrays into HTML via DOM rendering

    html = "";
    /* Flag 1 : having no node flights, ie. direct fligts  */
    if (node[0] === null) {
        msg = "We found Direct Flights for you.";
        for (i = 0; i < nodes.length - 1; i++) {

            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[i], nodes[i + 1]) + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[i] + " &mdash; " + nodes[i + 1] + "</span>"
            html += "<span class='col text-right'>₹ " + findDist(nodes[i], nodes[i + 1]) + "</span>"
            html += "</div></div></div>"

        }
        /* Flag 2 : having more than one node flights, ie. multi-stop flights  */
    } else if (node[0] === 0) {
        msg = "We found multi-stop Flights for you.";
        for (i = 1; i < node.length - 1; i += 2) { // Loop jumped by 2 to avoid re-occurance of already destination entity
            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[0], node[i]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i], node[i + 1]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i + 1], nodes[1]) + "<br>" + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[0] + " &mdash; " + node[i] + "<br><i class='fa fa-map-marker'></i> " + node[i] + " &mdash; " + node[i + 1] + "<br><i class='fa fa-map-marker'></i> " + node[i + 1] + " &mdash; " + nodes[1] + "</span>"
            html += "<span class='col text-right'> ₹" + findDist(source, node[i]) + "<br> ₹" + findDist(node[i], node[i + 1]) + "<br>₹" + findDist(node[i + 1], dest) + "</span>"
            html += "</div></div></div>"
        }
    } else if (node.length !== 0) {
        /* Flag 3 (none): having  one node flights, ie. one-stop flights  */
        msg = "We found one stop Flights for you.";
        for (i = 0; i < node.length; i++) {
            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[0], node[i]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i], nodes[1]) + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[0] + " &mdash; " + node[i] + "<br><i class='fa fa-map-marker'></i> " + node[i] + " &mdash; " + nodes[1] + "</span>"
            html += "<span class='col text-right'> ₹" + findDist(source, node[i]) + "<br> ₹" + findDist(node[i], dest) + "</span>"
            html += "</div></div></div>"
        }
    } else {
        msg = "No Flights found from the airports selected";
    }
    html += "";
    //DoM rendering
    document.getElementById("msg").innerHTML = msg;
    document.getElementById("result").innerHTML = html;
}
/*
            ALGORITM

            First, find out the type of airport. Intl are hubs, Dom and Mil are points. Two Doms/Mil in different territory must go through 
            an Intl.
            Second, Priority of Source and Dest. 
            Third, Route
             Fourth, Distance and Fare
        */
ALGORITM
First, find out the type of airport. Intl are hubs, Dom and Mil are points. Two Doms/Mil in different territory must go through
an Intl.
Second, Priority of Source and Dest.
Third, Route
Fourth, Distance and Fare
ALGORITM First find out the type of airport . Intl are hubs Dom and Mil are points . Two Doms / Mil in different territory must go through an Intl . Second Priority of Source and Dest . Third Route Fourth Distance and Fare
function initvar() {
    var srcvar = document.getElementById("source")
    var source = srcvar.value
    var sourcestr = srcvar.options[srcvar.selectedIndex].text;
    var destvar = document.getElementById("dest")
    var dest = destvar.value
    var deststr = destvar.options[destvar.selectedIndex].text;
    document.getElementById("op_source").innerHTML = sourcestr + " <b>(" + source + ")</b>"
    document.getElementById("op_dest").innerHTML = deststr + " <b>(" + dest + ")</b>"
    var typeS = type[source];
    var typeD = type[dest];
    var nodes = [source, dest];
    var node = [];
    var tempnode1 = [];
    var tempnode2 = [];
    function getNode(from, to) {
        value = priority[from][to];
        return value;
    }
    function findRoute(source, dest) {
        startArr = priority[source];
        finArr = priority[dest];
        for (var key of Object.keys(startArr)) {
            if (startArr[key] >= typeS) {
                tempnode1.push(key)
            }
        }
        for (var key of Object.keys(finArr)) {
            if (finArr[key] >= typeD) {
                tempnode2.push(key)
            }
        }
        if (startArr[dest] !== -1) {
            node.push(null); 
        } else {
            node = tempnode1.filter(value => tempnode2.includes(value));
            if (node.length == 0) { 
                node.push(0); 
                for (k = 0; k < tempnode1.length; k++) {
                    for (l = 0; l < tempnode2.length; l++) {
                        if (getNode(tempnode1[k], tempnode2[l]) !== -1) {
                            node.push(tempnode1[k], tempnode2[l])
                        }
                    }
                }
            }
        }
        return nodes;
    }
    findRoute(source, dest)
    function findDist(source, dest) {
        var sdc = dist_code[source]
        var ddc = dist_code[dest]
        return (dist[sdc][ddc]) * 1000
    }
    function findFare(dist) {
        const flight = 8; 
        const miscFee = 750; 
        var tax = dist * 0.1; 
        distCost = (flight * dist + miscFee + tax) 
        return distCost;
    }
    function fare(start, end) {
        dist = dist_data[start][end];
        const flight = 5;
        const miscFee = 450;
        var tax = dist * 0.1;
        totalCost = (flight * dist + miscFee + tax)
        return totalCost;
    }
    function getAirline(source, dest) {
        search = source + "-" + dest;
        var result = airlines[search]
        return result
    }
    html = "";
    if (node[0] === null) {
        msg = "We found Direct Flights for you.";
        for (i = 0; i < nodes.length - 1; i++) {
            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[i], nodes[i + 1]) + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[i] + " &mdash; " + nodes[i + 1] + "</span>"
            html += "<span class='col text-right'>₹ " + findDist(nodes[i], nodes[i + 1]) + "</span>"
            html += "</div></div></div>"
        }
    } else if (node[0] === 0) {
        msg = "We found multi-stop Flights for you.";
        for (i = 1; i < node.length - 1; i += 2) { 
            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[0], node[i]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i], node[i + 1]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i + 1], nodes[1]) + "<br>" + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[0] + " &mdash; " + node[i] + "<br><i class='fa fa-map-marker'></i> " + node[i] + " &mdash; " + node[i + 1] + "<br><i class='fa fa-map-marker'></i> " + node[i + 1] + " &mdash; " + nodes[1] + "</span>"
            html += "<span class='col text-right'> ₹" + findDist(source, node[i]) + "<br> ₹" + findDist(node[i], node[i + 1]) + "<br>₹" + findDist(node[i + 1], dest) + "</span>"
            html += "</div></div></div>"
        }
    } else if (node.length !== 0) {
        msg = "We found one stop Flights for you.";
        for (i = 0; i < node.length; i++) {
            html += "<div class='card'><div class='card-body py-3'><div class='row'>"
            html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline(nodes[0], node[i]) + "<br><i class='fa fa-plane'></i> " + getAirline(node[i], nodes[1]) + "</span>"
            html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes[0] + " &mdash; " + node[i] + "<br><i class='fa fa-map-marker'></i> " + node[i] + " &mdash; " + nodes[1] + "</span>"
            html += "<span class='col text-right'> ₹" + findDist(source, node[i]) + "<br> ₹" + findDist(node[i], dest) + "</span>"
            html += "</div></div></div>"
        }
    } else {
        msg = "No Flights found from the airports selected";
    }
    html += "";
    document.getElementById("msg").innerHTML = msg;
    document.getElementById("result").innerHTML = html;
}
function initvar ( ) { var srcvar = document . getElementById ( "source" ) var source = srcvar . value var sourcestr = srcvar . options [ srcvar . selectedIndex ] . text ; var destvar = document . getElementById ( "dest" ) var dest = destvar . value var deststr = destvar . options [ destvar . selectedIndex ] . text ; document . getElementById ( "op_source" ) . innerHTML = sourcestr + " <b>(" + source + ")</b>" document . getElementById ( "op_dest" ) . innerHTML = deststr + " <b>(" + dest + ")</b>" var typeS = type [ source ] ; var typeD = type [ dest ] ; var nodes = [ source , dest ] ; var node = [ ] ; var tempnode1 = [ ] ; var tempnode2 = [ ] ; function getNode ( from , to ) { value = priority [ from ] [ to ] ; return value ; } function findRoute ( source , dest ) { startArr = priority [ source ] ; finArr = priority [ dest ] ; for ( var key of Object . keys ( startArr ) ) { if ( startArr [ key ] >= typeS ) { tempnode1 . push ( key ) } } for ( var key of Object . keys ( finArr ) ) { if ( finArr [ key ] >= typeD ) { tempnode2 . push ( key ) } } if ( startArr [ dest ] !== - 1 ) { node . push ( null ) ; } else { node = tempnode1 . filter ( value => tempnode2 . includes ( value ) ) ; if ( node . length == 0 ) { node . push ( 0 ) ; for ( k = 0 ; k < tempnode1 . length ; k ++ ) { for ( l = 0 ; l < tempnode2 . length ; l ++ ) { if ( getNode ( tempnode1 [ k ] , tempnode2 [ l ] ) !== - 1 ) { node . push ( tempnode1 [ k ] , tempnode2 [ l ] ) } } } } } return nodes ; } findRoute ( source , dest ) function findDist ( source , dest ) { var sdc = dist_code [ source ] var ddc = dist_code [ dest ] return ( dist [ sdc ] [ ddc ] ) * 1000 } function findFare ( dist ) { const flight = 8 ; const miscFee = 750 ; var tax = dist * 0.1 ; distCost = ( flight * dist + miscFee + tax ) return distCost ; } function fare ( start , end ) { dist = dist_data [ start ] [ end ] ; const flight = 5 ; const miscFee = 450 ; var tax = dist * 0.1 ; totalCost = ( flight * dist + miscFee + tax ) return totalCost ; } function getAirline ( source , dest ) { search = source + "-" + dest ; var result = airlines [ search ] return result } html = "" ; if ( node [ 0 ] === null ) { msg = "We found Direct Flights for you." ; for ( i = 0 ; i < nodes . length - 1 ; i ++ ) { html += "<div class='card'><div class='card-body py-3'><div class='row'>" html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline ( nodes [ i ] , nodes [ i + 1 ] ) + "</span>" html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes [ i ] + " &mdash; " + nodes [ i + 1 ] + "</span>" html += "<span class='col text-right'>₹ " + f ndDist(n o des[i ] , n des[i + 1 ) + " /span>"
 html += "</div></div></div>" } } else if ( node [ 0 ] === 0 ) { msg = "We found multi-stop Flights for you." ; for ( i = 1 ; i < node . length - 1 ; i += 2 ) { html += "<div class='card'><div class='card-body py-3'><div class='row'>" html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline ( nodes [ 0 ] , node [ i ] ) + "<br><i class='fa fa-plane'></i> " + getAirline ( node [ i ] , node [ i + 1 ] ) + "<br><i class='fa fa-plane'></i> " + getAirline ( node [ i + 1 ] , nodes [ 1 ] ) + "<br>" + "</span>" html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes [ 0 ] + " &mdash; " + node [ i ] + "<br><i class='fa fa-map-marker'></i> " + node [ i ] + " &mdash; " + node [ i + 1 ] + "<br><i class='fa fa-map-marker'></i> " + node [ i + 1 ] + " &mdash; " + nodes [ 1 ] + "</span>" html += "<span class='col text-right'> ₹" + f ndDist(s o urce,  n de[i ] ) + " br> ₹" + f n Dist(nod e [i], n o d [i + 1 ) + " b >₹" + fin D st(node[ i  + 1 ] , d s t ) + "< / p n>"
 html += "</div></div></div>" } } else if ( node . length !== 0 ) { msg = "We found one stop Flights for you." ; for ( i = 0 ; i < node . length ; i ++ ) { html += "<div class='card'><div class='card-body py-3'><div class='row'>" html += "<span class='col text-left'><i class='fa fa-plane'></i> " + getAirline ( nodes [ 0 ] , node [ i ] ) + "<br><i class='fa fa-plane'></i> " + getAirline ( node [ i ] , nodes [ 1 ] ) + "</span>" html += "<span class='col text-center'><i class='fa fa-map-marker'></i> " + nodes [ 0 ] + " &mdash; " + node [ i ] + "<br><i class='fa fa-map-marker'></i> " + node [ i ] + " &mdash; " + nodes [ 1 ] + "</span>" html += "<span class='col text-right'> ₹" + f ndDist(s o urce,  n de[i ] ) + " br> ₹" + f n Dist(nod e [i], d e s ) +  " / pan>"
 html += "</div></div></div>" } } else { msg = "No Flights found from the airports selected" ; } html += "" ; document . getElementById ( "msg" ) . innerHTML = msg ; document . getElementById ( "result" ) . innerHTML = html ; }
ALGORITM
First, find out the type of airport.
ALGORITM First find out the type of airport .
/* Variables for reading the input by the users */ //Declaring variables
 //  Fetch the type of Airport by getting the value from key
 //End and start node
 //Temp nodes for storing common stations between two airports
 //  Function to find common airports and generate a route
 //  Those airports who have a priority for operation at source
 //Those airports who have a priority for operation at destination
 /* The two above loops find out the (n-1) deep airports in the connection */ //If there exists a direct flight b/w Destination and Source 
 //FLAG
 //node = tempnode1.filter(value => tempnode2.includes(value));
 //If there exists jumping flights
 //assign common airports here: Find common airports in tempnode1[] and tempnode2[]
 //If there are no common aiports found
 //FLAG
 // Connect one of the values in startarr[] to finArr[] using an existing intermediate value, ie. an International (type 2) flight 
 //  Turnkey function to return absolute distance value from dist_data[] 
 /*function findDist(start, end) {
        dist = dist_data[start][end]; //[start] and [key] are accessing the indice within dist_data[]
        return dist;
    }

    findDist(source, dest)
    
*/ /*
        key_dist = dist[source] + dist[dest] - 2;
        return (749*key_dist + 550)*/ //  Turnkey function to return fare of a route
 // per km charge
 // miscellaneous aviation fee
 // 5% tax levied on state and central territory
 //Total fare = 1.1*[(per km charge)*distance] + misc fee
 //  Turnkey function to return fare of a route without inputting distance
 //Generate Flight Number as a random number for *time being*
 //  Output of the stored arrays into HTML via DOM rendering
 /* Flag 1 : having no node flights, ie. direct fligts  */ /* Flag 2 : having more than one node flights, ie. multi-stop flights  */ // Loop jumped by 2 to avoid re-occurance of already destination entity
 /* Flag 3 (none): having  one node flights, ie. one-stop flights  */ //DoM rendering
