﻿<!--
/******************************************
    This file is part of Bangla Unicode Web Tools.

    Bangla Unicode Web Tools is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Bangla Unicode Web Tools is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bangla Unicode Web Tools; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA







	Author: S M Mahbub Murshed
	Copyright: S M Mahbub Murshed
	Email: udvranto@yahoo.com
	Version: 1.3.4
	Date: September 15, 2006, 11:38 GMT-07(AZ)
******************************************/



var ID="EDT"; // the textbox id to apply the layout to
var ConvertFrom = "bijoy" // Options are, "bijoy", "somewherein", "boisakhi"
var resource = bn_resource;


/******************************************
	Changes resource strings

	Coded by : S M Mahbub Murshed
	Date: November 18, 2006
******************************************/
function SetResourceStrings()
{
	for (var resid in resource)
	{
		var resbyid = document.getElementById(resid);
		if(resbyid.type=="button")
			resbyid.value = resource[resid];
		else
			resbyid.innerHTML = resource[resid];
	}
}

/******************************************
	Toggle resource

	Coded by : S M Mahbub Murshed
	Date: November 18, 2006
******************************************/
function ToggleLanguage(lang)
{
	var resbyid;
	if(lang==1)
	{
		resource = en_resource;
		resbyid = document.getElementById("english_res");
		resbyid.innerHTML = "English";
		resbyid = document.getElementById("bangla_res");
		resbyid.innerHTML = "<a href=\"javascript:ToggleLanguage(2);\">বাংলা</a>";
	}
	else if(lang==2)
	{
		resource = bn_resource;
		resbyid = document.getElementById("english_res");
		resbyid.innerHTML = "<a href=\"javascript:ToggleLanguage(1);\">English</a>";
		resbyid = document.getElementById("bangla_res");
		resbyid.innerHTML = "বাংলা";
	}

	SetResourceStrings();
}


/******************************************
	Changes keyboard layout status

	\param ev the event

	Coded by : S M Mahbub Murshed
	Date: August 30, 2006
******************************************/
function ChangeKeyboarLayoutStatus()
{
	// var keyboard_ley = document.getElementById("keyboard");
	var field = document.getElementsByName('KeyboardLayoutOption');

	if(KeyBoardLayout==2)
		{ // keyboard_ley.innerHTML = "বর্তমান লেখন পদ্ধতি: <b>ইংরেজী</b>";
		field[0].checked = true; }
	else if(KeyBoardLayout==3)
		{ // keyboard_ley.innerHTML = "বর্তমান লেখন পদ্ধতি: <b>বিজয় বাংলা</b>";
		field[1].checked = true; }
	
}

/******************************************
	Changes converter status

	\param ev the event

	Coded by : S M Mahbub Murshed
	Date: October 15, 2006
******************************************/
function ChangeConverterStatus()
{
	var field = document.getElementsByName('ConversionOption');
	
	// Options are, "bijoy", "somewherein", "boisakhi"
	if(ConvertFrom=="bijoy")
		{ field[0].checked = true; }
	else if(ConvertFrom=="somewherein")
		{ field[1].checked = true; }
	else if(ConvertFrom=="boisakhi")
		{ field[2].checked = true; }
}





/******************************************
	Handles keyboard option button click

	\param event the event

	Coded by : S M Mahbub Murshed
	Date: August 30, 2006
******************************************/
function KeyboardLayoutOptionClick(event)
{
	var field = document.getElementsByName('KeyboardLayoutOption');

	for (var counter = 0; counter <2; counter++)
	{
		if (field[counter].checked)
		{
			KeyBoardLayout = counter+2; 
			ChangeKeyboarLayoutStatus();
			var myFld = document.getElementById(ID);
			myFld.focus();
			break;
		}
	}
} // end function KeyboardLayoutOptionClick







/******************************************
	Converts

	\param id the id of the html element

	Coded by : S M Mahbub Murshed
	Date: September 05, 2006
******************************************/
function ConvertFromTextArea(idcvt)
{
	var str = document.getElementById(idcvt).value;
	str = ConvertToUnicode(ConvertFrom, str);
	Insert(document.getElementById(ID), str);
} // end function ConvertFromTextArea


/******************************************
	Converts back to ASCII

	\param id the id of the html element

	Coded by : S M Mahbub Murshed
	Date: September 05, 2006
******************************************/
function ConvertToTextArea(idcvt)
{
	var str = document.getElementById(ID).value;
	str = ConvertToASCII(ConvertFrom, str);
	Insert(document.getElementById(idcvt), str);	
} // end function ConvertToTextArea



/******************************************
	Clears text area

	\param id the id of the html element

	Coded by : S M Mahbub Murshed
	Date: September 05, 2006
******************************************/
function ClearTextArea(idtxt)
{
	var elem = document.getElementById(idtxt);
	elem.value = "";
	elem.focus();
} // end function ClearTextArea



