var AJAX_SHOPPINGCART_POWER_SYSTEM="AJAX_SHOPPINGCART_POWER_SYSTEM";
var AJAX_SHOPPINGCART_POWER_SYSTEM_PRODUCTS="AJAX_SHOPPINGCART_POWER_SYSTEM_PRODUCTS";

/// Promotion Proximity Constants
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 = "Please register to receive free shipping!";
var AJAX_SHOPPINGCART_PROMO_DISTANCE_I_AM_A_MEMBER_MESSAGE = "You are eligible for Free Shipping!";
// Other constants
var AJAX_DEFAULT_RTLCODE="LOREAL";
var POWER_SYSTEM_ASSOCIATION_NAME='PowerSystem'
//
var AJAX_varlist="varlist";
var AJAX_QtyList="QtyList";

//
//var AJAX_BODYSHOP_VARIANT_FILTER_EXPRESSION_1="Isnull(isbeautybyebye,'Null Column') = 'Null Column'  or isbeautybyebye<>'2'";
var AJAX_BODYSHOP_VARIANT_FILTER_EXPRESSION_1="";

var DISCONT_VIEWDETAILS_PROD_TEMPLATE='<a href="$$$AJAX_ProductRelativePath$$$product.aspx?CatCode=$$$AJAX_ProductCategoryCode$$$&prdcode=$$$AJAX_ParentProductCode$$$" class="Ablack10pxRL"><img alt="More Details" src="/images/spacer.gif" width="10" height="17"> </a>';
var DISCONT_VIEWDETAILS_PROD_TEMPLATE_URL_REWRITTEN='<a href="$$$AJAX_ProductRelativePath$$$$$$AJAX_ProductURLRewrittenHomePage$$$?cm_mmc=QuickShopLink" class="Ablack10pxRL"><img alt="More Details" src="/images/spacer.gif" width="10" height="17"></a>';



//assign  modal popup custom events
_CoreModalPopUp.beforeOpen="modalBeforeOpen"; 
_CoreModalPopUp.beforeClose="modalBeforeClose";
//

//
function modalBeforeOpen() {
  if (AJAX_IsIE6()) {
       ToggleDropDowns('hidden')
       ToggleProductDetailVarQTYList('hidden');
       ToggleJustForYou('hidden');
       ToggleColorExplorerCategory('hidden');
        ToggleDiscontinuedDropDowns('hidden')
  }

}

//
function modalBeforeClose() {
    if (AJAX_IsIE6()) {
      ToggleDropDowns('visible')
      ToggleProductDetailVarQTYList('visible');
      ToggleJustForYou('visible');
      ToggleColorExplorerCategory('visible');
       ToggleDiscontinuedDropDowns('visible')
    }
}

function ToggleDiscontinuedDropDowns(_visibility) {

  //discontinue_layer_dropdown_container
    if (AJAX_IsIE6()) {
      try {
         var obj=$get('discontinue_layer_dropdown_container');
            if (obj!=null) {
              obj.style.visibility=_visibility;
              
            }
            var obj2=$get('discontinue_sort_containerid')
             if (obj2!=null) {
              obj2.style.visibility=_visibility;
              
            }
           if (oldDivID!=null) {
              if (_visibility=='hidden') {
                hideOldDiv(oldDivID);
                
              }
              else {
               showHideSearchDDL(oldDivID);
              }
           }
           
      }
      catch(err) { } 
    }

}
function ToggleProductDetailVarQTYList(_visibility) {
    if (AJAX_IsIE6()) {
      try {
         //variant list
           var obj=$get(AJAX_varlist);
            if (obj!=null) {
              obj.style.visibility=_visibility;
            }
            //quantity
            var mf = GetMainFormName();
	        if (mf==null) return;
            var x =  GetElementID(AJAX_QtyList,mf);
            var obj2=$get( x);
            if (obj2!=null) {
              obj2.style.visibility=_visibility;
            }
        }
       catch(err) { }
    }
}


function ToggleStateList(_visibility) {
    if (AJAX_IsIE6()) {
      try {
         //state list
           var obj=$get("state");
            if (obj!=null) {
              obj.style.visibility=_visibility;
              //alert("vis " + _visibility);
            }
        }
       catch(err) { }
    }
}

function ToggleDropDowns(_visibility) {
      // to make a drop down to hide automatically, please ad the style.visibility
      // please DO NOT DO it for bubbles, only for defaulted drop down on a particula page.
       if (AJAX_IsIE6()) {
             //Drpw downs with style visibility
               GetAllSelects();
               for (var i=0; i < allVisibleSelects.length; i++) {
                 allVisibleSelects[i].style.visibility=_visibility;
              }
              //SHOPPING CART SUMMARY PAGE
               try {
              var obj2=$get('SHOPPINGCART_LAYER_CONTAINER');
             if (obj2!=null) {
                   var  allSelects = obj2.getElementsByTagName("select");
                    for (var i=0; i < allSelects.length; i++) {
                        allSelects[i].style.visibility=_visibility; 
                    }
             }
           }   
           catch(err) {}
       
             
       }
}


function ToggleColorExplorerCategory(_visibility) {
      if (AJAX_IsIE6()) {
        try {
            //SELECTED SHADE AREA ON COLOR EXPLORER
             var obj1=$get('row_filter_category_selected');
             if (obj1!=null) {
                   if (_visibility=='visible') {
                        obj1.style.display="";
                   }
                   else  {
                      obj1.style.display="none";
                   }
             }
           }   
           catch(err) {}
        }
           
}


function ToggleJustForYou(_visibility) {
      if (AJAX_IsIE6()) {
        try {
             var obj1=$get('justforyou');
             if (obj1!=null) {
                   var  allSelects = obj1.getElementsByTagName("select");
                    for (var i=0; i < allSelects.length; i++) {
                        allSelects[i].style.visibility=_visibility; 
                    }
             }
           }   
           catch(err) {}
           
           //MYBODYSHOP_JustForYou
             try {
              var obj2=$get('MYBODYSHOP_JustForYou');
             if (obj2!=null) {
                   var  allSelects = obj2.getElementsByTagName("select");
                    for (var i=0; i < allSelects.length; i++) {
                        allSelects[i].style.visibility=_visibility; 
                    }
             }
           }   
           catch(err) {}
           
           //category select on my beauty profile
             try {
            var obj3=$get('Category');
            if (obj3!=null) {
               obj3.style.visibility=_visibility; 
            }
        }
        catch(err) { }
           
        }
        
      

}


var allVisibleSelects=new Array();

function GetAllSelects() {
    var index=0;
     if (allVisibleSelects==null || allVisibleSelects.length==0) {
        var  allSelects = document.getElementsByTagName("select");
       
        for (var i=0; i < allSelects.length; i++) {
                 // alert(allSelects[i].style.visibility);
                 if (allSelects[i].style.visibility=='visible') {
                        allVisibleSelects[index]=allSelects[i];
                        index++;
                }
          }
    }
}




//assign shopping cart events
_ShoppingCartBubble_Class.beforeOpen="ShoppingCartBeforeOpen"; 
_ShoppingCartBubble_Class.beforeClose="ShoppingCartBeforeClose";

function ShoppingCartBeforeOpen() {
 
  // step 1
  try {
    GetPowerSystem();
    }
    catch(err) {
  
    }
  //step 2
   try {
    GetPromotionProximity();  
    }
    catch(err) {
     DoDefault();
   }
    ToggleDropDowns('hidden')
    

  
}

//
function ShoppingCartBeforeClose() {
    ToggleDropDowns('visible')
}

/*
function ToggleExplorerArea(_display) { 
    if (AJAX_IsIE6()) {
       var objectTemp=$get('explorecheck');
       if (objectTemp!=null) {
           objectTemp.style.display=_display;
       }
    }
}
*/

function AJAX_IsIE6() {
  if (navigator.appName=='Microsoft Internet Explorer') {
      if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
         return true;
      }
  }
  return false;

}

function GetAJAXTopicCodes() {
   var CommaDelimitedList=""
   var parentObj=$get("AJAX_Topic_Filter");
   var allSelects=parentObj.getElementsByTagName("select");
   for (var i=0; i < allSelects.length; i++) {
          var selectedValue="";
          selectedValue=allSelects[i].options[allSelects[i].selectedIndex].value;
          if (selectedValue!='#' && selectedValue!='##') {
                  if (CommaDelimitedList=="") {
                     CommaDelimitedList=selectedValue;
                  }
                  else {
                    CommaDelimitedList=CommaDelimitedList + "," + selectedValue;
                  }
           }

     }
     SetClearButtonState(CommaDelimitedList);
  return CommaDelimitedList;
}

function SetClearButtonState(_codes) {
var obj=$get('ajax_filterbutton');
if (obj!=null) {
     if (_codes=="") {
        obj.style.display="none";
        //
     }
     else {
       obj.style.display="";
     }
 }

}

function ResetFilterDropDowns() {
   var parentObj=$get("AJAX_Topic_Filter");
   var allSelects=parentObj.getElementsByTagName("select");
    for (var i=0; i < allSelects.length; i++) {
           for (var j=0; j< allSelects[i].options.length; j++) {
              var str = allSelects[i].options[j].value;
              if (str=="#") { 
                   allSelects[i].options.selectedIndex=j;
                   break;
               }
           }
     }

}

function ResetCheckOutFilter() {
   var objectTemp=$get('select_whatisnew');
   for (var i=0; i< objectTemp.options.length; i++) {
              var str = objectTemp.options[i].value;
              if (str=="#") { 
                   objectTemp.options.selectedIndex=i;
                   break;
               }
     }

}
function ResetFilters() {
  ResetFilterDropDowns();
  //ResetCheckOutFilter();

}

function GetPromotionProximity()
{
     
      var obj=$get(AJAX_SHOPPINGCART_PROMO_MESSAGE);
      if (obj!=null)
      {
        obj.style.display="none";
      }
      _WebServiceAPI.GetPromotionProximity(CurrentCustomerID, AJAX_SHOPPINGCART_PROMO_DISTANCE_COUNT, AJAX_SHOPPINGCART_PROMO_DISTANCE_TYPES, null, 'DisplayPromotionProximityOnComplete');
}

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;
              }
        }
    }
      if (AJAX_IsIE6()) {
         ToggleDropDowns('hidden');
         ToggleProductDetailVarQTYList('visible');
         ToggleJustForYou('visible');
         ToggleColorExplorerCategory('visible');
     }



}

function GetPowerSystem(){
     var obj=$get(AJAX_SHOPPINGCART_POWER_SYSTEM);
      if ( obj!=null) {
        obj.style.display="none";
      }
      var obj2=$get('AJAX_COMPLETE_MESSAGE');
      if ( obj2!=null) {
        obj2.style.display="none";
      }
      
     _WebServiceAPI.GetProductAssociations(AJAX_DEFAULT_RTLCODE,_LastShoppingCartItem.ItemCode,POWER_SYSTEM_ASSOCIATION_NAME,false,'DisplayPowerSystemOnComplete');
}


function DisplayPowerSystemOnComplete(result){
        DoDefaultWithoutEvent();
        var obj=$get(AJAX_SHOPPINGCART_POWER_SYSTEM);
         var obj2=$get('AJAX_COMPLETE_MESSAGE');
         //
        
         if (result!=null) {
            if ( obj!=null) {
                obj.style.display="block";
            }
             if ( obj2!=null) {
                obj2.style.display="block";
            }
           var sb = new StringBuilder();
           var sbprdnames= new StringBuilder();
           sb.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
           sb.append("<tr>");
           sbprdnames.append("<tr>");
            for (var i=0; i < result.length; i++)  {
                var IsVariant=true;
                var HasShades=false;
                if (result[i].ParentName=="") {
                 IsVariant=false;
                }
                if (result[i].HasShades) {
                 HasShades=true;
                }
              
                // alert(IsVariant);
                if (IsVariant==true) { //related product is a variant
                 //sb.append("<td><div align=\"center\"><img src=\"/images/product/swatch/" + result[i].SKU + ".gif\" width=\"30\" height=\"30\"  onmouseover=\"javascript:_QuickShop_Class.ShowByObjectPosition(this,'" + result[i].SKU +"',true,5,5);\"/></div></td>");
                    if (HasShades) {
                             sb.append("<td><div align=\"center\"><img src=\"/images/product/packshot/" + result[i].ParentProductCode + "_s.jpg\" width=\"30\" height=\"30\"  onmouseover=\"javascript:_QuickShop_Class.ShowByObjectPosition(this,'" + result[i].SKU  +"',true,5,5,true);\"/></div></td>");
                    }
                    else {
                             sb.append("<td><div align=\"center\"><img src=\"/images/product/packshot/" + result[i].ParentProductCode + "_s.jpg\" width=\"30\" height=\"30\"  onmouseover=\"javascript:_QuickShop_Class.ShowByObjectPosition(this,'" + result[i].ParentProductCode  +"',false,5,5,false);\"/></div></td>");
                  
                    }
                }
                else { //is a parent product
                      if (HasShades) {
                             sb.append("<td><div align=\"center\"><img src=\"/images/product/packshot/" + result[i].SKU + "_s.jpg\" width=\"30\" height=\"30\"  onmouseover=\"javascript:_QuickShop_Class.ShowByObjectPosition(this,'" + result[i].SKU +"',true,5,5,false);\"/></div></td>");
                     }
                     else {
                             sb.append("<td><div align=\"center\"><img src=\"/images/product/packshot/" + result[i].SKU + "_s.jpg\" width=\"30\" height=\"30\"  onmouseover=\"javascript:_QuickShop_Class.ShowByObjectPosition(this,'" + result[i].SKU +"',false,5,5,false);\"/></div></td>");
                    
                     }
                }
                if (IsVariant==true) {
                   sbprdnames.append("<td class=\"Amedgrey09pxR\"><div align=\"center\">" +result[i].ParentName + "<br>" + result[i].Name + "</div></td>");
                }
                else {
                   sbprdnames.append("<td class=\"Amedgrey09pxR\"><div align=\"center\">" + result[i].Name + "</div></td>");
                }
                if(result.length>1) {
                 if (i<parseInt(result.length)-1) { //separator
                      //sb.append("<td><img src=\"/images/plus_sm_ICN.gif\" width=\"12\" height=\"12\" /></td>");
                      sb.append("<td></td>"); //Remove '+' sign.
                      sbprdnames.append("<td class=\"Amedgrey09pxR\"><div align=\"center\"></div></td>");
            
                  }
                }
             }
             
            sb.append("</tr>");  
            sb.append(sbprdnames.toString());
            sb.append("</table>");  
            
         var objpowersystem=$get(AJAX_SHOPPINGCART_POWER_SYSTEM_PRODUCTS);
         if (objpowersystem!=null) {
            
             objpowersystem.innerHTML= sb.toString();
        }
      }
          if (AJAX_IsIE6()) {
                ToggleDropDowns('hidden');
                ToggleProductDetailVarQTYList('visible');
                ToggleJustForYou('visible');
                ToggleColorExplorerCategory('visible');
        }
}


