function Login(logintype) {
    var df = document.loginform;
    if(logintype == 'athens') {
        df.redirect_handler.value = 'athens_pre_login_handler';
    }
    else {
        df.redirect_handler.value = 'login_handler';
    }
    df.submit();
}
function AthensLogin() {
    document.athensloginform.submit();
}
function SearchKWFocus(which) {
    if(which == 'top') {
        var df = document.topsearchform;
        $("#search_top_keywords").css({
            "color" : "black",
            "border" : "1px solid red"
        });
    }
    else if(which == 'mid') {
        var df = document.midsearchform;
        $("#search_mid_keywords").css({
            "color" : "black",
            "border" : "1px solid red"
        });
    }
    else {
        return false;
    }
    if(df.keywords.value == 'Enter keywords / ISBN here') {
        df.keywords.value = '';
    }
}
function SearchKWBlur(which) {
    if(which == 'top') {
        var df = document.topsearchform;
    }
    else if(which == 'mid') {
        var df = document.midsearchform;
    }
    else {
        return false;
    }
    if(df.keywords.value == '') {
        df.keywords.value = 'Enter keywords / ISBN here';
        $("#search_top_keywords").css({
            "color" : "#C0C0C0",
            "border" : "1px solid #C0C0C0"
        });
    }
}
function SearchCheckInput(which) {
    if(which == 'top') {
        var df = document.topsearchform;
    }
    else if(which == 'mid') {
        var df = document.midsearchform;
    }
    else {
        return false;
    }
    if(df.keywords.value == '' || df.keywords.value == 'Enter keywords / ISBN here') {
        alert("Please enter some keywords or an ISBN to search for");
        df.keywords.focus();
        return false;
    }
    return true;
}

function ShowMyLibrarySubNav() {
    $("#mylibrary_subnav").css({
        'visibility' : 'visible',
        'display' : 'block'
    });
}
function HideMyLibrarySubNav() {
    $("#mylibrary_subnav").css({
        'visibility' : 'hidden',
        'display' : 'none'
    });
}
function PreDownloadAlert() {
    $('#formresponse').html('<div class="formresponse"><p class="success"><b>Please Wait...</b><br/><br/>Please wait while we retrieve your item.</p></div>').css({
        'display' : 'block',
        'visibility' : 'visible'
    });
}
function PostDownloadAlert_123Reader() {
    $('#formresponse').html('<div class="formresponse"><p class="success"><b>123FastReader Item Request</b><br/><br/>Your item request is now being loaded into 123FastReader.</p></div>').css({
        'display' : 'block',
        'visibility' : 'visible'
    });
}
function DownloadBook(id, source) {
    PreDownloadAlert();
    var df = document.readform;
    df.book_id.value = id;
    if(source) {
        df.source.value = source;
    }
    df.redirect_handler.value = 'book_download_handler';
    df.submit();
}
function DownloadIssue(id, source) {
    PreDownloadAlert();
    var df = document.readform;
    df.issue_id.value = id;
    if(source) {
        df.source.value = source;
    }
    df.redirect_handler.value = 'journal_download_handler';
    df.submit();
}

/** ***************** SEARCH IN JOURNALS ****************** */
function JournalTextSearch(all) {
    var df = document.journaltextsearchform;
    
    // check search query
    var search = df.textsearch.value;
    if(search.length < 4) {
        alert("Sorry, your search query is too short.");
        return false;
    }
    search = escape(search);
    
    var item_id = df.item_id.value;
    
    // remove any previous results
    $("#searchresults_list").html("<i>Please wait for your results...</i>");
    
    // send ajax query to server to get some search results
    var url = '/ajax_123reader_search/?item_id=' + item_id + '&format=bd&item_type=journal';
    if(all) {
        url += '&search_type=all';
    }
    url += '&search=' + search;
    
    XMLHttpSend(url, 'HTML_XMLHttpCallback("searchresults_list")', 'GET');
    JournalShowSearchBox();
    return false;
}
function JournalShowSearchBox() {
    $("#searchresults").css({
        'visibility' : 'visible',
        'display' : 'block'
    });
}
/** ************************************************* */

