/*******************************************************************************
* Java Script Functions for RCF 03-13-2008                                     *
* Specifically tailored for Flesher Family Redwood                             *
*                                                                              *
*******************************************************************************/

// Page Layout Functions
// official date of record for each webpage; the alpha names and descendants pages get their dates from the generating program.
var d = document;											// convenient shorthand
var census_dor = "13 May 2008";
var email_dor = "1 Apr 2008";
var home_dor = "31 Mar 2010"; 
var locations_dor = "26 Aug 2009";
var mysql_dor = "23 Sep 2009";
var photos_dor = "21 Oct 2009";
var reunions_dor = "25 Aug 2009";
//var queries_dor = "23 Nov 2008";
//var whatsnew_dor = "1 Dec 2009";
var br = browserId();

function wrapperStyle () {
	if ( br == "ie7" ) {
		d.write("<style type='text/css'> #wrapper {margin-left: "+((screen.width-764)/2)+"} </style>"); }
	else if ( br == "ie6" ) {
		d.write("<style type='text/css'> #wrapper {margin-left: 3;} </style>"); }
	else if (br == "nn6") {
		d.write("<style type='text/css'> #wrapper {margin: 0 auto;} </style>"); }
	else {
		d.write("<style type='text/css'> #wrapper {margin-left: "+((screen.width-750)/2)+"} </style>");
	} // this branch not tested
}

function contentStyle () {
	if (br == "ie7" ) {
		document.write("<style type='text/css'> #content {margin-right: -10;} </style>");
	}
	else if (br == "ie6" ) {
		document.write("<style type='text/css'> #content {margin: 0 -10 0 0;} </style>");
	}
	else if (br == "nn6") {
		document.write("<style type='text/css'> #content {margin-right: -10;} </style>");
	}
	else {
		document.write("<style type='text/css'> #content {margin-right: -21;} </style>");
	} // this branch not tested
}

function showTitle() {
   document.write("<br><img width='764' height='165' "); //926x185 centered in 215
   document.write("src='../images/ffr.heading.gif' alt='Tree & FFR'><br>");
}

function showSidebar(domain) { // domain is not referenced since only one website is active.
	document.write("<img width='34' height='50' "); 
	document.write("src='../images/rodins.thinker.right.gif' "); 
	document.write("alt='Rodins Thinker'><br><br>");
	document.write("<a href='home.html'>Home</a><br><br>");
	document.write("<a href='namesalpha01.html'>Alpha<br>Name Index</a><br><br>");
	document.write("<a href='descendants.html'>Descendants<br>List</a><br><br>");
	document.write("<a href='photos_chart_menu.php'>Photos Chart<br>Page</a><br><br>");
	document.write("<a href='reunions_1_list.php'>Reunions Page</a><br><br>");
	document.write("<a href='photos_2a_state.php'>Cemetery Photos<br>Page</a><br><br>");
	document.write("<a href='mysql.php'>mySQL<br>database</a><br><br>");
//	document.write("<a href='photos_1.php'>Photos Page</a><br><br>");
	document.write("<a href='namesbirth.html'>Birth Order<br>Name Index</a><br><br>");
	document.write("<a href='surnames.html'>Surname Index</a><br><br>");
//	document.write("<a href='locations.html'>Location Index</a><br><br>");
	document.write("<a href='calendar.php'>Calendar<br>Page</a><br><br>");
	document.write("<a href='clock.php'>Clock<br>Page</a><br><br>");
	document.write("<a href='whatsnew.php'>What&#39;s New<br>Page</a><br><br>");
	document.write("<a href='queries.surrogate.php'>Queries Page</a><br><br>");
//	document.write("<a href='newsletters.html'>Newsletters</a><br><br>");
//	document.write("About Us&#40;Me&#41;<br>Page<br><br>");
//	document.write("Guest Book Page<br><br>");
	document.write("<a href='email.connection.html'>Contact Us</a><br><br>");
	document.write("<img width='34' height='50' ");
	document.write("src='../images/rodins.thinker.left.gif' ");
	document.write("alt='Rodins Thinker'><br><br>");
}