// Check Out Filter
 function DoPerformCheckoutFilter(_obj,_catgCode,_level) {
            
            var index=_obj.selectedIndex;
            var selvalue=_obj.options[index].value;
            if (selvalue!="#") {
               GetCategoryProductsCodesByCategory(_catgCode,selvalue,(_level==1) ? true:false,(_level==1) ? CategoryProductsCodesOnComplete:CategoryParentProductsCodesOnComplete );
            }

}

//This function handles a call to web service for category filtering based on exteneded properties
function GetCategoryProductsCodesByCategory(CategoryCode,FilterCriteria,variantsWanted,OnCompleteFuncName)  {
        //clear filter
        _NavigatorManager.ClearFilter(); 
        //call web service
        _WebServiceAPI.GetCategoryProductsCodes(CategoryCode,FilterCriteria,variantsWanted,OnCompleteFuncName);
 
 }

//This function handles a call to web service for category filtering based on exteneded properties
function GetCategoryProductsCodesByOnlineStatus(CategoryCode)  {
        //call web service
        _WebServiceAPI.GetCategoryProductsCodesByOnlineStatus(CategoryCode,-1,CategoryParentProductsCodesOnComplete);
 }
 
 //this function is a call back func after the web service is done with dataretrieval and 
 //logic is passed in this one   
function CategoryProductsCodesOnComplete (result)  {

        DoDefault();
         if (result!=null) {
            //clear filter
            _NavigatorManager.ClearFilter(); 
            _NavigatorManager.FilteredData=result;
            _NavigatorManager.DoFilterInitialization(VARIANT_LAYER_PARENT_CONTAINS);
         }
         else {  alert ("No Results for this Filter."); }
    }


function CategoryParentProductsCodesOnComplete (result)  {
         DoDefault();
         
         if (result!=null) {
                if (AJAX_IS_TOPIC_PRODUCT_SLIDER_ON) {
                     var constructedData=_TopicManager.GetConstruct(result);
                     if (constructedData==null || constructedData.length==0) {
                        alert ("No Results for this Filter.");
                     }
                     else {

                        CategoryProductsCodesOnComplete(constructedData);
             
                    }
                }
                else {
                     _NavigatorManager.FilteredData=result;
                     _NavigatorManager.DoMainFilterInitialization(MAIN_LAYER_PARENT_CONTAINS); 
                }
         }
         else { 
              alert ("No Results for this Filter.");
         }
   
   }      
//
function _TODO_replaceAll(str, replacements ) {
    for ( i = 0; i < replacements.length; i++ ) {
        var idx = str.indexOf( replacements[i][0] );

        while ( idx > -1 ) {
            str = str.replace( replacements[i][0], replacements[i][1] ); 
            idx = str.indexOf( replacements[i][0] );
        }

    }

    return str;
}


Core.Discontinued_Class=function (){
    /**
     * The HTML ID of the layer (div) for the discontinued shop class
     */
    this.Discontinued_DivID='DiscontinuedLook';
    
    /**
     * When the Discontinued shop bubble is shown, the user can click on that image.
     * This method is called when the user clicks on the image.
     * The method determines if it is a Variant or Product. Based on the requests, we
     * may need to do few more cases on this method.
     */
    this.ShowBubble=function(Code,IsVariant,hasShades) {
        this.Code=Code;
        this.hasShades=hasShades;
        this.IsVariant = IsVariant;
        if (this.IsVariant) {
            _DiscontinuedProductManager.LoadMakeupVariant(this.Code);
        }else {
            if(this.hasShades) {
                _DiscontinuedProductManager.LoadMakeupProduct(this.Code);
            }else{
                _DiscontinuedProductManager.LoadSkinCareProduct(this.Code);
            }
        }
    }
    this.ShowSearchBubble=function() {
        _DiscontinuedBubble_Class.LoadProductSearch();
    }
}
 /**
 * Inherit from the ProductManager_Class
 */
Core.Discontinued_Class.prototype = new Core.QuickShop_Class;

/*
 * It registers the Discontinued_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.Discontinued_Class.registerClass('Core.Discontinued_Class'); }
 /**
 * It instantiates an object of type Core.Discontinued_Class
 */
var _Discontinued_Class=new Core.Discontinued_Class();

/**
 * @class DiscontinuedProductManager_Class
 * This class Manages both Products and Variants
 * It adds a product/variant in the collection,
 * loads the data from webservice and caches the data locally
 * if caching is enabled for both Products and Variants
 * @constructor 
 */

 Core.DiscontinuedProductManager_Class=function() {
    /**
     * The holds the association code for the product
     */    
    var ProductAssociation = "DISCONT_PRD_ASSC";
    /**
     * The holds the association code for the Variant
     */
    var VariantAssociation = "DISCONT_PRD_ASSC_VAR";
    /**
     * The collection of the association products to be cached (visited previously by the user)
     */    
    this.CurrentCode = "";
    /**
     * The collection of the association products to be cached (visited previously by the user)
     */
    this.AssociationCollection=new Array();
    /**
     * Adds a product association to the internal product collection
     * @param {object} ProductObject The product object
     */
    this.AddAssociation= function (ProductObject) {
        var exist=false;
        if (this.AssociationCollection!=null) {
            for (var i=0; i<this.AssociationCollection.length; i++) {
                if (this.AssociationCollection[i].ProductCode==ProductObject.ProductCode) {
                    this.AssociationCollection[i]=ProductObject;
                    exist=true;
                    break;
                }
            }

            if(exist==false) {
                this.AssociationCollection[this.AssociationCollection.length]=ProductObject;
            }
        }
    }

    /**
     * Retrieve a product association to the internal product collection
     * @param {string} ProductCode The product code of the product to retrieve from the ProductCollection
     */
    this.GetAssociation=function (ProductCode) {
        for (var i=0;i<this.AssociationCollection.length;i++) {
            if (this.AssociationCollection[i].ProductCode==ProductCode) {
                  return this.AssociationCollection[i];
            }
        }
    }
    /**
     * This method below checks if a copy exist on the Memory, if it does, no need to call web service
     * @param {string} ProductCode The product code of the product to retrieve
     */
    this.LoadProduct=function (ProductCode) {
        DoWait();
        if (ProductCode != ''){
            _DiscontinuedBubble_Class.LockCoordinates();
            _DiscontinuedBubble_Class.HideShades();
             this.CurrentCode = ProductCode;
                
             var _Product=new Core.Product_Class();
             _Product.ProductCode=ProductCode;
             this.AddProduct(_Product);
            _WebServiceAPI.LoadDiscontinuedProduct(AJAX_DEFAULT_RTLCODE, ProductCode, true, true, this.OnRequestComplete);
        }else{
            DoDefault();
        }
    }
    /**
     * Loads a shade in a bubble
     * @param {string} VariantCode Loads the variant for display
     */
    this.LoadMakeupVariant=function(VariantCode) {
        this.Action=0;
        _DiscontinuedProductManager.LoadProduct(VariantCode);
    }
    /**
     * This method is called after a web Service Call is Completed
     * @param {string} result The result object returned from the web service
     */
    this.OnRequestComplete= function (result) {
        if (result != null)    {
            var _Product=_DiscontinuedProductManager.GetProduct(result.SKU);//later use the productid
            _Product.Result=result;
            _Product.Loaded=true;
            _DiscontinuedProductManager.AddProduct(_Product);  
            if (_Discontinued_Class.IsVariant) {        
                _WebServiceAPI.GetProductAssociationsIgnoreFlags(AJAX_DEFAULT_RTLCODE,_Product.ProductCode,VariantAssociation,false,true,_DiscontinuedProductManager.AssociationOnRequestComplete);
            }else{
                _WebServiceAPI.GetProductAssociationsIgnoreFlags(AJAX_DEFAULT_RTLCODE,_Product.ProductCode,ProductAssociation,true,true,_DiscontinuedProductManager.AssociationOnRequestComplete);
            }
        }
    }
    
    /**
     * This method is called after a web Service Call is Completed
     * @param {string} result The result object returned from the web service
     */
    this.AssociationOnRequestComplete= function (result) {
        if (result != null){
            result = result[0];
            var _AssocProduct=new Core.Product_Class();
            _AssocProduct.ProductCode = result.SKU;
            _AssocProduct.Result=result;
            _AssocProduct.Loaded=true;
            var _Prod = _DiscontinuedProductManager.GetProduct(_DiscontinuedProductManager.CurrentCode);
            _DiscontinuedProductManager.DoBranching(_Prod, _AssocProduct);
        }else{
            var _Prod = _DiscontinuedProductManager.GetProduct(_DiscontinuedProductManager.CurrentCode);
            _DiscontinuedProductManager.DoBranchingNoAssociation(_Prod);
        }
    }
    /**
     * TODO
     * @param {ProductBubble_Class} _Product The product bubble
     */
    this.DoBranching=function(_Product, _AssocProduct) {
        _DiscontinuedBubble_Class.IsMakeupProduct=true;
        switch(this.Action){
            case 0 :
                _DiscontinuedBubble_Class.IsMakeupProduct=true;
                _DiscontinuedBubble_Class.Code=_Product.ProductCode;
                _DiscontinuedBubble_Class.AssocCode = _AssocProduct.ProductCode;
                _DiscontinuedBubble_Class.LoadVariantRequestComplete(_Product.Result,_AssocProduct.Result); 
                break;              
            case 1 :
                _DiscontinuedBubble_Class.IsMakeupProduct=false;
                _DiscontinuedBubble_Class.Code=_Product.ProductCode;
                _DiscontinuedBubble_Class.AssocCode = _AssocProduct.ProductCode;
                _DiscontinuedBubble_Class.LoadProductRequestComplete(_Product.Result,_AssocProduct.Result);
                break;
            case 2 :
                _DiscontinuedBubble_Class.IsMakeupProduct=true;
                _DiscontinuedBubble_Class.Code=_Product.ProductCode;
                _DiscontinuedBubble_Class.AssocCode = _AssocProduct.ProductCode;
                _DiscontinuedBubble_Class.LoadProductRequestComplete(_Product.Result,_AssocProduct.Result);
                break;
            default :
                break;
        }
    }
   /**
     * TODO
     * @param {ProductBubble_Class} _Product The product bubble
     */
    this.DoBranchingNoAssociation=function(_Product) {
        if (_Product != null){
            _DiscontinuedBubble_Class.IsMakeupProduct=true;
            switch(this.Action){
                case 0 :
                    _DiscontinuedBubble_Class.IsMakeupProduct=true;
                    _DiscontinuedBubble_Class.LoadVariantRequestComplete(_Product.Result,null);
                    break;
                case 1:
                    _DiscontinuedBubble_Class.IsMakeupProduct=false;
                    _DiscontinuedBubble_Class.LoadProductRequestComplete(_Product.Result,null);
                    break;
                case 2:
                    _DiscontinuedBubble_Class.IsMakeupProduct=true;
                    _DiscontinuedBubble_Class.LoadProductRequestComplete(_Product.Result,null);
                    break;
                default:
                    break;
            }
        }
    }
    // Variant methods:
    /**
     * Retrieves the variant either from the web service or cache (if enabled) 
     * @param {string} VariantCode The variant code to find
     */
    this.LoadVariant=function (VariantCode) {
        if (VariantCode!=''){
                var _Variant= new Core.Product_Class();
                _Variant.ProductCode = VariantCode;
                _DiscontinuedProductManager.AddVariant(_Variant);
                _WebServiceAPI.LoadDiscontinuedProduct(AJAX_DEFAULT_RTLCODE, VariantCode, true, false, _DiscontinuedProductManager.VariantOnRequestComplete);
        }
    }
        /**
     * This method is called after a web Service Call is Completed
     * @param {string} result The result object returned from the web service
     */
    this.VariantOnRequestComplete= function (result) {
        if (result != null)    {  
            _WebServiceAPI.GetDiscontinuedProductAssociationsIgnoreFlags(AJAX_DEFAULT_RTLCODE,result.SKU,VariantAssociation,false,true,_DiscontinuedProductManager.AssociationVariantOnRequestComplete);
        }
    }
    
    this.AssociationVariantOnRequestComplete=function(result){
        if(result != null){
            var _Variant= new Core.Product_Class();
            _Variant.ProductCode = result[0].SKU;
            _Variant.Result = result[0];          
            _DiscontinuedBubble_Class.SetSelectedShade(_Variant.Result);
        }else{
            _DiscontinuedBubble_Class.SetSelectedShade(null);
        }
    } 
}
 /**
 * Inherit from the ProductManager_Class
 */
