/* $Id: admin_devel.js,v 1.2 2010/03/12 22:54:41 sun Exp $ */
(function($) {

/**
 * jQuery debugging helper.
 *
 * Invented for Dreditor.
 *
 * @usage
 *   $.debug(var [, name]);
 *   $variable.debug( [name] );
 */
jQuery.extend({
  debug: function () {
    // Setup debug storage in global window. We want to look into it.
    window.debug = window.debug || [];

    args = jQuery.makeArray(arguments);
    // Determine data source; this is an object for $variable.debug().
    // Also determine the identifier to store data with.
    if (typeof this == 'object') {
      var name = (args.length ? args[0] : window.debug.length);
      var data = this;
    }
    else {
      var name = (args.length > 1 ? args.pop() : window.debug.length);
      var data = args[0];
    }
    // Store data.
    window.debug[name] = data;
    // Dump data into Firebug console.
    if (typeof console != 'undefined') {
      console.log(name, data);
    }
    return this;
  }
});
// @todo Is this the right way?
jQuery.fn.debug = jQuery.debug;

})(jQuery);
;
/**
* bbCode control by subBlue design [ www.subBlue.com ]
* Includes unixsafe colour palette selector by SHS`
*/

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));

var baseHeight;
onload_functions.push('initInsertions()');

/**
* Shows the help messages in the helpline window
*/
function helpline(help)
{
	document.forms[form_name].helpbox.value = help_line[help];
}

/**
* Fix a bug involving the TextRange object. From
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
*/ 
function initInsertions() 
{
	var doc;

	if( document.forms[form_name])
	{
		doc = document;
	}
	else 
	{
		doc = opener.document;
	}

	var textarea = doc.forms[form_name].elements[text_name];
	if (is_ie && typeof(baseHeight) != 'number')
	{
		textarea.focus();
		baseHeight = doc.selection.createRange().duplicate().boundingHeight;
		// document.body.focus();
	}
}

/**
* bbstyle
*/
function bbstyle(bbnumber)
{	
	if (bbnumber != -1)
	{
		bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
	} 
	else 
	{
		insert_text('[*]');
		document.forms[form_name].elements[text_name].focus();
	}
}

/**
* Apply bbcodes
*/
function bbfontstyle(bbopen, bbclose)
{
	theSelection = false;

	var textarea = document.forms[form_name].elements[text_name];

	textarea.focus();

	if ((clientVer >= 4) && is_ie && is_win)
	{
		// Get text selection
		theSelection = document.selection.createRange().text;

		if (theSelection)
		{
			// Add tags around selection
			document.selection.createRange().text = bbopen + theSelection + bbclose;
			document.forms[form_name].elements[text_name].focus();
			theSelection = '';
			return;
		}
	}
	else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0))
	{
		mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
		document.forms[form_name].elements[text_name].focus();
		theSelection = '';
		return;
	}
	
	//The new position for the cursor after adding the bbcode
	var caret_pos = getCaretPosition(textarea).start;
	var new_pos = caret_pos + bbopen.length;		

	// Open tag
	insert_text(bbopen + bbclose);

	// Center the cursor when we don't have a selection
	// Gecko and proper browsers
	if (!isNaN(textarea.selectionStart))
	{
		textarea.selectionStart = new_pos;
		textarea.selectionEnd = new_pos;
	}	
	// IE
	else if (document.selection)
	{
		var range = textarea.createTextRange(); 
		range.move("character", new_pos); 
		range.select();
		storeCaret(textarea);
	}

	textarea.focus();
	return;
}

/**
* Insert text at position
*/
function insert_text(text, spaces, popup)
{
	var textarea;
	
	if (!popup) 
	{
		textarea = document.forms[form_name].elements[text_name];
	} 
	else 
	{
		textarea = opener.document.forms[form_name].elements[text_name];
	}
	if (spaces) 
	{
		text = ' ' + text + ' ';
	}
	
	if (!isNaN(textarea.selectionStart))
	{
		var sel_start = textarea.selectionStart;
		var sel_end = textarea.selectionEnd;

		mozWrap(textarea, text, '')
		textarea.selectionStart = sel_start + text.length;
		textarea.selectionEnd = sel_end + text.length;
	}
	else if (textarea.createTextRange && textarea.caretPos)
	{
		if (baseHeight != textarea.caretPos.boundingHeight) 
		{
			textarea.focus();
			storeCaret(textarea);
		}

		var caret_pos = textarea.caretPos;
		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
	}
	else
	{
		textarea.value = textarea.value + text;
	}
	if (!popup) 
	{
		textarea.focus();
	}
}

/**
* Add inline attachment at position
*/
function attach_inline(index, filename)
{
	insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
	document.forms[form_name].elements[text_name].focus();
}

/**
* Add quote text to message
*/
function addquote(post_id, username)
{
	var message_name = 'message_' + post_id;
	var theSelection = '';
	var divarea = false;

	if (document.all)
	{
		divarea = document.all[message_name];
	}
	else
	{
		divarea = document.getElementById(message_name);
	}

	// Get text selection - not only the post content :(
	if (window.getSelection)
	{
		theSelection = window.getSelection().toString();
	}
	else if (document.getSelection)
	{
		theSelection = document.getSelection();
	}
	else if (document.selection)
	{
		theSelection = document.selection.createRange().text;
	}

	if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
	{
		if (divarea.innerHTML)
		{
			theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
			theSelection = theSelection.replace(/<br\/>/ig, '\n');
			theSelection = theSelection.replace(/&lt\;/ig, '<');
			theSelection = theSelection.replace(/&gt\;/ig, '>');
			theSelection = theSelection.replace(/&amp\;/ig, '&');			
		}
		else if (document.all)
		{
			theSelection = divarea.innerText;
		}
		else if (divarea.textContent)
		{
			theSelection = divarea.textContent;
		}
		else if (divarea.firstChild.nodeValue)
		{
			theSelection = divarea.firstChild.nodeValue;
		}
	}

	if (theSelection)
	{
		insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
	}

	return;
}

/**
* From http://www.massless.org/mozedit/
*/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	var scrollTop = txtarea.scrollTop;

	if (selEnd == 1 || selEnd == 2) 
	{
		selEnd = selLength;
	}

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);

	txtarea.value = s1 + open + s2 + close + s3;
	txtarea.selectionStart = selEnd + open.length + close.length;
	txtarea.selectionEnd = txtarea.selectionStart;
	txtarea.focus();
	txtarea.scrollTop = scrollTop;

	return;
}

