﻿function sliderChange(event, ui, hidField, displayResultField, isNegative) {
    var value = parseInt(ui.value, 10);
    if (isNegative) {
        $("#" + hidField).attr("value", Math.abs(value - 100))
    }
    else {
        $("#" + hidField).attr("value", value)
    }
    //set the hidden field value
    setAnswerValue(value, displayResultField);
}

function setAnswerValue(value, displayResultField, isNegative) {
    isNegative = (isNegative == undefined) ? false : isNegative;
    var answer;
    if (isNegative) {
        value = (100-value)
    }
    if (value <= 20) {
        answer = "Never"
    }
    else if (value <= 40) {
        answer = "Seldom / Rarely"
    }
    else if (value <= 60) {
        answer = "Sometimes"
    }
    else if (value <= 80) {
        answer = "Often"
    }
    else {
        answer = "Almost Always"
    }
    $("#" + displayResultField).html(answer + "<div style='font-size: .9em; padding-top: 2px;'>(" + value + "% of the time)</span>");
}

function showErrModal() {
    $.blockUI({
        message:            $('#divErr'),
        allowBodyStretch:   true,
        css: {
            textAlign:      'left',
            padding:        15
        }
    });
}


$(document).ready(function(){
    init();
});


function init() {
    //page init stuff
    //showWait()
    //showChooseReportType()
}


function showWelcome() {
    $.blockUI({
        message: $('#divWelcome'),
        allowBodyStretch: true,
        css: {
            textAlign: 'left',
            padding: 15,
            top: '200px',
            width: '400px'
        }
    });
}




function showChooseReportType() {
    var width = 550;
    var sLeft = ((windowWidth() - width) / 2) + 'px';
    var sWidth = width + 'px';
    $.blockUI({
        message: $('#divChoose'),
        allowBodyStretch: true,
        css: {
            textAlign: 'left',
            padding: 15,
            top: '120px',
            left: sLeft,
            width: sWidth
        }
    });
}

function alertSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    window.alert('Width = ' + myWidth);
    window.alert('Height = ' + myHeight);
}

function windowWidth() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
}