/*
 *
 * Author object
 *
 */

function Author(fname, lname, locale) 
{
   this.fname  = fname;
   this.lname  = lname;
   this.locale = locale;

   // methods
   this.display = DisplayAuthor;
}

function DisplayAuthor() 
{
   if( (this.fname == undefined || this.fname.length == 0) &&
       (this.fname == undefined || this.lname.length == 0) ){
      return( g_UNKNOWN );
   }
   else {
      if( this.locale == 1041 ) {       
         return( this.lname + ' ' + this.fname );
      }
      else {
         return( this.fname + ' ' + this.lname );      
      }
   }
}

/*
 *
 * Announcement Object
 *
 */

function Announcement(id, fid, text, priority, bIsNew, bIsEdited, author, date, type, position) {
   this.isFolder  = false;
   this.id        = id;
   this.folderid  = fid;
   this.text      = text;
   this.priority  = priority;
   this.bIsNew    = bIsNew;
   this.bIsEdited = bIsEdited;
   this.author    = author;
   this.date      = date;
   this.type      = type;
   this.position  = position;

   // methods
   this.display = DisplayAnnouncement;
}

function DisplayAnnouncement(AnnList) {

   var ico = (this.priority == 1) ? '/ico_urgent.gif' : '/tick2.gif';
   var text;
   var command;

   text = '';

   if (this.type == 'global') {
      command = 'global'


      if (this.position == 1) {

          text +=   '<div class="win-subsection-title-bar">' + AnnList.globalHeader + '</div>';

      }

   }
   else {
      command = 'detail'

      if (this.position == 1 && AnnList.global == true) {

          text +=   '<div class="win-subsection-title-bar">' + AnnList.localHeader + '</div>';

      }
   }

   text +=  '<div><table><tr><td width="16" align="center" valign="top">';

   // add bullet for top-level announcements
   if (this.folderid == -1) {
       text += '<img src="' + g_SITEIMAGEDIR + ico + '" border="0">';
   }
   else {
       text += '&nbsp;';
   }


   text += '</td>';

   // apend bullet for announcements in folder
   if (this.folderid != -1) {
       text += '<td width="12" align="center" valign="top">';
       text += '<img src="' + g_SITEIMAGEDIR + ico + '" align="middle" border="0"';

       if (this.priority == 1) {
           text += ' style="margin-right: 4px;"';
       }
       else {
           text += ' style="margin-left: 3px; margin-right: 7px;"';
       }

       text += '>';
       text += '</td>';
   }

   text += '<td align="left" valign="top" width="100%">';
   text += '<a href="/ann/default.asp?command=' + command + '&id=' + this.id + '" target="in_main"';

   text += (this.priority == 1) ? ' class="link-important"' : '';

   text += '>' + this.text;

   text += '</a>';

   if (!AnnList.bMinimalDisplay) {

       text += '<span class="win-author">'

       if ((this.bIsNew && this.bIsEdited) || (!this.bIsNew && this.bIsEdited)) {
          text += '(' + g_UPDATEDON + ' ' + this.date;
       }
       else {
          text += '(' + g_POSTEDON + ' ' + this.date;
       }

       if (this.author) {
          text += ' ' + g_BY + ' ' + this.author.display();
       }

       text += ')';

      if (this.bIsNew) {
          text += '<img src="' + g_SITEIMAGEDIR + '/ico_new.gif" align="middle" hspace="2">';
      }

      text += '</span>';
   }

   text += '</td></tr></table></div>';
   return text;
}


/*
 *
 * Announcement Folder Object
 *
 */
function AnnouncementFolder(id, text, bIsNew, bIsEdited, type, position) {
    this.isFolder   = true;
    this.id         = id;
    this.folderid   = id;
    this.text       = text;
    this.bIsNew     = false;        // contains new announcements
    this.bIsEdited  = bIsEdited;    // contains edited announcements
    this.type       = type;
    this.position   = position;
    this.bIsUrgent  = false;

    this.display    = DisplayAnnouncementFolder;
}

function DisplayAnnouncementFolder(AnnList) {

    var text;
    var command;

   var folderPrefix = 'ann';
   var folderIcon = '/ico_folder_closed16.gif';

    var divid = (this.type == 'global') ? ('global_' + folderPrefix + 'folder_' + this.id) : (folderPrefix + 'folder_' + this.id);
    var imgid = (this.type == 'global') ? ('global_' + folderPrefix + 'folderimg_' + this.id) : (folderPrefix + 'folderimg_' + this.id);

   // if annFolderState is defined and the id exists in our list
   if ((window.annFolderState) && (annFolderState.findItem(this.id, this.type) == true)) {
      folderIcon = '/ico_folder_open16.gif';
   }

    text = '';
    text += '<div id="' + divid + '"><table><tr><td width="16" align="center" valign="top">' +
            '<a target="in_main" href="javascript: EVENT_folder_click(' + this.id + ', \'' + this.type + '\', \'' + folderPrefix + '\');"><img id="' + imgid + '" src="/images/ico' + folderIcon + '" border="0" hspace="0" vspace="0"></a></td>' +
            '<td align="left" valign="top">' + this.text;

    if (this.bIsUrgent) {
        text += '<img src="' + g_SITEIMAGEDIR + '/ico_urgent.gif" align="middle" hspace="2">';
    }

    if (this.bIsNew) {
        text += '<img src="' + g_SITEIMAGEDIR + '/ico_new.gif" align="middle" hspace="2">';
    }

    text += '</td></tr></table></div>';

    return text;
}

function EVENT_folder_click(folderid, type, folderPrefix) {

    var divid = (type == 'global') ? ('global_' + folderPrefix + 'folder_' + folderid) : (folderPrefix + 'folder_' + folderid);
    var imgid = (type == 'global') ? ('global_' + folderPrefix + 'folderimg_' + folderid) : (folderPrefix + 'folderimg_' + folderid);

    var folder = document.getElementById(divid);
    var bEnableFooter = false;

    if (folder) {

        var sibling = folder.nextSibling;
        if (sibling) {

            if (sibling.className == 'display-none') {
                if (sibling.style.display == 'block') {
                    sibling.style.display = 'none';
                }
                else {
                    sibling.style.display = 'block';
                }

                bEnableFooter = true;
            }

         if (sibling.className == 'display-block') {
            // sibling.stype.display will be '' when you browse to another page and then return to the homepage.
            if ((sibling.style.display == '') || (sibling.style.display == 'block')) {
               sibling.style.display = 'none';
            }
            else {
               sibling.style.display = 'block';
            }

            bEnableFooter = true;
         }

         if (bEnableFooter == true) {
             var Footer = document.getElementById('footer');
                if (Footer) {
                    Footer.style.visibility = 'hidden';
                    loadFooter();
                }
         }

        }

        var img = document.getElementById(imgid);
        if (img) {

            if (img.src.indexOf('closed') > -1) {
                img.src = '/images/ico/ico_folder_open16.gif';
            eval(folderPrefix + 'FolderState.addItem(' + folderid + ',\'' + type + '\')');
         }
            else {
                img.src = '/images/ico/ico_folder_closed16.gif';
            eval(folderPrefix + 'FolderState.removeItem(' + folderid + ',\'' + type + '\')');
            }
        }
    }
}




/*
 *
 * Announcements List
 *
 */

function AnnouncementList(noItemsText, bMinimalDisplay) {
   this.noItemsText  = noItemsText;
   this.items        = new Array();
   this.global       = false;
   this.globalHeader = '';
   this.localheader  = '';
   this.bMinimalDisplay = bMinimalDisplay;

   // methods
   this.addItem = AddAnnouncement;
   this.display = DisplayAnnouncementList;
}

function AddAnnouncement(annObj) {
   this.items[this.items.length] = annObj;
}

function DisplayAnnouncementList() {
   var text;
   var folderchildtext;
   var Folder;

   if (this.items.length == 0) {
       text = this.noItemsText;
   }
   else {

       text = '<div>';

       var folderid = -1;
       for (var i = 0; i < this.items.length; i++) {

           if (this.items[i].isFolder) {

               Folder      = this.items[i];
               folderid    = Folder.folderid;
               foldertype  = Folder.type

               folderchildtext = '';

               // jump out if we're an empty folder
               if ( (i+1) < this.items.length && folderid == this.items[i+1].folderid) {

               // if annFolderState is defined and the id exists in our list
               if ((window.annFolderState) && (annFolderState.findItem(folderid, foldertype) == true)) {
                   folderchildtext += '<div class="display-block">';
               }
               else {
                  folderchildtext += '<div class="display-none">';
               }

                   i++;

                   for (i; (i < this.items.length) && (this.items[i].folderid == folderid); i++) {

                       // if announcement is urgent, alert parent folder
                       if (this.items[i].priority == 1) {
                           Folder.bIsUrgent = true;
                       }

                       // if announcement is new, alert parent folder
                       if (this.items[i].bIsNew) {
                           Folder.bIsNew = true;
                       }

                       folderchildtext += this.items[i].display(this);
                   }

                   i--;

                   folderchildtext += '</div>';
               }

               text += Folder.display(this);
               text += folderchildtext;


           }
           else {
               text += this.items[i].display(this);
           }

      }

      text += '</div>';
   }

   return text;
}



/*
 *
 * Link Object
 *
 */

