﻿// Set the default Retailer Code
var AJAX_DEFAULT_RTLCODE="LOREAL";
var AJAX_ASSOCIATION="Lost_Found";
var DISCONT_PARENTCAT = "";
var EMAIL_LEFT_POSITION="250";
var EMAIL_TOP_POSITION="160";

var PHONE_LEFT_POSITION="37";
var PHONE_TOP_POSITION="295";


var SHADEBUBBLE_LEFT_POSITION="0";
var SHADEBUBBLE_TOP_POSITION="0";

var SingleLeftShade="";


function modalBeforeOpen() {
  ToggleDropDowns('hidden');
}

//
function modalBeforeClose() {

  ToggleDropDowns('visible');
}

//
function ToggleDropDowns(_visibility) {
       if (AJAX_IsIE6()) {
           GetAllSelects();
           for (var i=0; i < allVisibleSelects.length; i++) {
             allVisibleSelects[i].style.visibility=_visibility;
          }
       }
}

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++;
                }
          }
    }
}
function AJAX_IsIE6() {
  if (navigator.appName=='Microsoft Internet Explorer') {
      if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
         return true;
      }
  }
  return false;

}


/*
 * It Creates a namespace using MS Ajax Libraries "making javascript easier" if TYPE is defined
 */
 if (IsTypeDefined){ Type.registerNamespace("Maybelline");  }

/**
 * @class EmailFriendBubble_Class
 * This class Sends Email Messages to from the site
 * @constructor 
 */
Maybelline.EmailFriendBubble_Class=function() {
    /**
    * The DHTML ID of the main layer of the EmailFriend bubble
    */
    this.ProductEmailTemplate="Product_TellAFriend.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 = "<strong>!&nbsp;</strong>";
    /**
    * The DHTML ID of the General Error Message
    */   
    this.GeneralErrorID = "EmailFriend_GeneralError";
    /**
    * The DHTML ID of the General Error Message
    */   
    this.GeneralError = "<div class='marginTop10 lightRedFont marginTop10 marginBottom20'><strong>Por favor verifica la información señalada.</strong></div>";
    /**
    * The email error message
    */   
    this.EmailError = "<div class='marginTop10 lightRedFont marginTop10 marginBottom20'><strong>&iexcl;La direcci&oacute;n de correo electr&oacute;nico o la contrase&ntilde;a son incorrectas!</strong></div>";
    /**
    * The fatel error message
    */   
    this.FatalError = "<div class='marginTop10 lightRedFont marginTop10 marginBottom20'><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;
    /**    
    * 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) {
        if(this.LeftPosition != "")
            _MaybellineModal_Class.popUpLeftAdj = this.LeftPosition;
        else
            _MaybellineModal_Class.popUpLeftAdj = EMAIL_LEFT_POSITION;
            
         if(this.TopPosition != "")        
            _MaybellineModal_Class.popUpTopAdj = this.TopPosition;
         else
            _MaybellineModal_Class.popUpTopAdj = EMAIL_TOP_POSITION;        
        

        _MaybellineModal_Class._PopupControlID=this.Bubble_DivID;
        _MaybellineModal_Class.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);
        senderEmailListobj.innerHTML = this.GetEmailList(friendEmailobj.value);
        
        if(this.LeftPosition != "")
            _MaybellineModal_Class.popUpLeftAdj = this.LeftPosition;
        else
            _MaybellineModal_Class.popUpLeftAdj = EMAIL_LEFT_POSITION;
            
         if(this.TopPosition != "")        
            _MaybellineModal_Class.popUpTopAdj = this.TopPosition;
         else
            _MaybellineModal_Class.popUpTopAdj = EMAIL_TOP_POSITION; 
            
        _MaybellineModal_Class._PopupControlID=this.BubbleConfirm_DivID;
        _MaybellineModal_Class.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.ValidateField($get(this.Sender_FnameID), this.Sender_FnameErrorID, this.FieldError);
        // Sender Last Name
        var fromLname = this.ValidateField($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){
            var errorsb = new StringBuilder(); 
            if (this.hasErrors)
                errorsb.append(this.GeneralError);
            
            if(this.EmailhasErrors)
                errorsb.append(this.EmailError);
                
            $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
       _WebServiceAPI.EmailAFriend(fromFname, fromLname, fromEmail, fromMsg, toEmail, copyEmail, code, isProduct, validTemplate, 'html', this.OnCompleteRequest);
    }
    
    /**
     * 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 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(",");
            for ( i =0;i<=elist.length-1;i++) {
                this.ValidateEmailField(elist[i],errorID,errorVal);
            }
		}
	}
	
    /**
     * 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"){
                $get(_EmailFriendBubble_Class.Bubble_DivID).style.display="none";
                _EmailFriendBubble_Class.ShowConfirmBubble();
            }else{
                //$get(_EmailFriendBubble_Class.GeneralErrorID).innerHTML = result;
                $get(_EmailFriendBubble_Class.GeneralErrorID).innerHTML = _EmailFriendBubble_Class.FatalError;
            } 
         }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();
    }
}

/**
 * @class ModalPopUp creates a modal pop up "bubble" for Maybelline
 */
Maybelline.ModalPopUp= function () {
    /**
     *  The layer of the whole modal window (object)
     */
    var _backgroundElement=null;
  
    /**
     * to help position the left popup if it needs to be off center
     */
    this.popUpLeftAdj = 0;
    /**
     * to help position the top popup if it needs to be off center
     */
    this.popUpTopAdj = 0;

    /**
      * Show Modal
      */
    this.ShowModal=function () {
    
        /**
         *  _InitializeForeground
         */
        this._InitializeForeground=function() {
            this._foregroundElement = $get(this._PopupControlID);
            this._foregroundElement.style.display = 'none';
            this._foregroundElement.style.position = 'absolute';
            
            this._parentElement = this._foregroundElement.parentNode;
            this._parentElement.appendChild(this._foregroundElement);
        }
    
        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;
        }

        if (this._foregroundElement!=null) {
            this._foregroundElement.style.left = this.popUpLeftAdj+'px'; 
            this._foregroundElement.style.top = this.popUpTopAdj+'px';          
            this._foregroundElement.style.display = 'block';
            
            //this._dragHandleElement = $get(this._PopupControlID);
            //this._dragBehavior = $create(Core.FloatingBehavior, {"handle" : this._dragHandleElement}, null, null, this._foregroundElement);
            
        }
        IS_MODELPOPUP_VISIBLE=true;
        if (this.beforeOpen!=null) {
             eval(this.beforeOpen + "();");
        
        }
     }
}

