/****************************************************************************
file: init.js
developer: Bob Lewis
date: 29May06
description: contains init functions for site for:
             Restoration Review (Leroy Garrett);
             pages are loaded into the includeone span in the 'article.htm' 
             page by way of a call to the clientSideInclude function found 
             in utils.js;
             this function uses the window.XMLHttpRequest to retrieve the 
             page and display it inside an element in the article.htm file;
             
             Following notes from notes.txt in Restoration Review folder
             When an article is accessed from a volume index, the page is loaded 
               into the article.htm file using a call to clientSideInclude;
             When an index is accessed from the number drop-down menu, it is 
               loaded into the display_index.htm file using a call to clientSideInclude;
             When an article or index is access directly, using the absolute url, 
               the file itself will call the init() function of the print.js script 
               and will display the file in the appropriate file using a call to 
               clientSideInclude;
             When an intro file is called (from the intros folder) directly, using 
               the absolute url, the volume is detected from the file name and used 
               to load the appropriate index file (using a call to clientSideInclude) 
               and display the intro file in a pop-up window--the way intro files are 
               always displayed;
             
update: 29May06: this function can call either display_page.php or 
                 display_page.htm the only difference is that the 
                 php file will read the query_string whereas the html 
                 file will parse  window.location.href for the query 
                 string;
                 If php, the following modifications need to be 
                 made to the display.php file:
                 1. the following line must be commented out of the 
                    init() function:
                    clientSideInclude('includeone', include_page);
                 2. the following line must be commented out in the 
                    body of the file:
                    <span id="includeone"></span>
                 3. the follwing line must be inserted in place of the 
                    previous line:
                    <? readfile($include_file);?>
                 4. the following lines must be inserted at the top of 
                    the PHP file:
                    <?php
                    $include_file = $_SERVER['QUERY_STRING'];
                    ?>
                 Since both approaches will currently work on the 
                 Godaddy.com Unix server, I am using the html approach, 
                 since the site is currently on a Windows server; 
                 if I move it to the Unix server, the site will continue 
                 to work, but could be adapted to php in the above manner;
                 (see 03Jul06 update below);
update: 30May06: continued development
        01May06: continued development
        01Jun06: continued development
        02Jun06: continued development 
                 (Frank and Margaret Mitchell's 67th anniversary [1939]
                 (today we sold Mother's house at 555 Clairidge Drive,
                 (Boiling Springs, SC 29316);
        07Jun06: added format_reading_pane() function to reduce margins of
                 article;
        15Jun06: modified format_reading_pane() function to include the 
                 position of the page header;
        03Jul06: site has been transferred to a Unix server leased from godaddy.com;
                 the domain is an alias of gratidao.net
        26Apr07: completed last of several updates involving the addition of a 'Comments'
                 button to menu03, along with several related functions which have been added
                 to the bottom of the function list;
functions:       index_init()
                 display_article_init()
                 print_page()
                 display_intro(page)
                 display_index_init()
                 build_select_menu()
                 set_cursor(obj)
                 authors_init()
                 series_init()
                 set_page_style()
                 set_menu(menu)
                 go_here(where)
                 format_buttons()
                 load_menu()
                 get_number_index()
                 get_article()
                 get_year(year)
                 get_month(num)
                 format_reading_pane()
                 goto_comments()
				 check_for_comments
				 comment_alert
				 goto_comments
				 notify_parent_onclose
****************************************************************************/
//alert("init.js");

var testing = 0; //1;// 0;
var current_volume;
var current_number;
var current_year;
var direction = 1;
var rMargin;
var serverloc;
var close_flag;
var myWindow; //handle for pop-up window

if(location.href.indexOf("localhost") > -1)
  {
    serverloc = "local";
  }
else
  {
    serverloc = "remote";
  }

var menu01 = "";
menu01 += "<html><head>";
menu01 += "</head><body>";
menu01 += "<p align='center' style='font-weight:bold;color:white'>RESTORATION<br>REVIEW</p>";
menu01 += "<p align='center'><input type='button' value='Home' onclick='go_here(1)'></p>";
menu01 += "<p align='center'><input type='button' value='Author Index' onclick='go_here(4)'></p>";
//menu01 += "<p align='center'><input type='button' value='Series Index' onclick='go_here(5)'></p>";
menu01 += "<p align='center'><input type='button' value='Search Articles' onclick='go_here(7)'></p>";
menu01 += "<p>&nbsp;</p>"
menu01 += "<p align='center'><input type='button' value='Garrett: Works' onclick='go_here(6)'></p>";
menu01 += "</body></html>";

