/**
 * @fileoverview Provides methods for Yahoo! Local profile page
 * @namespace YAHOO.Profile
 */

YAHOO.namespace('Local.Profile');

/**
 *
 *
 */
YAHOO.Local.Profile.toggleAddComment = function(e) {
    YAHOO.util.Event.preventDefault(e);
    var btn = YAHOO.util.Dom.get('yls-pf-addcomment-btn');
    var container = YAHOO.util.Dom.get('yls-pf-commentformbdy');
    if (YAHOO.util.Dom.getStyle(container, 'display') === 'none') {
        YAHOO.util.Dom.setStyle(container, 'display', 'block');
    } else {
        YAHOO.util.Dom.setStyle(container, 'display', 'none');
    }
};


/**
 * Adds onclick event to 'Send to Phone' button in SRP.
 * Loads external send-to-phone js and css.
 * @method addSendToPhoneEvents
 */
YAHOO.Local.Profile.addSendToPhoneEvents = function() {
    var addEvent = function(el) {
        YAHOO.util.Event.on(el, 'click', function(e){
            YAHOO.util.Event.stopEvent(e);
            var element = YAHOO.util.Event.getTarget(e);
            //hardcode the destruction of 'save to local' container if it exists
            if (YAHOO.util.Dom.get('yls-sl-cont')) {
                YAHOO.Local.SaveToLocal.destroy();
            }
            //traverse from target element until we encounter TBODY. TBODY contains the listing id which we pass to sms api.
            var getListingId = function() {
                while (element.tagName.toLowerCase() != 'tbody') {
                    element = element.parentNode;
                }
                return element.id;
            };
            YAHOO.Local.util.InProgress.create(YAHOO.Local.data.IN_PROGRESS, el);
            if (!YAHOO.lang.isObject(YAHOO.Local.SendToPhone)) {
                var arrUrls = [YAHOO.Local.data.SEND_TO_PHONE.js, YAHOO.Local.data.SEND_TO_PHONE.css];
                if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
                    arrUrls.push(YAHOO.Local.data.YUI.connection);
                }
                var file = new YAHOO.Local.util.loadFile(arrUrls, 'YAHOO.Local.SendToPhone');
                file.onComplete.subscribe(function(){
                    YAHOO.Local.SendToPhone.create(getListingId(), el);
                });
            } else {
                YAHOO.Local.SendToPhone.create(getListingId(), el);
            }
        });
    };

    //Grab all the 'send to phone' links and add event
    YAHOO.util.Dom.batch(YAHOO.util.Dom.getElementsByClassName('yls-pf-sendtophone', 'a', 'yls-pf-tabular-activity'), addEvent, this);
};



/**
 * Adds onclick event to 'Add to Collections' button.
 * @method addCollectionsEvents
 */
YAHOO.Local.Profile.addCollectionsEvents = function() {
    var addEvent = function(el) {
        YAHOO.util.Event.on(el, 'click', function(e){
            YAHOO.util.Event.stopEvent(e);

            if (!YAHOO.Local.data['IS_LOGGEDIN']) {
                location.href = YAHOO.Local.data['LOGIN_URL'];
                return;
            }

            //hardcode the destruction of 'save to local' container if it exists
            if (YAHOO.util.Dom.get('yls-sp-cont')) {
                YAHOO.Local.SendToPhone.destroy();
            }

            //traverse from target element until we encounter LI. LI contains the listing id which we pass to sms api.
            /* deprecated in choice of getting listing id from the actual href
            var getListingId = function() {
                while (element.tagName.toLowerCase() != 'tbody') {
                    element = element.parentNode;
                }
                return element.id;
            };
            */
            var getListingId = function() {
                if(el.id.indexOf('tbl-ac-') != -1) {
                    var listingId = el.id.replace(/tbl-ac-/, ''); //listing id is namespaced by 'ac-'. eg...'ac-12345'
                } else if(el.id.indexOf('ac-') != -1) {
                    var listingId = el.id.replace(/ac-/, '');
                }
                return listingId;
            };

            YAHOO.Local.util.InProgress.create(YAHOO.Local.data.IN_PROGRESS, el);
            if (!YAHOO.lang.isObject(YAHOO.Local.AddToCollection)) {
                var arrUrls = [YAHOO.Local.data.ADD_TO_COLLECTION.js, YAHOO.Local.data.ADD_TO_COLLECTION.css];
                if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
                    arrUrls.push(YAHOO.Local.data.YUI.connection);
                }
                if (!YAHOO.lang.isObject(YAHOO.util.Anim)) {
                    arrUrls.push(YAHOO.Local.data.YUI.animation);
                }

                var file = new YAHOO.Local.util.loadFile(arrUrls, 'YAHOO.Local.AddToCollection');
                file.onComplete.subscribe(function(){
                    YAHOO.Local.AddToCollection.create(getListingId(), el);
                });
            } else {
                YAHOO.Local.AddToCollection.create(getListingId(), el);
            }
        });
    };

    //Grab all the 'add to collection' links and add event
    YAHOO.util.Dom.batch(YAHOO.util.Dom.getElementsByClassName('yls-pf-addcollection', 'a', 'yls-pf-main'), addEvent, this);
};




/**
 * Add events to the user recommend (thumbs up/down) buttons. Copied from details.js.
 * YAHOO.util.loadFile to load external UserRecommend javascript file.
 * @method addUserRecommendEvent
 */
YAHOO.Local.Profile.addUserRecommendEvent = function() {
    var addEvent = function(el) {
        //we add event for this element seperately
        if (el.id == 'yls-rc-reccollection') {
            return;
        }
        YAHOO.util.Event.on(el, 'click', function(e){
            if (!YAHOO.Local.data['IS_LOGGEDIN']) {
                location.href = YAHOO.Local.data['LOGIN_URL'];
                return;
            }
            var element = YAHOO.util.Event.getTarget(e);
            var arrUrls = [YAHOO.Local.data.USER_RECOMMEND.js];
               if(!YAHOO.lang.isObject(YAHOO.Local.UserRecommend)) {
                   if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
                       arrUrls.push(YAHOO.Local.data.YUI.connection);
                   }
                   var file = new YAHOO.Local.util.loadFile(arrUrls, 'YAHOO.Local.UserRecommend');
                   file.onComplete.subscribe(function(){
                       YAHOO.Local.UserRecommend.send(element);
                    });
               } else {
                   YAHOO.Local.UserRecommend.send(element);
               }
          });
    };
    //Grab all the active 'rcm' (thumb) buttons and add event
    YAHOO.util.Dom.batch(YAHOO.util.Dom.getElementsByClassName('yls-rc-active', 'span', 'yls-pf-main'), addEvent, this);
};





