//  Global objects
var gwinPopup = null;
var gszPage = null;
var gszTitle = null;

//
//  Capitalize a string.
//
function capitalize(szString)
{
  var wd = szString.split(" ");

  for (var w=0; w<wd.length; w++)
  {
    var x = wd[w];
    x = x.substr(0,1).toUpperCase() + x.substr(1); // capitalize first letter
    wd[w] = x;
  }

  szReturn = wd.join(" ");
  return szReturn;
}

//
//  Open a popup window to enter comments.
//
function comment(szPage)
{
  //  Save the page name and title
  gszPage = szPage;

  //  Define popup properties
  var wHeight=380;
  var wWidth=420;
  var wTop=(screen.height-wHeight)/2;
  var wLeft=((screen.width-wWidth)/2)-12;
  var szProps='location=no,status=no,toolbar=no,menubar=no,directories=no,scrollbars,resizable,left=' + wLeft + ',top=' + wTop + ',height=' + wHeight + ',width=' + wWidth;

  //  Close the popup if it's still opened.
  if ( gwinPopup && !gwinPopup.closed )
    gwinPopup.close();

  //  Open new popup
  gwinPopup = window.open("comment.html", "commentWindow", szProps);
  gwinPopup.focus();
  // gwinPopup.document.form.name.focus();
}

//
//  Add comments from the popup window to the database.
//
function addComment(f)
{
  var szComment = '';
  var szName = '';

  if ( gwinPopup.document.form.comment.value.length > 0 )
  {
    szComment = gwinPopup.document.form.comment.value;

    if ( gwinPopup.document.form.name.value.length > 0 )
      szName = gwinPopup.document.form.name.value;
  }

  cancelComment();

  if ( szComment.length > 0 )
  {
    szHREF = window.location.href;
    szHREF = szHREF.substr(7);
    szHREF = szHREF.replace(/&/g,"*am*");
    szHREF = szHREF.replace(/=/g,"*eq*");
    szHREF = szHREF.replace(/\+/g,"*pl*");

    szLoc  = "comment.php?&page=" + gszPage;
    szLoc += "&comment=" + szComment;
    if ( szName.length > 0 )
      szLoc += "&name=" + szName;
    szLoc += "&href=" + szHREF;
    window.location = szLoc;
  }

  return false;
}

//
//  Close the popup window
//
function cancelComment ()
{
  if ( gwinPopup )
  {
    gwinPopup.close();
    gwinPopup = null;
  }
}

//
//  Add a mailto: link.
//
function jemail(user, domain, suffix)
{
  linkName =  user + '@' + domain + '.' + suffix;

  document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + linkName + '</a>');
}

//
//  Open an actor page.
//
function linkActor(szID)
{
  window.location = 'actor.php?&id=' + szID + '&width=' + screen.width + '&height=' + screen.height;
}

//
//  Open a con
//
function linkCon(szID)
{
  window.location = 'con1.php?&id=' + szID;
}

//
//  Open a list page
//
function linkList(szName)
{
  window.location = 'list.php?&name=' + szName;
}

//
//  Link to the MidAmerican Fan Photo Archive.
//
function linkMAFPA(szString)
{
  szLocation = 'http://www.google.com/search?q=%22' +
               szString.replace(" ","+") +
               '%22&btnG=Google+Search&domains=http%3A%2F%2Fmidamericon.org&sitesearch=http%3A%2F%2Fmidamericon.org';
  window.location = szLocation;
}

//
//  Open a generic page
//
function linkPage(szName)
{
  window.location = 'page.php?&name=' + szName;
}

//
//  Open a photo page
//
function linkPhoto(szPhotoID)
{
  window.location = 'photo.php?&id=' + szPhotoID + '&width=' + screen.width + '&height=' + screen.height;
}

//
//  Open a performance
//
function linkPlay(szID)
{
  window.location = 'play.php?&id=' + szID;
}

//
//  Open a venue
//
function linkVenue(szID)
{
  window.location = 'venue.php?&id=' + szID;
}