var menu02 = "";
menu02 += "<html><head>";
menu02 += "</head><body>";
menu02 += "<p align='center' style='font-weight:bold;color:white'>RESTORATION<br>REVIEW</p>";
menu02 += "<p align='center'><input type='button' value='Home' onclick='go_here(1)'></p>";
menu02 += "<p align='center'><input type='button' value='Volume Index' onclick='go_here(2)'></p>";
//menu02 += "<p align='center'><input type='button' value='Number Index' onclick='go_here(3)'></p>";
    menu02 += "<p align='center'><input type='button' value='Author Index' onclick='go_here(4)'></p>";
    //menu02 += "<p align='center'><input type='button' value='Series Index' onclick='go_here(5)'></p>";
menu02 += "<p align='center'><input type='button' value='Search Articles' onclick='go_here(7)'></p>";
menu02 += "<p>&nbsp;</p><p align='center'><input type='button' value='Garrett: Works' onclick='go_here(6)'></p>";
menu02 += "</body></html>";

var menu03 = "";
//menu03 += "<html><head>";
//menu03 += "</head><body>";
if(testing == 1)
  {
    menu03 += "<p align='center' style='font-weight:bold;color:white'><span style='cursor:hand;' onclick='goto_comments()'>RESTORATION</span><br>REVIEW</p>";
  }
else
  {
    menu03 += "<p align='center' style='font-weight:bold;color:white'>RESTORATION<br>REVIEW</p>";
  }
menu03 += "<p align='center'><input type='button' value='Home' id='homeBtn' onclick='go_here(1)'></p>";
menu03 += "<p align='center'><input type='button' value='Volume Index' id='volIndexBtn' onclick='go_here(2)'></p>";
menu03 += "<p align='center'><input type='button' value='Number Index' id='numIndexBtn' onclick='get_number_index()'></p>";
    menu03 += "<p align='center'><input type='button' value='Author Index' onclick='go_here(4)'></p>";
    //menu03 += "<p align='center'><input type='button' value='Series Index' onclick='go_here(5)'></p>";
/*
menu03 += "<p align='center'><input type='button' value='Garrett: Works' onclick='go_here(6)'></p>";
//menu03 += "<p align='center' id='citation'><span></span>";
menu03 += "<p align='center'><input type='button' value='Text Width' onclick='format_reading_pane()'></p>";
menu03 += "<p align='center'><input type='button' value='Print Article' onclick='print_page()'></p>";
//menu03 += "</body></html>";
*/
//menu03 += "<p align='center' id='citation'><span></span>";
menu03 += "<p align='center'><input type='button' value='Text Width' onclick='format_reading_pane()'></p>";
menu03 += "<p align='center'><input type='button' value='Print Article' onclick='print_page()'></p>";

if(testing == 0)
  {
    menu03 += "<p align='center'><input type='button' id='commentsBtn' value='Comments' onclick='goto_comments()'> <span id='cCount' style='color:yellow'></span></p>";
  }

menu03 += "<p align='center'><input type='button' value='Search Articles' onclick='go_here(7)'></p>";
menu03 += "<p>&nbsp;</p>"
menu03 += "<p align='center'><input type='button' value='Garrett: Works' id='worksBtn' onclick='go_here(6)'></p>";

