function Len(string)
{
	if (string == null)
		return (false);

	return String(string).length;
}

function setRelativeRoot()
{
  var TestStr2 = "/AWSWeb/";
  TestLen = Len(TestStr2);
  var Pos = 0;
  var PathLen = 0;
  var PathLen4 = 0;
  var MPos = 0;
  var LPos = 0;
  var LLen = 0;
  var CPath = "";
  CPath = location.href;
  PathLen = Len(CPath);
  PathLen4 = PathLen - TestLen + 1;
  var TestStr = ""
  Pos = 1;
  MPos = PathLen4;
  while (Pos <= PathLen4)
    {
    TestStr = CPath.substr(Pos, TestLen);
    if (TestStr == TestStr2)
      {
      MPos = Pos;
      break;
      }
    Pos++;
    }
  if (Pos < PathLen4)
    LPos = Pos + TestLen;
  else
    for (Pos = 8; Pos <= PathLen; Pos++)
      if (CPath.substr(Pos, 1) == "/")
        {
        LPos = Pos + 1;
        break;
        }
  LLen = PathLen - LPos + 1;
  FPath = CPath.substr(LPos, LLen);
  FLen = Len(FPath);
  Pos = 1;
  var SlashCnt = 0;
  while (Pos <= FLen)
    {
    if (FPath.substr(Pos, 1) == "/")
      SlashCnt++;
    Pos++;
    }
  if (SlashCnt == 0)
    relativeRoot = "./";
  else
    {
    relativeRoot = "";
    for (LoopCnt = 1; LoopCnt <= SlashCnt; LoopCnt++)
      relativeRoot += "../";
    }
}

function mailURL()
{ 
  HTMLtitle = document.title;
  docutitle = "";
  pNode = document.getElementById("doctitle");
  cNodes = pNode.childNodes;
  for (var i = 0; i < cNodes.length; i++) 
    {
    var child = cNodes[i];
    docutitle = docutitle + child.nodeValue;
    }
  if (Len(HTMLtitle) > Len(docutitle))
    { docutitle = HTMLtitle; }
  titlelen = Len(docutitle);
  titlepos = titlelen;
  while (titlepos >= 0)
    {
    TestPos = docutitle.substr(titlepos, 1);
    escTestPos = escape(TestPos);
    pt1 = docutitle.substring(0, titlepos);
    pt2 = docutitle.substring(titlepos + 1, Len(docutitle));
    if (TestPos == '"')
      {
        if (titlepos == 0)
          { docutitle = "%22" + docutitle.substring(1, Len(docutitle)); }
        else
          {
          if (titlepos == titlelen)
            { docutitle = docutitle.substring(0, Len(docutitle) - 1) + "%22"; }
          else
            { docutitle = pt1 + "%22" + pt2; }
          }
      }
    if (TestPos == "'")
      {
        if (titlepos == 0)
          { docutitle = "%27" + docutitle.substring(1, Len(docutitle)); }
        else
          {
          if (titlepos == titlelen)
            { docutitle = docutitle.substring(0, Len(docutitle) - 1) + "%27"; }
          else
            { docutitle = pt1 + "%27" + pt2; }
          }
      }
    if (TestPos == "?")
      {
        if (titlepos == titlelen)
          { docutitle = docutitle.substring(0, titlelen - 1) + "%3F"; }
        else
          { docutitle = pt1 + "%3F" + pt2; }
      }
    if (TestPos == "&")
      {
        if (docutitle.substr(titlepos, 2) == "& ")
          { docutitle = pt1 + "%26" + pt2; }
        if (docutitle.substr(titlepos, 7) == "&mdash;")
          { docutitle = pt1 + "--" + pt2.substring(6, Len(pt2)); }
        if (docutitle.substr(titlepos, 5) == "&amp;")
          { docutitle = pt1 + "%26" + pt2.substring(4, Len(pt2)); }
      }
    if (escTestPos == "%u2014")
      { docutitle = pt1 + "--" + pt2; }
    if (TestPos == "<")
      {
        if (docutitle.substr(titlepos, 4) == "<br>")
          { docutitle = pt1 + " " + pt2.substring(3, Len(pt2)); }
        if (docutitle.substr(titlepos, 3) == "<u>")
          { docutitle = pt1 + pt2.substring(2, Len(pt2)); }
        if (docutitle.substr(titlepos, 4) == "</u>")
          { docutitle = pt1 + pt2.substring(3, Len(pt2)); }
      }
    if (escTestPos == "%0A")
      { docutitle = pt1 + " " + pt2; }

    if (TestPos == "n")
      { if (docutitle.substr(titlepos, 4) == "null")
          { if (escape(docutitle.substr(titlepos + 4, 1)) == "%20")
              { if (docutitle.substr(titlepos - 1, 1) == " ")
                  { docutitle = pt1.substring(0, Len(pt1) - 1) + " " + pt2.substring(4, Len(pt2)); }
                else
                  { docutitle = pt1 + " " + pt2.substring(4, Len(pt2)); }
              }
            else
              { docutitle = pt1 + " " + pt2.substring(3, Len(pt2)); }
          }
      }
    if (TestPos == "S")
      {
        if (docutitle.substr(titlepos, 3) == "Say")
          { if (docutitle.substr(titlepos + 3, 3) == "%3F")
              { docutitle = pt1 + "Really Say%3F"; }
          }
      }
    titlepos--;
    }
  MLsubject = escape("A page from the Acaciawood School Website");
  MLbody = escape(docutitle + " (" + location.href + ")");
  mailToURL = "mailto:?subject=" + MLsubject + "&body=" + MLbody;
  window.location = mailToURL;
}

function offml()
{
m1 = "lt";
m2 = "mai";
m3 = "o:";
a1 = "ce@";
a2 = "hool";
a3 = "awsc";
a4 = ".org";
a5 = "offi";
ml = m2 + m1 + m3 + a5 + a1 + a3 + a2 + a4;
document.write('<a href="' + ml + '">');
document.write('<img src="' + relativeRoot + 'graphics/OffEMail.gif" border="0"></a>');
}

function webml()
{
m1 = "lt";
m2 = "mai";
m3 = "o:";
a1 = "mas";
a2 = "hool";
a3 = "awsc";
a4 = ".org";
a5 = "web";
a6 = "ter@";
ml = m2 + m1 + m3 + a5 + a1 + a6 + a3 + a2 + a4;
document.write('<a href="' + ml + '">');
document.write('<img src="' + relativeRoot + 'graphics/WebEMail.gif" border="0"></a>');
}
