﻿
/* function to show/hide faq item */
function opencloseFaq(collapsible, subject, content) {
    var controlCollapsible = document.getElementById(collapsible);
    var controlSubject = document.getElementById(subject);
    var controlContent = document.getElementById(content);

    if (controlSubject.className == 'faq') {
        //controlCollapsible.className = 'dropdown_open';
        controlCollapsible.title = 'hide subsection';
        controlSubject.className = 'closed';
        controlContent.style.display = 'block';
    }
    else {
        //controlCollapsible.className = 'dropdown_closed';
        controlCollapsible.title = 'reveal information';
        controlSubject.className = 'faq';
        controlContent.style.display = 'none';
    }
}

/* function to open/close control and optionally set classes */
function openCloseControl(controlToGetFocusId, collapsibleControlId, collapsibleOpenClassName, collapsibleClosedClassName, update1ControlId, update1OpenClass, update1ClosedClass, update2ControlId, update2OpenClass, update2ClosedClass) {
    var collapsibleControl = document.getElementById(collapsibleControlId);
    var controlClosed = (collapsibleControl.style.display != "block");
    var update1Control;
    var update2Control;

    if (update1ControlId != null && update1ControlId != "undefined" && update1ControlId != "") {
        update1Control = document.getElementById(update1ControlId);
        if (!controlClosed && update1ClosedClass.length > 0) update1Control.className = update1ClosedClass;
        if (controlClosed && update1OpenClass.length > 0) update1Control.className = update1OpenClass;
    }

    if (update2ControlId != null && update2ControlId != "undefined" && update2ControlId != "") {
        update2Control = document.getElementById(update2ControlId);
        if (!controlClosed && update2ClosedClass.length > 0) update2Control.className = update2ClosedClass;
        if (controlClosed && update2OpenClass.length > 0) update2Control.className = update2OpenClass;
    }

    // Set the collapsible control.
    if (controlClosed) {
        if (collapsibleOpenClassName.length > 0) collapsibleControl.className = collapsibleOpenClassName;
        collapsibleControl.style.display = 'block';
    }
    else {
        if (collapsibleClosedClassName.length > 0) collapsibleControl.className = collapsibleClosedClassName;
        collapsibleControl.style.display = 'none';
    }

    // Set focus if control is specified.
    if (controlClosed && controlToGetFocusId != null && controlToGetFocusId != "undefined") {
        document.getElementById(controlToGetFocusId).focus();
    }
}

// 2008.09.12 APL Plus Ltd. (David) - Function to automate clicking of button on enter.
function checkKeyThenClick(e, buttonId) { //e is event object passed from function invocation; buttonId is the Id of the button to click
    var characterCode;  //literal character code will be stored in this variable

    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        var btn = document.getElementById(buttonId);

        if (btn != null) { //If we find the button click it

            // If Firefox... use HREF.. else IE use click()
            if (document.createEvent) {
                document.location = btn.href;
            }
            else {
                btn.click();
            }

            event.keyCode = 0
        }
        //document.forms[0].submit() //submit the form
        return false
    }
    else {
        return true
    }
}

function AllowOnlyNumeric() {
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9) or a decimal (.)
    if ((key > 47 && key < 58) || key == 46 || key==13)
    // If it was, then allow the entry to continue
        return;
    else
    // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null;
}


