var debug = 0;
var optimizedImagePrefix = "http://Hitachi-ID.com/";
// var optimizedImagePrefix = "";
var winW=-1;
var winH=-1;
function PadDigits( n, totalDigits )
  {
  n = n.toString();
  var pd = '';
  if( totalDigits > n.length )
    {
    for( var i=0; i < (totalDigits-n.length); i++)
      {
      pd += '0';
      }
    }
  return pd + n.toString();
  }
function MyNow()
  {
  var d = new Date();
  var s =
    PadDigits(d.getFullYear(),4) + "-"
    + PadDigits(d.getMonth(),2) + "-"
    + PadDigits(d.getDay(),2) + " "
    + PadDigits(d.getHours(),2) + ":"
    + PadDigits(d.getMinutes(),2) + ":"
    + PadDigits(d.getSeconds(),2);
  return s;
  }
function MyLogWindow( message )
  {
  if ( ! MyLogWindow.window_
       || MyLogWindow.window_.closed )
    {
    var win = window.open( "", null, "width=400,height=200," +
                           "scrollbars=yes,resizable=yes,status=no," +
                           "location=no,menubar=no,toolbar=no" );
    if( ! win )
      {
      return;
      }
    var doc = win.document;
    doc.write( "<html><head><title>Debug MyLogWindow</title></head>" +
               "<body></body></html>" );
    doc.close();
    MyLogWindow.window_ = win;
    }
  var MyLogWindowLine = MyLogWindow.window_.document.createElement("div");
  MyLogWindowLine.appendChild(
    MyLogWindow.window_.document.createTextNode(message) );
  MyLogWindow.window_.document.body.appendChild(MyLogWindowLine);
  }
function IsIE()
  {
  var browserId = navigator.appName;
  var browserVer = navigator.appVersion;
  if( browserId
      && browserId.indexOf("Microsoft") != -1
      && browserVer
      && ( parseInt( browserVer ) >= 4 ) )
    {
    return 1;
    }
  return 0;
  }
function IsMozilla()
  {
  var browserId = navigator.appName;
  var browserVer = navigator.appVersion;
  if( browserId
      && browserId.indexOf("Netscape") != -1
      && browserVer
      && ( parseInt( browserVer ) >= 5 ) )
    {
    return 1;
    }
  return 0;
  }
function MyLog( text )
  {
  if( debug )
    {
    if( IsIE() )
      {
      MyLogWindow( MyNow() + ": " + text );
      }
    else
      {
      console.log( MyNow() + ": " + text );
      }
    }
  }
var qwin;
function openaskquestion()
  {
  document.getElementById("askaquestion").href = "";
  qwin = window.open( "http://Hitachi-ID.com/cgi-bin/askquestion.cgi",
                      "_blank",
                      "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no,width=700, height=700"
                      );
  }
function OpenWindow(myURL)
  {
  // var dy = 25
  // var dx = 15
  var dy = 0
  var dx = 0
  var myWidth=1024
  var myHeight=768
  var scrx=myWidth
  var scry=myHeight
  if( window.screen )
    {
    myWidth = window.screen.availWidth;
    scrx = myWidth
    myHeight = window.screen.availHeight;
    scry = myHeight
    }
  if( myWidth<800 ) { myWidth = 800 }
  if( myWidth>1280 ) { myWidth = 1280 }
  if( myHeight<600 ) { myHeight = 600 }
  if( myHeight>768 ) { myHeight = 768 }
  myWidth -= dx
  myHeight -= dy
  return window.open( myURL, "",
                      "screenY="+(scry-myHeight)/2+",screenX="+(scrx-myWidth)/2+","+
                      "top="+(scry-myHeight)/2+",left="+(scrx-myWidth)/2+","+
                      "width="+myWidth
                      +",height="+myHeight
                      +",menubar=no,navbar=no,scrollbars,resizable=yes" )
  }
function OpenWindowXY(myURL,myWidth,myHeight)
  {
  var left = 0
  var top = 0
  var scrx=1024
  var scry=768
  if( window.screen )
    {
    left = (window.screen.availWidth - myWidth)/2;
    top = (window.screen.availHeight - myHeight)/2;
    }
  // MyLog("w="+myWidth+", h="+myHeight+", t="+top+", l="+left );
  var args = "screenY="+top+",screenX="+left+","+
             "top="+top+",left="+left
             +",width="+myWidth
             +",height="+myHeight
             +",menubar=no,navbar=no,scrollbars,resizable=yes";
  // alert("args="+args);
  return window.open( myURL, "", args );
  }
