	function fn() 
	{
		var chapdir = document.location.pathname;
//		var URL = "../../../cgi/NewSmartCompile.pl?code=palmer&ext=html&key=252&path=" + chapdir;
		var URL = "http://www.codepublishing.com/AK/Palmer/cgi/NewSmartCompile.pl?code=palmer&ext=html&key=252&path=" + chapdir;
	
		document.location.href = URL;
	}

	function gn()
	{
		fn();
	}

	function init()
	{
		
		var e = document.getElementById('mainContent');
		var f = buildForm();
		//finds an h1 if the document has one
		var h = document.getElementsByTagName('h1');
		//don't insert compile chapter form into Title digest pages
		var p = document.getElementsByTagName('p');
		//don't insert compile chapter form into repealed chapter, which will have p-tag of "Rxhead"
	
		if( h.length > 0 && h[0].className == 'Title') { return; }
		if( p.length > 0 && p[0].className == 'Rxhead') { return; }
		var penultimate = e.lastChild;
    	try { //this works only in IE8
		   penultimate.style.marginBottom="1em";
  		}
  		catch(err) { //this works only in Firefox
            penultimate.style="margin-bottom:1em";
         }
		//stick the form into the document as the last thing before the </blockquote>
		e.appendChild( f );
		var g = document.getElementsByTagName('input');
		//attach the fn() function to the form button
		g[0].onclick = function(){ fn(); };
		
	}
	
	//constructs the "compile chapter" form
	function buildForm()
	{
		var myForm = document.createElement( 'form' );
		var myPara = document.createElement( 'p' );
		myPara.className = 'show';
		var button = document.createElement('input');
		button.setAttribute('value', "Compile Chapter");
		button.setAttribute('type', "button");
		myPara.appendChild(button);
		myForm.appendChild(myPara);
		return myForm;
	
	}
	
	window.onload = function(){ init(); };