Core.DiscontinuedProductManager_Class.prototype = new Core.ProductManager_Class;

 /**
 * It registers the  DiscontinuedProductManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.DiscontinuedProductManager_Class.registerClass('Core.DiscontinuedProductManager_Class'); }

 /**
 * It instantiates an object of type Core.DiscontinuedProductManager_Class
 */
var _DiscontinuedProductManager=new Core.DiscontinuedProductManager_Class();

/**
 * @class DiscontinuedBubble_Class
 * This class is responsible into managing the Product Bubble Class
 * Please be aware that the properties of this class needs to be overridden based on the case that we will be using.
 * The one which needs to be changed are
 *        this.VariantBubble_ImagePrefix   and    this.VariantBubble_ImageSuffix;
 * The other properties are DHTML Object IDs that needs to be populated with the data.....
 * In case there are other data that needs to be populated, we either need to support on this class or we need to prototype
 * its methods.
 *  this.RowSize=8 is a very important property, it manages how many variants will be shown in one row if
 * the product is a makeup product. It customizes building of shade table.
 */

Core.DiscontinuedBubble_Class=function() {
    /**
     * The DHTML ID of the main layer of the Product bubble
     */
    this.Bubble_DivID="Discontinued_ProductBubble_Div";
    /**
     * The DHTML ID of the Product Image object
     */
    this.Bubble_ImageID="Discontinued_ProductBubble_Image";
        /**
     * The DHTML ID of the Product Image object
     */
    this.Bubble_ImageID2="Discontinued_ProductBubble2_Image";
    
    /**
     * The DHTML ID of the Associated Product Image object
     */
    this.Bubble_AssociatedImageID="Discontinued_AssociatedProductBubble_Image";
    /**
     * The DHTML ID of the Quantity object
     */
    this.Bubble_QuantityID="Discontinued_ProductBubble_Quantity";
    /**
     * The DHTML ID   of the Product price label
     */
    this.Bubble_PriceID="Discontinued_ProductBubble_Price";
    /**
     * The DHTML ID   of the Product Name label
     */
    this.Bubble_ProductNameID="Discontinued_ProductBubble_ProductName";
    
    this.Bubble_ProductNameID2="Discontinued_ProductBubble2_ProductName";
    /**
     * The DHTML ID of the Associated Product Name
     */ 
     this.Bubble_AssocProductNameID="Discontinued_ProductBubble_AssociatedProductName";
    /**
     * The DHTML ID   of the Product description label
     */
    this.Bubble_ProductDescriptionID="Discontinued_ProductBubble_ProductDescription";
    /**
     * The DHTML ID   of the Add to bag object
     */
    this.Bubble_AddToBagID="Discontinued_ProductBubble_AddToBag"; //not used yet on js code
     this.Bubble_OutOfStockID="Discontinued_ProductBubble_OutOfStock"
    /**
     * Product Code
     */
    this.Code="";
    
    /**
     * Associated Product Code
     */
    this.AssocCode="";
    /**
     *  The DHTML ID   of the drop down layer that lists all variants
     */
    this.Bubble_LayerDropDownListID="Discontinued_ProductBubble_VariantDropDownList";
    /**
     * The DHTML ID   of the drop down that lists all variants
     */
    this.Bubble_DropDownListID="DropDown_" + this.Bubble_LayerDropDownListID;
    /**
     * The DHTML ID   of small shades layer
     */
    this.ProductBubble_Small_ShadesID="Discontinued_ProductBubble_Small_Shades"
      /**
     * The DHTML ID of the Recommended Shade
     */
    this.ProductBubble_RecommendedShadeID = "Discontinued_ProductBubble_Recommended_Shade";
      /**
     * The DHTML ID of the Recommended Shade Image
     */
    this.ProductBubble_RecommendedShadeImgID = "Discontinued_ProductBubble_Recommended_ShadeImg";
      /**
     * The DHTML ID of the Recommended Shade Image
     */
    this.ProductBubble_RecommendedProdNameID = "Discontinued_ProductBubble_Recommended_ProdName";
          /**
     * The DHTML ID of the Recommended Container
     */
    this.ProductBubble_RecommendedContinerID = "RecommendedContainer";
    this.ProductBubble_RecommendedContinerID1 = "RecommendedContainer1";
    this.ProductBubble_RecommendedContinerID2 = "RecommendedContainer2";
     /**
     * The DHTML ID   of the variants thumbnail table
     */
    this.Variants_Main_All_Thumbnails='Ajax_Main_Bubble_All_Thumbnail_Shades';
    /**
     * The DHTML ID   of all variants
     */
    this.Variants_ThumbnailDivID='Ajax_allShades_layer';
    /**
     * The DHTML ID   search bubble
     */    
    this.DiscontinuedSearch_DivID='Discontinued_SearchBubble_Div';
    
    /**
     * The DHTML ID product drop down search bubble
     */    
    this.Discontinued_ProductsDropDownID="Discontinued_ProductsDropDown";
    /**
     * The DHTML ID variant drop down search bubble
     */    
    this.Discontinued_VariantsDropDownID="Discontinued_VariantsDropDown";
    /**
     * The DHTML ID  Shade select
     */    
    this.Discontinued_ShadeSelectID="Discontinued_ShadeSelect";    
    /**
     * The DHTML ID  Search Button
     */    
    this.Discontinued_Search_ButtonID="Discontinued_Search_Button";
   /**
     * The DHTML ID  Search Button
     */    
    this.Discontinued_CategoryDropDownID="Discontinued_CategoryDropDown";    
    
    this.VIEWMOREDETAILS_ID="Discontinued_PRODUCT_BUBBLE_VIEWMOREDETAILS";
    this.VIEWMOREDETAILS_INNERHTML_TEMPLATE="";
    this.SelectShadeLabel="Discontinued_ProductBubble_SelectShadeLabel";
    this.DropDownShadeLabel="Discontinued_ProductBubble_DropDownShadeLabel";
    this.DropDownSizeLabel="Discontinued_ProductBubble_DropDownSizeLabel";
    this.Discontinued_ProductBubble_FoundID="Discontinued_ProductBubble_Found";
    this.Discontinued_ProductBubble_NotFoundID = "Discontinued_ProductBubble_NotFound";
     this.Discontinued_ProductBubble_NotFoundID1 = "Discontinued_ProductBubble_NotFound1";
    this.Discontinued_ProductBubble_QtyLabelID="Discontinued_ProductBubble_QtyLabel";
    this.Discontinued_ProductBubble_PriceLabelID = "Discontinued_ProductBubble_PriceLabel";
    this.Discontinued_ProductBubble_QuantityContainerID = "Discontinued_ProductBubble_QuantityContainer";
    this.Discontinued_ProductBubble_AddToBagContainerID = "Discontinued_ProductBubble_AddToBagContainer";
    this.Discontinued_ProductBubble_BottomBarID = "Discontinued_ProductBubble_BottomBar";
    
    this.VIEWMOREDETAILS2_ID="PRODUCT_BUBBLE2_VIEWMOREDETAILS";
    this.VIEWMOREDETAILS_INNERHTML_TEMPLATE2="";    
    this.Bubble_Image_Prefix = "/images/product/" + PRODUCT_SMALL_IMAGE_PREFIX;
    this.Bubble_Image_SwatchPrefix = "/images/product/" + VARIANT_MEDIUM_SHADE_IMAGE_PREFIX;
    this.Bubble_Image_Suffix = PRODUCT_MEDIUM_IMAGE_SUFFIX;
    this.Bubble_Image_SwatchSuffix = VARIANT_SMALL_SHADE_IMAGE_SUFFIX;
    this.Discontinued_ProductBubble_SelectedShadeNameID='Discontinued_ProductBubble_SelectedShadeName';
    this.Discontinued_ProductBubble_AssociatedSelectedShadeNameID='Discontinued_ProductBubble_AssociatedSelectedShadeName';
    /**
     * This Method loads the discontinued product search bubble
     */    
    this.LoadProductSearch=function(){
       var obj1=$get(this.DiscontinuedSearch_DivID);
          if (obj1!=null) {
              obj1.style.visibility='visible';
          }
        
        // load the first selected category
        var ddobj = $get(this.Discontinued_CategoryDropDownID);
        if (ddobj!=null) { //ddobj is null when the categeory has no discontinued products
        this.FilterProductsByCategory(ddobj.options[ddobj.selectedIndex].value);
        
        // this.FilterProductsByCategory(this.options[this.selectedIndex].id);
        // popup the bubble
        _CoreModalPopUp._PopupControlID=this.DiscontinuedSearch_DivID;
        _CoreModalPopUp.ShowModal();
        }
    }
    /**
     * This Method loads the products using the passed in category code
     */        
    this.FilterProductsByCategory=function(CategoryCode)  {
        if(CategoryCode != "#" && CategoryCode != ""){
            // load the products drop down
            _WebServiceAPI.GetCategoryProductsByOnlineStatus(AJAX_DEFAULT_RTLCODE, CategoryCode, -1, true, this.SetProductDropDown);
            // reset the drop downs after each selection
            this.ResetFilterDropDown(_DiscontinuedBubble_Class.Discontinued_VariantsDropDownID);
            this.hideShowDropDown(_DiscontinuedBubble_Class.Discontinued_ShadeSelectID, false);
        }else{
            // reset the drop downs if the selection is "Select"
            this.ResetFilterDropDown(_DiscontinuedBubble_Class.Discontinued_ProductsDropDownID);
            this.ResetFilterDropDown(_DiscontinuedBubble_Class.Discontinued_VariantsDropDownID);
            // hide the Shade drop down 
            this.hideShowDropDown(_DiscontinuedBubble_Class.Discontinued_ShadeSelectID, false);
        }
    }
    /**
     * This Method loads the variants using the passed in product code
     */        
    this.FilterVariantsByProduct=function(ProductCode){
 
        if(ProductCode != "#" && ProductCode != ""){
            // load the variants drop down
             if (ProductCode.indexOf(":1")!=-1) {
               _WebServiceAPI.GetVariantInformationIgnoreFlags(AJAX_DEFAULT_RTLCODE, ProductCode.replace(":1",""), true, this.SetVariantDropDown);
            }
            else {
              this.hideShowDropDown(_DiscontinuedBubble_Class.Discontinued_ShadeSelectID, false);
            }
       
        }else{
            // reset the drop downs if the selection is "Select"
            this.ResetFilterDropDown(_DiscontinuedBubble_Class.Discontinued_VariantsDropDownID);
            // hide the Shade drop down 
            this.hideShowDropDown(_DiscontinuedBubble_Class.Discontinued_ShadeSelectID, false);
        }
    }
    
    this.GetSku=function (str) {
       if ( str.indexOf(":") !=-1 ) {
         var str_array=str.split(":");
        
         return str_array[0];
       
         }
         else {
          return str;
        }
     
    }
     this.HasShades=function (str) {
       if ( str.indexOf(":1") !=-1 ) {
           return true;
       
         }
         else {
          return false;
        }
     
    }
    
    /**
     * This Method is called when the webservice is done with data retrieval
     * @param {object} result the data that comes into a JASON format from a web service
     */               
    this.SetProductDropDown=function(Products){
        if(Products != null){
            var ddobj = $get(_DiscontinuedBubble_Class.Discontinued_ProductsDropDownID);
            if (ddobj != null){
                var sb = new StringBuilder();
                sb.append("<select class=\"Ablack10pxR\" onchange=\"javascript:_DiscontinuedBubble_Class.FilterVariantsByProduct(this.options[this.selectedIndex].value);_DiscontinuedBubble_Class.SetSearchButton(_DiscontinuedBubble_Class.GetSku(this.options[this.selectedIndex].value), false, _DiscontinuedBubble_Class.HasShades(this.options[this.selectedIndex].value));\">");
                for(i=0; i<Products.length; i++)  {
                    // set the first item to the search button
                    // set the Shade list to the first item
                    if (i == 0){
                        _DiscontinuedBubble_Class.SetSearchButton(Products[i].SKU, false, Products[i].HasShades);
                        if (Products[i].HasShades) { //F.N added this to prevent th skincaresun body and fragrance on shade level which leads on error.??
                       // _DiscontinuedBubble_Class.FilterVariantsByProduct(Products[i].SKU);
                         _DiscontinuedBubble_Class.FilterVariantsByProduct(Products[i].SKU + ":1");
                        }
                    }       
                    sb.append("<option value='");
                    sb.append(Products[i].SKU);
                    if (Products[i].HasShades) { 
                       sb.append(":1");
                    }
                    else {
                       sb.append(":0");
                    }
                    sb.append("'>");
                    sb.append(Products[i].Name);
                    sb.append("</option>");
                }
                sb.append("</select>");
                ddobj.innerHTML = sb.toString();
                
            }
        }
    }
    /**
     * This Method is called when the webservice is done with data retrieval
     * @param {object} result the data that comes into a JASON format from a web service
     */     
    this.SetVariantDropDown=function(result){
        if(result != null){
            // show the Shade drop down
            _DiscontinuedBubble_Class.hideShowDropDown(_DiscontinuedBubble_Class.Discontinued_ShadeSelectID, true);

            var Products = result;
            var ddobj = $get(_DiscontinuedBubble_Class.Discontinued_VariantsDropDownID);
            if (ddobj != null){
                var sb = new StringBuilder();
                sb.append("<select class=\"Ablack10pxR\" onchange=\"javascript:_DiscontinuedBubble_Class.SetSearchButton(this.options[this.selectedIndex].value, true, false);\">");
                sb.append("<option value='#'>- Select -</option>");
                for(i=0; i<Products.length; i++)  {
                    if(Products[i].Online == '-1'){
                        sb.append("<option value='");
                        sb.append(Products[i].SKU);
                        sb.append("'>");
                        sb.append(Products[i].Name); 
                        sb.append("</option>");
                    }   
                }
                sb.append("</select>");
                ddobj.innerHTML = sb.toString();
            }
        }
    }
    /**
     * This Method sets the search button based on the product/variant
     * @param {string} productcode
     * @param {bool} true - Variant /false - Product
     * @param {bool} hasShades if the product has shades
     */    
    this.SetSearchButton=function(ProductCode, ProductType, HasShades){
        var searchBtn = $get(_DiscontinuedBubble_Class.Discontinued_Search_ButtonID);
        var str = "javascript:_Discontinued_Class.ShowBubble('" + ProductCode + "'," + ProductType + "," + HasShades + ");";
        str += "$get(_DiscontinuedBubble_Class.DiscontinuedSearch_DivID).style.visibility='hidden';"
        searchBtn.onclick = new Function(str);
    }
    /**
     * This Method shows or hides the shades drop down
     * @param {string} parentObjName
     * @param {bool} true - show /false - hide
     */       
    this.hideShowDropDown=function(parentObjName, display){
        var shadeSelect = $get(parentObjName);
        if(display == true)
            shadeSelect.style.display = "";
        else
            shadeSelect.style.display = "none";
    }
    /**
     * This Method resets the specified drop down
     * @param {string} parentObjName
     */   
    this.ResetFilterDropDown=function(parentObjName) {
        var parentObj=$get(parentObjName);
        var allSelects=parentObj.getElementsByTagName("select");
        for (var i=0; i < allSelects.length; i++) {
            for (var j=0; j< allSelects[i].options.length; j++) {
                allSelects[i].options[j] = null;
            }
            allSelects[i].options[0] = new Option('- Select -','#');    
        }
    } 
    /**
     * This Method is called when the webservice is done with data retrieval
     * @param {object} result the data that comes into a JASON format from a web service
     */
    this.LoadProductRequestComplete=function(ProductResult, AssociationResult) {
        this.PopulateData(ProductResult,AssociationResult);
    }
        /**
     * This Method is called when the webservice is done with data retrieval
     * @param {object} result the data that comes into a JASON format from a web service
     */
    this.LoadVariantRequestComplete=function(ProductResult, AssociationResult) {
        this.PopulateVariantData(ProductResult,AssociationResult);
    }
    
    this.ShowHideBubbleImage=function(objID, value){
        var obj=$get(objID);
        if(obj!=null)
            obj.src=value;
    }
    this.ShowHideBubbleProductName=function(objID, value, showHide){
        var obj=$get(objID);
        if(obj!=null){
             if(showHide)
                obj.innerHTML = value;
             else
                obj.innerHTML = '';
        }
    }
    this.ShowHideBubbleContainer=function(objID, value, showHide){
        var obj=$get(objID);
        if(obj!=null){
            if (showHide){
                obj.style.display = "";
                obj.style.visibility = "visible";
                if (value != '')
                    obj.innerHTML = value;
            }else{
                obj.style.display = "none";
                obj.style.visibility = "hidden"; 
            }
        }   
    }
    
    this.ShowHideBottomSection=function(showHide){
        this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_QtyLabelID,'',showHide);
        this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_PriceLabelID,'',showHide);
        this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_QuantityContainerID,'',showHide);
        this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_AddToBagContainerID,'',showHide);
        this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_BottomBarID,'',showHide);
    }
    
    this.BuildViewMoreLink=function(prdCode,_Product){
        var viewmoredetailsobj=$get(this.VIEWMOREDETAILS_ID);
        if(viewmoredetailsobj!=null) {
           // var strviewmoredetails=viewmoredetailsobj.innerHTML;
            var strviewmoredetails=DISCONT_VIEWDETAILS_PROD_TEMPLATE
            //DISCONT_VIEWDETAILS_PROD_TEMPLATE_URL_REWRITTEN=
              // url rewriting determination
                 var _urlrewritten=""
                 if (_Product.URLRewrittenHomePage) {
                    if (_Product.URLRewrittenHomePage!="") {
                      //on this case override the actual url with urlrewriting.
                       strviewmoredetails=DISCONT_VIEWDETAILS_PROD_TEMPLATE_URL_REWRITTEN;
                       _urlrewritten=_Product.URLRewrittenHomePage;
                    }
                 }
                 //
            if (this.VIEWMOREDETAILS_INNERHTML_TEMPLATE=="") {
                this.VIEWMOREDETAILS_INNERHTML_TEMPLATE=strviewmoredetails;//preserve for future clicks
            }else {
                strviewmoredetails=this.VIEWMOREDETAILS_INNERHTML_TEMPLATE;
            }
            strviewmoredetails=strviewmoredetails.replace("$$$AJAX_ParentProductCode$$$",prdCode);
            strviewmoredetails=strviewmoredetails.replace("$$$AJAX_ProductCategoryCode$$$",_Product.CategoryPath);
            strviewmoredetails=strviewmoredetails.replace("$$$AJAX_ProductRelativePath$$$",this.GetRelativePath(_Product.CategoryHomePage));
             // url rewriting replacement
            if (_urlrewritten!="") {
                     strviewmoredetails=strviewmoredetails.replace("$$$AJAX_ProductURLRewrittenHomePage$$$",_urlrewritten);
           }
                  //
            viewmoredetailsobj.innerHTML= strviewmoredetails.toString();
        }
    
    
    }
    /**
     * populates the product bubble
     * If it belongs to make up, it also builds the shade table with defautl 8 cells in one row.
     * @param {object} result the data that comes into a JASON format from a web service
     */
    this.PopulateData=function(prodResult, assocResult)  {
        DoDefault();
        if (prodResult==null) {return false;}
        if (prodResult.Variants==null) {return false;}               //product has no variants
        if (typeof(prodResult)=='undefined') {return false;}
        if (typeof(prodResult.Variants)=='undefined') {return false;} //product has no variants

        //check if the main layer exist. If it does not, return.
        var prodBubble=$get(this.Bubble_DivID);
        if ((prodBubble==null) || (prodBubble=='undefined')) {
            alert('The \"' + this.Bubble_DivID + '\" is not found.');
            return;
        }
        var selshadelabelobj=$get(this.Discontinued_ProductBubble_SelectedShadeNameID);
        if (selshadelabelobj!=null) {
          selshadelabelobj.style.display="none";
        
        }
         var selshadelabelobj=$get(this.Discontinued_ProductBubble_AssociatedSelectedShadeNameID);
        if (selshadelabelobj!=null) {
          selshadelabelobj.style.display="none";
        
        }
        //
        // Discontinued Product
        var dropdownlistObj=$get(this.Bubble_LayerDropDownListID);
     // Found product image
        // show the selected product image   
        this.ShowHideBubbleImage(this.Bubble_ImageID, this.Bubble_Image_Prefix + prodResult.SKU + this.Bubble_Image_Suffix);
        
        // Show Found product name
        this.ShowHideBubbleProductName(this.Bubble_ProductNameID, prodResult.Name, true);
        this.ShowHideBubbleProductName(this.Bubble_ProductNameID2, prodResult.Name, true);

        var productBubbleSmShadesObj =$get(this.ProductBubble_Small_ShadesID);
        if (productBubbleSmShadesObj!=null) { //products with shades
            if (this.IsMakeupProduct) {
                // show the label for the Shade
                this.ShowHideBubbleContainer(this.DropDownShadeLabel,'',true);
                // hide the label for the Size
                this.ShowHideBubbleContainer(this.DropDownSizeLabel,'',false);
                
                // show the shades of the selected product 
                var innerHTML =  "<table width=\"70%\" border=0 cellspacing=1 cellpadding=1><tr><td><div class=\"BL_green1px\" align=\"left\"><p class=\"Adrkgrey12pxR\">Select a " + prodResult.Name + " Shade</p></div></td></tr></table>"
                innerHTML += this.GetShadeTableString(prodResult,true);              

                productBubbleSmShadesObj.innerHTML=innerHTML;
                productBubbleSmShadesObj.style.display="";
                                     
            }else { //products with no shades
                // Hide the label for the Shade
                this.ShowHideBubbleContainer(this.DropDownShadeLabel,'',false);
                // Show the label for the Size
                this.ShowHideBubbleContainer(this.DropDownSizeLabel,'',true);
                //hide the actual shade name
                this.ShowHideBubbleContainer(this.SelectShadeLabel,'',false);
                // hide the recommended product section
                this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID, '', false);
                this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID1, '', false);
                this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID2, '', false);
                productBubbleSmShadesObj.innerHTML="";
                productBubbleSmShadesObj.style.display="none";
            }   
        }
        
         // Associated Products 
        if (assocResult!=null){
            if (this.AssocCode == null || this.AssocCode == '')
                this.AssocCode = assocResult.ProductCode;
            
            // Use the Associated Product for the price
            this.DetermineMultiplePrices(assocResult.Variants);
            // show associated product image
            //this.ShowHideBubbleImage(this.Bubble_AssociatedImageID, this.AssocCode);
            this.ShowHideBubbleImage(this.Bubble_AssociatedImageID, this.Bubble_Image_Prefix + this.AssocCode + this.Bubble_Image_Suffix)
            
            // show associated product name
            this.ShowHideBubbleProductName(this.Bubble_AssocProductNameID, assocResult.Name, true);

            // Use the Associated Product for the price
            // if (this.DistinctPrice!=0)
            //    this.ShowHideBubbleContainer(this.Bubble_PriceID,"$ " + this.DistinctPrice,true);
            //else
            //    this.ShowHideBubbleContainer(this.Bubble_PriceID,'',false);  
            
            if(this.IsMakeupProduct){
                // Hide the label for the Shade
                this.ShowHideBubbleContainer(this.SelectShadeLabel,'',false);
                if (assocResult.Variants!=null){
                    // Show the label for the Shade
                    this.ShowHideBubbleContainer(this.SelectShadeLabel,assocResult.Variants[0].Name,true);
                    // Hide the drop down for the variant
                    this.ShowHideBubbleContainer(this.Bubble_LayerDropDownListID,'',false);
                    
                    // set the first variant to the selected shade
                    this.SetSelectedShade(assocResult.Variants[0]);
                    if (assocResult.ParentName=="") { //parent product
                    this.ShowHideBubbleContainer(this.ProductBubble_RecommendedProdNameID,assocResult.Name,true);
                    }
                    else {
                      this.ShowHideBubbleContainer(this.ProductBubble_RecommendedProdNameID,assocResult.ParentName + " " + assocResult.Name,true);
                   
                    }
                }
            }else{
                if (assocResult.Variants!=null) {
                    var hasuniqueprices=false;
                    if (this.DistinctPrice!=0) {
                        hasuniqueprices=true;
                     }
                    //
                      this.ShowHideBubbleContainer(this.Bubble_PriceID,  "$ " + assocResult.Variants[0].MainPrice, true);
                    // show the variant drop down for non makeup products
                    this.ShowHideBubbleContainer(this.Bubble_LayerDropDownListID,GenerateDropDownVariants(assocResult.Variants,this.Bubble_DropDownListID,hasuniqueprices,this.ShowPriceOnDropDown,'_DiscontinuedBubble_Class.SelectItem();'),true);
                    this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID1, '', true);
                    this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID2, '', true);
                   
                }else {
                    // hide variant drop down if no variants exist
                    this.ShowHideBubbleContainer(this.Bubble_LayerDropDownListID,'',false);
                }
            }
            // build the view more link
            this.BuildViewMoreLink(this.AssocCode, assocResult);
            //Populate some of the LastShoppingCartItem object properties, be sure to handle the price upon the addtobag item
            _LastShoppingCartItem.PopulateData("","",this.AssocCode,assocResult.Name,this.DistinctPrice);
            if (this.DistinctPrice==0){
                    this.SelectItem();//set the first item as selected
            }
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',false);
            this.ShowHideBottomSection(true);
            var obj=$get(this.Bubble_PriceID); 
            if(obj!=null) {
               obj.style.visibility='visible';
               obj.style.display="";
            }
            
        }else{
            if (this.IsMakeupProduct && prodResult.Variants!=null) { //this loads the association for first shade
                this.GetAssociatedShade(prodResult.Variants[0].SKU);
            }
            else {
            // no associated product exists -- hide bottom section of the bubble
            this.ShowHideBottomSection(false);
            this.ShowHideBubbleContainer(this.DropDownShadeLabel,'',false);
            this.ShowHideBubbleContainer(this.DropDownSizeLabel,'',false);
            this.ShowHideBubbleContainer(this.SelectShadeLabel,'',false);
            this.ShowHideBubbleContainer(this.Bubble_PriceID,'',false); 
            this.ShowHideBubbleContainer(this.Bubble_LayerDropDownListID,'',false);          
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',true);
            }
        }
         $get(this.Bubble_DivID).style.visibility='visible'
        _CoreModalPopUp._PopupControlID=this.Bubble_DivID;
        _CoreModalPopUp.ShowModal();
    }
 
    
    /**
     * populates the product bubble
     * If it belongs to make up, it also builds the shade table with defautl 8 cells in one row.
     * @param {object} result the data that comes into a JASON format from a web service
     */
    this.PopulateVariantData=function(prodResult, assocResult)  {
        DoDefault();
        if (prodResult==null) {return false;}
        if (typeof(prodResult)=='undefined') {return false;}

        //check if the main layer exist. If it does not, return.
        var prodBubble=$get(this.Bubble_DivID);
        if ((prodBubble==null) || (prodBubble=='undefined')) {
            alert('The \"' + this.Bubble_DivID + '\" is not found.');
            return;
        }
    
        // Discontinued Product
        var dropdownlistObj=$get(this.Bubble_LayerDropDownListID);
        // Found product image
        var obj=$get(this.Bubble_ImageID);
        // Not Found product image
        var imgobj2=$get(this.Bubble_ImageID2);
        // Found product name
        var prodnameobj=$get(this.Bubble_ProductNameID);
        // Not Found product name
        var prodnameobj2=$get(this.Bubble_ProductNameID2);
        // Small Shade ??
        var productBubbleSmShadesObj =$get(this.ProductBubble_Small_ShadesID);
        // Product Desc ??
        var productdescrobj=$get(this.Bubble_ProductDescriptionID);
        $get(this.ProductBubble_RecommendedContinerID).style.display = "none";

        if(prodnameobj!=null) {  
            prodnameobj.innerHTML=prodResult.Name;
        }
        //
        if(prodnameobj2!=null) {
            prodnameobj2.innerHTML=prodResult.Name;
        }
        //
        if (productdescrobj!=null) {
           productdescrobj.innerHTML=prodResult.Description;
        }
        
        // load the swatch images
        if (obj!=null) {
            obj.src=this.Bubble_Image_SwatchPrefix + prodResult.SKU + this.Bubble_Image_SwatchSuffix;
        }
        if (imgobj2!=null) {
            imgobj2.src=this.Bubble_Image_SwatchPrefix + prodResult.SKU + this.Bubble_Image_SwatchSuffix;
        }        
        
        //
        var labelObj=$get( this.SelectShadeLabel);
        //
        var shadeobj1=$get(this.DropDownShadeLabel);
        //
        var sizeobj2=$get(this.DropDownSizeLabel);
      
        if (productBubbleSmShadesObj!=null) { //products with shades
            if (shadeobj1!=null) {
                shadeobj1.style.display="none";
                shadeobj1.style.visibility='hidden';
            }
            if (sizeobj2!=null) {
                sizeobj2.style.display="";
                sizeobj2.style.visibility='visible';
            }

            productBubbleSmShadesObj.innerHTML="";
            productBubbleSmShadesObj.style.display="none";
        }
        
         // Associated Products 
        if (assocResult!=null){
            if (this.AssocCode == null || this.AssocCode == '')
                this.AssocCode = assocResult.ProductCode;
            
            // Use the Associated Product for the price
            this.DistinctPrice = assocResult.MainPrice;
                
            var obj=$get(this.Bubble_AssociatedImageID);
            if (obj!=null) {
                obj.src=this.Bubble_Image_SwatchPrefix + this.AssocCode + this.Bubble_Image_SwatchSuffix;
            }
        
            var assocprodnameobj=$get(this.Bubble_AssocProductNameID);
            if(assocprodnameobj!=null) {  
                assocprodnameobj.innerHTML=assocResult.Name;
            }
            // Use the Associated Product for the price
            var priceobj=$get(this.Bubble_PriceID);
            if (priceobj!=null) {
                if (this.DistinctPrice!=0) { //means same price variants
                    priceobj.innerHTML="$ " + this.DistinctPrice;
                }
                else { //means multiple prices
                    priceobj.innerHTML=""; 
                }   
            }  
            
            if(this.IsMakeupProduct){
                if (labelObj!=null) {
                    labelObj.innerHTML ="";
                    labelObj.innerHTML = assocResult.Name
                    if (dropdownlistObj!=null){
                        dropdownlistObj.style.display='none';   
                    }
                    
                    this.SetSelectedShade(assocResult);
                    var obj= $get(this.ProductBubble_RecommendedProdNameID);
                    if (obj!=null) {
                          if (assocResult.ParentName=="") {
                             obj.innerHTML = assocResult.Name;
                           }
                           else {
                             obj.innerHTML = assocResult.ParentName + " " + assocResult.Name;
                           }
                      
                    }
                    
                }
            }else{
                if (dropdownlistObj!=null) {
                    dropdownlistObj.style.visibility='hidden';
                    dropdownlistObj.style.display='none';
                }
                if (labelObj!=null) {
                    labelObj.innerHTML = "";
                }
            }
            // build the view more link
            this.BuildViewMoreLink(this.AssocCode, assocResult);
            //Populate some of the LastShoppingCartItem object properties, be sure to handle the price upon the addtobag item
            _LastShoppingCartItem.PopulateData("","",this.AssocCode,assocResult.Name,this.DistinctPrice);
            if (this.DistinctPrice==0){
                    this.SelectItem();//set the first item as selected
            }
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',false);
        }else{
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',true);
            //
             this.ShowHideBottomSection(false);
            this.ShowHideBubbleContainer(this.DropDownShadeLabel,'',false);
            this.ShowHideBubbleContainer(this.DropDownSizeLabel,'',false);
            this.ShowHideBubbleContainer(this.SelectShadeLabel,'',false);
            this.ShowHideBubbleContainer(this.Bubble_PriceID,'',false); //?????????
            this.ShowHideBubbleContainer(this.Bubble_LayerDropDownListID,'',false);    
            //
            
       
        }
         $get(this.Bubble_DivID).style.visibility='visible'
        _CoreModalPopUp._PopupControlID=this.Bubble_DivID;
        _CoreModalPopUp.ShowModal();
    }    
    
    /**
     * This method gets the selected shade's  associated product
     * @param {string} variant code of the
     */ 
    this.GetAssociatedShade=function(VariantCode) {
        var selshadeobj=$get('A_' + VariantCode);
        if (selshadeobj!=null) {
          var selshadelabelobj=$get(this.Discontinued_ProductBubble_SelectedShadeNameID);
          if (selshadelabelobj!=null) {
              selshadelabelobj.style.display='';
              selshadelabelobj.innerHTML=selshadeobj.alt;
          }
          this.getswapimagesrc(selshadeobj,'on');
        }
        var variant = _DiscontinuedProductManager.LoadVariant(VariantCode);
    }
    
    /**
     * This method toggles the selected shade as the users clicks the swatch
     * @param {object} result the data that comes into a JASON format from a web service
     */
    this.SetSelectedShade=function(Variant){
        if(Variant != null){
            // show details of the associated product
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID, '', true);
             this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID1, '', true);
             this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID2, '', true);
            this.ShowHideBubbleContainer(this.SelectShadeLabel,  Variant.Name, true);
             this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_AssociatedSelectedShadeNameID,  Variant.Name, true);
            this.ShowHideBubbleContainer(this.Bubble_PriceID,  "$ " + Variant.MainPrice, true);
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedShadeImgID,  "<img src='" + this.Bubble_Image_SwatchPrefix + Variant.SKU + ".gif' width=50 height=50/>", true);
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedShadeID,  Variant.Name, true);
            
            // set the associated product image on shade select
            this.ShowHideBubbleImage(this.Bubble_AssociatedImageID, this.Bubble_Image_Prefix + Variant.ParentProductCode + this.Bubble_Image_Suffix)
            
            // set the associated product name on shade select
            this.ShowHideBubbleContainer(this.Bubble_AssocProductNameID,  Variant.ParentName, true);
            
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedProdNameID,  Variant.ParentName, true);
            
            
            // build the view more link
            this.BuildViewMoreLink(Variant.ParentProductCode, Variant);
            
            // shows the add to bag related items
            this.ShowHideBottomSection(true);
            
            // show the conatiner that has the Associated item once a variant is selected
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',false);
            //when there is a shade as an association, still built the drop down of variants just so we re-use the add to bag functionality
            // and hide it
          
            var obj1=$get(this.Bubble_LayerDropDownListID);
            if (obj1!=null) {
              obj1.innerHTML=this.BuildDrpDownVariant(Variant,this.Bubble_DropDownListID,'_DiscontinuedBubble_Class.SelectItem();')
              obj1.style.display="none";
               obj1.style.visibility="hidden";
            
            }
            //manage out of stock
            this.ManageStock(Variant.StockWeb.toString());
        }
        else{
            // show the a message if there is no associated variant for this item
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedShadeImgID,  "<img src='/images/spacer.gif' width=50 height=50/>", true);
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedShadeID,  "Sorry no match", true);
            this.ShowHideBubbleContainer(this.SelectShadeLabel,  "No match", true);
            
            // hide the conatiner that has the Associated item once a variant is selected
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_FoundID,'',false);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID,'',true);
            this.ShowHideBubbleContainer(this.Discontinued_ProductBubble_NotFoundID1,'',true);
            //
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID, '', false);
            this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID1, '', false);
             this.ShowHideBubbleContainer(this.ProductBubble_RecommendedContinerID2, '', false);
              
        }
    }
    
  
  
  this.BuildDrpDownVariant=function(Variant,DropDownID,onchangeFuncCall)      
    {
        var sb = new StringBuilder();
        sb.append("");
      if (Variant != null ) {
            sb.append("<select id=\"");
            sb.append(DropDownID);
            sb.append("\" class=\"Ablack10pxR\" onchange=\"" + onchangeFuncCall +"\">");
            sb.append("<option value=\"");
            sb.append(Variant.SKU);
            sb.append("#");
            sb.append(Variant.MainPrice);
            sb.append("#");
            sb.append(Variant.StockWeb.toString());
            sb.append("\">");
            sb.append(Variant.Name); 
            sb.append("</option>");
           sb.append("</select>")
        }
      return sb.toString();
}
    /**
     * it manages to build up the string of the shade table
     * please be aware that this method uses the javascript
     * string builder class to improve the performance vs the regular string concatination
     * @param {object} result the data that comes into a JASON format from a web service
     * @param {bool} SmallShadesWanted true or false, if true, we build the thumbnails
     */
    this.GetShadeTableString=function(result) {
        if (result!=null  && result.Variants!=null) {
            var VariantsToBeDisplayed=result.Variants;
            var CurrentRowNumber=0;
            var CurrentCellInCurrentRow=0;
            var sb = new StringBuilder();
            var HasShadeSubGroup=false;
            var StartSubGroupConst='$#Begin#$';
            var PreviousSubGroupValue=StartSubGroupConst;
            var swatchW=VARIANT_SMALL_SHADE_WIDTH;
            var swatchH=VARIANT_SMALL_SHADE_HEIGHT;
            
            if (typeof(SHADE_SUB_GROUP_FLD)!='undefined' || SHADE_SUB_GROUP_FLD!='') {
                   HasShadeSubGroup=true;
                   sb.append("<table border=0 cellspacing=1 cellpadding=1><tr><td >");
            }else{
                   sb.append("<table border=0 cellspacing=1 cellpadding=1><tr>");
            }
            var previousSku="#_999_notavailable_999_#";
            var filter= this.FilterVariantList; //
            for(var i=0; i<VariantsToBeDisplayed.length; i++) {
               if (previousSku!=VariantsToBeDisplayed[i].SKU) { //prevent duplicates, for somereason I have seen once in awhile
               previousSku=VariantsToBeDisplayed[i].SKU;
            // if ((filter=='') || (filter.indexOf(VariantsToBeDisplayed[i].SKU)) !=-1)) {
              if (filter=='' || filter.indexOf(VariantsToBeDisplayed[i].SKU)!=-1) {
               if (HasShadeSubGroup==true) {
              //subgrouping get value
               var currenSubGroupValue="";
               if (VariantsToBeDisplayed[i].Properties!=null) {
                    var _Properties=VariantsToBeDisplayed[i].Properties;
                    for(var j=0; j<_Properties.length; j++) {
                        if (_Properties[j].Name.toLowerCase()==SHADE_SUB_GROUP_FLD.toLowerCase()) {
                          currenSubGroupValue=_Properties[j].Value;;
                          }
                    }
                }

                //subgrouping build table
                 if (PreviousSubGroupValue!=currenSubGroupValue && HasShadeSubGroup==true) {
                        if (PreviousSubGroupValue!=StartSubGroupConst) { //close subgrouping
                            if (CurrentRowNumber>0 && CurrentCellInCurrentRow<this.RowSize) {
                                for(var k=CurrentCellInCurrentRow; k<this.RowSize; k++)
                                {
                                    sb.append("<td><img src=\"" + SPACER_IMAGE + "\"" + " width=\"" + swatchW + "\" height=\"" +swatchH + "\" border=\"0\"></td>");
                                   
                                }
                             }
                            sb.append("</tr></table></div></td></tr></table></div>" );
                        }
                        sb.append("<div class=\"BL_pink1px\" align=\"left\"><table border=0 cellspacing=1 cellpadding=1><tr><td width=\"35%\" class=\"Adrkpink10pxR\" >" );
                      
                        sb.append(currenSubGroupValue);
                        sb.append("</td><td align=\"left\">" );
                        sb.append("<div class=\"Adrkpink10pxR\"><table border=0 cellspacing=1 cellpadding=1><tr>");
                        CurrentRowNumber+=1;
                        CurrentCellInCurrentRow=0;
                        PreviousSubGroupValue=currenSubGroupValue;
                
                    }
                 }
               
                if (CurrentCellInCurrentRow >= this.RowSize ) {
                    sb.append("</tr><tr>");
                    CurrentRowNumber+=1;
                    CurrentCellInCurrentRow=0;
                }
            
                sb.append("<td><img id='A_" + VariantsToBeDisplayed[i].SKU +"' src='" + this.Bubble_ImagePrefix_SmallShade + VariantsToBeDisplayed[i].SKU +  this.Bubble_ImageSuffix_SmallShade + "' onclick=\"javascript:_DiscontinuedBubble_Class.getswapimagesrc(this,'on');_DiscontinuedBubble_Class.GetAssociatedShade('" + VariantsToBeDisplayed[i].SKU +"');\" style=\"cursor:pointer\""  + " width=\"" + swatchW + "\"  height=\"" +swatchH + "\" alt=\"" + VariantsToBeDisplayed[i].Name + "\"></td>");
                CurrentCellInCurrentRow+=1;
             }
            }
            }
             //end of for loop
             if (CurrentRowNumber>0 && CurrentCellInCurrentRow<this.RowSize) {
                    for(var i=CurrentCellInCurrentRow; i<this.RowSize; i++)
                    {
                       sb.append("<td><img src=\"" + SPACER_IMAGE + "\"" + " width=\"" + swatchW + "\" height=\"" +swatchH + "\" border=\"0\"></td>");           
                    }
             }
             //
             sb.append("</tr></table>");
             
             if (HasShadeSubGroup) {
                sb.append("</div></td></tr></table></div></td></tr></table>" );
             }
             if (CurrentRowNumber>5) {
               _CoreModalPopUp._IsforegroundElementLarge=true;
             }else {
               _CoreModalPopUp._IsforegroundElementLarge=false;
             }
            //alert(sb.toString());
            return sb.toString();
        }
        return "";
    }
    
}
 /**
 * Inherit from the ProductManager_Class
 */