function Link(id, fid, text, url, target, icon, type, position) {
   this.isFolder  = false;
   this.id        = id;
   this.folderid  = fid;
   this.text      = text;
   this.url       = url;
   this.target    = target;
   this.icon      = icon;
   this.type      = type;
   this.position  = position;

   // methods
   this.display = DisplayLink;
}

function DisplayLink(LinksList) {

   var text;
   var command;

   text = '<table><tr><td width="16" align="center" valign="top">';

   // add bullet for top-level links
   if (this.folderid == -1) {
       text += '<img src="/images/' + this.icon + '" border="0" hspace="0" vspace="0">';
   }
   else {
       text += '&nbsp;';
   }

   text += '</td>';

   // apend bullet for links in folder
   if (this.folderid != -1) {
       text += '<td width="12" align="left" valign="top">';
       text += '<img src="/images/' + this.icon + '" align="middle" border="0" vspace="0" style="margin-left: 3px; margin-right: 7px;">';
       text += '</td>';
   }

   text += '<td align="left" valign="top">';
   text += '<a href="Javascript: OpenLink(\'' + JSReplace(this.url) + '\',\'' + this.target + '\');">' + this.text + '</a>';

   text += '</td></tr></table>';

   return text;
}

function JSReplace(str) {
   str = str.replace(/%0D%0A/g, ' ');   // \r\n (Windows)
   str = str.replace(/%0A/g, ' ');      // \n (Unix)
   str = str.replace(/%0D/g, ' ');      // \r (Mac)
   str = str.replace(/\\/g, '\\\\');    // \ to \\
   str = str.replace(/\'/g, '\\\'');    // ' to \'
   return str;
}


/*
 *
 * LinkFolder Object
 *
 */
function LinkFolder(id, text, icon, type, position) {
   this.isFolder  = true;
   this.id        = id;
   this.text      = text;
   this.icon      = icon;
   this.type      = type;
   this.position  = position;

   this.display    = DisplayLinkFolder;
}


function DisplayLinkFolder(LinksList) {

   var text;
   var command;

   var folderPrefix = 'link';
   var folderIcon = '/ico_folder_closed16.gif';

   var divid = (this.type == 'global') ? ('global_' + folderPrefix + 'folder_' + this.id) : (folderPrefix + 'folder_' + this.id);
   var imgid = (this.type == 'global') ? ('global_' + folderPrefix + 'folderimg_' + this.id) : (folderPrefix + 'folderimg_' + this.id);

    // if linkFolderState is defined and the id exists in our list
   if ((window.linkFolderState) && (linkFolderState.findItem(this.id, this.type) == true)) {
      folderIcon = '/ico_folder_open16.gif';
   }

   text = '';
   text += '<div id="' + divid + '"><table><tr><td width="18" align="center" valign="top">' +
           '<a target="in_main" href="javascript: EVENT_folder_click(' + this.id + ', \'' + this.type + '\', \'' + folderPrefix + '\');"><img id="' + imgid + '" src="/images/ico' + folderIcon + '" border="0"></a></td>' +
           '<td align="left" valign="top">' + this.text +
           '</td></tr></table></div>';

   return text;
}


/*
 *
 * Links List
 *
 */

function LinksList(noItemsText, localheader, localactions) {
   this.noItemsText  = noItemsText;
   this.localheader  = localheader;
   this.localactions = localactions;
   this.items        = new Array();

   // methods
   this.addItem = AddLink;
   this.display = DisplayLinkList;
}

function AddLink(linkObj) {
   this.items[this.items.length] = linkObj;
}

function DisplayLinkList() {
   var text;
   var folderchildtext;
   var Folder;

   text = '<div class="win-subsection-title-bar">' +
             '<div style="float: right;">' + this.localactions + '</div>' +
             this.localheader +
          '</div>';


   if (this.items.length == 0) {
       text += '<div style="padding-left: 5px;">' + this.noItemsText + '</div>';

   }
   else {

       var folderid = -1;
       for (var i = 0; i < this.items.length; i++) {

           if (this.items[i].isFolder) {

               Folder      = this.items[i];
               folderid    = Folder.id;
               foldertype  = Folder.type;

               folderchildtext = '';

               // jump out if we're an empty folder
               if ( (i+1) < this.items.length && folderid == this.items[i+1].folderid) {

               // if linkFolderState is defined and the id exists in our list
               if ((window.linkFolderState) && (linkFolderState.findItem(folderid, foldertype) == true)) {
                   folderchildtext += '<div class="display-block">';
               }
               else {
                   folderchildtext += '<div class="display-none">';
               }

                   i++;

                   for (i; (i < this.items.length) && (this.items[i].folderid == folderid); i++) {

                       folderchildtext += this.items[i].display(this);
                   }

                   i--;

                   folderchildtext += '</div>';
               }

               text += Folder.display(this);
               text += folderchildtext;


           }
           else {
               text += this.items[i].display(this);
           }

      }

   }

   text += '<br/>'

   return text;
}


/*
 *
 * Content Blob
 *
 */

function ContentBlob(textContent) {
   this.content   = textContent;

   // methods
   this.display = DisplayContentBlob;
}

function DisplayContentBlob() {
   var text;

   text = this.content;

   return text;
}

/*
 *
 * Event Item
 *
 */

function Event(id, title, startdate, enddate, allday, personal, responded, webMeetingType, webMeetingUser, webMeetingURL, webConf) {
   this.id        = id;
   this.title     = title;
   this.startdate = new Date(startdate);
   this.enddate   = new Date(enddate);
   this.allday    = allday;
   this.personal  = personal;
   this.responded = responded;

   this.webMeetingType = webMeetingType;
   this.webMeetingUser = webMeetingUser;
   this.webMeetingURL = webMeetingURL;
   this.webConf = webConf;

   // methods
   this.display = DisplayEvent;
}

function DisplayEvent(refDate, bMinimalDisplay, isToday) {

   var text = '';
   var strTime = '';

   if(this.allday.toLowerCase() == 'true') {
       strTime = g_CAL_EVENT_ALLDAY;
   } else {
       if(!dateCmp(refDate, this.startdate)) {
           strTime = g_CAL_EVENT_CONTINUED;
       } else {
           var evtDate = this.startdate;
           var evtHour = evtDate.getHours();
           var evtMin  = evtDate.getMinutes();

           if (TimeFormat24()) {
               if (!isNaN(evtHour) && !isNaN(evtMin)) {
                   strTime = evtHour + ":" + ((evtMin < 10) ? "0" : "") + evtMin;
               }
           } else {
               if (!isNaN(evtHour) && !isNaN(evtMin)) {
                   var strAmPm = g_CAL_AM;
                   if(evtHour > 12) {
                       evtHour = evtHour - 12;
                       strAmPm = g_CAL_PM;
                   }

                   if(evtHour == 12) {
                       strAmPm = g_CAL_PM;
                   }

                   if (evtHour == 0) {
                       evtHour = '12';
                   }

                   strTime = evtHour + ":" + ((evtMin < 10) ? "0" : "") + evtMin + ' ' + strAmPm;
               }
           }

       }

   }

   var rowClass = '';
   if (isToday) {
      rowClass = ' class="win-highlight"'
   }

   var webMeetingTypeIcon = '&nbsp;';
   if (this.webMeetingType == 'Web' || this.webMeetingType == 'WebAudio') {
      webMeetingTypeIcon = '<img hspace="2" border="0" src="/images/apps/conferencing10.gif" title="' + g_CAL_WEB_CONF + '"/>';
   }
   if (this.webMeetingType == 'Audio') {
      webMeetingTypeIcon = '<img hspace="2" border="0" src="/images/ico/ico_audioconf10.gif" title="' + g_CAL_AUDIO_CONF + '"/>';
   }

   text +=  '<table width="100%" border="0" cellpadding="1" cellspacing="0">' +
            '<tr' + rowClass + '>' +
               '<td align="left" width="5%" valign="top">' + webMeetingTypeIcon + '</td>' +
               '<td align="left" width="20%" valign="top">&nbsp;' + strTime + '</td>' +
               '<td width="2%">&nbsp;</td>' +
               '<td align="left" width="63%">' +
                  '<a href="/cal/cal.aspx?_command=detail&id=' + this.id + '&on=' + MakeDateStringFromObj(this.startdate);

   if(this.allday.toLowerCase() != 'true') {
       if(dateCmp(refDate, this.startdate)) {
           text += '%20' + strTime;
       } else {
           text += '%20' + FormatHours(this.startdate.getHours(), true)  + ':' + FormatMinutes(this.startdate.getMinutes()) + ' ' + getMeridiem(this.startdate);
       }
   }

   text +=  '" target="in_main">' + this.title + '</a>';

   if (!this.responded) {
       text += ' <a href="/cal/cal.aspx?_command=detail&id=' + this.id + '&on=' + MakeDateStringFromObj(this.startdate);

       if(this.allday.toLowerCase() != 'true') {
           if(dateCmp(refDate, this.startdate)) {
               text += '%20' + strTime;
           } else {
               text += '%20' + FormatHours(this.startdate.getHours(), true)  + ':' + FormatMinutes(this.startdate.getMinutes()) + ' ' + getMeridiem(this.startdate);
           }
       }

       text += '" target="in_main" class="link-important">(' + g_CAL_PLEASERESPOND + ')</a>';
   }

   if (this.personal) {
      text += '&nbsp;<img src="/images/ico/ico_personal12.gif" title="' + g_CAL_PERSONALEVENT + '">';
   }

   text += '</td>';

   var webMeetingLink = '&nbsp;';
   if (this.webMeetingType == 'Web' || this.webMeetingType == 'WebAudio')
   {
       if (this.webMeetingUser == 'Host') {
           // make sure host still has permission
           if (this.webConf == 'True')
           {
               webMeetingLink = '<a target="_blank" class="link-nounder" href="' + this.webMeetingURL + '">' + g_CAL_START + '</a>';
           }
       }
       if (this.webMeetingUser == 'Participant') {
           webMeetingLink = '<a target="_blank" class="link-nounder" href="' + this.webMeetingURL + '">' + g_CAL_JOIN + '</a>';
       }
   }
   text += '<td valign="top" width="10%">' + webMeetingLink + '</td>';

   text += '</tr></table>' + '\n';

   return text;
}

