﻿/**
 * IsTypeDefined is a boolean indicating wether the TYPE is defined or no
 * which is part of the MS AJAX
 */
var IsTypeDefined=false; 
/** 
 * Determines if TYPE is defined and if so, it set a global variable to true
 */
function SetTypeState() {
       if (typeof(Type)!='undefined') {
               IsTypeDefined=true
       }
       else {
            IsTypeDefined=false;
            eval("Core=function() {  }");
       
       }
}
/** 
 * calls SetTypeState and sets it to true if TYPE is defined
 */
SetTypeState();

/*
 * It Creates a namespace using MS Ajax Libraries "making javascript easier" if TYPE is defined
 */
 if (IsTypeDefined){ Type.registerNamespace("Core");  }

 /**
 * @class StringBuilder
 * Models a simple string builder class
 * @param {string} value The value to append to the array
 * @constructor
 */
 function StringBuilder(value) {
     this.strings = new Array("");
     this.append(value);
 }

 /**
 * Appends the given value to the end of this instance.
 */
 StringBuilder.prototype.append = function(value) {
     if (value) {
         this.strings.push(value);
     }
 }

 /**
 * Clears the string buffer
 */
 StringBuilder.prototype.clear = function() {
     this.strings.length = 1;
 }

 /**
 * Converts this instance to a String.
 */
 StringBuilder.prototype.toString = function() {
     return this.strings.join("");
 } 
//////////////////////////////////////////////////////////////////////////////////////
// Global Variables
//////////////////////////////////////////////////////////////////////////////////////

/**
 * Default Retailer
 */
var AJAX_DEFAULT_RETAILER='LOREAL';
/**
 * Used by the supporting classes to determine if a modal
 * popup is currently visible.
 */
var IS_MODELPOPUP_VISIBLE=false;
/**
 * boolean loadPleasewait as Modal
 */
var CORE_AJAX_LOAD_PLEASEWAIT_ASMODAL=true;
 /**
 * The div or span id of the please wait layer
 */
var CORE_AJAX_PLEASEWAIT_DHTMLOBJECT_ID="coreajax_pleasewait";

/**
 * Style Sheet of paging Numbers
 */
var CORE_AJAX_PAGING_NUMBERS_STYLESHEET="<li>";
/**
 * closing tag of page numbers
 */
var CORE_AJAX_PAGING_NUMBERS_CLOSING_TAG="</li>";
/**
 * Style Sheet of current Page
 */
var CORE_AJAX_CURRENT_PAGE_STYLESHEET = "<li><u>";
/**
 * closing tag of current page
 */
var CORE_AJAX_CURRENT_PAGE_CLOSING_TAG="</u></li>";
/**
 * Prefix
 */
var PAGE_PAGExOFy="&nbsp;-&nbsp;"; //Page
/**
 * Middle
 */
var OFF_PAGExOFy="&nbsp;of&nbsp;"; //of
/**
 * SUFFIX
 */
var DISPLAY_PAGExOFy="&nbsp;displayed.&nbsp;"; //displayed
/**
*Main product Layer
*/
var MAIN_LAYER_PARENT_CONTAINS = 'Category$$Product$$List$$Begin';
/**
 * footer timer for email subscription
 */
 var footer_timer=null;
 /**
 * The path to the popup used if the user need to signin
 */
var POPUPPATHSIGNIN = SSLSiteName + "/_us/_en/members/popup_Favorite_login.aspx";

/**
 * The height to the popup used if the user need to signin
 */
var POPUPSIGNINHIEGHT = "210";

/**
 * The width to the popup used if the user need to signin
 */
var POPUPSIGNINWIDTH = "352";
/**
* This variable will be used to when to show the OOS. If web stock is 3 or less, show OOS icon.
*/
var OOS_THRESHOLD = 5; 

