﻿// JScript File

/*------------------------------------------------------------------------------
Creation Date   :   2008/03/18
Created By      :   Manishankar Monda;
Purpose         :   This is the javascript file used only by 'Glossary.xsl' file.

CHANGE HISTORY

Date            Modifier            Purpose
-------------------------------------------
2008/03/18      Manishankar         This page is created.
2008/03/19		Manishankar			Some elementary functions for writing some tags in the document are developed.
03/31/2008      Manishankar         The color of the alphabet separator '|' has been changed.
------------------------------------------------------------------------------*/


//This array determines whether the glossaries of corresponding characters are present or not.
var anchors = new Array(26);

//At the very begining all the array elements are assigned to 0.
for( i=0;i < 26;i++)
{ 
    anchors[i]=0;
}

//This function gets the title of the glossary content and determines whether an anchor will be placed for it or not.
//The anchors like <a name=''> </a> are written to the document by this function.
function WriteAnchor( glossary_title )
{
    first_character  = glossary_title.toUpperCase().charAt(0);
    first_character_ascii = glossary_title.toUpperCase().charCodeAt(0)-65;
    
    if (anchors[first_character_ascii] == 0) //this is the first content having title starting with 'first_character'.
    {
        //writing the anchor to the page because this content is the first content with first character = first_character in title.
        document.write ("<a name = '"+first_character+"'></a>");
        anchors[first_character_ascii] = 1;
    }
}

//this function is used for showing the glossary header. (A|B|C|D..)
function ShowGlossaryHeader()
{
    var header_string = "";
    
    for (i=0;i<25;i++)
    {
        if (anchors[i] == 1) //contents with title starting with character 25+i are present.
            //the styles are used for making the page similar to the mockup given by client.
            header_string = header_string + "<a href='#"+String.fromCharCode(i+65)+"'>"+String.fromCharCode(i+65)+"</a>"+"<span style='padding-left: 1.5px; padding-right: 1.5px; color: #333;'> | </span>";
        else
            //the styles are used for making the page similar to the mockup given by client.
            header_string = header_string +String.fromCharCode(i+65)+"<span style='padding-left: 1.5px; padding-right: 1.5px; color: #333;'> | </span>";
    }

    //this portion is for character Z. z = 25 + 65
    if (anchors[25] == 1)
        header_string = header_string + "<a href='#"+String.fromCharCode(25+65)+"'>"+String.fromCharCode(25+65)+"</a>";
    else
        header_string = header_string +String.fromCharCode(25+65);
    
    //the glossary header is written.
    document.getElementById("glossary_header").innerHTML = "<p class='alpha-list'>"+header_string + "</p>";
}

//these are the elementary functions for writing <table>, <tr>, <td> tags to the page.

//This function writes the begining tag of a table in the document.
function BeginTable ()
{
	document.write ("<table style='width: 100%'>") ;
}

//This function writes the ending tag of a table in the document.
function EndTable ()
{
	document.write ("</table>") ;
}

//This function writes the begining tag of a table-row in the document.
function BeginRow()
{
	document.write ("<tr>") ;
}

//This function writes the ending tag of a table-row in the document.
function EndRow()
{
	document.write ("</tr>") ;
}

//This function writes the Begining tag of a table-column in the document.
function BeginColumn()
{
	document.write ("<td>") ;
}

//This function writes the Ending tag of a table-column in the document.
function EndColumn()
{
	document.write ("</td>") ;
}

//This function writes the Begining tag of am anchor in the document.
//The argument is used as the link that will be put in the href attribute.
function BeginAnchor( external_link )
{
	document.write ("<a href='"+FormatExternalLink(external_link)+"' target='_blank'>") ;
}

//This function writes the Ending tag of am anchor in the document.
function EndAnchor()
{
	document.write ("</a>") ;
}

//This function is used for reformatting the url link when the url link will not contain any 'http://' or 'https://'
function FormatExternalLink(external_link)
{	
	if ( external_link.search("^http://") < 0 && external_link.search("^https://") < 0 && external_link.search("^ftp://") < 0 ) //The link doesnot begin with 'http://' or 'https://'
		external_link = "http://" + external_link ; //'http://' is added at the begining of the url.
	
	return external_link ;
}

