﻿// JavaScript Document


//CheckQuestionnairePopup - checks cookie to see if user has visited 4 or more pages.  If so show the lightbox
function CheckQuestionnairePopup() {

    //Disable survey
    //return false;

    //Do not show if in PDF Mode
    var qs = new Querystring();
    if (!qs.contains("pdfMode")) {

        //Check cookie
        if (document.cookie.length > 0) {

            var x = getCookie('PageViewCount');
            var y = getCookie('QuestionnaireProcessed');

            //        alert(document.cookie);
            //        alert(x);
            //        alert(y);

            if (y == '') { //no Questionnaire cookies - add
                setCookie('QuestionnaireProcessed', 'false', '')
                setCookie('PageViewCount', 1, '')
            }
            else if (y == 'false') { //questionnaire popup not previously shown

                if (x != '') {
                    if (x == 3) {
                        //Show Questionnaire Popup
                        //e.g. ShowQuestionnaireLightbox();
                        //alert('Questionnaire Lightbox');
                        myLightWindow = new lightwindow();
                        title: '',
					    myLightWindow.activateWindow({
					        href: '/survey-popup.html',
					        title: '',
					        height: 250,
					        width: 300
					    });


                        //Add QuestionnaireProcessed=true to cookies
                        setCookie('QuestionnaireProcessed', 'true', '')
                    }
                    var z = parseInt(x) + 1;
                    setCookie('PageViewCount', z, '')
                }
            }
        }
    }
}


function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function eraseCookie(name) {
    setCookie(name, "", -1);
}

function showhide1(hideableObj, state) {

    var DisplayState = '';
    if (state.toString() == 'true') {
        DisplayState = '';
    }
    else if (state.toString() == 'false') {
        DisplayState = 'none';
    }
    else {
        DisplayState = state;
    }
    //alert(DisplayState);

    document.getElementById(hideableObj).style.display = DisplayState;

    //    if (state == 'none') {
    //        document.getElementById(textboxObj).value = '';
    //    }

}

function hideprinttools() {
    document.getElementById('doc-tools').style.display = 'none';
}

//validate any required entry into the questionnaire form
function validate(theForm) {
    var checkSelected = false;
    for (i = 0; i < theForm.q6.length; i++) {
        if (theForm.q6[i].checked)
            checkSelected = true;
    }
    if (!checkSelected) {
        alert("Please select at least one checkbox for Question 6.");
        return (false);
    }
}

