﻿var openQuestion;
var curA =document.documentElement;
    function openOldSection(){
        
        url= location.href;
        onPageLoad();
        if (url.indexOf("#") > 0){
            section =  url;
            questions = document.getElementsByTagName('a');
            for (curAId = 0; curAId < questions.length; curAId++)
            {
                curA = questions[curAId];
                if (curA.className =="question")
                {
                
                    if (curA.href == section)
                    {
                        parentNode = curA.parentNode
                        spansInParent = parentNode.getElementsByTagName('div');
                        for (curSpanId = 0; curSpanId < spansInParent.length; curSpanId++)
                        {
                            curSpanInParent = spansInParent[curSpanId];
                            if( curSpanInParent.className == "answer")
                            {
                                curSpanInParent.style.display = 'block';
                                openQuestion = curSpanInParent;
                            }
                        }
                    }
                }
            }
        }
       
       
        
    }



   
    function onPageLoad()
    {
        questions = document.getElementsByTagName('a');
        for (curAId = 0; curAId < questions.length; curAId++)
        {
            curA = questions[curAId];
            if (curA.className =="question")
            {
                curA.onclick = questionClick;
                parentNode = curA.parentNode
                spansInParent = parentNode.getElementsByTagName('div');
                for (curSpanId = 0; curSpanId < spansInParent.length; curSpanId++)
                {
                   curSpanInParent = spansInParent[curSpanId];
                    if( curSpanInParent.className == "answer")
                    {
                        hideAllAnswers();
                        curSpanInParent.style.display = 'block';
                        openQuestion = curSpanInParent;
                    }
                }
            }
        }
      hideAllAnswers();
    }
    
    function questionClick(event)
    {
        event = (event) ? event : window.event;
        myQuestion = (event.target)? event.target : event.srcElement;
        questionParent = myQuestion.parentNode;
        spansInParent = questionParent.getElementsByTagName('div')
        for (curSpanId = 0; curSpanId < spansInParent.length; curSpanId++)
        {
            curSpanInParent = spansInParent[curSpanId];
             if( curSpanInParent.className == "answer")
                {
                    if(openQuestion != null)
                    {
                        if(curSpanInParent.innerHTML == openQuestion.innerHTML)
                        {
                            openQuestion.style.display= 'none';
                            openQuestion = null;
                            showTutorialText()
                        }
                        else
                        {
                            hideAllAnswers();
                            curSpanInParent.style.display = 'block';
                            openQuestion = curSpanInParent;
                            hideTutorialText();
                        }
                    }
                    else
                    {
                        hideAllAnswers();
                        curSpanInParent.style.display = 'block';
                        openQuestion = curSpanInParent;
                        hideTutorialText();
                    
                    }
                
                }
        
 
        }
        
    }
    
    function showTutorialText()
    {
        myText = document.getElementById("tutorialText");
        if( myText != null)
        {
            myText.style.visibility  = 'visible';
        }
    }
    
    
    function hideTutorialText()
    {
        myText = document.getElementById("tutorialText");
        if( myText != null)
        {
            myText.style.visibility  = 'hidden';
        }
    }
    
    
    function hideAllAnswers()
    {
        answers = document.getElementsByTagName('div');
        for (curSpanId = 0; curSpanId < answers.length; curSpanId++)
        {
          
            curSpan = answers[curSpanId];
            if (curSpan.className =="answer")
            {
               curSpan.style.display='none';
            }
        }
    }