/** ******************* admin login panel **************** */
admin_login_panel_state = false;
function ToggleAdminLoginPanel() {
    if(admin_login_panel_state) {
        $("#admin_login_link").css({
            'visibility' : 'visible',
            'display' : 'block'
        });
        $("#admin_login_panel").css({
            'visibility' : 'hidden',
            'display' : 'none'
        });
    }
    else {
        $("#admin_login_link").css({
            'visibility' : 'hidden',
            'display' : 'none'
        });
        $("#admin_login_panel").css({
            'visibility' : 'visible',
            'display' : 'block'
        });
    }
    admin_login_panel_state = !admin_login_panel_state;
}
/** ******************************************************** */

/** ******************* AJAX ************************ */
var xmlhttp = false;
function XMLHttpSend(url, callbackfunction, method) {
    xmlhttp = false;
    /* @cc_on @ */
    /*
     * @if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with
     * old IE versions. // and security blocked creation of the objects. try { xmlhttp = new
     * ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new
     * ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; } } @end @
     */
    if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4) {
            eval(callbackfunction);
        }
    };
    if(url.indexOf("?") != -1) {
        url += '&randomnumber=' + Math.random();
    }
    else {
        url += '?randomnumber=' + Math.random();
    }
    
    if(method != 'GET' && method != 'POST') {
        method = 'GET';
    }
    
    xmlhttp.open(method, url, true);
    xmlhttp.send(null);
}
function XMLHttpCallBack() {
    var res = xmlhttp.responseText;
    try {
        eval(res);
    }
    catch(e) {
        // do nothing
    }
}
// variation on XMLHttp_CallBack() but writes response (which is in HTML) to the specified HTML id
// (i.e. a div)
function HTML_XMLHttpCallback(id) {
    $("#" + id).html(xmlhttp.responseText);
    /*
     * var div = document.getElementById(id); var res = xmlhttp.responseText; if(div) { try {
     * div.innerHTML = res; } catch (e) { // nothing } }
     */
}
/** ************************************************* */

/** ***** FAVOURITES ****** */
function RemoveFromFavourites(book_id) {
    if(confirm("Are you sure you want to remove this ebook from your favourite ebooks?\n\nYou can add it again later.")) {
        XMLHttpSend('/ajax_favourites/?item_id=' + book_id + '&item_type=book&mode=remove', 'XMLHttpCallBack("favourites_message_area")', 'GET');
    }
}
function AddToFavourites(book_id) {
    XMLHttpSend('/ajax_favourites/?item_id=' + book_id + '&item_type=book&mode=add&msgdiv=recent_item_message_area', 'XMLHttpCallBack("recent_item_message_area")', 'GET');
}
function AddToFavouritesSimple(book_id, hide_id, msg_id) {
    XMLHttpSend('/ajax_favourites/?item_id=' + book_id + '&item_type=book&mode=add&msgdiv=recent_item_message_area', 'XMLHttpCallBack("recent_item_message_area")', 'GET');
    $("#" + hide_id).css({
        'display' : 'none',
        'visibility' : 'hidden'
    });
    $("#" + msg_id).html('<i>Added to favourites (<a href="javascript:RemoveFromFavouritesSimple(\'' + book_id + '\',\'' + hide_id + '\',\'' + msg_id + '\')">undo</a>)</i>&nbsp;');
}
function RemoveFromFavouritesSimple(book_id, hide_id, msg_id) {
    if(confirm("Are you sure you want to remove this ebook from your favourite ebooks?\n\nYou can add it again later.")) {
        XMLHttpSend('/ajax_favourites/?item_id=' + book_id + '&item_type=book&mode=remove', 'XMLHttpCallBack("favourites_message_area")', 'GET');
        $("#" + hide_id).css({
            'display' : 'none',
            'visibility' : 'hidden'
        });
        $("#" + msg_id).html('<i>Removed from favourites (<a href="javascript:AddToFavouritesSimple(\'' + book_id + '\',\'' + hide_id + '\',\'' + msg_id + '\')">undo</a>)</i>&nbsp;');
    }
}
function RefreshAll() {
    RefreshRecentItems();
    setTimeout("RefreshFavourites()", 500);
}
function RefreshFavourites() {
    XMLHttpSend('/ajax_favourites/?mode=refresh_favourites', 'HTML_XMLHttpCallback("favourites_container")', 'GET');
}
function RefreshRecentItems() {
    XMLHttpSend('/ajax_favourites/?mode=refresh_recent_items', 'HTML_XMLHttpCallback("recent_container")', 'GET');
}

