function selectSeat(row,col,seatRow,seatCol,paxCount,className,blockChild, strFeeRcd)
{   
    var objSeat = document.getElementById("tbSeat_" + row + "_" + col);
    var objPaxSeat;
    var objdvPaxType;
    var objSeatRow;
    var objSeatCol;
    var objFeeRcd;
    
    if(objSeat != null)
    {
        if(objSeat.className == className)
        {
            for(iCount = 1;iCount <= paxCount; iCount++)
            {
                objPaxSeat = document.getElementById("dvSeatNumber" + iCount);
                objSeatRow = document.getElementById("hdSeatRow" + iCount);
                objSeatCol = document.getElementById("hdSeatCol" + iCount);
                objdvPaxType = document.getElementById("dvPaxType" + iCount);
                objFeeRcd = document.getElementById("hdFeeRcd" + iCount);
                   
                if(objPaxSeat != null)
                {
                    if(trim(objPaxSeat.innerHTML).length == 0 && trim(objdvPaxType.innerHTML) != "INF")
                    { 
                       if (trim(objdvPaxType.innerHTML) == "CHD" && blockChild > 0)
                       {
                           ShowMessageBox("This Seat is blocked for Children", 0,'');
                           break; 
                       }
                       else
                       {
                           if (haveInfant(trim(objdvPaxType.innerHTML), paxCount) == true && blockChild > 0)
                           {
                               ShowMessageBox("This Seat is blocked for Infant", 0,'');
                               break; 
                           }
                           else
                           {
                               objPaxSeat.innerHTML = seatRow + seatCol;
                               objSeatRow.value = seatRow;
                               objSeatCol.value = seatCol;
                               objSeat.className = "selectedseat";
                               objFeeRcd.value = strFeeRcd;
                               
                               if (objdvPaxType.innerHTML == "ADULT")
                               {
                                   //Search infant To update seat infant with adult
                                   for(jCount = 1;jCount <= paxCount; jCount++)
                                   {
                                        objPaxSeat = document.getElementById("dvSeatNumber" + jCount);
                                        objdvPaxType = document.getElementById("dvPaxType" + jCount);
                                        objSeatRow = document.getElementById("hdSeatRow" + jCount);
                                        objSeatCol = document.getElementById("hdSeatCol" + jCount);
                                        objFeeRcd = document.getElementById("hdFeeRcd" + jCount);
                                        
                                        if(trim(objdvPaxType.innerHTML) == "INF" && trim(objPaxSeat.innerHTML).length == 0)
                                        {
                                            objPaxSeat.innerHTML = seatRow + seatCol;
                                            objSeatRow.value = seatRow
                                            objSeatCol.value = seatCol;
                                            objFeeRcd.value = strFeeRcd;
                                            
                                            break;         
                                        }
                                   }           
                               }
                               break; 
                           }
                       }
                    }    
                }
            }
        }
        else
        {
            for(iCount = 1;iCount <= paxCount; iCount++)
            {
                objPaxSeat = document.getElementById("dvSeatNumber" + iCount);
                objSeatRow = document.getElementById("hdSeatRow" + iCount);
                objSeatCol = document.getElementById("hdSeatCol" + iCount);
                objFeeRcd = document.getElementById("hdFeeRcd" + iCount);
                
                if(objPaxSeat != null)
                {
                    if(objPaxSeat.innerHTML == (seatRow + seatCol))
                    {
                       objPaxSeat.innerHTML = "";
                       objSeatRow.value = "";
                       objSeatCol.value = "";
                       objSeat.className = className;
                       objFeeRcd.value = "";
                    }    
                }
            }
        }
    }
    objSeat = null;
    objPaxSeat = null;
    objdvPaxType = null;
    objSeatRow = null;
    objSeatCol = null;
}
function FillSeat()
{
    var objSeatPaxId = document.getElementsByName("hdSeatPaxId");
    var objSeatSegmentId = document.getElementsByName("hdSeatSegmentId");
    var objSeatRow = document.getElementsByName("hdSeatRow");
    var objSeatCol = document.getElementsByName("hdSeatCol");
    var objSeatFeeRcd = document.getElementsByName("hdFeeRcd");
    
    var paxXml = "";
    
    for(var iCount = 0;iCount < objSeatPaxId.length;iCount++)
    {
        paxXml = paxXml + 
                 "<mapping>" +
                     "<passenger_id>" + objSeatPaxId[iCount].value + "</passenger_id>" +
                     "<segment_id>" + objSeatSegmentId[iCount].value + "</segment_id>" +
                     "<seat_row>" + objSeatRow[iCount].value + "</seat_row>" +
                     "<seat_col>" + objSeatCol[iCount].value + "</seat_col>" +
                     "<fee_rcd>" + objSeatFeeRcd[iCount].value + "</fee_rcd>" +
                 "</mapping>"
    }
    
    objSeatPaxId = null;
    objSeatSegmentId = null;
    objSeatRow = null;
    objSeatCol = null;
    objSeatFeeRcd = null;
    
    return paxXml;
}
function saveSeatMap()
{
    var paxXml = FillSeat();
    if(paxXml.length > 0)
    {
        ShowProgressBar(true);
        //Call filled seat service with rendering the control
        tikAeroB2C.WebService.B2cService.FillSeat("<booking>" + paxXml + "</booking>", true, SuccessGetPassengerDetail, showError, showTimeOut);
    }
}