Core.DiscontinuedBubble_Class.prototype = new Core.ProductBubble_Class;

 /**
 * It registers the  DiscontinuedProductManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.DiscontinuedBubble_Class.registerClass('Core.DiscontinuedBubble_Class'); }

 /**
 * It instantiates an object of type Core.DiscontinuedProductManager_Class
 */
var _DiscontinuedBubble_Class=new Core.DiscontinuedBubble_Class();

/**
 * @class VideoBubble_Class
 * This class is responsible for displaying videos in the ajax bubbles
 */
Core.VideoBubble_Class=function() {
    this.Bubble_DivID = "Video_Bubble";
    this.FlashDivID = "flashDiv";
    this.VideoPath = "";
    this.VideoHeight = "260";
    this.VideoWidth = "326";
    this._VideoPopUp;

    this.HideMe=function()
    {
        if (AJAX_IsIE6()) {
           ToggleProductDetailVarQTYList('visible');
        }      

        this._VideoPopUp.HideModal();
    } 

    /**
     * Shows the Sign in bubble
     */    
    this.ShowBubble=function(vidPath){
        this.VideoPath = vidPath;
        this.CreateFlashControl("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
            "video", 
            this.VideoWidth, /*width*/ 
            this.VideoHeight, /*height*/
            this.VideoPath,
            "",
            "true");
        this._VideoPopUp = new Core.ModalPopUp(); 
        this._VideoPopUp._PopupControlID=this.Bubble_DivID;
        this._VideoPopUp.ShowModal();

        
    }
    
    /**
     * Shows the Sign in bubble passing in width and height
     */    
    this.ShowBubbleWidhtHeight=function(vidPath, vidwidth, vidheight){
        this.VideoPath = vidPath;
        this.VideoWidth = vidwidth;
        this.VideoHeight = vidheight;
        this.CreateFlashControl("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
            "video", 
            this.VideoWidth, /*width*/ 
            this.VideoHeight, /*height*/
            this.VideoPath,
            "",
            "true");
        this._VideoPopUp = new Core.ModalPopUp(); 
        this._VideoPopUp._PopupControlID=this.Bubble_DivID;
        
        if (AJAX_IsIE6()) {
            ToggleProductDetailVarQTYList('hidden');
        }        
        
        this._VideoPopUp.ShowModal();

        
    }    
    
    this.CreateFlashControl=function(CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
    {
        var d = $get(this.FlashDivID);
        var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
        objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
        objectTag = objectTag + '<param name="movie" value=' + URL + '>'
        objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
        objectTag = objectTag + '<param name="quality" value="high">'  
        objectTag = objectTag + '<param name="autoStart" value=\"' + AUTOSTART + '\"/>';
        objectTag = objectTag + '<param name="wmode" value="transparent" />'  				
        objectTag = objectTag + '<embed wmode="transparent" autoStart= "' + AUTOSTART + '" src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#000000" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
        objectTag = objectTag + "</object>";  
        d.innerHTML = objectTag;
    }
}
 /**
 * It registers the  VideoBubble_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.VideoBubble_Class.registerClass('Core.VideoBubble_Class'); }

 /**
 * It instantiates an object of type Core.VideoBubble_Class
 */
var _VideoBubble_Class=new Core.VideoBubble_Class();

/**
 * @class TopicFavoriteBubble_Class
 * This class is responsible for displaying videos in the ajax bubbles
 */
Core.TopicFavoriteBubble_Class=function() {
    this.ConfirmBubble_DivID = "TopicConfirmFavorite_Bubble";
    this.TopicCode = "";
    this.TopicType = "";
    this.ConfirmBubble;

    this.AddFavorite=function(topCode, topType){
        this.TopicCode = topCode;
        this.TopicType = topType;
        if(CustomerSigned == true){
            _TopicManager.SaveTopic(this.TopicCode,this.TopicType, _TopicFavoriteBubble_Class.SaveTopicComplete);
        }else{
            _SignInBubble.TopicType = topType;
            _SignInBubble.ShowBubbleFromFavoritesBubble(this.TopicCode);
        }
    }
    
    this.SaveTopicComplete=function(result){
        DoDefault();
        if (result.ActivityStatus==true) {
            _CoreModalPopUp._PopupControlID = _TopicFavoriteBubble_Class.ConfirmBubble_DivID;
            _CoreModalPopUp.ShowModal();
        }
    }
}
 /**
 * It registers the  TopicFavoriteBubble_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.TopicFavoriteBubble_Class.registerClass('Core.TopicFavoriteBubble_Class'); }

 /**
 * It instantiates an object of type Core.TopicFavoriteBubble_Class
 */
var _TopicFavoriteBubble_Class=new Core.TopicFavoriteBubble_Class();


/**
 * @class Event_Bubble
 * This class is responsible for displaying event search in the ajax bubbles
 */
Core.EventBubble_Class=function() {
    this.Bubble_DivID = "Event_Bubble";
    this._EventPopUp;
      /**
     * The DHTML ID of the Top HTML Section
     */
    this.EventBubble_TopHTMLID = "TopHTML";    

    /**
     * Shows the Sign in bubble
     */    
    this.ShowBubble=function(topCode, topType){
        //this._EventPopUp = new Core.ScrollPopup(); 
        _ScrollPopup_Class._PopupControlID=this.Bubble_DivID;//this._EventPopUp._PopupControlID=this.Bubble_DivID;
        //$get(this.EventBubble_TopHTMLID).innerHTML = "topic is " + topCode + " code is " + topType;
        this.GetEventTopicInformation(topCode, topType, displayEvent);
        
      if (AJAX_IsIE6()) {
       //  ToggleDropDowns('hidden');
          try {
               var obj=$get("state");
                if (obj!=null) {
                    //alert(obj.name);
                  obj.style.visibility='hidden';
                  obj.style.display='none';
                }
            }
           catch(err) { }
     }
             
        _ScrollPopup_Class.ShowModal();
    }
    
    /**
     * Retrieves topic information
     * @param {string} TopicCode The selected topic code
     * @param {string} TopicType The topic type
     * @param {function} OnCompleteFuncName This is the callback function after the web service returns the result data
     */
    this.GetEventTopicInformation=function(TopicCode, TopicType, OnCompleteFuncName) {
        if(!IsAjaxLoaded()) {return false;}
       
        try {
            DoWait();
            MicrosoftFrance.MCS.Commerce.WS.AJAXProject.TopicWebService.GetTopicInformation(TopicCode, TopicType,  eval(OnCompleteFuncName),onError);
        }
        catch (e) {
            DoDefault();
            window.status = e.message;
        }
        return false;
    }
    
    function displayEvent(result)
    {
        if (result!=null) {
            DoDefault();
            var _Properties=result.Properties;
            //alert(_Properties.length);
            for(var j=0; j<_Properties.length; j++) {
                //alert(_Properties[j].Name + "::" + _Properties[j].Value);
                var topObj =$get("TopHTML");
                var midObg =$get("MidHtml");
                var btmObj =$get("BottomHTML");
                var hidObj =$get("HiddenHTML");
                if (_Properties[j].Name == "BB_Article_Content")
                {
                    topObj.innerHTML= _Properties[j].Value;
                }
                if (_Properties[j].Name == "BB_Article_Content_2")
                {
                    btmObj.innerHTML= _Properties[j].Value;
                }
                if (_Properties[j].Name == "BB_Article_Content_3")
                {
                    midObg.innerHTML= _Properties[j].Value;
                }
                hidObj.innerHTML = "<input type='hidden' id='hidtopiccode' value='" + result.TopicCode + "'>";
            }
         }
         else 
         { 
            alert ("No results for this event.");
         }  
    }        

}
 /**
 * It registers the  VideoBubble_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.EventBubble_Class.registerClass('Core.EventBubble_Class'); }

 /**
 * It instantiates an object of type Core.VideoBubble_Class
 */
var _EventBubble_Class=new Core.EventBubble_Class();





/**
 * @class Where2GetItMap_Bubble
 * This class is responsible for displaying store map in the ajax bubbles
 */
Core.Where2GetItMap_Class=function() {
    this.Bubble_DivID = "Where2GetItMap_Bubble";
    this._MapPopUp;
    this.MapSpanID="StoreMap"

    /**
     * Shows the map in bubble
     */    
    this.ShowBubble=function(add1, city, state, zip){
        this._MapPopUp = new Core.ModalPopUp(); 
        this._MapPopUp._PopupControlID=this.Bubble_DivID;
        this.GetMapInformation(add1, city, state, zip, displayMap);
        //this._MapPopUp.ShowModal();
    }
    
    this.HideMe=function()
    {
            
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._MapPopUp.HideModal();
    }    
    
    /**
     * Retrieves map for specific store
     * @param {string} add1 The stores address1
     * @param {string} city The topic type
     * @param {string} state The selected topic code
     * @param {string} zip The topic type     
     * @param {function} OnCompleteFuncName This is the callback function after the web service returns the result data
     */
    this.GetMapInformation=function(add1, city, state, zip, OnCompleteFuncName) {
        if(!IsAjaxLoaded()) {return false;}
        try {
            DoWait();
            Loreal.US.eCommerce.WS.Lancome.US.AJAXProject.Where2getitMapWebService.GetWhere2getitMap(add1, city,  state, zip, eval(OnCompleteFuncName),onError);
        }
        catch (e) {
            DoDefault();
            window.status = e.message;
        }
        return false;
    }
    
    function displayMap(result)
    {
         DoDefault();     
         if (result!=null) {
         
            //alert(result[0]);
            //alert(result[1]);
            var mapObj =$get("StoreMap");
            mapObj.innerHTML="<img id='Map' name='Map' style='BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none' align='middle' border='0' src='" + result[0] + "' />";
            var mapIDObj = $get("MapIdSpan");
            mapIDObj.innerHTML = result[1];
            //alert(mapIDObj.innerHTML);
            var mapLoadingObj = $get("Loading");
            mapLoadingObj.style.visibility = "hidden";
            
          if (AJAX_IsIE6()) {
               ToggleStateList('hidden');
         }            
            
            _Where2GetItMap_Class._MapPopUp.ShowModal();
         }
         else 
         { 
            alert ("No map for this store.");
         }  
    }        

}
 /**
 * It registers the  Where2GetItMap_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.Where2GetItMap_Class.registerClass('Core.Where2GetItMap_Class'); }

 /**
 * It instantiates an object of type Core.Where2GetItMap_Class
 */
var _Where2GetItMap_Class=new Core.Where2GetItMap_Class();






/**
 * @class ScrollPopup creates a modal pop up "bubble" that can scroll, needed on events index page
 */
Core.ScrollPopup= function () {
    /**
     *  The layer of the whole modal window (object)
     */
    this._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 (this._backgroundElement==null) {
            this._backgroundElement = document.createElement('div');
            this._backgroundElement.style.display = 'none'; //none
            this._backgroundElement.style.position = 'absolute';
            this._backgroundElement.className = 'modalBackground';
            document.body.appendChild(this._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 ((this._backgroundElement==null) || (typeof(this._backgroundElement)=='undefined') ) {
            this._Initialize();
        }

        if (this._PopupControlID !=null) {
            this._InitializeForeground();
        }

        var clientWidth =630;
        var 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;
        }
        
        this._backgroundElement.style.left = scrollLeft+'px';
        this._backgroundElement.style.top = scrollTop+'px';
        this._backgroundElement.style.width = clientWidth+'px';
        this._backgroundElement.style.height = clientHeight+'px';
        this._backgroundElement.style.display = 'block';
        //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 {
             //document.write(this._foregroundElement.offsetHeight);
             if (this._foregroundElement.style.top == null || this._foregroundElement.style.top == '')
             {
                this._foregroundElement.style.top = '119px';
             }
             else
             {
                this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/2)+'px';
             }
             //alert(this._foregroundElement.offsetHeight);
             // some popups came up with negative (-) in top property, below forced it to be positive position
             if (this._foregroundElement.style.top.indexOf('-') > -1)
                this._foregroundElement.style.top = this._foregroundElement.style.top.replace("-", "");
             //alert(this._foregroundElement.style.top);
           }
                     
        }
        
        
        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 (this._backgroundElement!=null) {
            this._backgroundElement.style.display = 'none';
        }
        if (this._foregroundElement!=null) {
            this._foregroundElement.style.display = 'none';
        }
        IS_MODELPOPUP_VISIBLE=false;
        this._IsforegroundElementLarge=false;
        
      if (AJAX_IsIE6()) {
         //ToggleDropDowns('visible');
          try {
                var obj=$get("state");
                if (obj!=null) {
                //alert(obj.name);
                    obj.style.visibility='visible';
                    obj.style.display='';
                }
         }
         catch(err) { }
     }         
    }
    

    /**
     * ResizeHandler 
     */
    this.ResizeHandler=function() {
        if (this._backgroundElement!=null && this._backgroundElement.style.display != 'none' ){
            _ScrollPopup_Class.ShowModal();
        }

    }

    /** 
     * ScrollHandler    
     */
    this.ScrollHandler=function() {
        if (_ScrollPopup_Class._backgroundElement!=null && _ScrollPopup_Class._backgroundElement.style.display != 'none' ){
            //alert("ASd");
            //_ScrollPopup_Class.ShowModal();
            
                    var clientWidth =630;
        var 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;
        }
        



        _ScrollPopup_Class._backgroundElement.style.left = scrollLeft+'px';
        _ScrollPopup_Class._backgroundElement.style.top = scrollTop+'px';
        _ScrollPopup_Class._backgroundElement.style.width = clientWidth+'px';
        _ScrollPopup_Class._backgroundElement.style.height = clientHeight+'px';
        _ScrollPopup_Class._backgroundElement.style.display = 'block';
        //show foreground element
        //this._foregroundElement.style.display = 'block'; 
            
        }

    }
}
/*
 * It registers the WebServiceAPI_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.ScrollPopup.registerClass('Core.ScrollPopup'); }
 
 /**
 * It instantiates an object of type Core.Where2GetItMap_Class
 */
