function BackToAvailability()
{
    ShowProgressBar(true);
    //SuccessSearchFlight() is in the Availability.js
    tikAeroB2C.WebService.B2cService.AvailabilityGetSession(SuccessSearchFlight, showError, showTimeOut);
}

function GetPassengerDetail()
{
    ShowProgressBar(true);
    tikAeroB2C.WebService.B2cService.GetPassengerDetail(SuccessGetPassengerDetail, showError, showTimeOut);
}

function SuccessGetPassengerDetail(result)
{
    var obj = document.getElementById("dvContainer");
    if(result != "{001}"){
        obj.innerHTML = result;
        SetPassengerDetail();
    }
    else{
        LoadSecure(false);
    }
    
    ShowProgressBar(false);
    obj = null;
}
function InitializePassengerMaskEdit()
{
    var iPaxcount = document.getElementsByName("hdPassengerId").length;
    for(var iCount = 1;iCount<=iPaxcount;iCount++)
    {
        InitializeMaskEdit("txtIssueDate_" + iCount, "$d$d/$d$d/$d$d$d$d");
        InitializeMaskEdit("txtExpiryDate_" + iCount, "$d$d/$d$d/$d$d$d$d");
        InitializeMaskEdit("txtBirthDate_" + iCount, "$d$d/$d$d/$d$d$d$d");
    }
}

function LoadContactTitle()
{
    var objSelect = document.getElementById("stTitle_1");
    var objContactTitle = document.getElementById("stContactTitle");
    
    
    //Populate contact detail title.
    for(var jCount=0; jCount<objSelect.length; jCount++)
    {
        objContactTitle.options[objContactTitle.options.length] = new Option(objSelect.options[jCount].text, objSelect.options[jCount].value);
    }
    objSelect = null;
    objContactTitle = null;    
}

function LoadContactCountry()
{
    var objSelect = document.getElementById("stNational_1");
    var objContactCountry = document.getElementById("stContactCountry");
    
    //Populate contact national.
    for(var jCount=0; jCount<objSelect.length; jCount++)
    {
        objContactCountry.options[objContactCountry.options.length] = new Option(objSelect.options[jCount].text, objSelect.options[jCount].value);
    }
    objSelect = null;
    objContactCountry = null;       
}

function GetContactInformationFromCookies()
{
    var objCookies = getCookie("coContact");
    var objChk = document.getElementById("chkRemember");
    
    if(objCookies != null)
    {
        
        var objFirstName = document.getElementById(FindControlName("input", "txtContactFirstname")); 
        var objLastName = document.getElementById(FindControlName("input", "txtContactLastname"));
        var objMobile =  document.getElementById(FindControlName("input", "txtContactMobile"));
        var objHome = document.getElementById(FindControlName("input", "txtContactHome"));
        var objBusiness = document.getElementById(FindControlName("input", "txtContactBusiness"));
        var objEmail = document.getElementById(FindControlName("input", "txtContactEmail"));
        var objAddress1 = document.getElementById(FindControlName("input", "txtContactAddress1"));
        var objAddress2 = document.getElementById(FindControlName("input", "txtContactAddress2"));
        var objZip =  document.getElementById(FindControlName("input", "txtContactZip"));
        var objCity = document.getElementById(FindControlName("input", "txtContactCity"));
        var objState = document.getElementById(FindControlName("input", "txtContactState"));
        var strContactInfo = objCookies.split("{}");
        
        objChk.checked = true
        
        //Get passenger contact information.
        SetComboValue(FindControlName("select", "stContactTitle"), strContactInfo[0]);
        objFirstName.value = strContactInfo[1]; 
        objLastName.value = strContactInfo[2];
        objMobile.value =  strContactInfo[3];
        objHome.value = strContactInfo[4];
        objBusiness.value = strContactInfo[5];
        objEmail.value = strContactInfo[6];
        objAddress1.value = strContactInfo[7];
        objAddress2.value = strContactInfo[8];
        objZip.value =  strContactInfo[9];
        objCity.value = strContactInfo[10];
        SetComboValue(FindControlName("select", "stContactCountry"), strContactInfo[11]);
        SetComboValue(FindControlName("select", "stContactLanguage"), strContactInfo[12]); 
        objState.value = strContactInfo[13];
        
        objFirstName = null; 
        objLastName = null;
        objMobile =  null;
        objHome = null;
        objBusiness = null;
        objEmail = null;
        objAddress1 = null;
        objAddress2 = null;
        objZip =  null;
        objCity = null;
    }
    else
    {
        objChk.checked = false
    }
    
    objCookies = null;
    objChk = null;
}
function SetPassengerDetail()
{
    //Initial mask edit
    var strCookies = getCookie("coFFP");
    InitializePassengerMaskEdit();
    if(strCookies == null)
    {
        GetContactInformationFromCookies();
    }
    else
    {
        document.getElementById("dvSelectMember").style.display = "block";
        document.getElementById("dvRemember").style.display = "none";
        document.getElementById("dvPassengerFFPComment").style.display = "block";
    }
    scroll(0,0);
    var objFirstName = document.getElementById(FindControlName("input", "txtContactFirstname")); 
    var objLastName = document.getElementById(FindControlName("input", "txtContactLastname"));
    var objPaxFirstName = document.getElementById("txtName_1");
    var objPaxLastName = document.getElementById("txtLastname_1");
    
    if(objLastName.value.length > 0 && objPaxLastName.value.length > 0)
    {
        if(objFirstName.value.toUpperCase() == objPaxFirstName.value.toUpperCase() && objLastName.value.toUpperCase() == objPaxLastName.value.toUpperCase())
        {
            var objIAmPassenger = document.getElementById("chkCopy");
            objIAmPassenger.checked = true;
            objIAmPassenger = null;
        }
    }
    
    //Lock all control that are client.
    var objProfileId = document.getElementsByName("hdClientProfileId");
    for(var iCount=1; iCount<=objProfileId.length; iCount++)
    {
        if(document.getElementById("txtClientNo_" + iCount).value.length > 0 &&
            document.getElementById("txtLastname_" + iCount).value.length > 0 &&
            document.getElementById("txtName_" + iCount).value.length > 0)
        {
            //Lock Control.
            LockPassengerInput(iCount, true);
        }   
    }
    objProfileId = null;
            
    objFirstName = null; 
    objLastName = null;
    objPaxFirstName = null;
    objPaxLastName = null;
}