/// Promotion Proximity Constants
var AJAX_SHOPPINGCART_LAYER_PROMO_MESSAGE = "AJAX_SHOPINGCART_LAYER_PROMO_MESSAGE";
var AJAX_SHOPPINGCART_PROMO_MESSAGE = "AJAX_SHOPINGCART_PROMO_MESSAGE";
var AJAX_SHOPPINGCART_PROMO_DISTANCE_TYPES = "BasketPriceEvaluator,CustomerSegmentEvaluator";
var AJAX_SHOPPINGCART_PROMO_DISTANCE_COUNT = 1;
var AJAX_SHOPPINGCART_PROMO_DISTANCE_BECOME_MEMBER_MESSAGE = "sign in for free shipping over $50!";
var AJAX_SHOPPINGCART_PROMO_DISTANCE_I_AM_A_MEMBER_MESSAGE = "You are eligible for Free Shipping!";
 
 
 
/**
 * Initialize any jQuery parameters here 
 */ 
 
 jQuery.ajaxSetup({
            timeout:120000,
            cache: false
            });
 
/**
 * Adding Product to Cart Functionality  
 */
function AddProductToBag(prdCode, varCode, quantity, doRedirect) {               
      DoWait();
      var _doRedirect = false;
      if ( typeof(doRedirect) != undefined )
            _doRedirect = doRedirect;
      jQuery.ajax({   
          type: "POST",   
          url: "/ws/ajax/ShoppingCart.asmx/AddSingleItem",   
          contentType: "application/json; charset=utf-8",   
          data: '{"customerId":"'+ CurrentCustomerID + '","productCode":"' + varCode + '","quantity":"' + quantity + '"}' ,   
          dataType: "json",   
          success: function (result){AddToBagSucceeded(prdCode,varCode,result,_doRedirect)},   
          error: AddToBagFailed   
      });
      
      UpdateCookie(varCode);
}
        
function UpdateCookie(varCode) {
       
      jQuery.ajax({   
          type: "POST",   
          url: "/ws/ajax/ShoppingCart.asmx/UpdateCookie",   
          contentType: "application/json; charset=utf-8",   
          data: '{"cookieName":"COREAJAXSHOPTAGCHECKOUT","cookieValue":"' + varCode + '","append":true,"delimiter":","}' ,   
          dataType: "json",   
          success: null,   
          error: null   
      });    
      
}
function AddToBagSucceeded(prdCode, varCode, result, doRedirect) { 
    if (result.ActivityStatus) {
      
      if ( doRedirect ) {
          document.location.href="/_us/_en/checkout/index_basket_browse.aspx"; 
      } else {
          jQuery.get(
              "/_us/_en/jQueryBubble/shoppingcart_dropdown.aspx?prdcode=" + prdCode + "&varcode=" + varCode,
              null,
              OnShoppigCartDropDownSuccess,
              "html"
            );
      }
  } else {      
      if (result.ErrorString.indexOf('The maximum amount of the shopping cart is reach') != -1) {
          alert('The total amount in your shopping bag exceedes the authorized amount of $500.00. We cannot accept your order online. Please call our customer service representative at (877) 378-4249');
      } else if (result.ErrorString.indexOf('The maximum count for the same shopping cart item was reached') != -1) {
          alert(result.ErrorString);
      } else if (result.ErrorString.indexOf('Product not available') != -1) {
          alert("Unfortunately this product is currently out of stock and not available for purchase.");
      } else {
          alert("We're sorry but this product is currently not available.");
      }
      DoDefault();
    }
             
}   
function AddToBagFailed(result) {
    alert(result.ActivityStatus + ' ' + result.ErrorString);
    DoDefault();
}
function OnShoppigCartDropDownSuccess(result){
    
    // call The proximity webserivce to calculate distance
    //http://www.shuuemura-usa.com/ws/ajax/ShoppingCart.asmx/GetPromotionProximity
    //{"customerId":"d34dbac2-fd36-4641-bf65-733a42259e3c","numberOfDistancesToReturn":1,"evaluatorTypeCodeFilter":"BasketPriceEvaluator,CustomerSegmentEvaluator"}
     
    if (result != null && result != "" ){
        $get("ShoppingBagDropDown").innerHTML = result;
        //$get("ShoppingBagDropDown").style.visibility = "visible";
        jQuery("#ShoppingBagDropDown").slideDown(1000); 
        /*
         jQuery.ajax({   
          type: "POST",   
          url: "/ws/ajax/ShoppingCart.asmx/GetPromotionProximity",   
          contentType: "application/json; charset=utf-8",   
          data: '{"customerId":"' + CurrentCustomerID + '","numberOfDistancesToReturn":' + AJAX_SHOPPINGCART_PROMO_DISTANCE_COUNT + ',"evaluatorTypeCodeFilter":"' + AJAX_SHOPPINGCART_PROMO_DISTANCE_TYPES + '"}' ,   
          dataType: "json",   
          success: DisplayPromotionProximityOnComplete,   
          error: null   
      }); */
      // Set the basket total, promotional count total
        try {
            // move the postion of scroll to top
            jQuery(window).scrollTop(1);
            
            // set baset price
            $get("ShoppingDropDown_BasketTotalDIV").innerHTML = $get("ShoppingDropDown_BasketTotal").innerHTML;
            
            //caculate promotional count
            var productCount = parseInt($get("ShoppingDropDown_ProdCount").innerHTML);
            var totalCountWithPromotionalItems = parseInt($get("ShoppingDropDown_TotalCount").innerHTML);
            // set prmotional item count
            $get("PromotionalItemCount").innerHTML = totalCountWithPromotionalItems - productCount;
            // set total item count in drop down header
            $get("ShoppingDropDown_TotalItemsHeader").innerHTML = totalCountWithPromotionalItems;
            // set the total item count in header
            $get("ShoppingCartBubble_TotalItems").innerHTML = totalCountWithPromotionalItems;

      } 
      catch(e){}
      DoDefault();
    }            
}