function PrinterFriendly()
  {
  var w = 0;
  var h = 0;
  var id;
  var t;
  id = document.getElementById("content");
  if( ! id )
    {
    id = document.getElementById("content-ja");
    }
  if( ! id )
    {
    alert("Printing not available on this page.");
    return;
    }
  var content = id.innerHTML;
  if( ! content )
    {
    alert("Printing not available on this page (2).");
    return;
    }
  t = document.getElementById("pageTitle");
  if( window && window.outerWidth )
    {
    w = window.outerWidth;
    }
  else
    {
    w = 1000;
    }
  if( window && window.outerHeight )
    {
    h = window.outerHeight;
    }
  else
    {
    h = 700;
    }
  var newW = OpenWindowXY("about:blank",w,h);
  newW.document.open("text/html", "replace");
  newW.document.write( "<html>" );
  newW.document.write( "<head>" );
  newW.document.write( "  <link href=\"/scripts/main.css\" rel=\"stylesheet\" media=\"all\" type=\"text/css\" />");
  newW.document.write( "  <!--[if lte IE 7]>");
  newW.document.write( "    <script type=\"text/javascript\" src=\"/scripts/pngfix.js\"></script>");
  newW.document.write( "    <link rel=\"stylesheet\" type=\"text/css\" href=\"/scripts/ie7.css\" media=\"all\" />");
  newW.document.write( "  <![endif]-->");
  newW.document.write( "<!--[if lte IE 6]>");
  newW.document.write( "  <link rel=\"stylesheet\" type=\"text/css\" href=\"/scripts/ie6.css\" media=\"all\" />");
  newW.document.write( "<![endif]-->");
  if( t )
    {
    newW.document.write( "<title>" + t.innerHTML + "</title>" );
    }
  newW.document.write( "</head>" );
  newW.document.write( "<body><table cellpadding=10 cellspacing=0 margin=0 class='printpage'><tr><td>" );
  if( t )
    {
    newW.document.write( "<h1 class='printH1'>" + t.innerHTML + "</h1><p>" );
    }
  newW.document.write( content );
  newW.document.write( "</td></tr><tr><td>" );
  newW.document.write( "<img src='/pics/mtech-logos/hids.png' alt='Hitachi ID Systems' />" );
  newW.document.write( "<br /><span id='smalltext'>" );
  newW.document.write( "500, 1401 - 1 Street SE, Calgary AB Canada T2G 2J3" );
  newW.document.write( "&nbsp;&nbsp;Tel: 1.403.233.0740 " );
  newW.document.write( "&nbsp;&nbsp;Fax: 1.403.233.0735 " );
  newW.document.write( "&nbsp;&nbsp;E-Mail: sales@Hitachi-ID.com" );
  newW.document.write( "</span>" );
  newW.document.write( "<div id='footer'>" );
  newW.document.write( "<a href='http://Hitachi-ID.com'>Hitachi-ID.com</a>" );
  newW.document.write( "</div>" );
  newW.document.write( "</td></tr></table></body>" );
  newW.document.write( "</html>" );
  newW.document.close();
  newW.print();
  $(newW.document.getElementById('ja-pdf')).setStyles({
  display: 'inline'
  });
  var h1 = newW.document.getElementsByTagName('h1')[0];
  $(h1).setStyles({
  display: 'none'
  });
  }
/***************************************************************************
 CODE TO HANDLE POPUP SCREEN SHOTS:
***************************************************************************/
var BORDER = 40;
var SCREEN_FRACTION = 0.9;
var IMGLOAD_TIME = 100; // ms
var img;
var imgHandle;
var url;
function PopupImageCallback()
  {
  if( imgHandle )
    {
    clearTimeout( imgHandle );
    imgHandle = "";
    }
  if( img.complete )
    {
    DisplayImage( url );
    }
  else
    {
    imgHandle = window.setTimeout( "PopupImageCallback()", IMGLOAD_TIME );
    }
  }
function DisplayImage()
  {
  var h, w;
  var maxh, maxw;
  h = img.height + BORDER;
  w = img.width + BORDER;
  // alert("Image load complete: "+w+"x"+h);
  if( window.screen )
    {
    maxw = window.screen.availWidth;
    maxh = window.screen.availHeight;
    }
  else
    {
    maxw = 1024;
    maxh = 768;
    }
  if( h > SCREEN_FRACTION * maxh )
    {
    h = SCREEN_FRACTION * maxh;
    }
  if( w > SCREEN_FRACTION * maxw )
    {
    w = SCREEN_FRACTION * maxw;
    }
  window.open( url,
               '_screenshot',
               'dependent=1, '
               + 'resizable=yes, scrollbars=yes, toolbar=no, statusbar=no, '
               + 'location=no, directories=no, status=no, menubar=no, '
               + 'copyhistory=no, '
               + 'width=' + w + "px, "
               + 'height=' + h + "px"
               );
  }
function PopupImageWindow( urlArg )
  {
  url = urlArg;
  img = new Image();
  img.src = url;
  PopupImageCallback();
  }
function JumpToURL( form )
  {
  var idx;
  var item;
  var val;
  if( form
      && form.selectWhitePaper
      && location
      && location.href )
    {
    idx = form.selectWhitePaper.selectedIndex;
    if( ! idx )
      {
      idx = 0;
      }
    item = form.selectWhitePaper.options[ idx ];
    if( item )
      {
      val = item.value;
      }
    else
      {
            }
    if( val )
      {
            location.href = val;
      }
    else
      {
            }
    }
  }
function LoadCSSorJS( filename, type )
  {
  if( type=="js" )
    {
    var newObj=document.createElement( 'script' );
    newObj.setAttribute( "type","text/javascript" );
    newObj.setAttribute( "src", filename );
    }
  else if( type=="css")
    {
    var newObj=document.createElement( "link" );
    newObj.setAttribute( "rel", "stylesheet" );
    newObj.setAttribute( "type", "text/css" );
    newObj.setAttribute( "href", filename );
    }
  if( typeof newObj != "undefined" )
    {
    document.getElementsByTagName( "head")[0].appendChild(newObj);
    }
  }