/*
 *
 * What's New Discussion Item
 *
 */

function DiscItem(id, forum, totalcnt, newcnt) {
   this.id        = id;
   this.forum     = forum;
   this.totalcnt  = totalcnt;
   this.newcnt    = newcnt;

   // methods
   this.display = DisplayDiscItem;
}

function DisplayDiscItem() {

   var text =  '<tr>' +
                  '<td height="15" align="center" valign="top"><img src="' + g_SITEIMAGEDIR + '/tick2.gif" border="0" width="7" height="9" style="margin-left: 4px; margin-right: 5px;"></td>' +
                  '<td height="15" align="left" width="70%">' +
                     '<a href="/disc/default.asp?command=threadview&forum_id=' + this.id + '" target="in_main">' + this.forum + '</a>' +
                  '</td>' +
                  '<td height="15" align="right" valign="top" style="white-space: nowrap;">' +
                     g_DISCTOTAL + ':&nbsp;<span class="txt-important">' + this.totalcnt + '</span>&nbsp;' +
                  '</td>' +
                  '<td height="15" align="right" valign="top" style="white-space: nowrap;">' +
                     g_DISCNEW + ':&nbsp;<span class="txt-important">' + this.newcnt + '</span>' +
                  '</td>' +
               '</tr>';

   return text;
}

/*
 *
 * What's New Database Item
 *
 */
function DBAppItem(id, name, totalcnt, newcnt, updatedcnt) {
   this.id           = id;
   this.name         = name;
   this.totalcnt     = totalcnt;
   this.newcnt       = newcnt;
   this.updatedcnt   = updatedcnt;

   // methods
   this.display = DisplayDBAppItem;
}

function DisplayDBAppItem() {

   var text =  '<tr>' +
                  '<td height="15" align="center" valign="top"><img src="' + g_SITEIMAGEDIR + '/tick2.gif" border="0" width="7" height="9" style="margin-left: 4px; margin-right: 5px;"></td>' +
                  '<td height="15" align="left" width="60%">' +
                     '<a href="/dbapp/dbapp.aspx?_appid=' + this.id + '" target="in_main">' + this.name + '</a>' +
                  '</td>' +
                  '<td height="15" align="right" valign="top" style="white-space: nowrap;">' +
                     g_DISCTOTAL + ':&nbsp;<span class="txt-important">' + this.totalcnt + '</span>&nbsp;' +
                  '</td>' +
                  '<td height="15" align="right" valign="top" style="white-space: nowrap;">' +
                     g_NEW + ':&nbsp;<span class="txt-important">' + this.newcnt + '</span>&nbsp;' +
                  '</td>' +
                  '<td height="15" align="right" valign="top" style="white-space: nowrap;">' +
                     g_UPDATED + ':&nbsp;<span class="txt-important">' + this.updatedcnt + '</span>' +
                  '</td>' +
               '</tr>';

   return text;
}


/*
 *
 * Mail (folders)
 *
 */
function MailMessageList(folder, noItemsText, localheader, localactions) {
   setInterval("window.location.reload()", (3 * 60 * 1000)); // 3 minutes

   this.folder       = folder;
   this.noItemsText  = noItemsText;
   this.localheader  = localheader;
   this.localactions = localactions;
   this.items        = new Array();

   // methods
   this.addItem = AddMessage;
   this.display = DisplayMessageList;
}

function AddMessage(mailObj) {
   this.items[this.items.length] = mailObj;
}

function DisplayMessageList() {
   var text;

   text = '<div class="win-subsection-title-bar">' +
             '<div style="float: right;">' + this.localactions + '</div>' +
             this.localheader +
          '</div>';


   if (this.items.length == 0) {
       text += '<div style="padding-left: 5px;">' + this.noItemsText + '</div>';

   }
   else {

       text +=  '<table width="100%" border="0" celpadding="2" cellspacing="2">';

       for (var i = 0; i < this.items.length; i++) {
           text += this.items[i].display(this);
       }

       var strSeeMore = g_SEEMORE + '...';
       text +=  '<tr>' + '\n' +
                   '<td align="right" colspan="2"><a href="/mail/dispatch.aspx?_command=home&folder=/'+this.folder+'" target="in_main" class="link-nounder">' + strSeeMore + '</a></td>' +
                '</tr>' + '\n';
       text += '</table>';

   }

   text += '<br/>';

   return text;
}


function MailFolderList() {
    this.items        = new Array();

    this.addItem    = AddFolder;
    this.display    = DisplayMailFolders;
}

function AddFolder(mailObj) {
   this.items[this.items.length] = mailObj;
}

function DisplayMailFolders() {

    if (this.items.length > 0) {
       var text =  '<table width="100%" border="0" celpadding="2" cellspacing="2">';

        for (var i = 0; i < this.items.length; i++) {
            text += this.items[i].display();
        }

       text += '</table><br/>';
    }

   return text;

}

/*
 *
 * Mail Message
 *
 */
var FLAGS_NONE     = 0;
var FLAGS_ANSWERED = 1;
var FLAGS_FLAGGED  = 2;
var FLAGS_DELETED  = 4;
var FLAGS_DRAFT    = 8;
var FLAGS_SEEN     = 16;
var FLAGS_RECENT   = 32;
var FLAGS_CUSTOM   = 64;

function MailMessage(uid, folder, from, subject, date, size, flags) {
   this.uid     = uid;
   this.folder  = folder;
   this.from    = from;
   this.subject = subject;
   this.date    = date;
   this.size    = size;
   this.flags   = flags;

   // methods
   this.display = DisplayMailMessage;
}

function DisplayMailMessage() {
   var text =  '<tr>' +
                  '<td height="15" align="left" valign="top">' +
                    '<img src="'+getMessageIcon(this.flags)+'" class="win-subsection-img" alt="" border="0" vspace="0" style="margin-left: 2px; margin-right: 4px;/>' +
                  '</td>';

   text += '<td height="15" align="left" valign="top">';
   if ((this.flags&FLAGS_SEEN)==0) { text += '<b>'; }


   // TODO Put "no subject" text in resource file
   text += '<a href="javascript:OpenLink(\'/mail/dispatch.aspx?_command=detail&id='
    + this.uid +'&folder=/' + this.folder
    + '&_open=remote\',\'new window\');" target="in_main">'
    + ((this.subject == undefined || this.subject.length == 0) ? "<i>No subject</i>" : this.subject)
    + '</a>';
   if ((this.flags&FLAGS_SEEN)==0) { text += '</b>'}
   text += '&nbsp;<span class="win-author">('+g_SENTBY+' '+this.from + ' '+g_ON+' '+this.date+')</span>'+
           '</td>' +
         '</tr>';

   return text;
}

function getMessageIcon(flags)
{
    var iconref = "/images/ico/";
    if (((flags&FLAGS_DRAFT)==FLAGS_DRAFT)) {
        iconref += "ico_mail_write16.gif";
    } else if (((flags&FLAGS_SEEN)==FLAGS_SEEN)) {
        if (((flags&FLAGS_ANSWERED)==FLAGS_ANSWERED)) {
            iconref += "ico_mail_reply16.gif";
        } else {
            iconref += "ico_mail_seen16.gif";
        }
    } else {
        iconref += "ico_mail_unseen16.gif";
    }
    return iconref;
}

/*
 *
 * Mail Folder
 *
 */
function MailFolder(name, messagecnt, unseencnt, recentcnt) {
   this.name         = name;
   this.messagecnt   = messagecnt;
   this.unseencnt    = unseencnt;
   this.recentcnt    = recentcnt;

   // methods
   this.display = DisplayMailFolder;
}

function DisplayMailFolder() {
    var text =  '<tr>' +
        '<td height="15" align="left" valign="middle">' +
        '<img src="/images/ico/'+getFolderIcon(this.name)+'" class="win-subsection-img" alt="" border="0" vspace="0" style="margin-left: 2px; margin-right: 4px;/>' +
        '</td>'+
        '<td height="15" align="left" valign="middle">' +
        '<a href="/mail/dispatch.aspx?_command=home&folder=/' + this.name + '" target="in_main">' + this.name + '</a> ';

    if (this.unseencnt > 0) {
        var caption = g_UNREAD + ' ' + ((this.unseencnt == 1) ? g_SINGLE_MESSAGE : g_MESSAGES);
        text += '<span style="color:red;">' +
            '(' + this.unseencnt + ' ' + caption + ')' +
            '</span>';
    }
    else {
        var caption = (this.messagecnt == 1) ? g_SINGLE_MESSAGE : g_MESSAGES;
        text += '(' + this.messagecnt + ' ' + caption + ')';
    }

    text += '</td></tr>';

    return text;
}

