
/**
 * @class DhtmlPaginator
 * Paginator Class is used to dynamically handle the paging Next, Previous based on properties set for this object.
 * The values set are default, but they should be reset based on where it gets used
 * @constructor 
 */
 
Core.DhtmlPaginator=function () {
    /**
     * Part of substring of the main layer we are interested into applying paging
     */
    this.KeywordLayerContain='Category:Product:List'; //'
    /**
     * tag name
     */
    this.TagName='div';
    /**
     * size (number of elemnts displayed in one page)
     */
    this.PageSize=5;
    /**
     * total pages within a layer/product/category
     */
    this.TotalPages=0;
    /**
     *  array where results will be saved
     */
    this.NavigateArray=new Array();
    /**
     * current page where the user is navigating
     */
    this.CurrentPage=0;
    /**
     * the layer id of the parent
     */
    this.ParentID='';
    /**
     * if true the buttons will be managed autimatically
     */
    this.SetNavigationLabels=true;
    /**
     * The id of next button on the header
     */
    this.NextButtonID="nextpage";
    /**
     * The id of next button on the footer
     */
    this.NextButtonID_Footer="nextpage_footer";
    /**
     * the id of previous on the header
     */
    this.PreviousID="Previous";
    
    /**
     * the id of previous on the header
     */
    this.PreviousID_Footer="Previous_Footer";
    /**
     * the layer where total number of pages will be displayed(optional)
     */
    this.DisplayPageNumberID="currentpageof";
     /**
     * the layer where total number of pages will be displayed(optional)on the footer
     */
    this.DisplayPageNumberID_Footer="currentpageof_footer";
    
    /**
     *  if GeneratePageNumbers=true, the page numbers will be generated
     */
    this.GeneratePageNumbers=false;
     /**
     *  This layer holds all other buttons like next, prev, 1,2,3, view all etc.. and it will
     * be marked as hidden if there is only one page.
     */
    this.MainPaginatorLayerID="AJAX_PAGINATOR_LAYER";
    this.MainPaginatorLayerID_FOOTER="AJAX_PAGINATOR_LAYER_FOOTER";
     /**
     * Layer id where the numbers will be displayedon the header
     */
    this.PageNumberLayerID="Ajax_Page_Numbers"
    
    /**
     * Layer id where the numbers will be displayedon the footer
     */
    this.PageNumberLayerID_Footer="Ajax_Page_Numbers_Footer";
     /**
     * html for links opening tag for numbers
     */
     this.PageNumberOpeningTag=CORE_AJAX_PAGING_NUMBERS_STYLESHEET;
    
     /**
     * html for closing tags for numbers
     */
     this.PageNumberClosingTag=CORE_AJAX_PAGING_NUMBERS_CLOSING_TAG;
     
     /**
     * html for opening tag for current page
     */
     this.CurrentPageOpeningTag=CORE_AJAX_CURRENT_PAGE_STYLESHEET;
    
     /**
     * html for closing tag for current page
     */
     this.CurrentPageClosingTag=CORE_AJAX_CURRENT_PAGE_CLOSING_TAG;
   /**
     * Saves current to be shown
     */
    this.CurrentItemsToShow=new Array();
    /**
     *  Saves current to be Hidden
     */
    this.CurrentItemsToHide=new Array;
    
    /**
     *  all variants
     */
    this.AllVariantsBtnID="ajax_all_variants";
     /**
     * Text to be displayed on view all btn
     */
    this.ViewAllLabel="view all";
      
    /**
     *  Saves Filtered Data 
     */
    this.FilteredData=null;
    this.IsFilterOn=false;
    
    /**
     *  Generates page numbers for both header and footer
     *  if the GeneratePageNumbers is set to true and at least one layer for header or footer exist
     *
     */
    this.DoGeneratePageNumbers=function(){
     if(this.GeneratePageNumbers==false) return;
      var sb = new StringBuilder();
       if (this.TotalPages>=1) {
          for (var i = 1; i <= this.TotalPages ; i++) {
             // if there are over 20 pages add a break for every 20 pages
             if ((i%20) == 0)
                sb.append("<br/>");
                
             if (this.CurrentPage==i) {
              // sb.append(this.PageNumberOpeningTag + i.toString() +this.PageNumberClosingTag+ "&nbsp;");
                sb.append(this.CurrentPageOpeningTag + i.toString() +this.CurrentPageClosingTag+ "&nbsp;&nbsp;");
       
             }
             else {
              sb.append("<a " + " onclick=\"_NavigatorManager.DoPageByIndex('" + this.ParentID + "'," +i.toString() + ")\" style=\"cursor:pointer\";>" + this.PageNumberOpeningTag + i.toString() +this.PageNumberClosingTag+ "</a>&nbsp;&nbsp;");
            }
          }
          
           if (this.TotalPages>1) {
               if (this.CurrentPage==-1) {
                  sb.append(this.CurrentPageOpeningTag + this.ViewAllLabel +this.CurrentPageClosingTag+ "&nbsp;");
       
               }
               else {
                  sb.append("<a " + " onclick=\"_NavigatorManager.DoPageByIndex('" + this.ParentID + "',0)\" style=\"cursor:pointer\";>" + this.PageNumberOpeningTag + this.ViewAllLabel + this.PageNumberClosingTag+ "</a>&nbsp;");
             }
           }
          
           var pageNumbersObj_Header=$get(this.PageNumberLayerID);
           if (pageNumbersObj_Header!=null) {
                  pageNumbersObj_Header.innerHTML=sb.toString();
           }
           
           var pageNumbersObj_Footer=$get(this.PageNumberLayerID_Footer);
           if (pageNumbersObj_Footer!=null) {
                 pageNumbersObj_Footer.innerHTML=sb.toString();
           }
       }
       
    }
    /**
     * Initializes the object
     */
    this.Initialize=function() {
        var list;
         this.NavigateArray=new Array();
        if (this.ParentID!='') {
        //alert(typeof($));
            var parentObj=$get(this.ParentID);
            // if (parentObj==null || typeof(parentObj)='undefined') return;
            list=parentObj.getElementsByTagName(this.TagName);
        }
        else {
            list = document.body.getElementsByTagName(this.TagName);
            //var list = document.body.getElementsByTagName(this.TagName);
        }

        for (var i = 0; i < list.length ; i++) {
            if (list[i].id.indexOf(this.KeywordLayerContain) !=-1) {
                //this.NavigateArray[this.NavigateArray.length]=list[i].id;
                this.NavigateArray[this.NavigateArray.length]=list[i];
            }
        }

        if ((this.NavigateArray !=null) && (this.PageSize>0)) {
            this.TotalPages=Math.ceil(parseInt(this.NavigateArray.length)/parseInt(this.PageSize));
        }
        this.CurrentPage=0;
        
    }
    
    this.InitializeFilter=function() {
        this.HideAll(); //hide previous page!
         var list;
         this.NavigateArray=new Array();
        if (this.ParentID!='') {
             var parentObj=$get(this.ParentID);
             list=parentObj.getElementsByTagName(this.TagName);
        }
        else {
            list = document.body.getElementsByTagName(this.TagName);
        }
     
        for (var i = 0; i < list.length ; i++) {
            for (var j = 0; j < this.FilteredData.length ; j++) {
                 if (list[i].id.indexOf(this.FilteredData[j]) !=-1) {           //make sure productcode is part of
                      if(list[i].id.indexOf(this.KeywordLayerContain) !=-1){    //make sure it has the contain layer id
                         this.NavigateArray[this.NavigateArray.length]=list[i];
                       }
                  }
            }
        }

        if ((this.NavigateArray !=null) && (this.PageSize>0)) {
            this.TotalPages=Math.ceil(parseInt(this.NavigateArray.length)/parseInt(this.PageSize));
        }
        this.CurrentPage=0;
        this.DoNext();
        
    }


    /**
     * hides all pages
     */
    this.HideAll=function(){
        if (this.NavigateArray  !=null) {
            for (var i=0;i<this.NavigateArray.length;i++) {
                if (typeof(this.NavigateArray[i])=='object'){
                    this.NavigateArray[i].style.display='none';
                }
                else {
                    var divid=this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display='none';
                }
            }
        }
    }

    /**
     * shows all pages
     */
    this.ShowAll=function(){
        if (this.NavigateArray !=null ) {
            for (var i=0;i<this.NavigateArray.length;i++) {
                if (typeof(this.NavigateArray[i])=='object'){
                    // this.NavigateArray[i].style.display='block';
                    this.NavigateArray[i].style.display='';
                }
                else {
                    var divid=this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display='block';
                }
            }
        }
    }
    
    /*
     * this method supports navigating to a particular page by index
    */
    this.DoPageByIndex=function(index) {
        this.CurrentPage=parseInt(index)-1;
        if (this.CurrentPage>=0) {
             this.DoNext();
        }
        else {
           this.DoGeneratePageNumbers();
           this.EraseFooterLabel();
           this.ShowAll();
        }
    }
    
    this.EraseFooterLabel=function() {
             //display page x of y on a label for the current page on the footer
            var tempObj=$get(this.DisplayPageNumberID);
            if (tempObj!=null) {
                tempObj.innerHTML="";
            }
            //display page x of y on a label for the current page on the footer
            var tempObj_Footer=$get(this.DisplayPageNumberID_Footer);
             if (tempObj_Footer!=null) {
                tempObj_Footer.innerHTML="";
            }
    
    
    }
    /**
     * naviates to the next page
     */
    this.DoNext=function() {
        if (this.CurrentPage>=this.TotalPages) return false;
        if (this.CurrentPage<=this.TotalPages)  this.HideAll();
        if (this.CurrentPage<=0) this.CurrentPage=0;

        this.CurrentPage=this.CurrentPage+1;
        var startI=(this.CurrentPage-1) * this.PageSize;
        var endI=this.CurrentPage * this.PageSize;

        this.SetLabels();
        this.DoGeneratePageNumbers();
        this.CurrentItemsToShow=new Array();
        for (var i=startI;i<endI;i++) {
            if (i<this.NavigateArray.length) {
                 this.CurrentItemsToShow[ this.CurrentItemsToShow.length]=this.NavigateArray[i]
                if (typeof(this.NavigateArray[i])=='object'){
                    // this.NavigateArray[i].style.display='block';
                    this.NavigateArray[i].style.display='';
                }
                else {
                    var divid=this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display='block';
                }
            }
        }
    }

 
      /**
     * naviates to the next page in a slide
     */
    this.DoNextSlide=function() {
        if (this.CurrentPage>=this.TotalPages) return false;
        if (this.CurrentPage<=0) this.CurrentPage=0;
        this.CurrentPage=this.CurrentPage+1;
        var startI=(this.CurrentPage-1) * this.PageSize;
        var endI=this.CurrentPage * this.PageSize;
        this.SetLabels();
        this.DoGeneratePageNumbers();
        //initialize array
        this.CurrentItemsToHide=new Array();
        //copy array
        for (var i = 0; i < this.CurrentItemsToShow.length; i++)   {
            this.CurrentItemsToHide[this.CurrentItemsToHide.length]=this.CurrentItemsToShow[i];

        }
        //initialize array
        this.CurrentItemsToShow=new Array();
        for (var i=startI;i<endI;i++) {
             if (i<this.NavigateArray.length) {
                 this.CurrentItemsToShow[ this.CurrentItemsToShow.length]=this.NavigateArray[i];
             }
        }
        //initialize array
        CurrentItemsToShow=new Array();
        //initialize array
        CurrentItemsToHide=new Array();
         //copy array to global variable
        for (var i = 0; i < this.CurrentItemsToShow.length; i++)   {

            CurrentItemsToShow[CurrentItemsToShow.length]=this.CurrentItemsToShow[i];

        }
         //copy array to global variable
        for (var i = 0; i < this.CurrentItemsToHide.length; i++)   {

            CurrentItemsToHide[CurrentItemsToHide.length]=this.CurrentItemsToHide[i];

        }
       
       //initialize index of item to be shown first
       ToShowIndex=0;
       //initialize index of item to be hidden first
       ToHideIndex=0;
       DoCoreSlideNext();
    }
    /**
     * navigates to Previous page
     */
    this.DoPrev=function() {
        if (this.CurrentPage<=1) return false;
        if (this.CurrentPage<=this.TotalPages)  this.HideAll();
        if (this.CurrentPage==this.TotalPages) this.CurrentPage=this.TotalPages;

        this.CurrentPage=this.CurrentPage-1;

        var startI=(this.CurrentPage-1) * this.PageSize;
        var endI=this.CurrentPage * this.PageSize;

        this.SetLabels();
        this.DoGeneratePageNumbers();
        for (var i=startI;i<endI;i++) {
            if (i<this.NavigateArray.length) {
                if (typeof(this.NavigateArray[i])=='object') {
                    this.NavigateArray[i].style.display='';
                }
                else {
                    var divid=this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display='block';
                }
            }
        }
    }

    /**
     * navigates to Previous page in a slide
     */
    this.DoPrevSlide=function() {
        if (this.CurrentPage<=1) return false;
        if (this.CurrentPage==this.TotalPages) this.CurrentPage=this.TotalPages;

        this.CurrentPage=this.CurrentPage-1;

        var startI=(this.CurrentPage-1) * this.PageSize;
        var endI=this.CurrentPage * this.PageSize;

        this.SetLabels();
        this.DoGeneratePageNumbers();
        //initialize
        this.CurrentItemsToHide=new Array();
        //copy current shown to array of to be hidden
        for (var i = 0; i < this.CurrentItemsToShow.length; i++)   {
            this.CurrentItemsToHide[this.CurrentItemsToHide.length]=this.CurrentItemsToShow[i];

        }
         //initialize
        this.CurrentItemsToShow=new Array();
        
        for (var i=startI;i<endI;i++) {
            if (i<this.NavigateArray.length) {
                //save the reference for further processing in a slide
                this.CurrentItemsToShow[ this.CurrentItemsToShow.length]=this.NavigateArray[i];
             }
        }
        //initialize
         CurrentItemsToShow=new Array();
         //initialize
         CurrentItemsToHide=new Array();
          //copy array to global variable
         for (var i = 0; i < this.CurrentItemsToShow.length; i++)   {

            CurrentItemsToShow[CurrentItemsToShow.length]=this.CurrentItemsToShow[i];

          }
         
         //copy array to global variable
         for (var i = 0; i < this.CurrentItemsToHide.length; i++)   {

            CurrentItemsToHide[CurrentItemsToHide.length]=this.CurrentItemsToHide[i];

        }
        //set initial index for items to be shown
         ToShowIndex=CurrentItemsToShow.length - 1;
         //set initial index for items to be hidden
         ToHideIndex=CurrentItemsToHide.length -1;
         //call the slide function
         DoCoreSlidePrev();
    }
    
     /**
     * This function hides the main layer of paginator if there is less or equal one page and shows otherwise
     * 
     * 
     */
    this.ManagePaginatorMainLayers=function() {
         var temp_objMainPaginatorLayerID=$get( this.MainPaginatorLayerID );
            
         var temp_objMainPaginatorLayerID_FOOTER=$get( this.MainPaginatorLayerID_FOOTER );
         
          if (temp_objMainPaginatorLayerID!=null) {
                if (this.TotalPages>1) {
                        temp_objMainPaginatorLayerID.style.visibility="visible";
                         }
                else {
                        temp_objMainPaginatorLayerID.style.visibility="hidden";  
                }
          }
          
           if (temp_objMainPaginatorLayerID_FOOTER!=null) {
                if (this.TotalPages>1) {
                        temp_objMainPaginatorLayerID_FOOTER.style.visibility="visible";
                         }
                else {
                        temp_objMainPaginatorLayerID_FOOTER.style.visibility="hidden";  
                }
          }
    
    }
    /**
     * This function manages the next, previous buttons both on header and footer,
     * it also manages the Off btns. They are all optional and the code handles the run time error if any
     * of them is missing
     */
     
    this.SetLabels=function(){
        
         var _off="_OFF";
         //Next
         var tempObj_Next=$get(this.NextButtonID);
         var tempObj_OFF_Next=$get(this.NextButtonID +_off);
          //Next footer 
         var tempObj_Next_Footer=$get(this.NextButtonID_Footer);
         var tempObj_OFF_Next_Footer=$get(this.NextButtonID_Footer +_off);
         
         //Prev
         var tempObj_Prev=$get(this.PreviousID);
         var tempObj_OFF_Prev=$get(this.PreviousID +_off);
         //Prev Footer
         var tempObj_Prev_Footer=$get(this.PreviousID_Footer);
         var tempObj_OFF_Prev_Footer=$get(this.PreviousID_Footer +_off);
         //all variants btn
         var tempobj_AllVariantsBtnID=$get(this.AllVariantsBtnID);
         
         
          this.ManagePaginatorMainLayers();
         if (this.SetNavigationLabels) {
             
            //handle all shades btn
              if (tempobj_AllVariantsBtnID!=null) {
                  if (this.TotalPages>1) {
                        tempobj_AllVariantsBtnID.style.visibility="visible";
                        tempobj_AllVariantsBtnID.style.display="";
                }
                else {
                        tempobj_AllVariantsBtnID.style.visibility="hidden";  
                }
            }
            
            
            //Hide all OFF Buttons on header and footer navigations
            if ( tempObj_OFF_Next!=null) {
                        tempObj_OFF_Next.style.display="";
            }
            
            if ( tempObj_OFF_Prev!=null) {
                        tempObj_OFF_Prev.style.display="";
            }
            
            if ( tempObj_OFF_Next_Footer!=null) {
                        tempObj_OFF_Next_Footer.style.display="";
            }
            
            if ( tempObj_OFF_Prev_Footer!=null) {
                        tempObj_OFF_Prev_Footer.style.display="";
            }
            
            //display page x of y on a label for the current page
            var tempObj=$get(this.DisplayPageNumberID);
            
            if (tempObj!=null) {
                tempObj.innerHTML=PAGE_PAGExOFy + this.CurrentPage + OFF_PAGExOFy + this.TotalPages +  DISPLAY_PAGExOFy;
            }
            //display page x of y on a label for the current page on the footer
            var tempObj_Footer=$get(this.DisplayPageNumberID_Footer);
             if (tempObj_Footer!=null) {
                tempObj_Footer.innerHTML=PAGE_PAGExOFy + this.CurrentPage + OFF_PAGExOFy + this.TotalPages + DISPLAY_PAGExOFy;;
            }
            
            // tempObj=$get(this.PreviousID);
             if (tempObj_Prev!=null) {
                  if (this.TotalPages>1) {
                    
                       tempObj_Prev.style.display="";
                       
                }
                else {
                       tempObj_Prev.style.display="none";
                      
                }
            }
            if (tempObj_OFF_Prev!=null) {
                  if (this.TotalPages>1) {
                      
                       tempObj_OFF_Prev.style.display="none";
                }
                else {
                    
                       tempObj_OFF_Prev.style.display="";
                }
            }
            //handle prev button initially on footer
            
             if (tempObj_Prev_Footer!=null) {
                  if (this.TotalPages>1) {
                      
                        tempObj_Prev_Footer.style.display="";
                       
                }
                else {
                    
                      tempObj_Prev_Footer.style.display="none"; 
                  
                }
            }
            
            if ( tempObj_OFF_Prev_Footer!=null) {
                  if (this.TotalPages>1) {
                       
                         tempObj_OFF_Prev_Footer.style.display="none";
                }
                else {
                     
                      tempObj_OFF_Prev_Footer.style.display="";
                }
            }
            
            //tempObj=$get(this.NextButtonID);
            //
            if (tempObj_Next!=null) {
                 if (this.TotalPages>1) {
                   
                     tempObj_Next.style.display="";
                   
                                 
                }
                else {
                     tempObj_Next.style.display="none";
                  
                }
            }
         
         if (tempObj_OFF_Next!=null) {
                 if (this.TotalPages>1) {
                       tempObj_OFF_Next.style.display="none";
                                 
                }
                else {
                      tempObj_OFF_Next.style.display=""
                }
            }
             
             //handle next button initially on footer
            
             if (tempObj_Next_Footer!=null) {
                  if (this.TotalPages>1) {
                          tempObj_Next_Footer.style.display="";
                }
                else {
                      
                       tempObj_Next_Footer.style.display="none";
                }
            }
            
            if (tempObj_OFF_Next_Footer!=null) {
                  if (this.TotalPages>1) {
                         tempObj_OFF_Next_Footer.style.display="none";
                }
                else {
                        tempObj_OFF_Next_Footer.style.display="";
                }
            }
            //
              if (this.TotalPages>1) { // if more than one page do the following.
                    if (this.CurrentPage>=this.TotalPages) {
                       
                        //show previous header and/or footer
                        if (tempObj_Prev!=null) {
                            //tempObj_Prev.style.visibility="visible";
                            tempObj_Prev.style.display="";
                            
                        }
                        if ( tempObj_Prev_Footer!=null) {
                             //tempObj_Prev_Footer.style.visibility="visible";
                             tempObj_Prev_Footer.style.display="";
                             
                        }
                       
                        //hide OFF previous 
                        if ( tempObj_OFF_Prev!=null) {
                             tempObj_OFF_Prev.style.display="none";
                        }
                        if ( tempObj_OFF_Prev_Footer!=null) {
                              tempObj_OFF_Prev_Footer.style.display="none";
                        }
                        
                        
                        // Hide NEXT
                        if (tempObj_Next!=null) {
                            //tempObj_Next.style.visibility="hidden";
                            tempObj_Next.style.display="none";
                        }
                        if (tempObj_Next_Footer!=null) {
                            //tempObj_Next_Footer.style.visibility="hidden";
                            tempObj_Next_Footer.style.display="none";
                        }
                       
                        // Show NEXT DISABLED
                       if ( tempObj_OFF_Next!=null) {
                             tempObj_OFF_Next.style.display="";
                        }
                        
                        if ( tempObj_OFF_Next_Footer!=null) {
                             tempObj_OFF_Next_Footer.style.display="";
                        }
                        
                    }

                    if (this.CurrentPage<=1) {
                        //hide next
                       
                        if (tempObj_Prev!=null) {
                            //tempObj_Prev.style.visibility="hidden";
                             tempObj_Prev.style.display="none";
                        }
                        
                         if (tempObj_Prev_Footer!=null) {
                            //tempObj_Prev_Footer.style.visibility="hidden";
                            tempObj_Prev_Footer.style.display="none";
                        }
                        
                        //show previous disabled
                        if ( tempObj_OFF_Prev!=null) {
                             tempObj_OFF_Prev.style.display="";
                        }
                        if ( tempObj_OFF_Prev_Footer!=null) {
                             tempObj_OFF_Prev_Footer.style.display="";
                        }
                        //show next
                        if (tempObj_Next!=null) {
                            //tempObj_Next.style.visibility="visible";
                            tempObj_Next.style.display="";
                        }
                        
                        if (tempObj_Next_Footer!=null) {
                            //tempObj_Next_Footer.style.visibility="visible";
                            tempObj_Next_Footer.style.display="";
                        }
                        
                         // hide NEXT DISABLED
                        if ( tempObj_OFF_Next!=null) {
                             tempObj_OFF_Next.style.display="none";
                        }
                         if ( tempObj_OFF_Next_Footer!=null) {
                             tempObj_OFF_Next_Footer.style.display="none";
                        }
                    }
            }
        }
    }
   
 }
