﻿// Set the default Retailer Code
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";

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.ModelTopicEmailTemplate="ModelTopic_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>PLEASE FILL ALL THE REQURED FIELDS!</strong></div>";
    /**
    * The email error message
    */   
    this.EmailError = "<div class='marginTop10 lightRedFont marginTop10 marginBottom20'><strong>PLEASE ENTER A VALID EMAIL ADDRESS!</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";  
    /**    
    * The DHTML ID of the Bubble Header
    */
    this.EmailFriend_HeaderID="EmailFriend_Header";
    /**    
    * The DHTML ID of the Bubble Header for the confirm bubble
    */    
    this.EmailFriend_HeaderConfirmID = "EmailFriend_HeaderConfirm";
    /**    
    * The DHTML ID of the Bubble Sub Header
    */
    this.EmailFriend_SubHeaderID="EmailFriend_SubHeader"; 
    /**    
    * The value of the Header
    */    
    this.EmailFriend_Header="";
    /**    
    * The value of the Sub Header
    */        
    this.EmailFriend_SubHeader="";
    /**    
    * 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 = "";
    /**    
    * Flag denoting Model email
    */
    this.IsModelPage=false;    
    /**
     * When the Email a friend bubble is shown, 
     */
    this.ShowBubble=function(which) {
        
        // setting the subject line and teaser from the passed in values
        var header = $get(this.EmailFriend_HeaderID);
        var subHeader = $get(this.EmailFriend_SubHeaderID);    
        
        if (header != null){
            if (this.EmailFriend_Header != ""){
                header.innerHTML = this.EmailFriend_Header;
            }else{
                header.innerHTML = "";
            }
        }

        if (subHeader != null){
            if (this.EmailFriend_SubHeaderID != ""){
                subHeader.innerHTML = this.EmailFriend_SubHeader;
            }else{
                subHeader.innerHTML = "";
            }
        }
        
        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);
        
        // setting the subject line and teaser from the passed in values
        var header = $get(this.EmailFriend_HeaderConfirmID);
        if (header != null){
            if (this.EmailFriend_Header != ""){
                header.innerHTML = this.EmailFriend_Header;
            }else{
                header.innerHTML = "";
            }
        }
        
        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;
        }

        if (this.IsModelPage)
        {
            validTemplate = this.ModelTopicEmailTemplate; 
        }

       // 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)
     */
    this._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;
    
    this.ShowLoading = 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';
        
        if(this.ShowLoading == true){
            document.body.appendChild(this._foregroundElement);
        }else{
            this._parentElement = this._foregroundElement.parentNode;
            this._parentElement.appendChild(this._foregroundElement);            
        }
    }
        
    /**
      * Show Modal
      */
    this.ShowModal=function () {
        
        if(this.ShowLoading == true){
            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;
        }
        if(this.ShowLoading == true){
            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';
        }
        
        if (this._foregroundElement!=null) {
            this._foregroundElement.style.left = this.popUpLeftAdj+'px'; 
            this._foregroundElement.style.top = this.popUpTopAdj+'px';          
            this._foregroundElement.style.display = 'block';
        }
        IS_MODELPOPUP_VISIBLE=true;
        if (this.beforeOpen!=null) {
             eval(this.beforeOpen + "();");
        
        }
     }
         /**
     * Hide
     */
    this.Hide=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 (this.beforeClose!=null) {
             eval(this.beforeClose + "();");
        
        }
    }
}

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 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);
        var addToFavObj = $get('AddToFavBtn');
        
        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 the Variant is part of a multipan then we have to switch the layout
        if (_Variant.ShadeColor.indexOf(",") > 0){
            if(shadeColorobj != null){	
                shadeColorobj.innerHTML = showMultipan(_Variant.ShadeColor,_Variant.Result.ParentProductCode)
                correctPNG();
	        }

        }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)};
        }
        if(addToFavObj!=null){
            addToFavObj.style.display = 'none';
            var bolFavAlrdy = false;
            for (var i in arrFavProds) {
                if(arrFavProds[i]==_Variant.Result.SKU){
                    bolFavAlrdy = true;
                }
            }
            if(! bolFavAlrdy){
                addToFavObj.style.display = 'block';
            }
        }
        
        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');
    }
}
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.ConfirmBubbleID="ProductConfirmFavorite_Bubble";
 
    this.DoVariantBranching=function(_Variant) {
        _Maybelline_VariantBubble_Class.Code=_Variant.ProductCode;
        _Maybelline_VariantBubble_Class.PopulateData(_Variant.Result);
    }
 
     /**
     * AddProductToFavoritesOnComplete
     * @param {object} result that comes from web service
     */
     this.AddProductToFavoritesOnComplete=function(result) {
        if (result!=null) {
            if(result==true) {
                // use the bubble
                _FavePopUp._PopupControlID=_ProductManager.ConfirmBubbleID;                   
                _FavePopUp.ShowModal();
            }else {
                alert('Your request failed to complete. Please try again.');
            }
        }
    }
    
    // GDH 4-20-2007 changed to use the CORE values - they differ from the product types
     this.ConvertTypeToInteger=function(value) {
         switch(value){
            case 'Product':
                return 0;
                break;
            case 'Variant':
                return 0;
                break;
            default:
                return 0;
                break;
        }
     } 
 }
 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.Omniture_Product_Val = "";
    this.Variant_Name = "";
    this.ShowBubble=function(omnitureProductVal,name,code, isVariant, hasShades) {
        
        // We want to make the Swatch button click request to Omniture only once, even though the user has clicked more than one swatched
        // but only one requqest for SwatchColorButton should go to Omniture
        // The function is defined in /js/omniture.js file
        if ( this.Omniture_Product_Val == "" ){
            tagSwatchColorButtonOnClickEvent(omnitureProductVal,name);
        }
        this.Omniture_Product_Val = omnitureProductVal ;
        this.Variant_Name = name;
        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);
            }
        }
    }
}

 Maybelline.QuickShop_Class.prototype = new Core.QuickShop_Class;
 
 if (IsTypeDefined) { Maybelline.QuickShop_Class.registerClass('Maybelline.QuickShop_Class'); }
 
 Maybelline.DiscontinuedBubble_Class=function() {
 
     /**
     * The DHTML ID product drop down search bubble
     */    
    this.Discontinued_ProductsDropDownID="Discontinued_ProductsDropDown";
 
     this.FilterProductsByCategory=function(CategoryCode)  {
        if(CategoryCode != "#" && CategoryCode != ""){
            // load the products drop down
            _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);
                    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'>Best For " + _Product.SkinTone + " Skin</div>");
				    sb.append("<img src='/images/buttons/add_to_makeup_bag.gif' border='0' class='productDetailButton' onclick=\"javascript:_Maybelline_QuickShop_Class.AddToFavorites(true,'" + _Product.Result.SKU + "');\" style='cursor:pointer;'>");
				    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>PLEASE FILL ALL THE REQURED FIELDS!</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>Your text is on its way! <br/>Your message has been successfully sent.</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 = "";
     /**
     * Product Name for Omniture Tag function
     */  
    this.ProductName = "";
    /**
     * variant code for hte function to use
     */  
    this.VariantCode = "";
    /**
     * Variant Name for Omniture Tag function
     */
     this.VariantName = "";
    /**
     * 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;
        
        // call the omniture tag function
        this.ProductName = prodName;
        this.VariantName = varName;
        tagProductSentToPhoneStart(prodName,varName);
              
        _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"){
                tagProductSentToPhoneEnd(_SendPhoneBubble_Class.ProductName,_SendPhoneBubble_Class.VariantName);
                $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 = "400";
    this.VideoWidth = "550";
    this._VideoPopUp;
    this.VideoTopicName = "";
    this.VideoTopicCode = "";
    this.VideoDownloadPath = "/mca/video-download.aspx?fileName=";
      /**
     * The DHTML ID of the Top HTML Section
     */
    this.VideoBubble_TopHTMLID = "TopHTML";    
    this.VideoBubble_RLink1HTMLID = "RLink1HTML";    
    this.VideoBubble_RLink2HTMLID = "RLink2HTML";
    this.VideoBubbleDownloadID = "VideoBubbleDownload";
    this.VideoWatchFullLinkID = "VideoWatchFullLink";

    /**
     * Shows the Sign in bubble
     */    
    this.ShowBubble=function(topCode, topType){
        this.GetVideoTopicInformation(topCode, topType, displayVideo);
        _ScrollPopup_Class._PopupControlID = this.Bubble_DivID;
        
        // this is to make the background (faded blue) scroll with the user
        window.onscroll =  _ScrollPopup_Class.ScrollHandler; 
        window.onresize =  _ScrollPopup_Class.ResizeHandler; 
        
        // hide the drop downs on the page
        if (AJAX_IsIE6()) {
            try {
                var obj=$get("prod_select");
                if (obj!=null) {
                    obj.style.visibility='hidden';
                    obj.style.display='none';
                }
            }catch(err) { }
        }
        
        _ScrollPopup_Class.ShowModal();
    }
    
    this.Hide=function() {
        _ScrollPopup_Class.Hide();
        var flashHolder = $get(_VideoBubble_Class.FlashDivID);
        if(flashHolder != null)
            flashHolder.innerHTML = "";
            
        // show the drop downs on the page
        if (AJAX_IsIE6()) {
            try {
                var obj=$get("prod_select");
                if (obj!=null) {
                    obj.style.visibility='visible';
                    obj.style.display='';
                }
            }catch(err) { }
        }
        
        
    }
    
    /**
     * 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) {
            _VideoBubble_Class.VideoTopicName = result.Name;
            _VideoBubble_Class.VideoTopicCode = result.TopicCode;
            $get('VideoTitleHTML').innerHTML = result.Name;
            
            var _Properties=result.Properties;
            for(var j=0; j<_Properties.length; j++) 
            {
                if(_Properties[j].Name=='Has_Chapters')
                {
                    if(_Properties[j].Value=='True')
                    {
                        _VideoBubble_Class.GetVideoSubTopics(result.TopicCode, result.TopicType, displaySubTopics);
                    }
                    else
                    {
//                        $get(_VideoBubble_Class.VideoBubble_TopHTMLID).innerHTML = 'Does not have chapters';
                    }
                }
                if(_Properties[j].Name=='Related_Link_1')
                {
                    $get(_VideoBubble_Class.VideoBubble_RLink1HTMLID).href = _Properties[j].Value;
                }
                if(_Properties[j].Name=='Related_Link_2')
                {
                    $get(_VideoBubble_Class.VideoBubble_RLink2HTMLID).innerHTML = _Properties[j].Value;
                }
                if(_Properties[j].Name=='Video_File_Path')
                {
                    // The video player was changed and required a new parameter slatepath, which is the name of image file. Video_File_Path
                    // as the file name for slate/image path. 
                    _VideoBubble_Class.VideoPath = VIDEO_GALLERY_PLAYER_PATH + '?content=' + _Properties[j].Value + '&slatepath=' + _Properties[j].Value;
                }
                 if(_Properties[j].Name=='Stream_Path')
                {
                    _VideoBubble_Class.VideoPath =  _VideoBubble_Class.VideoPath + '&streampath=' + _Properties[j].Value + '&popup=true';
                }
                
                
            }
            var downLoadObj = $get(_VideoBubble_Class.VideoBubbleDownloadID);
                downLoadObj.href = _VideoBubble_Class.VideoDownloadPath + result.TopicCode + ".mov";
                
            $get(_VideoBubble_Class.VideoWatchFullLinkID).href = "javascript:_VideoBubble_Class.ChangeFlashFile('0');";
            
            _VideoBubble_Class.CreateFlashControl("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
                "rfVideoPlayer", 
                _VideoBubble_Class.VideoWidth, /*width*/ 
                _VideoBubble_Class.VideoHeight, /*height*/
                _VideoBubble_Class.VideoPath,
                "",
                "");         
         }
         else 
         { 
            alert ("No results for this event.");
         }  
    }        

    this.GetVideoSubTopics=function(TopicCode, TopicType, OnCompleteFuncName) 
    {
        if(!IsAjaxLoaded()) {return false;}
       
        try {
            //DoWait();
            MicrosoftFrance.MCS.Commerce.WS.AJAXProject.TopicWebService.GetSubTopics(TopicCode, TopicType,  eval(OnCompleteFuncName),onError);
        }
        catch (e) {
            DoDefault();
            window.status = e.message;
        }
        return false;
    }

    function displaySubTopics(result)
    {
         //DoDefault();     
         if (result!=null) 
         {
            var varChapterTitles = '';
            for(var j=0; j<result.length; j++) 
            {
                objTopic = result[j];
                var _Properties=objTopic.Properties;
                for(var k=0; k<_Properties.length; k++) 
                {
                    if(_Properties[k].Name=='Video_Seek_Time')
                    {
                        varChapterTitles = varChapterTitles + '<a href="javascript:_VideoBubble_Class.ChangeFlashFile(\'' + _Properties[k].Value + '\');">' + objTopic.Name + '</a><br>';
                    }
                }
            }
            $get('ChapterTitlesHTML').innerHTML = varChapterTitles;
         }
         else 
         { 
            alert ("No results for this event.");
         }           
    }

    this.ChangeFlashFile=function(SeekPos){
        this.CreateFlashControl("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
            "rfVideoPlayer", 
            this.VideoWidth, /*width*/ 
            this.VideoHeight, /*height*/
            this.VideoPath + '&seek=' + SeekPos,
            "",
            "");
    }
    
    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="' + ObjectID + '" 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();

