var strNav = '';
var imgPath = "";
var imgCount = 1;
var lastTitle = false;
var menuwidth=160
var offsetleft=0
var offsettop=30

var ns4=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0

var l_url_next_chap_url;
var l_url_prev_chap_url; 


/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
//    highlightStartTag = "<font style='color:blue; background-color:#fddf70'>";
    highlightStartTag = "<font style='color:#003399;border-bottom: 2px dotted;cursor:pointer;display:inline;text-decoration:none;'>";
    highlightEndTag = "</font>";
    var spce = new RegExp(/[\s\f\n\r\t\v\u00A0\u2028\u2029<&]/);
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (were not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
	   // alert('before char is' + bodyText.charAt(i-1));
	    //alert('after char is' + bodyText.charAt((i)+searchTerm.length));
		//alert(bodyText.substring(i,1));
	    if( ( bodyText.charAt(i-1)== ' ') && (spce.test(bodyText.charAt(i+searchTerm.length)))){
		//('this is the word ' +searchTerm);
	   //('before char is' + bodyText.charCodeAt(i-1));
	    //('after char is' + bodyText.charCodeAt((i)+searchTerm.length));
newText += bodyText.substring(0, i) + highlightStartTag + '<a id="'+i+'one"  onmouseover=javascript:JT_show(\'http://www.sriramchandra.org/glossary/glossary.asp?alph='+searchTerm+'\',\''+i+'one\',\'GLOSSARY\'); onmouseout=javascript:JT_hide();>'+ bodyText.substr(i, searchTerm.length) + '</a>' + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
		}
		else{
		//('this is not a word' + searchTerm);
	   //('before char is' + bodyText.charCodeAt(i-1));
	   //('after char is' + bodyText.charCodeAt((i)+searchTerm.length))
		   ;
		}
		
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
	//alert('got in here too' + searchText);
		      	// if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
  //alert('i am in');
  // This function prompts the user for any words that should
  // be highlighted on this web page
  if (!defaultText) {
    defaultText = "";
  }
  
  // we can optionally use our own highlight tag values
  if ((!textColor) || (!bgColor)) {
    highlightStartTag = "";
    highlightEndTag = "";
  } else {
    highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
    highlightEndTag = "</font>";
  }
  
  if (treatAsPhrase) {
    promptText = "Please enter the phrase you'd like to search for:";
  } else {
    promptText = "Please enter the words you'd like to search for, separated by spaces:";
  }
  
  searchText = prompt(promptText, defaultText);

  if (!searchText)  {
    alert("No search terms were entered. Exiting function.");
    return false;
  }

	
	


  
 // return highlightSearchTerms("Rajayoga Patanjali Sutras", false, true, highlightStartTag, highlightEndTag);
}


