// Version : 2.00 - XMLHttp request source code for IE 5+ and Mozilla based browsers (Foxfire, Netscape 6+)
// ERROR CHECK PATRONS BARCODE. ||||||||||
function errorCheck_Barcode()
{ 
// document.write(enter_barcode.getElementsByTagName("input")[0].value); return;
 window.status="";
 var sItem_Flag;
 var sPatronBarcode;
 var libraryNum=["0660", "0661", "0662", "0663", "20660", "20661", "20662", "20663"];
 var i;
 sPatronBarcode=enter_barcode.getElementsByTagName("input")[0].value;
 if(sPatronBarcode=="" || sPatronBarcode.length < 1){return;}
 var barcode=-1;
 for(i=0; i<8; i++)
 {
  if(sPatronBarcode.indexOf(libraryNum[i])==0 || sPatronBarcode.indexOf(libraryNum[i])==2){barcode=1; break;}
 }
 if(barcode==1 && (sPatronBarcode.length==12 || sPatronBarcode.length==14))
 {get_PatronRecord(sPatronBarcode)}
 else
 {sItem_Flag="1"; patron_Notice(sItem_Flag)}
}

// GET PATRON RECORD .||||||||||
var ohttpReq;
function get_PatronRecord(sPatronBarcode)
{
 var sItem_Flag="0";
 var iIndexInto;
 var sReturnedData;

 // Code for Mozilla, etc.
 if(window.XMLHttpRequest)
 {
  ohttpReq=new XMLHttpRequest();
  ohttpReq.open("GET", "authenticate_children.asp?patron_barcode="+sPatronBarcode, false);
  ohttpReq.send(null);
 }
 // Code for IE.
 else if(window.ActiveXObject)
 {
  ohttpReq=new ActiveXObject("Microsoft.XMLHTTP");
  if(ohttpReq)
  {
   ohttpReq.Open("GET", "authenticate_children.asp?patron_barcode="+sPatronBarcode, false);
   ohttpReq.send();
  }
 }
 sReturnedData=ohttpReq.responseText;
// document.write(sReturnedData); return;
 sItem_Flag=sReturnedData.substr(iIndexInto + 8, 1);
 patron_Notice(sReturnedData)
}

// KEY PRESS. ||||||||||
function keyPress(e)
{
 var key=window.event ? e.keyCode : e.which;
 if(key==13){errorCheck_Barcode()}
 return;
}

var iTumbleBookMenu_Flag=0;
// SHOW BARCODE INPUT BOX. ||||||||||
function showBarcodeInputBox()
{
var BarcodeInputBox="<table class='menuBorder_2' cellspacing='0' cellpadding='0' border='0'><tr><td>"+
"<table class='menuBorder_1' cellspacing='0' cellpadding='0' border='0'><tr><td>"+
"<table class='menuBorder_0' cellspacing='0' cellpadding='0' border='0'><tr><td>"+
"<table width='225 height='50' cellspacing='0' cellpadding='0' border='0'>"+
"<tr><td class='headerBarcodeBox' height='12' colspan='3' onclick='hideBarcodeInputBox()'>&nbsp;Enter your Smithtown Library barcode :<\/td><\/tr>"+
"<tr><td height='4' colspan='3'><\/td><\/tr>"+
"<tr><td align='center' colspan='3'><input class='inputboxstyle' type='text' name='input_barcode' size='16' maxlength='14'><\/td><\/tr>"+
"<tr><td height='4' colspan='3'><\/td><\/tr>"+
"<tr><td width='64' height='16'><\/td><td width='96' class='submitBarcode_off' onmouseover=this.className='submitBarcode_on' onmouseout=this.className='submitBarcode_off'  onclick='errorCheck_Barcode()'><\/td><td width='65' height='16'><\/td><\/tr>"+
"<tr><td height='3' colspan='3'><\/td><\/tr>"+
"<\/table>"+
"<\/td><\/tr><\/table>"+
"<\/td><\/tr><\/table>"+
"<\/td><\/tr><\/table>";
 
 document.getElementById("enter_barcode").innerHTML=BarcodeInputBox;
 document.getElementById("enter_barcode").style.left=157;
 document.getElementById("enter_barcode").style.top=-1335; //-1193
 document.getElementById("enter_barcode").style.visibility="visible";
 iTumbleBookMenu_Flag=1;
 enter_barcode.getElementsByTagName("input")[0].focus();
}

// HIDE BARCODE INPUT BOX. ||||||||||
function hideBarcodeInputBox()
{document.getElementById("enter_barcode").style.visibility="hidden"; iTumbleBookMenu_Flag=0;}

// PATRON NOTIFICATION. ||||||||||
function patron_Notice(sItem_Flag)
{
 var sNotice;
 switch(sItem_Flag)
 {
  case "0":
   window.location="http://www.tumblebooks.com/library/auto_login.asp?U=SMTH&P=books";
   return; break;
  case "1":sNotice="The patron library barcode you have entered is invalid for the Smithtown Library.&nbsp; Please re-enter your barcode.";
   break;
//  case "2":sNotice="Please call the Circulation Department of your local branch.&nbsp; There appears to be a problem with your library card.";
//   break;
  case "3":sNotice="The patron library barcode you have entered could not be found.&nbsp; Please re-enter your barcode.";
   break;
 }

 NoticeBox="<table class='menuBorder_2' border='0' cellspacing='0' cellpadding='0'><tr><td>"+
 "<table class='menuBorder_1' border='0' cellspacing='0' cellpadding='0'><tr><td>"+
 "<table class='menuBorder_0' border='0' cellspacing='0' cellpadding='0'><tr><td>"+
 "<table class='menuBG' width='350' border='0' cellspacing='0' cellpadding='0'>"+
 "<tr><td height='8' align='left' colspan='4'><\/td><\/tr>"+
 "<tr><td width='10'><\/td><td width='340' align='left' colspan='2'><font class='infoBoxText'>&nbsp;&nbsp;&nbsp;&nbsp;"+sNotice+"<\/font><\/td><td width='10'><\/td><\/tr>"+
 "<tr><td width='10' height='2'><\/td><td width='340' colspan='2' bgcolor='#D7E1EE'></td><td><\/td><\/tr>"+
 "<tr><td width='10'><\/td><td width='340' align=right colspan='2'><img src='Images/button_window_close_small.gif' border='0' onClick=hideNoticeBox();>&nbsp;&nbsp;&nbsp;&nbsp;<\/td><td width='10'><\/td><\/tr>"+
 "<tr><td height='4' align=left colspan='4'><\/td><\/tr>"+
 "<\/table>"+
 "<\/td><\/tr><\/table>"+
 "<\/td><\/tr><\/table>"+
 "<\/td><\/tr><\/table>";
     
 document.getElementById("PatronNotice").innerHTML="<form name='inputbarcode'>"+NoticeBox+"<\/form>";            
 document.getElementById("PatronNotice").style.left=(available_width=document.body.clientWidth-350)/2
 document.getElementById("PatronNotice").style.top=265; 
 document.getElementById("PatronNotice").style.visibility="visible";   
 setTime_0=setTimeout("hideNoticeBox()", 7000)
}

// HIDE PATRON NOTIFICATION. ||||||||||
function hideNoticeBox()
{
 document.getElementById("PatronNotice").style.visibility="hidden";
 enter_barcode.getElementsByTagName("input")[0].value="";
 enter_barcode.getElementsByTagName("input")[0].focus();
}