
$(document).ready(function() {
    toggleQuerySelection();
    $(":reset").click(function() {
        $("#inputSelection").val("0");
        toggleQuerySelection();
    });
});

$(document).ready(function() {
    togglePlotTypeSelection();
    $(":reset").click(function() {
        $("#plotType").val("ldPlot");
        togglePlotTypeSelection();
    });
});

function toggleQuerySelection() {

    if ($("#inputSelection") && $("#inputSelection").val()) {
        switch($("#inputSelection").val()) {
            case "0":
                showAndEnable("#fileQuery");
                hideAndDisable("#textQuery");
                hideAndDisable("#chromosomeQuery");
                hideSection("#genomicLocusLimit");
                break;
            case "1":
                hideAndDisable("#fileQuery");
                showAndEnable("#textQuery");
                hideAndDisable("#chromosomeQuery");
                hideSection("#genomicLocusLimit");
                break;
            case "2":
                hideAndDisable("#fileQuery");
                hideAndDisable("#textQuery");
                showAndEnable("#chromosomeQuery");
                showSection("#genomicLocusLimit");
        }
    }
}

function togglePlotTypeSelection() {
    if ($("#plotType") && $("#plotType").val()) {
        switch($("#plotType").val()) {
            case "ldPlot":
                showAndEnable("#querySnpSection");
                hideAndDisable("#associationDataSection");
                enableSection("#rSquaredLimitSection");
                enableSection("#distanceLimitSection");
                break;
            case "associationPlot":
                showAndEnable("#associationDataSection");
                hideAndDisable("#querySnpSection");
                disableSection("#rSquaredLimitSection");
                disableSection("#distanceLimitSection");
                break;
        }
    }
}

function toggleChromosomeSelection() {
    if ($("#chromosome") && $("#chromosome").val()) {
        switch($("#chromosome").val()) {
            case "chrX":
                $("#chromsomeInstruction").text("Warning: There is no phased genotype data for chrX in HapMap release 22");
                break;
            case "chrY":
                $("#chromsomeInstruction").text("Warning: There is no phased genotype data for chrY");
                break;
            default:
                $("#chromsomeInstruction").text("");
        }
    }
}

function showAndEnable(sectionId) {
    showSection(sectionId);
    enableSection(sectionId);
}

function hideAndDisable(sectionId) {
    hideSection(sectionId);
    disableSection(sectionId);
}

function showSection(sectionId) {
    $(sectionId).show();
}

function hideSection(sectionId) {
    $(sectionId).hide();
}

function enableSection(sectionId) {
    $(sectionId).find("input,select,textarea").attr("disabled", false);
}

function disableSection(sectionId) {
    $(sectionId).find("input,select,textarea").attr("disabled", true);
}