YAHOO.Local.Profile.addRecommendCollectionEvent = function() {
     YAHOO.util.Event.on('yls-rc-reccollection', 'click', function(e){
        var element = YAHOO.util.Event.getTarget(e);
        var arrUrls = [YAHOO.Local.data.USER_RECOMMEND.js];
        if(!YAHOO.lang.isObject(YAHOO.Local.UserRecommend)) {
            if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
                arrUrls.push(YAHOO.Local.data.YUI.connection);
            }
            var file = new YAHOO.Local.util.loadFile(arrUrls, 'YAHOO.Local.UserRecommend');
            file.onComplete.subscribe(function(){
                 YAHOO.Local.UserRecommend.sendRecommendCollection(element);
            });
        } else {
            YAHOO.Local.UserRecommend.sendRecommendCollection(element);
        }
    });
     YAHOO.util.Event.on('yls-rc-reccollection', 'mouseover', function(e){
         YAHOO.util.Dom.addClass(this, 'rec-high');
    });
     YAHOO.util.Event.on('yls-rc-reccollection', 'mouseout', function(e){
         YAHOO.util.Dom.removeClass(this, 'rec-high');
    });
};

/**
 * The listing rollover for recent activity module. Copied from result YAHOO.Local.Results.ListingRollover.
 * @class ListingRollover
 */
YAHOO.Local.Profile.ListingRollover = (function() {

    /**
     * Provides a holder so we can store node the user clicked on
     * @private
     */
    var _lockedNode = null;

    /**
     * Traverse from target element until we encounter TBODY. TBODY is the trigger element for the listing rollover.
     * @method _getTargetListItem
     * @private
     */
    var _getTargetListItem = function(e) {
        var element = YAHOO.util.Event.getTarget(e);
        while (element.tagName.toLowerCase() != 'tbody') {
            element = element.parentNode;
        }
        return element;
    };

    return {
        resultRows: YAHOO.util.Dom.getElementsByClassName('yls-pf-tabular-business', 'tbody', 'yls-pf-tabular-activity'),

        highlightListing: function(listItem, bStatus) {
            if(bStatus) {
                YAHOO.util.Dom.addClass(listItem, 'yls-pf-hover');
            } else {
                YAHOO.util.Dom.removeClass(listItem, 'yls-pf-hover');
            }
        },

        /**
         * Locks the rollover state by removing rollover event from all list items.
         * @method lockHighlight
         */
        lockHighlight: function(e, obj) {
            _lockedNode = _getTargetListItem(e);

            YAHOO.util.Event.removeListener(obj.resultRows, 'mouseover');
            YAHOO.util.Event.removeListener(obj.resultRows, 'mouseout');

            //use mouseup since click is taken
            YAHOO.util.Event.addListener('yls-sp-close', 'mouseup', obj.unLockHighlight, obj, true); //send to phone
            YAHOO.util.Event.addListener('yls-sl-close', 'mouseup', obj.unLockHighlight, obj, true); //save for later close button
            YAHOO.util.Event.addListener('yls-sl-cancel', 'mouseup', obj.unLockHighlight, obj, true); //save for later cancel button
            YAHOO.util.Event.addListener('yls-cl-cancel', 'mouseup', obj.unLockHighlight, obj, true); //add to collection cancel button
            YAHOO.util.Event.addListener('yls-cl-close', 'mouseup', obj.unLockHighlight, obj, true); //add to collection close button

            //unlock the highlight if user clicks outside of the litebox
            YAHOO.util.Event.addListener(document.body, 'click', function(e) {
                var el = YAHOO.util.Event.getTarget(e);
                //we should change this logic at some time to make it smarter - cyee
                if (    !YAHOO.util.Dom.isAncestor('yls-sp-cont', el) && el.id != 'yls-sp-cont' && //not send to phone container
                        !YAHOO.util.Dom.isAncestor('yls-sl-cont', el) && el.id != 'yls-sl-cont' && //not save for later container
                        !YAHOO.util.Dom.isAncestor('yls-cl-cont', el) && el.id != 'yls-cl-cont' && //not add to collection container
                        !YAHOO.util.Dom.isAncestor('yls-pf-delete-cont', el) && el.id != 'yls-pf-delete-cont' && !YAHOO.util.Dom.hasClass(el, 'yls-pf-clear')  //not delete collection container
                        && !YAHOO.util.Dom.hasClass(el, 'yls-pf-delete-item') //not delete item from collection
                        ) {
                    this.unLockHighlight();
                }
            }, obj, true);
        },

        /**
         * Unlocks the locked element by adding back rollover events to all list items
         * @method unLockHighlight
         */
        unLockHighlight: function(){
            if (YAHOO.lang.isNull(_lockedNode)) {
                return;
            }
            this.highlightListing(_lockedNode, false);
            var actionItemsRow = _lockedNode.getElementsByTagName('tr')[1];
            this.toggleActionItems(actionItemsRow, 'none'); //hide the action items row
            YAHOO.util.Event.addListener(this.resultRows, 'mouseover', this.onMouseOver, this);
            YAHOO.util.Event.addListener(this.resultRows, 'mouseout', this.onMouseOut, this);
        },

        toggleActionItems: function(el, displayType) {
            YAHOO.util.Dom.setStyle(el, 'display', displayType);
        },

        onMouseOver: function(e, obj) {
            //obj.highlightListing(YAHOO.util.Event.resolveTextNode(this), true);
            obj.highlightListing(this, true);
            var el = this.getElementsByTagName('tr')[1];
            var displayType = 'table-row';
            var isIe = (!this.webkit && !navigator.userAgent.match(/opera/gi) && navigator.userAgent.match(/msie/gi));
            ///YAHOO.util.Dom.setStyle(el, 'height', 100 +'px');
            if (isIe) {
                displayType = 'block';
            }
            obj.toggleActionItems(el, displayType);
        },
        onMouseOut: function(e, obj) {
            //obj.highlightListing(YAHOO.util.Event.resolveTextNode(this), false);
            obj.highlightListing(this, false);
            var el = this.getElementsByTagName('tr')[1];
            obj.toggleActionItems(el, 'none');
        },
        attachEvents: function() {
           // in this function, 'this' refers to the ListingRollover obj, which is passed to
           // the event handler as an object, so that event handler can easily reference the
           // correct method of ListingRollover
           YAHOO.util.Event.addListener(this.resultRows, 'mouseover', this.onMouseOver, this);
           YAHOO.util.Event.addListener(this.resultRows, 'mouseout', this.onMouseOut, this);
           YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('yls-pf-sendtophone', 'a', 'yls-pf-main'), 'click', this.lockHighlight, this);
           if (YAHOO.util.Dom.get('yls-pf-tabular-activity')) { // yls-pf-tabular-activity tell us Listing Rollovers are present in the page
               YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('yls-pf-addcollection', 'a', 'yls-pf-tabular-activity'), 'click', this.lockHighlight, this);
           }
           //YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('yls-pf-clear', 'a', 'yls-pf-main'), 'click', this.lockHighlight, this);
        }
    };
})();


