﻿/*=============================================================================================================
        Script Use: To control opening and closing of collapsible menu in GapBlogs Section.
        
        Functions Used: defaultBlogDivs - To initialize the divs, populate the array dynamically and 
                                          show the divs in sets using indices.
                        hide - To hide the divs to provide the collapsing UI look 
                        show - To show the divs to provide the collapsing UI look 
                        toggleBlogDivs -  To toggle the divs to provide the collapsing UI look                         
                        getCurrentIndex - To get the index of the current div as per the Url
                        getAppendedString - To append the string "divBlog" to the Gapper ID
                        showDivsInSet - To show divs in sets
                        showPrevDiv - To show the Previous set of Gappers
                        showNextDiv - To show the Next set of Gappers
                        showAllTitleDivs - To show all the Title Divs
                        hideAllTitleDivs - To hide all the Title Divs
                        showAllInfoDivs - To show all the Info Divs
                        hideAllInfoDivs - To hide all the Info Divs
                        divOnMouseOut - To hide the Required Info Divs on Mouse Out
                        
=============================================================================================================*/


//Global variables
	  var divisor=10;                        //Value shows the number of Gappers on one page.
	                                        //change this number to change the no. of Gappers on one page.
	  var arrayDivs = new Array()           //Used to store Title Divs of the Gappers. 
	  var arrayInfoDivs = new Array()       //Used to store Info Divs of the Gappers.
	  var startIndex = 0;                   //Counter Start Point.
	  var endIndex=startIndex+(divisor-1);  //Counter End Point.
	  var currentIndex=0;                   //Counter Current Point.
  var countGapper = 0;
/*------------------------------------------------------------------------------------
Function          :  defaultBlogDivs()
Parameters passed :  None
Returning         :  None
Use				  :  To initialize the divs, populate the array dynamically and 
                     show the divs in sets using indices.
 ------------------------------------------------------------------------------------*/