/**
* Insert at Caret position. Code from
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
*/
function storeCaret(textEl)
{
	if (textEl.createTextRange)
	{
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

/**
* Color pallette
*/
function colorPalette(dir, width, height)
{
	var r = 0, g = 0, b = 0;
	var numberList = new Array(6);
	var color = '';

	numberList[0] = '00';
	numberList[1] = '40';
	numberList[2] = '80';
	numberList[3] = 'BF';
	numberList[4] = 'FF';

	document.writeln('<table cellspacing="1" cellpadding="0" border="0">');

	for (r = 0; r < 5; r++)
	{
		if (dir == 'h')
		{
			document.writeln('<tr>');
		}

		for (g = 0; g < 5; g++)
		{
			if (dir == 'v')
			{
				document.writeln('<tr>');
			}
			
			for (b = 0; b < 5; b++)
			{
				color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
				document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
				document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
				document.writeln('</td>');
			}

			if (dir == 'v')
			{
				document.writeln('</tr>');
			}
		}

		if (dir == 'h')
		{
			document.writeln('</tr>');
		}
	}
	document.writeln('</table>');
}


/**
* Caret Position object
*/
function caretPosition()
{
	var start = null;
	var end = null;
}


/**
* Get the caret position in an textarea
*/
function getCaretPosition(txtarea)
{
	var caretPos = new caretPosition();
	
	// simple Gecko/Opera way
	if(txtarea.selectionStart || txtarea.selectionStart == 0)
	{
		caretPos.start = txtarea.selectionStart;
		caretPos.end = txtarea.selectionEnd;
	}
	// dirty and slow IE way
	else if(document.selection)
	{
	
		// get current selection
		var range = document.selection.createRange();

		// a new selection of the whole textarea
		var range_all = document.body.createTextRange();
		range_all.moveToElementText(txtarea);
		
		// calculate selection start point by moving beginning of range_all to beginning of range
		var sel_start;
		for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
		{		
			range_all.moveStart('character', 1);
		}
	
		txtarea.sel_start = sel_start;
	
		// we ignore the end value for IE, this is already dirty enough and we don't need it
		caretPos.start = txtarea.sel_start;
		caretPos.end = txtarea.sel_start;			
	}

	return caretPos;
};
﻿/**
 * Unicode Phonetic Parser for writing in webpages
 * This script transliterate the user input and display unicode bangla characters
 * 
 * @name Ekushey Unicode Parser
 * @version 1.0 [Date 30th July, 2006]
 * @author Hasin Hayder. Visit My Homepage at http://hasin.wordpress.com
 * @license LGPL
 */
 
/**
 * This script is released under Lesser GNU Public License [LGPL] 
 * which implies that you are free to use this script in your 
 * web applications without any problem. No warranty ensured. If you like 
 * this script, Please acknowledge by keeping a link to my website 
 * http://hasin.wordpress.com in the page where you use this script. 
 */ 
/**
 * Last Modification:01/11/2008 by Sabuj Kundu(http://manchu.wordpress.com)
 */
 /**
  * Added Intellisense (27 Jan, 2008 by Hasin Hayder)
  */
  /**
  *Little modification by Sabuj Kundu to solve the dhirgho i kar and dhirgho u kar :P
  */
  
/* added shift intelligency by Hasin Hayder, 14th March 2008 */
/* added  accent key ( ` ) as joiner.   (By Sabuj Kundu, 17th March 2008) */
/*Fixed oi kar   (By Sabuj Kundu, 24th March 2008)*/
// Set of Characters
var activeta; //active text area
var phonetic=new Array();
var shift=false; //for intelligent shift
// phonetic bangla equivalents
//Bengali: {U+0980..U+09FF} 
phonetic['k'] = '\u0995'; // ko
//digits
phonetic['0']='\u09e6';//'০'; 
phonetic['1']='\u09e7';//'১';
phonetic['2']='\u09e8';//'২';
phonetic['3']='\u09e9';//'৩';
phonetic['4']='\u09ea';//'৪';
phonetic['5']='\u09eb';//'৫';
phonetic['6']='\u09ec';//'৬';
phonetic['7']='\u09ed';//'৭';
phonetic['8']='\u09ee';//'৮';
phonetic['9']='\u09ef';//'৯';

phonetic['i']='\u09BF'; // hrossho i kar
phonetic['I']='\u0987'; // hrossho i
phonetic['ii']='\u09C0'; // dirgho i kar
phonetic['II']='\u0988'; // dirgho i
phonetic['e']='\u09C7'; // e kar
phonetic['E'] = '\u098F'; // E
phonetic['U'] = '\u0989'; // hrossho u
phonetic['u'] = '\u09C1'; // hrossho u kar
phonetic['uu'] = '\u09C2'; // dirgho u kar
phonetic['UU'] = '\u098A'; // dirgho u
phonetic['r']='\u09B0'; // ro
phonetic['WR']='\u098B'; // wri
phonetic['a']='\u09BE'; // a kar
phonetic['A']='\u0986'; // shore a
phonetic['ao']='\u0985'; // shore o
phonetic['s']='\u09B8'; // dontyo so
phonetic['t']='\u099f'; // to
phonetic['K'] = '\u0996'; // Kho

phonetic['kh'] = '\u0996'; // kho

phonetic['n']='\u09A8'; // dontyo no
phonetic['N']='\u09A3'; // murdhonyo no
phonetic['T']='\u09A4'; // tto
phonetic['Th']='\u09A5'; // ttho

phonetic['d']='\u09A1'; // ddo
phonetic['dh']='\u09A2'; // ddho

phonetic['b']='\u09AC'; // bo
phonetic['bh']='\u09AD'; // bho
phonetic['v']='\u09AD'; // bho
//phonetic['rh']='o';	 // doye bindu ro
phonetic['R']='\u09DC';	 // doye bindu ro
phonetic['Rh']='\u09DD';	 // dhoye bindu ro
phonetic['g']='\u0997';	// go
phonetic['G']='\u0998';	// gho

phonetic['gh']='\u0998'; // gho

phonetic['h']='\u09B9';	// ho
phonetic['NG']='\u099E';	// yo
phonetic['j']='\u099C';	// borgio jo
phonetic['J']='\u099D'; // jho
phonetic['jh']='\u099D'; // jho
phonetic['c']='\u099A'; //  cho
phonetic['ch']='\u099B'; // cho
phonetic['C']='\u099B'; // ccho
phonetic['th']='\u09A0'; // tho
phonetic['p']='\u09AA'; // po
phonetic['f']='\u09AB'; // fo
phonetic['ph']='\u09AB'; // fo
phonetic['D']='\u09A6'; // do
phonetic['Dh']='\u09A7'; // dho

phonetic['z']='\u09AF';// ontoshyo zo
phonetic['y']='\u09DF';	// ontostho yo
phonetic['Ng']='\u0999';	// Uma
phonetic['ng']='\u0982';	// uniswor
phonetic['l']='\u09B2';	// lo
phonetic['m']='\u09AE';	// mo
phonetic['sh']='\u09B6';	// talobyo sho
phonetic['S']='\u09B7'; // mordhonyo sho
phonetic['O']= '\u0993';//'\u09CB'; // o
phonetic['ou']='\u099C'; // ou kar
phonetic['OU']='\u0994'; // OU
phonetic['Ou']='\u0994'; // OU
phonetic['Oi']='\u0990'; // OU
phonetic['OI']='\u0990'; // OU
phonetic['tt']='\u09CE'; // tto
phonetic['H']='\u0983'; // bisworgo
phonetic["."] ="\u0964"; // dari
phonetic[".."] = "."; // fullstop
phonetic['HH'] = '\u09CD' + '\u200c'; // hosonto
phonetic['NN'] = '\u0981'; // chondrobindu
phonetic['Y'] ='\u09CD'+'\u09AF'; // jo fola
phonetic['w'] ='\u09CD'+ '\u09AC'; // wri kar
phonetic['W'] ='\u09C3';// wri kar
phonetic['wr'] ='\u09C3'; // wri kar
phonetic['x'] ="\u0995"  + '\u09CD'+ '\u09B8';
phonetic['rY'] = phonetic['r']+ '\u200D'+ '\u09CD'+'\u09AF';
phonetic['L'] = phonetic['l'];
phonetic['Z'] = phonetic['z'];
phonetic['P'] = phonetic['p'];
phonetic['V'] = phonetic['v'];
phonetic['B'] = phonetic['b'];
phonetic['M'] = phonetic['m'];
phonetic['V'] = phonetic['v'];
phonetic['X'] = phonetic['x'];
phonetic['V'] = phonetic['v'];
phonetic['F'] = phonetic['f'];
phonetic['vowels']='aIiUuoiiouueEiEu'; //dont change this pattern
//End Set


var carry = '';  //This variable stores each keystrokes
var old_len =0; //This stores length parsed bangla charcter
var ctrlPressed=false;
var len_to_process_oi_kar=0;
var first_letter = false;
var carry2="";
isIE=document.all? 1:0;
var switched=false;

function checkKeyDown(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = true;
	}
	else if(e==16)
	shift=true;
}

function checkKeyUp(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = false;
		//alert(ctrlPressed);
	}

}



function parsePhonetic(evnt)
{
	// main phonetic parser
	var t = document.getElementById(activeta); // the active text area
	var e = (window.event) ? event.keyCode : evnt.which; // get the keycode

	if (e=='113')
	{
		//switch the keyboard mode
		if(ctrlPressed){
			switched = !switched;
			//alert("H"+switched);
			return true;
		}
	}

	if (switched) return true;
	
	if(ctrlPressed)
	{
		// user is pressing control, so leave the parsing
		e=0; 
	}

	if (shift)
	{
		var char_e = String.fromCharCode(e).toUpperCase(); // get the character equivalent to this keycode
		shift=false;
	}
	else
	var char_e = String.fromCharCode(e); // get the character equivalent to this keycode
	
	if(e==8 || e==32)
	{
		// if space is pressed we have to clear the carry. otherwise there will be some malformed conjunctions
		carry = " ";	
		old_len = 1;
		return;
	}

	lastcarry = carry;
	carry += "" + char_e;	 //append the current character pressed to the carry
	
	//the intellisense
	if ((phonetic['vowels'].indexOf(lastcarry)!=-1 && phonetic['vowels'].indexOf(char_e)!=-1) || (lastcarry==" " && phonetic['vowels'].indexOf(char_e)!=-1) )
	{
		//let's check for dhirgho i kar and dhirgho u kar :P		
		if(carry=='ii' || carry=='uu'){carry = lastcarry+char_e;}
		else
		{
			char_e = char_e.toUpperCase();
			carry = lastcarry+char_e;		
		}				
	}
	//intellisense ended
	
	bangla = parsePhoneticCarry(carry); // get the combined equivalent
	tempBangla = parsePhoneticCarry(char_e); // get the single equivalent

	if (tempBangla == ".." || bangla == "..") //that means it has next sibling
	{
		return false;
	}
	//alert(carry);
	if (char_e=="+" || char_e=="="||char_e=="`")
	{
		if(carry=="++" || carry=="=="||carry=="``")
		{
			// check if it is a plus/equal/accent  key/sign
			insertConjunction(char_e,old_len);
			old_len=1;
			return false;
		}	
		//otherwise this is a simple joiner
		insertAtCursor("\u09CD");old_len = 1;
		carry2=carry;
		carry=char_e;
		return false;
	}
	
	
	else if(old_len==0) //first character
	{
		// this is first time someone press a character
		insertConjunction(bangla,1);
		old_len=1;
		return false;
		
	}
/*	else if((char_e=='z' || char_e=='Z')&& carry2=="r+")//force Za-phola after Ra
	{
		//alert('yes');
		insertConjunction('\u200D'+'\u09CD'+phonetic['z'],1);
		old_len=1;	
		return false;
	} */
	
	else if(carry=="Ao")
	{
		// its a shore o
		insertConjunction(parsePhoneticCarry("ao"),old_len);
		old_len=1;
		return false;
	}
	else if (carry == "ii")
	{
		// process dirgho i kar
		//alert('dirgho i kar');
		insertConjunction(phonetic['ii'],1);
		old_len = 1;
		return false;
	}
	
	else if (carry == "oI")
	{
		//oi kar
		insertConjunction('\u09C8',old_len); //same treatment like ou kar (By manchu)
		old_len = 1; 
		return false;
	}		

	else if (char_e == "o")
	{
		old_len = 1;
		insertAtCursor('\u09CB');
		carry = "o";
		return false;
	}
	
	
	else if (carry == "oU")
	{
		// ou kar
		insertConjunction("\u09CC",old_len);
		old_len = 1;
		return false;
	}	
	
	else if((bangla == "" && tempBangla !="")) //that means it has no joint equivalent
	{
		
		// there is no joint equivalent - so show the single equivalent. 
		bangla = tempBangla;
		if (bangla=="")
		{
			// there is no available equivalent - leave as is
			carry ="";
			return;
		}
		
		else
		{
			// found one equivalent
			carry = char_e;
			insertAtCursor(bangla);
			old_len = bangla.length;
			return false;
		}
	}
	else if(bangla!="")//joint equivalent found 
	{
		// we have found some joint equivalent process it
		
		insertConjunction(bangla, old_len);
		old_len = bangla.length;
		return false;
	}
}

    function parsePhoneticCarry(code)
    {
	//this function just returns a bangla equivalent for a given keystroke
	//or a conjunction
	//just read the array - if found then return the bangla eq.
	//otherwise return a null value
        if (!phonetic[code])  //Oh my god :-( no bangla equivalent for this keystroke

        {
			return ''; //return a null value
        }
        else
        {
            return ( phonetic[code]);  //voila - we've found bangla equivalent
        }

    }