YAHOO.Local.Profile.CreateCollection = {

    container:  YAHOO.util.Dom.get('yls-pf-createcoll'),
    labelText: {},
    inputEls: {},

    /**
     * Verify's the INPUT values so we can add/remove the ghost text css and clear/redefine the INPUT value.
     * @param e {Event}: The mouse event on the INPUT element
     * @method verify
     */
    verify: function(e) {
        YAHOO.util.Event.stopPropagation(e);
        var inputEl = YAHOO.util.Event.getTarget(e);
        switch (inputEl.value) {
            case this.labelText.title:
                inputEl.value = '';
                YAHOO.util.Dom.removeClass(inputEl, 'yls-gl-srchform-ghost');
            break;

            case this.labelText.desc:
                inputEl.value = '';
                YAHOO.util.Dom.removeClass(inputEl, 'yls-gl-srchform-ghost');
            break;

            case '':
                if (inputEl.id == this.inputEls['title'].id) {
                    inputEl.value = this.labelText['title'];
                    YAHOO.util.Dom.addClass(inputEl, 'yls-gl-srchform-ghost');
                } else if (inputEl.id == this.inputEls['desc'].id){
                    inputEl.value = this.labelText['desc'];
                    YAHOO.util.Dom.addClass(inputEl, 'yls-gl-srchform-ghost');
                }
            break;
        }
    },

    /**
     * Toggles the display type of the Create Collection container
     * @method toggle
     */
    toggle: function() {
        if(YAHOO.Local.data.IS_LOGGEDIN) {
            if (YAHOO.util.Dom.getStyle(this.container, 'display') !== 'block') {
                YAHOO.util.Dom.setStyle(this.container, 'display', 'block');
                if (YAHOO.util.Dom.inDocument('yls-pf-coll-createbtn')) {
                    var xy = [
                                YAHOO.util.Dom.getRegion('yls-pf-coll-createbtn').right,
                                YAHOO.util.Dom.getRegion('yls-pf-coll-createbtn').bottom
                             ];

                    var xOffset = this.container.offsetWidth || this.container.pixelWidth;
                    YAHOO.util.Dom.setXY(this.container, [ parseInt(xy[0] - xOffset), parseInt(xy[1])]);
                }
            } else {
                YAHOO.util.Dom.setStyle(this.container, 'display', 'none');
                this.destroyErrorMessage();
            }
        } else {
            YAHOO.Local.Profile.Login.redirectToLogin('collection');
        }
    },

    /**
     * Creates an error message container and displays the message from server
     * @method createErrorMessage
     */
     createErrorMessage: function(msg) {
        var parent = YAHOO.util.Dom.get('yls-pf-createcoll');
        var sibling = YAHOO.util.Dom.get('yls-pf-createcoll-form');
        var messageContainer = document.createElement('b');
        messageContainer.id = 'yls-pf-createcoll-msg';
        YAHOO.util.Dom.addClass(messageContainer, 'yls-gl-palette1');
        YAHOO.util.Dom.addClass(messageContainer, 'yls-gl-error');
        messageContainer.innerHTML = msg;
        parent.insertBefore(messageContainer, sibling);
    },

    /**
     * Removes the error message from parent.
     * @method destroyErrorMessage
     */
    destroyErrorMessage: function() {
       var messageContainer = YAHOO.util.Dom.get('yls-pf-createcoll-msg');
       if(messageContainer) {
           var messageContainer = YAHOO.util.Dom.get('yls-pf-createcoll-msg');
           var parent = messageContainer.parentNode;
           parent.removeChild(messageContainer);
       }
    },

    /**
     * For CoreID State Al case, sets CoreID nickname before UGC form submission
     * To use attach this function as the form's onsubmit handler
     * @method handleCoreINoNickname
     */
    handleCoreIdNoNickname: function(e) {
        YAHOO.util.Event.preventDefault(e);

        var self = this;
        var _form = YAHOO.util.Dom.get('yls-pf-createcoll-form');
        if (typeof(_form['yIdAliasSelect']) != 'undefined') {
            var _form_data = { 'yIdAliasSelect':_form['yIdAliasSelect'].value, 'yIdNicknameInput':_form['yIdNicknameInput'].value };
            YAHOO.Local.util.updateCoreId(self, _form_data, function(oForm, _responseData) {
                if (_responseData.status == 'OK') {
                    self.sendAndReload();
                } else {
                    var oIdPicker = YAHOO.util.Dom.get('yIdSignDiv');
                    var error_msgs = YAHOO.util.Dom.getElementsByClassName('yls-gl-error', 'p',  oIdPicker.parentNode);
                    var error_msg = (error_msgs.length > 0) ? error_msgs[0] : null;
                    if (YAHOO.lang.isNull(error_msg)) {
                        error_msg = document.createElement('p');
                        YAHOO.util.Dom.addClass(error_msg, 'yls-gl-error');
                        YAHOO.util.Dom.addClass(error_msg, 'yls-gl-palette1');
                        oIdPicker.parentNode.insertBefore(error_msg, oIdPicker);
                        error_msg.style.display = 'block';
                    }
                    error_msg.innerHTML = _responseData.errormsg;
                }
            });
        } else  {
            this.sendAndReload();
        }
    },

    /**
     * Sends the post data to handler. Then, reload self to display the new collection to user
     * @method sendAndReload
     */
    sendAndReload: function() {
        var formAction = '/annotations_handler.php';
        var crumb = YAHOO.Local.data['LOCAL_CB']; //crumb data
        var self = this;

        var handleSuccess = function(o) {
            var response = eval(o.responseText);
            if (response.status == 'ok') {
                var url = window.location.toString();
                url = url.replace(/&open\=collection/, ''); //remove open=collection, so the popup doesn't open after user creates a collection.
                window.location = url;
            } else if (response.status == 'error') {
                self.createErrorMessage(response.msg);
            }
        };
        var handleFailure = function(o) {
            //do nothing
        };

        var callback =
        {
            success: handleSuccess,
            failure: handleFailure
        };
        var postData = 'procaction=savecollection&ctitle=' + YAHOO.util.Dom.get('yls-pf-colltitle').value + '&permission=' + YAHOO.util.Dom.get('yls-pf-private').checked +'&desp=' + YAHOO.util.Dom.get('yls-pf-colldesc').value + '&lcscb=' + crumb;

        var request = YAHOO.util.Connect.asyncRequest('POST', formAction, callback, postData);
    },

    toggleHandler: function() {
         //load the connection manager on first click of create collection button
         if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
             var self = this;
             var file = new YAHOO.Local.util.loadFile(YAHOO.Local.data['YUI'].connection, 'YAHOO.util.Connect');
             file.onComplete.subscribe(function(){
                  self.toggle();
             });
         } else {
              this.toggle();
         }
    },

    /**
     * Grabs the label innerHTML to set the INPUT value (ghost text)
     * Adds events on the INPUT fields for Create Collection FORM and trigger button.
     * @method init
     */
    init: function() {

        var self = this;
        this.labelText = {
            title: YAHOO.util.Dom.get('yls-pf-coll-titlelabel').innerHTML,
            desc: YAHOO.util.Dom.get('yls-pf-coll-desclabel').innerHTML
        };
        this.inputEls =  {
             title: YAHOO.util.Dom.get('yls-pf-colltitle'),
             desc: YAHOO.util.Dom.get('yls-pf-colldesc')
        };

        this.inputEls['title'].value = this.labelText.title;
        this.inputEls['desc'].value = this.labelText.desc;
        YAHOO.util.Event.on('yls-pf-coll-createbtn', 'click', function(e) {
            YAHOO.util.Event.preventDefault(e);
            self.toggleHandler();
        });

        //in some cases, we want to open the pop-up when the page loads.
        if (YAHOO.Local.data['OPEN'] === 'collections') {
            this.openByDefault();
        }

        YAHOO.util.Event.on([this.inputEls['title'], this.inputEls['desc']], 'focus', function(e) { self.verify(e); });
        YAHOO.util.Event.on([this.inputEls['title'], this.inputEls['desc']], 'blur', function(e) { self.verify(e); });
        YAHOO.util.Event.on('yls-pf-close', 'click', function(e) { YAHOO.util.Event.stopEvent(e); self.toggle(e); });
        YAHOO.util.Event.on('yls-pf-cancel', 'click', function(e) { YAHOO.util.Event.stopEvent(e); self.toggle(e); });
        YAHOO.util.Event.on('yls-pf-submit', 'click', function(e) { YAHOO.util.Event.stopEvent(e); self.handleCoreIdNoNickname(e); });
    },

    openByDefault: function() {
        var self = this;
        YAHOO.util.Event.onAvailable('yls-pf-createcoll', function() { self.toggleHandler(); });

    }
};


