﻿var pgHost = typeof(pgHost)=="undefined"?(location.hostname=="localhost"?"":"http://printgreen.xywidgets.com/"):pgHost;
var pgShowBtn = typeof(pgShowBtn) == "undefined" ? true : pgShowBtn;
var pgWidth = typeof(pgWidth) == "undefined" ? 400 : pgWidth;
var pgHeight = typeof(pgHeight) == "undefined" ? 300 : pgHeight;
var pgBorderWidth = typeof(pgBorderWidth) == "undefined" ? 0 : pgBorderWidth;
var pgWidgetType = typeof(pgWidgetType) == "undefined" ? "printGreen" : pgWidgetType;
var pgWebsiteId = typeof(pgWebsiteId) == "undefined" ? -1 : pgWebsiteId;
var pgRefId = typeof(pgRefId) == "undefined" ? 0 : pgRefId;
var pgColor = typeof(pgColor) == "undefined" ? "#047300" : pgColor;
var pgDeltaY = typeof(pgDeltaY) == "undefined" ? 0 : pgDeltaY;
var pgDefer = typeof(pgDefer) == "undefined" ? 0 : pgDefer;
var pgWidgetParams = typeof(pgWidgetParams) == "undefined" ? "" : pgWidgetParams;

function pgCloseWindowLabel() { return pgWidgetType.toLowerCase() == "il_printgreen" ? "סגור חלון" : "Close Window"; }
function pgCloseWindowLabelWidth() { return pgWidgetType.toLowerCase() == "il_printgreen" ? 50 : 80; }
function pgGetColor() { if (pgWebsiteId.toString() == "269016") return "#909090"; if (pgWebsiteId.toString() == "8784164") return "#ffffff"; return pgColor; }
function pgGetDeltaY() { if (pgWebsiteId.toString() == "847662") return 90; return pgDeltaY; }

function enablePrintGreen()
{
  if (window.ifrPrintGreen) closePrintGreen();
  var ifrPrintGreen = document.createElement("iframe");
  ifrPrintGreen.width = pgWidth;
  ifrPrintGreen.height = pgHeight;
  ifrPrintGreen.scrolling = "no";
  ifrPrintGreen.frameBorder = 0;
  ifrPrintGreen.style.zIndex = 1000000;
  ifrPrintGreen.style.position = "absolute";
  if (navigator.browserLanguage == "he") ifrPrintGreen.style.right = "482px";
  else ifrPrintGreen.style.left = "482px";
  ifrPrintGreen.style.top = (12+pgGetDeltaY()+document.documentElement.scrollTop+document.body.scrollTop)+"px";
  if (document.all) ifrPrintGreen.allowTransparency = true;
  document.body.appendChild(ifrPrintGreen);
  var d = ifrPrintGreen.contentWindow.document;
  d.open();
  d.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"+
  "<html>"+
  "<style type='text/css'>"+
  "html, body {margin:0px; padding:0px; height: 100%; overflow: auto; font-family:Arial;}</style>"+
  "<body onload='parent.ifrPrintGreenLoaded=1;' style='border:solid "+pgBorderWidth+"px "+pgGetColor()+"; text-align: center; background-color:transparent;'>"+
  "<iframe src='"+pgHost+"LaunchWidget.aspx?css=body&r="+pgRefId+"&wb="+pgWebsiteId+"&webid="+pgWebsiteId+"&wt="+pgWidgetType+"&wps="+escape(pgWidgetParams)+"&url="+escape(location.href)+"' "+
  "scrolling='no' frameborder='0' width='100%' height='100%' "+(document.all?"allowtransparency='true'":"")+"></iframe>"+
  "<a href='javascript:' onclick='parent.closePrintGreen(); return false;' style='position:absolute; top:5px; left:"+(pgWidth-pgCloseWindowLabelWidth())+"px; color:"+pgGetColor()+"; font-size:10px;'>"+pgCloseWindowLabel()+"</a>"+
  "</body></html>");
	
	d.close();
  window.ifrPrintGreen = ifrPrintGreen;
}

function closePrintGreen()
{
  if (window.ifrPrintGreen)
  {
    document.body.removeChild(window.ifrPrintGreen);
    window.ifrPrintGreen = null;
  }
}

function pgActivateWidget()
{
  if (document.all) document.body.onbeforeprint = enablePrintGreen;  
}

function pgViewStatsSrc()
{
  return pgHost+"viewstats.aspx?wt="+pgWidgetType+"&webid="+pgWebsiteId+"&url="+encodeURIComponent(document.location.href);
}

function pgButtonImageHtml()
{
  return "<img src='"+pgHost+"images/printgreen/PrintGreenButton2.png' style='border:0px;' />";
}

if (document.all) 
{  
  pgActivateWidget();
  if (pgShowBtn) 
  {
    if (pgDefer)
    {
      var es = document.getElementById("pgEmbedScript");
      if (es && es.parentNode)
      {
        var btn = document.createElement("a");
        es.parentNode.appendChild(btn);
        btn.href = pgHost;
        btn.innerHTML = pgButtonImageHtml();
      }
    }
    else
    {
      document.write("<a href='"+pgHost+"'>"+pgButtonImageHtml()+"</a>");
    }
  }
  if (pgDefer)
  {
    if (document && document.body)
    {
      var vs = document.createElement("script");
      vs.type = "text/javascript";
      vs.src = pgViewStatsSrc();
      document.body.appendChild(vs);
    }
  }
  else
  {
    document.write("<script type='text/javascript' src='"+pgViewStatsSrc()+"'></script>");
  }
}