function DisplayPromotionProximityOnComplete(result)
{
    var obj=$get('AJAX_SHOPPINGCART_PROMO_MESSAGE');    
     //DoDefaultWithoutEvent();
    // Display the results 
    
    if (result!=null) 
    {
        if ( obj!=null) 
        {
            obj.style.display="";
        }
       if (result[0]!=null && typeof(result[0]!='undefined')) {
             // For now assume we are going to only display the information
            // from the first distance returned.                   
            if (result[0].EvaluatorType == "CustomerSegmentEvaluator")
            {
               if (CustomerSigned==false) {
                obj.innerHTML = AJAX_SHOPPINGCART_PROMO_DISTANCE_BECOME_MEMBER_MESSAGE;
              }
              else {
                  obj.innerHTML  =AJAX_SHOPPINGCART_PROMO_DISTANCE_I_AM_A_MEMBER_MESSAGE;
              }
            }
            else
            {
                obj.innerHTML = result[0].PromotionTextWithComputedDistance;
            }
        }
        else { //assume like there is a promotion and display the messages above, on this case nothing was being returned.            
            if (CustomerSigned==false) {
                obj.innerHTML = AJAX_SHOPPINGCART_PROMO_DISTANCE_BECOME_MEMBER_MESSAGE;
              }
              else {
                  obj.innerHTML  =AJAX_SHOPPINGCART_PROMO_DISTANCE_I_AM_A_MEMBER_MESSAGE;
              }
        }
    } else{
        alert('no results');
    }
    
      
}

/**
* Makeup "bubble" functions
*/

function DisplayMakeupBubbleDetails(prdCode) {   
    DoWait();
     
    jQuery.get(
      "/_us/_en/jQueryBubble/facecare_makeup_products.aspx?prdcode=" + prdCode,
      null,
      OnMakeupBubbleDetailsSuccess,
      "html"
    );
    
}