var _ScrollPopup_Class=new Core.ScrollPopup();

/**
 * @class EmailFriendBubble_Class
 * This class Sends Email Messages to from the site
 * @constructor 
 */
Core.EmailFriendBubble_Class=function() {
    /**
    * The DHTML ID of the main layer of the EmailFriend bubble
    */
    this.ProductEmailTemplate="TellAFriendProduct.xml";
    this.TopicEmailTemplate="Topic_TellAFriend.xml";
    this.IsStaticTemplate=false;
    /**
    * The DHTML ID of the main layer of the EmailFriend bubble
    */
    this.Bubble_DivID="EmailFriend_div";
    /**
    * The DHTML ID of the confirm layer of the EmailFriend bubble
    */
    this.BubbleConfirm_DivID="EmailFriendConfirm_div";
    /**
    * The error message to designate incorrect fields
    */   
    this.FieldError = "<span style='color:#FF0000'><strong>!&nbsp;</strong></span>";
    /**
    * The DHTML ID of the General Error Message
    */   
    this.GeneralErrorID = "EmailFriend_GeneralError";
    /**
    * The DHTML ID of the General Error Message
    */   
    this.GeneralError = "<div style='color:#FF0000'><strong>Please fill all the required fields with valid data.</strong></div>";
    /**
    * The email error message
    */   
    this.EmailError = "<div style='color:#FF0000'><strong>Please enter a valid email address.</strong></div>";
    /**
    * The email addresses limit exceeded error message
    */   
    this.EmailAddressesLimitError = "<div style='color:#FF0000'><strong>Please do not enter more than 10 email addresses.</strong></div>";
    /**
    * The fatel error message
    */   
    this.FatalError = "<div style='color:#FF0000'><strong>Sorry this email cannot be sent.</strong></div>";
    /**    
    * The DHTML ID of the Sender's first name
    */
    this.Sender_FnameID="Sender_Fname";
    /**    
    * The DHTML ID of the Sender's first name error
    */
    this.Sender_FnameErrorID="Sender_FnameError";
    /**
    * The DHTML ID of the Sender's last name
    */
    this.Sender_LnameID="Sender_Lname";
    /**    
    * The DHTML ID of the Sender's last name error
    */
    this.Sender_LnameErrorID="Sender_LnameError";
    /**
    * The DHTML ID of the Sender's Email
    */
    this.Sender_EmailID="Sender_Email";
    /**    
    * The DHTML ID of the Sender's email name error
    */
    this.Sender_EmailErrorID="Sender_EmailError";
    /**    
    * The DHTML ID of the Friend's email addresses
    */
    this.Friend_EmailID="Friend_Email";    
    /**    
    * The DHTML ID of the Friend's message
    */
    this.Friend_EmailErrorID="Friend_EmailError";
    /**    
    * The DHTML ID of the Friend's email addresses error
    */
    this.Friend_MessageID="Friend_Message"; 
    /**    
    * The DHTML ID of the checkbox asking to copy the sender to the email
    */
    this.Sender_CopyEmailID="Sender_CopyEmail"; 
    /**    
    * The DHTML ID of the Friend's email addresses
    */    
    this.Friend_EmailListID="Friend_EmailList";  
    /**    
    * to track if there is missing information
    */
    this.hasErrors=false;
    /**    
    * to track if there is a bad email address entered
    */
    this.EmailhasErrors=false;
    /**    
    * to track if the email addresses limit is exceeded
    */
    this.EmailAddressesLimithasError=false;
    /**    
    * Product Code
    */
    this.ProductCode=""; 
    /**    
    * Topic Code
    */
    this.TopicCode=""; 
    /**    
    * Topic Type
    */
    this.TopicType="";    
    this.LeftPosition = "";
    this.TopPosition = "";
    /**
     * When the Email a friend bubble is shown, 
     */
    this.ShowBubble=function(which) {
        _CoreModalPopUp._PopupControlID=this.Bubble_DivID;
        _CoreModalPopUp.ShowModal();
    }
    /**
     * When the Email a friend confirmation bubble is shown, 
     */
    this.ShowConfirmBubble=function() {
    
        // Get email addresses to show on the confirm page
        var senderEmailListobj=$get(this.Friend_EmailListID);
        var friendEmailobj=$get(this.Friend_EmailID);
        if ((friendEmailobj != null) && (senderEmailListobj != null))
            senderEmailListobj.innerHTML = this.GetEmailList(friendEmailobj.value);
        _CoreModalPopUp._PopupControlID=this.BubbleConfirm_DivID;
        _CoreModalPopUp.ShowModal();
    }
    
    /**
     * Validates the email fields and sends the email 
     */
    this.SendEmail=function() {
        this.hasErrors=false;
        this.EmailhasErrors=false;
        var copyEmail=false;
        var validTemplate="";
        var code="";
        var isProduct=false;
        // Get all the fields needed for the email
        
        // check the validity of the input fields
        // Sender First Name
        var fromFname = this.ValidateTextField($get(this.Sender_FnameID), this.Sender_FnameErrorID, this.FieldError);
        // Sender Last Name
        var fromLname = this.ValidateTextField($get(this.Sender_LnameID), this.Sender_LnameErrorID, this.FieldError);      


        // Sender Email
        var fromEmail = "";
        if ($get(this.Sender_EmailID) != null)
            fromEmail = $get(this.Sender_EmailID).value;
                   
        this.ValidateEmailField(fromEmail, this.Sender_EmailErrorID, this.FieldError);
        
        // Friends Email        
        var toEmail = "";
        if ($get(this.Friend_EmailID) != null)
            toEmail = $get(this.Friend_EmailID).value;
        
        this.ValidateEmailField(toEmail, this.Friend_EmailErrorID, this.FieldError);
       
        // Friends Message
        var fromMsg = "";
        // check if the messsage box control exits
        if($get(this.Friend_MessageID) != null)
            fromMsg = $get(this.Friend_MessageID).value;
            
        //check and set the Copy to control
        if ($get(this.Sender_CopyEmailID) != null)
             copyEmail = $get(this.Sender_CopyEmailID).checked;

        // check for general errors & check for email errors
        if (this.hasErrors || this.EmailhasErrors || this.EmailAddressesLimithasError){
            var errorsb = new StringBuilder(); 
            if (this.hasErrors)
                errorsb.append(this.GeneralError);
            
            if (this.EmailhasErrors)
                errorsb.append(this.EmailError);
                
            if (this.EmailAddressesLimithasError)
                errorsb.append(this.EmailAddressesLimitError);
                
            $get(this.GeneralErrorID).innerHTML = errorsb.toString();
            
            return;    
        }
   
        // determine if Product or Topic
        if (this.ProductCode != ""){
            // send the appropraiate template
            validTemplate = this.ProductEmailTemplate; 
            isProduct = true;
            // send productcode passed in
            code = this.ProductCode; 
        }else if (this.TopicCode != ""){
            // send the appropraiate template
            validTemplate = this.TopicEmailTemplate; 
            isProduct = false;
            // send topicCode:topicType passed in
            code = this.TopicType + ":" + this.TopicCode;
        
        }else if (this.IsStaticTemplate == true){
            validTemplate = this.TopicEmailTemplate; 
            isProduct = false;
        }

       // goes into the WS Call
       //Loreal.US.eCommerce.WS.Lancome.US.AJAXProject.CustomerWebService.SendMailTellAFriend(fromFname, fromLname, fromEmail, fromMsg, toEmail, copyEmail, code, isProduct, validTemplate, 'html', this.OnCompleteRequest,onError,onTimeout);
       if (IsAjaxLoaded())
       {
        	try
        	{
	            DoWait();	            
	            MicrosoftFrance.MCS.Commerce.WS.AJAXProject.CustomerWebService.SendMailTellAFriend(fromFname, fromLname, fromEmail, fromMsg, toEmail, copyEmail, code, isProduct, validTemplate, 'html', 'http://www.google.fr', this.OnCompleteRequest, onError, onTimeout);
	            	          
                if ($get('Sender_Fname') != null)
                    $get('Sender_Fname').value = ''; 
                if ($get('Sender_Lname') != null)
                    $get('Sender_Lname').value = '';  
                if ($get('Sender_Email') != null)
                    $get('Sender_Email').value = '';    
                if ($get('Friend_Email') != null)
                    $get('Friend_Email').value = ''; 
                if ($get('Friend_Message') != null)
                    $get('Friend_Message').value = '';                    
	        }
	        catch (ex)  
	        {
	            DoDefault();
	            window.status = ex.message;
	        }
        
        }

       return false;
    }
    
    /**
     * Validates the field used on Mandatory fields 
     * @param {object} field - control to validate
     * @param {string} errorID - the control ID of the error container
     * @param {string} errorVal - value to add into the error container on error
     */
    this.ValidateField=function(field, errorID, errorVal) {
        var fieldVal = "";
        if(field != null){
            fieldVal = field.value;            
            if (fieldVal.length <= 0){
                $get(errorID).innerHTML = errorVal;
                this.hasErrors = true;
            }else{                                               
                $get(errorID).innerHTML = '';
            }
        }
        return fieldVal;
    }
    
    /**
     * Validates the field used on Mandatory text fields 
     * @param {object} field - control to validate
     * @param {string} errorID - the control ID of the error container
     * @param {string} errorVal - value to add into the error container on error
     */
    this.ValidateTextField=function(field, errorID, errorVal) {
        var fieldVal = "";
        if(field != null){
            fieldVal = field.value;
            var regExp = new RegExp("[a-zàâäéèêëîïôöùûü]+", "gi");                     
            if (fieldVal.length <= 0 || fieldVal.match(regExp) != fieldVal){
                $get(errorID).innerHTML = errorVal;
                this.hasErrors = true;
            }else{                                
                $get(errorID).innerHTML = '';
            }
        }
        return fieldVal;
    }
    
    /**
     * Validates the Email field
     * @param {string} email - value from the email textbox (could be a comma separated list)
     * @param {string} errorID - the control ID of the error container
     * @param {string} errorVal - value to add into the error container on error     
     */
    this.ValidateEmailField=function(email, errorID, errorVal) {
        // validation support for multiple addresses
        if (email.indexOf(',') == -1){
            var emailhasError=false;
            var at="@";
            var dot=".";
            var lat=email.indexOf(at);
            var lstr=email.length;
            var ldot=email.indexOf(dot);
            
            // has an @
            if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr)
               emailhasError = true;
            // has at least one .
            if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr)
                emailhasError = true;
            // has only 1 @
            if (email.indexOf(at,(lat+1))!=-1)
                emailhasError = true;
            // has a . after the @
            if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot)
                emailhasError = true;
            // doesn't have a . right before @
            if (email.indexOf(dot,(lat+2))==-1)
                emailhasError = true;
            // no spaces
            if (email.indexOf(" ")!=-1)
                emailhasError = true;
                
            if(emailhasError){
                $get(errorID).innerHTML = errorVal;
                this.EmailhasErrors = emailhasError;
                return;
            }else{
                $get(errorID).innerHTML = '';
            }
		}else{
		    var elist = email.split(",");
		    if (elist.length <= 10){
		        if (this.EmailAddressesLimithasError)
		            this.EmailAddressesLimithasError = false;
		            
                for ( i =0;i<=elist.length-1;i++) {
                    this.ValidateEmailField(elist[i],errorID,errorVal);
                }
            }else{               
                $get(errorID).innerHTML = errorVal;
                this.EmailAddressesLimithasError = true;
                return;
            }
            
		}
	}
	
    /**
     * This method is called after a web Service Call is Completed
     * @param {string} result The result object returned from the web service
     */
    this.OnCompleteRequest=function(result){
        DoDefault();
         if (result!=null) {
            if(result == "true"){
                var eDiv = $get(_EmailFriendBubble_Class.Bubble_DivID)
                if(eDiv != null){   
                    eDiv.style.display="none";
                }
                _EmailFriendBubble_Class.ShowConfirmBubble();
            }else{
                //$get(_EmailFriendBubble_Class.GeneralErrorID).innerHTML = result;
                $get(_EmailFriendBubble_Class.GeneralErrorID).innerHTML = _EmailFriendBubble_Class.FatalError;
                _EmailFriendBubble_Class.ShowBubble();
            } 
         }else { 
            alert ("Sorry this email cannot be sent.");
         }
    
    }

    /**
     * This method helps the confirm page display the "friend's" emails
     * @param {string} emailList value from the email textbox (could be a comma separated list)
     */    
    this.GetEmailList=function(emailList) {
        var sb = new StringBuilder();
        
        if (emailList.indexOf(',') == -1){
            sb.append(emailList);
        }else{
            var elist = emailList.split(",");
            for ( i =0;i<=elist.length-1;i++ ) {
               sb.append(elist[i]);
               sb.append("<br/>");
            }
        }
        return sb.toString();
    }
}

