
// include application js file after this hdr.js

function bodyAppend( d )
{
	document.childNodes[1].appendChild( d ) ;
}

function makediv( id )
{
	var d = document.createElement( 'div' );
	d.id = id;
	return d;
}

function text( t )
{
	return document.createTextNode( t );
}

function br()
{
	return document.createElement( 'br' );
}

function makelink( h, n ) // n must be a node, i.e. text(t), not plaintext
{
	var a = document.createElement( 'a' );
	a.href = h;
	a.appendChild( n );
	return a;
}

/*
function append_br( node )  // obsolete?
{
	node.appendChild( document.createElement( 'br' ) );
}

function append_text( node, txt ) // obsolete?
{
	node.appendChild( document.createTextNode( txt ) );
}
*/

function banner()
{
	function capital( letter )
	{
		var cap = document.createElement( 'span' );
		cap.className = 'acro';
		cap.appendChild( text( letter ) );
		return cap;
	}
	
	document.write('<div id="logo"></div><div id="gfohdr"></div>');

	var tree = document.createElement( 'img' );
	tree.setAttribute( 'alt', "Genealogy Forum Logo" );
	tree.setAttribute( 'src', "http://www.gfo.org/hdr/logo.jpg" );
	document.getElementById( 'logo' ).appendChild( makelink( 'http://www.gfo.org', tree ) );

	var bnnr = document.getElementById( 'gfohdr' );
	var hdr7 = makediv( 'gfoH7' ); bnnr.appendChild( hdr7 );
	var hdr6 = makediv( 'gfoH6' ); hdr7.appendChild( hdr6 );
	var hdr5 = makediv( 'gfoH5' ); hdr6.appendChild( hdr5 );
	var hdr4 = makediv( 'gfoH4' ); hdr5.appendChild( hdr4 );
	var hdr3 = makediv( 'gfoH3' ); hdr4.appendChild( hdr3 );
	var hdr2 = makediv( 'gfoH2' ); hdr3.appendChild( hdr2 );
	var hdr1 = makediv( 'gfoH1' ); hdr2.appendChild( hdr1 );
	
	hdr1.appendChild( capital( 'G' ) ); hdr1.appendChild( text( 'enealogical ' ) );
	hdr1.appendChild( capital( 'F' ) ); hdr1.appendChild( text( 'orum of ' ) );
	hdr1.appendChild( capital( 'O' ) ); hdr1.appendChild( text( 'regon' ) );
}

var v_phone  = '(503) 963-1932';
var v_gfoinc = 'Genealogical Forum of Oregon, Inc.';
var v_street = '2505 S.E. 11th Ave., Suite B-18';
var v_csz    = 'Portland, OR 97202';

function snail_mail()
{
	document.write(v_gfoinc+'<br>');
	document.write(v_street+'<br>');
	document.write(v_csz);
}

function snailmail(id)
{
	var addr = document.getElementById(id)
	addr.appendChild( text( v_gfoinc ) ); addr.appendChild( br() );
	addr.appendChild( text( v_street ) ); addr.appendChild( br() );
	addr.appendChild( text( v_csz ) );
}

function snail_mail_short()
{
	document.write( v_street + ', ' + v_csz );
}

function gfo_email( txt )
{
	document.write( '<a href="mailto:gfoi'+'nfo@hotmail.com">');
	if( !txt ) txt = 'gfoin'+'fo@hotmail.com';
	document.write( txt + '</a>' );
}

function gfo_phone()
{
	document.write( v_phone );
}

function visitor_fee()
{
	document.write( '$7.00' );
}

function my_file()
{
    var chunks = location.toString().split("/");
    var fn = chunks[chunks.length-1];
    return fn.split( '.' )[0];
}

// s.substr( -n ) should work, but IE is broken
function rightstr( s, n )
{
    return s.substr( s.length - n );
}

function lz( n, totlen )
{
    return rightstr( '0000000000' + String( n ), totlen ) ;
}