function OnMakeupBubbleDetailsSuccess(result) {
    if (result != null && result != "") {
        $get("AjaxMakeupBubble").innerHTML = result;        

        DoDefault();
        _CoreModalPopUp._PopupControlID = 'AjaxMakeupBubble';
        _CoreModalPopUp.ShowModal();

        var varlistDropdown = $get("varlistDropdown");
        SelectVariantFromDropdown(varlistDropdown.options[varlistDropdown.selectedIndex].value, varlistDropdown.options[varlistDropdown.selectedIndex].text);        
        
    } 
    else{
        alert('no results');
    }

}

function AddMakeupProductToBag(prdcode) {
    var varlistDropdown = $get("varlistDropdown");
    var qtyDropdown = $get("qtyDropdown");

    var varQty = qtyDropdown.options[qtyDropdown.selectedIndex].value;
    var varStrArr = varlistDropdown.options[varlistDropdown.selectedIndex].value.split('#');
    var varSku = varStrArr[0];

    AddProductToBag(prdcode, varSku, varQty);
}


function AddMutipleProductsToBag(crossSellVarArray, crossSellVarQuantity) {
    DoWait();
    jQuery.ajax({
        type: "POST",
        url: "/ws/ajax/ShoppingCart.asmx/AddMultipleItems",
        contentType: "application/json; charset=utf-8",
        data: '{"customerId":"' + CurrentCustomerID + '","productCodes":' + ConvertArrayToJSONString("string", crossSellVarArray) + ',"quantity":' + ConvertArrayToJSONString(1,crossSellVarQuantity) + '}',
        dataType: "json",
        success: AddMutipleProductsToBagSucceeded,
        error: AddMutipleProductsToBagFailed
    });
}

function AddMutipleProductsToBagSucceeded(result) {
    if (result.ActivityStatus) {
        document.location.href = "/_us/_en/checkout/index_basket_browse.aspx";
    } else {
        var resultObj = jQuery.parseJSON(result.ErrorString);
        alert(resultObj.ErrorMessages[0].PrdParentName + " is out is Stock.");
        DoDefault();
    }
}
function AddMutipleProductsToBagFailed(result) {
    alert(result.ErrorString);
    DoDefault();
}

/**
* Collection Product "bubble" functions
*/

var locationX = 0;

function DisplayCollectionProductBubbleDetails(event, prdCode) {
    if (!event.offsetX)
        locationX = event.layerX - $(event.target).position().left;
    else
        locationX = event.offsetX    
    
    jQuery.get(
      "/_us/_en/jQueryBubble/collection_products.aspx?prdcode=" + prdCode,
      null,
      OnCollectionProductBubbleDetailsSuccess,
      "html"
    );

}

function OnCollectionProductBubbleDetailsSuccess(result) {
    if (result != null && result != "") {        
        $get("AjaxCollectionProductBubble").innerHTML = result;

        $get("AjaxCollectionProductBubble").style.visibility = "visible";
        $get("AjaxCollectionProductBubble").style.display = "";
        $get("AjaxCollectionProductBubble").style.marginLeft = (locationX - 60) + "px";        
    }
    else {
        alert('no results');
    }

}

function DisplayCollectionVariantBubbleDetails(event, varCode) {
    if (!event.offsetX)
        locationX = event.layerX - $(event.target).position().left;
    else
        locationX = event.offsetX

    jQuery.get(
      "/_us/_en/jQueryBubble/collection_variants.aspx?varcode=" + varCode,
      null,
      OnCollectionVariantBubbleDetailsSuccess,
      "html"
    );

}

function OnCollectionVariantBubbleDetailsSuccess(result) {
    if (result != null && result != "") {
        $get("AjaxCollectionProductBubble").innerHTML = result;

        $get("AjaxCollectionProductBubble").style.visibility = "visible";
        $get("AjaxCollectionProductBubble").style.display = "";
        $get("AjaxCollectionProductBubble").style.marginLeft = (locationX - 60) + "px";
    }
    else {
        alert('no results');
    }

}