/** ******* COLLECTIONS BROWSER ********** */
var bb_cur_open = '';
var bb_cur_open_label = '';
var bb_subject_open = false;
function bb_Expand_BIC(div) {
    if(div.indexOf("cat") != -1) {
        // Modify the window location to include the BIC and the name, e.g.
        // #!bic=MB&name=Medicine%20General
        var code = div.substr(4); // start after cat_
        //var name = escape(expanding_link_element.innerText());
        var url = window.location.toString();
        if(url.indexOf('#!') != -1) {
            // strip out existing #!
            url = url.substr(0, url.indexOf('#!'));
        }
        window.location = url + '#!bic=' + code; // + '&name=' + name;
    }
    bb_cur_open_label = $("#"+div+"_link").html();
    $("#" + div).css({
        "display" : "block",
        "visibility" : "visible",
        "background-color" : "#FFEFEF"
    });
    var contract_html = bb_cur_open_label;
    contract_html = contract_html.replace('+&nbsp;', '-&nbsp;');
    contract_html = contract_html.replace('bb_Expand', 'bb_Contract');
    $("#"+div+"_link").html(contract_html);
}
function bb_Contract_BIC(div) {
    /*
    var url = window.location.toString();
    if(url.indexOf('#!') != -1) {
        // strip out existing #!
        url = url.substr(0, url.indexOf('#!'));
        window.location = url + '#!';
    }
    */
    $("#" + div).css({
        "display" : "none",
        "visibility" : "hidden"
    });
    var expand_html = bb_cur_open_label;
    expand_html = expand_html.replace('-&nbsp;', '+&nbsp;');
    expand_html = expand_html.replace('bb_Contract', 'bb_Expand');
    if(console){
        console.log(expand_html);
    }
    $("#"+div+"_link").html(expand_html);
    bb_cur_open_label = '';
}
$(document).ready(function() {
    // Check if there is a BIC in the browser location after #!
    // E.g. #!bic=MB
    // If so then do bb_Expand for this BIC
    var url = window.location.toString();
    if(url.indexOf('#!bic=') != -1) {
        var regex = /\#\!bic=(\w+)/;
        var matches = url.match(regex);
        if(matches.length == 2) {
            var code = matches[1];
            var name = unescape(matches[2]);
            if(url.indexOf('mylibrary') != -1) {
                ml_ExpandSection('my_ebooks_category', 'My eBooks - browse by category');
            }
            bb_Expand_BIC('cat_' + code);
        }
    }
});