function getFolderIcon(name) {
   var icon = 'ico_folder_closed16.gif';
   switch(name.toLowerCase())
   {
     case 'inbox':
         icon= 'ico_inbox16.gif';
     break;
   }
   return icon;
}


/*
 *
 * What's New Directory Item
 *
 */

function DirItem(id, name, date) {
   this.id     = id;
   this.name   = name;
   this.date   = date;

   // methods
   this.display = DisplayDirItem;
}

function DisplayDirItem() {

   var text =  '<tr>' +
               '<td height="15" width="16" valign="top" align="center"><img src="' + g_SITEIMAGEDIR + '/tick2.gif" border="0" width="7" height="9"></td>' +
               '<td height="15" valign="top" align="left"><a href="/members/dispatch.aspx?_command=detail&id=' + this.id + '" target="in_main">' +
               this.name + '</a>&nbsp;' + g_JOINEDON + ' ' + this.date + '</td>' +
               '</tr>' + '\n';

   return text;
}

/*
 *
 * What's New Document Item
 *
 */

function DocItem(id, title, bIsNew, bIsEdited, author, date, pid) {
   this.id        = id;
   this.pid       = pid;
   this.title     = title;
   this.bIsNew    = bIsNew;
   this.bIsEdited = bIsEdited;
   this.author    = author;
   this.date      = date;

   // methods
   this.display = DisplayDocItem;
}

function DisplayDocItem(bMinimalDisplay) {

   var itemText = '<a href="/docs/docapp.aspx?_command=detail&_appid=5&id=' + this.id + '&_clientInfo=%3cclientInfo%3e%3cfid%3e' + this.pid + '%3c%2ffid%3e%3c%2fclientInfo%3e" target="in_main">' +
                  this.title + '</a>';

   var authorText = '';
   var dateText   = '';
   var img        = '';

   if (this.bIsNew && this.bIsEdited) {
      dateText = g_EDITEDON + '&nbsp;' + this.date;
      img      = '<img src="' + g_SITEIMAGEDIR + '/ico_new.gif" align=absmiddle>';
   }

   else if (this.bIsNew && !this.bIsEdited) {
      dateText = g_CREATEDON + '&nbsp;' + this.date;
      img      = '<img src="' + g_SITEIMAGEDIR + '/ico_new.gif" align=absmiddle>';
   }
   else if (!this.bIsNew && this.bIsEdited) {
      dateText = g_EDITEDON + '&nbsp;' + this.date;
      img      = '';

   }
   if (this.author) {
      authorText += ' ' + g_BY + ' ' + this.author;
   }

   if (!bMinimalDisplay)
   {
       itemText += '<span class="win-author">(' + dateText + ' ' + authorText + ')</span>&nbsp;' + img;
   }
   else
   {
       itemText += img;
   }

   var text =  '<tr>' +
               '<td height="15" width="16" valign="top" align="center"><img src="' + g_SITEIMAGEDIR + '/tick2.gif" border="0" width="7" height="9"></td>' +
               '<td height="15" valign="top" align="left">' + itemText + '</td>' +
               '</tr>';

   return text;

}


/*
 *
 * Calendar Footer
 *
 */

function CalFooter(dt, joinURL, showConfBox) {
   this.date = dt;
   this.joinURL = joinURL;
   this.showConfBox = showConfBox;

   // methods
   this.display = DisplayCalFooter;
}

function IsValidMeeting()
{
   var meeting = document.getElementById('meeting_number').value;
   if (meeting != null && meeting.length > 0) {
      if (isNaN(meeting)) {
         alert(g_CAL_INVALIDMEETINGID);
         return false;
      }
   }
   return true;
}

function DisplayCalFooter() {

   var dt = new Date(this.date);
   var ds = MakeDateString(dt.getMonth(), dt.getDate(), dt.getFullYear());
   var text = '<br/>';

   if (this.showConfBox) {
      text +=     '<table class="generic-container page-subsection-bg" cellspacing="0" cellpadding="0" border="0">' +
                  '<tr><td class="fld-title">' +
                  '<b>' + g_CAL_JOINMEETING + ':</b><br/>' +
                  '<input id="meeting_number" type="text" size="24" value="' + g_CAL_INSERTMTNGNUM + '" style="color: gray;" onfocus="this.select();" onclick="this.style.color=\'black\'"/>&nbsp;' +
                  '<img border="0" id="joinaMeeting" src="images/ico/ico_go16.gif" style="cursor: pointer;" onclick="if(IsValidMeeting()){var meeting = document.getElementById(\'meeting_number\').value;var url = \'' +
                  this.joinURL.replace(new RegExp("\'", "g"), "\\\'") + '\';url = url.replace(\'MK=\',\'MK=\'+meeting);window.open(url, \'_blank\');}"/>' +
                  '</td></tr>' +
                  '</table><br/><div class="page-hr">&nbsp;</div>';
   }

   text +=     '<a href="/cal/cal.aspx?_command=day&ViewName=day&StartDate=' + ds + '" target="in_main">' +
               '<img src="/images/ico/ico_caldays_116.gif" style="border-width: 0px; vertical-align: middle"/>' +
               '</a>' + '&nbsp;' +
               '<a href="/cal/cal.aspx?_command=day&ViewName=day&StartDate=' + ds + '" target="in_main" class="link-nounder">' + g_CAL_TODAY + '</a>&nbsp;&nbsp;&nbsp;' +
               '<a href="/cal/cal.aspx?_command=week&ViewName=week&StartDate=' + ds + '" target="in_main">' +
                  '<img src="/images/ico/ico_caldays_716.gif" style="border-width: 0px; vertical-align: middle"/>' +
               '</a>' + '&nbsp;' +
               '<a href="/cal/cal.aspx?_command=week&ViewName=week&StartDate=' + ds + '" target="in_main" class="link-nounder">' + g_CALVIEWWEEK + '</a>&nbsp;&nbsp;&nbsp;' +
               '<a href="/cal/cal.aspx?_command=month&ViewName=month&StartDate=' + ds + '" target="in_main">' +
                  '<img src="/images/ico/ico_caldays_3116.gif" style="border-width: 0px; vertical-align: middle"/>' +
               '</a>' + '&nbsp;' +
               '<a href="/cal/cal.aspx?_command=month&ViewName=month&StartDate=' + ds + '" target="in_main" class="link-nounder">' + g_CALVIEWMONTH + '</a>';

   return text;
}



/*
 *
 * Section Object
 *
 */

function Section(name, image, seeMoreLink, colspan, bMinimalDisplay, maxDisplay, hasSpacerLine) {
   this.name         = name;
   this.image        = image;
   this.seeMoreLink  = seeMoreLink;
   this.colspan      = colspan ? colspan : '2';
   this.items        = new Array();
   this.bMinimalDisplay = bMinimalDisplay;
   this.maxDisplay   = maxDisplay;
   this.hasSpacerLine = hasSpacerLine ? hasSpacerLine : false;

   // methods
   this.addItem = AddItem;
   this.display = DisplaySection;
}

function AddItem(itemObj) {
   this.items[this.items.length] = itemObj;
}

function DisplaySection() {

   var text =  '<div class="win-subsection-title-bar">';

   if (this.image) {
      text += '<img src="' + this.image + '" class="win-subsection-img" alt=""/>';
   }

   text += '&nbsp;' + this.name + '</div>' +
           '<table cellspacing="2" cellpadding="0" width="100%">';

   for (var i = 0; i < this.items.length; i++) {
      text += this.items[i].display(this.bMinimalDisplay);
   }

   var bSeeMore   = false;
   var strSeeMore = g_SEEMORE + '...';
   if (this.name.indexOf('dbapp') > -1) {
      bSeeMore = true;
      strSeeMore = g_SEEALLDATABASES;
   }
  else if (i == this.maxDisplay) {
      bSeeMore = true;
   }

   if (this.seeMoreLink.length && bSeeMore) {
      var strAppName = this.name.split("/");
      text +=  '<tr>' + '\n' +
               '<td align="right" colspan="' + this.colspan + '"><a href="' + this.seeMoreLink + '" target="in_main" id="' + strAppName[1] + 'SeeMore' + '" class="link-nounder">' + strSeeMore + '</a></td>' +
               '</tr>' + '\n';
   }

   if (this.hasSpacerLine) {
      text += '<tr><td colspan="' + this.colspan + '">&nbsp;</td></tr>';
   }

   text += '</table>' + '\n';

   return text;
}


// Calendar Section List
function CalSection(name, dateString, refDate, isToday) {
   Section.call(this, name, '', '');

   this.dateString   = dateString;
   this.refDate      = refDate;
   this.isToday      = isToday;
   this.display      = DisplayCalSection;

}

function DisplayCalSection() {

   var text =  '<table width="100%" border="0" cellpadding="0" cellspacing="0">' +
               '<tr>' +
                  '<td height="15px;" align="left"><span class="hp-title">' + this.name + '</span></td>' +
                  '<td height="15px;" align="right">' + this.dateString + '</td>' +
               '</tr>' +
               '</table>';

   var strAllDayText = '';
   var strNonAllDayText = '';
   for (var i = 0; i < this.items.length; i++) {
       if(this.items[i].allday.toLowerCase() == 'true') {
           strAllDayText += this.items[i].display(this.refDate, this.bMinimalDisplay, this.isToday);
       } else {
           strNonAllDayText += this.items[i].display(this.refDate, this.bMinimalDisplay, this.isToday);
       }
   }

   text += strAllDayText;
   text += strNonAllDayText;


   text += '<br/>';

   return text;
}