////////////
//inserted all of mmenu.js
var vmenu = "";
vmenu += "<select size='1' id='vmenu' onchange='load_menu()'>";
vmenu += "<option>Select Volume Number</option>";
vmenu += "<option value='01_"+get_year(1)+"'>Volume 01, "+get_year(1)+"</option>"; //1959
vmenu += "<option value='02_"+get_year(2)+"'>Volume 02, "+get_year(2)+"</option>";
vmenu += "<option value='03_"+get_year(3)+"'>Volume 03, "+get_year(3)+"</option>";
vmenu += "<option value='04_"+get_year(4)+"'>Volume 04, "+get_year(4)+"</option>";
vmenu += "<option value='05_"+get_year(5)+"'>Volume 05, "+get_year(5)+"</option>";
vmenu += "<option value='06_"+get_year(6)+"'>Volume 06, "+get_year(6)+"</option>";
vmenu += "<option value='07_"+get_year(7)+"'>Volume 07, "+get_year(7)+"</option>";
vmenu += "<option value='08_"+get_year(8)+"'>Volume 08, "+get_year(8)+"</option>";
vmenu += "<option value='09_"+get_year(9)+"'>Volume 09, "+get_year(9)+"</option>";
vmenu += "<option value='10_"+get_year(10)+"'>Volume 10, "+get_year(10)+"</option>";
vmenu += "<option value='11_"+get_year(11)+"'>Volume 11, "+get_year(11)+"</option>";
vmenu += "<option value='12_"+get_year(12)+"'>Volume 12, "+get_year(12)+"</option>";
vmenu += "<option value='13_"+get_year(13)+"'>Volume 13, "+get_year(13)+"</option>";
vmenu += "<option value='14_"+get_year(14)+"'>Volume 14, "+get_year(14)+"</option>";
vmenu += "<option value='15_"+get_year(15)+"'>Volume 15, "+get_year(15)+"</option>";
vmenu += "<option value='16_"+get_year(16)+"'>Volume 16, "+get_year(16)+"</option>";
vmenu += "<option value='17_"+get_year(17)+"'>Volume 17, "+get_year(17)+"</option>";
vmenu += "<option value='18_"+get_year(18)+"'>Volume 18, "+get_year(18)+"</option>";
vmenu += "<option value='19_"+get_year(19)+"'>Volume 19, "+get_year(19)+"</option>"; //1977
vmenu += "<option value='20_"+get_year(20)+"'>Volume 20, "+get_year(20)+"</option>";
vmenu += "<option value='21_"+get_year(21)+"'>Volume 21, "+get_year(21)+"</option>";
vmenu += "<option value='22_"+get_year(22)+"'>Volume 22, "+get_year(22)+"</option>";
vmenu += "<option value='23_"+get_year(23)+"'>Volume 23, "+get_year(23)+"</option>";
vmenu += "<option value='24_"+get_year(24)+"'>Volume 24, "+get_year(24)+"</option>";
vmenu += "<option value='25_"+get_year(25)+"'>Volume 25, "+get_year(25)+"</option>";
vmenu += "<option value='26_"+get_year(26)+"'>Volume 26, "+get_year(26)+"</option>";
vmenu += "<option value='27_"+get_year(27)+"'>Volume 27, "+get_year(27)+"</option>";
vmenu += "<option value='28_"+get_year(28)+"'>Volume 28, "+get_year(28)+"</option>";
vmenu += "<option value='29_"+get_year(29)+"'>Volume 29, "+get_year(29)+"</option>";
vmenu += "<option value='30_"+get_year(30)+"'>Volume 30, "+get_year(30)+"</option>";
vmenu += "<option value='31_"+get_year(31)+"'>Volume 31, "+get_year(31)+"</option>";
vmenu += "<option value='32_"+get_year(32)+"'>Volume 32, "+get_year(32)+"</option>";
vmenu += "<option value='33_"+get_year(33)+"'>Volume 33, "+get_year(33)+"</option>";
vmenu += "<option value='34_"+get_year(34)+"'>Volume 34, "+get_year(34)+"</option>"; //1992</option>";
vmenu += "</select>";

var imenu = "";
imenu += "<select size='11' id='imenu' onchange='get_number_index()'>";
imenu += "<option style='color:green'>Select Issue Number</option>";
imenu += "<option value='1'>Number 1</option>";
imenu += "<option value='2'>Number 2</option>";
imenu += "<option value='3'>Number 3</option>";
imenu += "<option value='4'>Number 4</option>";
imenu += "<option value='5'>Number 5</option>";
imenu += "<option value='6'>Number 6</option>";
imenu += "<option value='7'>Number 7</option>";
imenu += "<option value='8'>Number 8</option>";
imenu += "<option value='9'>Number 9</option>";
imenu += "<option value='10'>Number 10</option>";
imenu += "</select>";

var imenuB = ""; //for volumes 1 through 5
imenuB += "<select size='5' id='imenu' onchange='get_number_index()'>";
imenuB += "<option style='color:green'>Select Issue Number</option>";
imenuB += "<option value='1'>Number 1</option>";
imenuB += "<option value='2'>Number 2</option>";
imenuB += "<option value='3'>Number 3</option>";
imenuB += "<option value='4'>Number 4</option>";
imenuB += "</select>";


