ï»¿

var xmlhttp = null;
var xmldom = null;
        
if( window.XMLHttpRequest ){ // code for IE7, Firefox, Opera, etc.
    xmlhttp = new XMLHttpRequest();
}
        else if( window.ActiveXObject ){// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if( xmlhttp != null ){
          xmlhttp.open("GET", "/scripts/wizard_spoerg_ASE.xml", false);
          xmlhttp.send(null);          
          xmldom = xmlhttp.responseXML;
        }
        else{alert("Your browser does not support XMLHTTP.");}


//VÆLG OMRÅDE      
function OptionsHandler_1( option ){
    if ( xmldom ) {
		document.getElementById( 'step_2' ).style.display = 'none'; 
		document.getElementById( 'step_3' ).style.display = 'none';
		document.getElementById( 'result' ).style.display = 'none'; //THIS IS VALIDATION/RESET OF DATA IN UNDERLYING ELEMENTS  
        if ( option || option != '-1' ) {
            var elements = xmldom.getElementsByTagName ( "Subject" ); 
            for(var i=0; i < elements.length; i++){
                if(elements[i].getAttribute( "type" ) == option){
                    var XMLpath = elements[i].getElementsByTagName("Area")
                    var oSituations = '<h2> <label for="Sporg_select2" class="mt8 mb8">2. VÃ¦lg omrÃ¥de:</label></h2><select id="Sporg_select2" onclick="OptionsHandler_2(this.options[this.options.selectedIndex].value)"><option value="-1">VÃ¦lg</option>';
                    for(var j=0; j < XMLpath.length; j++){
                          oSituations += '<option value="' + XMLpath[j].getAttribute("area") + '">' + XMLpath[j].getAttribute("area") + '</option>';
                    }
					 oSituations += "</select>";
                    document.getElementById( 'step_2' ).style.display = 'block'; 
                    document.getElementById( 'step_2' ).innerHTML = oSituations;
                }
            } 
        }
        if ( option == '-1' ) {
            document.getElementById( 'step_2' ).style.display = 'none'; 
			document.getElementById( 'step_3' ).style.display = 'none';
			document.getElementById( 'result' ).style.display = 'none'; 
        }
    } 
}

//SPØRGSMÅL  
function OptionsHandler_2( option ){
    if ( xmldom ) {
		document.getElementById( 'step_3' ).style.display = 'none';
		document.getElementById( 'result' ).style.display = 'none'; //THIS IS VALIDATION/RESET OF DATA IN UNDERLYING ELEMENTS
        if ( option || option != '-1' ) {
            var elements = xmldom.getElementsByTagName ( "Area" ); 
            for(var i=0; i < elements.length; i++){
                if(elements[i].getAttribute( "area" ) == option){
                    var XMLpath = elements[i].getElementsByTagName("Question")
                    var oSituations = '<h2> <label for="Sporg_select3" class="mt8 mb8">3. PrÃ¦cisÃ©r omrÃ¥de:</label></h2><select id="Sporg_select3" onclick="OptionsHandler_3(this.options[this.options.selectedIndex].value, &quot;' + option + '&quot;)"><option value="-1">VÃ¦lg</option>';
                    for(var j=0; j < XMLpath.length; j++){
                          oSituations += '<option value="' + XMLpath[j].getAttribute("quest") + '">' + XMLpath[j].getAttribute("quest") + '</option>';
                    }
					oSituations += "</select>";
                    document.getElementById( 'step_3' ).style.display = 'block'; 
                    document.getElementById( 'step_3' ).innerHTML = oSituations;
                }
            } 
        }
        if ( option == '-1' ) {
            document.getElementById( 'step_3' ).style.display = 'none';
			document.getElementById( 'result' ).style.display = 'none';  
        }
    } 
}


//VIS SVAR
function OptionsHandler_3( question, selectedArea ){
    if ( xmldom ) {
        if ( question ) {
            var questionElements = xmldom.getElementsByTagName ( "Question" ); 
           
		    for(var i=0; i < questionElements.length; i++){
                if( questionElements[i].getAttribute( "quest" ) == question  && questionElements[i].parentNode.getAttribute ( "area" ) == selectedArea){
					var sHTML = '<h1>' + question + '</h1>';
					var element = questionElements[i];
                    sHTML += ( element.textContent ? element.textContent : element.text );
                    document.getElementById( 'result' ).style.display = 'block';
                    document.getElementById( 'result' ).innerHTML = sHTML;
                }
            }
			if ( question == '-1' ) {
            document.getElementById( 'result' ).style.display = 'none'; 
        }
        }
    }
}




