All pastes #982531 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-12 17:36 UTC
rendered paste body
showDialog - function(name, nullifyContent) {
      if (currentDialog)
        currentDialog.hide();

      if (nullifyContent) {
        newContent = null;
			}

      if (dialogs[name]) {
        currentDialog = dialogs[name];
        this.resetDialogContent(name);

        currentDialog.show();
      } else { this.notifyOnLoad = true; alert('The profiles editor is still loading, please wait a seconds...'); }
    }init - function() {
      for(var i=0; i < profile_columns.length; i++) {
        new YAHOO.util.DDTarget(profile_columns[i], 'profile_column');
      }

      /* dragable + sortable panels init */
      var draggable_elements = DOM.getElementsByClassName(panel_class_name);
      for (var i = 0; i < draggable_elements.length; i++) {
        var n = new YAHOO.felocity.util.SortableItem(draggable_elements[i], 'profile_column', {'className':'panel'});

				n.custom_events.startDrag.subscribe(adjustContainers, gap);
				n.custom_events.endDrag.subscribe(adjustContainers, gap);
      }

      /* make theater panels dragable anywhere */
      var draggable_elements = DOM.getElementsByClassName('dd_panel');
      for (var i = 0; i < draggable_elements.length; i++) {
        new YAHOO.util.DD(draggable_elements[i], 'theater', {'isTarget': false});
      }

      /* make the control panel draggable */
      new YAHOO.util.DD('control_panel', 'cp', {'isTarget':false});

      /* dialogs + tabs init */
      var dialogs_to_init = {
        'theme': { 'id': 'themes_dlg', 'tabs': 'themes_tabs' },
        'content': { 'id': 'content_dlg' },
        'avatar': {'id': 'avatar_dlg', 'tabs': 'avatar_tabs' },
        'text': { 'id': 'text_dlg' },
        'caption': { 'id': 'caption_dlg' },
        'picture': { 'id': 'pictures_dlg', 'tabs': 'pictures_tabs' },
        'edit_text': { 'id': 'edit_text_dlg' },
        'edit_caption': { 'id': 'edit_caption_dlg' },
        'edit_title': { 'id': 'edit_title_dlg' },
        'edit_media': { 'id': 'edit_media_dlg' },
        'edit_custom': { 'id': 'edit_custom_dlg' },
        'edit_avatar': { 'id': 'edit_avatar_dlg' },
        'edit_movie': { 'id': 'edit_movie_dlg' }
      };

      for(var dialog_name in dialogs_to_init) {
        var dialog_id = dialogs_to_init[dialog_name]['id'];

        if (dialogs_to_init[dialog_name]['tabs']) {
          var tabName = dialogs_to_init[dialog_name]['tabs'];
          dialogTabs[tabName] = new YAHOO.widget.TabView(tabName);
        }

        DOM.setStyle(dialog_id, 'display', 'block');
        dialogs[dialog_name] = new YAHOO.widget.Panel(dialog_id, dialog_opts);
        dialogs[dialog_name].render();
      }

      new YAHOO.widget.TabView("theme_gallery_tabs", {'orientation': 'left'});

      /* turn 'add' and 'update' class elements in 'a' tags into "buttons" */
      var button_keyCheck = function(e) { if (YAHOO.util.Event.getCharCode(e) == 13) this.onclick(); };
      var button_highlight = function(e) { YAHOO.util.Dom.addClass(this, 'active-button'); };
      var button_unHighlight = function(e) { YAHOO.util.Dom.removeClass(this, 'active-button'); };

      /* keydown, focus, blur */
      var button_classes = ['update', 'add'];
      for(var i in button_classes) {
        var className = button_classes[i];

        var buttons = DOM.getElementsByClassName(className, 'a');
        for(var i=0; i<buttons.length; i++) {
          var button = buttons[i];

          /* skip all the gallery/theme "add" buttons */
          if (DOM.hasClass(button, 'centered'))
            continue;

          YAHOO.util.Event.addListener(button, 'keydown', button_keyCheck);
          YAHOO.util.Event.addListener(button, 'focus', button_highlight);
          YAHOO.util.Event.addListener(button, 'blur', button_unHighlight);
        }
      }

      /* add drag and drop fun! */
      var dd_elements = DOM.getElementsByClassName('decoration');
      for(var i=0; i<dd_elements.length; i++) {
        var decor = dd_elements[i];

        if (decor.id.match(/picture|avatar/)) {
          var dd = new YAHOO.util.DD(decor.id, 'decoration', {'isTarget':false});
          dd.addInvalidHandleId(decor.id + '_r');

          new YAHOO.gaia.util.DDResize(decor.id, decor.id + '_r', 'resize', null, resizeImage);
        } else {
          new YAHOO.util.DD(decor.id, 'decoration', {'isTarget':false});
        }
      }


      /* add the click handlers to dynamically add the images to the Pictures/Gallery tabs */
      YAHOO.util.Event.onContentReady('pictures_gallery_tabs', function() {
        var pg_tabs = new YAHOO.widget.TabView("pictures_gallery_tabs", {'orientation': 'left'});

        for(var i=0; ; i++) {
          var tab = pg_tabs.getTab(i);
          if (! tab)
            break;

          tab.addListener('click', gap.fireLoadGalleryPicturesTab, {'name': tab.get('element').id});
        }

        /* load the Gaia pictures tab */
        gap.loadGalleryPicturesTab('Gaia');
      });

      YAHOO.util.Event.onContentReady('themes_tabs', function() {
        var tab = dialogTabs['themes_tabs'].getTab(1);
        if (! tab) return;

        tab.addListener('click', gap.fireLoadPhotobucketIFrame, { 'name': 'jwidget_theme' });
      });

      YAHOO.util.Event.onContentReady('pictures_tabs', function() {
        var tab = dialogTabs['pictures_tabs'].getTab(2);
        if (! tab) return;

        tab.addListener('click', gap.fireLoadPhotobucketIFrame, { 'name': 'jwidget_pictures' });
      });

      if (this.notifyOnLoad)
        alert("Profiles editor has finished loading");
    }serializeProfile - function() {
      var column_data         = new Object();
      var picture_data        = new Array();
      var caption_data        = new Array();
      var media_custom_data   = new Array();
      var element_list;
      var movie_data = new Array();
    
      // layout
      // get all panels by column
      for (var i = 0; i < profile_columns.length; i++) {
        // create an object space for the column
        column_data[profile_columns[i]] = new Array();
        
        // get all items within this column
        element_list = DOM.getElementsByClassName(panel_class_name, null, profile_columns[i]);
        
        for (var j = 0; j < element_list.length; j++) {
          var ele             = element_list[j];
          var id              = ele.id;

          /* skip hidden panels, they've been removed */
          if ( (DOM.getStyle(id, 'display') == 'none') && !ele.getAttribute('banned'))
            continue;

          var panel_type      = id.replace(/id_/, "");
          var panel_title     = this.encode(document.getElementById(panel_type + "_title").innerHTML);

          column_data[profile_columns[i]].push([panel_type, panel_title])
            
          // is this a media / custom? if not, continue
          if (!panel_type.match(/media|custom/)) continue;

          var content;
          if (panel_type.match(/custom/)) {
            content = document.getElementById(panel_type + '_raw');
          } else {
            content = document.getElementById(panel_type + '_content');
          }

          media_custom_data.push( {
            "id": panel_type,
            'new': id.match(/_new/),
            "content": this.encode(this.textify(content.innerHTML))
          });
        }
      }
    
      element_list = DOM.getElementsByClassName('dd_panel', null, 'theaters');
      for(var i=0; i < element_list.length; i++) {
        var item = element_list[i];
        var id = item.id;
        var panel_type = id.replace(/^id_/, '');

        var type = panel_type;
        type = type.replace(/^movie_/, '');
        type = type.replace(/_(new|\d+)$/, '');
        movie_data.push( {
          'id': panel_type,
          'new': id.match(/_new/) ? '1' : 0,
          'type': type,
          'x' : DOM.getStyle(id, 'left').replace(/px/, ''),
          'y': DOM.getStyle(id, 'top').replace(/px/, ''),
          'width': DOM.getStyle(id, 'width').replace(/px/, ''),
          'height': DOM.getStyle(id, 'height').replace(/px/, '')
        });
      }

      // pictures
      // get all picture items. These have a class of picture_decoration
      element_list = DOM.getElementsByClassName(decoration_class_name, null, pictures_container_name);
      for (var i = 0; i < element_list.length; i++) {
        var ele     = element_list[i];
        var id      = ele.id;
        var x       = DOM.getStyle(id, 'left');
        var y       = DOM.getStyle(id, 'top');
        var width   = ele.offsetWidth;
        var height  = ele.offsetHeight;
        var zindex  = ele.style.zIndex;
        
        var is_avatar       = (DOM.hasClass(ele, avatar_class_name)) ? true : false;
        var is_picture      = (DOM.hasClass(ele, picture_class_name)) ? true : false;
        var is_new          = id.match(/_new/);
        var avatar_type     = null;
        var avatar_user_id  = null;
        var avatar_facing   = null;
        var picture_url     = null;
        
        // handle avatar specific attributes derrived from the class names
        if (is_avatar) {
          avatar_type = ele.getAttribute('gaiasize');
          avatar_user_id = ele.getAttribute('gaiaid');
          avatar_facing = ele.getAttribute('gaiafacing');
        }
        
        if (is_picture) {
          picture_url = document.getElementById(ele.id+"_content").src;
        }
        
        picture_data.push( {
            "id"        : id,
              "x"         : x,
              "y"         : y,
              "z"         : zindex,
              // "type"   : type,
              "content"   : this.encode(picture_url),
              "width"     : width,
              "height"    : height,
              "avi_id"    : avatar_user_id,
              "facing"    : avatar_facing,
              "size"      : avatar_type,
              'type'      : ele.getAttribute('gaiatype'),
              "new"       : is_new
              });

      } // end picture push
    
      // text and captions
      element_list = DOM.getElementsByClassName(decoration_class_name, null, texts_container_name);
      for (var i = 0; i < element_list.length; i++) {
        var ele         = element_list[i];
        var id          = ele.id;
        var x           = DOM.getStyle(id, 'left');
        var y           = DOM.getStyle(id, 'top');
        var zindex      = ele.style.zIndex;
        var type = DOM.hasClass(ele, text_class_name) ? "text" : "caption";
        var direction   = (document.getElementById(ele.id+"_dir")) ? document.getElementById(ele.id+"_dir").className.replace('caption_bottom_', '') : '';

        var content;
        if (type == 'text')
          content = document.getElementById(ele.id+'_raw').innerHTML;
        else
          content = document.getElementById(ele.id+"_content").innerHTML;
        
        caption_data.push( {
            "type"      : type,
              "id"        : id,
              "x"         : x,
              "y"         : y,
              "z"         : zindex,
              "content"   : this.encode(this.textify(content)),
              "dir"       : direction,
              'new'       : id.match(/_new/)
              });
      }
    
      // theme, complile, done
      var root = document.createElement("textarea");
      var profile_form = document.getElementById("profile");
      var output_string = "";
      YAHOO.util.Dom.setStyle(root, 'display', 'none');
    
      // columns
      for (col_name in column_data) {
        var items           = column_data[col_name];
        var form_field      = col_name.replace(/umn_/, "");
        output_string   = "";
        
        for (var i = 0; i < items.length; i++) {
            var pair = items[i];
            output_string += pair[0] + "=" + pair[1] + "&";
        }
        
        document.getElementById(form_field).value = output_string;
      }

      /* movie panels */
      for (var i=0; i < movie_data.length; i++) {
        output_string = "";
        var n = root.cloneNode(true);
        for (prop in movie_data[i]) {
          var val = movie_data[i][prop];
          output_string += prop + "=" + val + "&";
        }
        
        n.name = (movie_data[i]["new"]) ? "additions[]" : "decorations[]";
        n.value = output_string;
        profile_form.appendChild(n);
      }

      // pictures
      for (var i=0; i < picture_data.length; i++) {
        output_string = "";
        var n = root.cloneNode(true);
        for (prop in picture_data[i]) {
          var val = picture_data[i][prop];
          output_string += prop + "=" + val + "&";
        }
        
        n.name = (picture_data[i]["new"]) ? "additions[]" : "decorations[]";
        n.value = output_string;
        profile_form.appendChild(n);
      }
    
      // text and cap
      for (var i=0; i < caption_data.length; i++) {
        output_string = "";
        var n = root.cloneNode(true);
        for (prop in caption_data[i]) {
          var val = caption_data[i][prop];
          output_string += prop + "=" + val + "&";
        }
        
        n.name = (caption_data[i]["new"]) ? "additions[]" : "decorations[]";
        n.value = output_string;
        profile_form.appendChild(n);
      }

      // media and custom
      for (var i=0; i < media_custom_data.length; i++) {
        output_string = "";
        var n = root.cloneNode(true);
        for (prop in media_custom_data[i]) {
          if (prop == 'new') continue;

          var val = media_custom_data[i][prop];
          output_string += prop + "=" + val + "&";
        }
        
        n.name = (media_custom_data[i]["new"]) ? "additions[]" : "decorations[]";
        n.value = output_string;
        profile_form.appendChild(n);
      }

      document.getElementById('pictures_container').appendChild(this.buildNode('input', {type:'hidden', id:'form_save', name:'save'}));
    
      // theme placeholder
      if (themeId) {
        profile_form.appendChild(this.buildNode('input', {'name':'theme_id',  'value': themeId, 'type':'hidden'}));
      }

      if (backgroundImage != null) {
        profile_form.appendChild(this.buildNode('input', {'name':'theme_bg',  'value': backgroundImage, 'type':'hidden'}));
			}
	
      profileModified = false;
      document.getElementById('profile').submit();
    }removeItem - function(name, type) {
      if (type == 'panel') {
        var panel = document.getElementById('id_' + name);

        if (panel)
          DOM.setStyle(panel.id, 'display', 'none');

        profileModified = true;
      } else {
        if (type.match(/media|custom|movie/)) {
          name = 'id_' + name;
        }
  
        var theNode = document.getElementById(name);
        if (theNode) {
          var parentNode = theNode.parentNode;
          var divId = theNode.id;
          parentNode.removeChild(theNode);

          if (! divId.match(/_new/)) {
            /* remove id_ from cusom and media */
            divId = divId.replace('id_', '');

            var inputNode = this.buildNode('input', {name:'deletions[]', type:'hidden',value:divId});
            document.getElementById('profile').appendChild(inputNode);

            profileModified = true;
          }
        }
      }
    }editItem - function(name, type) {
      var movie_props = ['left', 'top', 'width', 'height'];
      var auto_close = true;

      if (name == 'update') {
        if ((type == 'media') || (type == 'custom')) {
          var id = editNodeId;

          if ( (type == 'media') && (! newContent.match(/^http:\/\/|^\s*$/)) ) {
            alert("Invalid media URL.\nYour media URL should start with http://");
            return false;
          }

          newContent = newContent.replace(/youtube.com\/watch\?v=/, 'youtube.com/v/');
          document.getElementById(id + '_title').innerHTML = nl2br(newTitle);

          if (type == 'custom') {
            document.getElementById(id + '_raw').innerHTML = nl2br(newContent);
            this.bbcode(newContent, id + '_content');
          } else {
            document.getElementById(id + '_content').innerHTML = nl2br(newContent);
          }
        } else if (type == 'movie') {
          var id = editingNode.id;

          for (var index in movie_props) {
            var prop = movie_props[index];
            var value = document.getElementById('edit_movie_' + prop).value;
            DOM.setStyle(id, prop, value + 'px');
          }

          auto_close = false;
        } else if (type == 'custom') {
          document.getElementById(id + '_raw').innerHTML = nl2br(newContent);
          this.bbcode(newContent, id + '_content');
        } else {
					// alert(editingNode.id+':'+editingNode.innerHTML+'///'+newContent);
          editingNode.innerHTML = nl2br(newContent);
        }
  
        profileModified = true;

        if (auto_close)
          currentDialog.hide();
      } else if (type == 'avatar') {
        this.editAvatar(name, false);
      } else if (type == 'text') {
        var divId = name + '_raw';
        newContent = document.getElementById('edit_text_content').value = this.textify(document.getElementById(divId).innerHTML);
        editingNode = document.getElementById(divId);

        this.showDialog('edit_text', false);
      } else if (type == 'caption') {
        newContent = document.getElementById('edit_caption_content').value = this.textify(document.getElementById(name + '_content') .innerHTML);
        editingNode = document.getElementById(name);
        this.captionDirection = editingNode.getAttribute('gaiatype');

        var select = document.getElementById('caption_direction');
        for(i=0; i<select.options.length; i++) {
          if(select.options[i].value == this.captionDirection) {
            select.selectedIndex = i;
          }
        }

        this.showDialog('edit_caption', false);
      } else if (type.match(/media|custom/)) {
        editNodeId = name;
  
        newTitle = document.getElementById('edit_' + type + '_title').value = this.textify(document.getElementById(name + '_title').innerHTML);
        if (type.match(/custom/)) {
          newContent = document.getElementById('edit_' + type + '_content').value = this.textify(document.getElementById(name + '_raw').innerHTML);
        } else {
          newContent = document.getElementById('edit_' + type + '_content').value = this.textify(document.getElementById(name + '_content').innerHTML);
        }

        this.showDialog('edit_' + type, false);
      } else if (type == 'movie') {
        var item = document.getElementById('id_' + name);
        editingNode = item;

        this.showDialog('edit_movie');

        for(var index in movie_props) {
          var prop = movie_props[index];
          var input = document.getElementById('edit_movie_' + prop);

          var value = DOM.getStyle(item, prop);
          value = value.replace(/px/, '');

          input.value = value;
        }
      } else {
        var divId = name + '_title';
        if (document.getElementById(divId) != null) {
          editingNode = document.getElementById(divId);
          newContent = document.getElementById('new_title_input').value = editingNode.innerHTML;

          var section = '';
          var what = '';

          switch(name) {
            case 'details':
            case 'signature':
            case 'about':
            case 'interests':
              section = name + '/';
            break;

            case 'friends':
            case 'comments':
              section = 'profileprefs/';
              what = 'your ' + name + ' panel avatar style';
            break;

            default:
              DOM.setStyle('edit_title_message', 'display', 'none');
            break;
					}

          if (section != '') {
            document.getElementById('edit_title_link').href = '/account/' + section;
            DOM.setStyle('edit_title_message', 'display', 'block');

            if (what != '') {
              document.getElementById('edit_title_what').innerHTML = what;
            } else {
              document.getElementById('edit_title_what').innerHTML = 'the contents of this frame';
            }
          }

          this.showDialog('edit_title', false);
        }
      }
    }createNode - function(type, button) {
      var newNode;
      var parentElement;
      var divContent;
      var resizeable = false;
      var imageNode = null;
      var autoclose = false;
 
      var style = { 'left': '30%', 'top': '10%', 'position': 'absolute', 'z-index': ++this.maxZ };

      if ( (type == 'text') || (type == 'caption') ) {
        autoclose = true;

        if (newContent == null)
          return;
  
        textsCount++;
  
        var divClass;
        var divId;
        var newNode;
        if (type == 'text') {
          divId = 'text_new' + textsCount;
          divClass = 'decoration text_decoration';
  
          var contentNode = this.buildNode('p', {'id':divId + '_content'}, '');
          var rawNode = this.buildNode('p', {'id':divId + '_raw'}, nl2br(newContent));
          DOM.setStyle(rawNode, 'display', 'none');

          newNode = this.buildNode('div', {'id': divId, 'className':divClass, 'gaiatype':'text' },
                                   [ this.getEditRemoveControls(divId, type,true),
                                     contentNode,
                                     rawNode
                                     ]);

          this.bbcode(newContent, contentNode.id);
        } else {
          divId = 'caption_new' + textsCount;
          divClass = 'decoration caption_decoration';
  
          var contentNode = this.buildNode('p', {'id':divId + '_content'}, '');
          newNode = this.buildNode('div', {'id': divId, 'className':divClass, 'gaiatype':'left' },
                                   [ 
                                    this.getEditRemoveControls(divId, type, true),
                                    this.buildNode('div', {'className':'decoration_content caption'}, 
                                                   [
                                                    this.buildNode('div', {'className':'caption_top'}),
                                                    contentNode,
                                                    this.buildNode('div', {'id':divId + '_dir', 'className':'caption_bottom_left'})
                                                    ])
                                    ]);
          contentNode.innerHTML = nl2br(newContent);
        }
  
        parentElement = document.getElementById('texts_container');
  
      } else if (type == 'picture') {
        if (newContent == null)
          return;
  
        picturesCount++;
        resizeable = true;
  
        divId = 'picture_new' + picturesCount;
        divClass = 'decoration picture_decoration resizable';
  
        parentElement = document.getElementById('pictures_container');

        imageNode = this.buildNode('img', {'src':newContent, 'id':divId+'_content'});
        newNode = this.buildNode('div', {'id': divId, 'className':divClass, 'gaiatype':this.pictureType },
                                 [
                                  this.getEditRemoveControls(divId, type, false),
                                  imageNode,
                                  this.buildNode('div', {'id': divId + '_r', 'className':'handle'})
                                  ]);
  
      } else if (type == 'avatar') {
        if ( (newContent == null) || (newContent == 'choose') )
          return;
  
        avatarsCount++;
        resizeable = true;

        divId = 'avatar_new' + avatarsCount;
        divClass = 'decoration avatar_decoration resizable';

        parentElement = document.getElementById('pictures_container');

        imageNode = this.buildNode('img', {'id':divId + '_content', 'src':'http://' + this.AVATAR_SERVER + '/gaia/members/' + newContent });

        newNode = this.buildNode('div', {'id': divId, 'className':divClass, 'gaiaid':this.avatarId, 'gaiafacing':'left', 'gaiasize':'body', 'width':'120px', 'height':'150px' }, 
                                 [
                                  this.getEditRemoveControls(divId, type, true),
                                  imageNode,
                                  this.buildNode('div', {'id': divId + '_r', 'className':'handle'})
                                  ]);
  
      }
  
      parentElement.appendChild(newNode);
      for(attr in style) {
        DOM.setStyle(newNode.id, attr, style[attr]);
      }

      var dd = new YAHOO.util.DD(newNode.id,'decoration', {'isTarget':false});

      if (resizeable) {
        dd.addInvalidHandleId(divId+'_r');

        new YAHOO.gaia.util.DDResize(divId, divId + '_r', 'resize', null, resizeImage);
      }

      profileModified = true;

      if (autoclose)
        currentDialog.hide();
    }getEditRemoveControls - function(divId, type, edit) {
      if (edit == null)
        edit = false;
  
      var controls;
      var remove_classes = 'remove';
      if (! edit)
        remove_classes = 'remove centered';

      var remove_a = this.buildNode('a', {className:remove_classes, href:'#remove'}, 'remove');

      var click_it = {
        'id': divId,
        'type': type,
        callEdit: function() { gap.editItem(this.id, this.type); },
        callRemove: function() { gap.removeItem(this.id, this.type); }
      };

      YAHOO.util.Event.addListener(remove_a, 'click', click_it.callRemove, click_it, true);
      YAHOO.util.Event.preventDefault(remove_a);
  
      if (edit) {
        var edit_a = this.buildNode('a', {className:'edit', href:'#edit'}, 'edit');
        YAHOO.util.Event.addListener(edit_a, 'click', click_it.callEdit, click_it, true);
        YAHOO.util.Event.preventDefault(edit_a);

        controls =  this.buildNode('ul', {className:'buttons'},
                                   [
                                    this.buildNode('li', [edit_a]),
                                    this.buildNode('li', [remove_a])
                                    ]);
      } else {
        controls =  this.buildNode('ul', {className:'buttons-noedit'}, [ this.buildNode('li', [remove_a]) ]);
      }
  
      return controls;
    }editAvatar - function(divId, update) {
      if (update == false) {
        editingNode = document.getElementById(divId);

        if (editingNode == null)
          return;
  
        this.avatarFacing = editingNode.getAttribute('gaiafacing');
        this.avatarSize = editingNode.getAttribute('gaiasize');
  
        this.showDialog('edit_avatar', true);

        var select = document.getElementById('avatar_size');
        for(i=0; i<select.options.length; i++) {
          if(select.options[i].value == this.avatarSize) {
            select.selectedIndex = i;
          }
        }
  
        this.checkAvatarSelection();
  
        for(i=0; i<select.options.length; i++) {
          if(select.options[i].value == this.avatarFacing) {
            select.selectedIndex = i;
          }
        }
      } else {
        var divNode = editingNode;
        if (divNode == null)
          return;
  
        var curFacing = document.getElementById(divNode.id).getAttribute('gaiafacing');
        var curSize = document.getElementById(divNode.id).getAttribute('gaiasize');
        var imageNode = document.getElementById(divNode.id + '_content');
        var image = imageNode.src;
  
        if (this.avatarSize != curSize) {
          curFacing = '';
          image = image.replace(/_[^.]+\.(png|gif)/, '.png');
  
          if (this.avatarSize == 'head') {
            image = image.replace('.png', '_48x48.gif');
            /* DOM.setStyle(imageNode.id, 'width', '48px');
							 DOM.setStyle(imageNode.id, 'height', '48px'); */
            DOM.setStyle(divNode, 'width', '48px');
            DOM.setStyle(divNode, 'height', '48px');
          } else if (this.avatarSize == 'bust') {
            image = image.replace('.png', '_96x96.png');
            /* DOM.setStyle(imageNode.id, 'width', '96px');
							 DOM.setStyle(imageNode.id, 'height', '96px'); */
            DOM.setStyle(divNode, 'width', '96px');
            DOM.setStyle(divNode, 'height', '96px');
          } else if (this.avatarSize == 'body') {
            /* DOM.setStyle(imageNode.id, 'width', '120px');
							 DOM.setStyle(imageNode.id, 'height', '150px'); */
            DOM.setStyle(divNode, 'width', '120px');
            DOM.setStyle(divNode, 'height', '150px');
          }
        }
  
        if ( (this.avatarFacing != curFacing) && (this.avatarSize == 'body') ) {
          if (this.avatarFacing == 'left') {
            image = image.replace(/_flip.png/, '.png');
          } else {
            image = image.replace('.png', '_flip.png');
          }
        }
  
        divNode.setAttribute('gaiafacing', this.avatarFacing);
        divNode.setAttribute('gaiasize', this.avatarSize);
        imageNode.src = image;
  
        profileModified = true;
        currentDialog.hide();
      }
    }addPanel - function(type, title) {
      if (type.match(/^movie/))
        type = type + '_new';

      if (document.getElementById('id_' + type)) {
        DOM.setStyle('id_' + type, 'display', 'block');
        //        new Effect.Highlight('id_' + type);
      } else {
        var cssClass = 'panel ' + type + '_panel';
        var divId;
        var typeId = type;
        var newPanel;
  
        if (type == 'custom') {
          customCount++;
          divId = 'id_custom_new' + customCount;
          typeId = 'custom_new' + customCount;
  
          newPanel = this.buildNode('div', {className: cssClass, id: divId},
                                    [
                                     this.buildNode('h2', {id:typeId + '_title'}, title),
                                     this.getEditRemoveControls(typeId, type, true),
                                     this.buildNode('div', {id:typeId + '_raw', 'style':'display:none'}, ''),
                                     this.buildNode('div', {id:typeId + '_content'}, ''),
                                     this.buildNode('div', {className:'clear'})
                                     ]);
        } else if (type == 'media') {
          mediaCount++;
          divId = 'id_media_new' + mediaCount;
          typeId = 'media_new' + mediaCount;
  
          newPanel = this.buildNode('div', {className: cssClass, id: divId},
                                    [
                                     this.buildNode('h2', {id:typeId + '_title'}, title),
                                     this.getEditRemoveControls(typeId, type, true),
                                     this.buildNode('div', 'You must be in view mode to view your media.'),
                                     this.buildNode('p', {style:'display:none', id:typeId + '_content'}, ''),
                                     this.buildNode('div', {className:'clear'})
                                     ]);
        } else {
          divId = 'id_' + type;

          var edit_type = 'panel';
          if (type.match(/^movie_/)) {
            edit_type = 'movie';
            cssClass = cssClass + ' dd_panel';
          }

          newPanel = this.buildNode('div', {className: cssClass, id: divId},
                                    [
                                     this.buildNode('h2', {id:type + '_title'}, title),
                                     this.getEditRemoveControls(type, edit_type, true),
                                     this.buildNode('p', 'The contents of this panel will be visible after you save your profile.'),
                                     this.buildNode('div', {className:'clear'})
                                     ]);
        }
  
        addedItemsCount++;

        if (! type.match(/^movie/)) {
          parentId = 'column_' + ( (addedItemsCount % 3) + 1);
          var parent = document.getElementById(parentId);

          if (parent.hasChildNodes())
            parent.insertBefore(newPanel, parent.firstChild);
          else
            parent.appendChild(newPanel);

          var n = new YAHOO.felocity.util.SortableItem(newPanel, 'profile_column', {'className':'panel'});
          n.events.startDrag.subscribe(adjustContainers, gap);
          n.events.endDrag.subscribe(adjustContainers, gap);
        } else {
          parentId = 'theaters';
          DOM.setStyle(newPanel, 'width', '200px');
          DOM.setStyle(newPanel, 'height', '200px');
          DOM.setStyle(newPanel, 'top', '0px');
          DOM.setStyle(newPanel, 'left', '0px');

          document.getElementById(parentId).appendChild(newPanel);

          new YAHOO.util.DD(newPanel, 'movie', {'isTarget':false});
        }
      }

      profileModified = true;
    }addAvatarByUsername - function() {
      if (! newContent)
        return;

      newContent = newContent.replace(/^\s+|\s+$/, '');
      if (newContent == '')
        return;
  
      var handleResponse = function(resp) {
        var xml = resp.responseXML.documentElement;
        var status;
        if (! xml) {
          status = 500;
        } else {
          status = xml.getAttribute('status');
        }
  
        if (status == 200) {
          document.getElementById('avatar_lookup_message').innerHTML = '';
          DOM.setStyle('avatar_lookup_message', 'display', 'none');

          this.avatarId = xml.getAttribute('userId');
          newContent = xml.getAttribute('avatarPath');
          this.createNode('avatar', null);
        } else if (status == 404) {
          DOM.setStyle('avatar_lookup_message', 'display', 'block');
          document.getElementById('avatar_lookup_message').innerHTML = "Whoops!  Couldn't find any user with that username.";
        } else if (status == 500) {
          DOM.setStyle('avatar_lookup_message', 'display', 'block');
          document.getElementById('avatar_lookup_message').innerHTML = "Whoops!  Something went wrong, please try again.";
        }
      }
  
      var handleError = function(resp) {
        alert(resp.statusText);
      }

      var callback = { 'success': handleResponse, 'failure': handleError, 'scope': gap };
 
      var requestUrl = '/profiles/?mode=lookup&username='+newContent;
      YAHOO.util.Connect.asyncRequest('GET', requestUrl, callback, null);
      document.getElementById('avatar_lookup_message').innerHTML = 'Looking up avatar...';
      DOM.setStyle('avatar_lookup_message', 'display', 'block');
    }modifyText - function(type) {
      if (type == 'text') {
        id = editingNode.id.replace(/_raw$/, '_content');
        editingNode.innerHTML = nl2br(newContent);
        this.bbcode(newContent, id);
      } else if (type == 'caption') {
        var parentDiv = editingNode;
        parentDiv.setAttribute('gaiatype', this.captionDirection);
        document.getElementById(parentDiv.id + '_content').innerHTML = nl2br(newContent);
        document.getElementById(parentDiv.id + '_dir').className = 'caption_bottom_' + this.captionDirection;
      }
  
      profileModified = true;
      currentDialog.hide();
    }photobucket_complete - function(imageURL) {
        /* this doesn't fire off an onChange, so it has to be set here */
        this.pictureType='link';
        newContent=imageURL;
				
        if (currentDialog.id.match(/theme/)) {
          document.getElementById('theme_pb_url').value = imageURL;
        } else {
          document.getElementById('pics_pb_url').value = imageURL;
        }
    }applyTheme - function(theme_id) {
      var id = 'theme_' + theme_id;
      var head = document.getElementById('profiles_head');

      if (document.getElementById(id)) {
        if (prevThemeNode)
          head.removeChild(prevThemeNode);

        themeId = theme_id;

        /* IE sucks */
        if (navigator.userAgent.match(/MSIE/)) {
          var style = document.createElement("style");
          style.setAttribute("type", "text/css");

          head.appendChild(style);
          style.styleSheet.cssText = document.getElementById(id).innerHTML;

          prevThemeNode = style;
        } else {
          var node = this.buildNode('style', {type:'text/css'}, document.getElementById(id).innerHTML);
          head.appendChild(node);

          prevThemeNode = node;
        }

        backgroundImage = null;
        profileModified = true;
      }
    }applyBg - function() {
      if (! newContent)
        return;

      var head = document.getElementById('profiles_head');

      if (prevBackground)
        head.removeChild(prevBackground);

      /* IE sucks */
      if (navigator.userAgent.match(/MSIE/)) {
        var style = document.createElement("style");
        style.setAttribute("type", "text/css");

        head.appendChild(style);
        style.styleSheet.cssText = 'html, body { background: url(' + newContent + ') repeat top left; }';

        prevBackground = style;
      } else {
        var node = this.buildNode('style', {type:'text/css'}, 'html, body { background: url(' + newContent + ') repeat top left; }');
        head.appendChild(node);

        prevBackground = node;
      }

      profileModified = true;
      backgroundImage = newContent;
    }buildNode - function(tag, attrs, children) {
      var newNode = document.createElement(tag.toUpperCase());
      if (newNode == null)
        return null;
      
      /* no children, just a text node */
      if ( (typeof attrs == 'string') && !children) {
        children = attrs;
        attrs = null;
      }

      /* not really attributes, but children! */
      if (attrs && (attrs instanceof Array)) {
        children = attrs;
        attrs = null;
      }

			var dump_attr = '';
      var attr_out;
      if (attrs != null) {
        /* THANKS IE!  You're so special! */
				if (attrs['className']) {
					newNode.className = attrs['className'];
				}

        for(attr in attrs) {
          if (attr == 'className') continue;

          newNode.setAttribute(attr, attrs[attr]);
        }
      }

      /* simple text, create a text node */
      if (typeof children == 'string') {
        newNode.appendChild(document.createTextNode(children));

        /* children to attach to this node */
      } else if (typeof children == 'object') {
        for(var i=0; i<children.length; i++) {
          if (typeof children[i] != 'object') {
            newNode.appendChild(document.createTextNode(children[i]));
          } else {
            newNode.appendChild(children[i]);
          }
        }
      }

      return newNode;
    }setContent - function(content) {
      newContent = content;
    }setTitle - function(title) {
      newTitle = title;
    }resetDialogContent - function(name) {
      document.getElementById(name)
      switch(name) {
        case 'text':
        case 'caption':
          this.setEmptyValue(name);
        break;

        case 'picture':
          this.setEmptyValue('pics_pb_url');
          this.setEmptyValue('pics_url');
        break;

        case 'theme':
          this.setEmptyValue('theme_pb_url');
          this.setEmptyValue('theme_url');
        break;

        case 'avatar':
          var select = document.getElementById('avatar_select');
          if (select) select.selectedIndex=0;

          this.setEmptyValue('avatar_username');
        break;
      };
    }modifiedAlert - function(e) {
      if (profileModified) {
        return 'Hey!  You modified your profile without saving it.\nDo you really want to leave without saving?';
			} else {
        return;
      }
		}loader - function() {
      profileLoader = new YAHOO.widget.Panel('profile_loading',
        { 'constraintoviewport': true,
          'close':false,
          'modal':true,
          'visible':true,
          'zIndex': "100000",
          'x':'200', 'y':'200',
          'width': 200,
          'draggable':'false'
         });

      profileLoader.setHeader('Loading');
      profileLoader.setBody('Please wait while we are loading the profile editor...');
      profileLoader.render(document.body);
      profileLoader.show();
		}checkSubmit - function() {
      if (document.getElementById('form_save')) {
        return true;
			}

      return false;
		}setEmptyValue - function(name) {
      var element = document.getElementById(name);
      if (element)
        element.value = '';
    }fireLoadGalleryPicturesTab - function(e, params) {
      gap.loadGalleryPicturesTab(params['name']);
    }loadGalleryPicturesTab - function(name) {
      if (loadedPicturesTab[name]) {
        return;
      }

      str = 'requested: ' + name + "\n";
      for(prop in this.galleryPictures) {
        str += prop + ': ' + this.galleryPictures[prop] + ', ';
      }

			//      alert(str);

      var id = this.galleryPictures[name]['id'];
      var pics = this.galleryPictures[name]['images'];
      var tab = document.getElementById('gallery_' + id);

      for(var i=0; i < pics.length; i++) {
        var add_node =	this.buildNode('a', {'className':'add centered', 'href':'#' }, 'add');

        var launch = {
          'pictureType':'gaia',
          'content': pics[i]['image']
        };

        YAHOO.util.Event.addListener(add_node, 'click', gap.fireCreatePictureNode, launch, true);
        YAHOO.util.Event.preventDefault(add_node);

        var node = this.buildNode('div', {'className': 'pic_gallery_item'}, 
          [
            this.buildNode('img', { 'width': 30, 'height': 30, 'src': 'http://' + this.GRAPHICS_SERVER + '/images/profiles/v2/picture_thumbs/' + pics[i]['thumb'] }),
            add_node
          ]);

        tab.appendChild(node);
      }

      loadedPicturesTab[name] = true;
    }fireLoadPhotobucketIFrame - function(e, params) {
      gap.loadPhotobucketIFrame(params['name']);
    }loadPhotobucketIFrame - function(name) {
      if(loadedPBFrame[name])
        return;

      var element = document.getElementById(name);

      var newNode = this.buildNode('iframe', { 'frameborder':'0', 'height':'300', 'width':'480', 'scrolling':'auto', 'src': 'http://photobucket.com/svc/jwidget.php?linkType=url&pbaffsite=47&width=450&height=250&largeThumb=false&url=http://' + this.MAIN_SERVER + '/profile/photobucket_callback.html' });

      var parent = element.parentNode;
      parent.insertBefore(newNode, element);
      parent.removeChild(element);

      newNode.id = name;

      loadedPBFrame[name] = true;
    }fireCreatePictureNode - function() {
      gap.pictureType = this.pictureType;
      gap.setContent('http://' + gap.GRAPHICS_SERVER + '/images/profiles/v2/pictures/' + this.content);
      gap.createNode('picture', null);
    }encode - function(str) {
      if (! str)
        return str;

      var encoded = str.replace(/=/g, '%3d');
      encoded = encoded.replace(/&/g, '%26');

      return encoded;
    }textify - function(text) {
      text = text.replace(/&lt;/g, '<');
      text = text.replace(/&gt;/g, '>');
      text = text.replace(/&amp;/g, '&');

      return br2nl(text);
    }panelStartDrag - function(clickEl) {
      YAHOO.log("evtStartDrag fired");
		
		// get the height the element began with
      var h = clickEl.offsetHeight;
      
      // find the tallest container of the bunch
      var tallest = 0;
      for (var i = 0; i < profile_columns.length; i++) {
        var el = YAHOO.util.Dom.get(profile_columns[i]);
        var height = el.offsetHeight;
      	// if (!YAHOO.util.Dom.isAncestor(el, clickEl)) {
      	// 	height = height + h;
      	// }
      	
        if (height > tallest) {
          tallest = height;
        }
      }
      
      if (tallest < YAHOO.util.Dom.getViewportHeight()) {
        tallest = YAHOO.util.Dom.getViewportHeight();
      }
      
      YAHOO.log("evtStartDrag adjusting profile_columns to "+tallest);
      
      for (var i = 0; i < profile_columns.length; i++) {
        var el = YAHOO.util.Dom.get(profile_columns[i]);
        if (el.offsetHeight < tallest) {
          YAHOO.util.Dom.setStyle(el, "height", tallest+"px");
        }
      }
    }panelEndDrag - function() {
      YAHOO.log("evtEndDrag fired");
		
      for (var i = 0; i < profile_columns.length; i++) {
        var el = profile_columns[i];
        YAHOO.util.Dom.setStyle(el, "height", "auto");
      }
    }checkAvatarSelection - function () {
      var select = document.getElementById('avatar_facing');
      if (this.avatarSize != 'body') {
        select.disabled = true;
  
        return;
      } else {
        select.disabled = false;
      }
    }bbcode - function(source, dest) {
      this.bbcode_dest = dest;

      var handleResponse = function(resp) {
        var bbcode_text = resp.responseText;

        document.getElementById(this.bbcode_dest).innerHTML = bbcode_text;
      }
  
      var handleError = function(resp) {
        alert('bbcode retrieval failed, please try again: ' + resp.statusText);
      }

      var callback = { 'success': handleResponse, 'failure': handleError, 'scope': gap };

      var requestUrl = '/account/?mode=preview';
      YAHOO.util.Connect.asyncRequest('POST', requestUrl, callback, 'content=' + source);
    }AVATAR_SERVER - a2.cdn.gaiaonline.comMAIN_SERVER - www.gaiaonline.comGRAPHICS_SERVER - s.gaiaonline.commaxZ - 1galleryPictures - [object Object]