/******************************************
	ConvertOptionChange

	Coded by : S M Mahbub Murshed
	Date: September 05, 2006
******************************************/
function ChangeConvertOptionStatus()
{
	var field = document.getElementsByName('ConversionOption');
	var convertarea = document.getElementById('CONVERTEDT');

	if(ConvertFrom == "bijoy")
	{
		convertarea.style.fontFamily = "SutonnyMJ";
		convertarea.style.fontSize = "12pt";
		convertarea.style.width = 400;
		// convertarea.cols = 80;

		field[0].checked = true;
	}
	else if(ConvertFrom == "somewherein")
	{
		convertarea.style.fontFamily = "SushreeMJ";
		convertarea.style.fontSize = "12pt";
		convertarea.style.width = 400;
		field[1].checked = true;
	}
	else if(ConvertFrom == "boisakhi")
	{
		convertarea.style.fontFamily = "Boishakhi";
		convertarea.style.fontSize = "10pt";
		convertarea.style.width = 400;
		field[2].checked = true;
	}
	
} // end function ChangeConvertOptionStatus




/******************************************
	ConvertOptionChange

	\param event the event

	Coded by : S M Mahbub Murshed
	Date: September 05, 2006
******************************************/
function ConvertOptionChange(event)
{
	var field = document.getElementsByName('ConversionOption');

	for (var counter = 0; counter < field.length; counter++)
	{
		if (field[counter].checked)
		{
			if(counter == 0)
				ConvertFrom = "bijoy";
			else if(counter == 1)
				ConvertFrom = "somewherein";
			else if(counter == 2)
				ConvertFrom = "boisakhi";
			break;
		}
	}
	ChangeConvertOptionStatus();
}

/******************************************
	On page load

	Coded by : S M Mahbub Murshed
	Date: September 12, 2006
******************************************/
function OnPageLoad()
{
	SetResourceStrings();
	ChangeKeyboarLayoutStatus();
	ChangeConverterStatus();

	var myFld = document.getElementById(ID);
	var unicodefontLabel = document.getElementById("unicodefont");

	if(IE)
	{
		unicodefontLabel.innerHTML = "If you can't see Bangla, please download Unicode Bangla Font <a href=SutonnyBanglaOMJ.ttf>from here</a>"
		myFld.style.fontFamily = "SutonnyBanglaOMJ";
	}
	else
	{
		unicodefontLabel.innerHTML = "If you can't see Bangla, please download Unicode Bangla Font <a href=SolaimanLipi_29-05-06.ttf>from here</a>"
		myFld.style.fontFamily = "SolaimanLipi";

/*		unicodefontLabel.innerHTML = "If you can't see Bangla, please download Unicode Bangla Font <a href=SutonnyBanglaOMJ.ttf>from here</a>"
		myFld.style.fontFamily = "SutonnyBanglaOMJ"; */
	}
	myFld.style.width = 400;
	var convertarea = document.getElementById('CONVERTEDT');
	convertarea.style.width = 400;
}
/******************************************

    This file is part of Bangla Unicode Web Tools.

    Bangla Unicode Web Tools is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Bangla Unicode Web Tools is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bangla Unicode Web Tools; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


	Contains common utilities to:
	1. Insert and Remove character into
	   text area.
	2. Hide and show any div element
	3. Determine bangla character category
	4. Find equivalent kar to sorborno mapping

	Author: S M Mahbub Murshed
	Copyright: S M Mahbub Murshed
	Email: udvranto@yahoo.com
	Version: 1.2.0
	Date: September 06, 2006, XX:XX GMT
*******************************************/




/******************************************
******************************************
      General utility to insert
      text into the cursor position
******************************************
*******************************************/


/******************************************
	Function to insert a character into the text area.

	\param text The string or character to insert

	Coded by : Arup Kamal
	Date: August 26, 2006 (approx)
*******************************************/
function Insert(field, text)
{
	if (document.selection) 
	{
		field.focus();
		sel = document.selection.createRange();
		sel.text = text;
		sel.collapse(true);
		sel.select();
	}

	else if (field.selectionStart || field.selectionStart == '0')
	{
		
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		var scrollTop = field.scrollTop;
		startPos = (startPos == -1 ? field.value.length : startPos );
		field.value = field.value.substring(0, startPos)
			+ text
			+ field.value.substring(endPos, field.value.length);
		field.focus();
		field.selectionStart = startPos + text.length;
		field.selectionEnd = startPos + text.length;
		field.scrollTop = scrollTop;
	}
	else
	{
		var scrollTop = field.scrollTop;
		field.value += value;
		field.focus();
		field.scrollTop = scrollTop;
	}

} // end function Insert





