// var pictureWindow = null;

function email_address()
{
    var s1 = "&#99;&#111;&#109;";
    var s2 = "&#46;";
    var s3 = "&#103;&#109;&#97;&#105;&#108;";
    var s4 = "&#64;";
    var s5 = "&#112;&#104;&#111;&#116;&#111;";
    var s6 = "&#115;&#101;&#97;&#115;&#111;&#110;&#115;";
    var s7 = "&#102;&#111;&#117;&#114;";

    return s7 + s6 + s5 + s4 + s3 + s2 + s1;
}

function phone_number()
{
    var s1 = "&#55;&#52;&#50;&#52;";
    var s2 = "&#45;";
    var s3 = "&#57;&#57;&#55;";
    var s4 = "&#45;";
    var s5 = "&#57;&#53;&#50;";

    return s5 + s4 + s3 + s2 + s1;
}

function postal_address_1()
{
    var s1 = "&#68;&#114;&#105;&#118;&#101;";
    var s2 = "&#32;";
    var s3 = "&#87;&#104;&#105;&#116;&#110;&#101;&#121;";
    var s4 = "&#32;";
    var s5 = "&#49;&#48;&#57;&#50;";

    return s5 + s4 + s3 + s2 + s1;
}

function postal_address_2()
{
    var s1 = "&#53;&#53;&#49;&#50;&#52;";
    var s2 = "&#32;";
    var s3 = "&#77;&#78;";
    var s4 = "&#44;&#32;";
    var s5 = "&#86;&#97;&#108;&#108;&#101;&#121;";
    var s6 = "&#32;";
    var s7 = "&#65;&#112;&#112;&#108;&#101;";

    return s7 + s6 + s5 + s4 + s3 + s2 + s1;
}

function isDigit(ch)
{
    return ch >= '0' && ch <= '9';
}

function isNumber(str)
{
    for (var i = 0; i < str.length; i++)
    {
        var ch = str.charAt(i);
        if (!isDigit(ch))
        {
            return false;
        }
    }

    return true;
}

function viewGallery()
{
    var galleryCode = document.getElementById("galleryCode").value;
    if (galleryCode.length != 4 || !isNumber(galleryCode))
    {
        alert("Sorry, that gallery code is not valid. Please enter a four digit gallery code (e.g., 1234).");
        return false;
    }

    var url = ".?page=" + galleryCode;
    location.assign(url);

    return false;
}

/*
function closePictureWindow()
{
    if (pictureWindow)
    {
        if (!pictureWindow.closed)
        {
            pictureWindow.close();
        }
        pictureWindow = null;
    }
}

function displayPicture(pictureURL, width, height)
{
    xPos = getWindowX() + (getViewportWidth() / 2) - (width / 2);
    yPos = getWindowY() + (getViewportHeight() / 2) - (height / 2);

    closePictureWindow();

    openPictureWindow(pictureURL, xPos, yPos, width, height);
}

function openPictureWindow(pictureURL, xPos, yPos, width, height)
{
    var windowAttributes = "width=" + width + ",height=" + height + ",resizable=no,left=" + xPos + ",top=" + yPos;
    pictureWindow = window.open("", "", windowAttributes);

    pictureWindow.document.open();

    pictureWindow.document.write("<html>");
    pictureWindow.document.write("<head><title>Picture Window</title></head>");
    pictureWindow.document.write("<body style=\"margin: 0\"><img src=\"" + pictureURL + "\"></body>");
    pictureWindow.document.write("</html>");

    pictureWindow.document.close();

    pictureWindow.focus();
}

function getViewportHeight()
{
  if (window.innerHeight)
  {
    return window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  {
    return document.documentElement.clientHeight;
  }
  else if (document.body.clientHeight)
  {
    return document.body.clientHeight;
  }

  return 0;
}

function getViewportWidth()
{
  if (window.innerWidth)
  {
    return window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth)
  {
    return document.documentElement.clientWidth;
  }
  else if (document.body.clientWidth)
  {
    return document.body.clientWidth;
  }

  return 0;
}

function getWindowX()
{
  if (window.screenLeft)
  {
    return window.screenLeft;
  }
  else if (window.screenX)
  {
    return window.screenX;
  }

  return 0;
}

function getWindowY()
{
  if (window.screenTop)
  {
    return window.screenTop;
  }
  else if (window.screenY)
  {
    return window.screenY;
  }

  return 0;
}
*/

function externalLinks()
{
    if (!document.getElementsByTagName)
    {
        return;
    }

    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++)
    {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
        {
            anchor.target = "_blank";
        }
    }
}

// window.onload = externalLinks;

window.onload = function()
{
    externalLinks();

    var galleryCode = document.getElementById("galleryCode");
    if (galleryCode)
    {
        galleryCode.focus();
    }
}