/**
 * Delete a list item from collection
 * NOTE: Delete collection from profile see DeleteCollection class
 * @class DeleteListItem
 */
YAHOO.Local.Profile.DeleteItem = {
    createContainer: function() {
        var self = this;
        var getCollectionName = function() {
            var element = self.targetEl;
            while (element.tagName.toLowerCase() != 'tbody') {
                element = element.parentNode;
            }
            var name = element.getElementsByTagName('a')[0].innerHTML;
            return name;
        };

        var innerHTML = function() {
            var data = YAHOO.Local.data['DELETE_LIST_ITEM'];
            s = '<h4>' + data.HEADER +'</h4>';
            s += '<p>' + data.MESSAGE + ' ' + getCollectionName() + '?</p>';
            s += '<button type="submit" id="yls-pf-delete-submit" class="yls-gl-btnhlite">' + data.BUTTON_TEXT[0] + '</button><button class="yls-gl-btn" id="yls-pf-delete-cancel">' + data.BUTTON_TEXT[1] + '</button>';
            return s;
        };

        var container = document.createElement('div');
        container.id = 'yls-pf-delete-item-cont';
        container.innerHTML = innerHTML();

        var xy = [YAHOO.util.Dom.getRegion(this.targetEl).left, YAHOO.util.Dom.getRegion(this.targetEl).bottom];
        YAHOO.util.Dom.addClass(container, 'yls-gl-litebox');
        YAHOO.util.Dom.addClass(container, 'yls-pf-delete-cont');
        YAHOO.util.Dom.get('yls-gl-pg').appendChild(container);
        YAHOO.util.Dom.setXY(container, xy);

        YAHOO.util.Event.on('yls-pf-delete-cancel', 'click', function() {
            self.destroyContainer();
        });
        YAHOO.util.Event.on('yls-pf-delete-submit', 'click', function() {
            self.sendAndReload();
        });
    },

    /**
     * Sends the post data to handler. Then, reload self to display the new collection to user
     * @method sendAndReload
     */
    sendAndReload: function() {

        var listingId = this.targetEl.id.replace(/d-/, ''); //listing id on the delete button is namespaced by 'd-'. eg...'d-12345'
        var formAction = '/ups_handler.php';
        var handleSuccess = function(o) {
            var response = eval(o.responseText);
            if (response.status == 'ok') {
                window.location.reload();
            }

        };
        var handleFailure = function(o) {
            //do nothing
        };

        var callback =
        {
            success: handleSuccess,
            failure: handleFailure
        };
        var postData = 'type=save&action=clear&id=' + listingId;

        var doRequest = function() {
            var request = YAHOO.util.Connect.asyncRequest('POST', formAction, callback, postData);
        };
        if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
            var file = new YAHOO.Local.util.loadFile(YAHOO.Local.data.YUI.connection, 'YAHOO.util.Connect');
            file.onComplete.subscribe(function(){
                doRequest();
            });
        } else {
            doRequest();
        }

    },

    /**
     * Removes and purges the popup container and its children from page
     * @method destroyContainer
     */
    destroyContainer: function() {
        if (YAHOO.util.Dom.inDocument('yls-pf-delete-item-cont')) {
            YAHOO.util.Event.purgeElement('yls-pf-delete-item-cont', true);
            YAHOO.util.Dom.get('yls-gl-pg').removeChild(YAHOO.util.Dom.get('yls-pf-delete-item-cont'));
            YAHOO.Local.Profile.ListingRollover.unLockHighlight();
        }
    },

    /**
     * Toggles the display type to show and hide the popup container
     * @method toggle
     */
    toggle: function(e) {
        YAHOO.util.Event.preventDefault(e);
        this.targetEl = YAHOO.util.Event.getTarget(e);
        if (YAHOO.util.Dom.inDocument('yls-pf-delete-cont')) {
            this.destroyContainer();
        } else {
            this.createContainer();
        }
    },

    /**
     * Add listeners to the delete item href in the page
     * @method addEvent
     */
    addEvent: function() {
        var coll = YAHOO.util.Dom.getElementsByClassName('yls-pf-delete-item', 'a', 'yls-pf-main');
        var self = this;
        YAHOO.util.Event.on(coll, 'click', function(e) {
            YAHOO.Local.Profile.ListingRollover.lockHighlight(e, YAHOO.Local.Profile.ListingRollover);
            self.toggle(e);
        });
        YAHOO.util.Event.on(document.body, 'click', function(e) {
            var el = YAHOO.util.Event.getTarget(e);
            if (!YAHOO.util.Dom.isAncestor('yls-pf-delete-item-cont', el) && el.id != 'yls-pf-delete-item-cont' && !YAHOO.util.Dom.hasClass(el, 'yls-pf-delete-item')) {
                self.destroyContainer();
            }
        });

    }
};