var _EmailVideoBubble_Class = new Maybelline.EmailFriendBubble_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';
           if (this._IsforegroundElementLarge==true) {
              this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/4)+'px';
           
           }
           else {
             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';
             }
             // 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("-", "");
           }                     
        }
        
        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;        
    }
    

    /**
     * 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' ){      
            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';  
        }

    }
}
/*
 * 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.ScrollPopup
 */
var _ScrollPopup_Class=new Core.ScrollPopup();

/*
 * Class used for Add to Favorites logic
 */
Core.AddToFavorites_Class=function (){
     this.PopupPath = "/club/popup_add_favorite.aspx";
     this.PopupHeight = POPUPSIGNINHIEGHT;
     this.PopupWidth = POPUPSIGNINWIDTH;
     this.newWindow = "";
     /**
     * This method will be called from the bubbles to add a product on the
     *  favorites from quick shop
     */
    this.AddToFavoritesFromBubble=function(TopicType, TopicCode) {
        //alert(CustomerSigned);
        if(CustomerSigned == true){
            if (this.newWindow && !this.newWindow.closed)	{
		        this.newWindow.close();
	        }            
	        var winl = (screen.width - this.PopupWidth) / 2;
	        var wint = (screen.height - this.PopupHeight) / 2;
	        this.newWindow = open(this.PopupPath + "?objCode=" + TopicCode + "&TopicType=" + TopicType, 'FavoritePopup', ("toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + this.PopupWidth + ",height=" + this.PopupHeight + "\""));
        }else{
            _SignInBubble.TopicType = TopicType;
            _SignInBubble.ShowBubbleFromFavoritesBubble(TopicCode);
        }
    }
}