/*
 * It registers the EmailFriendBubble_Class using registerClass method of MS AJAX Library
 */
if (IsTypeDefined) { Core.EmailFriendBubble_Class.registerClass('Core.EmailFriendBubble_Class'); }

/**
 * It instantiates an object of type _EmailFriendBubble_Class
 */
var _EmailFriendBubble_Class = new Core.EmailFriendBubble_Class();







/**
 * @class SearchError_Bubble
 * This class is responsible for displaying search error in the ajax bubbles
 */
Core.SearchError_Class=function() {
    this.Bubble_DivID = "SearchError_Bubble";
    this._MapPopUp;
	
	/**
     * Shows the search error in bubble if one is there, otherwise sends to next page
     */    
    this.ShowBubbleLostFocus=function(absoluteURL, caller){
        this._MapPopUp = new Core.ModalPopUp(); 
        this._MapPopUp._PopupControlID=this.Bubble_DivID;
        this.SearchKeyword(absoluteURL, caller);		
    }
    
    this.HideMe=function()
    {
            
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._MapPopUp.HideModal();
    }  

    /**
     * Shows the search error in bubble if one is there, otherwise sends to next page
     */    
    this.ShowBubble=function(absoluteURL){
        this._MapPopUp = new Core.ModalPopUp(); 
        this._MapPopUp._PopupControlID=this.Bubble_DivID;
        this.SearchKeyword(absoluteURL, null);
    }
    
    this.HideMe=function()
    {
            
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._MapPopUp.HideModal();
    }    
    
    /**
     * Retrieves map for specific store
     * @param {string} absoluteURL The absoluteURL
     */
    this.SearchKeyword=function(absoluteURL, caller) {
        if(!IsAjaxLoaded()) {return false;}
        try {
            //DoWait();
	        var mf = GetMainFormName();		
	        if (mf==null) return;
	        var searchVal = document.forms[mf].elements["SearchKeywords"].value;
	        
	        // remove " and ' double and single quotes
	        var i;
	        var returnString = "";
	        var filteredValues = "'\"";     // Characters stripped out
	        
            for (i = 0; i < searchVal.length; i++) {
                var c = searchVal.charAt(i);
                if (filteredValues.indexOf(c) == -1) 
                    returnString += c;
            }
	        
	        searchVal = returnString.toLowerCase();
	        
	        //alert ("searchVal.toLowerCase() : " + searchVal.toLowerCase());
	        // if keyword is 'search' display error
	        if (searchVal.toLowerCase() == "search" || searchVal.toLowerCase() == "")
	        {
	            _SearchError_Class._MapPopUp.ShowModal();
				if (caller != null && caller != 'undefined')
				{
					caller.blur();
				}
	            
	        }
	        else
	        {
	            if (typeof(absoluteURL)!='undefined') {
	                //document.forms[mf].action=absoluteURL + "search/search.aspx?Search=" + searchVal;
	                document.location.href = absoluteURL + "search/search.aspx?Search=" + searchVal;
	            }
	            else {
	                 //document.forms[mf].action="search/search.aspx?Search=" + searchVal;
	                 document.location.href = "search/search.aspx?Search=" + searchVal;   
	            }
	         }   
	        
	        
	        
	        /*else
	        {
	            document.forms[mf].submit();
	        }*/
            
        }
        catch (e) {
            DoDefault();
            window.status = e.message;
        }
        return false;
    }
    
}
 /**
 * It registers the  SearchError_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.SearchError_Class.registerClass('Core.SearchError_Class'); }

 /**
 * It instantiates an object of type Core.SearchError_Class
 */
