
var popup = function()
{
  if(!document.createTextNode || !document.getElementsByTagName){ return; }

  var a = document.getElementsByTagName("a");
  var area = document.getElementsByTagName("area");

  var links = new Array();
  for(var i = 0; i<a.length; i++){ links.push(a[i]); }
  for(var i = 0; i<area.length; i++){ links.push(area[i]); }

  for(var i=0; i<links.length; i++)
  {
    if(links[i].className.match('popup'))
    {
      links[i].onclick = function()
      {
        var url = this.href;

        p = new Array();
        p["_size"]        = "0";
        p["_name"]        = "newwindow";
        p["_width"]       = "460";
        p["_height"]      = "500";
        p["_left"]        = "150";
        p["_top"]         = "100";
        p["_menubar"]     = "no";
        p["_resizable"]   = "yes";
        p["_scrollbars"]  = "no";
        p["_status"]      = "no";
        p["_toolbar"]     = "no";
		p["_location"]    = "no";

        var pString = this.className.replace(/.*\bpopup\?([\S]*)\b.*/, "$1");

        var pTokens = pString.split("$");
        for (var i = 0; i < pTokens.length; i++)
        {
          var pName = pTokens[i].replace(/(.*):.*/, "$1");
          var pValue = pTokens[i].replace(/.*:(.*)/, "$1");
          p[pName] = pValue;
        }
        if(parseInt(p["_size"]) > 0)
        {
          if (window.innerWidth && typeof(window.innerWidth) == 'number')
          {
            w = window.innerWidth;
            h = window.innerHeight;
          }
          else if (document.documentElement && (document.documentElement.clientWidth != 0 && document.documentElement.clientHeight != 0))
          {
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
          }
          else if (document.body.clientHeight && document.body.clientWidth)
          {
            w = document.body.clientWidth;
            h = document.body.clientHeight;
          }
          else
          {
            w = 800;
            h = 600;
          }
          p["_height"]      =  h * p["_size"] / 100;
          p["_width"]       =  w * p["_size"] / 100;
          p["_menubar"]     = "yes";
          p["_resizable"]   = "yes";
          p["_scrollbars"]  = "yes";
          p["_status"]      = "yes";
          p["_toolbar"]     = "yes";
		  p["_location"]     = "yes";
        }

        if(window.open)
        {
          var attString  = 'width='+p["_width"];

              attString += ', height='+p["_height"];
              attString += ', left='+p["_left"];
              attString += ', top='+p["_top"];
              attString += ', menubar='+p["_menubar"];
              attString += ', resizable='+p["_resizable"];
              attString += ', scrollbars='+p["_scrollbars"];
              attString += ', status='+p["_status"];
              attString += ', toolbar='+p["_toolbar"];
			  attString += ', location='+p["_location"];

          var newWin = window.open(url, p["_name"], attString);
          newWin.focus();
          return false;
        }
        else
        {
          this.target = "_blank";
        }
      }
    }
  }
}
window.onload = popup;
