function startPage(theme)
{
  var html='';

  if (theme==null) theme = 'photo';

  preload('images/witspsc_theme_' + theme + '_title.jpg');
  preload('images/witspsc_theme_' + theme + '_body.jpg');



  html += '  <body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0" onUnload="closePage();">';

  html += '<table cellspacing="0" cellpadding="0" border="0" style="padding:0px; margin:0px;width:100%;height:100%;">';
  html += '  <tr>';
  html += '    <td style="width:794px;">';
  html += '      <table cellspacing="0" cellpadding="0" border="0" style="padding:0px; margin:0px;height:100%;">';
  html += '        <tr>';
  html += '          <td style="background-image:url(images/witspsc_theme_'+theme+'_title.jpg);width:794px;height:47px;padding:0px;vertical-align:top">';
//  html += '               <div style="text-align:right;vertical-align:top;">';
//  html += '               <a href="javascript:emailPage();" class="menu"><img src="images/psc_icon_email.gif" border="0" alt="Email this page to a friend">&nbsp;email</a>';
//  html += '               <a href="javascript:printPage();" class="menu"><img src="images/psc_icon_print.gif" border="0" alt="Print this page">&nbsp;print</a>';
//  html += '               </div>';
  html += '          </td>';
  html += '        </tr>';
  html += '        <tr>';
  html += '          <td style="padding:0px;vertical-align:top; background-image:url(images/witspsc_theme_'+theme+'_body.jpg);width:794;background-repeat:no-repeat;background-color:rgb(203,199,186);">';
  html += '            <span class="normal">';
  html += '            <table cellspacing="0" cellpadding="0" border="0" style="padding:0px; margin:0px;height:100%;" >';
  html += '              <tr>';
  html += '                <td style="width:240px;height:525px;text-align:left;vertical-align:top;padding:10px;padding-left:18px;">';
  html += '                  <div style="height:450px"></div>';

//  if (!contains(window.location.href, 'index.htm' ))
//  {
    html += '                  <table cellpadding="0" cellspacing="0" border="0" style="margin-left:55px;">';
    html += '                    <tr><td><img src="images/witspsc_icon_print.gif" align="abs-middle">&nbsp;</td><td><a onClick="printPage();return null;" class="more">Print this page</a></td></tr>';
    html += '                    <tr><td><img src="images/witspsc_icon_email.gif">&nbsp;</td><td><a onClick="emailPage();" class="more">Email a friend</a></td></tr>';
    html += '                  </table>';
    html += '                  <table cellpadding="0" cellspacing="0" border="0" style="margin-left:48px;">';
    html += '                    <tr><td height="60"></td></tr>';
    html += '                    <tr><td><img src="images/witspsc_hand_small.gif" border="0" ></td></tr>';
    html += '                  </table>';
//  }

  html += '                </td>';
  html += '                <td id="content" style="vertical-align:top;text-align:left;padding:12px;padding-right:35px;">';
  html += '                <br>';

  document.write(html);

//  if (title!=null) document.title=document.title + ' - ' + title;

}

function endPage()
{

  if (_sectionCount!=0) endSection();


  var html='';

  html += '                </td>';
  html += '              </tr>';
//  html += '              <tr>';
//  html += '                 <td>';
//  html += '                 </td>';
//  html += '                 <td height="10">';
//  html += '                  <p align=center><img src="images/psc_hand.gif" ></p>';
//  html += '                 </td>';
//  html += '              </tr>';
  html += '            </table>';
  html += '            </span>';

  html += '          </td>';
  html += '        </tr>';
  html += '      </table>';
  html += '    </td>';
  html += '    <td >';

  html += generateMenu();

  html += '    </td>';
  html += '  </tr>';
//  html += '  <tr>';
//  html += '    <td class="footer">';
//  html += '      <img src="images/psc_icon_email.gif">&nbsp;&nbsp;<a href="javascript:emailPage();" class="menu">email a friend</a>';
//  html += '      &nbsp; &nbsp;';
//  html += '      <img src="images/psc_icon_print.gif">&nbsp;&nbsp;<a href="javascript:printPage();" class="menu">printable version</a>';
//  html += '    </td>';
  html += '  </tr>';

  html += '</table>';

  html += '  </body>';

  document.write(html);

}

function closePage()
{
  self.scrollBy(-10000,-10000);
}

