
function TextSize(change) {
    if (change == 0) {
        now = 0.75;
    }
    else {
        var now = document.body.style.fontSize;
        now = (now == '') ? 0.75 : parseFloat(now);
        now += change / 10;
    }
    if (now > 0.6 && now <= 1.5) {
        document.body.style.fontSize = now + 'em';
    }
}

function getTopicmapTitle() {
    return $('#topicmap .topicmap-title:hidden').val();
}

function getDocumentCheckboxes() {
    return $('#document-list .document-selection:checkbox');
}

function getJurisdictionCheckboxes() {
    return $('#jurisdictions .country:checkbox');
}

function getTopicsCheckboxes() {
    return $('#topics .topic:checked').filter(function() {
        return !$(this).parent('li').parent('ul').parent('li').children('input').is(':checked')
    });
}

function getQueryStringValueByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else return decodeURIComponent(results[1].replace(/\+/g, " ")); 
}

function getSelectedJurisdictions() {
    var checkboxes = getJurisdictionCheckboxes();
    return checkboxes.filter(function(index) {
        return this.checked;
    }).map(function() {
        return this.value;
    }).get();
}

function getSelectedTopics() {
    var checkboxes = getTopicsCheckboxes();
    return checkboxes.map(function() {
        return this.value;
    }).get();
}

function clearAll() {
    var jurisCheckboxes = getJurisdictionCheckboxes();
    var topicCheckboxes = $('#topics .topic:checked');

    jurisCheckboxes.each(function() {
        this.checked = false;
    });
    
    topicCheckboxes.each(function() {
        this.checked = false;
    });
}

function showCompareJurisdictions() {
    var selectedJurisdictions = getSelectedJurisdictions();
    var selectedTopics = getSelectedTopics();

    var paramJurisdictions = selectedJurisdictions.join(',');
    var paramTopics = selectedTopics.join(',');

    window.open("compare-jurisdictions-results.aspx?topicmap=" + getTopicmapTitle() + "&" +
                    "jurisdictions=" + encodeURIComponent(paramJurisdictions) +
                    "&topics=" + encodeURIComponent(paramTopics));
}

function showKCLCaseFiles(href) {
    var options = "status=no,scrollbars=yes,resizable=yes,width=380,height=180,top=480,left=600";
    window.open(href, 'case_file', options);    
}

function selectDeselect(checked) {
    var checkboxes = getDocumentCheckboxes();
    checkboxes.each(function() {
        this.checked = checked;
    });
    $('.select-deselect:checkbox').each(function() {
        this.checked = checked;
    });
}

function getSelectedDocuments() {
    var checkboxes = getDocumentCheckboxes();
    return checkboxes.filter(function(index) {
        return this.checked;
    }).map(function() {
        return this.value;
    }).get();
}

function printSelectedDocuments() {
    var selectedDocuments = getSelectedDocuments();
    if (selectedDocuments.length === 0) {
        alert("Please select at least one item from the list.");
        return false;
    }
    var paramValue = selectedDocuments.join(',');
    window.open("print.aspx?ids=" + paramValue);
}

function emailSelectedDocuments() {
    var selectedDocuments = getSelectedDocuments();
    if (selectedDocuments.length === 0) {
        alert("Please select at least one item from the list.");
        return false;
    }
    var paramValue = selectedDocuments.join(',');
    window.location.href = "email.aspx?ids=" + paramValue;
}

function HideShow(lnkHide, lnkShow, id_container, hide_from) {
    try {
        document.getElementById(lnkShow).style.display = 'block';
        document.getElementById(lnkHide).style.display = 'none';
        var items = document.getElementById(id_container).getElementsByTagName('li');
        for (var i = items.length - 1; i >= hide_from; i--)
            items[i].style.display = hide_from ? 'none' : 'block';
        return true;
    } catch (e) {
        return false;
    }
}