//////////FUNCTIONS////////////

function index_init()
{
  if(document.all.vol_num)
    {
      document.all.vol_num.style.display = "none";
    }
  set_page_style();
  set_menu(menu01);
  document.all.mmenu.innerHTML = vmenu;
  format_buttons(); //in menu01.js
  //script in the head portion of index.htm checks query_string;
  //if volume was passed to index.htm, then load volume menu
  if(pos >= 0)
    {
      load_menu();
    }
  //new 22Apr07
  //return the results to display_visitor_count();
  if(serverloc == "remote")
    {
      makeRequest(('http://www.leroygarrett.org/restorationreview/rr_visitor_counter.php'),9);
    }
}

function display_visitor_count(count)
{
  count = parseInt(count);
  document.all.visitor_count.innerText = count;
}

function display_article_init()
{
  set_page_style()
  set_menu(menu03)
  format_buttons();
  clientSideInclude('includeone', include_page);
  
  var current_month = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
 
  //use the top div tag to set margins
  var myDivs = document.getElementsByTagName("div");
  if(myDivs[0])
    {
      myDivs[0].style.position = "relative";
      myDivs[0].style.top = "20";
      myDivs[0].style.marginLeft = "20";
      myDivs[0].style.marginRight = "0";
    }
  
  //change the content of the header span (older pages may contain webbot include)
  if(document.all.header)
    {
      if(current_year == null)
        {
          current_year = get_year(current_volume);
        }
      document.all.header.innerHTML = "Volume "+current_volume+", Number "+current_number+", "+current_month[current_number]+" "+current_year;;
      var header = document.getElementById("header");
      headerWidth = header.offsetWidth;
      var cWide = document.documentElement.offsetWidth;
      document.all.header.style.position = "absolute";
      document.all.header.style.top = "0";
      document.all.header.style.left = eval(cWide - headerWidth) - 10;
      document.all.header.style.width = headerWidth;
      document.all.header.style.color = "#ACA4A4";
      document.all.header.style.fontSize = "10pt";
      //insert new span for RR title; left justify
      header.insertAdjacentHTML('beforeBegin', "<span id='logo'>Restoration Review</span>");
      var logo = document.getElementById("logo");
      logo.style.color = "#ACA4A4";
      logo.style.fontSize = "10pt";
      logo.style.position = "absolute";
      logo.style.top = "0";
      logo.style.left = document.body.style.marginLeft;
    }

  //remove the horizontal bar
  var myHrs = document.getElementsByTagName("hr");
  if(myHrs[0])
    {
      myHrs[0].style.display = "none";
    }

  if(serverloc == "remote")
    {
      check_for_comments(); //13Apr07
    }
}

function check_for_comments()
{
  var str = window.location.href
  pos = str.indexOf("?");
  articleID  = str.slice(pos+1);
  //return the results to comment_alert()
  makeRequest(('comments/get_list.php?'+articleID),1);
}

//receives input from list_Comments(http_request) in ajax.js
function comment_alert(input)
{
  total_comments = input.split("<tr").length-1;
  if(testing == 0)
  {

    if(total_comments > 1 || total_comments < 1)
      {
        document.all.commentsBtn.value = total_comments+" Comments";
        document.all.commentsBtn.style.color = "#008000";
      }        
    else
      {
        document.all.commentsBtn.value = total_comments+" Comment";
        document.all.commentsBtn.style.color = "#008000";
      }        
  }
}

function print_page()
{
  //<link rel=alternate media=print href="printversion.doc">
  var str01 = window.location.href
  var myWindow = window.open(include_page+"?"+str01);
}

function display_intro(page)
{
  var str01 = window.location.href
  var myWindow = window.open(page+"?"+str01);
}

