/**
 * grouply.js
 *
 * The javascript infrastructure for the Grouply application
 *
 * @author Glenn R. Wichman, Heng Woon Ong, others
 * @copyright 2007 iGroup Network
 * @package js
 */

Grouply = {
  registry : {},
  form_registry : {},
  readies : [],
  xrcalled : false,
  currentPopin : null, 
  imgplus : "img/icons/plus.gif",
  imgminus : "img/icons/minus.gif",
  onReady : function(func, scope) {
    Ext.EventManager.onDocumentReady(func, scope);
    return;
    
    if (Grouply.xrcalled) {
      func.call(scope||window);
    } else {
      Grouply.readies.push([func, scope]);
    }
  },
  executeReadies : function() {
    for (var i = 0; i < Grouply.readies.length; i++) {
      var a = Grouply.readies[i];
      a[0].call(a[1]||window);
    }
    Grouply.xrcalled = true;
  },
  setCookie : function(name, value, days, path, domain, secure) {
    //domain = domain ? domain : "groupful.com";
    var expires = -1;
    if(typeof days == "number" && days >= 0) {
      var d = new Date();
      d.setTime(d.getTime()+(days*24*60*60*1000));
      expires = d.toGMTString();
    }
    value = escape(value);
    document.cookie = name + "=" + value + ";"
      + (expires != -1 ? " expires=" + expires + ";" : "")
      + (path ? "path=" + path : "path=/")
      + (domain ? "; domain=" + domain : "")
      + (secure ? "; secure" : "");
  },
  deleteCookie : function(name, path, domain) {
    if (Grouply.getCookie(name)) {
      s = name + "=" +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
      document.cookie = s;
    }
  },
  getCookie : function(name) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring( 0, name.length))) {
      return null;
    }
    if (start == -1) {
      return null;
    }
    var end = document.cookie.indexOf(";", len);
    if ( end == -1 ) {
      end = document.cookie.length;
    }
    return unescape(document.cookie.substring(len, end));
  },
  xsloaded : function() {
    Grouply.executeReadies();
    Grouply.makeHH();
    Grouply.deferredJs('contentHolder');
  },
  makeHH : function() {
    var root;    
    if (arguments.length == 1) {
      root = arguments[0]; 
    } else {
      root = document;
    }
    hoverels = Ext.DomQuery.select("*[class*=ca-hh]", root);
    for (var i = 0; i < hoverels.length; i++) {
      Ext.get(hoverels[i]).addClassOnOver("ca-h");
    }
  },
  newSearch : function(cfg) {
    if (typeof(cfg) == 'undefined') {
      cfg = "{}";
    } else if (typeof(cfg) != 'string') {
      cfg = Ext.util.JSON.encode(cfg);
    }
    Grouply.setCookie("searchcookie", cfg);
  },
  doSearch : function(cfg, pg) {
    if (typeof(cfg) == 'undefined') {
      cfg = {};
    } else if (typeof(cfg) == 'string') {
      cfg = Ext.util.JSON.decode(cfg);
    }
    cfg['clear'] = '1';
    if (typeof(pg) == 'undefined') {
      pg = "search";
    }
    action = Grouply.sitebase + pg;
    Grouply.post(action, cfg);
  },
  post : function(action, params, method) {
    if (typeof(method) == 'undefined') {
      method = 'POST';
    }
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", action);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);
    form.submit();
  },
  changeGroup : function(el) {
    var v = el.getValue();
    if (v != 0) {
      document.location.href = "http://" + v + "/home";
    }
  },
  register : function(id, obj) {
    Grouply.registry[id] = obj;
  },
  unregister : function(myid) {
   delete Grouply.registry[myid];
   if (Ext.get(myid))
   {
    Ext.get(myid).remove();
   }
  },
  get : function(id) {
    return Grouply.registry[id];
  },
  refreshActiveTab : function(tsname) {
    var ts = Grouply.get(tsname);
    if (ts) {
      var mytab = ts.getActiveTab();
      if (mytab) {
        Grouply.refreshTab(mytab);
      }
    }
  },
  refreshTab : function(mytab) {
    mytab.doAutoLoad();
    mytab.isDirty = false;
  },
  imgstring : function(img) {
    if (img.indexOf("/") != -1) {
      return img;
    }
    return "/grouply/img/icons/digest/" + img + ".gif";
  },
  tabstring : function(img, txt, wid) {
    var s;
    // Hate to do browser specific code, but can't find a way around it yet...
    if (Ext.isIE) {
      var txwid = wid - 34;
      s= "<div style='width:" + wid + "px'>"
        + "<div style='width:34; float:left;'>"
        + "<img src='" + Grouply.imgstring(img) + "'></div>"
        + "<div style='width:" + txwid + "; float:right; text-align:center; padding-top:8px'>" + txt + "</div>"
        + "</div>";
    } else {
      s= "<table style='width:" + wid + "px'><tbody><tr><td>"
        + "<div><img src='" + Grouply.imgstring(img) + "'></div>"
        + "</td><td><div style='text-align:left'>"
        + txt
        + "</div></td></tr></tbody></table>";
    }
    return s;
  },
  tabstring20 : function(img, txt, wid) {
    var s = "<table style='width:" + wid + "px'><tbody><tr><td width=1>"
        + "<img src='" + Grouply.imgstring(img) + "'>"
        + "</td><td align=left>"
        + txt
        + "</td></tr></tbody></table>";
    return s;
  },
  activateTab : function (tab) {
    if (tab.ownerCt.sticky) {
      UiState.set(tab.ownerCt.qid, "at", tab.id);
    }
    if (tab.isDirty) {
      Grouply.refreshTab(tab);
    }
  },
  tabsetDirty : function (tsname) {
    var ts = Grouply.get(tsname);
    ts.items.each(function(tab){tab.isDirty=true});
    Grouply.refreshActiveTab(tsname);
  },
  debugObj : function(obj) {
    var s = "<table border=1 cellspacing=0>";
    for (var a in obj) {
      s += "<tr><td>" + a + "</td><td>" + (typeof obj[a]) + "</td><td>" + obj[a] + "</td></tr>";
    }
    return s + "</table>";
  },
  setattrs : function(ar, attr, val) {
    for (var i=0; i < ar.length; i++) {
      ar[i][attr]=val;
    }
  },
  setstyles : function(ar, attr, val) {
    for (var i=0; i < ar.length; i++) {
      ar[i].style[attr] = val;
    }
  },
  togglePortlet : function (pname, qid) {
    var divel = document.getElementById(pname + '_content');
    if (divel) {
      if (divel.style.display == "none") {
        Grouply.openPortlet(pname, qid);
      } else {
        Grouply.closePortlet(pname, qid);
      }
    }
  },
  openPortlet : function(pname, qid) {
    var divel = document.getElementById(pname + '_content');
    if (divel) {
      if (divel.style.display != "none") {
        return; //already open
      }
      var imgel = document.getElementById(pname + '_toggle');
      divel.style.display = "block";
      imgel.src = Grouply.imgminus;
      collapsed = false;
      Grouply.loadOnExpand(pname);
      if (qid) {
        UiState.set(qid, "c", false);
      }
    }
  },
  closePortlet : function(pname, qid) {
    var divel = document.getElementById(pname + '_content');
    if (divel) {
      if (divel.style.display == "none") {
        return; //already closed
      }
      var imgel = document.getElementById(pname + '_toggle');
      divel.style.display = "none";
      imgel.src = Grouply.imgplus;
      collapsed = true;
      if (qid) {
        UiState.set(qid, "c", true);
      }
    }
  },
  allPortlets : function(root, func) {
    var clist = Ext.DomQuery.select("div[class*=collapse][id$=_title]", root);
    for (var i = 0; i < clist.length; i++) {
      el = clist[i];
      var pname = el.id.substr(0, el.id.length - 6);
      var gobj = Grouply.get(pname);
      if (gobj) {
        func(pname, gobj.qid);
      }
    }
  },
  loadOnExpand : function(pname) {
    var portlet = Grouply.get(pname);
    if (portlet) {
      if (portlet.loadonexpand && portlet.ajax && portlet.file) {
        file_el = document.getElementById(pname + "_file");
        if (file_el) {
          if (file_el.innerHTML == "") {
            Grouply.ajaxloadportlet(pname, portlet.file, portlet.params, eval(portlet.callback));
          }
        }
      }
    }
  },
  reloadPortlet : function(pname) {
    var portlet = Grouply.get(pname);
    if (portlet) {
      if (portlet.file) {
        file_el = document.getElementById(pname + "_file");
        if (file_el) {
          Grouply.ajaxloadportlet(pname, portlet.file, portlet.params, eval(portlet.callback), false, true);
        }
      }
    }
  },
  popin : {
    on : function(id, eventName, handler) {
      var dcode = Grouply.get(id);
      if (dcode) {
        var dialog = dcode.get();
        if (dialog) {
          dialog.on(eventName, handler);
        }
      }
    },
    show : function(id, trigger, position, callback) {
      var dcode = Grouply.get(id);
      if (dcode) {
        if (!dcode.loaded) {
          Grouply.popin.ajaxShow(id, false, false, false, callback, false, trigger, position);
          return;
        }
        var dialog = dcode.get();
        if (dialog) {
          if (position) {
            dialog.alignTo(trigger, position);
          }
          dialog.show(trigger, callback);
        } 
      }
    },
    align : function(id, trigger, position) {
      if (!trigger) {
        trigger = document.body;
      }
      if (!position) {
        position = "c-c";
      }
      var dcode = Grouply.get(id);
      if (dcode) {
        var dialog = dcode.get();
        if (dialog) {
          if (position) {
            dialog.alignTo(trigger, position);
          }
        } 
      }
    },
    hide : function(id, callback) {
      var dcode = Grouply.get(id);
      if (dcode) {
        var dialog = dcode.get();
        if (dialog) {
          dialog.hide(null, callback);
        }
      }
    },
    setTitle : function(id, title) {
      var dcode = Grouply.get(id);
      if (dcode) {
        var dialog = dcode.get();
        if (dialog) {
          dialog.setTitle(title);
        }
      }
    },
    ajaxShow : function(id, page, params, customTitle, callback, loadScripts, trigger, position) {
      Grouply.currentPopin=id;
      var dcode = Grouply.get(id);
      var dialog = dcode.get();

      if (!page) {
        page = dcode.page();
        if (!page) {
          return;
        }
      }
      if (!params) {
        params = dcode.params();
      }
      if (!trigger) {
        trigger = document.body;
      }
      if (!position) {
        position = "c-c";
      }
      if (customTitle) {
        Grouply.popin.setTitle(id, customTitle);
      }
      
      dialog.on('show', function(){Grouply.deferredJs(id + "_content", callback);}, dialog, { single : true } );
      
      if (params) {
        if (typeof(params) == "string") {
          params += "&page=" + Grouply.currentPopin;
        } else {
          params.page = Grouply.currentPopin;
        }
      }
      
      Grouply.ajaxload(Grouply.currentPopin+'_content', page, 
        params, 
        function() {
          var cp = Grouply.currentPopin + "_content";
          var cpi = document.getElementById(cp).innerHTML;
          if (cpi != "") {
            var dd = Grouply.get(Grouply.currentPopin);
            if (!dd.refresh) {
              dd.loaded = true;
            }
            
            if (position) {
              dialog.alignTo(trigger, position);
            }
            dialog.show(trigger, callback);
          }
        },
        loadScripts);
    },
    
    resizeToContent : function(popinid, resizeWidth, maxwid, maxheight)
    {
      var dialog = Grouply.get(popinid).get();
      var frameheight = dialog.getFrameHeight();
      var contentheight = Ext.get(popinid+"_content").getHeight();
      var newheight = frameheight + contentheight;
      if (maxheight) {
        if (newheight > maxheight) {
          newheight = maxheight;
        }
      }
      dialog.setHeight(newheight);
      if (resizeWidth) {
        var framewidth = dialog.getFrameWidth();
        var contentwidth = Ext.get(popinid+"_content").getWidth();
        var newwidth = framewidth + contentwidth;
        if (maxwid) {
          if (newwidth > maxwid) {
            newwidth = maxwid;
          }
        }
        dialog.setWidth(newwidth);
      }
    },
    
    fixYMapOverlap : function (popinid)
    {
      if (Ext.get('mapContainer'))
      {
        if ( (Ext.get('mapContainer').child('embed', true) && Ext.get('mapContainer').child('embed', true).src.match(/http:\/\/maps.yahooapis.com\//)) || (Ext.get('mapContainer').child('param[name=movie]', true) && Ext.get('mapContainer').child('param[name=movie]', true).value.match(/http:\/\/maps.yahooapis.com\//)) )
        {
          bmright = Grouply.get(popinid).get().getEl().getRight();
          bmtop = Grouply.get(popinid).get().getEl().getTop();
          bmbtm = Grouply.get(popinid).get().getEl().getBottom();
          maptop = Ext.get('mapContainer').getTop();
          mapbtm = Ext.get('mapContainer').getBottom();
          mapleft = Ext.get('mapContainer').getLeft();
          if ( ( (bmtop > maptop && bmtop < mapbtm) || (maptop > bmtop && maptop < bmbtm) || !(mapbtm < bmtop && mapbtm < bmbtm) ) && bmright > mapleft)
          {
            Grouply.get(popinid).get().alignTo(Ext.get('mapContainer'), 'r-l?');
          }
        }
      }

    }
  },
  ajaxtimeout : 180000,
  ajaxload : function (div, url, params, callback, loadScripts, noIndicator) {
    var el = Ext.get(div);
    
    if (el) {
      var mgr = el.getUpdateManager();
      mgr.loadScripts = loadScripts ? true : false;
      mgr.showLoadIndicator = noIndicator ? false : true;
      mgr.timeout = Grouply.ajaxtimeout;
      el.load(url, params, callback);
    }
  },
  ajaxloadportlet : function(div, url, params, callback, loadScripts, noIndicator) {
    cb = function(){Grouply.deferredJs(div, callback);};
    Grouply.ajaxload(div + "_file", url, params, cb, loadScripts, noIndicator);
  },
  ajaxloadform : function (div, formid, callback, loadScripts, noIndicator) {
    if (typeof(formid) == "string") {
      formid = document.getElementById(formid);
    }
    var url = formid.action;
    var formstring = Ext.Ajax.serializeForm(formid);
    Grouply.ajaxload(div, url, formstring, callback, loadScripts, noIndicator);
  },
  addParam : function(params, name, value) {
    if (params) {
      if (typeof(params) == "string") {
        params += "&" + name + "=" + encodeURIComponent(value);
      } else {
        params[name] = value;
      }
    } else {
      params = {};
      params[name] = value;
    }
    return params;
  },
  
  /**
   *
   * callback {Function} (Optional) The function to be called upon receipt of the HTTP response. 
   * The callback is called regardless of success or failure and is passed the following parameters:
   
       * options {Object} The parameter to the request call.
       * success {Boolean} True if the request succeeded.
       * response {Object} The XMLHttpRequest object containing the response data.
   */
  ajax : function (url, params, callback, object) {
    Ext.Ajax.timeout = Grouply.ajaxtimeout;
    if (!object) {
      object = {};
    }
    if (url) {
      object.url = url;
    }
    if (params) {
      object.params = params;
    }
    if (callback) {
      object.callback = callback;
    }
    return Ext.Ajax.request(object);
  },
  ajaxform : function(formid, callback, object) {
    if (typeof(formid) == "string") {
      formid = document.getElementById(formid);
    }
    var url = formid.action;
    var formstring = Ext.Ajax.serializeForm(formid);
    Grouply.ajax(url, formstring, callback, object);
  },
  ajaxform2 : function(formid, callback, object) {
    var formobj = Ext.getDom(formid);
    var url = formobj.action;
    if (!object) {
      object = {};
    }
    object.form = formobj;
    object.url = url;
    object.callback = callback;
    Grouply.ajax(url, null, null, object);
  },
  updateActionStatus : function() {
    Grouply.ajaxload("actionStatusHolder", "actionstatus.pagelet.php", false, false, false, true);
  },
  combobox : {
    setValue : function(cb, value) {
      if (typeof(cb) == 'string') {
        cb = Grouply.get(cb);
      }
      cb.setValue(value);
      if (cb['autowidthobj']) {
        cb.autowidthobj.onselect(cb);
      }
    }
  },
  editor : {
    converts : { "8217" : "'", "8220" : '"', "8221" : '"' },
    getValue : function(id) {
      var ed = Grouply.get(id);
      if (ed) {
        return ed.getRawValue(); // use rawvalue instead of value since it forces push/sync to fire, causing issues with bind components.
      }
      return "";
    },
    setValue : function(id, value) {
      var ed = Grouply.get(id);
      if (ed) {
        ed.setValue(value);
      }
    },
    clean : function (str) {
      var newstr = str;
      for (var i = 0; i < str.length; i++) {
        var j = str.charCodeAt(i);
        if (j > 127) {
          var newchar = "?";
          if (Grouply.editor.converts[""+j]) {
            newchar = Grouply.editor.converts[""+j];
            newstr = newstr.substr(0,i) + newchar + newstr.substr(i+1);
          }
        }
      }
      return newstr;
    },
    cleanValue : function(id) {
      return Grouply.editor.clean(Grouply.editor.getValue(id));
    },
    cleanEditor : function(id) {
      Grouply.editor.setValue(id, Grouply.editor.cleanValue(id));
    },
    hideSwitcher : function(id) {
      var el = document.getElementById(id + "_editorSwitcher");
      if (el) {
        el.style.visibility = "hidden";
      }
    },
    showSwitcher : function(id) {
      var el = document.getElementById(id + "_editorSwitcher");
      if (el) {
        el.style.visibility = "visible";
      }
    }
  },
  
  clearText : function (thefield, defaultVal) {
    if (thefield.value==defaultVal) 
    {
      thefield.value = "";
    }else if (thefield.value=="")
    {
      thefield.value=defaultVal;
    }
  },
  
  findValueText : function(combodata, value) {
    for (var i = 0; i < combodata.length; i++) {
      var pair = combodata[i];
      if (pair[0] == value) {
        return pair[1];
      }
    }
    return null
  },
  
  stickCombo : function(el) {
    UiState.set(el.qid, "v", el.getValue());
  },
  
  inArray : function(ar, val) {
    for (var i = 0; i < ar.length; i++) {
      if (ar[i] == val) {
        return true;
      }
    }
    return false;
  },
  
  renderEditor : function(editorid) 
  { 
    if (!document.getElementById(editorid) || document.getElementById(editorid).innerHTML!="") 
    { 
      return true; 
    } 
                       
    eval("Grouply.onReady("+editorid+"_code.init,"+editorid+"_code);"); 
     
  },
  
  renderComponent : function(cmpid) 
  {

    if (!Ext.get(cmpid) || Ext.get(cmpid).dom.innerHTML != "") 
    { 
      return; 
    } 
                       
    eval("Grouply.onReady("+cmpid+"_code.init,"+cmpid+"_code);"); 
     
  },
  
  reRenderComponent : function (cmpid)
  {
    var comp = Grouply.get(cmpid);
    if (comp) {
      comp.destroy();
    }
    eval(cmpid + "_code.init()");
  },
   
  hideEl : function(id) 
  { 
    if (el = Ext.get(id)) 
    { 
      el.setVisibilityMode(Ext.Element.DISPLAY); 
        el.hide(); 
    } 
  }, 
     
  showEl : function (id, fn) 
  { 
    if (el = Ext.get(id)) 
    { 
      el.setVisibilityMode(Ext.Element.DISPLAY); 
      if (el.isDisplayed())
      {
        return;
      }
      el.show({ 
            duration: 0.35, 
            callback: fn 
      }); 
    } 
  },
  
  isFormValid : function (formid)
  {
    var myform = document.getElementById(formid);
    
    if (!myform)
    {
      return false;
    }
    
    for (i=0;i<myform.length;i++)
    {
      if (myform[i].tagName == "input" || myform[i].tagName == "INPUT" || myform[i].tagName == "textarea" || myform[i].tagName == "TEXTAREA")
      {
        extel = Grouply.get(myform[i].name);
        if (!extel) continue;
        
        if (!extel.validate())
        {
          return false;
        }
      }
    }
    
    return true;
  },
  
  resetEmptyText : function()
  {
    if(this.getRawValue() == "")
    {
      this.setValue('');
      this.lastSelectionText = '';
    } 
    
  },
  
  clearFormEmptyText : function (formid)
  {
    var myform = document.getElementById(formid);
    
    if (!myform)
    {
      return false;
    }
    
    Grouply.form_registry[formid] = {};
    
    for (i=0;i<myform.length;i++)
    {
      if (myform[i].tagName == "input" || myform[i].tagName == "INPUT" || myform[i].tagName == "textarea" || myform[i].tagName == "TEXTAREA")
      {
        extel = Grouply.get(myform[i].name);
        if (!extel) continue;
        Grouply.form_registry[formid][myform[i].name] = extel.getRawValue();
        if (extel && extel.el.dom.value == extel.emptyText)
        {
          
          extel.el.dom.value='';
        } 
      }
    }
  },
  
  restoreFormValues : function(formid)
  {
    for (key in Grouply.form_registry[formid])
    {
      if (el = Grouply.get(key))
      {
        el.setValue(Grouply.form_registry[formid][key]);
      }
    }
  },
  
  submitForm : function (formid, clearEmptyText, checksubmit)
  {
    var myform = document.getElementById(formid);
    
    if (!myform)
    {
      return false;
    }
    
    if (clearEmptyText)
    {
      Grouply.clearFormEmptyText(formid);
    }
    
    if (checksubmit) {
      if (myform.onsubmit && !(myform.onsubmit())) {
        return false;
      }
    }
    
    myform.submit();
  },
  
  checkMaxLength : function (myid, maxlen, charsRemainingBind)
  {
    el = Grouply.get(myid);
    if (el)
    {
      oldval = el.getValue();
      oldval_length = oldval.length;
      if (oldval_length > maxlen)
      {
        el.setValue(oldval.substr(0,maxlen));
        oldval_length = maxlen;
      }
      
      if (charsRemainingBind)
      {
        bindEl = Ext.get(charsRemainingBind);
        if (bindEl)
        {
          charsRemaining = maxlen - oldval_length;
          bindEl.dom.innerHTML = charsRemaining;
        }
        
      }
    }
  },
  
  messageBox : {
    show : function (title, msg)
    {
      Ext.MessageBox.show({
        title : title,
        msg : msg,
        buttons: Ext.MessageBox.OKCANCEL,
        closable:true,
        progress:false,
        modal:false,
        width:300,
        cls : "co-o"
      });
    },
      
    hide : function (delay)
    { 
      if (delay)
      {
        setTimeout("Grouply.messageBox.hide()", delay);
      } 
      else
      {
        Ext.MessageBox.hide();
      }
    },
    
    // TODO: fix this by adding a shim?
    fixYMapOverlap : function ()
    {
      if (Ext.get('mapContainer'))
      {
        if ( (Ext.get('mapContainer').child('embed', true) && Ext.get('mapContainer').child('embed', true).src.match(/http:\/\/maps.yahooapis.com\//)) || (Ext.get('mapContainer').child('param[name=movie]', true) && Ext.get('mapContainer').child('param[name=movie]', true).value.match(/http:\/\/maps.yahooapis.com\//)) )
        {
          bmright = Ext.MessageBox.getDialog().getEl().getRight();
          bmtop = Ext.MessageBox.getDialog().getEl().getTop();
          bmbtm = Ext.MessageBox.getDialog().getEl().getBottom();
          maptop = Ext.get('mapContainer').getTop();
          mapbtm = Ext.get('mapContainer').getBottom();
          mapleft = Ext.get('mapContainer').getLeft();
          if ( ( (bmtop > maptop && bmtop < mapbtm) || (maptop > bmtop && maptop < bmbtm) || !(mapbtm < bmtop && mapbtm < bmbtm) ) && bmright > mapleft)
          {
            Ext.MessageBox.getDialog().alignTo(Ext.get('mapContainer'), 'r-l?');
          }
        }
      }

    }
  },
  
  progressBar : {
    timer : null,
    
    show : function (title, msg)
    {
      Ext.MessageBox.show({
        title : title,
        msg : msg,
        buttons: false,
        closable:false,
        progress:true,
        modal:true,
        width:300,
        cls : "co-o"
      });
      
      Grouply.progressBar.timer = {
          run: function(i){
              if (i>5)
              {
                i=(i%5)+1;
              }
              Ext.MessageBox.updateProgress(i/5);
          },
          interval: 1000
      };
      
      Ext.TaskMgr.start(Grouply.progressBar.timer);
    },
    
    hide : function (msg, delay)
    {

        Ext.MessageBox.minWidth = 300;
        Grouply.progressBar.finish(msg);

      
      if (delay)
      {
        setTimeout("Grouply.progressBar.hide()", delay);
      } else
      {
        Ext.MessageBox.hide();
      }
    },
    
    finish : function (msg)
    {
      if (Grouply.progressBar.timer) {
        Ext.TaskMgr.stop(Grouply.progressBar.timer);
        Ext.MessageBox.updateProgress(1, null, msg);
        Grouply.progressBar.fixYMapOverlap();
      }
    },
    
    fixYMapOverlap : function ()
    {
      if (Ext.get('mapContainer'))
      {
        if ( (Ext.get('mapContainer').child('embed', true) && Ext.get('mapContainer').child('embed', true).src.match(/http:\/\/maps.yahooapis.com\//)) || (Ext.get('mapContainer').child('param[name=movie]', true) && Ext.get('mapContainer').child('param[name=movie]', true).value.match(/http:\/\/maps.yahooapis.com\//)) )
        {
          bmright = Ext.MessageBox.getDialog().getEl().getRight();
          bmtop = Ext.MessageBox.getDialog().getEl().getTop();
          bmbtm = Ext.MessageBox.getDialog().getEl().getBottom();
          maptop = Ext.get('mapContainer').getTop();
          mapbtm = Ext.get('mapContainer').getBottom();
          mapleft = Ext.get('mapContainer').getLeft();
          if ( ( (bmtop > maptop && bmtop < mapbtm) || (maptop > bmtop && maptop < bmbtm) || !(mapbtm < bmtop && mapbtm < bmbtm) ) && bmright > mapleft)
          {
            Ext.MessageBox.getDialog().alignTo(Ext.get('mapContainer'), 'r-l?');
          }
        }
      }

    }
  },
  
  showUpdatableProgressBar : function (title, msg)
  {
    
    Ext.MessageBox.show({
        title : title,
        msg : msg,
        buttons: false,
        closable:false,
        progress:true,
        modal:true,
        width:300,
        wait:false,
        cls:"co-o"
    });
  }, 
  
  updateUpdatableProgressBar : function (msg, progress) 
  {
    Ext.MessageBox.updateText(msg);
    Ext.MessageBox.updateProgress(progress);
  },
  
  // if alertMsg is set, will display a normal alert box with alertMsg and an OK button, where clicking on OK will hide MessageBox
  hideUpdatableProgressBar : function (alertMsg, alertTitle)
  {
    if (alertMsg && alertMsg != '')
    {
      Ext.MessageBox.minWidth = 300;
      Grouply.alert(alertMsg, alertTitle);
    } else
    {
      Ext.MessageBox.hide();
    }
  },
  
  alert : function(msg, title, fn, scope, buttons) {
    if (!title) {
      title = "Grouply";
    }
    if (!buttons) {
      buttons = Ext.MessageBox.OK;
    }
    Ext.MessageBox.show({
        title : title,
        msg : msg,
        buttons: buttons,
        fn: fn,
        scope : scope,
        cls : "co-o"
    });
  },
  confirm : function(msg, yesfunc, nofunc, title, yesno) {
    if (!nofunc) {
      nofunc = Grouply.confirmNoFuncDefault;
    }
    if (!title) {
      title = "Grouply";
    }
    btns = Ext.Msg.OKCANCEL;
    if (yesno === true) {
      btns = Ext.Msg.YESNO;
    } else if (yesno) {
      btns = yesno;
    }
    
    Grouply.confirmYesFunc = yesfunc;
    Grouply.confirmNoFunc = nofunc;

    Ext.Msg.show({
       title: title,
       msg: msg,
       buttons: btns,
       fn: Grouply.confirmConfirm,
       cls : "co-o"
    });
  },
  
  confirmConfirm : function (btn) {
    Ext.Msg.hide();
    if (btn == 'ok' || btn == 'yes'){
      Grouply.confirmYesFunc();
    } else {
      Grouply.confirmNoFunc();
    }
  },
  
  confirmNoFuncDefault : function () {
  },

  pressable : function (elname) {
    var el = document.getElementById(elname);
    el.onmousedown = Grouply.pressableMouseDown;
    el.onmouseup = Grouply.pressableMouseUp;
    el.onmouseout = Grouply.pressableMouseUp;
  },
  pressableMouseUp : function(e) {
    var evt = window.event? window.event : e;
    targ = evt.srcElement ? event.srcElement : e.target;
    css = targ.className;
    var p = css.indexOf("Pressed");
    if (p != -1) {
      targ.className = css.substring(0, p);
    }
  },
  pressableMouseDown : function(e) {
    var evt = window.event? window.event : e;
    targ = evt.srcElement ? event.srcElement : e.target;
    css = targ.className;
    if (css.indexOf("Pressed") == -1) {
      targ.className = css + "Pressed";
    }
  },
  stuckTab : function(element, dflttab) {
    stuck = null;
    if (element.sticky) {
      stuck = UiState.get(element.qid, "at");
    }
    return stuck ? stuck : dflttab;
  },
  
  copyObj : function (from)
  {
    if (Grouply.isArray(from))
    {
      to = [];
    } else
    {
      to = {};
    }
    
    for(i in from)
    {
      to[i]=from[i];
    }
    return to;
  },
  
  isArray : function (obj)
  {
    return (typeof(obj) == 'object' && obj.length >= 0);
  },
  
  elipsis : function(str, max) {
    if (str.length > max) {
      str = str.substring(0, max -3) + "...";
    }
    return str;
  },
  eventInBox : function(event, box) {
    var point = event.getXY();
    var rect = box.getBox();
    return (point[0] >= box.x && point[0] <= box.x + box.width && point[1] >= box.y && point[1] <= box.y + box.height);
  },
  
  toggleQuote : function (qdiv) {
    var pel = document.getElementById(qdiv);
    var qel = document.getElementById("q" + qdiv);
    if (pel && qel) {
      if (pel.name == 'quote_shown') {
        pel.name = 'quote_hidden';
        pel.innerHTML = "- Show quoted text -";
        qel.style.display = "none";
      } else {
        pel.name = 'quote_shown';
        pel.innerHTML = "- Hide quoted text -";
        qel.style.display = "block";
      }
    }
  },
  
  toggleResponse : function (qdiv) {
    var pel = document.getElementById(qdiv);
    var qel = document.getElementById("q" + qdiv);
    if (pel && qel) {
      if (pel.name == 'quote_shown') {
        pel.name = 'quote_hidden';
        pel.innerHTML = "- Show signup responses -";
        qel.style.display = "none";
      } else {
        pel.name = 'quote_shown';
        pel.innerHTML = "- Hide signup responses -";
        qel.style.display = "block";
      }
    }
  },
  
  insertSig : function (sigDivId, editorid, htmldecode)
  { 
    var sigvalue = "";
    var sigDiv = Ext.get(sigDivId);
    if (!sigDiv)
    {
      return;
    }
    
    sigDiv = sigDiv.dom;
    
    el = Grouply.get(editorid);
    
    sig = '\n\n' + sigDiv.innerHTML;
     
    if (htmldecode)
    {
      sig = Ext.util.Format.htmlDecode(sig);
    }
    
    if (el.tb && el.iframe)
    {
      sig = sig.replace(/\n/g, "<br/>");
    }
    
    Grouply.editor.setValue(editorid, sig);
    
  
  },
  
  mailto : function(encodedemail) {
    SendEmail.openEmailPopin('sendamessage', "sendas=text&coded_email=" + encodeURIComponent(encodedemail), 'Send an email');
  },
  
  lastSelect : true,
  
  cbSelect : function(div, check, feedback, callback) {
    Grouply.lastSelect = check;
    var checkboxes = Ext.DomQuery.select('div[id=' + div + '] input[type=checkbox]');
    for (var i = 0; i < checkboxes.length; i++) {
      var el = checkboxes[i];
      if (!el.disabled) {
        el.checked = check;
      }
      if (feedback) {
        feedback(el);
      }
    }
    
    if (callback)
    {
      callback();
    }
  },
  
  navtab : function(panel, tab) {
    var dest = panel.destinations[panel.activeTab.title];
    if (dest) {
      if (Grouply.sitebase) {
        if (dest != panel.currentpage) {
          document.location.href = Grouply.sitebase + dest;
        }
      }
    }
  },
  
  displayDelayed : function() {
    for (var i = 0; i < Grouply.delayed.length; i++) {
      var divc = Grouply.delayed[i];
      var dive = document.getElementById("pagedelay_"+i);
      if (dive) {
        dive.innerHTML = divc;
      }
    }
  },
  
  href : {
    php : "",
    group : function(prov, gname) {
      return Grouply.sitebase + "group" + Grouply.href.php + "/" + prov + "/" + gname;
    },
    message : function(prov, gname, msgnum) {
      return Grouply.sitebase + "message" + Grouply.href.php + "/" + prov + "/" + gname + "/" + msgnum;
    }
  },
  
  selectLink : function(sel) {
    var combo = Grouply.get("actionrequiredcombo");
    var dest;
    if (combo) {
      dest = combo.getValue();
    } else {
      dest = sel.value;
    }
    document.location.href = dest;
  },
  
  deferredJs : function(container, callback) {
    var root = document.getElementById(container);
    if (!root) {
      root = document;
    }
    Grouply.dfjsq = Ext.DomQuery.select("script[language=grouplyscript][class*=dj-" + container + "]", root);
    var q = Grouply.dfjsq;
    Grouply.dfjscb = callback;
    Grouply.processDfjsq();
  },
  processDfjsq : function() {
    if (Grouply.dfjsq.length == 0) {
      if (Grouply.dfjscb) {
        Grouply.dfjscb();
      }
      return;
    }
    var scri = Grouply.dfjsq.shift();
    if (scri.src) {
      Grouply.loadJsFile(scri.src, Grouply.processDfjsq);
    } else {
      // maybe better to use firstChild.nodeValue ?
      var js = scri.innerHTML;
      setTimeout(js, 0);
      Grouply.processDfjsq();
    }
  },  
  loadJsFile : function(fname, cb) {
    if (typeof(Grouply.loadedjsfiles[fname]) == "undefined") {
      Grouply.loadedjsfiles[fname] = true;
      var el = document.createElement('script');
      el.setAttribute("type", "text/javascript");
      el.setAttribute("language", "JavaScript");
      el.setAttribute("src", fname);
      if (cb) {
        el.onload = cb;
        el.onreadystatechange = cb;
      }
      document.getElementsByTagName("head")[0].appendChild(el);
    } else if (cb) {
      cb();
    }
  },
  loadedjsfiles : {},
  
  convertTable : function(tableel) {
    if (!tableel)
    {
      return;
    }
    
    var container = Ext.Element.get(tableel).parent().dom;

    var tr = Ext.DomQuery.selectNode("tr", tableel);
    var td = Ext.DomQuery.selectNode("td.x-toolbar-cell", tableel);
    var tablediv = document.createElement("div");
    while(td) {
      tddiv = document.createElement("div");
      if (td.id) {
        tddiv.id = td.id;
      }
      
      tddiv.style.cssText = 'float:left;min-height:20px';
      tddiv.setAttribute('style', 'float:left;min-height:20px');
      if (td.firstChild && !td.firstChild.className.match(/x-toolbar-more/))
      {
        tddiv.appendChild(td.firstChild);
        tablediv.appendChild(tddiv);
      }
      
      td.parentNode.removeChild(td);
      td = Ext.DomQuery.selectNode("td.x-toolbar-cell", tableel);
    }
    ldiv = document.createElement("div");
    ldiv.style.cssText = 'clear:left';
    ldiv.setAttribute('style', 'clear:left');
    tablediv.appendChild(ldiv);
    container.replaceChild(tablediv, tableel);
  },
  
  convertEditorToolbar : function(editor_id) {
    var ed = Ext.DomQuery.selectNode("div[id="+ editor_id + "] div[class*=x-small-editor] table[class*=x-toolbar-ct]");
    Grouply.convertTable(ed);
  },
  
  addStylesheet : function(fname) {
    var url = Grouply.sitebase + "/css/" + fname + ".css?v=" + Grouply.version;
    var id = "css_" + fname + "_css";
    var existing = document.getElementById(id);
    if (existing) {
      return;
    }
    var ss = document.createElement("link");
    ss.setAttribute("rel", "stylesheet");
    ss.setAttribute("type", "text/css");
    ss.setAttribute("id", id);
    ss.setAttribute("href", url);
    document.getElementsByTagName("head")[0].appendChild(ss);
  },
  
  menu : {
    click : function(e) {
      var tt = e.getTarget("div[name^=mi_]");
      if (!tt) {
        return;
      }
      var name = tt.getAttribute('name');
      if (!name) {
        return;
      }
      name = name.substr(3);
      var menu = Grouply.menu.menus[tt.parentNode.id];
      if (menu.val != name) {
        if (menu.val) {
          var el = Ext.get(menu.id).child("div[name=mi_"+menu.val+"]");
          if (el) {
            el.removeClass(menu.scs);
          }
        }
        Ext.get(tt).addClass(menu.scs);
        menu.val = name;
        menu.text = Ext.get(tt).first().dom.innerHTML;
        if (menu['trigger']) {
          Grouply.menu.hdOut(false);
        }
        if (menu.cb) {
          menu.cb(menu);
        }
      }
    },
    addCallback : function(id, cb) {
      Grouply.menu.menus[id].cb = cb;
    },
    clickCB : function(e, cb) {
      var id = e.getTarget("div[name^=mi_]").parentNode.id;
      var menu = Grouply.menu.menus[id];
      cb(menu);
    },
    clickHref : function(e, t) {
      if (t.tagName.toLowerCase() == "div") {
        var a = Ext.get(t).child('a');
        if (a) {
          var href = a.dom.getAttribute('href');
          if (href) {
            document.location.href = href;
          }
        }
      }
      return true;
    },
    init : function(id, val, scs, hdown, ap, anchor, trigger) {
      Grouply.menu.menus[id] = { val : val, scs : scs, id : id, ap : ap, cb : null };
      if (hdown) {
        var el = Ext.get(id);
        var trig = trigger ? trigger : el.prev();
        var anc = anchor ? Ext.get(anchor) : trig;
        el.appendTo(document.body);
        el.position('absolute');
        Grouply.menu.clearTriggers(id);
        Grouply.menu.addTrigger(id, trig, anc);
      }
    },
    addTrigger : function(id, trig, anc) {
      if (typeof(trig) == "string") {
        if (trig.indexOf("*") == 0) {
          Grouply.menu.addTriggers(id, trig);
          return;
        }
      }
      if (!anc) {
        anc = trig;
      }
      trig = Ext.get(trig);
      anc = Ext.get(anc);
      Grouply.menu.triggers.push({ id:id, trigger:trig, anchor:anc });
      trig.hover(Grouply.menu.hdIn, Grouply.menu.hdOut);
    },
    addTriggers : function(id, selector, root) {
      if (!root) {
        root = document;
      }
      els = Ext.DomQuery.select(selector, root);
      for (var i = 0; i < els.length; i++) {
        Grouply.menu.addTrigger(id, els[i]);
      }
    },
    clearTriggers : function(id) {
      nt = [];
      for (var i =0; i < Grouply.menu.triggers.length; i++) {
        var trig = Grouply.menu.triggers[i];
        if (trig.id != id) {
          nt.push(trig);
        }
      }
      Grouply.menu.triggers = nt;
    },
    fromTarget : function(t) {
      for (var i =0; i < Grouply.menu.triggers.length; i++) { 
        var trig = Grouply.menu.triggers[i];
        if (trig.trigger.dom == t) {
          var m = Grouply.menu.menus[trig.id];
          m.trigger = trig.trigger;
          m.anchor = trig.anchor;
          return m;
        }
      }
      return false;
    },
    hdIn : function(e, t) {
      if (Grouply.menu.currenthd) {
        return;
      }
      var m = Grouply.menu.fromTarget(this);
      if (m) {
        var mel = Ext.get(m.id);
        mel.show();
        mel.alignTo(m.anchor, m.ap);
        //var duration = mel.getHeight() * 0.002;
        var duration = 0.05;
        mel.slideIn('t', { duration : duration });
        Grouply.menu.currenthd = mel;
        Grouply.menu.currenttrigger = m.trigger;
        Ext.getBody().on('mouseout', Grouply.menu.hdOut);
      }
    },
    hdOut : function(e) {
      if (Grouply.menu.currenthd) {
        if (e) {
          var p = new Ext.lib.Point(e.getPageX(), e.getPageY());
          var r = Grouply.menu.currenthd.getRegion();
          if (r.contains(p)) {
            return;
          }
          r = Grouply.menu.currenttrigger.getRegion();
          if (r.contains(p)) {
            return;
          }
        }
        Ext.getBody().un('mouseout', Grouply.menu.hdOut);
        var m = Grouply.menu.currenthd;
        Grouply.menu.currenthd = null;
        m.slideOut('t', { duration : 0.05 });
      }
    },
    getValue : function(id) {
      var menu = Grouply.menu.menus[id];
      return menu ? menu.val : false;
    },
    menus : {},
    triggers : []
  }
  
};

Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

/**
 * object UiState
 *
 * this parallels the php class UiState defined in {@link ext.classes.inc;php}
 * it manages all component stickiness.
 */
UiState = {
  retrieve : function() {
    var state = Grouply.getCookie('uistate');
    if (state == null || state == "null") {
      return {"owner":Grouply.username };
    }
    st = Ext.util.JSON.decode(state);
    if (st.owner != Grouply.username) {
      return {"owner":Grouply.username };
    }
    return st;
  },
  store : function(newstate) {
    Grouply.setCookie('uistate', Ext.util.JSON.encode(newstate));
  },
  set : function (element, state, value) {
    var uistate = UiState.retrieve();
    if (typeof(uistate[element]) == "undefined") {
      uistate[element] = {};
    }
    uistate[element][state] = value;
    UiState.store(uistate);
  },
  get : function (element, state, dflt) {
    if (typeof(dflt) == "undefined") {
      dflt = null;
    }
    var uistate = UiState.retrieve();
    if (typeof(uistate[element]) == "undefined" ) {
      if (dflt != null) {
        //UiState.set(element, state, dflt);
      }
      return dflt;
    }
    if (typeof(uistate[element][state]) == "undefined") {
      if (dflt != null) {
        //UiState.set(element, state, dflt);
      }
      return dflt;
    }
    return uistate[element][state];
  }
};

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
     var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
     var imgTitle = (myImage.title) ? 
                 "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
     var imgStyle = "display:inline-block;" + myImage.style.cssText
     var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
     myImage.outerHTML = strNewHTML   
    }
}

function togglecomments (cm_id) {

   var cm = document.getElementById(cm_id);
   toggle_cm_name = "cm_" + cm_id;
   if (cm.className=="showcomments") {
      cm.className="hidecomments";

    document.getElementById(toggle_cm_name).innerHTML="Show comments";
   }
   else {
      cm.className="showcomments";
    document.getElementById(toggle_cm_name).innerHTML="Hide comments";
   }
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function ShowShort( targetId ){
  var target = document.getElementById( targetId + "Long" );
    target.style.display = "none";
  target = document.getElementById( targetId + "Short" );
    target.style.display = "";
}

function ShowLong( targetId ){
  var target = document.getElementById( targetId + "Long" );
    target.style.display = "";
  target = document.getElementById( targetId + "Short" );
    target.style.display = "none";
}

function toggleSeeMore(id) {
  var el = document.getElementById(id+'_content');
  var el_toggler = document.getElementById(id+'_toggler');
  if (el)
  {
    if (el.style.display=="")
    {
      el.style.display="none";
      el_toggler.innerHTML = "see more";
    } else
    {
      el.style.display="";
      el_toggler.innerHTML = "see less";
    }
  }

}
