//Functions in this script module
//function newWin(sPage, xsize, ysize, sb)
//function newDocWin(sPage, xsize, ysize)
//function NLWin(sPage, xsize, ysize)
//function showrecipe(type)
//function shownl()
//function showtool()
//function showdoc() 
//function nextmeeting() 
//function monday (y, m, d) 
//function nexthumpday() 
//function countdown( date_in, event_name ) 
//function gostyle() 

function newWin(sPage, xsize, ysize, sb)
{
  var left = (screen.width-xsize)/2;
  var docWindow;
  var docFeatures;

  if (sb=="") { sb="no"; }
  if (ysize > (screen.height-60)) {
    ysize=screen.height-60;
    sb="yes";
  }
  if (xsize > (screen.width-60)) {
    xsize=screen.width-60;
    sb="yes";
  }
  if (ysize==0) {
    ysize=640;
  }
  if (xsize==0) {
    xsize=640;
  }

//  if (sb=="yes") {
//    xsize = xsize + 30;
//  }

//  xsize=screen.width-20;
//  ysize=screen.height-100;
//  left=10;

  docFeatures="menubar=no, ScrollBars=" + sb + ", Width=" + xsize + ", Height=" + ysize + ", Top=5, Left=" + left;
  docWindow = window.open(sPage, "", docFeatures);
}


function newDocWin(sPage, xsize, ysize)
{
  var docWindow;
  var docFeatures;


  if (xsize==0) { xsize=screen.width-10; }
  if (ysize==0) { ysize=screen.height-100; }

  docFeatures="menubar=no, ScrollBars=yes, Width=" + xsize + ", Height=" + ysize + ", Top=0, Left=0";
  docWindow = window.open(sPage, "", docFeatures);
}


function NLWin(sPage, xsize, ysize)
{
  var docWindow;
  var docFeatures;

  if (confirm ("click OK to view in PDF format, or Cancel to view in Text format") == false) {
     sPage = left(sPage,len(sPage)-4) + ".txt";
  }

  if (xsize==0) { xsize=screen.width-10; }
  if (ysize==0) { ysize=screen.height-100; }

  docFeatures="menubar=no, ScrollBars=yes, Width=" + xsize + ", Height=" + ysize + ", Top=0, Left=0";
  docWindow = window.open(sPage, "", docFeatures);
}



function showrecipe(type) {
 var src;
 var str;
 var el;

  if (type=="ex") {
    if (ex.value == '') {
      alert ('select a recipe');
    }
    else {
      src = "recipes/" + ex.value;
    }
  }
  if (type=="ag") {
    if (ag.value == '') {
      alert ('select a recipe');
    }
    else {
      src = "recipes/" + ag.value;
    }
  }
  var ht=screen.height-350;

  str="<IFRAME style='border-width:3px; height:" + ht + "px; width:100%;' SCROLLING=YES SRC='" + src + "'></IFRAME>"
  el = document.getElementById('recipe');
  el.innerHTML = str;
}

function shownl() {
  var str;
  var el;
  var src= "news/" + news.value;
  var ht=screen.height-100;

  str="<IFRAME style='border-width:3px; height:" + ht + "px; width:97%;' SCROLLING=YES SRC='" + src + "'></IFRAME>"

  el = document.getElementById('nl');
  el.innerHTML = str;
}

function showtool() {
  var str;
  var el;
  var src= "tools/" + tools.value;
  var ht=screen.height-250;

  str="<IFRAME style='border-width:3px; height:" + ht + "px; width:97%;' SCROLLING=YES SRC='" + src + "'></IFRAME>"

  el = document.getElementById('tool');
  el.innerHTML = str;
}


function showdoc() {
  var str;
  var el;
  var src=docs.value;
  var ht=screen.height-250;
  

  if (docs.value=='HBD') { 
    src='http://hbd.org/hbd/CurrentHBD.html';
  }
  else if (docs.value=='HBDF') {
    src='http://hbd.org/forums';
  }
  else if (docs.value=='NBF') {
    src='http://forum.northernbrewer.com'
  }
  else {
    src = 'docs/' + docs.value
  }

  str="<IFRAME style='border-width:3px; height:" + ht + "px; width:97%;' SCROLLING=YES SRC='" + src + "'></IFRAME>"

  el = document.getElementById('doc');
  el.innerHTML = str;
}



function countdown( date_in, event_name ) {
  var now = new Date();
  var dt = new Date(date_in);
  var sec = (dt - now) / 1000;
  var min = sec / 60;
  var hrs = min / 60;
  var days = Math.floor(hrs / 24);

  hrs = Math.floor(hrs - (days * 24));
  min = Math.floor(min - (days * 24 * 60) - (hrs * 60));
  sec = Math.floor(sec - (days * 24 * 60 * 60) - (hrs * 60 * 60) - (min* 60));

  if (now > dt) {
    el = document.getElementById ("message");
    el.style.display="none";
  } else {
  document.write (days + " days until " + event_name + "!");
  }
}

function gostyle() {
   if (styles.value == '') {
     alert ('select a Style');
   }
   else {
    window.location=styles.value;
   }
}

function gohop1() {
  if (hop1.value == '') {
    alert ('select a Hop variety');
  }
  else {
   window.location=hop1.value;
  }
}
function gohop2() {
  if (hop2.value == '') {
    alert ('select a Hop variety');
  }
  else {
   window.location=hop2.value;
  }
}

function BTWin(sURL){
  var sPage;
  var sOptions='" menubar=no status=yes, scrollbars=yes, width=800,height=' + (screen.height-150) + ', left=10, top=10"';

  if (sURL=="issue2.2/oneil.html") {
    sPage = "http://brewingtechniques.com/library/backissues/issue2.2/o'neil.html"
  }
  else {
    if (sURL.substring(0,1) == "/") {
      sPage = 'http://brewingtechniques.com' + sURL;
    }
    else {
      sPage = 'http://brewingtechniques.com/library/backissues/' + sURL;
    }
  }
  window.open(sPage,"",sOptions);
}

