//Replacement of a ton of script in the passenger control
function populatePassenger(object, index)
{
    //Don't even do anything unless contactData is available
    if(contactData){ 
        //get the fieldset that has all the fields for the passenger passed in
        var fieldsetIndex = index - 1;
        var passengerFields = $('#passengerInputContent>fieldset:eq(' + fieldsetIndex + ')');
        //these are the items that are maped to the contactData item included in the passengerFields control
        var fieldIdentifiers = [
            {'name': 'DropDownListTitle', 'value': contactData.title},
            {'name': 'TextBoxFirstName', 'value': contactData.firstName},
            {'name': 'TextBoxMiddleName', 'value': contactData.middleName},
            {'name': 'TextBoxLastName', 'value': contactData.lastName},
            {'name': 'TextBoxCustomerNumber', 'value': contactData.ff},
            {'name': 'DropDownListBirthDateDay', 'value': contactData.bdayDay},
            {'name': 'DropDownListBirthDateMonth', 'value': contactData.bdayMonth},
            {'name': 'DropDownListBirthDateYear', 'value': contactData.bdayYear},
            {'name': 'DropDownListGender', 'value': contactData.gender},
            {'name': 'DropDownListNationality', 'value': contactData.nationality},
            {'name': 'DropDownListResidentCountry', 'value': contactData.countryOfResidence}
            ];
    }
    
    if($('#' + object.id + ':checked').val() == null){
        $.map(fieldIdentifiers, function(obj){
            if(obj){
                // Clear the passenger data input values (except birth-date that the user added).
                if ( (obj.name.indexOf("DropDownListBirthDate") < 0) && (obj.value != "") ) {
                    $(":input[@id*="+obj.name+"]", passengerFields).val('');
                }
                // If the input has the isreadonly attribute
                if($(":input[@id*="+obj.name+"]", passengerFields).attr("isreadonly")== "true"){
                    // Remove the readonly attribute
                    $(":input[@id*="+obj.name+"]", passengerFields).removeAttr("readonly");
                    // Remove the isreadonly attribute
                    $(":input[@id*="+obj.name+"]", passengerFields).removeAttr("isreadonly");
                    // Reset the onfocus attribute
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("onfocus", "InputOn(this,'input_on')");
                    // Reset the onblur attribute
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("onblur", "InputOff(this,'input')");
                    // Reset class to input
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("class", "input");
                }
            }
        });                
    }
    else{
        $.map(fieldIdentifiers, function(obj){
            if(obj){
                // Copy the contact data values into the passenger data inputs
                $(":input[@id*="+obj.name+"]", passengerFields).val(obj.value);
                // If not Resident Country or birth-date dropdowns
                // DropDownListBirthDateDay, DropDownListBirthDateMonth, DropDownListBirthDateYear
                if ( (obj.name != "DropDownListResidentCountry") && ( (obj.name.indexOf("DropDownListBirthDate") < 0) && (obj.value != "") ) ) {
                    // Disable the passenger data inputs
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("readonly", "true");
                    // Mark as isreadonly
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("isreadonly", "true");
                    // Set onfocus event to fire the blur event, disabling the control
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("onfocus", "this.blur();");
                    // Remove the onblur event
                    $(":input[@id*="+obj.name+"]", passengerFields).removeAttr("onblur");
                    // Set class to disabledinput
                    $(":input[@id*="+obj.name+"]", passengerFields).attr("class", "input_disabled");
                }
            }
        });  
    }      
}