/******************************************
	Function to delete a set of 
	character and insert a set of characters
	into the text area.

	\param value The string or character to insert
	\param len	Number of characters to delete from current cursor position

	Coded by : Arup Kamal
	Date: August 26, 2006 (approx)
*******************************************/
function RemoveNInsert(field, value, len) 
{
	if (document.selection) 
	{
		field.focus();
		sel = document.selection.createRange();
		if (field.value.length >= len)
			{ 			
			sel.moveStart('character', -1*(len));   
			}
		sel.text = value;
		sel.collapse(true);
		sel.select();
		}

	else if (field.selectionStart || field.selectionStart == 0) {
		field.focus();
		var startPos = field.selectionStart-len;
		var endPos = field.selectionEnd;
		var scrollTop = field.scrollTop;
		startPos = (startPos == -1 ? field.value.length : startPos );
		field.value = field.value.substring(0, startPos)
		+ value
		+ field.value.substring(endPos, field.value.length);
		field.focus();
		field.selectionStart = startPos + value.length;
		field.selectionEnd = startPos + value.length;
		field.scrollTop = scrollTop;
	} else {
		var scrollTop = field.scrollTop;
		field.value += value;
		field.focus();
		field.scrollTop = scrollTop;
	}

} // end function RemoveNInsert





/******************************************
	Function to detect caps lock
	Returns true if caps lock is on

	\param e The keypress event

	Coded by : http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html
	Date: Sepetember 11, 2006
*******************************************/
function capsDetect( e )
{
	if( !e ) e = window.event;
	if( !e ) return false;
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	return ( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}




/******************************************
      General utility to show
      or hide a div element
*******************************************/




/******************************************
	Hides an html div element

	\param id the id of the html element

	Coded by : (Lost the URL where I obtained it from)
	Date: September 05, 2006
*******************************************/
function HideDIV(id)
{
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
} // end function hidediv





/******************************************
	Shows an html div element

	\param id the id of the html element

	Coded by : (Lost the URL where I obtained it from)
	Date: September 05, 2006
*******************************************/
function ShowDIV(id)
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
} // end function showdiv





/******************************************
*******************************************
      Bangla unicode utility
*******************************************
*******************************************/





/******************************************
	Determines whether the unicode
	character is an bangla digit
	character or not.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaDigit(CUni)
{
	if(CUni=='০' || CUni=='১'
	|| CUni=='২' || CUni=='৩'
	|| CUni=='৪' || CUni=='৫'
	|| CUni=='৬' || CUni=='৭'
	|| CUni=='৮' || CUni=='৯')
		return true;

	return false;
} // end function IsBanglaDigit







/******************************************
	Determines whether the unicode
	character is a bangla pre kar
	character or not. Pre kar
	character are appended BEFORE
	a banjonborno or juktakhor character
	after rendering.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaPreKar(CUni)
{
	if(CUni=='ি' || CUni=='ৈ' 
	|| CUni=='ে' )
		return true;
	
	return false;
} // end function IsBanglaPreKar





/******************************************
	Determines whether the unicode
	character is a bangla post kar
	character or not. Post kar
	character are appended AFTER
	a banjonborno or juktakhor character
	after rendering.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaPostKar(CUni)
{
	if(CUni == 'া' || CUni=='ো'
	|| CUni=='ৌ' || CUni=='ৗ' || CUni=='ু'
	|| CUni=='ূ' || CUni=='ী'
	|| CUni=='ৃ')
		return true;
	return false;
} // end function IsBanglaPostKar




/******************************************
	Determines whether the unicode
	character is a bangla kar
	character or not. Its a super
	set or Pre and Post kars.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaKar(CUni)
{
	if(IsBanglaPreKar(CUni) || IsBanglaPostKar(CUni) )
		return true;
	return false;

} // end function IsBanglaKar






/******************************************
	Determines whether the unicode
	character is a bangla banjonborno
	character or not.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaBanjonborno(CUni)
{
	if(CUni=='ক' || CUni=='খ' || CUni=='গ' || CUni=='ঘ' || CUni=='ঙ' 
        || CUni=='চ' || CUni=='ছ' || CUni=='জ' || CUni=='ঝ' || CUni=='ঞ' 
        || CUni=='ট' || CUni=='ঠ' || CUni=='ড' || CUni=='ঢ' || CUni=='ণ'
        || CUni=='ত' || CUni=='থ' || CUni=='দ' || CUni=='ধ' || CUni=='ন'
        || CUni=='প' || CUni=='ফ' || CUni=='ব' || CUni=='ভ' || CUni=='ম'
        || CUni=='শ' || CUni=='ষ' || CUni=='স' || CUni=='হ' 
	|| CUni=='য' || CUni=='র' || CUni=='ল' || CUni=='য়' 
	|| CUni=='ং' || CUni=='ঃ' || CUni=='ঁ'
	|| CUni=='ৎ')
		return true;

	return false;
} // end function IsBanglaBanjonborno




/******************************************
	Determines whether the unicode
	character is a bangla soroborno
	character or not.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaSoroborno(CUni)
{
	if(CUni == 'অ' || CUni=='আ'
	|| CUni=='ই' || CUni=='ঈ'
	|| CUni=='উ' || CUni=='ঊ'
	|| CUni=='ঋ' || CUni=='ঌ'
	|| CUni=='এ' || CUni=='ঐ' 
	|| CUni=='ও' || CUni=='ঔ' )
		return true;

	return false;
} // end function IsBanglaSoroborno





/******************************************
	Determines whether the unicode
	character is a bangla nukta
	character or not.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaNukta(CUni)
{
	if(CUni=='ং' || CUni=='ঃ' || CUni=='ঁ')
		return true;

	return false;

} // end function IsBanglaNukta






/******************************************
	Determines whether the unicode
	character is a bangla ja fola or ra fola
	character or not.

	\param CUni The Unicode string

	Coded by : S M Mahbub Murshed
	Date: August 30, 2006
*******************************************/
function IsBanglaFola(CUni)
{
	if(CUni=="্য" || CUni=="্র")
		return true;

	return false;
} // end function IsBanglaFola