/*
 *
 * CalendarList (calendar)
 *
 */
function CalendarList(noItemsText) {
    SectionedList.call(this, noItemsText);

    this.Days       = new Array();
    this.ListOfDays = new Array();
    this.addItem    = AddEvent;
    this.display    = DisplayEvents;
}

function AddEvent(eventObj) {

    // handle the all day event case, for sync
    if (dateCmp(eventObj.startdate, eventObj.enddate) && eventObj.startdate.getHours() == 0 && eventObj.startdate.getMinutes() == 0 && eventObj.enddate.getHours() == 0 && eventObj.enddate.getMinutes() == 0) {
        eventObj.enddate.setMinutes(1);
    }

    var refDate = new Date(eventObj.startdate);
    var refEndDate = new Date(eventObj.enddate);

    // If we have a start window and it is after the event start date then we only
    // want to show events after the start window
    if(typeof(this.StartWindow) != 'undefined' && eventObj.startdate <= this.StartWindow) {
        refDate = new Date(this.StartWindow);
    }

    // If we have a end window and it is after the event end date then we only
    // want to show events up to the end window
    if(typeof(this.EndWindow) != 'undefined' && eventObj.enddate > this.EndWindow) {
        refEndDate = new Date(this.EndWindow);
    }

    refDate.setHours(0);
    refDate.setMinutes(0);

    while(refDate < refEndDate) {
        if(typeof(this.Days[refDate]) == 'undefined') {
            this.Days[refDate] = new Array();
            this.ListOfDays[this.ListOfDays.length] = new Date(refDate.toString());
        }
        var eventArray = this.Days[refDate];
        eventArray[eventArray.length] = eventObj;

        refDate.setDate(refDate.getDate() + 1);
    }
}

function DisplayEvents() {
    for (var i = 0; i < this.ListOfDays.length; i++)
    {
        var objDay = this.Days[this.ListOfDays[i]];
        var dtEventStart = new Date( this.ListOfDays[i] );
        var daySection;

        if(dateCmp(dtEventStart, TODAY)) {
            daySection = new CalSection(g_CAL_TODAY, MakeLocaleMonthDD(dtEventStart), dtEventStart, true);
        } else {
            daySection = new CalSection(DayName(dtEventStart.getDay()), MakeLocaleMonthDD(dtEventStart), dtEventStart, false);
        }

        for(var x = 0; x < objDay.length; x++) {
            daySection.addItem(objDay[x]);
        }
        AddSection.call(this, daySection);
    }

    return DisplayList.call(this);
}


/*
 *
 * Sectioned List  (calendar and what's new)
 *
 */

function SectionedList(noItemsText) {
   this.noItemsText  = noItemsText;
   this.sections     = new Array();
   this.footers      = new Array();

   // methods
   this.addItem   = AddSection;
   this.addFooter = AddFooter;
   this.display   = DisplayList;
}

function AddSection(sectionObj) {
   this.sections[this.sections.length] = sectionObj;
}

function AddFooter(footerObj) {
   this.footers[this.footers.length] = footerObj;
}

function DisplayList() {

   var text = '';

   if (this.sections.length == 0) {
      if(this.noItemsText != null) {
          text += this.noItemsText;
      }
   }
   else {
      for (var i = 0; i < this.sections.length; i++) {
         text += this.sections[i].display();
      }
   }

   for (var i = 0; i < this.footers.length; i++) {
      text += this.footers[i].display();
   }

   return text;
}

/*
 *
 * Poll Vote Item
 *
 */

function PollVoteItem(id, choiceType, checked, response) {
   this.id           = id;
   this.choiceType   = choiceType;
   this.checked      = checked;
   this.response     = response;

   // methods
   this.display = DisplayVoteItem;
}

function DisplayVoteItem() {

   var text = '<table border="0" cellpadding="0" cellspacing="0">' +
              '<tr>' +
                 '<td valign="absmiddle"><input type="' + this.choiceType + '" name="in_choices" ' + 'value="' + this.id + '"' + this.checked + '></td>' +
                 '<td>' + this.response + '</td>' +
              '</tr>' +
              '</table>';

   return text;
}

/*
 *
 * Poll Vote List
 *
 */

function PollVoteList(id, question) {
   this.id        = id;
   this.question  = question;
   this.items     = new Array();

   // methods
   this.addItem   = AddVoteItem;
   this.display   = DisplayPollVoteList;
}

function AddVoteItem(voteObj) {
   this.items[this.items.length] = voteObj;
}

function DisplayPollVoteList() {

   var bTwoCols = (this.items.length > 5) ? true : false;

   var text =  this.question + '<br/><br/>' +
               '<form name="poll_vote" method="post" action="/poll/save.asp" onSubmit="return(validateform(\'command\',\'start\'));">' +
               '<input type="hidden" name="id" value="' + this.id + '">' +
               '<input type="hidden" name="source" value="strtpg">' +
               '<input type="hidden" name="command" value="vote">' +
               '<table width="100%" border="0" celpadding="0" cellspacing="2">';

               if (!bTwoCols) {
                  for (var i = 0; i < this.items.length; i++) {
                     text += '<tr><td>' + this.items[i].display() + '</td></tr>';
                  }
               }
               else {
                  var nRows = (Math.round(this.items.length / 2));
                  var colVal1;
                  var colVal2;

                  for (var i = 0; i < nRows; i++) {
                     // column 1 array element always exists
                     colVal1 = this.items[i].display();
                     // make sure the column 2 array element exists. it won't for odd numbers of poll items
                     if (this.items[i+nRows]) {
                        colVal2 = this.items[i+nRows].display();
                     }
                     else {
                        colVal2 = '&nbsp;';
                     }

                     text += '<tr><td width="50%" valign="top">' + colVal1 + '</td><td width="50%" valign="top">' + colVal2 + '</td></tr>';
                  }
               }

   text +=     '</table>' +
               '<br/>' +
               '<input id="vote" type="submit" name="Vote" value="' + g_POLLVOTE + '" class="btn-std"/>' +
               '</form>';

   return text;

}


/*
 *
 * Poll Result Item
 *
 */

function PollResultItem(cnt, response, percent, votes, selected) {
   this.cnt       = cnt;
   this.response  = response;
   this.percent   = percent;
   this.votes     = votes;
   this.selected  = selected;

   // methods
   this.display = DisplayResultItem;
}

function DisplayResultItem() {

   var text = '';
   var tdClass = '';

   if (this.selected == 'selected') {
      tdClass = ' class="trg-folder"';
   }
   text += '<td width="5%" valign="top"' + tdClass +'>' + this.cnt + '.</td>' +
           '<td width="55%"' + tdClass +'>' + this.response + '</td>' +
           '<td width="25%" style="text-align: right; white-space: nowrap;"' + tdClass +'>' + this.percent + ' %</td>' +
           '<td widht="15%" style="text-align: center; white-space: nowrap;"' + tdClass +'>' + this.votes + '</td>';

   return text;
}


/*
 *
 * Poll Results List
 *
 */

function PollResults(id, question, totalvotes, bVisible, bFixed, expDate) {
   this.id           = id;
   this.question     = question;
   this.totalvotes   = totalvotes;
   this.bVisible     = bVisible;
   this.bFixed       = bFixed;
   this.expDate      = expDate;
   this.items        = new Array();

   // methods
   this.addItem   = AddPollResultItem;
   this.display   = DisplayPollResults;
}

function AddPollResultItem(resultObj) {
   this.items[this.items.length] = resultObj;
}

function DisplayPollResults() {

   var text = this.question + '<br/><br/>';
   var rowClass = 'tro';

   // if poll results are visible
   if (this.bVisible) {
      text += '<table width="100%" cellpadding="0" cellspacing="0" class="dt">' +
              '<tr class="tr-hdr">' +
                 '<td width="5%">&nbsp;</th>' +
                 '<td width="55%">' + g_POLLRESPONSES + '</th>' +
                 '<td width="25%" align="right">%</th>' +
                 '<td width="14%" align="center">#</th>' +
              '</tr>';

      for (var i = 0; i < this.items.length; i++) {
         if (i % 2 == 0) {
            rowClass = 'tro';
         }
         else {
            rowClass = 'tre';
         }
         text += '<tr class="' + rowClass + '">' + this.items[i].display() + '</tr>';
      }

      text += '<tr class="tr-total">' +
                 '<td colspan="2">&nbsp;</td>' +
                 '<td style="text-align: right;">' + g_POLLTOTAL + ':</td>' +
                 '<td style="text-align: center;">' + this.totalvotes + '</td>' +
              '</tr>' +
              '</table>';
   }

   // else results are not visible
   else {
      text += g_POLLSTILLGOING;
      if (this.bFixed) {
         text += '&nbsp;(' + g_POLLSCHEDULEDTOSTOP + ' ' + this.expDate + ')';
      }
      text += "<br/>";
   }

   // always display change my vote button
   text += '<br/>' +
           '<form name="frm_changevote" method="post" action="#">' +
           '<input id=""changeMyVote"" type="button" value="' + g_POLLCHANGEMYVOTE + '" class="btn-std" ' +
              'onclick="window.location=\'/poll/default.asp?command=vote&id=' + this.id + '&source=strtpg\'">' +
           '</form>';

   return text;
}