var _SearchError_Class=new Core.SearchError_Class();


/**
 * @class PromoCode_Bubble
 * This class is responsible for displaying promo error in the ajax bubbles
 */
Core.PromoCode_Class=function() {
    this.Bubble_DivID = "PromoCode_Bubble";
    this._PromoPopUp;

    /**
     * Shows the promo error in bubble if user entered a promo but did not apply it
     */    
    this.ShowBubble=function(absoluteURL){
        this._PromoPopUp = new Core.ModalPopUp(); 
        this._PromoPopUp._PopupControlID=this.Bubble_DivID;
        this.PromoCheck(absoluteURL);
    }
    
    this.HideMe=function()
    {
            
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._PromoPopUp.HideModal();
    }    
    
    /**
     * Display Promo Error bubble if user entered a promo but did not hit apply button
     * Apply button check is done by checking if either KeyCodeSuccessMessage or ErrorSpan have values
     * @param {string} absoluteURL The absoluteURL
     */
    this.PromoCheck=function(absoluteURL) {
        if(!IsAjaxLoaded()) {return false;}
        try {
            //DoWait();
          
          	var mf = GetMainFormName();
	        var promoVal =$get("ctl00_ctl00_brandlayout0_ctl00_mainbody0_ctl00_ctl05_ctl00_ctl00_KeyCodeSuccessMessage");
	        var x = GetElement("KeyCodeSuccessMessage", mf);       
	        var ErrorVal =$get("ErrorSpan");
	        var promoBox = GetElement("keycode", mf);
	        var promostring = promoBox.value.trim();
            // if keycode is entered and apply promo button not pressed display box
            if (promostring.length > 0 && ErrorVal.innerHTML.length == 0 && promoVal.innerHTML.length == 0)
            {
                _PromoCode_Class._PromoPopUp.ShowModal();
            }
            else
            {
                window.location = absoluteURL;
            }
            
        }
        catch (e) {
            DoDefault();
            window.status = e.message;
        }
        return false;
    }
    
}
 /**
 * It registers the  PromoCode_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.PromoCode_Class.registerClass('Core.PromoCode_Class'); }

 /**
 * It instantiates an object of type Core.PromoCode_Class
 */