Maybelline.ModalPopUp.prototype = new Core.ModalPopUp;
/*
 * It registers the WebServiceAPI_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.ModalPopUp.registerClass('Maybelline.ModalPopUp'); }

Maybelline.VariantBubble_Class=function () {
    this.VariantSKUID = "VariantBubble_VariantSKU";
    this.VariantFinishID = "VariantBubble_VariantFinish";
    this.VariantSkinToneID = "VariantBubble_VariantSkinTone";
    this.VariantBubble_ShadeColorID = "VariantBubble_ShadeColor";
    this.productImgsID = "productImgs";
    this.VariantBubble_DivID2 = "VariantBubble_Div2";
    this.SendToPhoneBtnID = "SendToPhoneBtn";
    this.IconPrefix = VARIANT_BUBBLE_ICON_PREFIX;
    this.IconSuffix = VARIANT_BUBBLE_ICON_SUFFIX;
    this.VariantBubble_ImageSuffix_LargeMultipanShade = VARIANT_LARGEMULTIPAN_SHADE_IMAGE_SUFFIX;
    this.VariantBubble_ImageSuffix_SmallMultipanShade = VARIANT_SMALLMULTIPAN_SHADE_IMAGE_SUFFIX;
    this.FinishText = "FINISH<br/>";
    this.ProductCode = "";
    this.ProductName = "";
    this.VariantCode = "";
    this.VariantName = "";
    this.SingleShadeMediumImageLayer="SingleShadeMediumImageLayer";///
    this.SingleShadeMediumImage="SingleShadeMediumImage";///
    this.HasOneSingleLeftShadeImage=false;///
    
    this.DoSingleLeftImageBottom=function(_code)  {
       var _obj1=$get(this.SingleShadeMediumImageLayer);
       if (_obj1!=null) {  _obj1.style.display=""; }
       var _objimg1=$get(this.SingleShadeMediumImage);
       //var _src=this.VariantBubble_ImagePrefix_LargeShade + _Variant.Result.ParentProductCode + this.VariantBubble_ImageSuffix_LargeShade; 
       var _src=this.VariantBubble_ImagePrefix_LargeShade +_code + "_m.jpg"; 
       //alert(_Variant.Result.SKU);
       if (_objimg1!=null) { _objimg1.src=_src;}
    }


     /**
     * This Method populates the variant bubble
     * @param {object} result The data that comes into a JASON format from a web service
     */
    this.PopulateData=function(result)  {
        var _Variant = new Core.Product_Class();
        _Variant.PopulateData(result);

        var prodnameobj=$get(this.VariantBubble_ProductNameID);
        var shadenameobj=$get(this.VariantBubble_VariantNameID);
        var shadeSKUobj=$get(this.VariantSKUID);
        var shadeColorobj=$get(this.VariantBubble_ShadeColorID);
        var shadeImgobj=$get(this.VariantBubble_ImageID);
        var finishObj=$get(this.VariantFinishID);
        var skinToneObj=$get(this.VariantSkinToneID);
        var sendToPhoneObj = $get(this.SendToPhoneBtnID);
        
        if(shadeSKUobj!=null) {
            shadeSKUobj.innerHTML=_Variant.Result.Description;
        }
        if(prodnameobj!=null) {
            prodnameobj.innerHTML=_Variant.Result.ParentName;
        }
        if(shadenameobj!=null) {
            shadenameobj.innerHTML=_Variant.Result.Name;
        }
         if (SingleLeftShade=="1") { this.HasOneSingleLeftShadeImage=true;}


        // if the Variant is part of a multipan then we have to switch the layout
               if (_Variant.ShadeColor.indexOf(",") > 0){
          
           if (this.HasOneSingleLeftShadeImage==true) {
                    if(shadeColorobj != null){  shadeColorobj.style.display="none";  }
                    //handle here the image
                    this.DoSingleLeftImageBottom(_Variant.Result.SKU);
                 
    
           }
           else {
                 if(shadeColorobj != null){	//existed
                     shadeColorobj.innerHTML = showMultipan(_Variant.ShadeColor,_Variant.Result.ParentProductCode)
                     correctPNG();
	             }
	      }

        }else{
                if (this.HasOneSingleLeftShadeImage==true) {
                        if(shadeColorobj != null){  shadeColorobj.style.display="none";  }
                        //handle here the image
                        this.DoSingleLeftImageBottom(_Variant.Result.SKU);
                }
                else {
                            if (shadeImgobj!=null) {
                           
                                 shadeColorobj.innerHTML = "<img src='" + this.VariantBubble_ImagePrefix_LargeShade + _Variant.Result.ParentProductCode + this.VariantBubble_ImageSuffix_LargeShade + "' style='width:99px;height:182px'>"
                                 //shadeImgobj.src=this.VariantBubble_ImagePrefix_LargeShade + _Variant.Result.ParentProductCode + this.VariantBubble_ImageSuffix_LargeShade;
                                 correctPNG();
                             }
                            if(shadeColorobj != null){
                                shadeColorobj.style.backgroundColor = _Variant.ShadeColor;
                            }  
                }          
            
        }

        
        if(finishObj!=null && _Variant.Finish != "") {
            finishObj.innerHTML= this.FinishText + _Variant.Finish;
        }else{
            finishObj.innerHTML="";
        }
        if(skinToneObj!=null) {
            skinToneObj.src= this.IconPrefix + _Variant.SkinTone + this.IconSuffix;
        }
        if(sendToPhoneObj!=null){
            sendToPhoneObj.onclick = function(){_SendPhoneBubble_Class.ShowBubble(_Variant.Result.SKU, _Variant.Result.Description,_Variant.Result.Name,_Variant.Result.ParentName)};
        }
        
        this.ProductCode = _Variant.Result.ParentProductCode;
        this.ProductName = _Variant.Result.ParentName;
        this.VariantCode = _Variant.Result.Description;
        this.VariantName = _Variant.Result.Name
         
        toggle(this.productImgsID, 'off');
        toggle(this.VariantBubble_DivID2, 'off');   
        toggle(this.VariantBubble_DivID, 'on');        
        //_MaybellineModal_Class._PopupControlID=this.VariantBubble_DivID;
        //_MaybellineModal_Class.popUpLeftAdj=SHADEBUBBLE_LEFT_POSITION;
        //_MaybellineModal_Class.popUpTopAdj=SHADEBUBBLE_TOP_POSITION;
        //_MaybellineModal_Class.ShowModal();
    }
}
Maybelline.VariantBubble_Class.prototype = new Core.VariantBubble_Class;
/*
 * It registers the VariantBubble_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.VariantBubble_Class.registerClass('Maybelline.VariantBubble_Class'); }


 Maybelline.ProductManager_Class=function() {
 
 
     this.DoVariantBranching=function(_Variant) {
    _Maybelline_VariantBubble_Class.Code=_Variant.ProductCode;
    _Maybelline_VariantBubble_Class.PopulateData(_Variant.Result);
    }
 
 }
 Maybelline.ProductManager_Class.prototype = new Core.ProductManager_Class;
/*
 * It registers the VariantBubble_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.ProductManager_Class.registerClass('Maybelline.ProductManager_Class'); }
 
 
 
 Maybelline.QuickShop_Class=function (){

    this.ShowBubble=function(code, isVariant, hasShades) {
        this.Code = code;
        this.IsVariant = isVariant;
        this.hasShades = hasShades;
        if (this.IsVariant) {
            _ProductManager.LoadMakeupVariant(this.Code)
        }else {
            if(this.hasShades) {
              _ProductManager.LoadMakeupProduct(this.Code);
            }else {
              _ProductManager.LoadSkinCareProduct(this.Code);
            }
        }
    }
}

 if (IsTypeDefined) { Maybelline.QuickShop_Class.registerClass('Maybelline.QuickShop_Class'); }
 
 Maybelline.DiscontinuedBubble_Class=function() {
 
     this.PrdCode = "";
    this.PreSelectProductDD = false;
     /**
     * The DHTML ID product drop down search bubble
     */    
    this.Discontinued_ProductsDropDownID="Discontinued_ProductsDropDown";
 
     this.FilterProductsByCategory=function(CategoryCode,preSelectProductDD,prdCode)  {
        if(CategoryCode != "#" && CategoryCode != ""){
            // load the products drop down
            _DiscontinuedBubble_Class.PrdCode = prdCode;
            _DiscontinuedBubble_Class.PreSelectProductDD = preSelectProductDD;
            _WebServiceAPI.GetCategoryProductsByOnlineStatus(AJAX_DEFAULT_RTLCODE, CategoryCode, -1, true, this.SetProductDropDown);
            
        }
    }
 
      /**
     * 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 onchange='javascript:_DiscontinuedProductManager.FilterVariantsByProduct(this.options[this.selectedIndex].value,this.options[this.selectedIndex].text);'>");
                sb.append("<option value='#'>- Select -</option>");
                for(i=0; i<Products.length; i++)  {     
                    sb.append("<option value='");
                    sb.append(Products[i].SKU);
                    if (_DiscontinuedBubble_Class.PreSelectProductDD && Products[i].SKU == _DiscontinuedBubble_Class.PrdCode) {
                        sb.append("' selected='true");
                    }
                    sb.append("'>");
                    sb.append(Products[i].Name);
                    sb.append("</option>");
                }
                sb.append("</select>");
                ddobj.innerHTML = sb.toString();
            }
        }
    }
    
    
 }
 
 /**
 * Inherit from the ProductManager_Class
 */
