
function GetTOC()
{
	var strBookMark;
	var strTitle;
	var strURL;
	var nTotal = g_rgTOC.length;
	var nCtr;
	var nCurrentBookMarkInCurrentURL;
	var nCurrentURLInCurrentBookMark;

	var nSubTopics;
	var n;
	var strSubTopic;
	var strSubTopicTitle;
	var strSubTopicURL;
	
	var strCurrentURL = document.location.pathname;

//	Could not find a case-insensitive version of indexOf(). So converting everything to lowercase.
	strCurrentURL = strCurrentURL.toLowerCase();
	
//	document.write (strCurrentURL);
//	document.write (nTotal);

//	strCurrentURL = "/Living/Diet/";

	document.write ("<table width=100% border=0 cellpadding=0 cellspacing=0>");
	document.write ("<tr bgcolor='#ccecff'><td colspan='2'>&nbsp;</td></tr>");

	for(nCtr = 0; nCtr < nTotal; nCtr++)
	{
		strBookMark = g_rgTOC[nCtr][0];

		strTitle = GetTitle(strBookMark);
		strURL = GetURL(strBookMark);
		strURL = strURL.toLowerCase()
		
		// see if this URL is a part of the current URL
		nCurrentBookMarkInCurrentURL = strCurrentURL.indexOf(strURL);
		
		// and see if the current URL is a part of this URL
		nCurrentURLInCurrentBookMark = strURL.indexOf(strCurrentURL)

		
		// if the two URLs are completely unrelated, we simply write down this URL as a top-level topic
		if (nCurrentBookMarkInCurrentURL == -1 && nCurrentURLInCurrentBookMark == -1)
		{
			document.write("<tr bgcolor='#EFEFEF'>");
          	document.write("	<td width='22%' height='20' align='center'><img src='/Images/bullet_rnb.gif' width='20' height='14'></td>");
          	document.write("    <td width='78%' height='20'>");
			document.write("		<a href='" + strURL + "'>" + strTitle + "</a><br>");
			document.write("	</td>");
			document.write("</tr>");
		}
			
		
		// if either of them is a part of the other, we gotta drill down
		if (nCurrentBookMarkInCurrentURL != -1 || nCurrentURLInCurrentBookMark != -1)
		{
			document.write("<tr>");
			document.write("	<td width='22%' height='20' align='center' bgcolor='#FFFCE8'>");
			document.write("		<img src='/images/bullet_rnb.gif' width='20' height='14'></td>");
			document.write("	<td width='78%' height='20' bgcolor='#FFFCE8'><b>");

			// check if the top-level URL is same
			if (nCurrentBookMarkInCurrentURL == 0 && nCurrentURLInCurrentBookMark == 0)
				document.write(strTitle);
			else
				document.write("<a href='" + strURL + "'>" + strTitle + "</a><br>");


			document.write("	</b></td>");
			document.write("</tr>");

			
			
			// now iterate within this section
			nSubTopics = g_rgTOC[nCtr].length;
			if(nSubTopics > 1)
			{
				//If subtopics present, a little space required ABOVE the inner listing [Sud]
				document.write("<tr>");
				document.write("<td width='100%' colspan=2><img src='/images/trans.gif' height='5'></td>");
				document.write("</tr>");	
			}
			for (n = 1; n < nSubTopics; n++)
			{
				strSubTopic			= g_rgTOC[nCtr][n];
				strSubTopicTitle	= GetTitle(strSubTopic);
				strSubTopicURL		= GetURL(strSubTopic);
				strSubTopicURL		= strSubTopicURL.toLowerCase();
				
				document.write("<tr>");
				document.write("<td width='22%' height=20 align=right valign=top><img src='/images/bullet.gif' width='8' height='12'></td>");
				document.write("<td width='78%' height=20>");
				//document.write("	<img src='/images/bullet.gif' width='8' height='12'>");

				// if this URL is the same as the current URL, we wont hyperlink it
				if (strSubTopicURL == strCurrentURL)
					document.write ("<b>" + strSubTopicTitle + "</b>");
				else
					document.write("<a href='" + strSubTopicURL + "'>" + strSubTopicTitle + "</a>");
				
				document.write("</td>");
				document.write("</tr>");

			} // end of inner for
			
			if(nSubTopics > 1)
			{
				//If subtopics present, a little space required Below the inner listing [Sud]
				document.write("<tr>");
				document.write("<td width='100%' colspan=2><img src='/images/trans.gif' height='5'></td>");
				document.write("</tr>");	
			}
		} // end of if
	} // end of outer for
	document.write ("<tr bgcolor='#ccecff'><td colspan='2' height=5 align='center'>");
	document.write ("	<img src='/images/trans.gif' width=1 height=5></td></tr>");
	document.write ("</table>");
} // end of GetTOC()