function navLinks()
{
	function noLink( d, t )
	{
		d.appendChild( text( t + ' ' ) );
	}

	function seqLink_x( d, t, f )
	{
		d.appendChild( makelink( f, text( t ) ) );
		d.appendChild( text( ' ' ) ) ;
	}

	function seqLink( d, t, num )
	{
		var anyfile = file_root + lz( num, file_num_digits ) + '.htm';
		seqLink_x( d, t, anyfile );
	}

	function firstLink(d)
	{
		var file_num = rightstr( my_file(), file_num_digits ) ;
		if( --file_num < file_num_first )
			noLink( d, 'first' );
		else
			seqLink( d, 'first', file_num_first );
	}

	function prevLink(d)
	{
		var file_num = rightstr( my_file(), file_num_digits ) ;
		if( --file_num < file_num_first )
			noLink( d, 'previous' );
		else
			seqLink( d, 'previous', file_num );
	}

	function nextLink(d)
	{
		var file_num = rightstr( my_file(), file_num_digits ) ;
		if( ++file_num > file_num_last )
			noLink( d, 'next' );
		else
			seqLink( d, 'next', file_num );
	}

	function lastLink(d)
	{
		var file_num = rightstr( my_file(), file_num_digits ) ;
		if( ++file_num > file_num_last )
			noLink( d, 'last' );
		else
			seqLink( d, 'last', file_num_last );
	}

	if( file_num_last <= 0 ) return;
	var which = "prevnext1" ;
	if( document.getElementById( which ) ) which = "prevnext2" ;
	
	document.write( '<div id="' + which + '"></div>' );
	var d = document.getElementById( which );
	d.style.textAlign='center';
	d.style.padding='.5em';
	
	if( file_num_last > file_num_first )
		{firstLink( d );prevLink( d );}

	seqLink_x( d, 'intro', 'index.htm' );

	if( file_num_last > file_num_first )
		{nextLink( d );lastLink( d );}
}

function site_links()
{
	var home="http://www.gfo.org/";
	var sep=" | ";
	document.write( '<p>');
	document.write( 'HOME'.link( home+"index.htm") +sep  );
	document.write( 'Calendar'.link( home+"calendar.htm") +sep  );
	document.write( 'Collections/Guides'.link( home+"resources.htm") +sep  );
	document.write( 'Directions'.link( home+"directions.htm") +sep  );
	document.write( 'Education'.link( home+"edu/classes.htm") +sep  );
	document.write( 'Hours'.link( home+"hours-loc.htm") +sep  );
	document.write( 'Insider'.link( home+"insider/index.htm") +sep  );
	document.write( 'Interest&nbsp;Groups'.link( home+"intgrp/index.htm") +sep  );
	document.write( 'Library'.link( home+"library/index.htm") +sep );
	document.write( 'Mailing&nbsp;List'.link( home+"mlist.htm") +sep  );
	document.write( 'Membership'.link( home+"membership/index.htm") +sep  );
	document.write( 'Membership&nbsp;Meetings'.link( home+"month_meet.htm") +sep  );
	document.write( 'News'.link( home+"index.htm#news") +sep  );
	document.write( 'Publications'.link( home+"pubslist.pdf") +sep  );
	document.write( 'Research'.link( home+"respol.htm") );
	document.write( '<\/p>');
}

function footer( lastrev, id)
{
	var d = makediv( "contact" );
	d.appendChild( text( "If you have comments or suggestions, please send email to: " ) );
	d.appendChild( makelink( 'mailto:s.lar' + 'ry@rocketmail.com', text( "GFO Webmaster" ) ) );
	d.appendChild( br() );
	d.appendChild( text( "Copyright \u00A9 1998-2012 Genealogical Forum of Oregon, Inc. All rights reserved." ) );
	d.appendChild( br() );
	d.appendChild( text( "Last Revision: " + lastrev ) );
	if( id ) 
	{ document.getElementById( id ).appendChild( d ); }
	else
	{ bodyAppend( d ) } ;
}
