﻿// JavaScript Document


//CheckQuestionnairePopup - checks cookie to see if user has visited 4 or more pages.  If so show the lightbox
function CheckQuestionnairePopup() {
    //uncomment the following line to disable the Questionnaire trigger
    //return false;
    
    //Check cookie
    if (document.cookie.length > 0) {
        
        var x = getCookie('PageViewCount');
        var y = getCookie('QuestionnaireProcessed');

        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();

					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);
    //alert('cookie deleted');
}

function showhide1(hideableObj, state, textboxObj) {

    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 = '';
    //    }

}

//validate any required entry into the questionnaire form
function validate(theForm) {
    var checkSelected = false;
    for (i = 0; i < theForm.q5.length; i++) {
        if (theForm.q5[i].checked)
            checkSelected = true;
    }
    if (!checkSelected) {
        alert("Please select at least one checkbox for Question 5.");
        return (false);
    }
}