function insertAtCursor(myValue) {
	/**
	 * this function inserts a character at the current cursor position in a text area
	 * many thanks to alex king and phpMyAdmin for this cool function
	 * 
	 * This function is originally found in phpMyAdmin package and modified by Hasin Hayder to meet the requirement
	 */
	var myField = document.getElementById(activeta);
	if (document.selection) {		
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
}

function insertConjunction(myValue, len) {
	/**
	 * this function inserts a conjunction and removes previous single character at the current cursor position in a text area
	 * 
	 * This function is derived from the original one found in phpMyAdmin package and modified by Hasin to meet our need
	 */
	//alert(len);
	var myField = document.getElementById(activeta);
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		if (myField.value.length >= len){  // here is that first conjunction bug in IE, if you use the > operator
			sel.moveStart('character', -1*(len));   
			//sel.moveEnd('character',-1*(len-1));
		}
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		myField.focus();
		var startPos = myField.selectionStart-len;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
	//document.getElementById("len").innerHTML = len;
}

function makePhoneticEditor2(textAreaId)
{
	activeTextAreaInstance = document.getElementById(textAreaId);
	activeTextAreaInstance.onkeypress = parsePhonetic; 
	activeTextAreaInstance.onkeydown = checkKeyDown; 
	activeTextAreaInstance.onkeyup = checkKeyUp;
	activeTextAreaInstance.onfocus = function(){activeta=textAreaId;};
}
function makeVirtualEditor(textAreaId)
{
	activeTextAreaInstance = document.getElementById(textAreaId);
	activeTextAreaInstance.onfocus = function(){activeta=textAreaId;};
};
/**
 * Unicode Phonetic Parser for writing in webpages
 * This script transliterate the user input and display unicode bangla characters
 * 
 * @name Ekushey Unicode Parser
 * @version 1.0 [Date 30th July, 2006]
 * @author Hasin Hayder. Visit My Homepage at http://hasin.wordpress.com
 * @license LGPL
 */
 
/**
 * This script is released under Lesser GNU Public License [LGPL] 
 * which implies that you are free to use this script in your 
 * web applications without any problem. No warranty ensured. If you like 
 * this script, Please acknowledge by keeping a link to my website 
 * http://hasin.wordpress.com in the page where you use this script. 
 */ 

// Set of Characters
var activeta; //active text area
var phonetic=new Array();

// phonetic bangla equivalents
//Bengali: {U+0980..U+09FF} 
phonetic['k'] = '\u0995'; // ko
/*
	This part is modified by Sabuj kundu(Manchumahara)
	Email: manchu_mahara@yahoo.com
	Help:http://salahuddin66.blogspot.com
*/
//09e6 09e7 09e8 09e9 09ea 09eb 09ec 09ed 09ee 09ef=০১২৩৪৫৬৭৮৯
phonetic['0']='\u09e6';//'০'; 
phonetic['1']='\u09e7';//'১';
phonetic['2']='\u09e8';//'২';
phonetic['3']='\u09e9';//'৩';
phonetic['4']='\u09ea';//'৪';
phonetic['5']='\u09eb';//'৫';
phonetic['6']='\u09ec';//'৬';
phonetic['7']='\u09ed';//'৭';
phonetic['8']='\u09ee';//'৮';
phonetic['9']='\u09ef';//'৯';

/*
	This part is modified by Sabuj kundu(Manchumahara)
	Email: manchu_mahara@yahoo.com
*/
phonetic['i']='\u09BF'; // hrossho i kar
phonetic['I']='\u0987'; // hrossho i
phonetic['ii']='\u09C0'; // dirgho i kar
phonetic['II']='\u0988'; // dirgho i
phonetic['e']='\u09C7'; // e kar
phonetic['E'] = '\u098F'; // E
phonetic['U'] = '\u0989'; // hrossho u
phonetic['u'] = '\u09C1'; // hrossho u kar
phonetic['uu'] = '\u09C2'; // dirgho u kar
phonetic['UU'] = '\u098A'; // dirgho u
phonetic['r']='\u09B0'; // ro
phonetic['WR']='\u098B'; // wri
phonetic['a']='\u09BE'; // a kar
phonetic['A']='\u0986'; // shore a
phonetic['ao']='\u0985'; // shore o
phonetic['s']='\u09B8'; // dontyo so
phonetic['t']='\u099f'; // to
phonetic['K'] = '\u0996'; // Kho

phonetic['kh'] = '\u0996'; // kho

phonetic['n']='\u09A8'; // dontyo no
phonetic['N']='\u09A3'; // murdhonyo no
phonetic['T']='\u09A4'; // tto
phonetic['Th']='\u09A5'; // ttho

phonetic['d']='\u09A1'; // ddo
phonetic['dh']='\u09A2'; // ddho

phonetic['b']='\u09AC'; // bo
phonetic['bh']='\u09AD'; // bho
phonetic['v']='\u09AD'; // bho
//phonetic['rh']='o';	 // doye bindu ro
phonetic['R']='\u09DC';	 // doye bindu ro
phonetic['Rh']='\u09DD';	 // dhoye bindu ro
phonetic['g']='\u0997';	// go
phonetic['G']='\u0998';	// gho

phonetic['gh']='\u0998'; // gho

phonetic['h']='\u09B9';	// ho
phonetic['NG']='\u099E';	// yo
phonetic['j']='\u099C';	// borgio jo
phonetic['J']='\u099D'; // jho
phonetic['jh']='\u099D'; // jho
phonetic['c']='\u099A'; //  cho
phonetic['ch']='\u099A'; // cho
phonetic['C']='\u099B'; // ccho
phonetic['th']='\u09A0'; // tho
phonetic['p']='\u09AA'; // po
phonetic['f']='\u09AB'; // fo
phonetic['ph']='\u09AB'; // fo
phonetic['D']='\u09A6'; // do
phonetic['Dh']='\u09A7'; // dho

phonetic['z']='\u09AF';// ontoshyo zo
phonetic['y']='\u09DF';	// ontostho yo
phonetic['Ng']='\u0999';	// Uma
phonetic['ng']='\u0982';	// uniswor
phonetic['l']='\u09B2';	// lo
phonetic['m']='\u09AE';	// mo
phonetic['sh']='\u09B6';	// talobyo sho
phonetic['S']='\u09B7'; // mordhonyo sho
phonetic['O']= '\u0993';//'\u09CB'; // o
phonetic['ou']='\u099C'; // ou kar
phonetic['OU']='\u0994'; // OU
phonetic['Ou']='\u0994'; // OU
phonetic['Oi']='\u0990'; // OU
phonetic['OI']='\u0990'; // OU
phonetic['tt']='\u09CE'; // tto
phonetic['H']='\u0983'; // bisworgo
phonetic["."] ="\u0964"; // dari
phonetic[".."] = "."; // fullstop
phonetic['HH'] = '\u09CD' + '\u200c'; // hosonto
phonetic['NN'] = '\u0981'; // chondrobindu
phonetic['Y'] ='\u09CD'+'\u09AF'; // jo fola
phonetic['w'] ='\u09CD'+ '\u09AC'; // wri kar
phonetic['W'] ='\u09C3';// wri kar
phonetic['wr'] ='\u09C3'; // wri kar
phonetic['x'] ="\u0995"  + '\u09CD'+ '\u09B8';
phonetic['rY'] = phonetic['r']+ '\u200c'+ '\u09CD'+'\u09AF';
phonetic['L'] = phonetic['l'];
phonetic['Z'] = phonetic['z'];
phonetic['P'] = phonetic['p'];
phonetic['V'] = phonetic['v'];
phonetic['B'] = phonetic['b'];
phonetic['M'] = phonetic['m'];
phonetic['V'] = phonetic['v'];
phonetic['X'] = phonetic['x'];
phonetic['V'] = phonetic['v'];
phonetic['F'] = phonetic['f'];
//End Set


var carry = '';  //This variable stores each keystrokes
var old_len =0; //This stores length parsed bangla charcter
var ctrlPressed=false;
var len_to_process_oi_kar=0;
var first_letter = false;

isIE=document.all? 1:0;
var switched=false;

function checkKeyDown(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = true;
	}
}

function checkKeyUp(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = false;
		//alert(ctrlPressed);
	}

}


function parsePhonetic(evnt)
{
	// main phonetic parser
	var t = document.getElementById(activeta); // the active text area
	var e = (window.event) ? event.keyCode : evnt.which; // get the keycode

	if (e=='113')
	{
		//switch the keyboard mode
		if(ctrlPressed){
			switched = !switched;
			//alert("H"+switched);
			return true;
		}
	}

	if (switched) return true;
	
	if(ctrlPressed)
	{
		// user is pressing control, so leave the parsing
		e=0; 
	}

	var char_e = String.fromCharCode(e); // get the character equivalent to this keycode
	
	if(e==8 || e==32)
	{
		// if space is pressed we have to clear the carry. otherwise there will be some malformed conjunctions
		carry = " ";	
		old_len = 1;
		return;
	}

	lastcarry = carry;
	carry += "" + char_e;	 //append the current character pressed to the carry
	
	bangla = parsePhoneticCarry(carry); // get the combined equivalent
	tempBangla = parsePhoneticCarry(char_e); // get the single equivalent

	if (tempBangla == ".." || bangla == "..") //that means it has next sibling
	{
		return false;
	}
	if (char_e=="+")
	{
		if(carry=="++")
		{
			// check if it is a plus sign
			insertJointAtCursor("+",old_len);
			old_len=1;
			return false;
		}	
		//otherwise this is a simple joiner
		insertAtCursor("\u09CD");old_len = 1;
		carry="+";
		return false;
	}
	else if(old_len==0) //first character
	{
		// this is first time someone press a character
		insertJointAtCursor(bangla,1);
		old_len=1;
		return false;
		
	}

	else if(carry=="ao")
	{
		// its a shore o
		insertJointAtCursor(parsePhoneticCarry("ao"),old_len);
		old_len=1;
		return false;
	}
	else if (carry == "ii")
	{
		// process dirgho i kar

		insertJointAtCursor(phonetic['ii'],1);
		old_len = 1;
		return false;
	}
	else if (carry == "oi" )
	{
		insertJointAtCursor('\u09C8',1);
		return false;
	}		

	else if (char_e == "o")
	{
		old_len = 1;
		insertAtCursor('\u09CB');
		carry = "o";
		return false;
	}
	else if (carry == "ou")
	{
		// ou kar
		insertJointAtCursor("\u09CC",old_len);
		old_len = 1;
		return false;
	}	
	
	else if((bangla == "" && tempBangla !="")) //that means it has no joint equivalent
	{
		
		// there is no joint equivalent - so show the single equivalent. 
		bangla = tempBangla;
		if (bangla=="")
		{
			// there is no available equivalent - leave as is
			carry ="";
			return;
		}
		
		else
		{
			// found one equivalent
			carry = char_e;
			insertAtCursor(bangla);
			old_len = bangla.length;
			return false;
		}
	}
	else if(bangla!="")//joint equivalent found 
	{
		// we have found some joint equivalent process it
		
		insertJointAtCursor(bangla, old_len);
		old_len = bangla.length;
		return false;
	}
}

    function parsePhoneticCarry(code)
    {
	//this function just returns a bangla equivalent for a given keystroke
	//or a conjunction
	//just read the array - if found then return the bangla eq.
	//otherwise return a null value
        if (!phonetic[code])  //Oh my god :-( no bangla equivalent for this keystroke

        {
			return ''; //return a null value
        }
        else
        {
            return ( phonetic[code]);  //voila - we've found bangla equivalent
        }

    }