function showPageName(name) {
	document.write("Today is: <span id='date'>d d m y</span>&#59; ");
	document.write("the time now is: <span id='time'>00:00:00</span> ");
	document.write("at the "+name);
}
function showSurnameIndex() {
	document.write("<h2>");
	document.write("<a href='namesalpha01.html#A'>A</a> ");
	document.write("<a href='namesalpha01.html#B'>B</a> ");
	document.write("<a href='namesalpha01.html#C'>C</a> ");
	document.write("<a href='namesalpha01.html#D'>D</a> ");
	document.write("<a href='namesalpha01.html#E'>E</a> ");
	document.write("<a href='namesalpha02.html#F'>F</a>; ");
	document.write("FLESHER: ");
	document.write("<a href='namesalpha02.html#FA'>A</a>, ");
	document.write("<a href='namesalpha02.html#FM'>M</a>, ");
	document.write("<a href='namesalpha02.html#FR'>R</a>; ");
	document.write("<a href='namesalpha02.html#FS'>S</a>; <br>");
	document.write("<a href='namesalpha03.html#G'>G</a> ");
	document.write("<a href='namesalpha03.html#H'>H</a> I J ");
	document.write("<a href='namesalpha03.html#K'>K</a> L ");
	document.write("<a href='namesalpha03.html#M'>M</a> N O ");
	document.write("<a href='namesalpha04.html#P'>P</a> Q R ");
	document.write("<a href='namesalpha04.html#S'>S</a> T U ");
	document.write("<a href='namesalpha04.html#V'>V</a> ");
	document.write("<a href='namesalpha04.html#W'>W</a> X Y ");
	document.write("<a href='namesalpha04.html#Z'>Z</a> <br>");
	document.write("</h2>");
	document.write("<br><div class='centered'>Click a name below to go to the Descendants Page</div>");
}

function showFooter(page,lastupdate) {
   document.write("<div id='footer'><table><tr>");
   if (page != "") { 
		document.write("<td class='hits'>");
      document.write("<a href='http://www.easycounter.com/'>");
      document.write("<img class='noborder' src='http://www.easycounter.com/");
//      document.write("counter.php?rcflesher09,"+page+"' alt='stats counter'></a><br>");
//      document.write("counter.php?rcfspdms' alt='stats counter'></a><br>");
      document.write("counter.php?rcfffr' alt='ctr softwr'></a><br>");
      document.write("<a href='http://www.easycounter.com/FreeCounter3.html'>stats counter</a>");
		document.write("</td>");
	  }
   document.write("<td class='address'>");
   document.write("<address>Page last updated:<br>"+lastupdate+" <br>");
   document.write("For more info contact:<br>");
	document.write("<a href='http://rcflesher.com/rcf/webmaster.html'>");
	document.write("Ray FLESHER</a>");
	document.write("<br></address></td>");
   document.write("<td class='host'>prepared by rcflesher.com<br>powered by Apache2<br>hosted at<br>lunarpages.com</td>");
   document.write("<td class='validation'><a href='http://validator.w3.org/'>");
   document.write("<img class='noborder' src='../images/valid-html401.png' alt='Valid 4.01 T' ");
   document.write("width='88' height='31'></a><br>validated<br>html code</td></tr></table>");
   document.write("</div>");
}

 // Browser Identification

function browserId() { 
	var br = "def"; // browser code
	var bn = navigator.appName;
	var bv = parseInt(navigator.appVersion);
	var MSIE = "Microsoft Internet Explorer";
	var NN = "Netscape";
//	var FF12 = "Firefox/2.0.0.12";
	var m8 = navigator.appVersion.indexOf("MSIE 8.0")
	var m7 = navigator.appVersion.indexOf("MSIE 7.0")
	var m6 = navigator.appVersion.indexOf("MSIE 6.0")
	if (bn == MSIE && bv == 4 && m8 != -1) {br = "ie8";}
	else if (bn == MSIE && bv == 4 && m7 != -1) {br = "ie7";}
	else if (bn == NN && bv == 5) {br = "nn6";}
	else if (bn == MSIE && bv == 4 && m6 != -1) {br = "ie6";}
	else if (bn == NN && bv == 4) {br = "nn4";}
	return br;
}

// Time Functions

var month=new Array(12);
month[0]="Jan";month[1]="Feb";month[2]="Mar";month[3]="Apr";month[4]="May";month[5]="Jun";
month[6]="Jul";month[7]="Aug";month[8]="Sep";month[9]="Oct";month[10]="Nov";month[11]="Dec";

var dow=new Array(7);
dow[0]="Sun";dow[1]="Mon";dow[2]="Tue";dow[3]="Wed";dow[4]="Thu";dow[5]="Fri";dow[6]="Sat";