/*
 * It registers the AddToFavorites_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.AddToFavorites_Class.registerClass('Core.AddToFavorites_Class'); }
 
 /*
 * It instantiate an object like Core.AddToFavorites_Class that will be used by other js on the ajax pages
 */
var _AddToFavorites_Class=new Core.AddToFavorites_Class();

/**
* It instantiates an object of type Core.SignInBubble_Class
*/
var _SignInBubble=new Core.SignInBubble_Class();

/*
 * Class used for Remove from Favorites logic
 */
Core.RemoveFromFavorites_Class=function (){
    
    this.RemoveFavTopic=function(TopicCode,TopicType)  {
        _WebServiceAPI.RemoveTopicFromFavorites(CurrentCustomerID, TopicCode, TopicType, this.RemoveFavTopicOnComplete);
    }
	
	this.RemoveFavTopicOnComplete=function(result) {
            DoDefault();
	     if (result.ActivityStatus==true) {
                //alert("your topic has been removed");
	     }
    }
}

/*
 * It registers the RemoveFromFavorites_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.RemoveFromFavorites_Class.registerClass('Core.RemoveFromFavorites_Class'); }
 
 /*
 * It instantiate an object like Core.RemoveFromFavorites_Class that will be used by other js on the ajax pages
 */
var _RemoveFromFavorites_Class=new Core.RemoveFromFavorites_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.ShowModalWithoutBackground();
        }
    }
}
 /**
 * 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 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();