function insertAtCursor(myValue) {
	/**
	 * this function inserts a character at the current cursor position in a text area
	 * many thanks to alex king and phpMyAdmin for this cool function
	 * 
	 * This function is originally found in phpMyAdmin package and modified by Hasin Hayder to meet the requirement
	 */
	var myField = document.getElementById(activeta);
	if (document.selection) {
		alert("hello2");
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
}

function insertJointAtCursor(myValue, len) {
	/**
	 * this function inserts a conjunction and removes previous single character at the current cursor position in a text area
	 * 
	 * This function is derived from the original one found in phpMyAdmin package and modified by Hasin to meet our need
	 */
	//alert(len);
	var myField = document.getElementById(activeta);
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		if (myField.value.length >= len){  // here is that first conjunction bug in IE, if you use the > operator
			sel.moveStart('character', -1*(len));   
			//sel.moveEnd('character',-1*(len-1));
		}
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		myField.focus();
		var startPos = myField.selectionStart-len;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
	//document.getElementById("len").innerHTML = len;
}

function makePhoneticEditor(textAreaId)
{
	activeTextAreaInstance = document.getElementById(textAreaId);
	activeTextAreaInstance.onkeypress = parsePhonetic; 
	activeTextAreaInstance.onkeydown = checkKeyDown; 
	activeTextAreaInstance.onkeyup = checkKeyUp;
	activeTextAreaInstance.onfocus = function(){activeta=textAreaId;};
};
/**
 * Unicode unijoy Parser for writing in webpages
 * This script helps to write unicode bangla using unijoy keyboard mapping
 * 
 * @name Unijoy Unicode Parser
 * @version 1.0 [Date 26th August, 2006]
 * @author Hasin Hayder. Visit My Homepage at http://www.hasinhyder.net
 * @license LGPL
 */
 
/**
 * This script is released under Lesser GNU Public License [LGPL] 
 * which implies that you are free to use this script in your 
 * web applications without any problem. No warranty ensured. If you like 
 * this script, Please acknowledge by keeping a link to my website 
 * http://hasin.wordpress.com in the page where you use this script. 
 */ 

// Set of Characters
var activeta; //active text area
var unijoy=new Array();
/*
	This part is modified by Sabuj kundu(Manchumahara)
	Email: manchu_mahara@yahoo.com
	Help:http://salahuddin66.blogspot.com
*/
//09e6 09e7 09e8 09e9 09ea 09eb 09ec 09ed 09ee 09ef=০১২৩৪৫৬৭৮৯
unijoy['0']='\u09e6';//'০'; 
unijoy['1']='\u09e7';//'১';
unijoy['2']='\u09e8';//'২';
unijoy['3']='\u09e9';//'৩';
unijoy['4']='\u09ea';//'৪';
unijoy['5']='\u09eb';//'৫';
unijoy['6']='\u09ec';//'৬';
unijoy['7']='\u09ed';//'৭';
unijoy['8']='\u09ee';//'৮';
unijoy['9']='\u09ef';//'৯';

/*
	This part is modified by Sabuj kundu(Manchumahara)
	Email: manchu_mahara@yahoo.com
*/
// unijoy bangla equivalents
unijoy['j'] = '\u0995'; // ko

unijoy['d']='\u09BF'; // hrossho i kar
unijoy['gd']='\u0987'; // hrossho i
unijoy['D']='\u09C0'; // dirgho i kar
unijoy['gD']='\u0988'; // dirgho i
unijoy['c']='\u09C7'; // e kar
unijoy['gc'] = '\u098F'; // E
unijoy['gs'] = '\u0989'; // hrossho u
unijoy['s'] = '\u09C1'; // hrossho u kar
unijoy['S'] = '\u09C2'; // dirgho u kar
unijoy['gS'] = '\u098A'; // dirgho u
unijoy['v']='\u09B0'; // ro
unijoy['a']='\u098B'; // wri
unijoy['f']='\u09BE'; // a kar
unijoy['gf'] = '\u0986'; //shore a
unijoy['F']='\u0985'; // shore ao
//unijoy['ao']='\u0985'; // shore o
unijoy['n']='\u09B8'; // dontyo so
unijoy['t']='\u099f'; // to
unijoy['J'] = '\u0996'; // Kho

//unijoy['kh'] = '\u0996'; // kho

unijoy['b']='\u09A8'; // dontyo no
unijoy['B']='\u09A3'; // murdhonyo no
unijoy['k']='\u09A4'; // tto
unijoy['K']='\u09A5'; // ttho

unijoy['e']='\u09A1'; // ddo
unijoy['E']='\u09A2'; // ddho

unijoy['h']='\u09AC'; // bo
unijoy['H']='\u09AD'; // bho
//unijoy['v']='\u09AD'; // bho
//unijoy['rh']='o';	 // doye bindu ro
unijoy['p']='\u09DC';	 // doye bindu ro
unijoy['P']='\u09DD';	 // dhoye bindu ro
unijoy['o']='\u0997';	// go
unijoy['O']='\u0998';	// gho

//unijoy['gh']='\u0998'; // gho

unijoy['i']='\u09B9';	// ho
unijoy['I']='\u099E';	// yo
unijoy['u']='\u099C';	// borgio jo
unijoy['U']='\u099D'; // jho
//unijoy['jh']='\u099D'; // jho
unijoy['y']='\u099A'; //  cho
unijoy['Y']='\u099B'; // cho
//unijoy['C']='\u099B'; // ccho
unijoy['T']='\u09A0'; // tho
unijoy['r']='\u09AA'; // po
unijoy['R']='\u09AB'; // fo
//unijoy['ph']='\u09AB'; // fo
unijoy['l']='\u09A6'; // do
unijoy['L']='\u09A7'; // dho

unijoy['w']='\u09AF';// ontoshyo zo
unijoy['W']='\u09DF';	// ontostho yo
unijoy['q']='\u0999';	// Uma
unijoy['Q']='\u0982';	// uniswor
unijoy['V']='\u09B2';	// lo
unijoy['m']='\u09AE';	// mo
unijoy['M']='\u09B6';	// talobyo sho
unijoy['N']='\u09B7'; // mordhonyo sho
unijoy['gx']= '\u0993';//'\u09CB'; // o
unijoy['X']='\u09CC'; // ou kar
unijoy['gX']='\u0994'; // OU
//unijoy['Ou']='\u0994'; // OU
unijoy['gC']='\u0990'; // Oi
unijoy['\\']='\u0983'; // khandaTa
unijoy['|']='\u09CE'; // bisworgo
unijoy["G"] ="\u0964"; // dari
//unijoy[".."] = "."; // fullstop
unijoy['g'] = ' ';//'\u09CD' + '\u200c'; // hosonto
unijoy['&'] = '\u0981'; // chondrobindu
unijoy['Z'] ='\u09CD'+'\u09AF'; // jo fola
unijoy['gh'] ='\u09CD'+ '\u09AC'; // bo fola
unijoy['ga'] ='\u098B';// wri kar
unijoy['a'] ='\u09C3'; // wri 
//unijoy['k'] ="\u0995"  + '\u09CD'+ '\u09B8';
unijoy['vZ'] = unijoy['v']+ '\u200D'+ '\u09CD'+'\u09AF';
unijoy['z'] =  '\u09CD'+ unijoy['v'];
unijoy['x'] = '\u09CB';
unijoy['C'] = '\u09C8'; //Oi Kar



var carry = '';  //This variable stores each keystrokes
var old_len =0; //This stores length parsed bangla charcter
var ctrlPressed=false;
var first_letter = false;
var lastInserted;

isIE=document.all? 1:0;
var switched=false;

function checkKeyDown(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = true;
	}
}

function checkKeyUp(ev)
{
	//just track the control key
	var e = (window.event) ? event.keyCode : ev.which;
	if (e=='17')
	{
		ctrlPressed = false;
		//alert(ctrlPressed);
	}

}