/**
 * @class CoreModalPopUp creates a modal pop up "bubble"
 */
 Core.ModalPopUp= function () {
    /**
     *  The layer of the whole modal window (object)
     */
    var _backgroundElement=null;

    /**
     * The pop up that will show up (object)
     */
    this._foregroundElement=null;

    /**
     * the Id of the foregroundElement (string)
     */
    this._PopupControlID=null;
    
    /**
     * the name of the function to be called before the popup opens
     */
    this.beforeOpen=null; //null;
    
    /**
     * the name of the function to be called before the popup closes
     */
    this.beforeClose=null;
    
    this._IsforegroundElementLarge=false;
    
   

    /**
     * _Initialize
     */
    this._Initialize=function() {
        if (_backgroundElement==null) {
            _backgroundElement = document.createElement('div');
            _backgroundElement.style.display = 'none'; //none
            _backgroundElement.style.position = 'absolute';
            _backgroundElement.className = 'modalBackground';
            document.body.appendChild(_backgroundElement);
        }
    }

    /**
     *  _InitializeForeground
     */
    this._InitializeForeground=function() {
        this._foregroundElement = $get(this._PopupControlID);
        this._foregroundElement.style.display = 'none';
        this._foregroundElement.style.position = 'absolute';
        //document.body.appendChild(this._foregroundElement);
    }

    /**
      * Show Modal
      */
    this.ShowModal=function () {
        if ((_backgroundElement==null) || (typeof(_backgroundElement)=='undefined') ) {
            this._Initialize()
        }

        if (this._PopupControlID !=null) {
            this._InitializeForeground();
        }
        
        // [AS] - Set the background here.
        var clientWidth = 0;
        var clientHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            clientWidth = window.innerWidth;
            clientHeight = window.innerHeight;
            } 
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight;
        } 
        else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            clientWidth = document.body.clientWidth;
            clientHeight = document.body.clientHeight;
        }

	    if (document.body.scrollHeight)
	    {
		    if (document.body.scrollHeight >= clientHeight)
		    {
			    clientHeight = document.body.scrollHeight;
		    }
		}
		
		_backgroundElement.style.left = '0px';
		_backgroundElement.style.top = '0px';
		_backgroundElement.style.width = clientWidth + 'px';
		_backgroundElement.style.height = clientHeight + 'px';
		_backgroundElement.style.display = 'block';

        // Reset for sizing the foreground element
        clientWidth =630;
        clientHeight=460;
        var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

        if (window.innerWidth) {
            clientWidth = (window.__safari ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
        }
        else {
            clientWidth = document.documentElement.clientWidth;
        }

        if (window.innerHeight) {
            clientHeight = (window.__safari ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
        }
        else {
            clientHeight = document.documentElement.clientHeight;
        }

        //show foreground element
        this._foregroundElement.style.display = 'block'; 
        //position it
        if (this._foregroundElement!=null) {
           this._foregroundElement.style.left = scrollLeft+((clientWidth-this._foregroundElement.offsetWidth)/2)+'px';
            //this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight-60)/2)+'px';
           //alert(this._IsforegroundElementLarge);
           if (this._IsforegroundElementLarge==true) {
           
              this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/4)+'px';
           
           }
           else {
             
             this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/2)+'px';
        
           }
             
                      
        }
        IS_MODELPOPUP_VISIBLE=true;
        if (this.beforeOpen!=null) {
             eval(this.beforeOpen + "();");
        
        }
     }

    /**
     * Hide with event
     */
    this.Hide=function() {
        this.HideModal();
        if (this.beforeClose!=null) {
             eval(this.beforeClose + "();");
        
        }
    }
    /**
     * Hide without event
     */
    this.HideModal=function() {
        if (_backgroundElement!=null) {
            _backgroundElement.style.display = 'none';
        }
        if (this._foregroundElement!=null) {
            this._foregroundElement.style.display = 'none';
        }
        IS_MODELPOPUP_VISIBLE=false;
        this._IsforegroundElementLarge=false;
    }
    

    /**
     * ResizeHandler 
     */
    this.ResizeHandler=function() {
//        [AS] - Disable the resize
//        if (_backgroundElement!=null && _backgroundElement.style.display != 'none' ){
//            this.ShowModal();
//        }
    }

    /** 
     * ScrollHandler    
     */
    this.ScrollHandler=function() {
//        [AS] - Disable the scroll
//        if (_backgroundElement!=null && _backgroundElement.style.display != 'none' ){
//            this.ShowModal();
//        }
    }
}
/*
 * It registers the WebServiceAPI_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.ModalPopUp.registerClass('Core.ModalPopUp'); }

/*
 * It instantiate an object like ModalPopup class that will be used by other js on the ajax pages
 */