function update_time() {
   var rightnow = new Date(); // the current date and time
   var hours = rightnow.getHours(); // capture hours "00" thru "23"
   var minutes = rightnow.getMinutes(); // capture minutes "00" thru "59"
   var ap_code = "am";
	if (hours == 0) {ap_code = "am"; hours += 12;}
	else if (hours < 12) ap_code = "am";
	else if (hours == 12) ap_code = "pm";
   else { ap_code = "pm"; hours -= 12; }
   if (hours == 12 && minutes < 16 && ap_code == "pm") ap_code = "noon";
   var hourstring = hours.toString();
   if (minutes < 10) var minutestring = "0" + minutes.toString();
   else var minutestring = minutes.toString();
   var seconds = rightnow.getSeconds(); // capture seconds "00" thru "59"
   if (seconds < 10) var secondstring = "0" + seconds.toString();
   else var secondstring = seconds.toString();
   var timestring = hourstring + ":" + minutestring + ":" + secondstring;
   timestring = timestring + " " + ap_code;
   var timeplace = d.getElementById("time");
   timeplace.childNodes[0].nodeValue = timestring;
   setTimeout('update_time()', 1000);
   var ddd = dow[rightnow.getDay()];
   var dd = rightnow.getDate();
   var mmm = month[rightnow.getMonth()]; 
   var yyyy = rightnow.getFullYear();
   var datestring = ddd+" "+dd+" "+mmm+" "+yyyy;
   var dateplace = document.getElementById("date");
   dateplace.childNodes[0].nodeValue = datestring;
}

// Newsletter Functions

	var vol=new Array(); // which volume is each page in.
   var nbr=new Array(); // which number is each page in.
	var nxpg=new Array(); // which page is next each time
   var ppg=new Array(); // which page is next each time

function TwoDArray(x,y) {
   for (var i = 1; i <= x; i++) {
      this[i] = new Array(y);
   }
   this.width = x; this.height = y;
}

function loadFirstPage() {
	firstpage = new TwoDArray(14,4);
	firstpage[1][1]  =   1;  // which page starts a new issue
	firstpage[1][2]  =   5;
	firstpage[13][4] = 661;
	firstpage[14][1] = 675;
	firstpage[14][2] = 689;
	firstpage[14][3] = 699;
	for (var i=1;     i<=4;     i++) { vol[i]=1; }
	for (var i=661;   i<=674;   i++) { vol[i]=13;}
	for (var i=675;   i<=698;   i++) { vol[i]=14;}

	for (var i=1;     i<=4;     i++) { nbr[i]=1; }
	for (var i=661;   i<=674;   i++) { nbr[i]=4; }
	for (var i=675;   i<=688;   i++) { nbr[i]=1; }
	for (var i=689;   i<=698;   i++) { nbr[i]=2; }

	for (var i=1;     i<=3;     i++) {nxpg[i]=i+1; }
	nxpg[4]=661;
	for (var i=661;   i<=698-1; i++) {nxpg[i]=i+1; }

	for (var i=2;     i<=4;     i++) { ppg[i]=i-1; }
   ppg[661]=4;
	for (var i=661+1; i<=698;   i++) { ppg[i]=i-1; }
}
function showVol(value) {
	alert("The chosen volume number is "+value+".\nThe associated page nbr is "+firstpage[value][1]+".");
//	document.write(vol.indexOf(value));
}

function showPage(pgno, lastpage, exp) {
	loadFirstPage();
	pgno = showMenu(pgno, lastpage, exp);
	document.write("<br>");

	document.write("<div id='volumes'>");
	document.write("or choose a vol nbr here");
	document.write("<form action=''>");
	document.write("<select name='vols' onchange='showVol(this.value)'>");
	var yr = 1995;
	for (x=1; x<=14; x++) {
		document.write("<option value='"+x+"'>");
		document.write("Vol "+x+" "+(yr++)+" ");
		document.write("</option>");
	}
	document.write("</select>");
   document.write("</form>");
   document.write("</div><!--volumes-->");

   document.write("<br>");
   document.write("<img src='../images/ffr.p."+pgno+".jpg'");
   document.write(" height='880' Width='680' alt='FFR pg "+pgno+"'>");
   document.write("<br>");
   pgno = showMenu(pgno, lastpage, exp);
   document.write("<br><br>");
}

function showMenu(pgno, lastpage, exp) { 

   pgno = getCookie("pagenbr");
   if (pgno == "null") { pgno = 1; setCookie("pagenbr", pgno, exp); }
   if (pgno ==  null ) { pgno = 1; setCookie("pagenbr", pgno, exp); }

   document.write("<br>");
   document.write("Vol "+vol[pgno]+" No "+nbr[pgno]+" ");
   document.write("pg "+ pgno );
   document.write("&nbsp; &nbsp; ");
   if (pgno == 1) {document.write("First Page");}
   else {document.write("<a onclick='chooseFirstPage()'"); 
      document.write("href='newsletters.html'>First Page</a>");
      }
   document.write("&nbsp; &nbsp; ");
   if (pgno == 1) {document.write("Previous Page");}
   else {document.write("<a onclick='choosePreviousPage()'"); 
      document.write("href='newsletters.html'>Previous Page</a>");
      }
   document.write("&nbsp; &nbsp; ");
//	volx = page[pgno];
//	document.write("<br>idx="+nxpg.indexOf(volx)+" pgno="+pgno+"<br>");
   if (pgno == lastpage) {document.write("Next Page");}
   else {document.write("<a onclick='chooseNextPage()'"); 
      document.write("href='newsletters.html'>Next Page</a>");
      }
//	volx = page[pgno];
//	document.write("<br>idx="+nxpg.indexOf(volx)+" pgno="+pgno+"<br>");
   document.write("&nbsp; &nbsp; ");
   if (pgno == lastpage) {document.write("Last Page");}
   else {document.write("<a onclick='chooseLastPage()'"); 
      document.write("href='newsletters.html'>Last Page</a>");
      }
   document.write("&nbsp; &nbsp; ");
   if (pgno == firstpage[vol[pgno]][nbr[pgno]]) {
      document.write("<br>This is the first page of this issue.");
      }
   else {
      document.write("<br>This issue started on pg ");
      document.write(firstpage[vol[pgno]][nbr[pgno]]);
      }
   document.write("&nbsp; &nbsp; ");
//	var volx = vol[pgno];
//	document.write("<br>vol nbr = "+vol.indexOf(vol[pgno])+"<br>");
   return pgno;
}