function display_index_init()
{
  set_page_style()
  set_menu(menu02)
  format_buttons(); //in menu01.js
  //include_page value is set inside display_index.htm and article.htm
  //
  clientSideInclude('includeone', include_page); 

  //only works after new page has been loaded
  var myCells = document.getElementsByTagName("td");
  //myCells[4].innerHTML = "";

  //put all links into an array
  var myLinks = document.getElementsByTagName("a");
  
  //find the link for the image that has no outerText;
  //swap places in the array between this image link and the 
  //last image link--below the table (which has outerText);
  //build the drop-down menu (without taking the image link
  //into account); then move the image link back to its 
  //previous position on the page;
  for(i=0; i<myLinks.length; i++)
    {
      if(myLinks[i].outerText.length < 1)
        {
          var link1 = myLinks[i];          
//          var link2 = myLinks[i+1];
//          link1.swapNode(link2);
          build_select_menu();
 //         link2.swapNode(link1);
        }
    }

    //this function inside the display_index_init() function
	function build_select_menu()
	{
	//create select menu for links to articles
	var amenu = "";
	var menu_size;
	//menu_size = 9;
	//menu_size = myLinks.length - 1;
	if(myLinks.length > 9)
	  {
	    menu_size = myLinks.length - 1;
	  }
	else
	  {
	    menu_size = 9;
	  }
	//amenu += "<select size='11' id='amenu' style='color:black;font-face:arial;font-size:10pt' onchange='get_article()'>";
	amenu += "<select size='" + menu_size + "' id='amenu' style='color:black;font-face:arial;font-size:10pt' onchange='get_article()'>";

	//include all links but the last one--the image link
	for(i=0; i<myLinks.length-1; i++)
		{
		if(myLinks[i].outerText.length > 1)
			{
			if(i % 2 > 0)
				{
				  amenu += "<option value="+myLinks[i].href+" style='background-color:#EFF2F7'>• "+myLinks[i].outerText+"</option>"
				}
			else
				{
				  amenu += "<option value="+myLinks[i].href+">• "+myLinks[i].outerText+"</option>"
				}
			}
		}
	amenu += "</select>";
	myCells[4].innerHTML = amenu;
	myCells[4].style.backgroundColor = "#6B9CE7";
	myCells[5].style.backgroundColor = "white";
	myCells[5].style.backgroundColor = "#6B9CE7";
	}

    //change font color of 'CLICK TO ENLARGE' text
    document.all.click.style.color = "white";  

    if(current_year == null)
      {
        current_year = get_year(current_volume);
      }
	//get width of menu table
	var myTables = document.getElementsByTagName("table");
	menu_table_width = myTables[1].offsetWidth;

	//create new table for header info;
	var newTable = "";
	newTable += "<table style='font-weight:bold;border-collapse: collapse' height='30' width='"+menu_table_width+"'>";
	newTable += "  <tr>";
	newTable += "    <td width='33%' valign='top'>Volume "+current_volume+", No. "+current_number+"</td>";
	newTable += "    <td width='33%' valign='top'><p align='center'>Leroy Garrett, Editor</p></td>";
	newTable += "    <td width='33%' valign='top'><p align='right'>"+get_month(current_number)+" "+current_year+"</p></td>";
	newTable += "  </tr>";
	newTable += "</table>";
    //insert new span element before menu table;
	myTables[1].insertAdjacentHTML('beforeBegin', "<span id='header'></span>");
	//insert new table into new span element
	document.all.header.innerHTML = newTable;

    //if an intro page being accessed directly
    var str = window.location.href;
    var intro = str.split("&");
    if(intro.length > 4)
      {
        display_intro(intro[4]);
      }
}

function set_cursor(obj)
{
  obj.style.cursor = "hand";
}

function search_init()
{
  set_page_style()
  set_menu(menu01)
  format_buttons(); //in menu01.js
  document.all.main_R.style.fontFamily = "Arial";
  document.all.main_R.style.fontSize = "10pt";
  hWin = document.documentElement.clientHeight;
  document.all.main_R.style.height = hWin-30;
}

function authors_init()
{
  set_page_style()
  set_menu(menu01)
  format_buttons(); //in menu01.js
  document.all.main_R.style.fontFamily = "Arial";
  document.all.main_R.style.fontSize = "10pt";
}

function series_init()
{
  set_page_style()
  set_menu(menu01)
  format_buttons(); //in menu01.js
  document.all.main_R.style.fontFamily = "Arial";
  document.all.main_R.style.fontSize = "10pt";
}

function set_page_style()
{
  document.all.filler_R.style.borderLeft = "2 solid #6B9CE7";
  document.all.main_R.style.borderLeft = "2 solid #6B9CE7";
  document.all.main_L.style.backgroundColor = "#6B9CE7";
  document.all.filler_L.style.backgroundColor = "#6B9CE7";
  links = document.getElementsByTagName("a")
  //added 01Aug07 for authors
  for(i=0; i<links.length; i++)
    {
      links[i].style.color = "blue";
    }
}