function haveInfant(paxType, paxCount)
{
    var b = false;
    if (paxType == "ADULT")
    {
        var objdvPaxType;
        var objPaxSeat;
        for(iCount = 1;iCount <= paxCount; iCount++)
        {
            objdvPaxType = document.getElementById("dvPaxType" + iCount);
            objPaxSeat = document.getElementById("dvSeatNumber" + iCount);
            if(trim(objdvPaxType.innerHTML) == "INF" && objPaxSeat.innerHTML.length == 0)
            {
                b = true;
                break;
            }
        }
    }
    objdvPaxType = null;
    objPaxSeat = null;
    return b;
}

function BackToPassengerDetail()
{
    ShowProgressBar(true);    
    //Function SuccessGetPassengerDetail is in file FlightSummary.js
    tikAeroB2C.WebService.B2cService.BackToPassengerDetail(SuccessGetPassengerDetail, showError, showTimeOut);   
}

function showSeatMappingFlightSelect(strTrId, strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass)
{
    var objTable = document.getElementById("tbSeatItinerary");
    
    for(var iCount = 0;iCount < objTable.rows.length; iCount++)
    {    
        if(objTable.rows[iCount].id.toString().length != 0)
        {
            if(objTable.rows[iCount].id.toString() != strTrId)
            {
                //Change class name of tr element
                objTable.rows[iCount].className = "NotSelected";
            }
            else
            {
                //Change class name of tr element
                objTable.rows[iCount].className = "Selected";
            }
        }
    }
    objTable = null;
    
    //Call web service.
    SaveSeatMapSelectFlight(strTrId, strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass);
}

function SaveSeatMapSelectFlight(strTrId, strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass)
{
    var paxXml = FillSeat();
    if(paxXml.length > 0)
    {
        ShowProgressBar(true);
        //Call FillSeat service without rendering the control.
        tikAeroB2C.WebService.B2cService.FillSeat("<booking>" + paxXml + "</booking>", false, SuccessSaveSeatMapSelectFlight(strTrId, strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass), showError, showTimeOut);
    }
}

function SuccessSaveSeatMapSelectFlight(strTrId, strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass)
{
    tikAeroB2C.WebService.B2cService.GetMap(strSeatFlightId, strOriginRcd, strDestinationRcd, strBoardingClass, strBookingClass, SuccessLoadMap, showError, showTimeOut);
    tikAeroB2C.WebService.B2cService.GetPassengerSeatMap(strSeatFlightId, SuccessLoadMapPassenger, showError, showTimeOut);
}

function SuccessLoadMap(result)
{
    var objMap = document.getElementById(FindControlName("span", "dvSeatMap"));
    objMap.innerHTML = result;
    objMap = null
}
function SuccessLoadMapPassenger(result)
{
    var objMapPassenger = document.getElementById(FindControlName("span", "dvSeatPassenger"));
    objMapPassenger.innerHTML = result;
    objMapPassenger = null;
    
    ShowProgressBar(false);
}
