﻿/*************************************************************/
// 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;
    __doPostBack('','');
   
       
    //call ajax --> get QA (send function channel's guid ex:'{B2856639-4E4B-4989-8A7C-A5BDCB8C36AB}')
    //AJAX.replaceContent(td_FQAContentObj, "../../Templates/FAQ/ajaxFAQList.aspx", 'guid='+selectedChGuid + "&isInEditSite=" + isInEditSite +  "&dir=" + dir+"&IsPager="+IsPager+"&PagePortion="+PagePortion, true);   
}
/*************************************************************/
// 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")
//2. open question
//  2.1 show answer
//  2.2 change Icon (change td class to "icon_open" )
//NOTICE:
//Question id is Q_# (ex: Q_1)
//Answer id is A_# (ex: A_1)
//Image id is I_# (ex:I_1) 
//Space id is Space_# (ex:Space_1) 
//Space id is close_# (ex:close_1)    
function openClosed(objTrQuestion)
{
   // debugger;
    var trQuestionId =  objTrQuestion.id;
    var trAnswerId = null;
    var trSpaceId = null;
    var trCloseId = null;
    var tdImageId = null;
    var tdIconId  = null;
    
    if (trQuestionId.indexOf('Q_')!= -1)
    {
        trAnswerId = trQuestionId.replace("Q","A");//see comment in NOTICE
        trSpaceId = trQuestionId.replace("Q","Space");
        trCloseId = trQuestionId.replace("Q","close");
        tdImageId = trQuestionId.replace("Q","image");
        tdIconId = trQuestionId.replace("Q","icon");
    }
    else //close_
    {
        trAnswerId = trQuestionId.replace("close","A");//see comment in NOTICE
        trSpaceId = trQuestionId.replace("close","Space");
        tdImageId = trQuestionId.replace("close","image");
        tdIconId = trQuestionId.replace("close","icon");
        trQuestionId = trQuestionId.replace("close","Q");
        trCloseId = trQuestionId.replace("Q","close");

        
    }
    
    var trAnswer = document.getElementById(trAnswerId);
    var trSpace = document.getElementById(trSpaceId);
    var trClose = document.getElementById(trCloseId);
    var tdImage = document.getElementById(tdImageId);
    var tdIcon = document.getElementById(tdIconId);
    var trQuestion = document.getElementById(trQuestionId);
    var tdIconStyle = tdIcon.className;
   
    if(tdIconStyle.indexOf('icon_minus') != -1)
    {
        //1. question is open ---> close Question:
        //  1.1 hide answer (dont show trAnswer)
        trAnswer.style.display = "none";
        trSpace.style.display = "none";
//        tdImage.style.display = "none";
        trClose.style.display = "none";
        //  1.2 change icon (change td class to "icon_plus" )            
        tdIcon.className = tdIconStyle.replace("minus","plus"); 
        objTrQuestion.className = ""; 
        trQuestion.className = "";         
    }
    else
    {
        //2.question is close ---> open question
        //  2.1 show answer
            trAnswer.style.display = "";
            trSpace.style.display = "";
            trClose.style.display = "";
        //  2.2 change Icon (change td class to "icon_minus")
           tdIcon.className = tdIconStyle.replace("plus","minus");
           objTrQuestion.className = "answer" ;
//           tdImage.style.display = "";
                          
    }
}

// confirming the delete action does not invoke a delete action,
// it sends relevant information in the querystring, to ajaxfile('/IMS/Pages/ajaxDeletePosting.aspx')
function confirmDelete(msg,deletePostingGuid)
{
 if (confirm(msg))
    {
      
        //call ajax --> send function channel's guid ex:'{B2856639-4E4B-4989-8A7C-A5BDCB8C36AB}'
       AJAX.asyncWithCallback('/ArchiveGov/Templates/FAQ/ajaxDeletePosting.aspx', 'guid='+deletePostingGuid, "alertAndRefresh", true,true);       
    }
}

function alertAndRefresh(mes)
{
    alert(mes);
    location.reload(true);
}
/*************************************************************/
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"
    
    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)
    }
    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)
    }
   
    // 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;          
       }           
    }
    
    //step 3
    //update IsAllAnsOpen status (true/flase)
    IsAllAnsOpen = !IsAllAnsOpen;
    
    
    
}
/*************************************************************/
// function openClosed_hover
//change the icon on mouseOver mouseout
//NOTICE:
//Question id is Q_# (ex: Q_1)
//Answer id is A_# (ex: A_1)
//Image id is I_# (ex:I_1) 
//Space id is Space_# (ex:Space_1) 
//Space id is close_# (ex:close_1)    
function openClosed_hover(objTrQuestion)
{
   // debugger;
    var trQuestionId =  objTrQuestion.id;
    var trAnswerId = null;
    var trSpaceId = null;
    var trCloseId = null;
    var tdImageId = null;
    var tdIconId  = null;
    var tdIcon = null;
    if (trQuestionId.indexOf('Q_')!= -1)
    {
        trAnswerId = trQuestionId.replace("Q","A");//see comment in NOTICE
    }
    else
    {
        trAnswerId = trQuestionId.replace("close","A");//see comment in NOTICE
    }
    var trAnswer = document.getElementById(trAnswerId);
    
    if (trQuestionId.indexOf('Q_')!= -1 && trAnswer.style.display == "none")
    {
       tdIconId = trQuestionId.replace("Q","icon");
       tdIcon = document.getElementById(tdIconId);
       tdIcon.className = "icon_plus_roll";
    }
    else //close_
    {
        tdIconId = trQuestionId.replace("Q","icon");
        tdIcon = document.getElementById(tdIconId);
        tdIcon.className = "icon_minus_roll";       
    }
}

function openClosed_MouseOut(objTrQuestion)
{
   // debugger;
    var trQuestionId =  objTrQuestion.id;
    var trAnswerId = null;
    var trSpaceId = null;
    var trCloseId = null;
    var tdImageId = null;
    var tdIconId  = null;
    
    if (trQuestionId.indexOf('Q_')!= -1)
    {
        trAnswerId = trQuestionId.replace("Q","A");//see comment in NOTICE
    }
    else
    {
        trAnswerId = trQuestionId.replace("close","A");//see comment in NOTICE
    }
    var trAnswer = document.getElementById(trAnswerId);
    
    if (trQuestionId.indexOf('Q_')!= -1 && trAnswer.style.display == "none")
    {
        tdIconId = trQuestionId.replace("Q","icon");
        tdIcon = document.getElementById(tdIconId);
        tdIcon.className = "icon_plus";
    }
    else //close_
    {
        tdIconId = trQuestionId.replace("Q","icon");
        tdIcon = document.getElementById(tdIconId);
        tdIcon.className = "icon_minus";       
    }
}