/**
 * It registers the  DhtmlPaginator using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.DhtmlPaginator.registerClass('Core.DhtmlPaginator'); }

 /* End of Paginator Class */

/**
 * @class NavigatorManager
 * NavigatorManager  Class is used to dynamically iterate the DHTML Object and add next/prev buttons based
 * the values that are passed on the Initialize method
 * It Also keep the reference of such DHTML Object for the sake of bookmarking/navigations
 * Here is an example how I used this class and initialized it on topic page
 *       var _NavigatorManager=new NavigatorManager();
 *       _NavigatorManager.Initialize('Topic:Product:List','div','Topic_Product','td',5,false);
 * @constructor 
 */

 Core.NavigatorManager=function () {
    /**
     * collection of navigators
     */
    this._NavigatorCollection=new Array();
    this.FilteredData;
    
     this.DoMainFilterInitialization=function(ParentLayerContains) {
        var productCodesArray=new Array();
        var lastProductCodeFethched=""
        this.FilteredData.sort();
         for (var i=0;i<this.FilteredData.length;i++) {
            var currentRecord_Array=this.FilteredData[i].split(":"); 
            if (currentRecord_Array[1]!="" && currentRecord_Array[1]!=lastProductCodeFethched){
                lastProductCodeFethched=currentRecord_Array[1];
                productCodesArray[productCodesArray.length]=currentRecord_Array[1];
            }
            // productCodesArray[productCodesArray.length]=currentRecord_Array[1];
         }
         if (productCodesArray.length>0) {
              var currentNavigator=this.GetNavigator(ParentLayerContains);
               currentNavigator.IsFilterOn=true;
               currentNavigator.FilteredData=productCodesArray;
               currentNavigator.InitializeFilter();
         }
     }
    
    this.DoFilterInitialization=function(ParentLayerContains) {
        var currentPrdCode="";
        var currentParentPrdCode="";
        var currentNavigator=null;
        var variantsByProduct=new Array();
        var allDistinctFilteredProducts=new Array();
        var noMatchIDs=new Array();
        this.FilteredData.sort();
        for (var i=0;i<this.FilteredData.length;i++) {
            var currentRecord_Array=this.FilteredData[i].split(":"); 
                if (currentRecord_Array[0]!=currentParentPrdCode) {
                    if (currentNavigator!=null) { 
                        currentNavigator.FilteredData=variantsByProduct ;
                        currentNavigator.InitializeFilter();
                        
                     }
                     
                 variantsByProduct=new Array();
                 currentParentPrdCode=currentRecord_Array[0];
                 allDistinctFilteredProducts[allDistinctFilteredProducts.length]=currentRecord_Array[0];
                 // var tempParentID="Category:Product:List:" + currentParentPrdCode;
                 var tempParentID=ParentLayerContains + currentParentPrdCode;
                 currentNavigator=this.GetNavigator(tempParentID);
                 if (currentNavigator!=null || typeof(currentNavigator)!='undefined') {
                   
                       currentNavigator.FilteredData=new Array();;
                       currentNavigator.IsFilterOn=true;
                 }
              }
              if (currentRecord_Array[1]!=currentPrdCode) { //array is sorted and this condition is placed to remove any duplicate!
                 currentPrdCode=currentRecord_Array[1];
                 variantsByProduct[variantsByProduct.length]=currentPrdCode;
                
              }
        }
         //last product of the array
          if (currentNavigator!=null) { 
                        currentNavigator.FilteredData=variantsByProduct ;
                        currentNavigator.InitializeFilter();
                        
          }
      
        //hide the variants of those who does not have a match
        for (var i=0;i<this._NavigatorCollection.length;i++) {
        
             var blnExist=false;
              var tempObj=this.GetNavigator(this._NavigatorCollection[i].ParentID);
           
              if ( tempObj.ParentID.indexOf(ParentLayerContains)!=-1 ){
                          for (var j=0;j<allDistinctFilteredProducts.length;j++) {
                            var tempNavigatorID=ParentLayerContains + allDistinctFilteredProducts[j];
                              if (tempObj.ParentID==tempNavigatorID) {
                                         blnExist=true;
                                        break;
                               }
                   
                           }
                // alert(tempObj.ParentID);
                  if (blnExist==false) {
                       noMatchIDs[noMatchIDs.length]=tempObj.ParentID;
                      tempObj.IsFilterOn=true; //but no match
                      tempObj.HideAll();
                      tempObj.TotalPages=0;
                 }
              }
            
         }
         //
         var FilteredParent=new Array(); //removed the products that come from database but has no match on the page.
         for (var i=0;i<allDistinctFilteredProducts.length;i++) {
                for (var j=0;j<noMatchIDs.length;j++)  {
                   if ( noMatchIDs[j].indexOf(allDistinctFilteredProducts[i])!=-1 ) {
                     allDistinctFilteredProducts[i]="";
                     
                   }
                }
          }
          //
          for (var i=0;i<allDistinctFilteredProducts.length;i++) {
              if (allDistinctFilteredProducts[i]!="") {
                FilteredParent[FilteredParent.length]=":" + allDistinctFilteredProducts[i];
              }
          }       
          //
          if (allDistinctFilteredProducts.length>0) {
           this.FilteredData=FilteredParent;
           this.DoMainFilterInitialization(MAIN_LAYER_PARENT_CONTAINS);
          }
      
    }
    
    //
    this.ClearFilter=function() {
      for (var i=0;i<this._NavigatorCollection.length;i++) {
            if (this._NavigatorCollection[i].IsFilterOn==true) {
                    this._NavigatorCollection[i].Initialize();
                    this._NavigatorCollection[i].DoNext();
          
           }
       }
    }
    /**
     * adds a navigator in the collection
     * @param {object} NavigatorObject TODO
     */
    this.AddNavigator= function (NavigatorObject) {
        var exist=false;
        if (this._NavigatorCollection!=null) {
            for (var i=0;i<this._NavigatorCollection.length;i++) {
                if (this._NavigatorCollection[i].ParentID==NavigatorObject.ParentID) {
                    this.NavigatorObject[i]=NavigatorObject;
                    exist=true;
                    break;
                }
            }
            if(exist==false) {
                this._NavigatorCollection[this._NavigatorCollection.length]=NavigatorObject;
            }
        }
    }

    /**
     * returns an elemnt within a collection based on parentid which has to be unique
     * @param {string} ParentID where the object is contained
     */
    this.GetNavigator=function (ParentID) {
        for (var i=0;i<this._NavigatorCollection.length;i++) {
            if (this._NavigatorCollection[i].ParentID==ParentID) {
                return this._NavigatorCollection[i];
            }
        }
    }
    
    this.DoPageByIndex=function(ParentID,index) {
       var CurrentNavigator=this.GetNavigator(ParentID);
       CurrentNavigator.DoPageByIndex(index);
    }
    /**
     * naviates to the next page
     * @param {string} ParentID 
     * @param {object} NextObject 
     */
    this.DoNext=function(ParentID,NextObject,DoSlide) {
        var CurrentNavigator=this.GetNavigator(ParentID);
        CurrentNavigator.NextButtonID=NextObject.id;
        if (DoSlide) {
                CurrentNavigator.DoNextSlide();
        }
        else {
           CurrentNavigator.DoNext();
        }
    }
    
    /**
     * naviates to the next page from the footer
     * @param {string} ParentID 
     * @param {object} NextFooterObject 
     */
    this.DoNextFromFooter=function(ParentID,NextFooterObject) {
        var CurrentNavigator=this.GetNavigator(ParentID);
        CurrentNavigator.NextButtonID_Footer=NextFooterObject.id;
        CurrentNavigator.DoNext();
    }
    /**
     * Shows all pages
     * @param {string} ParentID 
     */
    this.ShowAll=function(ParentID) {
        var CurrentNavigator=this.GetNavigator(ParentID);
        CurrentNavigator.ShowAll();
    }

    /**
     * Navigates to previous page
     * @param {string} ParentID for prev button
     * @param {object} PreviousObject 
     */
    this.DoPrev=function(ParentID,PreviousObject,DoSlide) {
        var CurrentNavigator=this.GetNavigator(ParentID);
        CurrentNavigator.PreviousID=PreviousObject.id;
        if(DoSlide) {
          CurrentNavigator.DoPrevSlide();
        }
        else {
        CurrentNavigator.DoPrev();
        }
    }
    
      /**
     * Navigates to previous page from the footer
     * @param {string} ParentID of the whole container for pages
     * @param {object} PreviousFooterObject
     */
    this.DoPrevFromFooter=function(ParentID,PreviousFooterObject) {
        var CurrentNavigator=this.GetNavigator(ParentID);
        CurrentNavigator.PreviousID_Footer=PreviousFooterObject.id;
        CurrentNavigator.DoPrev();
    }
    /**
     * This is a very important method
     * which first retrievs from document object all the tags with name ParenTagName like "div", span", "td", "tr" etc....
     * Then it iterates via such object and searches only those that have as part of the ID the substring
     * ParentContains which could be like Topic:Product:List
     * If an object meets that criteria, then we are intersted from objects within that parent
     * that has their tags as ChildTagName and contains on their ID the value ChildContains.
     * @param {string} ParentContains Substring of DHTML Object we are interested. <b>Importnat, try to keep such value unique based on what we need to process</b>
     * @param {string} ParenTagName Tag name of parents like div, span, td, tr etc...
     * @param {string} ChildContains Substring of DHTML Object we are interested. <b>Importnat, try to keep such value unique based on what we need to process</b>
     * @param {string} ChildTagName Tag name of parents like div, span, td, tr etc...
     * @param {int} PageSize How manay elements of childcontain wanted to be visible at a certain time
     * @param {bool} BoolNavigationBtnsWanted It determines if we want to manage the buttons next and prev 
     * @param {bool} BoolGeneratePageNumbers if set to true, generates the page numbers like 1,2,3,4 etc..
      */
    this.Initialize=function(ParentContains, ParenTagName, ChildContains, ChildTagName, PageSize, BoolNavigationBtnsWanted,AssumeNavigationBtns,BoolGeneratePageNumbers) {
        var list = document.body.getElementsByTagName(ParenTagName);
        for (var i = 0; i < list.length ; i++) {
            if (list[i].id.indexOf(ParentContains) !=-1) {
                var _TempNavigator= new Core.DhtmlPaginator();
                _TempNavigator.PageSize=PageSize;
                _TempNavigator.SetNavigationLabels=BoolNavigationBtnsWanted;
                _TempNavigator.KeywordLayerContain=ChildContains; // //'
                _TempNavigator.TagName=ChildTagName;
                _TempNavigator.ParentID=list[i].id;
                //navigation buttons
                if(AssumeNavigationBtns!=null) {
                    if (AssumeNavigationBtns) {
                         _TempNavigator.NextButtonID="Next_" + list[i].id.replace(ParentContains,'');
                         _TempNavigator.PreviousID="Prev_" + list[i].id.replace(ParentContains,'');
                         //
                         _TempNavigator.AllVariantsBtnID="ajax_all_variants_" + list[i].id.replace(ParentContains,'');
                         //
                         _TempNavigator.NextButtonID_Footer=_TempNavigator.NextButtonID_Footer + "_" +list[i].id.replace(ParentContains,'');
                         _TempNavigator.PreviousID_Footer=_TempNavigator.PreviousID_Footer + "_" +list[i].id.replace(ParentContains,'');
                         _TempNavigator.DisplayPageNumberID=_TempNavigator.DisplayPageNumberID + "_" +list[i].id.replace(ParentContains,'');
                         _TempNavigator.DisplayPageNumberID_Footer=_TempNavigator.DisplayPageNumberID_Footer + "_" +list[i].id.replace(ParentContains,'');
                        //
                         _TempNavigator.ViewAllPagesHeader="viewall_header" + list[i].id.replace(ParentContains,'');
                         _TempNavigator.ViewAllPagesFooter="viewall_footer"  + list[i].id.replace(ParentContains,'');
                        
                        //
                         _TempNavigator.MainPaginatorLayerID="AJAX_PAGINATOR_LAYER"  + list[i].id.replace(ParentContains,'');
                         _TempNavigator.MainPaginatorLayerID_FOOTER="AJAX_PAGINATOR_LAYER_FOOTER"  + list[i].id.replace(ParentContains,'');
                        //
                        
                        _TempNavigator.SetNavigationLabels=true;
                    }
                 }
                   
                _TempNavigator.GeneratePageNumbers=BoolGeneratePageNumbers;
                _TempNavigator.Initialize();
                _TempNavigator.DoNext();
                this.AddNavigator( _TempNavigator);
            }
        }
    }
}
 /**
 * It registers the  Core.NavigatorManager using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.NavigatorManager.registerClass('Core.NavigatorManager'); }