Maybelline.DiscontinuedBubble_Class.prototype = new Core.ProductBubble_Class;

 /**
 * It registers the  DiscontinuedProductManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.DiscontinuedBubble_Class.registerClass('Maybelline.DiscontinuedBubble_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 
 */

 Maybelline.DiscontinuedProductManager_Class=function() {
 
    this.Discontinued_ImgID = "Discontinued_Img";
    this.Discontinued_NameID = "Discontinued_Name";
    this.Discontinued_TeaserID = "Discontinued_Teaser";
    this.Associated_ImgID = "Associated_Img";
    this.Associated_NameID = "Associated_Name";
    this.Associated_TeaserID = "Associated_Teaser";
    this.Discontinued_ShadesID = "Discontinued_Shades";
    this.FoundSectionID = "FoundSection";
   
    /**
     * This Method loads the variants using the passed in product code
     */        
    this.FilterVariantsByProduct=function(ProductCode, ProductName){
        DoWait();
        if(ProductCode != "#" && ProductCode != ""){
            // load the variants drop down
            _WebServiceAPI.GetVariantInformationIgnoreFlags(AJAX_DEFAULT_RTLCODE, ProductCode, true, this.OnRequestComplete);
            
            // set the product image
           // $get(this.Discontinued_ImgID).src = PRODUCT_THUMBNAIL_IMAGE_PREFIX + ProductCode + PRODUCT_THUMBNAIL_IMAGE_SUFFIX;
            $get(this.Discontinued_NameID).innerHTML = ProductName;
            
        }else{
            DoDefault();
        }
    }
    
    /**
     * 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 dis_shadeObj = $get(_DiscontinuedProductManager.Discontinued_ShadesID);
            if (dis_shadeObj != null){
                var commaList = _DiscontinuedProductManager.BuildShadeTable(result,dis_shadeObj);
                _WebServiceAPI.GetProductAssociationsByProductCodes(AJAX_DEFAULT_RTLCODE, commaList, AJAX_ASSOCIATION, true, _DiscontinuedProductManager.OnAssociationRequestComplete);
            }
            $get(_DiscontinuedProductManager.FoundSectionID).style.display = "block";
        }
    }
    
     /**
     * This method is called to build the table for the shades
     * @param {Product} group of variants
     */
    this.BuildShadeTable= function (result, divObj) {
            var sb = new StringBuilder();
            var commaList = "";
            for(i=0;i<result.length;i++){
                var _Product=new Core.Product_Class();
                _Product.PopulateData(result[i]);
                if(_Product.Result.Online == '-1'){
                    sb.append("<div><img src='/images/bg/lostandfound_table_vert_rules.gif'></div>");
                    sb.append("<div class='lostFoundProductCell borderZero'>");
                    sb.append("<span>" + _Product.Result.Name + " " + _Product.Result.Description + "</span>")
                    sb.append("<div class='lostFoundSwatch floatLeft' style='background-color:#FFFFFF'></div>");
                    sb.append("</div>");
                    sb.append("<div class='lostFoundProductCell borderZero lostFoundTableDivGutter' id='shade_" + _Product.Result.SKU + "'>");
				    sb.append("<div class='lostFoundSwatch floatLeft' style='background-color:#FFFFFF'></div>");
				    sb.append("<span>Sorry no match</span>");
			        sb.append("</div>");
			        sb.append("<div class='clearBoth'></div>");
                               
                    commaList += _Product.Result.SKU;
                    if (i != result.length - 1)
                        commaList += ",";
                }
            }
            divObj.innerHTML = sb.toString();
            return commaList;
    }
    
    this.OnAssociationRequestComplete=function(result){    
        if(result != null && result != ""){   
            for(i=0;i<result.length;i++){
                var sb = new StringBuilder();
                var _Product=new Core.Product_Class();
                _Product.PopulateData(result[i]);
                var replaceDiv = $get("shade_" + _Product.Discont_Association);
                if (replaceDiv){
				    sb.append("<div class='lostFoundSwatch floatLeft' style='background-color:" + _Product.ShadeColor + "'><a href='" + _Product.Result.CategoryHomePage.replace(".aspx","/") + _Product.Variant_QSName + "' class='swatchLink'><img src='/images/spacer.gif' width='27' height='23' border='0'></a></div>");
				    sb.append("<span><a href='" + _Product.Result.CategoryHomePage.replace(".aspx","/") + _Product.Variant_QSName + "'>" + _Product.Result.Name + " " + _Product.Result.Description + "</a></span>");
				    sb.append("<div class='mcaRecommend'>");
				    if (_Product.SkinTone != "")
				        sb.append("<div class='marginTop10 marginBottom10'>Ideal para piel " + _Product.SkinTone + "</div>");
				        sb.append("<img src='/images/buttons/send_to_phone.gif' border='0' onclick='_SendPhoneBubble_Class.TopPosition=findPosY(this)-300;_SendPhoneBubble_Class.ShowBubble(\"" + _Product.Result.SKU + "\",\"" + _Product.Result.Description + "\",\"" + _Product.Result.Name + "\",\"" + _Product.Result.ParentName + "\");' style='cursor:pointer;'><br>");
				    sb.append("</div>");

				    replaceDiv.innerHTML = sb.toString();
			    }
            }
            $get(_DiscontinuedProductManager.Associated_ImgID).src = PRODUCT_THUMBNAIL_IMAGE_PREFIX + _Product.Result.ParentProductCode + PRODUCT_THUMBNAIL_IMAGE_SUFFIX;
            $get(_DiscontinuedProductManager.Associated_NameID).innerHTML = _Product.Result.ParentName;
            $get(_DiscontinuedProductManager.Associated_NameID).href = _Product.Result.Homepage + "?prdcode=" + _Product.Result.ParentProductCode + "&CategoryPath=" + _Product.Result.CategoryPath;
            $get(_DiscontinuedProductManager.Associated_TeaserID).innerHTML = _Product.ParentProductTeaser;
        }else{
            // no matches for the results
            $get(_DiscontinuedProductManager.Associated_ImgID).src = "/images/spacer.gif";
            $get(_DiscontinuedProductManager.Associated_ImgID).width = "141";
            $get(_DiscontinuedProductManager.Associated_ImgID).height = "116";
            $get(_DiscontinuedProductManager.Associated_NameID).innerHTML = "";
            //$get(_DiscontinuedProductManager.Associated_NameID).href = _Product.Result.Homepage + "?prdcode=" + _Product.Result.ParentProductCode + "&CategoryPath=" + _Product.Result.CategoryPath;
            $get(_DiscontinuedProductManager.Associated_TeaserID).innerHTML = "Sorry there are no replacement products";
            
            
            
            
        }
        DoDefault();
    }
 }
 /**
 * Inherit from the ProductManager_Class
 */
