document.getElementById("Keywd").setAttribute("autocomplete","off");

useMenus = false;
useDefs = false;
useHints = false;

if (document.getElementById) {
	theMenu = document.getElementById("Pulldown");
	if (theMenu) { 	useMenus = true; }

	SearchBox = document.getElementById("Keywd");
	HintDiv = document.getElementById("Hint");
	hintRequest = ajaxRequest();

	if (HintDiv && hintRequest) {
	   if (SearchBox) {
	      if (hintRequest) {
		useHints = true;
		HintIdx = -1;
		SearchText = "";
	      }
	   }
	}

	theDef = document.getElementById("DefFrame");
	defRequest = ajaxRequest();
	if (theDef && defRequest) { useDefs = true; }
}

mStart = '<table cellpadding="5" cellspacing="0">';
mEnd = '</table>'
menu = new Array;
menu[0] = mStart
	+ MenuRow("HOME PAGE", "index.htm")
	+ MenuRow("SITE MAP", "toc.htm")
	+ MenuRow("ABOUT THE AUTHOR", "author.htm")
	+ MenuRow("WHAT'S NU?", "nu.htm")
	+ MenuRow("CURRENT CALENDAR", "current.htm")
	+ MenuRow("SEARCH THE GLOSSARY AND INDEX", "search.htm")
	+ mEnd;
menu[1] = mStart
	+ MenuRow("WHAT IS JUDAISM?", "judaism.htm")
	+ MenuRow("BELIEFS", "beliefs.htm")
	+ MenuRow("NATURE OF G-D", "g-d.htm")
	+ MenuRow("HUMAN NATURE", "human.htm")
	+ MenuRow("MESSIAH", "mashiach.htm")
	+ MenuRow("MYSTICISM", "kabbalah.htm")
	+ mEnd;
menu[2] = mStart
	+ MenuRow("WHO IS A JEW?", "whoisjew.htm")
	+ MenuRow("GENEALOGY", "genealogy.htm")
	+ MenuRow("JEWISH POPULATION", "populatn.htm")
	+ MenuRow("MOVEMENTS", "movement.htm")
	+ MenuRow("ASHKENAZIC AND SEPHARDIC JEWS", "ashkseph.htm")
	+ MenuRow("ATTITUDES TOWARD NON-JEWS", "gentiles.htm")
	+ MenuRow("THE ROLE OF WOMEN", "women.htm")
	+ MenuRow("RABBIS, PRIESTS, ETC.", "rabbi.htm")
	+ MenuRow("PATRIARCHS AND ORIGINS", "origins.htm")
	+ MenuRow("MOSES, AARON AND MIRIAM", "moshe.htm")
	+ MenuRow("PROPHETS & PROPHECY", "prophet.htm")
	+ MenuRow("SAGES & SCHOLARS", "sages.htm")
	+ mEnd;
menu[3] = mStart
	+ MenuRow("LAND OF ISRAEL", "israel.htm")
	+ MenuRow("SYNAGOGUES, SHULS & TEMPLES", "shul.htm")
	+ mEnd;
menu[4] = mStart
	+ MenuRow("SIGNS & SYMBOLS", "signs.htm")
	+ MenuRow("JEWISH COOKING", "food.htm")
	+ mEnd;
menu[5] = mStart
	+ MenuRow("HEBREW ALPHABET", "alephbet.htm")
	+ MenuRow("HEBREW ROOT WORDS", "root.htm")
	+ MenuRow("YIDDISH", "yiddish.htm")
	+ MenuRow("EXPRESSIONS & GREETINGS", "express.htm")
	+ MenuRow("JEWISH NAMES", "jnames.htm")
	+ MenuRow("THE NAME OF G-D", "name.htm")
	+ MenuRow("TORAH", "torah.htm")
	+ MenuRow("TORAH READINGS", "readings.htm")
	+ MenuRow("PRAYERS & BLESSINGS", "prayer.htm")
	+ MenuRow("JEWISH LITURGY", "liturgy.htm")
	+ mEnd;
menu[6] = mStart
	+ MenuRow("JEWISH LAW", "halakhah.htm")
	+ MenuRow("\"TEN COMMANDMENTS\"", "10.htm")
	+ MenuRow("LOVE & BROTHERHOOD", "brother.htm")
	+ MenuRow("SPEECH & LASHON HA-RA", "speech.htm")
	+ MenuRow("DIETARY LAWS", "kashrut.htm")
	+ MenuRow("KOSHER SEX", "sex.htm")
	+ MenuRow("CHARITY", "tzedakah.htm")
	+ MenuRow("TREATMENT OF ANIMALS", "animals.htm")
	+ MenuRow("SACRIFICES & OFFERINGS", "qorbanot.htm")
	+ MenuRow("LIST OF THE 613 COMMANDMENTS", "613.htm")
	+ mEnd;
