﻿/*************************************************************/
// JScript File - handel the  Frequently Asked Questions 
/*************************************************************/


//function submitSelectionFAQSubject
//handel the selection in the ddl
//show the questions and answers in the channel(recursive if needed)
//notice: isInEditSite/dir/PagePortion/IsPager are define in FAQList
function submitSelectionFAQSubject()
{

    //find out the selected channel's guid
    var ddl = dropDownObj;
    var selectedChGuid = ddl.value;   
    
    //call ajax --> get QA (send function channel's guid ex:'{B2856639-4E4B-4989-8A7C-A5BDCB8C36AB}')
    AJAX.replaceContent(td_FQAContentObj, '/IMS/Pages/ajaxFAQList.aspx', 'guid='+selectedChGuid + "&isInEditSite=" + isInEditSite +  "&dir=" + dir+"&IsPager="+IsPager+"&PagePortion="+PagePortion+"&FaqGuid="+FaqGuid+"&AddNewQuestion="+AddNewQuestion+"&ShowAllAnswers="+ShowAllAnswers+"&ToMoreInfo="+ToMoreInfo, false);
}

function a()
{
    alert('a');
}
/*************************************************************/
// function openClosed
//get the tr which was clicked
//options
//1. close Question:
//  1.1 hide answer
//  1.2 change icon (change td class to "icon_close" (_RTL/_LTR))
//2. open question
//  2.1 show answer
//  2.2 change Icon (change td class to "icon_open" (_RTL/_LTR))
//NOTICE:
//Question id is Q_# (ex: Q_1)
//Answer id is A_# (ex: A_1)    
function openClosed(objTrQuestion)
{

    var trQuestionId =  objTrQuestion.id;
    var trAnswerId = trQuestionId.replace("Q","A");//see comment in NOTICE
    var trAnswer = document.getElementById(trAnswerId);
    var tdIcon = objTrQuestion.getElementsByTagName("td")[0];
    var tdIconStyle = tdIcon.className;
   
    if(tdIconStyle.indexOf('icon_open') != -1)
    {
        //1. question is open ---> close Question:
        //  1.1 hide answer (dont show trAnswer)
        trAnswer.style.display = "none";
        //  1.2 change icon (change td class to "icon_close" (_RTL/_LTR)))            
        tdIcon.className = tdIconStyle.replace("open","close");            
    }
    else
    {
        //2.question is close ---> open question
        //  2.1 show answer
            trAnswer.style.display = "";
        //  2.2 change Icon (change td class to "icon_open" (_RTL/_LTR)))
           tdIcon.className = tdIconStyle.replace("close","open");                
    }
}
/*************************************************************/
var IsAllAnsOpen = false;

//function openAllAnswers
//on this event open/close all Answers(decide to open/close by var IsAllAnsOpen)
//input: the table
//1. move on all the answers rows ( id starts with :'A_')and change visibility ("display:''" or "display:'none'")
//2. move on all Questions Rows ( id starts with :'Q_') and change icon class(icon_open(_RTL/_LTR)/icon_close(_RTL/_LTR))(icon class is in first td)
//3. update IsAllAnsOpen status (true/flase)
function openCloseAllAnswers(objTable,dir)
{
    var tr_collections = objTable.getElementsByTagName("tr");
    var s_qRowDisplay= ""; //to init into "none" or into a empty string;
    var s_aTdClass= ""; //to init into "icon_open" or into "icon_close"
    var s_allTdClass="";
    
    if(!IsAllAnsOpen)
    {
        //open All answers
        s_qRowDisplay = ""; //in order to do : "style.display=''"
        s_aTdClass = "icon_open_" + dir; //in order to do : ".className='icon_open'" (_RTL/_LTR)
        s_allTdClass = "icon_open_All_" + dir; //in order to do : ".className='icon_open'" (_RTL/_LTR)
}
    else
    {
        //close All answers
         s_qRowDisplay = "none"; //in order to do : "style.display='none'"
         s_aTdClass = "icon_close_" + dir;; //in order to do : ".className='icon_close'" (_RTL/_LTR)
         s_allTdClass = "icon_close_All_" + dir; //in order to do : ".className='icon_open'" (_RTL/_LTR)
    }
   
    // change style to : "display:s_rowDisplay" 
    for (i = 0; i<tr_collections.length; i++)
    {
        var trCur = tr_collections[i];
        //step 1
        if(trCur.id.indexOf("A_") == 0)
        {
            //change visibility only to the rows which are answers (their id start with :'A_'. ex: id=A_1)
            trCur.style.display = s_qRowDisplay;
            
        }   
       //step 2
       if(trCur.id.indexOf("Q_") == 0) 
       {
            //change class only to the rows which are questions (their id start with :'Q_'. ex: id=Q_1)
            trCur.getElementsByTagName("td")[0].className = s_aTdClass;          
       } 
       if(trCur.id.indexOf("AllQ") == 0)
       { 
            trCur.getElementsByTagName("td")[0].className = s_allTdClass;
                  
       }         
    }
    
    //step 3
    //update IsAllAnsOpen status (true/flase)
    IsAllAnsOpen = !IsAllAnsOpen;
    
    
    
}