	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;
		//	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;
			if(coll !== null && coll.length > 0 && coll[0].value !== "") {
				window.alert("Description already exists.");
  			} else {
  				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 = "";
			}
  		},
  		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);
  			}
		 },
		 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;
		 }
	};