var _PromoCode_Class=new Core.PromoCode_Class();



/**
 * @class PopUp_Bubble
 * This class is responsible for displaying popups in the ajax bubbles
 */
Core.PopUp_Class=function() {
    this.Bubble_DivID = "PopUp_Bubble";
    this._DisplayPopUp;

    /**
     * Shows the popup bubble
     */    
    this.ShowBubble=function(){
        this._DisplayPopUp = new Core.ModalPopUp(); 
        this._DisplayPopUp._PopupControlID=this.Bubble_DivID;
        this._DisplayPopUp.ShowModal();
    }
    
    this.HideMe=function()
    {
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._DisplayPopUp.HideModal();
    }        
}
 /**
 * It registers the  PopUp_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.PopUp_Class.registerClass('Core.PopUp_Class'); }

 /**
 * It instantiates an object of type Core.PopUp_Class
 */
var _PopUp_Class=new Core.PopUp_Class();


/**
 * @class PopUpSecond_Class
 * This class is responsible for displaying popups in the ajax bubbles, used it there are to 
 * more than one on a page, if first is already used and need second
 */
Core.PopUpSecond_Class=function() {
    this.Bubble_DivID = "PopUpSecond_Bubble";
    this._DisplayPopUp;

    /**
     * Shows the popup bubble
     */    
    this.ShowBubble=function(){
        this._DisplayPopUp = new Core.ModalPopUp(); 
        this._DisplayPopUp._PopupControlID=this.Bubble_DivID;
        this._DisplayPopUp.ShowModal();
    }
    
    this.HideMe=function()
    {
          if (AJAX_IsIE6()) {
               ToggleStateList('visible');
         }      
        
        this._DisplayPopUp.HideModal();
    }        
}
 /**
 * It registers the  PopUpSecond_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.PopUpSecond_Class.registerClass('Core.PopUpSecond_Class'); }

 /**
 * It instantiates an object of type Core.PopUpSecond_Class
 */
var _PopUpSecond_Class=new Core.PopUpSecond_Class();