function set_menu(menu)
{
  document.all.the_menu.innerHTML = menu;
}

function go_here(where)
{
  var link = new Array();  
  link[1] = "http://www.leroygarrett.org/restorationreview/"; //13Sep07
  link[2] = "index.htm?"+current_volume;
  //link[3] = ""; //number index
  
  link[4] = "http://www.leroygarrett.org/restorationreview/authors.htm";
  link[5] = "series.htm";
  link[6] = "http://www.leroygarrett.org";
  link[7] = "http://www.leroygarrett.org/restorationreview/search/search.php";
  location.href = link[where];
}

function format_buttons()
{
  var tmp = document.all.filler_L.offsetWidth;
  oWidth = tmp * .70; //19Apr07
  //var myButtons = document.getElementsByTagName("input"); //changed for search page
  myelem = document.all.main_L;
  var myButtons = myelem.getElementsByTagName("input");
  for(i=0; i<myButtons.length; i++)
    {
      myButtons[i].style.width = oWidth;//"100";
      myButtons[i].style.height = "21";
      myButtons[i].style.fontFamily = "arial";
      myButtons[i].style.fontSize = "9pt";
      myButtons[i].style.color = "blue";
      //myButtons[i].style.background = "url(images/stucco2.gif)";
    }
}

function load_menu()
{
  //if(document.all.vmenu.value > 0)
  if(document.all.vmenu.value.length > 0)
    {
      //set volume if called from volume menu
      //else, use global value
      var str = document.all.vmenu.value;
      pos = str.indexOf("_");
      current_volume = str.substr(0,pos);
      current_year = get_year(current_volume);
    }
//  document.all.mmenu.innerHTML = imenu; //following conditional inserted on July 16, 2007

  if(current_volume < 6)
    {
      document.all.mmenu.innerHTML = imenuB;
    }
  else
    {
      document.all.mmenu.innerHTML = imenu;
    }

  document.all.vol_num.innerText = "Volume "+current_volume;
  document.all.vol_num.style.color = "black";//"#6B9CE7";
  document.all.vol_num.style.fontWeight = "bold";
  document.all.vol_num.style.display = "block";
}

function get_number_index()
{
 //see notes in the comment section at top of file
 if(document.all.imenu)
   {
     current_number = document.all.imenu.value;
   }
 //current_volume and current_number need to be passed to 
 //display_index, and there the global variables can be reset
 //if PHP, there are other options for setting these variables
 if(current_number < 10)
   {
     var folder = "rr"+current_volume+"_0"+current_number;
   }
 else
   {
     var folder = "rr"+current_volume+"_"+current_number;
   }

 if(current_year == null)
   {
     current_year = get_year(current_volume);
   }

if(arguments.length > 0) //added on 01Aug07 for author index
  {
    //get_number_index('rr29_09/rr29_09e.htm')
    //parse arguments[0] to extract current_volume, current_number
    //rr01_04/rr01_04c.htm
    str1 = arguments[0];
    str2 = str1.substr(2,5); //01_04
    strs = str2.split("_");
    current_volume = strs[0];
    //current_number = parseInt(strs[1]); //did not work on string value
    current_number = eval(strs[1]);
    current_year = get_year(current_volume);
    location.href = "article.htm?"+arguments[0]+"&"+current_volume+"&"+current_number+"&"+current_year;
  }
else
  {
    location.href = "display_index.htm?"+folder+"/"+folder+".htm&"+current_volume+"&"+current_number+"&"+current_year;
  }
}

//called when user clicks on article link in number menu
function get_article()
{
  var article = document.all.amenu.value;
  pos = article.lastIndexOf("/");
  article = article.substr(pos+1, article.length);
  if(current_number < 10)
    {
      var folder = "rr"+current_volume+"_0"+current_number;
    }
  else
    {
      var folder = "rr"+current_volume+"_"+current_number;
    }
  location.href = "article.htm?"+folder+"/"+article+"&"+current_volume+"&"+current_number+"&"+current_year;
}

function get_year(curr_vol) //year)
{
  var BASE = 1958;
  var year = eval(BASE + parseInt(curr_vol,10)); //year)); 
  return year;
}