function parseunijoy(evnt)
{
	// main unijoy parser
	var t = document.getElementById(activeta); // the active text area
	var e = (window.event) ? event.keyCode : evnt.which; // get the keycode

	if (e=='113')
	{
		//switch the keyboard mode
		if(ctrlPressed){
			switched = !switched;
			//alert("H"+switched);
			return true;
		}
	}

	if (switched) return true;
	
	if(ctrlPressed)
	{
		// user is pressing control, so leave the parsing
		e=0; 
	}

	var char_e = String.fromCharCode(e); // get the character equivalent to this keycode
	
	if(e==8 || e==32)
	{
		// if space is pressed we have to clear the carry. otherwise there will be some malformed conjunctions
		carry = " ";	
		old_len = 1;
		return;
	}

	lastcarry = carry;
	carry += "" + char_e;	 //append the current character pressed to the carry
	
	bangla = parseunijoyCarry(carry); // get the combined equivalent
	tempBangla = parseunijoyCarry(char_e); // get the single equivalent

	if (tempBangla == ".." || bangla == "..") //that means it has sibling
	{
		return false;
	}
	if (char_e=="g")
	{
		if(carry=="gg")
		{
			// check if it is a plus sign
			insertConjunction('\u09CD' + '\u200c',old_len);
			old_len=1;
			return false;
		}	
		//otherwise this is a simple joiner
		insertAtCursor("\u09CD");old_len = 1;
		carry="g";
		return false;
	}

	else if(old_len==0) //first character
	{
		// this is first time someone press a character
		insertConjunction(bangla,1);
		old_len=1;
		return false;
		
	}

	else if(char_e=="A")
	{
		//process old style ref
		newChar = unijoy['v']+ '\u09CD';
		insertAtCursor(newChar);
		old_len = 1;
		return false;
	}

	
	else if((bangla == "" && tempBangla !="")) //that means it has no joint equivalent
	{
		
		// there is no joint equivalent - so show the single equivalent. 
		bangla = tempBangla;
		if (bangla=="")
		{
			// there is no available equivalent - leave as is
			carry ="";
			return;
		}
		
		else
		{
			// found one equivalent
			carry = char_e;
			insertAtCursor(bangla);
			old_len = bangla.length;
			return false;
		}
	}
	else if(bangla!="")//joint equivalent found 
	{
		// we have found some joint equivalent process it
		
		insertConjunction(bangla, old_len);
		old_len = bangla.length;
		return false;
	}
}

    function parseunijoyCarry(code)
    {
	//this function just returns a bangla equivalent for a given keystroke
	//or a conjunction
	//just read the array - if found then return the bangla eq.
	//otherwise return a null value
        if (!unijoy[code])  //Oh my god :-( no bangla equivalent for this keystroke

        {
			return ''; //return a null value
        }
        else
        {
            return ( unijoy[code]);  //voila - we've found bangla equivalent
        }

    }


function insertAtCursor(myValue) {
	/**
	 * this function inserts a character at the current cursor position in a text area
	 * many thanks to alex king and phpMyAdmin for this cool function
	 * 
	 * This function is originally found in phpMyAdmin package and modified by Hasin Hayder to meet the requirement
	 */
	lastInserted = myValue;
	var myField = document.getElementById(activeta);
	if (document.selection) {
		//alert("hello2");
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
}

function insertConjunction(myValue, len) {
	/**
	 * this function inserts a conjunction and removes previous single character at the current cursor position in a text area
	 * 
	 * This function is derived from the original one found in phpMyAdmin package and modified by Hasin to meet our need
	 */
	//alert(len);
	lastInserted = myValue;
	var myField = document.getElementById(activeta);
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		if (myField.value.length >= len){  // here is that first conjunction bug in IE, if you use the > operator
			sel.moveStart('character', -1*(len));   
			//sel.moveEnd('character',-1*(len-1));
		}
		sel.text = myValue;
		sel.collapse(true);
		sel.select();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == 0) {
		myField.focus();
		var startPos = myField.selectionStart-len;
		var endPos = myField.selectionEnd;
		var scrollTop = myField.scrollTop;
		startPos = (startPos == -1 ? myField.value.length : startPos );
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		myField.scrollTop = scrollTop;
	} else {
		var scrollTop = myField.scrollTop;
		myField.value += myValue;
		myField.focus();
		myField.scrollTop = scrollTop;
	}
	//document.getElementById("len").innerHTML = len;
}

function makeUnijoyEditor(textAreaId)
{
	
        activeTextAreaInstance = document.getElementById(textAreaId);
        activeTextAreaInstance.onkeypress = parseunijoy; 
	activeTextAreaInstance.onkeydown = checkKeyDown; 
	activeTextAreaInstance.onkeyup = checkKeyUp;
	activeTextAreaInstance.onfocus = function(){activeta=textAreaId;};
            
};

function fontsizeup()
{
	var active = getActiveStyleSheet();

	switch (active)
	{
		case 'A--':
			setActiveStyleSheet('A-');
		break;

		case 'A-':
			setActiveStyleSheet('A');
		break;

		case 'A':
			setActiveStyleSheet('A+');
		break;

		case 'A+':
			setActiveStyleSheet('A++');
		break;

		case 'A++':
			setActiveStyleSheet('A');
		break;

		default:
			setActiveStyleSheet('A');
		break;
	}
}

function fontsizedown()
{
	active = getActiveStyleSheet();

	switch (active)
	{
		case 'A++' : 
			setActiveStyleSheet('A+');
		break;

		case 'A+' : 
			setActiveStyleSheet('A');
		break;

		case 'A' : 
			setActiveStyleSheet('A-');
		break;

		case 'A-' : 
			setActiveStyleSheet('A--');
		break;

		case 'A--' : 
		break;

		default :
			setActiveStyleSheet('A--');
		break;
	}
}

function setActiveStyleSheet(title)
{
	var i, a, main;

	for (i = 0; (a = document.getElementsByTagName('link')[i]); i++)
	{
		if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title'))
		{
			a.disabled = true;
			if (a.getAttribute('title') == title)
			{
				a.disabled = false;
			}
		}
	}
}

function getActiveStyleSheet()
{
	var i, a;

	for (i = 0; (a = document.getElementsByTagName('link')[i]); i++)
	{
		if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled)
		{
			return a.getAttribute('title');
		}
	}

	return null;
}

function getPreferredStyleSheet()
{
	return ('A-');
}

function createCookie(name, value, days)
{
	
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = '; expires=' + date.toGMTString();
	}
	else
	{
		expires = '';
	}
	document.cookie = name + '=' + value + expires + '; path=/';
	//alert('cookie created with name '+name+'  and value is '+value);
}

