window.onload = function() {
    responses = new Array();
    show("hmdmatrix");
}

function register_response(id) {
    
    qelements = id.split('_');
    qnum = qelements[0];
    qloc = qelements[1];
    var qid = qnum.replace('q','');
    
    if (qid == 3) {
      if (qloc == "r") {
        show("q4q");
        show("q4l");
        show("q4r");
        show("q5q");
        show("q5l");
        show("q5r");
      } else {
        hide("q4q");
        hide("q4l");
        hide("q4r");
        hide("q5q");
        hide("q5l");
        hide("q5r");
      }
    }

    alter = "";
    
    if (qloc == "l") {
        alter = "r";
    } else {
        alter = "l";
    }
    
    var otherOption = qnum + "_" + alter;    
    
    responses[qid] = qloc;
    
}

function hideall() {
    hide("hmd_preinstalled");
    hide("hmd_hosted");
    hide("hmd_inabox");
    hide("hmd_openvalue");
    hide("hmd_ovcomwide");
    hide("hmd_ovsub");
    hide("hmd_ovlicence");
    hide("hmd_openlicence");
    hide("alexstory");	
}

function show_results() {
    var currentResult = responses.join("");
    var showres = true;

    if (responses[4] || responses[5]) {
      if (!responses[1] || !responses[2] || !responses[3]) {
        alert("Please answer all five questions.");
        showres = false;
      }
    }
    
    if (showres) {
      switch(currentResult) {
        case 'lll':
          hideall();
          show("res_q1_l");          
          show("res_q2_l");          
          show("res_q3_l");          
          show("hmd_preinstalled");
          show("hmd_hosted");
          show("hmd_inabox");
        break;
        case 'lrl':
          hideall();
          show("res_q1_l");          
          show("res_q2_r");          
          show("res_q3_l");          
          show("hmd_preinstalled");
          show("hmd_inabox");
        break;
        case 'lrr':
          alert("Please answer questions 4 and 5.");
          showres = false;
        break;
        case 'rll':
          hideall();
          show("res_q1_r");          
          show("res_q2_l");          
          show("res_q3_l");          
          show("hmd_hosted");
          show("hmd_inabox");
        break;
        case 'rrl':
          hideall();
          show("res_q1_r");          
          show("res_q2_r");          
          show("res_q3_l");                    
          show("hmd_inabox");
        break;
        case 'rrr':
          alert("Please answer questions 4 and 5.");
          showres = false;
        break;        
        case 'llrll':
          hideall();
          show("res_q1_l");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_l");          
          show("hmd_preinstalled");
          show("hmd_hosted");
          show("hmd_openvalue");
          show("hmd_ovcomwide");
          show("hmd_ovsub");
        break;
        case 'llrlr':
          hideall();
          show("res_q1_l");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_r");          
          show("hmd_preinstalled");
          show("hmd_hosted");
          show("hmd_openvalue");
          show("hmd_ovsub");          
        break;
        case 'llrrl':
          hideall();
          show("res_q1_l");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_l");          
          show("hmd_preinstalled");
          show("hmd_hosted");
          show("hmd_openlicence");
          show("hmd_ovcomwide");
          show("hmd_ovsub");
        break;
        case 'llrrr':
          hideall();
          show("res_q1_l");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_r");          
          show("hmd_preinstalled");
          show("hmd_hosted");
          show("hmd_openlicence");
        break;
        case 'lrrll':
          hideall();
          show("res_q1_l");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_l");          
          show("hmd_preinstalled");
          show("hmd_openvalue");
          show("hmd_ovcomwide");
          show("hmd_ovsub");
        break;
        case 'lrrlr':
          hideall();
          show("res_q1_l");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_r");          
          show("hmd_preinstalled");
          show("hmd_openvalue");
          show("hmd_ovsub");
        break;
        case 'lrrrl':
          hideall();
          show("res_q1_l");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_l");          
          show("hmd_preinstalled");
          show("hmd_openlicence");
          show("hmd_ovsub");
        break;
        case 'lrrrr':
          hideall();
          show("res_q1_l");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_r");          
          show("hmd_preinstalled");
          show("hmd_openlicence");
        break;
        case 'rlrll':
          hideall();
          show("res_q1_r");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_l");          
          show("hmd_hosted");
          show("hmd_openvalue");
          show("hmd_ovcomwide");
          show("hmd_ovsub");
        break;
        case 'rlrlr':
          hideall();
          show("res_q1_r");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_r");          
          show("hmd_hosted");
          show("hmd_openvalue");
          show("hmd_ovsub");
        break;
        case 'rlrrl':
          hideall();
          show("res_q1_r");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_l");          
          show("hmd_hosted");
          show("hmd_openlicence");
          show("hmd_ovsub");
        break;
        case 'rlrrr':
          hideall();
          show("res_q1_r");          
          show("res_q2_l");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_r");          
          show("hmd_hosted");
          show("hmd_openlicence");
        break;
        case 'rrrll':
          hideall();
          show("res_q1_r");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_l");          
          show("hmd_openlicence");
          show("hmd_ovcomwide");
          show("hmd_ovsub");          
        break;
        case 'rrrlr':
          hideall();
          show("res_q1_r");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_l");          
          show("res_q5_r");          
          show("hmd_openvalue");
          show("hmd_ovsub");
        break;
        case 'rrrrl':
          hideall();
          show("res_q1_r");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_l");          
          show("hmd_ovlicence");
          show("hmd_openlicence");
        break;
        case 'rrrrr':
          hideall();
          show("res_q1_r");          
          show("res_q2_r");          
          show("res_q3_r");          
          show("res_q4_r");          
          show("res_q5_r");          
          show("hmd_openlicence");
        break;
        default:
          alert("Please answer the first three questions.");
          showres = false;
        break;
      }
    }
        
    
    if (showres) {
        // show results, hide questions
        hide("hmdmatrix");
        show("hmdresults");
    }
}

function show(id) {
    if (document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = 'block';
    }
}

function hide(id) {
    if (document.getElementById(id).style.display != 'none') {
        document.getElementById(id).style.display = 'none';
    }
}