/**
 * Delete a collection from user profile.
 * NOTE: Delete list item from collection see DeleteListItem class
 * @class DeleteCollection
 */
YAHOO.Local.Profile.DeleteCollection = {

    targetEl: null,
    hasListingRollover: YAHOO.util.Dom.inDocument('yls-pf-tabular-activity'), //listing rollover has different HTML structure and interaction, so we'll need this to test against
    createContainer: function() {
        var self = this;
        var getCollectionName = function() {
            if (self.hasListingRollover) {
                var element = self.targetEl;
                while (element.tagName.toLowerCase() != 'tbody') {
                    element = element.parentNode;
                }
                var name = element.getElementsByTagName('a')[0].innerHTML;
                return name;
             } else if(YAHOO.util.Dom.get('yls-pf-mycoll-title')) {
                return YAHOO.util.Dom.get('yls-pf-mycoll-title').innerHTML;
             } else if(YAHOO.util.Dom.get('yls-pf-tabson')) {
                var _tab_text = YAHOO.util.Dom.get('yls-pf-tabson').innerHTML;
                var _paren_idx = _tab_text.indexOf('(');
                if(_paren_idx == -1) {
                    return _tab_text;
                } else {
                    return _tab_text.substring(0, (_paren_idx - 1)); //cut out space before parenthesis too
                }
             }
        };

        var innerHTML = function() {
            var data = YAHOO.Local.data['DELETE_COLLECTION'];
            s = '<h4>' + data.HEADER +'</h4>';
            s += '<p>' + data.MESSAGE + ' ' + getCollectionName() + '?</p>';
            s += '<button type="submit" id="yls-pf-delete-submit" class="yls-gl-btnhlite">' + data.BUTTON_TEXT[0] + '</button><button class="yls-gl-btn" id="yls-pf-delete-cancel">' + data.BUTTON_TEXT[1] + '</button>';
            return s;
        };
        var container = document.createElement('div');
        container.id = 'yls-pf-delete-cont';
        container.innerHTML = innerHTML();

        var xy = [YAHOO.util.Dom.getRegion(this.targetEl).left, YAHOO.util.Dom.getRegion(this.targetEl).bottom];
        YAHOO.util.Dom.addClass(container, 'yls-gl-litebox');
        YAHOO.util.Dom.addClass(container, 'yls-pf-delete-cont');
        YAHOO.util.Dom.get('yls-gl-pg').appendChild(container);
        YAHOO.util.Dom.setXY(container, xy);

        YAHOO.util.Event.on('yls-pf-delete-cancel', 'click', function() {
            self.destroyContainer();
        });
        YAHOO.util.Event.on('yls-pf-delete-submit', 'click', function() {
            location.href = self.targetEl.href;
        });

    },

    destroyContainer: function() {
        if (YAHOO.util.Dom.inDocument('yls-pf-delete-cont')) {
            YAHOO.util.Event.purgeElement('yls-pf-delete-cont', true);
            YAHOO.util.Dom.get('yls-gl-pg').removeChild(YAHOO.util.Dom.get('yls-pf-delete-cont'));
            if (this.hasListingRollover) {
                YAHOO.Local.Profile.ListingRollover.unLockHighlight();
            }
        }
    },

    toggle: function(e) {
        YAHOO.util.Event.preventDefault(e);
        this.targetEl = YAHOO.util.Event.getTarget(e);
        if (YAHOO.util.Dom.inDocument('yls-pf-delete-cont')) {
            this.destroyContainer();
        } else {
            this.createContainer();
        }
    },

    addEvent: function() {
        var coll = YAHOO.util.Dom.getElementsByClassName('yls-pf-clear', 'a', 'yls-pf-tabular-activity');
        var self = this;
        YAHOO.util.Event.on(coll, 'click', function(e) {
            if (self.hasListingRollover) {
                YAHOO.Local.Profile.ListingRollover.lockHighlight(e, YAHOO.Local.Profile.ListingRollover);
            }
            self.toggle(e);
        });
        YAHOO.util.Event.on(document.body, 'click', function(e) {
            var el = YAHOO.util.Event.getTarget(e);
            if (!YAHOO.util.Dom.isAncestor('yls-pf-delete-cont', el) && el.id != 'yls-pf-delete-cont' && !YAHOO.util.Dom.hasClass(el, 'yls-pf-clear')) {
                self.destroyContainer();
            }
        });

    }

};

/**
 * Handles setting the collection permission to private/public
 * @class Permission
 */