function readCookie(name)
{
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++)
	{
		var c = ca[i];

		while (c.charAt(0) == ' ')
		{
			c = c.substring(1, c.length);
		}

		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length, c.length);			
		}
	}
	return null;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function load_cookie()
{
	var cookie = readCookie('style_cookie');
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

function unload_cookie()
{
	var title = getActiveStyleSheet();
	createCookie('style_cookie', title, 365);
}

onload_functions.push('load_cookie()');
onunload_functions.push('unload_cookie()');

/*
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
*/
;
/*! JS Avro Phonetic v1.0 http://omicronlab.com | https://raw.github.com/torifat/jsAvroPhonetic/master/MPL-1.1.txt */
var OmicronLab={Avro:{}};
OmicronLab.Avro.Phonetic={parse:function(a){for(var a=this.fixString(a),f="",c=0;c<a.length;++c){for(var e=c,g=c+1,h=e-1,k=!1,h=0;h<this.data.patterns.length;++h){var i=this.data.patterns[h],g=c+i.f.length;if(g<=a.length&&a.substring(e,g)==i.f){h=e-1;if(typeof i.u!=="undefined")for(var l=0;l<i.u.length;++l){for(var m=i.u[l],j=!0,d=0,n=0;n<m.m.length;++n){var b=m.m[n],d=b.t==="s"?g:h;if(typeof b.negative==="undefined"&&(b.negative=!1,b.s.charAt(0)==="!"))b.negative=
!0,b.s=b.s.substring(1);if(typeof b.v==="undefined")b.v="";if(b.s==="p"){if(!(d<0&&b.t==="p"||d>=a.length&&b.t==="s"||this.isPunctuation(a.charAt(d)))^b.negative){j=!1;break}}else if(b.s==="vowel"){if(!((d>=0&&b.t==="p"||d<a.length&&b.t==="s")&&this.isVowel(a.charAt(d)))^b.negative){j=!1;break}}else if(b.s==="c"){if(!((d>=0&&b.t==="p"||d<a.length&&b.t==="s")&&this.isConsonant(a.charAt(d)))^b.negative){j=
!1;break}}else if(b.s==="e"){var o;b.t==="s"?(d=g,o=g+b.v.length):(d=e-b.v.length,o=e);if(!this.isExact(b.v,a,d,o,b.negative)){j=!1;break}}}if(j){f+=m.r;c=g-1;k=!0;break}}if(k==!0)break;f+=i.r;c=g-1;k=!0;break}}k||(f+=a.charAt(c))}return f},fixString:function(a){for(var f="",c=0;c<a.length;++c){var e=a.charAt(c);f+=this.isCaseSensitive(e)?e:e.toLowerCase()}return f},isVowel:function(a){return this.data.vowel.indexOf(a.toLowerCase())>=0},isConsonant:function(a){return this.data.c.indexOf(a.toLowerCase())>=
0},isPunctuation:function(a){return!(this.isVowel(a)||this.isConsonant(a))},isExact:function(a,f,c,e,g){return(c>=0&&e<f.length&&f.substring(c,e)===a)^g},isCaseSensitive:function(a){return this.data.casesensitive.indexOf(a.toLowerCase())>=0},data:{patterns:[{f:"bhl",r:"\u09ad\u09cd\u09b2"},{f:"psh",r:"\u09aa\u09b6"},{f:"bj",r:"\u09ac\u09cd\u099c"},{f:"bd",r:"\u09ac\u09cd\u09a6"},{f:"bb",r:"\u09ac\u09cd\u09ac"},{f:"bl",r:"\u09ac\u09cd\u09b2"},{f:"bh",
r:"\u09ad"},{f:"vl",r:"\u09ad\u09cd\u09b2"},{f:"b",r:"\u09ac"},{f:"v",r:"\u09ad"},{f:"cNG",r:"\u099a\u09cd\u099e"},{f:"cch",r:"\u099a\u09cd\u099b"},{f:"cc",r:"\u099a\u09cd\u099a"},{f:"ch",r:"\u099b"},{f:"c",r:"\u099a"},{f:"dhn",r:"\u09a7\u09cd\u09a8"},{f:"dhm",r:"\u09a7\u09cd\u09ae"},{f:"dgh",r:"\u09a6\u09cd\u0998"},{f:"ddh",r:"\u09a6\u09cd\u09a7"},{f:"dbh",r:"\u09a6\u09cd\u09ad"},
{f:"dv",r:"\u09a6\u09cd\u09ad"},{f:"dm",r:"\u09a6\u09cd\u09ae"},{f:"DD",r:"\u09a1\u09cd\u09a1"},{f:"Dh",r:"\u09a2"},{f:"dh",r:"\u09a7"},{f:"dg",r:"\u09a6\u09cd\u0997"},{f:"dd",r:"\u09a6\u09cd\u09a6"},{f:"D",r:"\u09a1"},{f:"d",r:"\u09a6"},{f:"...",r:"..."},{f:".`",r:"."},{f:"..",r:"\u0964\u0964"},{f:".",r:"\u0964"},{f:"ghn",r:"\u0998\u09cd\u09a8"},{f:"Ghn",r:"\u0998\u09cd\u09a8"},
{f:"gdh",r:"\u0997\u09cd\u09a7"},{f:"Gdh",r:"\u0997\u09cd\u09a7"},{f:"gN",r:"\u0997\u09cd\u09a3"},{f:"GN",r:"\u0997\u09cd\u09a3"},{f:"gn",r:"\u0997\u09cd\u09a8"},{f:"Gn",r:"\u0997\u09cd\u09a8"},{f:"gm",r:"\u0997\u09cd\u09ae"},{f:"Gm",r:"\u0997\u09cd\u09ae"},{f:"gl",r:"\u0997\u09cd\u09b2"},{f:"Gl",r:"\u0997\u09cd\u09b2"},{f:"gg",r:"\u099c\u09cd\u099e"},{f:"GG",r:"\u099c\u09cd\u099e"},{f:"Gg",
r:"\u099c\u09cd\u099e"},{f:"gG",r:"\u099c\u09cd\u099e"},{f:"gh",r:"\u0998"},{f:"Gh",r:"\u0998"},{f:"g",r:"\u0997"},{f:"G",r:"\u0997"},{f:"hN",r:"\u09b9\u09cd\u09a3"},{f:"hn",r:"\u09b9\u09cd\u09a8"},{f:"hm",r:"\u09b9\u09cd\u09ae"},{f:"hl",r:"\u09b9\u09cd\u09b2"},{f:"h",r:"\u09b9"},{f:"jjh",r:"\u099c\u09cd\u099d"},{f:"jNG",r:"\u099c\u09cd\u099e"},{f:"jh",r:"\u099d"},{f:"jj",
r:"\u099c\u09cd\u099c"},{f:"j",r:"\u099c"},{f:"J",r:"\u099c"},{f:"kkhN",r:"\u0995\u09cd\u09b7\u09cd\u09a3"},{f:"kShN",r:"\u0995\u09cd\u09b7\u09cd\u09a3"},{f:"kkhm",r:"\u0995\u09cd\u09b7\u09cd\u09ae"},{f:"kShm",r:"\u0995\u09cd\u09b7\u09cd\u09ae"},{f:"kxN",r:"\u0995\u09cd\u09b7\u09cd\u09a3"},{f:"kxm",r:"\u0995\u09cd\u09b7\u09cd\u09ae"},{f:"kkh",r:"\u0995\u09cd\u09b7"},{f:"kSh",r:"\u0995\u09cd\u09b7"},{f:"ksh",
r:"\u0995\u09b6"},{f:"kx",r:"\u0995\u09cd\u09b7"},{f:"kk",r:"\u0995\u09cd\u0995"},{f:"kT",r:"\u0995\u09cd\u099f"},{f:"kt",r:"\u0995\u09cd\u09a4"},{f:"kl",r:"\u0995\u09cd\u09b2"},{f:"ks",r:"\u0995\u09cd\u09b8"},{f:"kh",r:"\u0996"},{f:"k",r:"\u0995"},{f:"lbh",r:"\u09b2\u09cd\u09ad"},{f:"ldh",r:"\u09b2\u09cd\u09a7"},{f:"lkh",r:"\u09b2\u0996"},{f:"lgh",r:"\u09b2\u0998"},{f:"lph",r:"\u09b2\u09ab"},
{f:"lk",r:"\u09b2\u09cd\u0995"},{f:"lg",r:"\u09b2\u09cd\u0997"},{f:"lT",r:"\u09b2\u09cd\u099f"},{f:"lD",r:"\u09b2\u09cd\u09a1"},{f:"lp",r:"\u09b2\u09cd\u09aa"},{f:"lv",r:"\u09b2\u09cd\u09ad"},{f:"lm",r:"\u09b2\u09cd\u09ae"},{f:"ll",r:"\u09b2\u09cd\u09b2"},{f:"lb",r:"\u09b2\u09cd\u09ac"},{f:"l",r:"\u09b2"},{f:"mth",r:"\u09ae\u09cd\u09a5"},{f:"mph",r:"\u09ae\u09cd\u09ab"},{f:"mbh",r:"\u09ae\u09cd\u09ad"},
{f:"mpl",r:"\u09ae\u09aa\u09cd\u09b2"},{f:"mn",r:"\u09ae\u09cd\u09a8"},{f:"mp",r:"\u09ae\u09cd\u09aa"},{f:"mv",r:"\u09ae\u09cd\u09ad"},{f:"mm",r:"\u09ae\u09cd\u09ae"},{f:"ml",r:"\u09ae\u09cd\u09b2"},{f:"mb",r:"\u09ae\u09cd\u09ac"},{f:"mf",r:"\u09ae\u09cd\u09ab"},{f:"m",r:"\u09ae"},{f:"0",r:"\u09e6"},{f:"1",r:"\u09e7"},{f:"2",r:"\u09e8"},{f:"3",r:"\u09e9"},{f:"4",r:"\u09ea"},
{f:"5",r:"\u09eb"},{f:"6",r:"\u09ec"},{f:"7",r:"\u09ed"},{f:"8",r:"\u09ee"},{f:"9",r:"\u09ef"},{f:"NgkSh",r:"\u0999\u09cd\u0995\u09cd\u09b7"},{f:"Ngkkh",r:"\u0999\u09cd\u0995\u09cd\u09b7"},{f:"NGch",r:"\u099e\u09cd\u099b"},{f:"Nggh",r:"\u0999\u09cd\u0998"},{f:"Ngkh",r:"\u0999\u09cd\u0996"},{f:"NGjh",r:"\u099e\u09cd\u099d"},{f:"ngOU",r:"\u0999\u09cd\u0997\u09cc"},{f:"ngOI",r:"\u0999\u09cd\u0997\u09c8"},
{f:"Ngkx",r:"\u0999\u09cd\u0995\u09cd\u09b7"},{f:"NGc",r:"\u099e\u09cd\u099a"},{f:"nch",r:"\u099e\u09cd\u099b"},{f:"njh",r:"\u099e\u09cd\u099d"},{f:"ngh",r:"\u0999\u09cd\u0998"},{f:"Ngk",r:"\u0999\u09cd\u0995"},{f:"Ngx",r:"\u0999\u09cd\u09b7"},{f:"Ngg",r:"\u0999\u09cd\u0997"},{f:"Ngm",r:"\u0999\u09cd\u09ae"},{f:"NGj",r:"\u099e\u09cd\u099c"},{f:"ndh",r:"\u09a8\u09cd\u09a7"},{f:"nTh",r:"\u09a8\u09cd\u09a0"},
{f:"NTh",r:"\u09a3\u09cd\u09a0"},{f:"nth",r:"\u09a8\u09cd\u09a5"},{f:"nkh",r:"\u0999\u09cd\u0996"},{f:"ngo",r:"\u0999\u09cd\u0997"},{f:"nga",r:"\u0999\u09cd\u0997\u09be"},{f:"ngi",r:"\u0999\u09cd\u0997\u09bf"},{f:"ngI",r:"\u0999\u09cd\u0997\u09c0"},{f:"ngu",r:"\u0999\u09cd\u0997\u09c1"},{f:"ngU",r:"\u0999\u09cd\u0997\u09c2"},{f:"nge",r:"\u0999\u09cd\u0997\u09c7"},{f:"ngO",r:"\u0999\u09cd\u0997\u09cb"},
{f:"NDh",r:"\u09a3\u09cd\u09a2"},{f:"nsh",r:"\u09a8\u09b6"},{f:"Ngr",r:"\u0999\u09b0"},{f:"NGr",r:"\u099e\u09b0"},{f:"ngr",r:"\u0982\u09b0"},{f:"nj",r:"\u099e\u09cd\u099c"},{f:"Ng",r:"\u0999"},{f:"NG",r:"\u099e"},{f:"nk",r:"\u0999\u09cd\u0995"},{f:"ng",r:"\u0982"},{f:"nn",r:"\u09a8\u09cd\u09a8"},{f:"NN",r:"\u09a3\u09cd\u09a3"},{f:"Nn",r:"\u09a3\u09cd\u09a8"},{f:"nm",r:"\u09a8\u09cd\u09ae"},
{f:"Nm",r:"\u09a3\u09cd\u09ae"},{f:"nd",r:"\u09a8\u09cd\u09a6"},{f:"nT",r:"\u09a8\u09cd\u099f"},{f:"NT",r:"\u09a3\u09cd\u099f"},{f:"nD",r:"\u09a8\u09cd\u09a1"},{f:"ND",r:"\u09a3\u09cd\u09a1"},{f:"nt",r:"\u09a8\u09cd\u09a4"},{f:"ns",r:"\u09a8\u09cd\u09b8"},{f:"nc",r:"\u099e\u09cd\u099a"},{f:"n",r:"\u09a8"},{f:"N",r:"\u09a3"},{f:"OI`",r:"\u09c8"},{f:"OU`",r:"\u09cc"},{f:"O`",r:"\u09cb"},
{f:"OI",r:"\u09c8",u:[{m:[{t:"p",s:"!c"}],r:"\u0990"},{m:[{t:"p",s:"p"}],r:"\u0990"}]},{f:"OU",r:"\u09cc",u:[{m:[{t:"p",s:"!c"}],r:"\u0994"},{m:[{t:"p",s:"p"}],r:"\u0994"}]},{f:"O",r:"\u09cb",u:[{m:[{t:"p",s:"!c"}],r:"\u0993"},{m:[{t:"p",s:"p"}],r:"\u0993"}]},{f:"phl",
r:"\u09ab\u09cd\u09b2"},{f:"pT",r:"\u09aa\u09cd\u099f"},{f:"pt",r:"\u09aa\u09cd\u09a4"},{f:"pn",r:"\u09aa\u09cd\u09a8"},{f:"pp",r:"\u09aa\u09cd\u09aa"},{f:"pl",r:"\u09aa\u09cd\u09b2"},{f:"ps",r:"\u09aa\u09cd\u09b8"},{f:"ph",r:"\u09ab"},{f:"fl",r:"\u09ab\u09cd\u09b2"},{f:"f",r:"\u09ab"},{f:"p",r:"\u09aa"},{f:"rri`",r:"\u09c3"},{f:"rri",r:"\u09c3",u:[{m:[{t:"p",s:"!c"}],
r:"\u098b"},{m:[{t:"p",s:"p"}],r:"\u098b"}]},{f:"rrZ",r:"\u09b0\u09b0\u200d\u09cd\u09af"},{f:"rry",r:"\u09b0\u09b0\u200d\u09cd\u09af"},{f:"rZ",r:"\u09b0\u200d\u09cd\u09af",u:[{m:[{t:"p",s:"c"},{t:"p",s:"!e",v:"r"},{t:"p",s:"!e",v:"y"},{t:"p",s:"!e",v:"w"},{t:"p",s:"!e",v:"x"}],r:"\u09cd\u09b0\u09cd\u09af"}]},{f:"ry",
r:"\u09b0\u200d\u09cd\u09af",u:[{m:[{t:"p",s:"c"},{t:"p",s:"!e",v:"r"},{t:"p",s:"!e",v:"y"},{t:"p",s:"!e",v:"w"},{t:"p",s:"!e",v:"x"}],r:"\u09cd\u09b0\u09cd\u09af"}]},{f:"rr",r:"\u09b0\u09b0",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!vowel"},{t:"s",s:"!e",v:"r"},{t:"s",s:"!p"}],r:"\u09b0\u09cd"},
{m:[{t:"p",s:"c"},{t:"p",s:"!e",v:"r"}],r:"\u09cd\u09b0\u09b0"}]},{f:"Rg",r:"\u09a1\u09bc\u09cd\u0997"},{f:"Rh",r:"\u09a2\u09bc"},{f:"R",r:"\u09a1\u09bc"},{f:"r",r:"\u09b0",u:[{m:[{t:"p",s:"c"},{t:"p",s:"!e",v:"r"},{t:"p",s:"!e",v:"y"},{t:"p",s:"!e",v:"w"},{t:"p",s:"!e",v:"x"},{t:"p",s:"!e",
v:"Z"}],r:"\u09cd\u09b0"}]},{f:"shch",r:"\u09b6\u09cd\u099b"},{f:"ShTh",r:"\u09b7\u09cd\u09a0"},{f:"Shph",r:"\u09b7\u09cd\u09ab"},{f:"Sch",r:"\u09b6\u09cd\u099b"},{f:"skl",r:"\u09b8\u09cd\u0995\u09cd\u09b2"},{f:"skh",r:"\u09b8\u09cd\u0996"},{f:"sth",r:"\u09b8\u09cd\u09a5"},{f:"sph",r:"\u09b8\u09cd\u09ab"},{f:"shc",r:"\u09b6\u09cd\u099a"},{f:"sht",r:"\u09b6\u09cd\u09a4"},{f:"shn",r:"\u09b6\u09cd\u09a8"},
{f:"shm",r:"\u09b6\u09cd\u09ae"},{f:"shl",r:"\u09b6\u09cd\u09b2"},{f:"Shk",r:"\u09b7\u09cd\u0995"},{f:"ShT",r:"\u09b7\u09cd\u099f"},{f:"ShN",r:"\u09b7\u09cd\u09a3"},{f:"Shp",r:"\u09b7\u09cd\u09aa"},{f:"Shf",r:"\u09b7\u09cd\u09ab"},{f:"Shm",r:"\u09b7\u09cd\u09ae"},{f:"spl",r:"\u09b8\u09cd\u09aa\u09cd\u09b2"},{f:"sk",r:"\u09b8\u09cd\u0995"},{f:"Sc",r:"\u09b6\u09cd\u099a"},{f:"sT",r:"\u09b8\u09cd\u099f"},
{f:"st",r:"\u09b8\u09cd\u09a4"},{f:"sn",r:"\u09b8\u09cd\u09a8"},{f:"sp",r:"\u09b8\u09cd\u09aa"},{f:"sf",r:"\u09b8\u09cd\u09ab"},{f:"sm",r:"\u09b8\u09cd\u09ae"},{f:"sl",r:"\u09b8\u09cd\u09b2"},{f:"sh",r:"\u09b6"},{f:"Sc",r:"\u09b6\u09cd\u099a"},{f:"St",r:"\u09b6\u09cd\u09a4"},{f:"Sn",r:"\u09b6\u09cd\u09a8"},{f:"Sm",r:"\u09b6\u09cd\u09ae"},{f:"Sl",r:"\u09b6\u09cd\u09b2"},{f:"Sh",r:"\u09b7"},
{f:"s",r:"\u09b8"},{f:"S",r:"\u09b6"},{f:"oo`",r:"\u09c1"},{f:"oo",r:"\u09c1",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u0989"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0989"}]},{f:"o`",r:""},{f:"oZ",r:"\u0985\u09cd\u09af"},{f:"o",r:"",u:[{m:[{t:"p",s:"vowel"},{t:"p",s:"!e",v:"o"}],
r:"\u0993"},{m:[{t:"p",s:"vowel"},{t:"p",s:"e",v:"o"}],r:"\u0985"},{m:[{t:"p",s:"p"}],r:"\u0985"}]},{f:"tth",r:"\u09a4\u09cd\u09a5"},{f:"t``",r:"\u09ce"},{f:"TT",r:"\u099f\u09cd\u099f"},{f:"Tm",r:"\u099f\u09cd\u09ae"},{f:"Th",r:"\u09a0"},{f:"tn",r:"\u09a4\u09cd\u09a8"},{f:"tm",r:"\u09a4\u09cd\u09ae"},{f:"th",r:"\u09a5"},{f:"tt",r:"\u09a4\u09cd\u09a4"},
{f:"T",r:"\u099f"},{f:"t",r:"\u09a4"},{f:"aZ",r:"\u0985\u09cd\u09af\u09be"},{f:"AZ",r:"\u0985\u09cd\u09af\u09be"},{f:"a`",r:"\u09be"},{f:"A`",r:"\u09be"},{f:"a",r:"\u09be",u:[{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0986"},{m:[{t:"p",s:"!c"},{t:"p",s:"!e",v:"a"},{t:"s",s:"!e",v:"`"}],r:"\u09af\u09bc\u09be"},
{m:[{t:"p",s:"e",v:"a"},{t:"s",s:"!e",v:"`"}],r:"\u0986"}]},{f:"i`",r:"\u09bf"},{f:"i",r:"\u09bf",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u0987"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0987"}]},{f:"I`",r:"\u09c0"},{f:"I",r:"\u09c0",u:[{m:[{t:"p",s:"!c"},{t:"s",
s:"!e",v:"`"}],r:"\u0988"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0988"}]},{f:"u`",r:"\u09c1"},{f:"u",r:"\u09c1",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u0989"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0989"}]},{f:"U`",r:"\u09c2"},{f:"U",r:"\u09c2",u:[{m:[{t:"p",
s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u098a"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u098a"}]},{f:"ee`",r:"\u09c0"},{f:"ee",r:"\u09c0",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u0988"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u0988"}]},{f:"e`",r:"\u09c7"},{f:"e",
r:"\u09c7",u:[{m:[{t:"p",s:"!c"},{t:"s",s:"!e",v:"`"}],r:"\u098f"},{m:[{t:"p",s:"p"},{t:"s",s:"!e",v:"`"}],r:"\u098f"}]},{f:"z",r:"\u09af"},{f:"Z",r:"\u09cd\u09af"},{f:"y",r:"\u09cd\u09af",u:[{m:[{t:"p",s:"!c"},{t:"p",s:"!p"}],r:"\u09af\u09bc"},{m:[{t:"p",s:"p"}],r:"\u0987\u09af\u09bc"}]},
{f:"Y",r:"\u09af\u09bc"},{f:"q",r:"\u0995"},{f:"w",r:"\u0993",u:[{m:[{t:"p",s:"p"},{t:"s",s:"vowel"}],r:"\u0993\u09af\u09bc"},{m:[{t:"p",s:"c"}],r:"\u09cd\u09ac"}]},{f:"x",r:"\u0995\u09cd\u09b8",u:[{m:[{t:"p",s:"p"}],r:"\u098f\u0995\u09cd\u09b8"}]},{f:":`",r:":"},{f:":",r:"\u0983"},{f:"^`",r:"^"},{f:"^",r:"\u0981"},
{f:",,",r:"\u09cd\u200c"},{f:",",r:","},{f:"$",r:"\u09f3"},{f:"`",r:""}],vowel:"aeiou",c:"bcdfghjklmnpqrstvwxyz",casesensitive:"oiudgjnrstyz"}};
(function(d){var b={opt:{bn:!0},callback:null,init:function(a,c){a&&d.extend(b.opt,a);if(c&&typeof c==="function")b.callback=c,c(b.opt.bn);return this.each(function(){d(this).bind("keydown.avro",b.keydown);d(this).bind("keypress.avro",b.keypress)})},destroy:function(){return this.each(function(){d(this).unbind(".avro")})},keypress:function(a){var c=a.keyCode||a.which||a.charCode,a=a.currentTarget||a.target||a.srcElement;b.opt.bn&&(c===32||c===13||c===9)&&b.replace(a)},keydown:function(a){if((a.keyCode||
a.which||a.charCode)===77&&a.ctrlKey&&!a.altKey&&!a.shiftKey)b.opt.bn=!b.opt.bn,typeof b.callback==="function"&&b.callback(b.opt.bn),a.preventDefault()},replace:function(a){var c=b.getCaret(a),e=b.findLast(a,c),d=OmicronLab.Avro.Phonetic.parse(a.value.substring(e,c));document.selection?(a=document.selection.createRange(),a.moveStart("character",-1*Math.abs(c-e)),a.text=d,a.collapse(!0)):(a.value=a.value.substring(0,e)+d+a.value.substring(c),a.selectionStart=a.selectionEnd=c-(Math.abs(c-e)-d.length))},
findLast:function(a,c){for(var b=c-1;a.value.charAt(b)!==" "&&b>0;)b--;return b},getCaret:function(a){if(a.selectionStart)return a.selectionStart;else if(document.selection){a.focus();var b=document.selection.createRange();if(b==null)return 0;var a=a.createTextRange(),d=a.duplicate();a.moveToBookmark(b.getBookmark());d.setEndPoint("EndToStart",a);return d.text.length}return 0}};d.fn.avro=function(a){if(b[a])return b[a].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof a==="object"||
!a)return b.init.apply(this,arguments);else d.error("Method "+a+" does not exist on jQuery.avro")}})(jQuery);;
// ==UserScript==
// @author        Crend King
// @version       1.0.4
// @name          Textarea Backup with expiry
// @namespace     http://www.cs.ucsc.edu/~kjin
// @description   Retains text entered into textareas, and expires after certain time span.
// @include       http://*
// @include       https://*
// @exclude       http://mail.google.com
// @exclude       https://mail.google.com
// ==/UserScript==