var _CoreModalPopUp=new Core.ModalPopUp();



/**
* @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;
    this.ImageAttribute = "actualsrc"; //fn 09/16/2009
    this.ChldImgPrfx = "_img"; //fn 09/16/2009
    this.LoadImages = true; //fn 09/16/2009

    /**
    *  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 15 pages add a break for every 20 pages . 
                // if ((i%15) == 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);

                }
                else {
                    sb.append(this.PageNumberOpeningTag + "<a" + " onclick=\"_NavigatorManager.DoPageByIndex('" + this.ParentID + "'," + i.toString() + ")\" style=\"cursor:pointer\";>" + i.toString() + "</a>" + this.PageNumberClosingTag);
                }
            }

            if (this.TotalPages > 1) {
                if (this.CurrentPage == -1) {
                    //sb.append("<div style=\"width:50px; height:20px; background-color:#7c7c7c\" align=\"center\" class=\"float_R padding05_T A_15GREY_11R\">peter</div>" + "");
                    sb.append("<li><u>View All</u></li>");
                }
                else {
                    //remove view all
                    sb.append("<li><a onclick=\"_NavigatorManager.DoPageByIndex('" + this.ParentID + "',0)\" style=\"cursor:pointer\">View All</a></li>");
                    // sb.append("<div style=\"width:50px; height:20px; cursor:pointer;\" align=\"center\" class=\"float_R padding05_T A_15GREY_11R\" onclick=\"_NavigatorManager.DoPageByIndex('" + this.ParentID + "',0)\" ></div>");
                }
            }

            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();
        }
        //DoMatchingColumnInitialize();
    }

    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 = '';
                    this.LoadImage(this.NavigateArray[i].id); // F.N 09/16/2009
                }
                else {
                    var divid = this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display = 'block';
                    this.LoadImage(divid); //09/16/2009
                }
            }
        }
    }


    /**
    * loads image that has the id like div but with _img as prefix F.N 09/16/2009
    */
    this.LoadImage = function(_prntLayerID) {
        if (this.LoadImages == true) {
            // alert(_prntLayerID);
            var _imgID = _prntLayerID + this.ChldImgPrfx;
            var _obj1 = document.getElementById(_imgID);
            if (_obj1 != null) {
                //alert(obj1.getAttribute('actualsrc'));
                if (_obj1.getAttribute(this.ImageAttribute) != null) {
                    var _src = _obj1.src;
                    var _actualsrc = _obj1.getAttribute(this.ImageAttribute);
                    if (_src != _actualsrc) {
                        _obj1.src = _actualsrc;
                    }
                }
            }
        }
    }

    /**
    * 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];
                this.LoadImage(this.NavigateArray[i].id); //F.N 09/16/2009
            }
        }
        //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 = '';
                    this.LoadImage(this.NavigateArray[i].id); //F.N 09/16/2009
                }
                else {
                    var divid = this.NavigateArray[i];
                    var oDiv = document.getElementById(divid);
                    oDiv.style.display = 'block';
                    this.LoadImage(divid);  //F.N 09/16/2009
                }
            }
        }
    }

    /**
    * 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];
                this.LoadImage(this.NavigateArray[i].id); //F.N 09/16/2009
            }
        }
        //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.LoadImages = true; //F.N 09/16/2009


    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.length > 1) {
                if (currentRecord_Array[1] != "" && currentRecord_Array[1] != lastProductCodeFethched) {
                    lastProductCodeFethched = currentRecord_Array[1];
                    productCodesArray[productCodesArray.length] = currentRecord_Array[1];
                }
            } else {
                lastProductCodeFethched = this.FilteredData[i];
                productCodesArray[productCodesArray.length] = this.FilteredData[i];
            }
            // productCodesArray[productCodesArray.length]=currentRecord_Array[1];
        }
        if (productCodesArray.length > 0) {
            var currentNavigator = this.GetNavigator(ParentLayerContains);
            var _tempNavigatorBeforeInitialization = currentNavigator;
            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) {
                    // for the time bieng do nothing ..TODO
                    //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);
        try {
            // his function is explicitly used for Armani, may not be required for other brands
            HideRows(CurrentNavigator.TotalPages, CurrentNavigator.PageSize);
        }
        catch (e) { };
    }
    /**
    * 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
    * @param {string} ParentID 
    * @param {object} NextObject 
    */
    this.DoNextTwoNavigators = function(ParentID, ParentID2, NextObject, DoSlide) {
        var CurrentNavigator = this.GetNavigator(ParentID);
        CurrentNavigator.NextButtonID = NextObject.id;
        if (DoSlide) {
            CurrentNavigator.DoNextSlide();
        }
        else {
            CurrentNavigator.DoNext();
        }
        // change the current Navigator to new ParentID2
        var CurrentNavigator2 = this.GetNavigator(ParentID2);
        CurrentNavigator2.NextButtonID = NextObject.id;
        if (DoSlide) {
            CurrentNavigator2.DoNextSlide();
        }
        else {
            CurrentNavigator2.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.LoadImages = this.LoadImages; //FN 09/16/2009
                _TempNavigator.DoNext();
                _TempNavigator.LoadImages = true; //FN set it back to true 09/16/2009
                //try{
                // This function is explicitly used for Armani, may not be required for other brands                    
                // HideRows(_TempNavigator.TotalPages,_TempNavigator.PageSize);
                //}
                // catch (e) {};
                this.AddNavigator(_TempNavigator);
            }
        }
    }
}
/**
* It registers the  Core.NavigatorManager using registerClass method of MS AJAX Library
*/
if (IsTypeDefined) { Core.NavigatorManager.registerClass('Core.NavigatorManager'); }

