﻿function webDesign_pageSettingsDialog_showAdvancedSettings(show) {
    // Show or hide the advanced settings table rows
    if (show) {
        $('tr.advancedSetting').css('display', 'table-row');
    }
    else {
        $('tr.advancedSetting').css('display', 'none');
    }
}

function webDesign_pageSettingsDialog_onClickAdvancedSettings(link) {
    // Toggle the display of the advanced settings when the link is clicked
    var show = ($('tr.advancedSetting').css('display') == 'none');
    webDesign_pageSettingsDialog_showAdvancedSettings(show);
    if (show) {
        // Show advanced settings and update the default path and title
        webDesign_pageSettingsDialog_updateDefaults();
    }
}

function webDesign_pageSettingsDialog_onChangeTextBoxPageName(textBox) {
    // Page name changed, if advanced settings visible, update the default path and title
    if ($('tr.advancedSetting').css('display') == 'table-row') {
        webDesign_pageSettingsDialog_updateDefaults();
    }
}

function webDesign_pageSettingsDialog_updateDefaults() {
    // Make the AJAX callback (fired by the hidden link button) to update the default path and title
    var linkButton = $('.webDesign.pageSettingsDialog a[id$="_LinkButtonUpdateDefaults"]');
    __doPostBack(linkButton.attr('id').replace(/_/g, '$'), '');
}

function webDesign_pageSettingsDialog_defaultsUpdated() {
    // AJAX callback to update defaults complete
    // Update the default path
    var hiddenDefaultPath = $('.webDesign.pageSettingsDialog input:hidden[id$="_HiddenFieldDefaultPagePath"]');
    var textBoxPath = $('.webDesign.pageSettingsDialog input:text[id$="_TextBoxPagePath"]');
    var checkBoxDefaultPath = $('.webDesign.pageSettingsDialog input:checkbox[id$="_CheckBoxDefaultPagePath"]');
    if (checkBoxDefaultPath.attr('checked')) {
        // Using default path, update the path textbox
        textBoxPath.val(hiddenDefaultPath.val());
    }
    // Update the default title
    var hiddenDefaultTitle = $('.webDesign.pageSettingsDialog input:hidden[id$="_HiddenFieldDefaultPageTitle"]');
    var textBoxTitle = $('.webDesign.pageSettingsDialog input:text[id$="_TextBoxPageTitle"]');
    var checkBoxDefaultTitle = $('.webDesign.pageSettingsDialog input:checkbox[id$="_CheckBoxDefaultPageTitle"]');
    if (checkBoxDefaultTitle.attr('checked')) {
        // Using default title, update the title textbox
        textBoxTitle.val(hiddenDefaultTitle.val());
    }
}

function webDesign_pageSettingsDialog_onClickCheckBoxDefault(checkBox, hiddenFieldId) {
    // Get the texbox and hidden field associated with the check box
    var textBox = $(checkBox).parent().siblings('input:text');
    var hiddenField = $('.webDesign.pageSettingsDialog input:hidden[id$="_' + hiddenFieldId + '"]');
    // Disable the textbox when the checkbox is checked
    textBox.attr('disabled', $(checkBox).attr('checked'));
    if ($(checkBox).attr('checked')) {
        // Checkbox is checked, set the textbox value to the default from the hidden field
        textBox.val(hiddenField.val());
    }
}