Maybelline.DiscontinuedProductManager_Class.prototype = new Core.ProductManager_Class;

 /**
 * It registers the  DiscontinuedProductManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.DiscontinuedProductManager_Class.registerClass('Maybelline.DiscontinuedProductManager_Class'); }


/**
 * @class SendPhoneBubble_Class
 * This class Sends SMS Messages to from the site
 * @constructor 
 */
Maybelline.SendPhoneBubble_Class=function() {
    /**
     * default templates
     */  
    this.EmailTemplate_Variant = "SendToPhoneTemplate_Variant.xml";
    this.EmailTemplate_Product = "SendToPhoneTemplate_Product.xml";
    /**
    * The DHTML ID of the main layer of the EmailFriend bubble
    */
    this.Bubble_DivID="PhoneFriend_div";
    /**
    * The DHTML ID of the main layer of the EmailFriend bubble confirm
    */    
    this.BubbleConfirm_DivID="PhoneFriendConfirm_div";
    /**
    * The DHTML ID of the message 
    */       
    this.Phone_MessageID="Phone_Message";
    /**
    * The DHTML ID the phone number  
    */       
    this.PhoneExt_1ID = "PhoneExt_1";
    /**
    * The DHTML ID the phone number 
    */       
    this.PhoneExt_2ID = "PhoneExt_2";
    /**
    * The DHTML ID the phone number  
    */       
    this.PhoneExt_3ID = "PhoneExt_3";
    /**
    * The DHTML ID the phone number suffix  
    */ 
    this.Phone_EmailSuffixID = "Phone_EmailSuffix";
    /**
    * The message sent for variants  
    */ 
    this.PageDisplayMessage_Variant = "Your Maybelline New York Product Info: $$Phone_ProductName$$ in $$Phone_VariantName$$ ($$Phone_VariantSKU$$)";
    /**
    * The message sent for products  
    */
    this.PageDisplayMessage_Product = "Your Maybelline New York Product Info: $$Phone_ProductName$$";
    /**
    * The error message to designate incorrect fields
    */   
    this.FieldError = "<strong>!&nbsp;&nbsp;</strong>";    
    /**
    * The DHTML ID of the General Error Message
    */   
    this.GeneralErrorID = "Phone_GeneralError";
    /**
    * The DHTML ID of the General Error Message
    */      
    this.GeneralError = "<div class='lightRedFont'><strong>Por favor verifica la información señalada.</strong></div>";
    /**
    * The fatel error message
    */   
    this.FatalError = "<div class='lightRedFont'><strong>SORRY THIS EMAIL CANNOT BE SENT!</strong></div>"; 
    /**
    * The Confirm message container id
    */   
    this.SentMessageID = "phone_ConfirmMessage";
    /**
    * The Confirm message 
    */
    this.SentMessage = "<div class='lightRedFont'><strong>&iexcl;Tu mensaje de texto ya est&aacute; en camino! <br/>Tu mensaje se proces&oacute; con &eacute;xito.</strong></div>";        
    /**
     * When the Email a friend bubble is shown, 
     */
    this.Phone_PhoneErrorID="Phone_PhoneError";
    /**
     * When the Email a friend bubble is shown, 
     */    
    this.Phone_ProviderErrorID="Phone_ProviderError";
    /**
     * product code for hte function to use
     */  
    this.ProductCode = "";
    /**
     * variant code for hte function to use
     */  
    this.VariantCode = "";
    /**
     * default left position
     */  
    this.LeftPosition = PHONE_LEFT_POSITION;
    /**
     * default top position
     */  
    this.TopPosition = PHONE_TOP_POSITION;
    /**
     * DHTML id of the checkbox used to save phone to profile.
     */ 
    this.Phone_SaveProfileID = "Phone_SaveProfile";
    
 
    /**
     * Show the bubble for the Send to Phone
     */    
    this.ShowBubble=function(SKU, varCode, varName, prodName) {

        _MaybellineModal_Class.Hide();
        
        var message = $get(this.Phone_MessageID);
        
        var msgText = "";  
        // if the in coming item is a Variant   
        if (varCode != ""){
            msgText = this.PageDisplayMessage_Variant; 
            msgText = msgText.replace("$$Phone_ProductName$$",prodName);
            msgText = msgText.replace("$$Phone_VariantName$$",varName);
           msgText = msgText.replace("$$Phone_VariantSKU$$",varCode);
        }else{
            msgText = this.PageDisplayMessage_Product;
            msgText = msgText.replace("$$Phone_ProductName$$",prodName);
        }       
        this.ProductCode = SKU;
        this.VariantCode = varCode;
        
        message.innerHTML = msgText;
              
        _MaybellineModal_Class.popUpLeftAdj = this.LeftPosition;
        _MaybellineModal_Class.popUpTopAdj = this.TopPosition;

        _MaybellineModal_Class._PopupControlID=this.Bubble_DivID;
        _MaybellineModal_Class.ShowModal();
    }
    
        /**
     * Validates the email fields and sends the email 
     */
    this.SendEmail=function() {
        this.hasErrors=false;
        var fromEmail = FROMEMAIL;
             
        // Message
        var fromMsg = "";
        // check if the messsage box control exits
        if($get(this.Phone_MessageID) != null)
            fromMsg = $get(this.Phone_MessageID).innerHTML;
            
        var toEmail = this.BuildSMSAddress();
        
        if(this.hasErrors){
            $get(this.GeneralErrorID).innerHTML = this.GeneralError;
            return false;
        }else{
        
            if(this.VariantCode != ""){
                emailTemp = this.EmailTemplate_Variant;
            }else{
                emailTemp = this.EmailTemplate_Product;
            }
        
            $get(this.GeneralErrorID).innerHTML = '<br/>';
            // goes into the WS Call
            _WebServiceAPI.EmailAFriend('-', '-', fromEmail, '', toEmail, false, this.ProductCode, true, emailTemp, 'text', this.OnCompleteRequest);
             
            if ($get(this.Phone_SaveProfileID).checked)
                _WebServiceAPI.UpdatePhoneInformation("phoneExt", CurrentCustomerID, $get(this.PhoneExt_1ID).value, $get(this.PhoneExt_2ID).value, $get(this.PhoneExt_3ID).value, "-", this.SaveProfileOnCompleteRequest);
        }
    }
    
    
    /**
     * 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){
         if (result!=null) {
            if(result == "true"){
                $get(_SendPhoneBubble_Class.Bubble_DivID).style.display="none";
                _SendPhoneBubble_Class.ShowConfirmBubble();
            }else{
                $get(_SendPhoneBubble_Class.GeneralErrorID).innerHTML = result;
            } 
         }else { 
            alert ("Sorry this email cannot be sent.");
         }
    }
    
        /**
     * Shell Results function - Save to profile doesn't do anything after saving
     * This method is called after a web Service Call is Completed
     * @param {string} result The result object returned from the web service
     */
    this.SaveProfileOnCompleteRequest=function(result){
         if (result!=null) {
            //if(result == "true")
         }else { 
            alert ("Sorry this email cannot be sent.");
         }
    }
    this.ShowConfirmBubble=function() {
    
        if(this.LeftPosition != "")
            _MaybellineModal_Class.popUpLeftAdj = this.LeftPosition;;

            
        if(this.TopPosition != "")        
            _MaybellineModal_Class.popUpTopAdj = this.TopPosition;
            
       _MaybellineModal_Class._PopupControlID=this.BubbleConfirm_DivID;
       $get(_SendPhoneBubble_Class.SentMessageID).innerHTML = _SendPhoneBubble_Class.SentMessage;
       _MaybellineModal_Class.ShowModal();
    }
    
    this.BuildSMSAddress=function(){
        var phone1 = $get(this.PhoneExt_1ID).value;
        var phone2 = $get(this.PhoneExt_2ID).value;
        var phone3 = $get(this.PhoneExt_3ID).value;
        
        if((phone1.length != 3) || (phone2.length != 3) || (phone3.length != 4) ||
        (isNaN(phone1)) || (isNaN(phone2)) || (isNaN(phone3))){
            $get(this.Phone_PhoneErrorID).innerHTML = this.FieldError;
            this.hasErrors=true;
        }else{
            $get(this.Phone_PhoneErrorID).innerHTML = '';
        }
        var suffix = $get(this.Phone_EmailSuffixID);
        if(suffix.options[suffix.selectedIndex].value == "#"){
            $get(this.Phone_ProviderErrorID).innerHTML = this.FieldError;
            this.hasErrors=true;    
        }else{
            $get(this.Phone_ProviderErrorID).innerHTML = '';
        }

        return phone1 + phone2 + phone3 + "@" + suffix.options[suffix.selectedIndex].value;
    
    }
}
 /**
 * Inherit from the Maybelline.EmailFriendBubble_Class
 */