/**
* instantiates Core.NavigatorManager
*/
var _NavigatorManager = new Core.NavigatorManager();


/**
* @class AddtoFavorite
* This class adds the products to user favorite, it also shows the login popup window if user is not signed in
* 
* @constructor 
*/

Core.FavoriteClass = function() {

    this.AddToFavorite = function(isVariant,objectCode){
        if(CustomerSigned == true){
          var productType = 1;
          if ( isVariant )
             productType = 0;               
          jQuery.ajax({   
              type: "POST",   
              url: "/ws/ajax/Favorites.asmx/FavoriteListProductAdd",   
              contentType: "application/json; charset=utf-8",   
              data: '{"customerId":"' + CurrentCustomerID + '","favoriteProductType":' + productType + ',"retailerCode":"' + AJAX_DEFAULT_RETAILER + '","productCode":"' + objectCode + '"}' ,   
              dataType: "json",   
              success: this.AddToFavoriteWSSuccess,   
              error: this.AddToFavoriteWSFailure   
          });    
        }
        else {
            var winl = (screen.width - POPUPSIGNINWIDTH) / 2;
	        var wint = (screen.height - POPUPSIGNINHIEGHT) / 2;
	        var popupPath = POPUPPATHSIGNIN;

	        this.newWindow = open(popupPath + "?objCode=" + objectCode, 'FavoritePopup', ("toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + POPUPSIGNINWIDTH + ",height=" + POPUPSIGNINHIEGHT + "\""));	        
	        this.newWindow.focus();
        }
    }
    
    this.AddToFavoriteWSSuccess = function(result){
        _CoreModalPopUp._PopupControlID = "ProductConfirmFavorite_Bubble";
        _CoreModalPopUp.ShowModal();
    }
    
    this.AddToFavoriteWSFailure = function(result){
        alert(result.ErrorString);
    }

    this.RemoveFromFavorites = function(isVariant, objectCode) {        
        var productType = 1;
        if (isVariant)
            productType = 0;
        jQuery.ajax({
            type: "POST",
            url: "/ws/ajax/Favorites.asmx/FavoriteListProductRemove",
            contentType: "application/json; charset=utf-8",
            data: '{"customerId":"' + CurrentCustomerID + '","favoriteProductType":' + productType + ',"retailerCode":"' + AJAX_DEFAULT_RETAILER + '","productCode":"' + objectCode + '"}',
            dataType: "json",
            success: this.RemoveFromFavoritesWSSuccess,
            error: this.RemoveFromFavoritesWSFailure
        });
    }

    this.RemoveFromFavoritesWSSuccess = function(result) {
        var mf = GetMainFormName();
        document.forms[mf].action = "/_us/_en/members/myaccount/favorites.aspx";
        document.forms[mf].submit();
    }

    this.RemoveFromFavoritesWSFailure = function(result) {
        alert(result.ErrorString);
    }
}
var _FavoriteClass = new Core.FavoriteClass();
//////////////////////////////////////////////////////////////////////////////////////
// Ajax Utility funcitons
//////////////////////////////////////////////////////////////////////////////////////