function GetTitle(bookMark)
{
	// find where | occurs in bookMark - all chard preceding it constitute the title
	var nPos = bookMark.indexOf("|");
	return bookMark.substr(0, nPos);
}


function GetURL(bookMark)
{
	// find where | occurs in bookMark - all chars succeedubg it constitute the URL
	var nPos = bookMark.indexOf("|");
	return bookMark.substr(nPos+1, bookMark.length-nPos);
}





function InitTOC()
{
	g_rgTOC[0]		= new Array(7);
	g_rgTOC[0][0]	= "About Diabetes"			+ "|" + "/AboutDiabetes/";
	g_rgTOC[0][1]	= "Definition"				+ "|" + "/AboutDiabetes/Definition.asp";
	g_rgTOC[0][2]	= "Symptoms"				+ "|" + "/AboutDiabetes/Symptoms.asp";
	g_rgTOC[0][3]	= "Types of Diabetes"		+ "|" + "/AboutDiabetes/Types.asp";
	g_rgTOC[0][4]	= "Occurrence"				+ "|" + "/AboutDiabetes/Occurrence.asp";
	g_rgTOC[0][5]	= "Diagnosis & Monitoring"	+ "|" + "/AboutDiabetes/Diagnosis.asp";
	g_rgTOC[0][6]	= "Complications"			+ "|" + "/AboutDiabetes/Complications.asp";


	g_rgTOC[1]		= new Array(3);
	g_rgTOC[1][0]	= "Therapies"		+ "|" + "/Therapies/";
	g_rgTOC[1][1]	= "Oral Medication"	+ "|" + "/Therapies/OralMed.asp";
	g_rgTOC[1][2]	= "Insulin"			+ "|" + "/Therapies/Insulin.asp";


	g_rgTOC[2]		= new Array(10);
	g_rgTOC[2][0]	= "Living with Diabetes"				+ "|" + "/Living/";
	g_rgTOC[2][1]	= "Taking up the Diabetes Challenge"	+ "|" + "/Living/Challenges.asp";
	g_rgTOC[2][2]	= "Managing Blood Sugar"				+ "|" + "/Living/BloodSugar.asp";
	g_rgTOC[2][3]	= "Preventing Complications"			+ "|" + "/Living/Complications.asp";
	g_rgTOC[2][4]	= "Diet Planning"						+ "|" + "/Living/Diet/";
	g_rgTOC[2][5]	= "Exercise Planning"					+ "|" + "/Living/Exercise.asp";
	g_rgTOC[2][6]	= "Travel Tips"							+ "|" + "/Living/Travel.asp";
	g_rgTOC[2][7]	= "Diabetes Checklist"					+ "|" + "/Living/Checklist.asp";
	g_rgTOC[2][8]	= "Recipes"								+ "|" + "/Living/Recipes/";
	g_rgTOC[2][9]	= "Share your Experiences"				+ "|" + "/Living/Experiences/";


	g_rgTOC[3]		= new Array(1);
	g_rgTOC[3][0]	= "For Family Members"	+ "|" + "/Family/";


	g_rgTOC[4]		= new Array(1);
	g_rgTOC[4][0]	= "Scientific Advances"	+ "|" + "/SciAdvances/";


	g_rgTOC[5]		= new Array(4);
	g_rgTOC[5][0]	= "Ranbaxy Brands"	+ "|" + "/Brands/";
	g_rgTOC[5][1]	= "Glimpid"			+ "|" + "/Brands/Glimpid.asp";
	g_rgTOC[5][2]	= "Pioglar"			+ "|" + "/Brands/Pioglar.asp";
	g_rgTOC[5][3]	= "Regan"			+ "|" + "/Brands/Regan.asp";
}