Maybelline.SendPhoneBubble_Class.prototype = new Maybelline.EmailFriendBubble_Class;

 /**
 * It registers the  DiscontinuedProductManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Maybelline.SendPhoneBubble_Class.registerClass('Maybelline.SendPhoneBubble_Class'); }

/**
 * @class Event_Bubble
 * This class is responsible for displaying event search 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;
      /**
     * The DHTML ID of the Top HTML Section
     */
    this.VideoBubble_TopHTMLID = "TopHTML";    

    /**
     * Shows the Sign in bubble
     */    
    this.ShowBubble=function(topCode, topType){
        $get(this.VideoBubble_TopHTMLID).innerHTML = "topic is " + topCode + " code is " + topType;
        this.GetVideoTopicInformation(topCode, topType, displayVideo);
        this._VideoPopUp = new Core.ModalPopUp(); 
        this._VideoPopUp._PopupControlID=this.Bubble_DivID;
        this._VideoPopUp.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.GetVideoTopicInformation=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 displayVideo(result)
    {
         DoDefault();     
         if (result!=null) {
            alert(result);
            $get(_VideoBubble_Class.VideoBubble_TopHTMLID).innerHTML = result.Name;

            _VideoBubble_Class.VideoPath = '/flash/videos/' + result.TopicCode + '.swf';
            //_VideoBubble_Class.VideoPath = '/flash/videos/hypnose.swf';
            
            alert(_VideoBubble_Class.VideoPath);
            
            _VideoBubble_Class.CreateFlashControl("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
                "video", 
                _VideoBubble_Class.VideoWidth, /*width*/ 
                _VideoBubble_Class.VideoHeight, /*height*/
                _VideoBubble_Class.VideoPath,
                "",
                "true");

            var _Properties=result.Properties;
            alert(_Properties.length);
            for(var j=0; j<_Properties.length; j++) 
            {
                alert(_Properties[j].Name + ": " + _Properties[j].Value);
            }

         }
         else 
         { 
            alert ("No results for this event.");
         }  
    }        

    this.CreateFlashControl=function(CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
    {
        var d = $get(this.FlashDivID);
        //var d = $get('testtext');
        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;
        //d.value = 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 ShadeSelectHelperBubble_Class
 * This class shows a Shade select image in a popup
 * @constructor 
 */
Maybelline.ShadeSelectHelperBubble_Class=function() {
    
    /**
    * The DHTML ID of the main layer of the Shade selector bubble
    */
    this.Bubble_DivID="ShadeSelector_div";
    
    this.LeftPosition = "200";
    this.TopPosition = "200";
    
     /**
     * When the Email a friend bubble is shown, 
     */
    this.ShowBubble=function() {
        
         _MaybellineModal_Class.popUpLeftAdj = this.LeftPosition;
         _MaybellineModal_Class.popUpTopAdj = this.TopPosition;
        
        _MaybellineModal_Class._PopupControlID=this.Bubble_DivID;
        _MaybellineModal_Class.ShowModal();
    }
}

/**
 * It instantiates an object of type Maybelline.ShadeSelectHelperBubble_Class
 */
var _ShadeSelectHelperBubble_Class=new Maybelline.ShadeSelectHelperBubble_Class();