// this script is based on http://userscripts.org/scripts/review/7671

// check latest version at http://userscripts.org/scripts/show/42879

/*

version history

1.0.4 on 04/22/2009:
- Synchronize with the original Textarea Backup script.

1.0.3 on 03/08/2009:
- Add "ask overwrite" option.

1.0.2 on 03/04/2009:
- Add "keep after submission" option.

1.0.1 on 02/22/2009:
- Extract the expiry time stamp codes to stand-alone functions.

1.0 on 02/21/2009:
- Initial version.

*/


///// preference section /////

// backup when keypress event triggers
const keypress_backup = false;

// backup when textarea loses focus
const blur_backup = true;

// backup at time interval
const timed_backup = true;

// backup time interval, in millisecond
const backup_interval = 10000;

// keep backup even successfully submitted
// make sure expiration is enabled 
const keep_after_submission = false;

// set true to display a confirmation window of restoration
// when the target textarea of is not empty
// set false to skip restoration if not empty
// user still can manually restore using GM menu
const ask_overwrite = true;

// auxiliary variable to compute expiry_timespan
// set all 0 to disable expiration
const expire_after_days = 0;
const expire_after_hours = 1;
const expire_after_minutes = 30;


///// code section /////

// expiry time for a backup, in millisecond
const expiry_timespan = (((expire_after_days * 24) + expire_after_hours) * 60 + expire_after_minutes) * 60000;