/** ******* CART ********** */
function AddToCart(item_type, item_id, e_option, last_page) {
    var df = document.cartform;
    df.item_type.value = item_type;
    df.item_id.value = item_id;
    df.e_option.value = e_option;
    df.last_page.value = last_page;
    df.action.value = 'add';
    df.submit();
}
function RemoveFromCart(id, last_page) {
    if(confirm("Are you sure you want to delete this item from your order?")) {
        var df = document.cartform;
        df.cart_item_id.value = id;
        df.last_page.value = last_page;
        df.action.value = 'remove';
        df.submit();
    }
}
function RemoveAllFromCart(last_page) {
    if(confirm("Are you sure you want to delete all the items from your order?")) {
        var df = document.cartform;
        df.last_page.value = last_page;
        df.action.value = 'remove_all';
        df.submit();
    }
}
// this is a different version just used on the books_list page
function RemoveCartItem(item_type, item_id) {
    for( var i = 0; i < RemoveItems.length; i++) {
        if(RemoveItems[i][0] == item_type && RemoveItems[i][1] == item_id) {
            // already in the array
            return;
        }
    }
    RemoveItems[RemoveItems.length] = new Array(item_type, item_id);
    $("#remlink_" + item_id).html("<i>Removed item</i> | <a href=\"javascript:UndoRemoveCartItem('" + item_type + "'," + item_id + ")\">undo</a> | <a href=\"javascript:UpdateCart()\">apply changes</a>");
    if(TickItems.length > 0 || RemoveItems.length > 0) {
        halt_nav = true;
    }
    else {
        halt_nav = false;
    }
}
function UndoRemoveCartItem(item_type, item_id) {
    var RC = new Array();
    for( var i = 0; i < RemoveItems.length; i++) {
        if(RemoveItems[i][0] == item_type && RemoveItems[i][1] == item_id) {
            // remove this one
            continue;
        }
        else {
            RC[RC.length] = new Array(RemoveItems[i][0], RemoveItems[i][1]);
        }
    }
    RemoveItems = RC;
    $("#remlink_" + item_id).html("<i>Already in order</i> | <a href=\"javascript:RemoveCartItem('" + item_type + "', " + item_id + ")\">remove</a>");
    if(TickItems.length > 0 || RemoveItems.length > 0) {
        halt_nav = true;
    }
    else {
        halt_nav = false;
    }
}
function TickCartItem(e, item_type, item_id, e_option, suppress_alerts) {
    // tick-box on or off
    if(e.checked) {
        // might already have the other option
        for( var i = 0; i < TickItems.length; i++) {
            if(TickItems[i][0] == item_type && TickItems[i][1] == item_id && TickItems[i][2] != e_option) {
                e.checked = false;
                if(!suppress_alerts) {
                    alert("You already have the other option.");
                }
                return;
            }
        }
        TickItems[TickItems.length] = new Array(item_type, item_id, e_option);
    }
    else {
        var TC = new Array();
        for( var i = 0; i < TickItems.length; i++) {
            if(TickItems[i][0] == item_type && TickItems[i][1] == item_id) {
                continue;
            }
            else {
                TC[TC.length] = new Array(TickItems[i][0], TickItems[i][1], TickItems[i][2]);
            }
        }
        TickItems = TC;
    }
    if(TickItems.length > 0 || RemoveItems.length > 0) {
        halt_nav = true;
    }
    else {
        halt_nav = false;
    }
    return;
}
function TickAllCartItems(e_option) {
    if(TickItems.length == 0 || (TickItems.length && confirm("Are you sure you want to clear your existing selection?"))) {
        // tick all of specified option and untick other option(s)
        TickItems = [];
        $('input[type=checkbox]').each(function() {
            var id = this.id;
            var regex = /(book|video|issue)_(\d+)_option_(\d+)/;
            var matches = regex.exec(this.id);
            if(matches.length > 0) {
                this.checked = false;
                if(matches[3] == e_option) {
                    this.checked = true;
                    TickCartItem(this, matches[1], parseInt(matches[2]), e_option, true);
                }
            }
        });
    }
}
function UpdateCart() {
    if(TickItems.length == 0 && RemoveItems.length == 0) {
        alert("No changes have been made to your order.\n\nPlease tick boxes to add items, then click this link again.");
        // return false;
    }
    else {
        var str = '';
        for( var i = 0; i < TickItems.length; i++) {
            str += '(' + TickItems[i][0] + ',' + TickItems[i][1] + ',' + TickItems[i][2] + ')';
        }
        var rstr = '';
        for( var i = 0; i < RemoveItems.length; i++) {
            rstr += '(' + RemoveItems[i][0] + ',' + RemoveItems[i][1] + ')';
        }
        halt_nav = false;
        var df = document.cartform;
        df.bulk_items.value = str;
        df.bulk_remove_items.value = rstr;
        df.last_page.value = window.location.toString();
        df.action.value = 'add';
        df.submit();
    }
}
function CartBuyCollection(collection_id, e_option) {
    var df = document.cartform;
    df.collection_id.value = collection_id;
    df.collection_option.value = e_option;
    df.action.value = 'add_collection';
    df.last_page.value = window.location.toString();
    df.submit();
}
var TickItems = new Array();
var RemoveItems = new Array();
var halt_nav = false;
window.onbeforeunload = function() {
    if(halt_nav) {
        return "You have unsaved changes to your order.\nIf you navigate away from this page, the changes will not be saved.";
    }
};

/** ****** SEARCH RESULTS ******** */
function RefineSearch() {
    document.adv_search_form.submit();
}
function RelatedSearch(query, field) {
    var df = document.adv_search_form;
    df.redirect_handler.value = 'search_handler';
    df.mysubs.value = 0;
    df.search_type.value = 'advanced';
    df.match_type.value = 'all';
    df.which.value = 'all';
    df.keywords.value = '';
    df.publisher.value = '';
    df.author.value = '';
    df.isbns.value = '';
    df.isbn.value = '';
    if(field == 'author') {
        df.author.value = query;
        df.submit();
    }
    else if(field == 'publisher') {
        df.publisher.value = query;
        df.submit();
    }
}

/** **** My Library ********** */