/*
 *
 * Accuweather portal
 *
 */

// global Weatherport image
var wxPort = new Image(200, 125);
var isNav = (document.layers ? true : false);

function loadWeather(bSSL) {

   // Check for Weather Section
   var theWeather;
   if (isNav){
      //For Netscape
      theWeather = document.startBody.document.col1.document.weather;
      if (!theWeather) {
         theWeather = document.startBody.document.col2.document.weather;
      }
   } else {
       //For IE
      theWeather = document.all ? eval("document.all.weather") : eval("document.getElementById('weather')");
   }
   if (!theWeather) {
      return;
   }

   var wp = (document.layers) ? theWeather.WeatherPortal : WeatherPortal;
   if (!wp.isValid) {
      return;
   }

   if (bSSL) {
       wxPort.src = '/images/us/accuweather/AccuWeatherLogo.gif';
       wxPort.width = 233;
       wxPort.height = 23;
       // SSL sites get the logo
       //wxPort.src = '/in_srvRequest.asp?URL=' + escape(wp.StickerSrc);
   } else {
       wxPort.src = wp.StickerSrc;
   }

   // load the Weather Portal
   if (document.layers) {
      var weatherLayer = theWeather.document;
      (weatherLayer.AccuW.weatherPort) ? weatherLayer.AccuW.weatherPort.src = wxPort.src : true;
      (weatherLayer.AccuW.weatherPort) ? weatherLayer.AccuW.weatherPort.width = wxPort.width : true;
      (weatherLayer.AccuW.weatherPort) ? weatherLayer.AccuW.weatherPort.height = wxPort.height : true;
   }
   else if (document.all) {
      document.all.weatherPort ? document.all.weatherPort.src = wxPort.src : true;
      document.all.weatherPort ? document.all.weatherPort.width = wxPort.width : true;
      document.all.weatherPort ? document.all.weatherPort.height = wxPort.height : true;

   }
   else {
      document.getElementsByName('weatherPort').length ? document.getElementsByName('weatherPort')[0].src = wxPort.src : true;
      document.getElementsByName('weatherPort').length ? document.getElementsByName('weatherPort')[0].width = wxPort.width : true;
      document.getElementsByName('weatherPort').length ? document.getElementsByName('weatherPort')[0].height = wxPort.height : true;
   }
}

function Weather(weatherName, isValid, zip, bgColor, stickerSrc, stickerDim, weatherURL, worldURL, logoURL) {

   this.Name      = weatherName;
   this.isValid   = isValid;
   this.zip       = zip;
   this.bgColor   = bgColor;
   this.StickerSrc = stickerSrc;
   this.weatherURL = weatherURL;
   this.worldURL   = worldURL;
   this.logoURL    = logoURL;
   this.stickerDim = stickerDim;

   // methods
   this.display = DisplayWeather;
}

function DisplayWeather() {

   var text =  '<form method=POST id="AccuID" name="AccuW">' +
               '<table cellspacing=0 cellpadding=0 border=0 width="100%">' + '\n' +
               '<tr><td colspan=2 align=center>' + '\n';

   if (this.isValid) {
      text +=  '<nobr><a href="/frame_saver.asp?url=' +
               escape(this.weatherURL+this.zip) + '" id="5dayForecast">' +
               '<img src="/images/spacer.gif" name="weatherPort" ' +
               'border=0 '+this.stickerDim+' alt="' + g_WEATHERLOADING + '"></a></nobr></td></tr>' + '\n' +
               '<tr><td align=center colspan=2>' + '\n' +
               '<hr width="75%">';
   }
   else {
      if (this.logoURL && this.logoURL.length>0) {
          text += '<img src="' + this.logoURL + '" border="0" alt="'+ g_WEATHER +'" name="'+ g_WEATHER + '"></td>' + '\n';
      } else {
          text += '<img src="' + g_SITEIMAGEDIR + '/accuweather/GenericWeatherLogo.gif" border="0" alt="'+ g_WEATHER +'" name="'+ g_WEATHER +'"></td>' + '\n' +
                  '</tr><tr><td align=center colspan=2><font size=4 color=black face="verdana"><b>'+ this.Name + '</b></font></td>';
      }
      text += '</tr><tr><td align=center colspan=2>';
   }

   text +=  '<font size=1 color=black face="verdana">' + g_WEATHERPROMPT + ':</font><br>' + '\n' +
            '</td></tr><tr><td align=right valign=middle><input name="thisZip" size=15></td>' +
            '<td align=left valign=middle>&nbsp;<input id="getForcast" type="button" class="btn-std" name="Forcast" value="' + g_WEATHERGETFORECAST + '" onclick="javascript:SubmitAccuW(\''+this.weatherURL+'\');">' +
            '</td></tr>' + '\n'

   if (this.worldURL && this.worldURL.length>0) {
       text +=  '<tr><td align=center colspan=2>' +
                '<font face="verdana" size=1>[<a href="/frame_saver.asp?url=' +
                escape(this.worldURL) + '" id="worldForecasts">' + g_WEATHERWORLDFORECAST + '</a>]</font><br>' +
                '</td></tr>' + '\n';
   }

   text +=  '</table></form>';

   return text;
}

/*
 *
 * Opt-in Email window
 *
 *
 * This can be removed for B22
 * Opt-in email no longer exists
 *
 */

function Optin() {

   // methods
   this.display = DisplayOptin;

}

function DisplayOptin() {

   var spam = '<tr><td>' + '\n' +
              '<form name=opt_in method=post action="in_start.asp?command=save" ONSUBMIT="return ValidateForm(this)">' + '\n' +
              '<table width=98% cellspacing=0 border=0 cellpadding=0 bgcolor=#FFFFCC>' + '\n' +
              '<tr>' + '\n' +
              '<td align=left valign=top>' + '\n' +
                  '&nbsp;<input type="checkbox" name="cat_' + g_IDfree_stuff + '" value="on"><span class=strtpg-ann-item>' + g_HOMEFREESTUFF + '</span>' + '\n' +
                  '</td><td align=left valign=top>' + '\n' +
                  '<input type="checkbox" name="cat_' + g_IDit_professionals + '" value="on"><span class=strtpg-ann-item>' + g_HOMEITPROF + '</span>' + '\n' +
                  '</td></tr><tr><td align=left valign=top>' + '\n' +
                  '&nbsp;<input type="checkbox" name="cat_' + g_IDfinance_investing + '" value="on"><span class=strtpg-ann-item>' + g_HOMEFINANCE + ' &amp; ' + g_HOMEINVESTING + '</span>' + '\n' +
                  '</td><td align=left valign=top>' + '\n' +
                  '<input type="checkbox" name="cat_' + g_IDtravel + '" value="on"><span class=strtpg-ann-item>' + g_HOMETRAVEL + '</span>' + '\n' +
              '</td></tr><tr><td align=left valign=top colspan=2>' + '\n' +
              '&nbsp;&nbsp;<a href="/opt/optin_email.asp" name="moreOptin" target=in_body><span class=strtpg-seemore>' + g_HOMESEEMORE + '...</span></a>' + '\n' +
              '</td></tr><tr><td colspan=2><span class=strtpg-br><br></span></td></tr><tr><td align=left valign=top colspan=2 nowrap>' + '\n' +
              '&nbsp;&nbsp;<input type="text" name="emailaddress" size="18" value="' + g_HOMEENTEREMAIL + '" maxlength="80">' + '\n' +
              '&nbsp;&nbsp;<input type="submit" name="subscribe" value="' + g_HOMESUBSCRIBE + '">' + '\n' +
              '</td></tr></table></form></td></tr>' + '\n';

   return spam;
}


/*
 *
 * Window Action
 *
 */

function INAction(action, text, target, htmlID) {
   this.action = action;
   this.text   = text;
   this.target = target;

   this.htmlID = htmlID;
   
   // methods
   this.display = DisplayAction;
}

function DisplayAction() {
   return('<a href="' + this.action + '" target="' + this.target + '" id="' + this.htmlID + '" class="link-nounder">' + this.text + '</a>');
}


/*
 *
 * Window Object
 *
 */

function INWindow(appid, title, icon, titleURL, bCanClose) {

   // member data
   this.appid        = appid;
   this.id           = 'win' + appid;
   this.collapsedid  = 'win' + appid + '_collapsed';
   this.title        = title;

   this.icon      = icon;
   this.titleURL  = titleURL;
   this.bCanClose = bCanClose;

   this.winStyle       = 'block';
   this.collapsedStyle = 'none';

   this.actions   = new Array();
   this.content   = new Array();


   // methods
   this.display       = DisplayWindow;
   this.WindowTop     = WindowTop;
   this.WindowBottom  = WindowBottom;
   this.setAction     = SetAction;
   this.setContent    = SetContent;
   this.setVisibility = SetVisibility;


   this.removeButton = DoRemoveButton;

   this.HTML = new Array();
}

function SetAction(action, text, target, htmlID) {
   this.actions[this.actions.length] = new INAction(action, text, target, htmlID);
}

function SetContent(contentObj) {
   this.content[this.content.length] = contentObj;
}