function runGo(){
return highlightSearchTerms("ABHYASA ABHYASI ABHAVA ABHAYA ABSOLUTE ABUDIYAT ABDAL ACHARA ACHARYA ACHIT AADHYATMIKA AADI-BHAUTIKA AADI-DAIVIKA AAGAMA AGNI AHAM AHAMKARA AITAQAD AJAPA AJNA AJNANADASA AISVARYA AKINCANA AKSHOBHA AMANSKA ALAMKABIR ALMIGHTY AMRTATVAM ANAHATA ANANTA ANAHAD ANTAR-YAAMI APARIGRAHA APTA ASAN ASANA ASBAT ASHRAMA ATMAN AUM OM AVADHUTA AVYAKTAGATI BARZAKH BAQA BHANWAR BEEJ-DAGDH BHAGAVAN BHAGAVATA BHAGYA BHAJANA BHAKTA BHAKTI BHANDAR BHAROSA BHAVANA BHOGA BHUMA BHUTADI BRAHMACHARYA BRAHM BRAHMAN BRAHMAND BRAHMAGATI BUDDHI CHAITANYA CHAKRA CHAKSHUS CHARYA CHANDAS CHIT CHITTA CHITLAKE DARSANA DAM DAMA DASA DASYA DAYA DHARANA DHI DEEKSHA DIVYA-CHAKSHUS DRSTI DVANDVA EHSAAN EKAGRA EKAM EKATVAM EKAYANA FANA FANA-E-MULTAQ GAIRAT GANGA-JAMUNI GHOUSE GHOUSE-UL-AZAM GITA GNANI GRANTHI GRHASTHA GUNA GURU GURUPASHU HANOPAYA HARDA HAMAHANGI HATHAYOGA HEYA HIMSA HLADA HRDAYA IBD IDA INDRIYA ISVARA ISA JADA JAGRAT JARA JAPA JASB JAZB JIVA JIVANMOKSHA JNANA JYOTI JYOTISMATI KAIVALYA KALA KAALA KARMA KARMASAYA KARMAYOGA KARANA SARIRA KARUNA KASHAF KHALAA KHULOOS KHUDA KOSA KRIYA KSHIPTA KSHOBH KUBRA KUNDALINI LAYA LILA LINGASARIRA LIMELADUNNI LOKA MA-KAARA MADHUMATI MALA MAANA MANAS MAYA MAAYA MAHAMAYA MAHAPRALAYA MAHATMA MAQBOOL MOKSHA MOODHA MUKTI MUMUKSHU NAADA NAADI NAADISUDDHI NAAYA NAAYAKA NIRBIJA NIRGUNA NIRVANA NIRVIKALPAKA NIVRTTI NIYAMA NYAASA NYAYA OMKARA PANCHAKALANIYAMA PANCHAGNIVIDYA PARA PARABRAHMAND PHANA-YE-PHANA PIND-DESH PRADHANA PRAJNA PRKRTI PRAKRTI PRAKRUTILAYA PRANA PRAANA PRALAYA PRANAHUTI PRANAYAMA PRAPATTI PRAPANNA PRASADA PRATEEKA PRATYAHARA PRATYAK PRAVRUTTI PUJA PURUSHA POORNA PURUSHA PURUSHARTHA QUDSA-ALAME-QUDSA QUTUB QUTUB-UL-AQTAB RAAGA RAJAYOGA RAJAS RASA RINA RTA RTAMBHARA RUPA SABDA SABR SADHANA SADGURU SAGUNA SAHAJA SAHAJMARG SAHAJIYA SAKTI SAKSHAAT-KARA SAALOKYA SALIK SAMADHI SAMAANYA SAMADHAN SAMASAM SAMAVASTHA SAMPATTI SAAMIPYA SAMSARA SAMSKARA SAMYAMA SAMVEGA SANGHA SANTI SANDHYA SANKIRTAN SANKIRTANA SARALATA SARUPYA SASMITA-SAMADHI SAT SATPAD SAAYUJYA SATPAD SATSANGH SHAB-E-QADR SHAGALRABTA SANTI SHANTI SAJJADA-NASHIN SHAT-SAMPATTHI SHAM SHRADDHA SHEELA SHUKR SIDDHI SKANDHA SMRTI SOHBATI SUDARSHANCHAKRA SUKSHMA SUKSHMASARIRA SURAT SULOOK SUSUMNA SUSUPTI SVADHISTHANA SVAPNA SVARG TADAP TALAB TAM TAMAS TANMATRAAS TANMAYA TANTRA TAT TATVA TAPAS TAARAKAJNANA TITIKSHA TOSHA UJJVALA UJJIVANA UNMADA UPAMAANA UPANISAD UPAAYA UPASANA UPRAM UPARATI ULIA UQBA VAIKAARIKA VAINASIKA VAIRAGYA VALAYATA VEDA VIDEHALAYA VIDYUT VIJNANA VIKALPA VIKSIPTA VINIYOGA VIPARYAYA VIRAAT VIRYA VISESA VISPHULINGA VISUDDHA CHAKRA VIVARTA VIVEKA WASL YAMA YANTRA YAUGIKA YOGA YOGI YOGAJA ZAAT", false, true, highlightStartTag, highlightEndTag);
}


//Ravi added for floating
function startMenu(){
if (!document.layers)
document.write('<div id="object1" style="position:absolute">')


<!--EDIT BELOW CODE TO YOUR OWN MENU-->
}
function endMenu(){
<!--END OF EDIT-->


document.write('</div>')
}


function openMenu(){
	strNav = '<ul>';

}

function closeMenu(){

strNav += '</ul>';
//	document.write(strNav);
document.getElementById('menudiv').innerHTML=strNav;
}

function addMenuHead(strHead,strLink){
	strNav += '<li><b><A href='+ strLink + ' style="text-decoration: none">'+ strHead +'</A></b></li>' ;
}

function addMainTitle(mtTitle,mlLink){
	
	strNav += '<li><A href="'+ mlLink +'" class="navLink1" style="text-decoration: none">' + mtTitle + '</A></li>';

	imgCount++;
}

function addSubTitle(stTitle,slLink,lastTitle){

	strNav += '<li><A href="'+ slLink +'" class="navLink1" style="text-decoration: none">' + stTitle + '</A></li>';

	imgCount++;
}

function openSubMenu(){
	lastTitle = false;
	strNav +='<ul>';
					
}

function closeSubMenu(){

strNav += '</ul>';
}



function getPrevNextChapter()
{
var txt=parent.location.href
var x=txt.indexOf("=")
if (x==-1) 
  {
     x= txt.lastIndexOf("/")
  }

l_url = txt.substr(x+1);  //BP1chap_2.htm
l_url_bef_dot =  l_url.split(".")[0]; // BP1chap_2
l_url_aft_dot =  l_url.split(".")[1]; //htm
l_url_curr_chap_no_bef = l_url_bef_dot.split("_")[0]; //BP1chap
l_url_curr_chap_no= l_url_bef_dot.split("_")[1]; //2


l_url_next_chap_url = l_url_curr_chap_no_bef + "_" + eval(eval(l_url_curr_chap_no) +1) +".htm";
l_url_prev_chap_url = l_url_curr_chap_no_bef + "_" + eval(eval(l_url_curr_chap_no) -1) +".htm"; 
l_url_toc_url = l_url_curr_chap_no_bef + "_" + "0.htm"; 

//document.write('<span style="color:red;"> Next Chapter = ' + l_url_next_chap_url + '</span> <br>');
//document.write('<span style="color:red;"> Prev Chapter = ' + l_url_prev_chap_url + '</span>');
}