var my_library_cur_open = '';
var my_library_cur_open_label = '';
/*
 * function ml_Expand(id, label) { $("#"+id).css({ "display":"block", "visibility":"visible" });
 * $("#"+id+"_link").html('<a
 * href="javascript:ml_Contract(\''+id+'\',\''+label+'\')">-&nbsp;'+label+'</a>');
 * if(my_library_cur_open.length > 0) { Contract(cur_open, cur_open_label); } my_library_cur_open =
 * id; my_library_cur_open_label = label; } function ml_Contract(id, label) { $("#"+id).css({
 * "display":"none", "visibility":"hidden" }); $("#"+id+"_link").html('<a
 * href="javascript:ml_Expand(\''+id+'\',\''+label+'\')">+&nbsp;'+label+'</a>');
 * my_library_cur_open = ''; my_library_cur_open_label = ''; }
 */
function ml_ExpandSection(id, label) {
    // if(my_library_cur_open)
    // {
    // ml_ContractSection(my_library_cur_open, my_library_cur_open_label);
    // }
    my_library_cur_open = id;
    my_library_cur_open_label = label;
    $("#" + id).css({
        "display" : "block",
        "visibility" : "visible"
    });
    $("#" + id + "_link").html('<a href="javascript:ml_ContractSection(\'' + id + '\',\'' + label + '\')">-&nbsp;' + label + '</a>');
}
function ml_ContractSection(id, label) {
    if(bb_cur_open) {
        bb_Contract(bb_cur_open, bb_cur_open_label);
    }
    $("#" + id).css({
        "display" : "none",
        "visibility" : "hidden"
    });
    $("#" + id + "_link").html('<a href="javascript:ml_ExpandSection(\'' + id + '\',\'' + label + '\')">+&nbsp;' + label + '</a>');
}
var num_saved_searches = 0;
function DeleteSavedSearch(id) {
    if(confirm("Are you sure you want to delete this saved search?")) {
        $("#ss_" + id).css({
            'display' : 'none',
            'visibility' : 'hidden'
        });
        num_saved_searches--;
        $.ajax({
            type : "POST",
            url : "/ajax_save_search/",
            data : "mode=remove&search_id=" + escape(id),
            success : function(data) {
                $("#savesearch_area").html("<p><b>The specified search has now been deleted.</b></p>");
                setTimeout(function() {
                    $("#savesearch_area").html("");
                    if(num_saved_searches == 0) {
                        $("#saved_searches_panel").css({
                            'display' : 'none',
                            'visibility' : 'hidden'
                        });
                    }
                }, 5000);
            }
        });
    }
}

/** *********** FREE TRIAL FORM ***************** */
function CheckFreeTrialForm() {
    var df = document.freetrial;
    if(!df.email.value || !df.confemail.value || !df.firstname.value || !df.lastname.value || !df.country.value || !df.organisation.value || !df.role.value || !df.password.value || !df.confpassword.value) {
        alert("Please complete all the fields");
        return false;
    }
    else if(df.email.value != df.confemail.value) {
        alert("You have not entered your email address correctly twice");
        return false;
    }
    else if(df.password.value != df.confpassword.value) {
        alert("You have not entered the same password twice");
        return false;
    }
    else {
        return true;
    }
}
/** ********************************************* */

/** *********** SEARCH *************** */
function CheckSaveSearch() {
    // ajax submit
    var df = document.savesearch;
    var query_string = df.query_string.value;
    var savename = df.savename.value;
    if(!savename) {
        alert("Please enter a name for your saved search.");
        return false;
    }
    $("#savesearch_area").html("<p><i>Please wait, saving your search...</i></p>");
    $.ajax({
        type : "POST",
        url : "/ajax_save_search/",
        data : "mode=add&savename=" + escape(savename) + "&qs=" + escape(query_string),
        success : function(data) {
            $("#savesearch_area").html("<p><b>Your search has now been saved.</b><br/>You can access your saved searches on your <a href='/mylibrary/'>My Library</a> page.</p>");
        }
    });
    return false;
}
function WhatIsSaveSearch() {
    $("#savesearch_whatisthis").html('<p><i>By saving this search you will be able to access the results shown below at any time.<br/>Your search will be listed in "My saved searches" on your <a href="/mylibrary/">My Library</a> page.</i></p>');
}
function CheckAdvancedSearchForm() {
    return true;
}
function AdvancedSearchFormDateChange() {
    var df = document.advancedsearchform;
    df.publication_date_month.disabled = false;
    df.publication_date_year.disabled = false;
    if(df.publication_date_match.selectedIndex == 0) // all dates
    {
        df.publication_date_month.selectedIndex = 0;
        df.publication_date_month.disabled = true;
        df.publication_date_year.selectedIndex = 0;
        df.publication_date_year.disabled = true;
    }
    else if(df.publication_date_match.selectedIndex == 1) // before...
    {
        df.publication_date_month.selectedIndex = df.publication_date_month.length - 1;
        df.publication_date_year.selectedIndex = df.publication_date_year.length - 1;
    }
    else if(df.publication_date_match.selectedIndex == 2) // during...
    {
        df.publication_date_month.selectedIndex = df.publication_date_month.length - 1;
        df.publication_date_year.selectedIndex = df.publication_date_year.length - 1;
    }
    else if(df.publication_date_match.selectedIndex == 3) // after...
    {
        df.publication_date_month.selectedIndex = 1;
        df.publication_date_year.selectedIndex = 1;
    }
}
$(document).ready(function() {
    if(document.forms['advancedsearchform']) {
        var df = document.advancedsearchform;
        if(df.publication_date_match.selectedIndex == 0) {
            df.publication_date_month.selectedIndex = 0;
            df.publication_date_month.disabled = true;
            df.publication_date_year.selectedIndex = 0;
            df.publication_date_year.disabled = true;
        }
    }
});
/** ********************************** */