function WindowTop() {

    this.HTML.push('<div class="win-container" id="win' + this.appid + '" style="display: ' + this.winStyle +';"><div class="win">');
    this.HTML.push('<div class="win-header"><img src="/images/apps/' + this.icon + '32.gif" class="win-img"/>');
    this.HTML.push('<div class="win-title">');

    // min / max icons
    if (this.bCanClose) {
        this.HTML.push('<img src="/images/schemes/ico_close_' + CSS_ID + '.gif" class="win-img-minmax" onclick="EVENT_close_window(\'' + this.appid + '\');" title="' + g_CLOSE + '"/>');
    }
    this.HTML.push('<img src="/images/schemes/ico_min_' + CSS_ID + '.gif" class="win-img-minmax" onclick="EVENT_minimize_window(\'' + this.id + '\',\'' + this.collapsedid + '\',\'' + this.appid + '\', true);" title="' + g_MINIMIZE + '"/>');

    // Window Title
    this.HTML.push('<div class="win-title-text">');
    if (this.titleURL != null && this.titleURL.length > 0) {
       this.HTML.push('<a href="' + this.titleURL + '" id="' + this.icon + '">' + this.title + '</a>');
    }
    else {
       this.HTML.push(this.title);
    }
    this.HTML.push('</div>');

    // Close win-title
    this.HTML.push('</div>');

    // Window actions
    if (this.actions.length) {
       this.HTML.push('<div class="win-subsection-options">');
       for (var i = 0; i < this.actions.length; i++) {

          this.HTML.push(this.actions[i].display());

          if ( (i + 1) < this.actions.length) {
             this.HTML.push('&nbsp;|&nbsp;');
          }

       }
       this.HTML.push('</div>');
    }

    // Close win-header
    this.HTML.push('</div>');

    // window contents
    this.HTML.push('<div class="win-contents">');
}

function WindowBottom() {

    // close out window contents
    this.HTML.push('</div>');

    this.HTML.push('</div></div>');
}

function DisplayWindow() {

   // set window and collapsed window visibility
   this.setVisibility();

   //
   // Write out the full window first
   //
   this.WindowTop();

   if(this.content.length > 0) {
       for(var i = 0; i < this.content.length; i++) {
           this.HTML.push(this.content[i].display());
       }

   }

   this.WindowBottom();

   //
   // write out the collapsed window
   //
   this.HTML.push('<div class="win-container" id="win' + this.appid + '_collapsed" style="display: ' + this.collapsedStyle +';"><div class="win win-collapsed">');
   this.HTML.push('<div class="win-header-collapsed"><img src="/images/apps/' + this.icon + '16.gif" class="win-img-collapsed" title="' + g_MINIMIZE + '">');

   // win-title
   this.HTML.push('<div class="win-title-collapsed">');

   if (this.bCanClose) {
      this.HTML.push('<img src="/images/schemes/ico_close_' + CSS_ID + '.gif" class="win-img-minmax" onclick="EVENT_close_window(\'' + this.appid + '\')" title="' + g_CLOSE + '"/>');
   }

   this.HTML.push('<img src="/images/schemes/ico_restore_' + CSS_ID + '.gif" class="win-img-minmax" onclick="EVENT_restore_window(\'' + this.id + '\',\'' + this.collapsedid + '\',\'' + this.appid + '\', true);" title="' + g_RESTORE + '"/>');

   // window title
   this.HTML.push('<div class="win-title-text">');
   if (this.titleURL != null && this.titleURL.length > 0) {
      this.HTML.push('<a href="' + this.titleURL + '">' + this.title + '</a>');
   }
   else {
      this.HTML.push(this.title);
   }
   this.HTML.push('</div>');

   // close win-title
   this.HTML.push('</div>');
   // win-header-collapsed
   this.HTML.push('</div>');
   // win-collapsed and win-container
   this.HTML.push('</div></div>');


   return(this.HTML.join(''));
}

function EVENT_minimize_window(id, collapsedid, appid, bReloadFooter) {

   var win        = document.getElementById(id);
   var collapsed  = document.getElementById(collapsedid);

   if (win && collapsed) {
      // add id to list of minimized windows
      setMinimizedWindowCookie(appid, 'add');

      win.style.display       = 'none';
      collapsed.style.display = 'block';

      // if we want to reload the command bar
      if (bReloadFooter) {
      loadFooter();
         show_cb_homepage('cb_lo');
         cb_menu_move();
      }
   }
}

function EVENT_minimize_all_windows() {
   toggleAllWindows('minimize');
}

function EVENT_restore_window(id, collapsedid, appid, bReloadFooter) {

   var win        = document.getElementById(id);
   var collapsed  = document.getElementById(collapsedid);

   if (win && collapsed) {
      // delete id from list of minimized windows
      setMinimizedWindowCookie(appid, 'delete');

      win.style.display       = 'block';
      collapsed.style.display = 'none';

      // if we want to reload the command bar
      if (bReloadFooter) {
      loadFooter();
         show_cb_homepage('cb_lo');
         cb_menu_move();
      }
   }
}

function EVENT_restore_all_windows() {
   toggleAllWindows('restore');
}


function EVENT_close_window(appid) {

   ConfirmRemoveApp(appid);

}

function setMinimizedWindowCookie(appid, action) {

   // the minimizedWindows cookie contains a list of application ids that
   // have been minimized on the homepage. (ex: minimizedWindows=<14><19>;)
   // note: application ids were being stored like <id>14</id><id>19</id> but a few pages threw a
   // "Potentially dangerous cookie" error because of the slashes.

   var myCookieName = "minimizedWindows";
   // build id string
   var myID = "<" + appid + ">";
   // get list of minimized windows
   var myMinimizedWin = getCookieValue(myCookieName);
   // always try to delete the id string first to make sure we never get duplicates
   var myNewMinimizedWin = myMinimizedWin.replace(myID, "");

   // add id string to list of minimized windows
   if (action == "add") {
      myNewMinimizedWin = myNewMinimizedWin + myID;
   }
   // don't need to do anything for restored windows. id string has already been removed.

   var exp = new Date()
   var oneYearFromNow = exp.getTime() + (365*24*60*60*1000)
   exp.setTime(oneYearFromNow)
   document.cookie= myCookieName + "=" + myNewMinimizedWin + "; expires=" + exp.toGMTString() + "; path=/";
}

function getCookieValue(cookieName) {
   var myCookie = document.cookie;
   var myKey    = cookieName + "=";
   var myValue  = "";
   var posStart = myCookie.indexOf(myKey);
   var posEnd   = -1;

   // if we found the key
   if (posStart != -1) {
      // find key separator
      posEnd = myCookie.indexOf(";", posStart);
      // if we didn't find a separator
      if (posEnd == -1) {
         // this is the last key in the cookie
         posEnd = myCookie.length;
      }
      myValue = myCookie.substring(posStart + myKey.length, posEnd);
   }
   return myValue;
}

function SetVisibility() {

   var myCookieName = "minimizedWindows";
   // build id string to search for
   var myID = "<" + this.appid + ">";
   // get list of minimized windows
   var myMinimizedWin = getCookieValue(myCookieName);

   // if there are any ids in our list
   if (myMinimizedWin.length != 0) {
      // if the id is found in the list of minimized windows
      if (myMinimizedWin.indexOf(myID) != -1) {
         // flip styles
         this.winStyle       = 'none';
         this.collapsedStyle = 'block';
      }
   }
}


function DoRemoveButton() {
   var text = '';
   if (!this.bGuest) {
      text = '<td align=right><a href="javascript:ConfirmRemoveApp('+this.appid+')" target="in_main"><img src="'+g_SITEIMAGEDIR+'/ico_close_window.gif" ' +
              ' border="0" title="'+g_CLOSE+'"></a></td>'
   }

   return(text);
}

function ConfirmRemoveApp(appid) {
   if(confirm(g_CONFRIMREMOVEAPP)) {
      // delete id from list of minimized windows
      setMinimizedWindowCookie(appid, 'delete');
      // remove app
      window.location= '/remove_app.asp?appid='+appid;
   }
}

/*
 *
 * User Welcome message
 *
 * Going away for B22
 * Keep around for the meantime so we know what to display in the adframe
 *
 */