function printPage()
{
  var win = openWindow('print2.htm', '', 530, 675, 'scrollbars=yes');


  var pageInfo = '';
//  pageInfo += '<hr>';
//  pageInfo += 'Palestine Solidarity Committee of South Africa<br>';
//  pageInfo += '<a href="'+document.location.href+'">' + document.location.href + '</a>';

  var html = document.all['content'].innerHTML + pageInfo;
  html = html.replace(/<a/gi, '<span style=\"text-decoration:underline\" ');
  html = html.replace(/<\/a/gi, '</span');
  html = html.replace(/images\/witspsc_hand.gif/gi, 'images/witspsc_hand_white.gif');



  win.document.all['printable'].innerHTML = html;

  win.print();
}

function emailPage()
{
  var body = 'Please read the following page on the Wits Palestine Solidarity Committee\'s website: ' + document.location.href + ' ';
  var subject = 'Wits Palestine Solidarity Committee';

  document.location.href='mailto:?subject='+subject+'&body=' + body;

}

// Menus ---------------------------------------------------------------------------------------------------------------
function generateMenu()
{

  var html = '';

  html += '        <table class="menu" cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">';
  html += '          <tr>';
  html += '            <td style="vertical-align:top; padding-left:10px;">';
  html += '              <div style="height:80px;"></div>';

  for (var i=0; i<menu.length; i++)
  {
    var menuItem = getMenuItem(i);
    var selectedMenuIndex = getSelectedMenuIndex();

    if (menuItem!=null)
    {
      if (menuItem.id!=null && trim(menuItem.id)!='')
      {
        html += '<nobr>';
        html += '<a href="'+menuItem.url+'" onClick="setSelectedMenuIndex('+ i +');">';
        if ( selectedMenuIndex=='witspsc' + i )
        {
          html += '<b>' + menuItem.id + '</b>';
        }
        else
        {
          html += menuItem.id;
        }
        html += '</a>';
        html += '</nobr><br>';
      }
      else
      {
        html += '<div class="divider"></div>';
      }
    }
  }

//  html += '               <div class="divider"></div>';
//  html += '               <div class="divider"></div>';
//  html += '               <img src="images/psc_icon_print.gif">&nbsp;<a href="javascript:printPage();" class="menu">Print this page</a>';
//  html += '               <br>';
//  html += '               <img src="images/psc_icon_email.gif">&nbsp;<a href="javascript:emailPage();" class="menu">Email a friend</a>';


  html += '            </td>';
  html += '          </tr>';
  html += '        </table>';

  return html;

}

function setSelectedMenuIndex(menuIndex)
{
  navigator.selectedMenuIndex='witspsc' + menuIndex;
}

function getSelectedMenuIndex(menuIndex)
{
  return navigator.selectedMenuIndex;
}

function getMenuItem(index)
{
  var menuItem = new Object;

  var entry = menu[index];

  if (entry!=null)
  {

    menuItem.id = menu[index][0];
    menuItem.url = menu[index][1];
  }
  else
  {
    menuItem = null;
  }

  return menuItem;
}

// sections -----------------------------------------------------------------------------------------------------------
var _sectionCount = 0;

function section(title)
{
  if (_sectionCount!=0) endSection();
  startSection(title);
}

function startSection(title)
{
  if (navigator.selectedSections==null) navigator.selectedSections='';

  var html = '';

  html +='<div id="sectionContainer" style="border-width:3px;border-color:white;">';
  html +='  <div id="sectionBar" class="section" style="cursor:pointer;" onClick="toggleSection('+(_sectionCount)+');">';
  html +='    <img align="absmiddle" id="sectionIcon'+(_sectionCount)+'" src="'+(isSelectedSection(title) ? 'images/witspsc_icon_minus.gif': 'images/witspsc_icon_plus.gif')+'">';
  html +='    <span id="sectionTitle'+(_sectionCount)+'">' + title + '</span>';
  html +='  </div>';
  html +='  <div id="sectionContent'+(_sectionCount)+'" style="display:'+(isSelectedSection(title) ? '': 'none')+';padding-left:26px;">';
//  html +='  <hr>';

  document.write(html);

  _sectionCount++;
}

function endSection()
{
  var html = '';

//  html +='  <hr>';
  html +='  </div>';
  html +='</div>';
  document.write(html);
}

