﻿var ua = navigator.userAgent.toLowerCase ();
OS = {};
OS.isFirefox = ua.indexOf ("gecko") != -1;
OS.isOpera = ua.indexOf ("opera") != -1;
OS.isIE = !OS.isOpera && ua.indexOf ("msie") != -1;

function BeginRequestHandler()
{
    //var progress = _get('progressBackgroundFilter');
    //var progressMessage = _get('processMessage');
    var btnStartCheckAnswers = document.getElementById('ctl00_ctl00_Content_Content_btnStartCheckAnswers');
    if(btnStartCheckAnswers != null) {
        btnStartCheckAnswers.disabled = true;
    }
    
    var btnStartProfile = document.getElementById('ctl00_ctl00_Content_Content_btnStartProfile');
    if(btnStartCheckAnswers != null) {
        btnStartProfile.disabled = true;
    }
    
    var btnResumeTest = document.getElementById('ctl00_ctl00_Content_Content_btnResumeTest');
    if(btnResumeTest != null) {
        btnResumeTest.disabled = true;
    }
    
    var btnStartProfile = document.getElementById('ctl00_ctl00_Content_Content_btnStartProfile');
    if(btnStartProfile != null) {
        btnStartProfile.disabled = true;
    }
    
    var btnLaterbeantwoorden = document.getElementById('ctl00_ctl00_Content_Content_btnLaterBeantwoorden');
    if(btnLaterbeantwoorden != null) {
        btnLaterbeantwoorden.disabled = true;
    }
    
    var btnNext = document.getElementById('ctl00_ctl00_Content_Content_btnNext');
    if(btnNext != null) {    
        btnNext.disabled  = true;        
    }  
    
    var btnNext2 = document.getElementById('ctl00_ctl00_Content_Content_btnNext2');
    if(btnNext2 != null) {    
        btnNext2.disabled  = true;        
    }  
    
    var btnPrevious = document.getElementById('ctl00_ctl00_Content_Content_btnPrevious');
    if(btnPrevious != null) {
        btnPrevious.disabled = true; 
    }
}

function EndRequestHandler(sender, args)
{
  if (args.get_error() != undefined && args.get_error().httpStatusCode == '12030')
  {
       args.set_errorHandled(true);
       window.location.reload(true);
  }

    var btnNext = document.getElementById('ctl00_ctl00_Content_Content_btnNext');
    var btnPrevious = document.getElementById('ctl00_ctl00_Content_Content_btnPrevious');
    if(btnNext != null) {
        btnNext.disabled = false;
    }
    if(btnPrevious != null) {
        btnPrevious.disabled = false;
    }
 
    SetSelectedRadioButtonsBold();
}

function openOnderzoekProtocol()
{
    window.open('../HealthRiscTest/OnderzoeksProtocol1.aspx', 'AanvullendeVragen', 'resizable=1, menubar=0, scrollbars=0, status=0, toolbar=0, titlebar=0, height=700, width=990', '');
}  

function switchCulture()
{
    var hidden = document.getElementById('ctl00_hidden_Language');
    if(hidden == null) {
        hidden = document.getElementById('ctl00_ctl00_hidden_Language');
    }
    if(hidden != null) {
        var value = hidden.value;
        if(value == "nl-NL") {
            hidden.value = "en-US";
        } 
        else 
        {
            hidden.value = "nl-NL";
        }
    }
}

function getClientWidth () {
    var b = document.body;
    var p = b.parentNode;
    var bcWidth = b.clientWidth;
    var pcWidth = p.clientWidth;
           
    if (OS.isIE) { // && !OS.isOpera
        return (pcWidth == 0) ? bcWidth : pcWidth;
    } else if (OS.isFirefox) {
      return (pcWidth == p.offsetWidth
                && pcWidth == p.scrollWidth) ? bcWidth : pcWidth;
    } else if (OS.isOpera) {
        return Math.min(window.innerWidth, document.body.clientWidth);
    }
    return bcWidth;
 }

