
var months = {};
months[0]="January";
months[1]="February";  
months[2]="March";  
months[3]="April"; 
months[4]="May";  
months[5]="June";  
months[6]="July";  
months[7]="August";
months[8]="September";  
months[9]="October";  
months[10]="November"; 
months[11]="December";

function checkFreshness(lotnumber) {
  if(!lotnumber || lotnumber.length < 4)  return 'Oops, that is not a valid lot number.';
 
  var day = lotnumber.substring(0,3);
  var year = lotnumber.substring(3,4);
  year = parseInt(year)+2000;

  if(day > 366) {
    return 'Sorry!  That is not a valid lot number.  Did you accidently use the barcode?';
  }
 
  
  var createDate = new Date();  
  createDate.setFullYear(year,0,day);
  var bestBefore = new Date();
  bestBefore.setFullYear(createDate.getFullYear(),createDate.getMonth()+18,createDate.getDate());
  var stringCreate = months[createDate.getMonth()]+" "+createDate.getDate()+", "+createDate.getFullYear();
  var stringBest = months[bestBefore.getMonth()]+" "+bestBefore.getDate()+", "+bestBefore.getFullYear();
  
  return "Your product was created on "+stringCreate+" and is approximately best before "+stringBest+"*";
  
}

function loadPopup(popup,vars) {
  var url = 'index.php?popup='+popup;
  for(i in vars) {
    url = url+'&vars[]='+vars[i];
  }    
   popupwindow = window.open(url,'Popup',"location=0,status=1,scrollbars=1,  width=500,height=400");
   popupwindow.moveTo(0,0);
}