/** ********* MY ACCOUNT ****************** */
function MyAccountShowTransactionDetails(id) {
    var e = document.getElementById('transaction_' + id);
    e.style.visibility = "visible";
    e.style.display = "block";
    var f = document.getElementById('transaction_' + id + '_link');
    f.innerHTML = '<a href="javascript:MyAccountHideTransactionDetails(' + id + ')">Hide</a>';
}
function MyAccountHideTransactionDetails(id) {
    var e = document.getElementById('transaction_' + id);
    e.style.visibility = "hidden";
    e.style.display = "none";
    var f = document.getElementById('transaction_' + id + '_link');
    f.innerHTML = '<a href="javascript:MyAccountShowTransactionDetails(' + id + ')">Show</a>';
}
function MyAccountDownloadMarc(type, type_id) {
    var df = document.download_form;
    df.which.value = 'marc';
    df.type.value = type;
    df.type_id.value = type_id;
    df.submit();
}

function MyAccountDownloadMarcLabel(type, type_id) {
    var df = document.download_form;
    df.which.value = 'marc_label';
    df.type.value = type;
    df.type_id.value = type_id;
    df.submit();
}

function MyAccountEditCheckForm() {
    var df = document.regform;
    if(!df.email.value || !df.confemail.value || !df.title.value || !df.firstname.value || !df.lastname.value || !df.country.value) {
        alert("Please complete all the fields");
        return false;
    }
    else if(pw && (!df.password.value || !df.confpassword.value)) {
        alert("Please complete all the fields");
        return false;
    }
    else if(df.email.value != df.confemail.value) {
        alert("You have not entered your email address correctly twice");
        return false;
    }
    else if(pw && df.password.value != df.confpassword.value) {
        alert("You have not entered your new password correctly twice");
        return false;
    }
    else if(pw && df.password.value.length > 0 && df.password.value.length < 6) {
        alert("Your new password must be at least 6 characters in length");
        return false;
    }
    else {
        return true;
    }
}
/** ***************************************** */

var currentCitationStyle = '';
function ShowCitationStyle(citation_style) {
    $("#citation_style_" + currentCitationStyle).css({
        'display' : 'none',
        'visibility' : 'hidden'
    });
    $("#citation_style_" + citation_style).css({
        'display' : 'block',
        'visibility' : 'visible'
    });
}

/** ****** MOBILE UI ************** */
$(document).ready(function() {
    var userAgent = navigator.userAgent.toLowerCase();
    var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1) ? true : false;
    clickEvent = isiPhone ? 'tap' : 'click';
    $('ul#accordion li.tab a.heading').click(function(e) {
        e.preventDefault();
        $(this).css('outline', 'none');
        if($(this).siblings('ul').is(":hidden")) {
            $('div.tab').css('background-image', 'url(/img/mobile/bg-tab-arrow.png)');
            $(this).children('div.tab').css('background-image', 'url(/img/mobile/bg-tab-arrow-down.png)');
            $('ul.sub-tab').hide();
            $(this).siblings('ul.sub-tab').show();
        }
        else {
            $(this).children('div.tab').css('background-image', 'url(/img/mobile/bg-tab-arrow.png)');
            $('ul.sub-tab').hide();
        }
    });
});

