/*
  Prevent framing of site, and re-unite stray pages with CBG frameset
*/

var defaultPage = "homepage.htm";
var newPage = "";

function CheckMyLocation()
{
  if (window == top || window.name != "CBGContent")
  {
     window.location = "http://www.cascadebrewersclub.org/?pageName=" + GetMyPageName()
     // window.location = "index.htm?pageName=" + GetMyPageName()
  }
}

function GetMyPageName()
{
  var path = window.location.pathname;
  return path.substring(path.lastIndexOf('/') + 1);
}

function GetFramedPageByName()
{
  newPage = GetQuerystringVariable("pageName");
  if (newPage.indexOf(".htm") == -1)
  {
    newPage = defaultPage;
  }
  parent.CBGContent.location.href = newPage;
}


function GetQuerystringVariable(variableName)
{
  var queryString = window.location.search.substring(1);
  var variables = queryString.split("&");
  for (var i=0; i<variables.length; i++)
  {
    var keyValuePair = variables[i].split("=");
    if (keyValuePair[0] == variableName) {
      return keyValuePair[1];
    }
  }
  return "VARIABLE NOT FOUND";
}

function BreakOutOfFrames()
{
  if (parent.location.href != window.location.href)
  {
    parent.location.href = window.location.href;
  }
}


