// Universal Related Select Menus - cascading popdown menus
// (Dynamically-sized related menus using JS 1.1's new Option cmd)
// by Andrew King. v1.33 19990715
// Copyright (c) 1999 internet.com LLC. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Originally published and documented at http://www.webreference.com
// Contact aking@internet.com for all other uses.
//
// 3-3-96 code optimized, modularized, and made universal-abk
// 3-8-97 jumpPage1 and 2 consolidated into generalized func
// 3-10-97 changeMenu added jumpPage(0,0), for non-ns3 browsers
// make popup act like a live popup when no related functionality
// 8-5-97 browser detect script changed to check for option functionality
// 9-11-97 aln changed to options.length, as IE 4 does not support
// nulling out options
// 12-22-98 added SIZE att to make select lists, used named forms/elements
// 1-1-99 added getFormNum to fix netscape 2 bug (doesn't support named fms)
//  pass formName, elementNum to relate and jmp as workaround
//  pass this.form,0 and increment instead of decrement in relate to get 
//   next form
//  assumes menu2 follows menu1 in HTML
// tested in mac ie3.01/ns2.02 (live), ns 3.01,4.05,4.5 and ie4.01 related
// 990701 - fixed back button bug in ie4+ by resetting all forms onload-abk
//    thanks to peter belesis (pbel@internet.com) for this fix
// 990714 - added IE5 persistence - abk pb, note this vers bombs gecko
//  use the newer vers on next page, intro2.html
// 990715 - went open source, created stipped down example files - abk
// 990720 - jmp() fix getFormNum(formName);->
//     var formNum = getFormNum(formName);
// 990722 - var for scope added, jmp chgd to named form for ns2.02 bug-abk

if(v){a=new Array(22);aln=22;}

function getFormNum (formName) {
	var formNum =-1;
	for (i=0;i<document.forms.length;i++){
		tempForm = document.forms[i];
		if (formName == tempForm) {
			formNum = i;
			correctForm = tempForm;
			break;
		}
	}
	return formNum;
}

function jmp(form, elt)
// The first parameter is a reference to the form.
{
	if (form != null) {
		with (form.elements[elt]) {
			if (0 <= selectedIndex)
				parent.major.location = options[selectedIndex].value;
		}
	}
}