YAHOO.Local.Profile.Permission = {


    send: function(e) {
        YAHOO.util.Event.preventDefault(e);
        var targetEl = YAHOO.util.Event.getTarget(e);
        var formAction = '/annotations_handler.php';

        var readOnlyText = { originalSetting: YAHOO.util.Dom.get('yls-pf-permission').innerHTML, newSetting: YAHOO.util.Dom.get('yls-pf-permission-opt').innerHTML };

        var handleSuccess = function(o) {
            var response = eval(o.responseText);
            if (response.status == 'ok') {
                YAHOO.util.Dom.get('yls-pf-permission').innerHTML = readOnlyText.newSetting;
                YAHOO.util.Dom.get('yls-pf-permission-opt').innerHTML = readOnlyText.originalSetting;
                YAHOO.Local.Profile.Permission.toggle();
            }

        };
        var handleFailure = function(o) {
            //do nothing
        };

        var callback =
        {
            success: handleSuccess,
            failure: handleFailure
        };

        //read the innerHTML of targetEl to get the new permission setting
        var getPermissionType = function() {
            var text = targetEl.innerHTML;
            var privateSetting = 'permission=0'; //private setting

            //if user sets to public send this postData
            if (text == YAHOO.Local.data['PERMISSION'][1]) {
                privateSetting  = 'permission=1';
            }

            return privateSetting;

        };
        var postData = 'procaction=edit_coll&cid=' + YAHOO.Local.data['COLLECTION_ID'] + '&' + getPermissionType();

        var request = YAHOO.util.Connect.asyncRequest('POST', formAction, callback, postData);

    },
    /**
     * Toggles the display type of the permission container
     * @method
     */
    toggle: function() {
        var option = YAHOO.util.Dom.get('yls-pf-permission-opt');
        if (YAHOO.util.Dom.getStyle(option, 'display') === 'none') {
            this.show();
        } else {
            this.hide();
        }
    },

    show: function() {
        var option = YAHOO.util.Dom.get('yls-pf-permission-opt');
        var xy = [YAHOO.util.Dom.getRegion('yls-pf-permission').left, YAHOO.util.Dom.getRegion('yls-pf-permission').bottom + 1];
        YAHOO.util.Dom.setStyle(option, 'display', 'block');
        YAHOO.util.Dom.setXY(option, xy);
    },

    hide: function() {
        var option = YAHOO.util.Dom.get('yls-pf-permission-opt');
        YAHOO.util.Dom.setStyle(option, 'display', 'none');
    },

    /**
     * Adds the permission event and sets up the handler to toggle container
     * @method addEvent
     */
    addEvent: function() {
        var self = this;
        //load the connection manager on first click of create collection button
        var handler = function(e) {
            YAHOO.util.Event.preventDefault(e);
            if (!YAHOO.lang.isObject(YAHOO.util.Connect)) {
            var file = new YAHOO.Local.util.loadFile(YAHOO.Local.data['YUI'].connection, 'YAHOO.util.Connect');
            file.onComplete.subscribe(function(){
                self.toggle(e);
            });
            } else {
                self.toggle(e);
            }
        };

        YAHOO.util.Event.on('yls-pf-permission', 'click', handler);
        YAHOO.util.Event.on('yls-pf-permission-opt', 'click', this.send);
        YAHOO.util.Event.on(document.body, 'click', function(e) {
            var el = YAHOO.util.Event.getTarget(e);
            if (el.id != 'yls-pf-permission' && el.id != 'yls-pf-permission-opt') {
                self.hide();
            }
        });
    }
};

/**
 * Allows css classNames 'yls-pf-editiable' elements to be edited by user.
 * @class TextEdit
 * @param editId {String}: The DOM id of the editable input field
 * @param editType {String}: The postdata query name sent to the server
 */
YAHOO.Local.Profile.TextEdit = function(editId, editType) {

    this.addEvent(editId, editType);
};


YAHOO.Local.Profile.TextEdit.prototype = {

    textHolder: '', //just in case we need to revert back to the old text we'll use this as a reference to it.

    makeEditable: function() {
        var self = this;
        YAHOO.util.Event.removeListener(this.editEl, 'click');

        //remove the hover class and pencil
        YAHOO.util.Dom.removeClass(this.editEl, 'yls-pf-editable');
        YAHOO.util.Dom.removeClass(this.editEl, 'yls-gl-palette2');

        this.input = document.createElement('input');
        this.input.id = 'yls-pf-editfield';
        this.input.value = this.editEl.innerHTML;

        //define textHolder text
        this.textHolder = this.editEl.innerHTML;

        //now, clear text
        this.editEl.innerHTML = '';

        this.submit = document.createElement('button');
        this.submit.id = 'yls-pf-edit-submit';
        YAHOO.util.Dom.addClass(this.submit, 'yls-gl-btnhlite');
        this.submit.innerHTML = YAHOO.Local.data['ADD_TO_COLLECTION'].BUTTON_TEXT[0]; //borrowing button text from add collection

        this.cancel = document.createElement('button');
        this.cancel.id = 'yls-pf-edit-cancel';
        YAHOO.util.Dom.addClass(this.cancel, 'yls-gl-btn');
        this.cancel.innerHTML = YAHOO.Local.data['ADD_TO_COLLECTION'].BUTTON_TEXT[1]; //borrowing button text from add collection


        this.editEl.appendChild(this.input);
        this.editEl.appendChild(this.submit);
        this.editEl.appendChild(this.cancel);


        YAHOO.util.Event.on(this.submit, 'click', function(e) { YAHOO.util.Event.preventDefault(e); self.save(); });
        YAHOO.util.Event.on(this.cancel, 'click', function(e) { YAHOO.util.Event.stopEvent(e); self.revert(); });

    },

    revert: function() {
        this.removeEdit();
        this.editEl.innerHTML = this.textHolder;
        this.addEvent(this.editEl, this.editType); //add back event
    },

    removeEdit: function() {

        //add back the hover and pencil
        YAHOO.util.Dom.addClass(this.editEl, 'yls-pf-editable');
        YAHOO.util.Dom.addClass(this.editEl, 'yls-gl-palette2');


        //this.textField.removeChild(this.submit);
        //this.textField.removeChild(this.cancel);
        //this.textField.removeChild(this.input);

        YAHOO.util.Event.purgeElement(this.input);
        YAHOO.util.Event.purgeElement(this.submit);
        YAHOO.util.Event.purgeElement(this.cancel);

    },

    save: function() {

        var self = this;
        var formAction = '/annotations_handler.php';
        var text = this.input.value;
        if (!text) self.revert();

        var handleSuccess = function(o) {
            var response = eval(o.responseText);
            if (response.status == 'ok') {
                self.textHolder = text;
                self.editEl.innerHTML = self.textHolder;
                self.removeEdit();
                self.addEvent(self.editEl, self.editType); //add back event�
            }

        };
        var handleFailure = function(o) {
            //do nothing
        };

        var callback =
        {
            success: handleSuccess,
            failure: handleFailure
        };

        var postData = 'procaction=edit_coll&cid=' + YAHOO.Local.data['COLLECTION_ID'] + '&' + this.editType + '=' + text;

        var request = YAHOO.util.Connect.asyncRequest('POST', formAction, callback, postData);

    },


    addEvent: function(editId, editType) {
        var self = this;
        this.editType = editType;
        this.editEl = YAHOO.util.Dom.get(editId);
        YAHOO.util.Event.on(this.editEl, 'click', function(e) {
            self.makeEditable();
        });
    }
};

