﻿/**
<!
(c) 2003 Chhahari.com
Original Author: Rajesh B. Shrestha, 2003
Version: 1.2
10 March 2005 Richard Wordingham: Add help bar for Tamil.
14 March 2005 Richard Wordingham: Indicate independent keys in consonant help.

Feel free to copy, modify and distribute as long as this header is kept intact.
-->
*/

var EDITOR_CONSONANTS = "consonants";
var EDITOR_PNEMONICS = "pnemonics";
var selectionRange;
var lastword ='';
var lastwordchar = '';
var word_begin = 1;

function clearHelpBars() {
	show_helpbar(EDITOR_CONSONANTS, "");
}

/**
 * Returns true if the given character is a Devnagari consonant, false otherwise.
 * 
 **/
function isDevanagariConsonant(chars) {

    if (chars > 'A' && chars < 'z')
        return false;

    // Return false if character is smaller than ka   
    if (chars.substring(chars.length-1,chars.length) < "क")
        return false;

    // Return false if character is greater than ha
    if (chars.substring(chars.length-1,chars.length) > "ह")
        return false;

    return true;
}

/**
 * Returns true if the given character is a Tamil consonant, false otherwise.
 * 
 **/
function isTamilConsonant(chars) {

    if (chars > 'A' && chars < 'z')
        return false;

    // Return false if final character is smaller than ka   
    if (chars.substring(chars.length-1,chars.length) < String.fromCharCode(0xb95))
        return false;

    // Return false if character is greater than ha
    if (chars.substring(chars.length-1,chars.length) > String.fromCharCode(0xbb9))
        return false;

// Worry about gaps later, if ever.
    return true;
}

/**
 * Displays the helpbar of the given prefix type with the given content.
 **/
function show_helpbar(prefix, content) {

	    eval(prefix).document.body.innerHTML = content;

	    //eval(prefix).document.body.style.border = "#737373 solid 1px";
	    document.all(prefix).style.display = "inline";
}

/**
 * Displays the possible vowel combinations of the given Devanagari consonant on the help bar.
 **/
function display_Devanagari_consonants_comb_helpbar (code, target) {
	
   var option = "";

   if (code == "त")
                  option = getCharLink(code, '&#2381;&#2340;');

   else if (code == "द")
                  option = getCharLink(code, '&#2381;&#2357;');

   else if (code == "र")
                  option = getCharLink(code, '&#2381;');

   else if (code == "छ")
                  option = getCharLink(code, '&#2380;&#2306;');

   else if (code == "ह")
                  option = getCharLink(code, '&#2381;&#2352;');

    var content =   "<div>"
                    + "<table width=100% height=100% border=1 cellspacing=0 cellpadding=2>"
                    + getCharLink(code, '&#2381;&#8205;')
                    + getCharLink(code, '&#2366;')
                    + getCharLink(code, '&#2367;')
                    + getCharLink(code, '&#2368;')
                    + getCharLink(code, '&#2369;')
                    + getCharLink(code, '&#2370;')
                    + getCharLink(code, '&#2375;')
                    + getCharLink(code, '&#2376;')
                    + getCharLink(code, '&#2379;')
                    + getCharLink(code, '&#2380;')
                    + getCharLink(code, '&#2381;&#8204;')
                    + getCharLink(code, '&#2371;')
                    + getCharLink(code, '&#2381;&#2352;')
                    + getCharLink(code, '&#2352;&#2381;&#8205;')
                    + getCharLink(code, '&#2352;&#2381;')
                    + getCharLink(code, '&#2305;')
                    + getCharLink(code, '&#2306;')
 	  + option
                    + "</table>"
                    + "</div>"
                    ;
    show_helpbar(EDITOR_CONSONANTS, content);
}

/**
 * Displays the possible vowel combinations of the given Tamil consonant on the help bar.
 **/
function display_Tamil_consonants_comb_helpbar (code, target) {
	
   var option = "";

// No special options as yet - ksha?
    var content =   "<div>"
                    + "<table width=100% height=100% border=1 cellspacing=0 cellpadding=2>"
                    + getCharLink(code, '&#xbcd;')
                    + getCharLink(code, '&#xbbe;')
                    + getCharLink(code, '&#xbbf;')
                    + getCharLink(code, '&#xbc0;')
                    + getCharLink(code, '&#xbc1;')
                    + getCharLink(code, '&#xbc2;')
                    + getCharLink(code, '&#xbc6;')
                    + getCharLink(code, '&#xbc7;')
                    + getCharLink(code, '&#xbc8;')
                    + getCharLink(code, '&#xbca;')
                    + getCharLink(code, '&#xbcb;')
                    + getCharLink(code, '&#xbcc;')
 	  + option
                    + "</table>"
                    + "</div>"
                    ;
    show_helpbar(EDITOR_CONSONANTS, content);
}

/**
 * Returns HTML as content for the helpbar for the given code and character.
 **/
function getCharLink (code, chars) {

    var str = "<a href='javascript:parent.addChar(\"" + chars +
                  "\")' style=\"text-decoration:none;color:black;\">" +
                 "<td align='center' style='border:1px solid gray' " +
                 "onmouseover='this.style.border=\"1px solid red\";window.status=\"\";return true;' " +
                 "onmouseout='this.style.border=\"1px solid gray\"' style='cursor:hand'>" + code + chars +
                 "<br/><span style=\"font-size: 80%\">+" + chars + "</span></td></a>";
    return str;

}

function display_consonants_comb_helpbar (code, target) {
  if (isDevanagariConsonant(code)) {
    display_Devanagari_consonants_comb_helpbar(code, target);
  } else if (isTamilConsonant(code)) {
    display_Tamil_consonants_comb_helpbar(code, target);
  }
}