function UserWelcome(userFlags, name, isGuest, isOpenSite, canRequest, strSiteName, nSiteID, nSiteBrandID, strCreateLinkAddress, seFlags, ssl) {

   var text;
   if (isGuest) {
      text = '<table width="100%" cellpadding=0 cellspacing=0 border=0>' + '\n' +
             '<tr bgcolor="#C8C8C8"><td width=5>&nbsp;</td>' + '\n' +
             '<td align=left height=25 width="100%">' +
             '<span class=strtpg-welcome-txt>' + g_HOMEWELCOME + '!&nbsp;</span><span class=strtpg-admin-txt>' + g_YOUAREGUEST + '.</span>' +
             '</td>' + '\n' +
             '<td align=right valign=top><img src="' + g_SITEIMAGEDIR + '/nav/curve.gif" border=0></td></tr>' + '\n';

      if (isOpenSite || canRequest) {
         text += '<tr bgcolor="#E0E0E0"><td width=5>&nbsp;</td><td align=left width="100%"><span class=links-small>' +
                  g_GUESTMESSAGE + '&nbsp;';

         if (canRequest) {
            text += '<a href="/invitation_request.asp?from=homepage&amp;loc=' + g_LocaleID + '" target="_top">';
         }
         else {
            text += '<a href="/register_member.asp?loc=' + g_LocaleID +'" target="_top">';
         }

         text +=  g_JOINNOW + '</a>.</span>' + '\n' +
                  '</td><td width=5>&nbsp;</td></tr>' + '\n';
      }

      text += '</table>' + '\n';


   }
   else {

      var align   = ( (userFlags & 1) && (seFlags & 1) ) ? 'center' : 'left';
      var hgt     = ( (userFlags & 1) && (seFlags & 1) ) ? '45' : '25';

      text = '<table width="100%" cellpadding=0 cellspacing=0 border=0>' + '\n' +
             '<tr bgcolor="#CCCCCC">' + '\n' +
             '<td align=' + align + ' height=' + hgt + ' width="100%">' + '\n';

      var sAdmin     = '<span class=strtpg-admin-txt>';
      var links_small_open    = '<span class=links-small>';
      var links_small_close   = '</span>';
      var personalize_site    = links_small_open + '<a href="/home/edituserprefs.asp?tab=TabHomePage" target=in_main>' + g_HOMEPERSONALIZELINK + '</a>' + links_small_close;

      if (userFlags & 1) {

         var links_separator     = '<span class=strtpg-admin-txt>&nbsp;|&nbsp;</span>';

         var manage_site         = links_small_open + '<a href="/home/managesite.asp" target=in_main>' + g_HOMEMANAGESITELINK + '</a>' + links_small_close;
         var customize_site      = links_small_open + '<a href="/home/editsite.asp" target=in_main>' + g_HOMECUSTOMIZELINK + '</a>' + links_small_close;
         var try_professional    = links_small_open + '<a href="/splash/pe_info.asp" target=in_main>' + g_TRYPROFESSIONAL + '</a>' + links_small_close;
         var upg_professional    = links_small_open + '<a href="http://www.webexone.com/commerce/subscribe1.asp?bill_site_id=' + nSiteID + ssl + '" target=_top>' + g_UPGRADEPROFESSIONAL + '</a>' + links_small_close;

         sAdmin += g_HOMEADMINOFSITE + '</span>';

         if (seFlags & 1) {

            sAdmin += '<br>' + manage_site + links_separator + customize_site + links_separator + personalize_site + links_separator;

            if (seFlags & 2) {
               sAdmin += try_professional + links_separator;
            }

            sAdmin += upg_professional;
         }
         else {
            sAdmin += '&nbsp;</td><td align=right>' + manage_site + links_separator + customize_site + links_separator + personalize_site;
         }

      }
      else {
         sAdmin = '&nbsp;</td><td align=right>' + personalize_site;
      }

      var sWelcome   = '<span class=strtpg-welcome-txt>&nbsp;' + g_HOMEWELCOME;
      sWelcome += (name.length) ? (', ' + name) : '';
      sWelcome += '</span>';

      text += sWelcome + '&nbsp;&nbsp;' + sAdmin;
      text += '</td><td align=right valign=top><img src="' + g_SITEIMAGEDIR + '/nav/curve.gif" border=0></td></tr></table>' + '\n';

   }

   return text;

}

function Footer(helpLocale, sfFlags, brandFlags2, tos, logo, logoURL, bLink, tafURL, siteHelpDir) {

    var tosHREF = "javascript: open_remote01('" + tos + "', '', '');";

    var text = '<div class="footer-container" id="footer">';

    /*
     * BrandFlag2_NoHomePageFooterLinks
     */
    if ( !(brandFlags2 & 0x40000) ) {
        text += '<div class="footer">';

        // Email the administrators
        // This floats to the right, so it is first in line
        text += '<div><img src="/images/ico/ico_email.gif" title="' + g_HOMEEMAILADMIN + '"/>';
        text += '<a href="/email-admin.asp">' + g_HOMEEMAILADMIN + '</a></div>';


       // New to Intranets?
       text += '<a href="javascript: cb_openhelp(\'' + helpLocale + '\',\'#html/welcome.htm\',\'' + siteHelpDir + '\');">' + g_HOMENEWTOINTRANETS + '</a>';

       // FAQs
       text += ' | <a href="javascript: cb_openhelp(\'' + helpLocale + '\',\'#html/faqs.htm\',\'' + siteHelpDir + '\');">' + g_HOMEFAQ + '</a>';

       // New Features
       text += ' | <a href="javascript: cb_openhelp(\'' + helpLocale + '\',\'#html/the_latest_new_features.htm\',\'' + siteHelpDir + '\');">' + g_HOMENEWFEATURES + '</a>';

       // Feedback
       text += ' | <a href="https://support.webex.com/webexone/support" target="_blank">' + g_TELLUS + '</a>';

       // Tell a Friend
       if (tafURL != '') {
          text += ' | <a href="javascript: open_remote01(\'' + tafURL + '\', \'\', \'\');">' + g_HOMETELLAFRIEND + '</a>';
       }

       /*
        * BrandFlag2_NoHelpLink
        * OR
        * SiteFeature_NoHelpLink
        */
       if ( !(sfFlags & 4) && !(brandFlags2 & 0x80000) ) {
          text += ' | <a href="javascript: cb_openhelp(\'' + helpLocale + '\',\'#html/welcome.htm\',\'' + siteHelpDir + '\');">' + g_HOMEHELP + '</a>';
       }

       text += '</div>';
    }

    // Copyright
    text += '<div class="copyright">';

    // build copyright text
    var ctext = g_SOCOPYRIGHT + ' &copy ';
    var dateToday = new Date();
    ctext += '1999-' + dateToday.getFullYear();

    text += '<span title="' + ctext + '. ' + g_HOMEINTRANETSCOM + '. ' + g_HOMERIGHTSRESERVED + '.">';
    text += ctext + '. ' + g_HOMERIGHTSRESERVED + '.';

    text += '</span>';

    // Subject to TOS text
    text += '<br>' + g_HOMESITESUBJECTTO;

    /*
     * BrandFlag2_NoTOSLink
     */
    if ( brandFlags2 & 0x8 ) {
       text += ' ' + g_HOMETERMSOFSERVICE + '.';
    }
    else {
       text += ' <a href="' + tosHREF + '">' + g_HOMETERMSOFSERVICE + '</a>.';
    }

    // close out copyright section
    text += '</div>';


    // disable logo link for partners
    text += '<div style="text-align: center; margin-top: 5px; margin-bottom: 20px;">';
    text += bLink ? '<a href="javascript: open_remote01(\'' + logoURL + '\',\'\', \'\')">' : '';
    text += '<img src="' + g_SITEIMAGEDIR + '/' + logo + '" align="middle" border="0">';
    text += bLink ? '</a>' : '';
    text += '</div>';

    // open bottom command bar div
    text += '<div>';

    return text;
}

function toggleAllWindows(toggleType) {

   // all window elements have an id that begins with this prefix
   var winPrefix          = 'win';
   // collapsed windows end in this suffix
   var winCollapsedSuffix = '_collapsed';

   var id;
   var collapsedid;
   var appid;

   // array of columns
   var arrColumns = new Array('col1','col2');
   var columnContainer;

   for (i=0; i < arrColumns.length; i++) {
      columnContainer = document.getElementById(arrColumns[i]);
      if (columnContainer) {

         // loop through all child nodes in the column container div
         for (j=0; j < columnContainer.childNodes.length; j++) {

            // if this node is a DIV (no need to look at text objects
            if (isElemADiv(columnContainer.childNodes[j])) {

               // loop through all child nodes of this child
               for (k=0; k < columnContainer.childNodes[j].childNodes.length; k++) {

                  // skip non-div tags
                  if (isElemADiv(columnContainer.childNodes[j].childNodes[k])) {

                     // if this div contains the window prefix
                     if (isElemAWindow(columnContainer.childNodes[j].childNodes[k], winPrefix) && !isElemACollapsedWindow(columnContainer.childNodes[j].childNodes[k], winCollapsedSuffix)) {

                        id = columnContainer.childNodes[j].childNodes[k].id;
                        collapsedid = id + winCollapsedSuffix;
                        appid = id.replace(winPrefix, '');

                        if (toggleType == 'minimize') {
                           EVENT_minimize_window(id, collapsedid, appid, false);
                        }
                        else {
                           EVENT_restore_window(id, collapsedid, appid, false);
                        }
                     }
                  }
               }
            }
         }
      }
   }

   // redisplay footer after minimizing/restoring all
   loadFooter();
   show_cb_homepage('cb_lo');
   cb_menu_move();

}

// determine if an element is a div
function isElemADiv(elem) {

   var isDiv = false;

   if (elem) {
      if (elem.nodeName == 'DIV') {
         isDiv = true;
      }
   }

   return isDiv;
}

// determine if an element is a application window
function isElemAWindow(elem, prefix) {

   var isWin = false;

   if (elem) {
      // if the window prefix is found at the very beginning of the id
      if (elem.id.indexOf(prefix) == 0) {
         isWin = true;
      }
   }

   return isWin;
}

// determine if an element is a collapsed application window
function isElemACollapsedWindow(elem, suffix) {

   var isCollapsedWin = false;

   if (elem) {
      // if the window prefix is found at the very beginning of the id
      if (elem.id.indexOf(suffix) >= 0) {
         isCollapsedWin = true;
      }
   }

   return isCollapsedWin;
}