function chooseFirstPage() {
   pgno = 1; 
}

function choosePreviousPage() {
// if (pgno == 675) {pgno = 2;}
// else {pgno = pgno - 1;} 
   pgno = ppg[pgno];
}

function chooseNextPage() {
		pgno = nxpg[pgno];
/*
	try {
		if(nxpg.indexOf(page[pgno])==-1){
			throw "not found";
			}
		pgno = nxpg[pgno];
		}
	catch(err) {
	if(err="not found"){
		pgno = pgno + 1;
	}
*/
//		if(pgno==1){}
//		else if(nxpg.indexOf(page[pgno])==-1){pgno = pgno + 1;}
//		else{pgno=nxpg[pgno];}
}

function chooseLastPage() {
   pgno = lastpage; 
}

// Cookie Functions
/*
comments go hear
*/

function deleteCookie(name) {
   document.cookie = name+"=; expires=Thu, 01-Jan-70 00:00:01 GMT"+"; path=/";
}
      
function getCookie(name) {
   var cookiename = name + "=";
   var dc = document.cookie;
   var begin, end;
   if (dc.length > 0) {
      begin = dc.indexOf(cookiename);
      if (begin != -1) {
         begin += cookiename.length;
         end = dc.indexOf(";", begin);
         if (end == -1) {
            end = dc.length;
         }
      return unescape(dc.substring(begin, end));
      }
   }
   return null;
}

function setCookie(name, value, expires) {
   document.cookie = escape(name) + "=" + escape(value) + "; path=/"
      + ((expires == null) ? "" : "; expires = " + expires.toGMTString());
}

// Redirection Functions

function newPage() { // not used; training only
   window.location.assign("http://rcflesher.com/index.html")
}
/*
function styleWrapper() {
	document.write("<style> #wrapper {margin-left: ");
   document.write(((screen.width-925)/2));
	document.write("}</style>");
}
*/
function pedigreeTable() {
		document.write("<table align='center' ");
			document.write("cellpadding='15'>");
	/*	var br = browserId();
		if (br == "ie8" || br == "ie7" || br == "ie6") {
			document.write("cellpadding='25'>");
		}
		else if (br == "nn6") {
			document.write("cellpadding='45'>");
		}
	*/	document.write("<tr><td>");
}

function pedigreeEnd() {
	document.write("</td></tr></table>");
}

function pageLength(page) {
}

function screenResolution() {
	document.write("screen resolution is ");
	document.write(screen.width+"x"+screen.height);
	document.write("<br>");
	document.write("window size is ");
	document.write(document.width+"x"+document.height);
	document.write("<br>");
	document.write("page size 925 leaves a margin of "+((document.width-925)/2)+".<br>");
	document.write("page size 925 leaves a margin of "+((screen.width-925)/2)+".<br>");
}
var RCFname= 'Raymond Clyde FLESHER';
var RCFdate= RCFname + ' (1943-)';
var RCFexp = ' b.19 Feb 1943 Harvey, Cook Co, IL';
/*function RCFnormal() {
	document.getElementById('RCF').innerHTML = "<b>"+RCFdate+"<\/b><br>"+
	"&nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>"; 
}*/
function RCFover() {
	document.getElementById('RCF').innerHTML = "<b>"+RCFname+"<\/b><br>"+
	"&nbsp; |&nbsp; [ "+RCFexp+" ]<br>";
//	this.innerHTML = 'Raymond Clyde FLESHER b.19 Feb 1943 Harvey, Cook Co, IL'
}
function RCFout() {
	document.getElementById('RCF').innerHTML = "<b>"+RCFdate+"<\/b><br>"+
	"&nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "+
	"<br>";
//	this.innerHTML='Raymond Clyde FLESHER (1943-)'
}