/**
 * DoWait 
 */
function DoWait() {
        window.status = "";
       document.body.style.cursor='wait';
       TogglePleaseWait('visible',false)
}


/** 
 * DoDefault 
 */
function DoDefault() {
     document.body.style.cursor='default';
     TogglePleaseWait('hidden',false)
}

function DoDefaultWithoutEvent() {
     document.body.style.cursor='default';
     TogglePleaseWait('hidden',true)
}

function TogglePleaseWait(_Visibility, RaiseEvent) {
    var _pleaseWaitObject=$get(CORE_AJAX_PLEASEWAIT_DHTMLOBJECT_ID);
    if (_pleaseWaitObject!=null) {
        if (IS_MODELPOPUP_VISIBLE)
        {
            _CoreModalPopUp.Hide();
        }
        
        _pleaseWaitObject.style.visibility=_Visibility;
        if(CORE_AJAX_LOAD_PLEASEWAIT_ASMODAL) {
            _CoreModalPopUp._PopupControlID=CORE_AJAX_PLEASEWAIT_DHTMLOBJECT_ID;
            if (_Visibility=='visible') {
                _CoreModalPopUp.ShowModal();
            }
            else {
                if (RaiseEvent) {
                _CoreModalPopUp.HideModal();
            }
        else {
            _CoreModalPopUp.Hide();
        }
    }
}

    }
}

/**
 * IsAjaxLibraryLoaded is a boolean indicating wether the AJAX JavaScript
 * libraries have been loaded
 */
var IsAjaxLibraryLoaded=false;

/**
 * Fires when Atlas is loaded
 */
function AjaxOnload() {
       IsAjaxLibraryLoaded=true;
}

/** 
 * Determines if ATLAS has been loaded
 */
function IsAjaxLoaded() {
   return IsAjaxLibraryLoaded;
}


function ConvertArrayToJSONString(valType, array) {
    var JSONStr = "[";

    for (i = 0; i < array.length; i++) {
        if (typeof (valType) == "string")
            JSONStr += "\"" + array[i] + "\",";
        else
            JSONStr += array[i] + ",";
    }
    return JSONStr.substring(0, JSONStr.length - 1) + "]"; 
}

////////////////////////////////////////////////////////////////////////////
// Shopping Drop Down Proximity function
///////////////////////////////////////////////////////////////////////////


