
// -------------------------------------------------

// indexloaded
// ===========
// Called when the frameindex page is loaded to do lots of exciting stuff

function indexloaded(doc)
{
  if (doc.implementation)
  { alert ("indexLoaded called");
    doQuotes (doc);

    doEMails (doc);
  }
}

// -------------------------------------------------

// contentloaded
// =============
// Called when a content page is loaded to put quotes where needed and other stuff

function contentloaded(doc)
{ alert ("contentLoaded called");
  if (doc.implementation)
  {
    doQuotes (doc);

    doNicknames (doc);

    doEMails (doc);
  }
}

// -------------------------------------------------

// doQuotes
// ========
// Called from contentloaded and indexLoaded to insert single or double quotes around <q> strings

function doQuotes(doc)
{
  var quotes = doc.getElementsByTagName("q");

  for (var n=0; n<quotes.length; n++)
  { alert("doQuotes: <q> tag found");
    quoteIt (doc, quotes[n], quotes[n].parentNode.nodeName == "Q" ? 1 : 2);
  }
}

// -------------------------------------------------

// doNicknames
// ===========
// Called from contentloaded to insert single quotes around class="nickname" strings

function doNicknames(doc)
{
  var spans = doc.getElementsByTagName("span");

  for (var n=0; n<spans.length; n++)
  {
    if (spans[n].className == "nickname")
    { alert("doNicknames: class = \"nickname\" found");
      quoteIt (doc, spans[n], 1);
    }
  }
}

// -------------------------------------------------

// quoteIt
// =======
// Called from doQuotes and doNicknames to insert single or double quotes around a string

function quoteIt (doc, element, num)
{ alert("quoteIt called");
  var openquote = num == 1 ? "\u2018" : "\u201c";
  var closequote = num == 1 ? "\u2019" : "\u201d";

  element.insertBefore(doc.createTextNode(openquote), element.firstChild);
  element.appendChild(doc.createTextNode(closequote));
}

// -------------------------------------------------

// doEMails
// ========
// Called from contentLoaded and indexLoaded to set href for an "a" element with class="mailto..."

function doEMails(doc)
{
  var as = doc.getElementsByTagName("a");

  for (var n=0; n<as.length; n++)
  {
    if (as[n].className.substr(0, 6) == "mailto")
    { alert ("doEMails: " + as[n].className.substr(6) + " called");
      as[n].href = "mailto:" + as[n].className.substr(6) + "@hitchinsymphony.org.uk";
    }
  }
}

// -------------------------------------------------

function mailto (name)
{
  self.location.href = "mailto:" + name + "@" + "hitchinsymphony.org.uk";
}

// -------------------------------------------------

// frameBiography
// ==============
// Included at the foot of a biography page to ensure that 
// it has a link to its programme page if called directly

function frameBiography(programme)
{
  if (window.name != "hsobiog")
  {
    document.writeln("This biography is a part of the <a href=" + programme + ">Hitchin Symphony Orchestra</a> web site");
  }
}

// -------------------------------------------------

// openBiography
// =============
// Open a new window for a Biography entry

function openBiography (pagehref) 
{
var win;
  win = window.open(pagehref, "hsobiog", "width=600,height=420,dependent=yes,resizable=yes,scrollbars=yes,location=no");
  win.focus();
}

// -------------------------------------------------

// openPicture
// ===========
// Open a new window for a Picture entry from members page

function openPicture (pichref, picwidth, picheight) 
{
  var win;

  win = window.open(pichref, "hsopic", "width=" + picwidth + ", height=" + picheight + ",dependent=yes,resizable=yes,scrollbars=yes");
  win.focus();
}

// -------------------------------------------------

// Check data entered into Mailing List request form

function checkMailingList(mailform)
{
  if (mailform.name1.value == "")
  {
    alert("Please enter your name");
    mailform.name1.focus();
    return false;
  }

  if (mailform.address1.value == "" &&
      mailform.address2.value == "" &&
      mailform.address3.value == "" &&
      mailform.postcode.value == "" &&
      mailform.email.value == "")
  {
    alert("Please enter either your address or your e-mail address");
    mailform.address1.focus();
    return false;
  }

  return true;
}
