/**
*
* egEdit Class
*/
function egEdit(id, title, posX, posY, width, height, container, name, hide) {
	 this.objName = 'edit_'+id;
	 this.id = id;
	 this.name = name;
	 this.value = title;
	 this.x = posX;
	 this.y = posY;
	 this.width = 0;
	 this.height = 0;

	 this.getHeight = egWindow_getHeight;
	 this.getWidth  = egWindow_getWidth;

	 this.show = egWindow_show;
	 this.hide = egWindow_hide;
	 this.moveTo = egWindow_moveTo;
	 this.displayAt = egWindow_displayAt;

	 this.active = 0;

	 this.getValue = egEdit_getValue;
	 this.setValue = egEdit_setValue;

	 this.setReadonly = egEdit_setReadonly;
	 
	 this.setActive = egEdit_setActive;
	 this.setInactive = egEdit_setInactive;

	 this.onChange = egEdit_onChangeHandler;

   if (!container) {
      container = 'easy-GUI_mainLayer';
   }
	 divRoot = document.getElementById(container);

	 var pos;
	 var value = this.value;
	 var currentValue = '';

	 while((pos = value.indexOf('<br />')) >= 0 ) {
	 		currentValue += value.substring(0, pos) + '\n';
	 		value = value.substring(pos+6, value.length);
	 }

	 this.value = currentValue + value;

	 if(height > 18) {
	 		divRoot.innerHTML += '<div id="' + this.id + '" class="egEditFrame"><textarea name="' + this.name + '" id="' + this.id + '_value" cols="1000" rows="1000" class="egEdit" onChange="egEdit_onChange(this.id);">' + this.value + '</textarea></div>';
	 }
	 else {
      var type = 'edit';
      if(hide) {
        type = 'password';
      }
	 		divRoot.innerHTML += '<div id="' + this.id + '" class="egEditFrame" style="height: 15px;"><input id="' + this.id + '_value" name="' + this.name + '" class="egEdit" type="' + type + '" value="' + this.value + '" onChange="egEdit_onChange(this.id);" onKeyPress="cancelBubble(arguments[0]); return egEdit_preventCRKey(event);" /></div>';
	 }

	 div = document.getElementById(this.id);
	 div.style.width = width+'px';
	 div.style.height = (height-3)+'px';
	 div.style.left = posX+'px';
	 div.style.top  = posY+'px';

	 inputItem = document.getElementById(this.id+'_value');
	 if(height > 18) {
		 inputItem.style.height = (height-4)+'px';
	 }
}

function egEdit_preventCRKey(e){
	var key = (window.event)? window.event.keyCode : e.which;
	if(key == 13) return false;
	return true;
}

function egEdit_getValue(){
	this.value = document.getElementById(this.id+'_value').value;
	return this.value;
}

function egEdit_setValue(value){
	this.value = value;
  document.getElementById(this.id+'_value').value = value;
}

function egEdit_setReadonly(){
	document.getElementById(this.id+'_value').readOnly = true;
}

function egEdit_setActive(){
	if(!this.active) {
    this.active = 1;
    this.setClassName();
	}
}

function egEdit_setInactive(){
	if(this.active) {
    this.active = 0;
    this.setClassName();
	}
}

function egEdit_onChangeHandler() {
}

function egEdit_onChange(id) {
	var append = '_value';
	if(typeof(egObjectsArray['edit_'+id.substr(0, id.length-(append.length))].onChange) =='function') {
		egObjectsArray['edit_'+id.substr(0, id.length-(append.length))].onChange();
	}
}
