	// ---- TINYMCE ----
	try{
		tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,link,unlink",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,|,forecolor,backcolor",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			width : "500",
			height : "200",
			handle_event_callback            : 'myHandleEvent'
		});
	}catch(e){
	}
	
	function myHandleEvent(e) {
	    if (e.type == 'keyup' || e.type == 'click') {
		    try{
				var textarea = document.getElementById(tinyMCE.activeEditor.id);
				textarea.value = tinyMCE.get(tinyMCE.activeEditor.id).getContent();
			}catch(e){
			}
	    }
	    return true;
	}
	// ---- TINYMCE ----
	
	var LanguageTag = {};
	LanguageTag = function() {};
	LanguageTag = Class.create();
	LanguageTag.prototype = {
		initialize: function(rand, name, property, document) {
			this.rand = rand;
			this.document = document;
			this.name = name;
			this.property = property;
			this.deletetinyMCEContent = true;
		//	alert('property '+property+' name '+name+' rand '+rand);
    		this.lsel = this.document.getElementById('lsel_' + this.rand);
    		this.ltext = this.document.getElementById('ltext_' + this.rand);
    		this.ladd = this.document.getElementById('ladd_' + this.rand);
    		this.ldel = this.document.getElementById('ldel_' + this.rand);
    		
    		this.lsel.onchange= this.lSelOnChange.bindAsEventListener(this);
    		this.ladd.onclick = this.deleteNode.bindAsEventListener(this);
    		this.ldel.onclick = this.addNode.bindAsEventListener(this);
  			for(var i=0; i < this.lsel.length; i++) {
  				var sIndex = this.lsel.options[i].value;
  				var lang = this.lsel.options[i].text;
  				var content = this.document.getElementsByName(this.property + 'Mapped(' + sIndex + ')');;
  				var langText = "";
  				if(content !== null && content.length == 1) {
  					langText = unescape(content[0].value);
  					
  				}
  				if(langText !== null && langText !== "") {
  					this.addElement(lang, sIndex, i);
  				}
  			}
  		},
  		addNode: function(e) {
  			//var coll = this.document.getElementsByName(this.name + '.' + this.property + '.' + this.getSelectedIndexValue());
  			var coll = this.document.getElementsByName(this.property + 'Mapped(' + this.getSelectedIndexValue() + ')');
			var othercoll = coll;
			var input;
			var appendToDOM = false;
			
  				try{
					this.ltext.value  = tinyMCE.get(tinyMCE.activeEditor.id).getContent();
				}catch(e){
				}
			
			if(coll !== null && coll.length > 0 && coll[0].value !== "") {
				this.deletetinyMCEContent = false;
				this.removeElement(this.getSelectedIndexValue() + '_' + this.rand);
				this.deletetinyMCEContent = true;
			}
			
  				if(this.ltext.value !== "") {
  				if(coll !== null && coll.length > 0) {
  					coll[0].value =  unescape(this.ltext.value);
				} else if(coll.length !== 1){
					input = this.document.createElement('input');
					input.type = 'hidden';
					//input.name= this.name + '.' + this.property + '.' + this.getSelectedIndexValue();
					input.name = this.property + 'Mapped(' + this.getSelectedIndexValue() + ')';
					input.id = this.property + 'Mapped(' + this.getSelectedIndexValue() + ')';
					appendToDOM = true;
					input.value = unescape(this.ltext.value);
				}
				
				this.addElement(this.getSelectedIndexText(), this.getSelectedIndexValue(), this.lsel.selectedIndex );
				if(appendToDOM) {
					this.ltext.parentNode.appendChild(input);
				}
				coll = othercoll;
  				} else {
  					alert('Empty description.');
  				}
		 
			return false;
  		},
  		deleteNode: function(e) {
  			//var coll = this.document.getElementsByName(this.name + '.' + this.property + '.' + this.getSelectedIndexValue());
  			var coll = this.document.getElementsByName(this.property + 'Mapped(' + this.getSelectedIndexValue() + ')');
  			if(coll !== null && coll.length == 1 && coll[0].value !== "") {
  				var parent = coll[0].parentNode;
  				coll[0].value = "";
  				this.removeElement(this.getSelectedIndexValue() + '_' + this.rand);
  				this.ltext.value = "";
  			} else {
  				window.alert("Description does not exist.");
  			}
  			return false;
  		},
  		lSelOnChange: function(e) {
			//var coll = this.document.getElementsByName(this.name + "." + this.property + "." + this.getSelectedIndexValue());
			var coll = this.document.getElementsByName(this.property + "Mapped(" + this.getSelectedIndexValue() + ')');
			if(coll !== null && coll.length == 1) {
				this.ltext.value = unescape(coll[0].value);
			} else {
				this.ltext.value = "";
			}
			//TINYMCE ENABLED KONTROLU KONMALI mceCleanup
			try{
				if(tinyMCE != null){
					tinyMCE.get(this.ltext.id).setContent('');
					tinyMCE.get(this.ltext.id).setContent(this.ltext.value);
				}
			}catch(err){
			}
  		},
  		getSelectedIndexValue: function() {
  			return this.lsel.options[this.lsel.selectedIndex].value;
  		},
  		getSelectedIndexText: function() {
  			return this.lsel.options[this.lsel.selectedIndex].text;
  		},
  		addElement: function(e, selIndex, sIndex) {
  			var placeHolder = document.getElementById('setLanguages_' + this.rand);
  		//	alert('placeHolder addelement'+placeHolder[0].value);
		  	var newLink = document.createElement('a');
		  	var newLinkId = selIndex + '_' + this.rand;
		  	var currentLink = document.getElementById(newLinkId);
		  	if(currentLink == null) {
		  	newLink.setAttribute('href','javascript:void(0);');
		  	newLink.innerHTML = '<b><u>' + e + '</u></b> ';
		  	newLink.setAttribute('id', newLinkId);
		  	newLink.onclick = this.updateTextArea.bindAsEventListener(this,selIndex,sIndex);
		  	placeHolder.appendChild(newLink);
		  	}
		 },
		 removeElement: function (e) {
  			var placeHolder = document.getElementById('setLanguages_' + this.rand);
  			var linkToRemove = document.getElementById(e);
  			
  			if(linkToRemove !== null) {
  			placeHolder.removeChild(linkToRemove);
  			}
  			try{
	  			if(deletetinyMCEContent&&tinyMCE != null){
	  				tinyMCE.get(this.ltext.id).setContent('');
	  			}
  			}catch(e){
  			}
		 },
		 updateTextArea: function(e,sIndexVal,sIndex) {
		 	var coll = this.document.getElementsByName(this.property + "Mapped(" + sIndexVal + ')');
		 //	alert(coll[0].value);
		 	if(coll !== null && coll.length == 1) {
				this.ltext.value = unescape(coll[0].value);
			} else {
				this.ltext.value = "";
			}
			this.lsel.selectedIndex = sIndex;
			//TINYMCE ENABLED KONTROLU KONMALI mceCleanup
			try{
				if(tinyMCE != null){
					tinyMCE.get(this.ltext.id).setContent('');
					tinyMCE.get(this.ltext.id).setContent(this.ltext.value);
				}
			}catch(e){
			}
		 }
	};
