var cmgPrintAdditionalParams;

function setupPrintButton(btnPrint)
{
  if (typeof(btnPrint) == "string")
  {
    btnPrint = document.getElementById(btnPrint);
  }
  
  btnPrint.href = "javascript:cmgShowPrint()";
}

function setupShareButton(btnShare)
{
  if (typeof(btnShare) == "string")
  {
    btnShare = document.getElementById(btnShare);
  }
  
  btnShare.href = "javascript:cmgShowOverlay('cmgShareThisPage')";
}

function setupEmailButton(btnEmail)
{
  if (typeof(btnEmail) == "string")
  {
    btnEmail = document.getElementById(btnEmail);
  }
  
  var emailBody = "Check out this page from Complete Media Group - " + window.location.href;
  btnEmail.href = "mailto:?body=" + escape(emailBody);
}

function cmgShowPrint()
{
  var url = location.href + (location.search == "" ? "?" : "&") + "printme";
  if (typeof(cmgPrintAdditionalParams) == "string")
  {
    url += "&" + cmgPrintAdditionalParams;
  }
  
  var wnd = window.open(url, "printme_window", "location=no,toolbar=no,menubar=no,status=no,resizable=yes,width=980");
  wnd.focus();
}

function cmgChangeSiteBgColor(siteBgColor)
{
  createCookie("siteBgColor", siteBgColor, 365);
  
  removeClassName(document.body, "siteBgColor_([^$\\s]*)");
  addClassName(document.body, "siteBgColor_" + siteBgColor);
}

function cmgChangeSiteTextSize(siteTextSize)
{
  createCookie("siteTextSize", siteTextSize, 365);
  
  removeClassName(document.body, "siteTextSize_([^$\\s]*)");
  addClassName(document.body, "siteTextSize_" + siteTextSize);
}

var cmgSiteSupportTextSizes = ["small", "medium", "large", "extralarge"];
var cmgSiteDefaultTextSize = "medium";

function cmgIncreaseSiteTextSize()
{
  var textSizeIndex = cmgGetSiteTextSizeIndex() + 1;
  if (textSizeIndex >= 0 && textSizeIndex < cmgSiteSupportTextSizes.length)
  {
    cmgChangeSiteTextSize(cmgSiteSupportTextSizes[textSizeIndex]);
  }
}

function cmgDecreaseSiteTextSize()
{
  var textSizeIndex = cmgGetSiteTextSizeIndex() - 1;
  if (textSizeIndex >= 0 && textSizeIndex < cmgSiteSupportTextSizes.length)
  {
    cmgChangeSiteTextSize(cmgSiteSupportTextSizes[textSizeIndex]);
  }
}

function cmgGetSiteTextSizeIndex()
{
  var siteTextSize = readCookie("siteTextSize");
  if (siteTextSize == null)
  {
    siteTextSize = cmgSiteDefaultTextSize;
  }
  
  for (var i=0; i<cmgSiteSupportTextSizes.length; i++)
  {
    if (cmgSiteSupportTextSizes[i] == siteTextSize)
    {
      return i;
    }
  }
  
  return Math.ceil(cmgSiteSupportTextSizes.length / 2);
}

// Initialize CMG Page
//=====================

var querystring = new Querystring();

if (querystring.contains("printme"))
{
  document.write("<link href=\"include/cmg_print.css\" rel=\"stylesheet\" type=\"text/css\" />");

  document.onclick = function(event) {
    if (typeof(event) == "undefined") event = window.event;
    
    event.returnValue = false;
    return false; // pass argument event block
  };
}

function cmgOnPageLoad()
{
  if (querystring.contains("printme"))
  {
    window.print();
  }
}

function cmgOnBodyInit()
{
  var siteBgColor = readCookie("siteBgColor");
  if (siteBgColor != null)
  {
    cmgChangeSiteBgColor(siteBgColor);
  }

  var siteTextSize = readCookie("siteTextSize");
  if (siteTextSize != null)
  {
    cmgChangeSiteTextSize(siteTextSize);
  }
}

//=====================