function isSelectedSection(title)
{
    return navigator.selectedSections.indexOf('|'+location.href+title)>(-1);
}

function toggleSection(id)
{
  var content = document.all['sectionContent' + id];
  var icon = document.all['sectionIcon' + id];
  var title = document.all['sectionTitle' + id].innerHTML;

  var selection = '|'+location.href+title;

  if (content.style.display=='none')
  {
    content.style.display = '';
    icon.src = 'images/witspsc_icon_minus.gif';
    navigator.selectedSections+=selection;
  }
  else
  {
    content.style.display = 'none';
    icon.src = 'images/witspsc_icon_plus.gif';
    navigator.selectedSections = (navigator.selectedSections.substr(0, navigator.selectedSections.indexOf(selection), selection.length)) + (navigator.selectedSections.substr(navigator.selectedSections.indexOf(selection) + selection.length));
  }







}

// images -----------------------------------------------------------------------------------------------------------

function showThumbnail(src)
{

  var opacity = 100;
  var filter = 'alpha(opacity='+opacity+');border-width:1px;border-color:#4e3325;';
  var html = '';



  html += '<img src="'+src+'" border="0" alt="Click to enlarge" style="cursor:pointer;filter:'+filter+'" id="'+'A'+'" onMouseOver="this.style.filter=\'alpha(opacity=75);\';"  onMouseOut="this.style.filter=\''+filter+'\';" onClick="showPhoto(\''+src.replace(/_thumbnail/gi, '')+'\');">';

  document.write(html);

}

function showPhoto(src)
{
  win = openWindow(src, '_blank', 670, 510, 'resizable=yes, status=no');
  win.document.title = self.document.title;
}


// news -----------------------------------------------------------------------------------------------------------
var syndicate = new Object;

function initSyndicatedNews(max_articles, display_date, display_summaries)
{
  syndicate.title_fontbold    = false;
  syndicate.title_fontital    = false;
  syndicate.title_fontface    = 'Tahoma, Arial, MS Reference Sans Serif, MS Sans Serif';
  syndicate.title_fontsize    = display_summaries==true ? '1' : '1';
  syndicate.title_fontcolor   = '#504d40';

  syndicate.date_fontbold     = false;
  syndicate.date_fontital     = false;
  syndicate.date_fontunder    = false;
  syndicate.date_fontface     = 'Tahoma, Arial, MS Reference Sans Serif, MS Sans Serif';
  syndicate.date_fontsize     = '1';
  syndicate.date_fontcolor    = '#4e3325';

  syndicate.summary_fontbold  = false;
  syndicate.summary_fontital  = false;
  syndicate.summary_fontunder = false;
  syndicate.summary_fontface  = 'Tahoma, Arial, MS Reference Sans Serif, MS Sans Serif';
  syndicate.summary_fontsize  = '1';
  syndicate.summary_fontcolor = '#000000';

  syndicate.bgcolor           = '';
  syndicate.max_articles      = '' + max_articles;
  syndicate.display_date      = display_date;
  syndicate.display_summaries = display_summaries;
  syndicate.not_found_message = '<font face="Tahoma, Arial, MS Reference Sans Serif, MS Sans Serif" size="2" color="#000000">Sorry, no articles were found.</font>';
}

// navigator -----------------------------------------------------------------------------------------------------------
function openWindow(src, id, width, height, specs) {
	win=window.open(src,id, specs + ",width="+ width +",height="+ height);
	return win;
}

function preload(src)
{
  var img = new Image();
  img.src = src;
}


// Strings -------------------------------------------------------------------------------------------------------------
function contains(str, searchStr)
{
  return str.toLowerCase().indexOf(trim(searchStr).toLowerCase())!=-1;
}

function trim(str)
{
  var result = removeLeadingSpaces(str);
  result = removeTrailingSpaces(result);
  return result;
}

function removeLeadingSpaces(str)
{
  var result = '';

  if (str!=null)
  {
    for (var i=0; i<str.length; i++)
    {
      if (str.substr(i,1)!=' ')
      {
        return str.substring(i);
      }
    }
  }

  return str;
}

function removeTrailingSpaces(str)
{
  var result = '';

  if (str!=null)
  {
    for (var i=str.length-1; i>=0; i--)
    {
      if (str.substr(i,1)!=' ')
      {
        return str.substring(0, i+1);
      }
    }
  }
  return str;
}