menu[7] = mStart
	+ MenuRow("JEWISH CALENDAR", "calendar.htm")
	+ MenuRow("CALENDAR: CLOSER LOOK", "calendr2.htm")
	+ MenuRow("SHABBAT", "shabbat.htm")
	+ MenuRow("SPECIAL SHABBATOT", "special.htm")
	+ MenuRow("JEWISH HOLIDAYS", "holiday0.htm")
	+ MenuRow("THE MONTH OF TISHRI", "holiday1.htm")
	+ MenuRow("ROSH HASHANAH", "holiday2.htm")
	+ MenuRow("DAYS OF AWE", "holiday3.htm")
	+ MenuRow("YOM KIPPUR", "holiday4.htm")
	+ MenuRow("FASTING TIPS", "fasttips.htm")
	+ MenuRow("SUKKOT", "holiday5.htm")
	+ MenuRow("KNOW YOUR ETROG", "etrog.htm")
	+ MenuRow("SHEMINI ATZERET AND SIMCHAT TORAH", "holiday6.htm")
	+ MenuRow("CHANUKKAH", "holiday7.htm")
	+ MenuRow("TU B'SHEVAT", "holiday8.htm")
	+ MenuRow("PURIM", "holiday9.htm")
	+ MenuRow("PESACH (PASSOVER)", "holidaya.htm")
	+ MenuRow("PESACH SEDER", "seder.htm")
	+ MenuRow("PESACH COOKING", "kfpfood.htm")
	+ MenuRow("COUNTING THE OMER", "holidayb.htm")
	+ MenuRow("SHAVU'OT", "holidayc.htm")
	+ MenuRow("TISHA B'AV", "holidayd.htm")
	+ MenuRow("ELUL AND SELICHOT", "elul.htm")
	+ MenuRow("MINOR FASTS", "holidaye.htm")
	+ MenuRow("ROSH CHODESH", "chodesh.htm")
	+ MenuRow("NEW HOLIDAYS", "holidayf.htm")
	+ MenuRow("BLESSING THE SUN", "chamah.htm")
	+ MenuRow("GENTILE'S GUIDE", "holidayg.htm")
	+ mEnd;
menu[8] = mStart
	+ MenuRow("BIRTH AND THE FIRST MONTH OF LIFE", "birth.htm")
	+ MenuRow("BAR MITZVAH, BAT MITZVAH AND CONFIRMATION", "barmitz.htm")
	+ MenuRow("MARRIAGE", "marriage.htm")
	+ MenuRow("DIVORCE", "divorce.htm")
	+ MenuRow("LIFE, DEATH AND MOURNING", "death.htm")
	+ MenuRow("OLAM HA-BA: THE AFTERLIFE", "olamhaba.htm")
	+ mEnd;
menu[9] = mStart
	+ MenuRow("BOOKS AND PUBLISHERS", "biblio.htm")
	+ MenuRow("PRAYERS AND BLESSINGS", "prayref.htm")
	+ MenuRow("CHANUKKAH", "chanukahref.htm")
	+ MenuRow("HAVDALAH", "havdalahref.htm")
	+ MenuRow("KADDISH", "kaddishref.htm")
	+ MenuRow("MEZUZAH", "mezuzahref.htm")
	+ MenuRow("ROSH HASHANAH", "roshhashref.htm")
	+ MenuRow("SHABBAT", "shabbatref.htm")
	+ MenuRow("SHEMA", "shemaref.htm")
	+ MenuRow("SUKKOT", "sukkotref.htm")
	+ MenuRow("TALLIT AND TEFILLIN", "tallitref.htm")
	+ MenuRow("BLESSING THE SUN", "chamahref.htm")
	+ MenuRow("GLOSSARY OF JEWISH TERMINOLOGY", "glossary.htm")
	+ mEnd;

function ajaxRequest() {
	return  window.XMLHttpRequest  ?
	new window.XMLHttpRequest :
	new ActiveXObject("Microsoft.XMLHTTP");
}