/**
 * COPIED FROM DETAIL PAGE
 * When a user is not logged in and they try to access a pop up (which requires them to be signed in),
 * we redirect them to login.yahoo.com and add a 'open=<popup name>' to .done via redirectToLogin method. After the user has logged in,
 * they get redirected back to us. At this point, Local.data['OPEN'] gets defined via PHP. If it is defined,
 * we call openPopUp method, to reopen the pop up the user previously clicked on.
 *
 * @class Login
 */
YAHOO.Local.Profile.Login = {
    /**
     * Redirects to login url with 'open' appended to URL
     * @param openType {String}: The 'open' value or module name we want to open.
     * @method redirectToLogin
     */
    redirectToLogin: function(openType) {
        if(arguments.length > 1) {
            location.href = YAHOO.Local.data['LOGIN_URL'] + encodeURIComponent('&open=' + openType + '&review_id=' + arguments[1] + '#' + arguments[2]);
        } else {
            location.href = YAHOO.Local.data['LOGIN_URL'] + encodeURIComponent('&open=' + openType + '#' + openType);
        }
        return;
    },

    /**
     * This function tests which module we want to open and calls the correct method.
     * @method openPopUp
     */
    openPopUp: function(openType) {
        switch (openType) {
            case 'collection':
                if (YAHOO.util.Dom.get('yls-pf-createcoll')) {
                    YAHOO.Local.Profile.CreateCollection.openByDefault();
                }
                break;
            default:
                // do nothing
                break;
         }
    }
};

/**
 * Generic delete confirmation (TODO: Replace DeleteCollection/DeleteItem functions with call to this)
 */
YAHOO.Local.Profile.Confirm = {
    /**
     * Creates confirmation dialog
     * @method createConfDialog
     * @param dataObjRef  The reference to the messages in YAHOO.Local.data JSON obj in page
     */
     createConfDialog: function(e, dataObjRef, isPosToRight) {
        YAHOO.util.Event.stopEvent(e);
        var el = YAHOO.util.Event.getTarget(e);

        var dialogHTML = function() {
            var data = YAHOO.Local.data[dataObjRef];
            var a = ['<h4>', data.HEADER, '</h4>', '<p>', data.MESSAGE, '</p>', '<button type="submit" id="yls-pf-confirm-submit" class="yls-gl-btnhlite">', data.BUTTON_TEXT[0], '</button><button class="yls-gl-btn" id="yls-pf-confirm-cancel">', data.BUTTON_TEXT[1], '</button>'];
            return a.join(' ');
        };

        var container = YAHOO.util.Dom.get('yls-pf-confirm-dialog');
        if(!YAHOO.lang.isObject(container) || container.tagName.toLowerCase() !== 'div') {
            container = document.createElement('div');
            container.id = 'yls-pf-confirm-dialog';
        }
        container.innerHTML = dialogHTML();

        YAHOO.util.Dom.addClass(container, 'yls-gl-litebox');
        YAHOO.util.Dom.addClass(container, 'yls-pf-delete-cont');  // for styling only ("delete" in className)
        YAHOO.util.Dom.get('yls-gl-pg').appendChild(container);
        var xy = [];
        if (isPosToRight) {
            xy = [YAHOO.util.Dom.getRegion(el).right, YAHOO.util.Dom.getRegion(el).bottom];
            xy[0] = xy[0] - parseInt(YAHOO.util.Dom.getStyle(container, 'width')) -30;
        } else {
            xy = [YAHOO.util.Dom.getRegion(el).left, YAHOO.util.Dom.getRegion(el).bottom];
        }

        YAHOO.util.Dom.setXY(container, xy);

        YAHOO.util.Event.on('yls-pf-confirm-cancel', 'click', function() {
            YAHOO.Local.Profile.Confirm.destroyConfDialog();
        });
        YAHOO.util.Event.on('yls-pf-confirm-submit', 'click', function(e, link_el) {
            if (YAHOO.lang.isUndefined(link_el.href)) { //link_el.href is undefined when user clicks 'remove' from My Alerts
                link_el = el;
            }
            window.location.replace(link_el.href);
        }, this);
        container = null;
    },

    /**
     * Generic delete confirmation (TODO: Replace DeleteCollection/DeleteItem functions with call to this)
     * @method destroyConfDialog
     */
    destroyConfDialog: function() {
        var container = YAHOO.util.Dom.get('yls-pf-confirm-dialog');
        if(YAHOO.lang.isObject(container) && container.tagName.toLowerCase() === 'div') {
            YAHOO.util.Event.purgeElement(container, true);
            container.parentNode.removeChild(container);
        }
        container = null;
    }
};