function defaultDivs(id)
{
    var indx=0;
    var arrHidden = new Array()
	var splitArr = new Array()
	
  	/*Splitting the input and storing in an array*/ 
  	switch (id)
  	{
  	    case 3:
  	   
  	        arrHidden = document.getElementById("UCGapProjects1_hdnProgrammeTeachID").value;
  	        countGapper = document.getElementById("UCGapProjects1_hdnTeachCountProgramme").value;
  	        ShowBtmBnd("UCGapProjects1_rptSideNavigation_ctl00_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl01_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl02_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl03_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	 if (countGapper > divisor) 
            {
              document.getElementById("UCGapProjects1_rptSideNavigation_ctl00_divPreviousNext").style.display="block"
            }
  	        break;
  	    case 4:
  	          
  	        arrHidden = document.getElementById("UCGapProjects1_hdnVolunteerProgrammeID").value;
  	        countGapper = document.getElementById("UCGapProjects1_hdnVolunteerCountProgramme").value;
  	        ShowBtmBnd("UCGapProjects1_rptSideNavigation_ctl01_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl00_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl02_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl03_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        if (countGapper > divisor) 
            {
                  document.getElementById("UCGapProjects1_rptSideNavigation_ctl01_divPreviousNext").style.display="block"
            }
  	        break; 
  	    case 5:
  	        arrHidden = document.getElementById("UCGapProjects1_hdnInternProgrammeID").value;
  	        countGapper = document.getElementById("UCGapProjects1_hdnInternCountProgramme").value;
  	       ShowBtmBnd("UCGapProjects1_rptSideNavigation_ctl02_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	       HideInfo("UCGapProjects1_rptSideNavigation_ctl01_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl00_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl03_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	       
  	        if (countGapper > divisor) 
            {
                  document.getElementById("UCGapProjects1_rptSideNavigation_ctl02_divPreviousNext").style.display="block"
           
            }
  	        break;
  	    case 6:
  	        arrHidden = document.getElementById("UCGapProjects1_hdnOneOfKindProgrammeID").value;
  	        countGapper = document.getElementById("UCGapProjects1_hdnOneOfKindCountProgramme").value;
  	        ShowBtmBnd("UCGapProjects1_rptSideNavigation_ctl03_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl01_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl02_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	        HideInfo("UCGapProjects1_rptSideNavigation_ctl00_divOtherTopBand","divOtherBtmBand","divOtherTopBand");
  	       if (countGapper > divisor) 
            {
                  document.getElementById("UCGapProjects1_rptSideNavigation_ctl03_divPreviousNext").style.display="block"
            }
  	        break;   
  	} 	
     
    
      splitArr = arrHidden.split(',');   
          
      startIndex = 0;
      
   /*arrayDivs contains all the names of the bloggers*/

      for(indx=startIndex;indx<=countGapper;indx++)
      {    
        arrayDivs[indx] = "divProgramme" + splitArr[indx];
        arrayInfoDivs[indx] = "divProgrammeInfo" + splitArr[indx];
      }   
        
      
      
      
      
      hideAllTitleDivs();
	  hideAllInfoDivs();	  
	  currentIndex = getCurrentIndex(id);
  	  
	  startIndex = (currentIndex-(currentIndex%divisor));
      
          if (startIndex>=countGapper)	//startIndex will never exceed arrayDivs.length. It will be equal in case of last entry.
          {
              endIndex=startIndex;
          }
          else          
          {
               endIndex = (startIndex + (divisor-1)); 
                            
               if(endIndex >= countGapper)
               {    
                 
                    var temp = endIndex - arrayDivs.length;                      
                    endIndex = endIndex - temp - 1;
               }
          } 
         
	  showDivsInSet();	  
}
/*------------------------------------------------------------------------------------
Function          :  hide(param)
Parameters passed :  param
Returning         :  None
Use				  :  To hide the divs to provide the collapsing UI look 
------------------------------------------------------------------------------------*/
function hide(param)
{        
       if((navigator.appVersion.indexOf("MSIE 6.")!="-1"))

        {    

           

             document.getElementById(param).style.visibility = "hidden";
            document.getElementById(param).style.position = "absolute";
            
        }
        else
        {
           //document.getElementById(param).style.display="none";
         }
        
             
            
            
}

/*------------------------------------------------------------------------------------
Function          :  show(param)
Parameters passed :  param
Returning         :  None
Use				  :  To show the divs to provide the collapsing UI look 
------------------------------------------------------------------------------------*/
function show(param)
{        
     if((navigator.appVersion.indexOf("MSIE 6.")!="-1"))

        {     

            
 
            document.getElementById(param).style.visibility = "visible";
            document.getElementById(param).style.position = "relative";
            
            
        }
          
            else
        {
            document.getElementById(param).style.display="block";
         }
          
}
  	       
/*------------------------------------------------------------------------------------
Function          :  toggleBlogDivs(BlogTitle,BlogInfo)
Parameters passed :  BlogTitle , BlogInfo
Returning         :  None
Use				  :  To toggle the divs to provide the collapsing UI look 
------------------------------------------------------------------------------------*/
function toggleProgrammeDivs(blogTitle,blogInfo)
{   
   
     showDivsInSet();    
     
    if (currentIndex >= startIndex && currentIndex <= endIndex )
        {       
            hide(arrayInfoDivs[currentIndex])                        
            
            show(arrayDivs[currentIndex])                        
        }
        
         hide(blogTitle)
        show(blogInfo)
       
}
/*------------------------------------------------------------------------------------
Function          :  getCurrentIndex()
Parameters passed :  None
Returning         :  currentIndex 
Use				  :  To get the index of the current div as per the Url
 ------------------------------------------------------------------------------------*/
function getCurrentIndex(id)
{
    
    var c = 0;
    var d = 0;
    var appendedString = getAppendedString(id);
	
  
        
//	    if(appendedString==StringhomeDiv)
//	    {	
//		    /*startIndex=0;
//		    endIndex=startIndex+(divisor-1);*/
//		    currentIndex=0;
//		    return currentIndex;
//	    }
	     
    for(c=0;c<countGapper;c++)
    {
        
	    if(appendedString==arrayDivs[c])
	    {
	       
		    currentIndex=startIndex;
		    return currentIndex;
		    
	    }
	    /*Move this out of for loop*/
    }
}
  
/*------------------------------------------------------------------------------------
Function          :  getAppendedString()
Parameters passed :  None
Returning         :  Appended String
Use				  :  To append the string "divBlog" to the Gapper ID.
------------------------------------------------------------------------------------*/
function getAppendedString(id)
{
	    //var getUrl = window.location.href.substring(window.location.href.indexOf(".aspx"),window.location.href.lastIndexOf("/"));
	   
		//var subStrBlogName = getUrl.substring((getUrl.indexOf("/")+1),(getUrl.length));
		switch (id)
  	    {
  	        case 3:
  	        var subStrBlogName = "AssistWithTeachingOrVocationalTraining"
  	        break;
  	        case 4:
  	        var subStrBlogName = "HelpChildrenwithCerebralPalsy"
  	        break;
  	        case 5:
  	        var subStrBlogName = "NewspaperReporter"
  	        break;
  	        case 6:
  	        var subStrBlogName = "CrocodileConservation"
  	        break;
  	    }
		 
		var toAppend = "divProgramme";
		var appendedString = toAppend.concat("",subStrBlogName);
		
		return appendedString;		
}

/*------------------------------------------------------------------------------------
Function          :  showDivsInSet()
Parameters passed :  None
Returning         :  None
Use				  :  To show divs in sets.
 ------------------------------------------------------------------------------------*/   
function showDivsInSet()
{ 
    var i=0;
      hideAllTitleDivs();
      hideAllInfoDivs();            

	  for(i=startIndex;i<=endIndex;i++)
	  {
	    
    	//document.getElementById("UCGapBlog1_lblViewBlogs").innerHTML =  (startIndex+1) + " to " + (endIndex+1) + " of " + arrayDivs.length;
		//Uncomment the above statement to show blog status. ex. "Showing 1 to 7 of 32 blogs"\
		
		show(arrayDivs[i])		
		  if ((currentIndex >= startIndex) && (currentIndex <= endIndex))
		  {
		    
			  hide(arrayDivs[currentIndex])
		  	  show(arrayInfoDivs[currentIndex])			  
		  }
		  else
		  {		  
		        
			  hide(arrayDivs[currentIndex])
		  	  hide(arrayInfoDivs[currentIndex])
		  }
	  }
}
  
/*------------------------------------------------------------------------------------
Function          :  showPrevDiv()
Parameters passed :  None
Returning         :  None
Use				  :  To show the Previous set of Gappers.
 ------------------------------------------------------------------------------------*/   
function showPrevDiv()
{ 
    endIndex=startIndex-1;
   
   if(endIndex<=0)
   {  
	   endIndex=(arrayDivs.length-1);
	   startIndex=endIndex-(endIndex%divisor)
	 
		 showDivsInSet(); 
   }
   else
   {
	   startIndex=(endIndex-(divisor-1));
	   showDivsInSet(); 
   }       
       
       hide(arrayDivs[startIndex])
       show(arrayInfoDivs[startIndex])
       
   if((currentIndex!=startIndex) && (currentIndex >= startIndex) && (currentIndex <= endIndex))
   {
       show(arrayDivs[startIndex])
       hide(arrayInfoDivs[startIndex])
   }
}


/*------------------------------------------------------------------------------------
Function          :  showNextDiv()
Parameters passed :  None
Returning         :  None
Use				  :  To show the Next set of Gappers.
 ------------------------------------------------------------------------------------*/ 
function showNextDiv()
{
               
  startIndex=endIndex+1;
  if(startIndex >= arrayDivs.length)
  {
	  startIndex=0;
  }
  endIndex = startIndex+(divisor-1);
  if(endIndex>=arrayDivs.length)
  {
	  endIndex=arrayDivs.length-1;
  }
  
  showDivsInSet();
         hide(arrayDivs[startIndex])
         show(arrayInfoDivs[startIndex])
       
       if((currentIndex!=startIndex) && (currentIndex >= startIndex) && (currentIndex <= endIndex))
       {
           show(arrayDivs[startIndex])
           hide(arrayInfoDivs[startIndex])
       }
}

/*------------------------------------------------------------------------------------
Function          :  showAllTitleDivs()
Parameters passed :  None
Returning         :  None
Use				  :  To show all the Title Divs.
 ------------------------------------------------------------------------------------*/ 
function showAllTitleDivs()
{
   var i=0;
		for (i=0;i<arrayDivs.length;i++)
		{
				var VarShowTitle = document.getElementById(arrayDivs[i]);
				VarShowTitle.style.visibility = "visible";
				VarShowTitle.style.position = 'relative';	
				
		}
}

/*------------------------------------------------------------------------------------
Function          :  hideAllTitleDivs()
Parameters passed :  None
Returning         :  None
Use				  :  To hide all the Title Divs.
 ------------------------------------------------------------------------------------*/ 
function hideAllTitleDivs()
{
	var i=0;
	    	
		for (i=0;i<arrayDivs.length;i++)
		{   		
			var VarhiddenTitle = arrayDivs[i];						
			hide(VarhiddenTitle)		
		}	
		
}

/*------------------------------------------------------------------------------------
Function          :  showAllInfoDivs()
Parameters passed :  None
Returning         :  None
Use				  :  To show all the Info Divs.
 ------------------------------------------------------------------------------------*/ 	
function showAllInfoDivs()
{
   var i=0;
		for (i=0;i<arrayInfoDivs.length;i++)
		{ 
				var VarShowInfo = document.getElementById(arrayInfoDivs[i]);
				VarShowInfo.style.visibility = "visible";
				VarShowInfo.style.position = 'relative';	
				
		}	 
}

/*------------------------------------------------------------------------------------
Function          :  hideAllInfoDivs()
Parameters passed :  None
Returning         :  None
Use				  :  To hide all the Info Divs.
 ------------------------------------------------------------------------------------*/ 
function hideAllInfoDivs()
{
	var i=0;
		for(i=0;i<arrayInfoDivs.length;i++)		    
		{  	        
			var VarhiddenInfo = arrayInfoDivs[i];       
			hide(VarhiddenInfo)
		}
}


function ShowInfo(objId1,replacedby,replaced)
{
    
    
     
     switch (objId1)
     {
       
        case "UCGapProjects1_rptSideNavigation_ctl00_divOtherTopBand":
        defaultDivs(3);
        break;
        case "UCGapProjects1_rptSideNavigation_ctl01_divOtherTopBand":
        defaultDivs(4);
        break;
        case "UCGapProjects1_rptSideNavigation_ctl02_divOtherTopBand":
        defaultDivs(5);
        break;
        case "UCGapProjects1_rptSideNavigation_ctl03_divOtherTopBand":
        defaultDivs(6);
        break;
            
        
     }
}


function HideInfo(objId1,replacedby,replaced)
{
        var newid = objId1.replace(replaced,replacedby);   
     document.getElementById(newid).style.display="none";
}
function ShowBtmBnd(objId1,replacedby,replaced)
{
    
     var newid = objId1.replace(replaced,replacedby);   
     document.getElementById(newid).style.display="block";
     document.getElementById(newid).focus();
}