function get_month(num)
{
  var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
  return months[num];
} 

function format_reading_pane()
{ 
  
  //alert(rMargin);//document.all.header.style.left);
  if(rMargin == null)
    {
      rMargin = document.all.header.style.left;
    }
  
  var myDivs = document.getElementsByTagName("div");
  if(myDivs[0])
    {
      var readLeft = myDivs[0].style.marginLeft;
      var readRight = myDivs[0].style.marginRight;
      if(direction == 1)
        {
		  if(readLeft == "20px" && readRight == "0px")
		    {
			  readLeft = "50px";
			  readRight = "50px";
			}
 		  else if(readLeft == "50px" && readRight == "50px")
			{
			  readLeft = "100px";
			  readRight = "100px";
			}
		  else if(readLeft == "100px" && readRight == "100px")
		 	{
			  readLeft = "150px";
			  readRight = "150px";
			}			
		  else if(readLeft == "150px" && readRight == "150px")
		 	{
			  readLeft = "200px";
			  readRight = "200px";
			  direction = 0;
			}			
		}
	  else
	    {
		  if(readLeft == "200px" && readRight == "200px")
		 	{
			  readLeft = "150px";
			  readRight = "150px";
			}			
		  else if(readLeft == "150px" && readRight == "150px")
		 	{
			  readLeft = "100px";
			  readRight = "100px";
			}			
		  else if(readLeft == "100px" && readRight == "100px")
		 	{
		 	  readLeft = "50px";
		 	  readRight = "50px";
		 	}
		  else if(readLeft == "50px" && readRight == "50px")
		 	{
		 	  readLeft = "20px";
		 	  readRight = "0px";
		 	  direction = 1;
		 	}
	    }
	  
      myDivs[0].style.marginLeft = readLeft;
      myDivs[0].style.marginRight = readRight;
      var headerNew = parseInt(rMargin) - parseInt(readRight);

      var header = document.getElementById("header"); //added 15Jun06
      header.style.left = headerNew;
    }
}

function goto_comments()
{
  //dimensions of objects in parent window
  menubar_width = document.all.filler_L.offsetWidth;
  main_width = document.all.filler_R.offsetWidth;

  //dimensions of parent window
  if(window.innerWidth) //non MSIE
    {
      var parentWidth = window.innerWidth;
      var parentHeight = window.innerHeight;
    }
  else
    {
      var parentWidth = document.body.offsetWidth;
      var parentHeight = document.body.offsetHeight;
    }

  var popUp_width = main_width - (.004 * main_width); //parentWidth - menubar_width;
  var popUp_height = parentHeight-89;

  //the absolute position of the parent window on the monitor screen
  if(window.screenY) //non MSIE
    {
      var winTop = window.screenY;
      var winLeft = window.screenX;
    }
  else
    {
      var winTop = window.screenTop; 
      var winLeft = window.screenLeft;
    }
 
  var popUp_posLeft = (menubar_width+winLeft)+4;
  var popUp_posTop = winTop+2;

  var str01 = window.location.href; 
  myWindow = window.open ("comments/comments.php?"+str01,"myWindow","location=1,resizable=1,width="+popUp_width+",height="+popUp_height+",left="+popUp_posLeft+",top="+popUp_posTop);
  if(testing == 0)
    {
      document.all.commentsBtn.disabled = true;
      document.all.homeBtn.disabled = true;
      document.all.volIndexBtn.disabled = true;
      document.all.numIndexBtn.disabled = true;
      document.all.worksBtn.disabled = true;
    }
}

function notify_parent_onclose(num)
{
  //in any event, enable the commentsBtn button
	if(testing == 0)
	{
	if(document.all.commentsBtn.disabled = true)
		{
		document.all.commentsBtn.disabled = false;
		document.all.homeBtn.disabled = false;
		document.all.volIndexBtn.disabled = false;
		document.all.numIndexBtn.disabled = false;
		document.all.worksBtn.disabled = false;
		}

	if(close_flag == 1)
		{
		close_flag = 0;
		}
	if(num == 1) //Exit button clicked
		{
		close_flag = 1; //set flag so the next time the funciton is called the commentsBtn button will be enabled
		//close window to trigger onbeforeclose 
		//which calls this function with an argument of 0
		myWindow.close(); 
		}
	}  
}