/** 	 
  * This is used to handle the subscribe to another user's review. 	 
  * Also, handles opting-in user to receive alerts when someone 	 
  * comments on their review. 	 
  * @class AlertSubscribe 	 
  */ 	 
 YAHOO.Local.Profile.AlertSubscribe = { 	 
  	 
     /** 	 
      * Creates a message bar at top of page to notify user has added alert 	 
      * @method handleMessage 	 
      * @param message {String}: The message returned by response 	 
      */ 	 
     handleMessage: function(message) { 	 
         var msg = YAHOO.util.Dom.get('yls-pf-alertmsg') || false; 	 
         if (msg) { 	 
             var parent = msg.parentNode; 	 
             parent.removeChild(msg); 	 
         } 	 
         var msg = document.createElement('div'); 	 
         msg.id = 'yls-pf-alertmsg'; 	 
         msg.innerHTML = message; 	 
         YAHOO.util.Dom.insertBefore(msg, 'yui-main'); 	 
         YAHOO.util.Dom.addClass(msg, 'yls-pf-tmsg'); 	 
         YAHOO.util.Dom.addClass(msg, 'yls-gl-palette2'); 	 
  	 
         //anchor user to alert message at top of page 	 
         location.href = '#alertmessage'; 	 
  	 
     }, 	 
  	 
     /** 	 
      * Do request to opt-in user to alert 	 
      * @method request 	 
      * @param e {Event} The event which triggered request 	 
      */ 	 
     request: function(e) { 	 
         YAHOO.util.Event.preventDefault(e); 	 
         var el = YAHOO.util.Event.getTarget(e); 	 
         var postData = YAHOO.Local.data['SUBSCRIBE_ALERT_QUERY']; 	 
         var handleSuccess = function(o){ 	 
             if(o.responseText !== undefined){ 	 
                 var response = eval(o.responseText); 	 
                 if (response.status == 'ok') { 	 
                     YAHOO.Local.Profile.AlertSubscribe.handleMessage(response.msg); 	 
                 } else if (response.status == 'error') { 	 
                     YAHOO.Local.Profile.AlertSubscribe.handleMessage(response.msg); 	 
                 } 	 
             } 	 
         }; 	 
         var callback = { success: handleSuccess }; 	 
  	 
         var request = YAHOO.util.Connect.asyncRequest('POST', 'alerts_handler.php', callback, postData); 	 
  	 
     }, 	 

     /**
      * Redirect non-loggedin users to the login page.
      * @method redirectToLogin
      * @param e {Event} The event which triggered this
      */
     redirectToLogin: function(e) {
         YAHOO.util.Event.preventDefault(e);
         location.href = YAHOO.Local.data.LOGIN_URL;
     },
  	 
     /** 	 
      * Add event listener to the subscribe button 	 
      * @method addEvent 	 
      */ 	 
     addEvent: function() { 	 
          if (!YAHOO.Local.data.IS_LOGGEDIN) {
              YAHOO.util.Event.on('yls-pf-subscribeto', 'click', this.redirectToLogin);   
          } else {
              YAHOO.util.Event.on('yls-pf-subscribeto', 'click', this.request); 	 
          }
     } 	 
 };





/**
 * Initialize profile page components
 * @method initPage
 */
YAHOO.Local.Profile.initPage = function() {

    var self = this;
    YAHOO.Local.util.initGlobalComponents();
    if (YAHOO.lang.isArray(YAHOO.Local.Profile.ListingRollover.resultRows)) {
        this.ListingRollover.attachEvents();
    }

    this.addSendToPhoneEvents();

    this.addCollectionsEvents();

    this.addUserRecommendEvent();

    //'add comment' feature is only present on single collection page, so we'll do a check for its DOM container
    if (YAHOO.util.Dom.get('yls-pf-commentformbdy')) {
        YAHOO.util.Event.on('yls-pf-addcomment-btn', 'click', this.toggleAddComment);
        YAHOO.util.Event.on('yls-ac-cancel', 'click', this.toggleAddComment);
    }

    //recommend a collection
    if (YAHOO.util.Dom.get('yls-rc-reccollection')) {
        this.addRecommendCollectionEvent();
    }

    //create a collection
    if (YAHOO.util.Dom.get('yls-pf-createcoll')) {
        this.CreateCollection.init();
    }

    //delete a collection
    if (YAHOO.util.Dom.getElementsByClassName('yls-pf-clear', 'a', 'yls-pf-main')[0]) {
        this.DeleteCollection.addEvent();
    }

    //delete item from collection
    if (YAHOO.util.Dom.getElementsByClassName('yls-pf-delete-item', 'a', 'yls-pf-main')[0]) {
        this.DeleteItem.addEvent();
    }

    //delete single collection comment
    var delcomments = YAHOO.util.Dom.getElementsByClassName('yls-pf-delete-comment', 'a', 'yls-pf-main');
    if(delcomments.length > 0) {
        YAHOO.util.Event.on(delcomments, 'click', YAHOO.Local.Profile.Confirm.createConfDialog, 'DELETE_COMMENT');
    }

    //delete review
    var delreviews = YAHOO.util.Dom.getElementsByClassName('yls-pf-delete-review', 'a', 'yls-pf-main');
    if(delreviews.length > 0) {
        YAHOO.util.Event.on(delreviews, 'click', YAHOO.Local.Profile.Confirm.createConfDialog, 'DELETE_REVIEW');
    }

    //add event to 'remove all alerts' button in My Alerts
    if(YAHOO.util.Dom.inDocument('yls-pf-removealerts')) {
        YAHOO.util.Event.on('yls-pf-removealerts', 'click', function(e) { YAHOO.Local.Profile.Confirm.createConfDialog(e, 'REMOVE_ALERTS', true); });
    }

    //add event to 'remove alert' buttons in My Alerts
    var removeAlert = YAHOO.util.Dom.getElementsByClassName('yls-pf-removealert', 'a', 'yls-pf-tabular-activity');
    if(removeAlert.length > 0) {
        YAHOO.util.Event.on(removeAlert, 'click', function(e) { YAHOO.Local.Profile.Confirm.createConfDialog(e, 'REMOVE_ALERT', true); });
    }

    //setting collection to private/public
    if (YAHOO.util.Dom.inDocument('yls-pf-permission')) {
        this.Permission.addEvent();
    }

    //single collection w/ editable text fields. yls-pf-editable tells us there's and editable element in the page
    if (YAHOO.util.Dom.getElementsByClassName('yls-pf-editable', 'span', 'yls-pf-mycoll-desc')[0]) {
        var desc = new YAHOO.Local.Profile.TextEdit('yls-pf-mycoll-desctxt', 'desc');
        var title = new YAHOO.Local.Profile.TextEdit('yls-pf-mycoll-title', 'title');
    }

    //add event to 'subscribe' to alert button in My Alerts 	 
    if (YAHOO.util.Dom.inDocument('yls-pf-subscribeto')) { 	 
        YAHOO.Local.Profile.AlertSubscribe.addEvent(); 	 
    } 

    // CoreID V1 handling for Add Comment forms
    if (YAHOO.util.Dom.get('yIdSignSelect')) {
        YAHOO.util.Event.on(YAHOO.util.Dom.get('yls-pf-commentform'), 'submit', YAHOO.Local.util.handleCoreIdNoNickname);
    }

    if(!YAHOO.lang.isUndefined(YAHOO.Local.data.OPEN)) {
        YAHOO.Local.Profile.Login.openPopUp(YAHOO.Local.data.OPEN);
    }

    //Initialize photo and nickname picker
    YAHOO.Local.Picker.init();

};