function GM_getValueUTF8(key)
{
	var value = GM_getValue(key);
	return (value && value.length) ? decodeURI(value) : '';
}

function GM_setValueUTF8(key, value)
{
	GM_setValue(key, encodeURI(value));
}



SaveTextArea.prototype =
{
	listen: function()
	{
		var self = this;
		// Save buffer every keystrokes.
		if (keypress_backup)
			this.ta.addEventListener('keypress', function(e)
			{
				self.commit(self.ta.value);
			}, true);

		// Save buffer when the textarea loses focus.
		if (blur_backup)
			this.ta.addEventListener('blur', function(e)
			{
				self.commit();
			}, true);

		// Save buffer every second.
		if (timed_backup)
			this._stay_tuned();

		// Should be a method really but there'd be more code to get it to work as
		// expected with event handlers so I won't bother.
		var onsubmit = function(e)
		{
			if (!keep_after_submission)
				GM_deleteValue(self.key());
		};

		var theform = this.ta.form;
		// Delete buffer when the form has been submitted.
		theform.addEventListener('submit', onsubmit, true);

		// Keep a copy of the submit method.
		theform.the_actual_submit_method = theform.submit;
		// Catch direct calls to submit() which doesn't trigger the submit event.
		theform.submit = function()
		{
			onsubmit();
			self.ta.form.the_actual_submit_method();
		};
	},

	_stay_tuned: function()
	{
		var self = this;
		setTimeout(function()
		{
			self.commit();
			self._stay_tuned();
		}, backup_interval);
	},

	restore: function()
	{
		// backup text is in format of "backup_content@save_time",
		// where save_time is the millisecond from Javascript Date object's getTime()
		var buff = remove_time_stamp(GM_getValueUTF8(this.key()));
		
		// Only restore buffer if previously saved (i.e form not submitted).
		if(!is_significant(buff))
			return;
		
		// Check with user before overwriting existing content with backup.
		if (buff != this.ta.textContent && is_significant(this.ta.textContent) && ask_overwrite)
			this._confirm_restore(buff);
		else
			this.ta.value = buff;

		this.previous_backup = this.ta.value;
		var self = this;
		GM_registerMenuCommand(
			'Restore previous backup for ' + this.ref(),
			function() { self.ta.value = self.previous_backup }
		);
	},

	_confirm_restore: function(buff)
	{
		var to_restore = remove_time_stamp(GM_getValueUTF8(this.key()));
		
		// Keep existing border so it's not lost when highlighting.
		this.old_border = this.ta.style.border;

		var msg = "[Textarea Backup] Existing text detected in '" + this.ref()
						+ "', overwrite with this backup?\n\n";
		msg += to_restore.length > 750
				 ? to_restore.substring(0, 500) + "\n..."
				 : to_restore;

		this.confirming = true;
		this.ta.scrollIntoView();
		
		// Highlight the textarea that the confirm message refers to.
		this._highlight_textarea(this.old_border);

		// Let the user see the existing content as Firefox will sometimes
		// maintain the old value.
		this.ta.value = this.ta.textContent;
		if (window.confirm(msg))
			this.ta.value = buff;

		this.confirming = false;
		this.ta.style.border = this.old_border;
	},

	_highlight_textarea: function(border, toggle)
	{
		var self = this;
		
		setTimeout(function(ta_border, toggle)
		{
			if(self.confirming)
			{
				self.ta.style.border = ( toggle ? '3px red solid' : ta_border );
				self._highlight_textarea(ta_border, toggle);
			} else
				self.ta.style.border = this.old_border;
		}, 1000, border, !toggle);

		return this.ta.style.border;
	},

	commit: function()
	{
		this.committed = append_time_stamp(this.ta.value);
		
		// Only save if:
		// a) There's significant text in the <textarea>.
		// b) The text that was there when the page loaded has changed.
		if(is_significant(this.committed) && this.initial_txt != this.committed)
			GM_setValueUTF8( this.key(), this.committed );
	},

	// Rough'n'ready method which should be nicer.
	key: function()
	{
		// If there are two textareas and neither of them have a name or id
		// then they will collide, but a textarea without either would be useless.
		return this.ta.baseURI + ';' + this.ref();
	},

	// Attempt to return the most appropriate textarea reference.
	ref: function()
	{
		return this.ta.id || this.ta.name || '';
	}
};

// expiration check routine
if (expiry_timespan > 0)
{
	// get all associated backups, and compare timestamp now and then
	var curr_time = (new Date()).getTime();
	var stored_bak = GM_listValues();
	for (var i in stored_bak)
	{
		var curr_bak = GM_getValueUTF8(stored_bak[i]);
		var bak_text = remove_time_stamp(curr_bak);
		var bak_time = get_time_stamp(curr_bak);
		
		// also remove empty backups
		if (curr_time - bak_time >= expiry_timespan
			|| !is_significant(bak_text))
		{
			GM_deleteValue(stored_bak[i]);
		}
	}
}

var textareas = document.getElementsByTagName('textarea');
for(var i = 0; i < textareas.length; i++)
{
	var ta = textareas[i];
	// Occasionally a textarea might not have a form, weird.
	if(ta['form'])
		new SaveTextArea(ta);
};
//alert ('test');
var activeta; //active text area, input field

function insertAtCursor(myValue) 
	{
            /**
		 * this function inserts a character at the current cursor position in a text area
		 * many thanks to alex king and phpMyAdmin for this cool function		  
		 * This function is originally found in phpMyAdmin package and modified by Hasin Hayder(http://hasin.wordpress.com) to meet the requirement	 
             */
		var myField = document.getElementById(activeta);
		if (document.selection) {		
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
			sel.collapse(true);
			sel.select();
		}
		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == 0) {
			
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			var scrollTop = myField.scrollTop;
			startPos = (startPos == -1 ? myField.value.length : startPos );
			myField.value = myField.value.substring(0, startPos)
			+ myValue
			+ myField.value.substring(endPos, myField.value.length);
			myField.focus();
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;
			myField.scrollTop = scrollTop;
		} else {
			var scrollTop = myField.scrollTop;
			myField.value += myValue;
			myField.focus();
			myField.scrollTop = scrollTop;
		}
	}
	function makeVirtualEditor(textAreaId)
	{
		activeTextAreaInstance = document.getElementById(textAreaId);
		activeTextAreaInstance.onfocus = function(){activeta=textAreaId;};		
	}



jQuery(document).ready (function ()
{
   
//alert ('test alert');
 var txtAreaId = jQuery (".text-full").attr ('id');
    var optionHtmlForTxtArea = '<input type="radio" name="layoutGrp" onclick="makeUnijoyEditor(\''+txtAreaId+'\');createCookie(\'kbsetting\',\'uni\',30);switched=false;" value="unijoy" checked=true /> ইউনিজয় &nbsp; '
                     + '<input type="radio" name="layoutGrp" onclick="avPhoneticEditor(\''+txtAreaId+'\');switched=true;" value="bangla" /><a href="javascript:void();" title="Phonetic layout"  onclick="openLayout();"> ফোনেটিক </a> &nbsp;'                
                     + '<input type="radio" name="layoutGrp"  onclick="avEngilish();createCookie(\'kbsetting\',\'eng\',30);switched=true;" value="english"/> ইংরেজি ';                
   jQuery (".text-full").before ('<span>'+optionHtmlForTxtArea+'</span>');
   makeUnijoyEditor(txtAreaId);	
   
   /*jQuery ('.text-full').click(function (){
       
       storeCaret(this);
   });*/
       
});

function  avPhoneticEditor(id)
{
    jQuery ('textarea').avro({'bn':true});
    
}

function avEngilish ()
{
   // alert ('english ');
    jQuery('textarea').avro({'bn':false},
    function(isBangla){
       // alert('Bangla enabled = ' + isBangla);
        }
    );
    
}

var newWindow; 
function openLayout()
{
	newWindow = window.open("http://quantummethod.org.bd/sites/default/files/avro-layout.html","","toolbar=yes,scrollbars=yes, resizable=yes,HEIGHT=310,WIDTH=800") ;
}
;