function HintChange() {
  if (hintRequest.readyState==4 && hintRequest.status==200) {
    theText = '<table id="HintList">';
    theText += '<tr><td onclick="takeHint(this)">';
    theText += hintRequest.responseText.replace(/\n/gi, '</td></tr><tr><td onclick="takeHint(this)">');
    theText += "</td></tr></table>";
    HintDiv.innerHTML = theText;
  }
}

function DefChange() {
  if (defRequest.readyState==4 && defRequest.status==200) {
    theDef.innerHTML=defRequest.responseText;
    theDef.style.visibility = "visible";
  }
}

function showMenu(num, obj) {
   if (useMenus) {
	pos = getPos(obj);
	with (theMenu) {
		style.left=1 + "px";
		innerHTML = menu[num];
		style.visibility = "visible";
		if (num > 7) {
			style.left=pos[0] + obj.offsetWidth - theMenu.offsetWidth + "px";
		} else {
			style.left=pos[0] + "px";
		}
		style.top=pos[1] + obj.offsetHeight + "px";
		if (window.innerHeight) {
			style.height = window.innerHeight - pos[1] - obj.offsetHeight - 10;
		} else {
			style.height = document.documentElement.clientHeight - pos[1] - obj.offsetHeight - 15;
		}
		style.overflow="auto";
		
	}
   }
}

function hideMenu() {
   if (useMenus) {
	theMenu.style.visibility = "hidden";
   }
}

function getPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function MenuRow(Desc, URL) {
	return "<tr onmouseout=\"hideMenu();\"><td class=\"pulldown\"><a href=\"" + URL + "\" class=\"menulink\">" + Desc + "</a></td></tr>"	
}

function ShowDef(URL) {
  if (useDefs) {
    theDef.innerHTML="";

    if (getPos(URL)[0] > 600) {
      theDef.style.left = getPos(URL)[0] - 350 + URL.offsetWidth + "px";
    } else {
      theDef.style.left = getPos(URL)[0] + "px";
    }
    theDef.style.top = getPos(URL)[1] + URL.offsetHeight + "px";

    defRequest.open("GET",URL,true);
    defRequest.onreadystatechange = DefChange;
    defRequest.send();
  }	
  return !useDefs;
}

function hideDef() {
  if (useDefs) {
    theDef.style.visibility = "hidden";
  }
}

function showHint(Key) {
  if (useHints) {
    pos = getPos(SearchBox);
    HintDiv.style.left = pos[0] - 1 + "px";
    HintDiv.style.top = pos[1] + 21 + "px";
    HintDiv.style.visibility="visible";

    if (Key == 40) {
      HintTable = document.getElementById("HintList");
      if (HintIdx > -1) {
        HintTable.rows[HintIdx].cells[0].style.backgroundColor = "#FFFFFF";
      }
      if (HintIdx < HintTable.rows.length - 1) {
        HintIdx++;
      }
      HintTable.rows[HintIdx].cells[0].style.backgroundColor = "#88CCFF";
      SearchBox.value = HintTable.rows[HintIdx].cells[0].innerHTML;
      HintDiv.scrollTop = HintTable.rows[HintIdx].offsetTop - (HintDiv.offsetHeight/2)
    } else if (Key == 38) {
      HintTable = document.getElementById("HintList");
      if (HintIdx > -1) {
        HintTable.rows[HintIdx].cells[0].style.backgroundColor = "#FFFFFF";
      }
      if (HintIdx <= 0) {
        HintDiv.style.visibility = "hidden";
        HintIdx = -1;
      } else if (HintIdx > 0) {
        HintIdx--;
        HintTable.rows[HintIdx].cells[0].style.backgroundColor = "#88CCFF";
        SearchBox.value = HintTable.rows[HintIdx].cells[0].innerHTML;
      }
      HintDiv.scrollTop = HintTable.rows[HintIdx].offsetTop - (HintDiv.offsetHeight/2)
    } else if (SearchBox.value != SearchText) {
      getHint(SearchBox.value);
      SearchText = SearchBox.value;
      HintIdx = -1;
    }
  }
}

function getHint(str) {
  if (str.length==0) { 
    HintDiv.innerHTML="";
    HintDiv.style.visibility="hidden";
    return;
  }

  hintRequest.open("GET","http://www.jewfaq.org/cgi-bin/hint.cgi?Keywords="+str,true);
  hintRequest.onreadystatechange=HintChange;
  hintRequest.send();
}

function takeHint(obj) {
  SearchBox.value = obj.innerHTML;
  document.getElementById("searchForm").submit();
  HintDiv.innerHTML = "";
  HintDiv.style.visibility = "hidden";
}
