// Global.js  
//global javascript file for Bath Pavilion
function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
    {
      oldonload();
      func();
    };
  }
}

//functions to remove the word 'search' from the input box when it is clicked
function emptyInputBox()
{
  if(!document.getElementById) {return false;}
  if(!document.getElementById("searchBox")) {return false;}
  
  var searchBox =  document.getElementById("searchBox");
  searchBox.value = "search";
  
  searchBox.onfocus = function()
  {
    focus(this);
  };
  searchBox.onblur = function()
  {
    blur(this);
  };
return true;
}

function focus (target)
{
  if(target.value == "search" || target.value == target.defaultValue)
  {
    target.value = "";
  }
}

function blur(target)
{
  if(target.value === "")
  {
    target.value = "search";
  }
}

//function to add popup functionality to links with the 'popup' class
function preparePops()
{
    if(!document.getElementsByTagName)      {return false; }
    if(!document.getElementsByTagName("a")) {return false; }
    
    var links = document.getElementsByTagName("a");
    
    for(var i=0; i<links.length; i++)
    {
        var link = links[i];
        
        if(link.className == "popup")
        {
            //alert("here is a popup candidate");
            link.onclick = function ()
            {
                makePop(this);
                return false;
            };
        }
    }
    return true;
}

function makePop(link)
{
    var href = link.href;
    var myWindow = window.open(href, "popup", "status=no,toolbar=no,resizable=no,directories=no,scrollbars=yes,menubar=no,location=no,height=369,width=520");
    myWindow.focus();
}

addLoadEvent(emptyInputBox);
addLoadEvent(preparePops);