/******************************************
	Determines whether the unicode
	character is a bangla halant
	character or not.

	\param CUni The Unicode character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsBanglaHalant(CUni)
{
	if(CUni=='্')
		return true;

	return false;
} // end function IsBanglaHalant




/******************************************
	Determines whether the
	character is a space
	character or not.

	\param C The character

	Coded by : S M Mahbub Murshed
	Date: August 28, 2006
*******************************************/
function IsSpace(C)
{
	if( C==' ' ||  C=='\t' || C=='\n'
	||  C=='\r')
		return true;

	return false;
} // end function IsSpace



/******************************************
	Maps an unicode character to its
	equivalent soroborno

	\param CUni The Unicode kar character to map with

	Coded by : S M Mahbub Murshed
	Date: August 30, 2006
*******************************************/
function MapKarToSorborno(CUni)
{
	var CSorborno = CUni;
	if(CUni=='া')
		CSorborno = 'আ';
	else if(CUni=='ি')
		CSorborno = 'ই';
	else if(CUni=='ী')
		CSorborno = 'ঈ';
	else if(CUni=='ু')
		CSorborno = 'উ';
	else if(CUni=='ূ')
		CSorborno = 'ঊ';
	else if(CUni=='ৃ')
		CSorborno = 'ঋ';
	else if(CUni=='ে')
		CSorborno = 'এ';
	else if(CUni=='ৈ')
		CSorborno = 'ঐ';
	else if(CUni=='ো')
		CSorborno = 'ও';
	else if(CUni=="ো")
		CSorborno = 'ও';
	else if(CUni=='ৌ')
		CSorborno = 'ঔ';
	else if(CUni=="ৌ")
		CSorborno = 'ঔ';


	return CSorborno;
} // end function MapKarToSorborno





/******************************************
	Maps an unicode soroborono to its
	equivalent kar

	\param CUni The Unicode sorborno character to map with

	Coded by : S M Mahbub Murshed
	Date: August 30, 2006
*******************************************/
function MapSorbornoToKar(CUni)
{
	var CKar = CUni;
	if(CUni=='আ')
		CKar = 'া';
	else if(CUni=='ই')
		CKar = 'ি';
	else if(CUni=='ঈ')
		CKar = 'ী';
	else if(CUni=='উ')
		CKar = 'ু';
	else if(CUni=='ঊ')
		CKar = 'ূ';
	else if(CUni=='ঋ')
		CKar = 'ৃ';
	else if(CUni=='এ')
		CKar = 'ে';
	else if(CUni=='ঐ')
		CKar = 'ৈ';
	else if(CUni=='ও')
		CKar = 'ো';
	else if(CUni=='ঔ')
		CKar = 'ৌ';

	return CKar;
} // end function MapSorbornoToKar


function expandit(objname,image){
    var folder='';
    curobj = objname + 'info';
    imgobj = objname + 'img';
    folder = getObjectRef(curobj).style;
	if (folder.display=="none") {
        folder.display="";
       
    } else {
        folder.display="none"
       
    }
}
function getObjectRef(n, d) {

  

  var p,i,x;  
  
  if(!d) 
  	d=document; 
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
	n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) 
  	x=d.all[n]; 
  
  for (i=0;!x&&i<d.forms.length;i++) 
  	x=d.forms[i][n];
	
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  	x=getObjectRef(n,d.layers[i].document);
	
  if(!x && d.getElementById) 
  	x=d.getElementById(n); 
	
  return x;
}