function O(txt,url) {
a[k]=new Option(txt,url);k++;
}
function relate(formName,elementNum,j) {
if(v){
k=1;
if(j==0){
parent.major.location = "main.htm";
a=new Array(2);
O("This submenu changes according to the titles of the main menu","main.htm");
}
if(j==1){
parent.major.location = "inside/4.htm";
a=new Array(4);
O("Introduction","inside/4.htm");
O("Editor's note","inside/1.htm");
O("Translator's preface","inside/2.htm");
O("Author's preface","inside/3.htm");
}
if(j==2){
parent.major.location = "inside/5.htm";
a=new Array(3);
O("Introduction","inside/5.htm");
O("General rules","inside/6.htm");
O("Questions and answers","inside/7.htm");
}
if(j==3){
parent.major.location = "inside/8.htm";
a=new Array(3);
O("Introduction","inside/8.htm");
O("General rules","inside/9.htm");
O("Questions and answers","inside/10.htm");
}
if(j==4){
parent.major.location = "inside/11.htm";
a=new Array(3);
O("Introduction","inside/11.htm");
O("General rules","inside/12.htm");
O("Questions and answers","inside/13.htm");
}
if(j==5){
parent.major.location = "inside/14.htm";
a=new Array(3);
O("Introduction","inside/14.htm");
O("General rules","inside/15.htm");
O("Questions and answers","inside/16.htm");
}
if(j==6){
parent.major.location = "inside/17.htm";
a=new Array(3);
O("Introduction","inside/17.htm");
O("General rules","inside/18.htm");
O("Questions and answers","inside/19.htm");
}
if(j==7){
parent.major.location = "inside/20.htm";
a=new Array(3);
O("Introduction","inside/20.htm");
O("General rules","inside/21.htm");
O("Questions and answers","inside/22.htm");
}
if(j==8){
parent.major.location = "inside/23.htm";
a=new Array(3);
O("Introduction","inside/23.htm");
O("General rules","inside/24.htm");
O("Questions and answers","inside/25.htm");
}
if(j==9){
parent.major.location = "inside/26.htm";
a=new Array(3);
O("Introduction","inside/26.htm");
O("General rules","inside/27.htm");
O("Questions and answers","inside/28.htm");
}
if(j==10){
parent.major.location = "inside/29.htm";
a=new Array(3);
O("Introduction","inside/29.htm");
O("General rules","inside/30.htm");
O("Questions and answers","inside/31.htm");
}
if(j==11){
parent.major.location = "inside/32.htm";
a=new Array(3);
O("Introduction","inside/32.htm");
O("General rules","inside/33.htm");
O("Questions and answers","inside/34.htm");
}
if(j==12){
parent.major.location = "inside/35.htm";
a=new Array(3);
O("Introduction","inside/35.htm");
O("General rules","inside/36.htm");
O("Questions and answers","inside/37.htm");
}
if(j==13){
parent.major.location = "inside/38.htm";
a=new Array(3);
O("Introduction","inside/38.htm");
O("General rules","inside/39.htm");
O("Questions and answers","inside/40.htm");
}
if(j==14){
parent.major.location = "inside/41.htm";
a=new Array(3);
O("Introduction","inside/41.htm");
O("General rules","inside/42.htm");
O("Questions and answers","inside/43.htm");
}
if(j==15){
parent.major.location = "inside/44.htm";
a=new Array(3);
O("Introduction","inside/44.htm");
O("General rules","inside/45.htm");
O("Questions and answers","inside/46.htm");
}
if(j==16){
parent.major.location = "inside/47.htm";
a=new Array(3);
O("Introduction","inside/47.htm");
O("General rules","inside/48.htm");
O("Questions and answers","inside/49.htm");
}
if(j==17){
parent.major.location = "inside/50.htm";
a=new Array(3);
O("Introduction","inside/50.htm");
O("General rules","inside/51.htm");
O("Questions and answers","inside/52.htm");
}
if(j==18){
parent.major.location = "inside/53.htm";
a=new Array(3);
O("Introduction","inside/53.htm");
O("General rules","inside/54.htm");
O("Questions and answers","inside/55.htm");
}
if(j==19){
parent.major.location = "inside/56.htm";
a=new Array(3);
O("Introduction","inside/56.htm");
O("General rules","inside/57.htm");
O("Questions and answers","inside/58.htm");
}
if(j==20){
parent.major.location = "inside/59.htm";
a=new Array(1);
O("Epilogue","inside/59.htm");
}
if(j==21){
parent.major.location = "appendix/1.htm";
a=new Array(1);
O("Specimen of Ayatullah as-Sistani's answers","appendix/1.htm");
O("Haram ingredients in the manufacturing of food","appendix/appendix2.htm");
O("Ingredients and preservatives in food products","appendix/appendix3.htm");
O("Pictures of scale fish","appendix/fish1.htm");
O("List of scale fish","appendix/table.htm");
}

aln2=a.length;
var formNum = getFormNum(formName); // var formNum added, explicit var pass
if (formNum>=0) {
	formNum++; // reference next form, assume it follows in HTML
	with (document.forms[formNum].elements[elementNum]) {
		for (var i=options.length-1;i>0;i--) options[i]=null;
		for (var i=1;i<aln2;i++) options[i-1]=a[i];
		options[0].selected=true;
	}
}
} else {
jmp(formName,elementNum);
}
}

// BACK BUTTON FIX for ie4+- or
// MEMORY-CACHE-STORING-ONLY-INDEX-AND-NOT-CONTENT
//
// from peter belesis:
// IE4+ remembers the index of each SELECT but NOT the CONTENTS of each
// SELECT, so it gets it wrong.
//
// it has to do with MEMORY CACHE (where form input is stored) and how
// IE stores information about SELECT menus.
//
// IE stores the selectedINDEX ONLY of the SELECT menu, not the
// CONTENTS-AT-THE-TIME-OF-SELECTION
//
// when we return to a page, it displays the default contents of each
// SELECT, grabs the stored index from cache and aligns the default
// contents to that index.
// 
// Netscape, on the other hand, seems to remember both INDEX and CONTENTS
// added ie5 persistence 990714

function IEsetup(){
	if(!document.all) return;
	IE5 = navigator.appVersion.indexOf("5.")!=-1;
	if(!IE5) {
		for (i=0;i<document.forms.length;i++) {
			document.forms[i].reset();
		}
	}
}

window.onload = IEsetup;