function PositionTestMenu()
{
    var width = getClientWidth();
    var loginMenu = document.getElementById('div_mnu_login');
    
    var IsLoggedIn = document.getElementById('ctl00_lvLogin_mnuLogin');
    if(IsLoggedIn == null) {
        IsLoggedIn = document.getElementById('ctl00_lvLogin_Menu2');
        if(IsLoggedIn == null) {
            IsLoggedIn = document.getElementById('ctl00_ctl00_lvLogin_mnuLogin');
            if(IsLoggedIn == null) {
                IsLoggedIn = document.getElementById('ctl00_ctl00_lvLogin_Menu2');
            }
        }
    }
    
    if(OS.isFirefox) {
        if(IsLoggedIn !=null) {
            if(loginMenu !=null && width > 950) {
                
                loginMenu.style.top = 104 + 'px';
            } else {
                loginMenu.style.top = 77 + 'px';
            }
        } else {
            if(loginMenu !=null && width > 836) {
                 loginMenu.style.top = 104 + 'px';
           } else {
                loginMenu.style.top = 77 + 'px';
            }
        }    
    } else if(OS.isOpera){
        if(IsLoggedIn !=null) {
            if(loginMenu !=null && width > 955) {
                loginMenu.style.top = 104;
            } else {
                loginMenu.style.top = 77;
            }
        } else {
            if(loginMenu !=null && width > 840) {
                 loginMenu.style.top = 104;
            } else {
                 loginMenu.style.top = 77;
            }
        }
    } else {
        if(IsLoggedIn !=null) {
            if(loginMenu !=null && width > 950) {
                loginMenu.style.top = 104;
            } else {
                loginMenu.style.top = 77;
            }
        } else {
            if(loginMenu !=null && width > 836) {
                 loginMenu.style.top = 104;
            } else {
                 loginMenu.style.top = 77;
            }
        }
    }
    
}

function UnCheckSelectableItems() {
    var options = document.getElementsByTagName('input');
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.type == 'checkbox')
        {                
            if(opt.attributes.getNamedItem("onclick").value == 'javascript:UnCheckNonOfSelectableItems();')
            {
                opt.checked = false;
            }
        }
    }
}

function UnCheckNonOfSelectableItems() {
    var options = document.getElementsByTagName('input');
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.type == 'checkbox')
        {
            
            if(opt.attributes.getNamedItem("onclick").value == 'javascript:UnCheckSelectableItems();')
            {
                opt.checked = false;
            }
        }
    }
}

function InitFont()
{
    dw_fontSizerDX.set(14, 10, 17, ['div#content','div#header','div#footer','table#ctl00_mnuMain','table#ctl00_lvLogin_mnuLogin','table#ctl00_ctl00_mnuMain','table#ctl00_ctl00_lvLogin_mnuLogin','table#ctl00_lvLogin_Menu1','table#ctl00_ctl00_lvLogin_Menu2','table#ctl00_ctl00_lvLogin_Menu3','table#ctl00_lvLogin_Menu2','table#ctl00_lvLogin_Menu3'] );
    dw_fontSizerDX.init();
    //reposition menu login
    PositionTestMenu();    
}

function SetSelectedRadioBold1(radioList,count)
{
    var checked = true;
    if(radioList != null)
    {
        var options = radioList.getElementsByTagName('input');
        for(i=0;i<options.length;i++)
        {
            var opt = options[i];
            if(opt.type == 'radio')
            {
                if(opt.checked)
                {
                    checked = false;
                    opt.nextSibling.style.fontWeight = 'bold';
                }
                else
                {
                    opt.nextSibling.style.fontWeight = 'normal';
                }
            }
        }    
    }
}

function SetSelectedRadioButtonsBold()
{
    var td = document.getElementById('tdTest');
    if(td == null) {
    td = document.getElementById('tdOnderzoek');
    }
    if(td != null) {
        var controls = td.getElementsByTagName('input');
        for(i=0;i<controls.length;i++)
        {
            var opt = controls[i];

            if(opt.type == 'radio')
            {
                if(opt.checked)
                {                    
                    opt.nextSibling.style.fontWeight = 'bold';
                }
                else
                {
                    opt.nextSibling.style.fontWeight = 'normal';
                }
            }
        }
    }
}

function SetSelectedRadioBold()
{
    var checked = true;
    var radioList = document.getElementById('ctl00_ctl00_Content_Content_rblChoice');
    if(radioList != null)
    {
        var options = radioList.getElementsByTagName('input');
        for(i=0;i<options.length;i++)
        {
            var opt = options[i];
            if(opt.type == 'radio')
            {
                if(opt.checked)
                {
                    checked = false;
                    opt.nextSibling.style.fontWeight = 'bold';
                }
                else
                {
                    opt.nextSibling.style.fontWeight = 'normal';
                }
            }
        }
    }
}

function ResetControls()
{
    var td = document.getElementById('tdTest');
    if(td == null) {
    td = document.getElementById('tdOnderzoek');
    }
    var controls = td.getElementsByTagName('input');
    for(i=0;i<controls.length;i++)
    {
        if(controls[i].type == 'text')
        {
            controls[i].value = '';
        }
        if(controls[i].type == 'radio')
        {
            controls[i].checked = false;
            controls[i].nextSibling.style.fontWeight = 'normal';
        }
    }
    var controls = td.getElementsByTagName('select');
    for(i=0;i<controls.length;i++)
    {
        controls[i].value = 'Undefined';
    }    
}