/**
* Classe que os objectos que pretendem ser representados dentro de uma datagrid
* têm que herdar. Esta classe fornece os métodos necessários que devem ser
* implementados nas subclasses
*/
Control = function()
{
	this.editable = "1";
}

/**
* Devolve o elemento HTML que representa o controlo
*/
Control.prototype.getDocumentElement = function()
{
	alert("Inherited method \"getDocumentElement\" from Control" + " requires implementation.");
}

/**
* Define o elemento HTML que representa o controlo
*/
Control.prototype.setDocumentElement = function(newElement)
{
	alert("Inherited method \"setDocumentElement\" from Control" + " requires implementation.");
}

/**
* Devolve o tipo de edição aceite
*/
Control.prototype.getEditable = function(isAdding)
{
	//	if (isAdding)
	//		return this.editable != '2'; // Editable if 0 or 1
	//	else
	//		return this.editable == '1';
	if (isAdding)
	{
		if (this.editable == '2')
			return false;
		return true;
	}
	else
	{
		if (this.editable == '0' || this.editable == '2' || this.editable == '3')
			return false;
		return true;
	}
}

/**
* Define o tipo de edição aceite
*/
Control.prototype.setEditable = function(mode)
{
	this.editable = mode;
	/*
	CREATE_ONLY = 0,
	NORMAL = 1,
	READ_ONLY = 2,
	CREATE_ONLY_REQUIRED = 3,
	REQUIRED = 4,
	HIDDEN = 5
	*/
	/* Editable States:
	0 - not editable (but editable when adding)	- UPDATE
	1 - editable								- CREATE 
	2 - never editable (even when adding)		- READ, DELETE
	*/
}

Control.prototype.setInvisible = function()
{
	//default behaviour is nothing
}


/**
* Devolve o texto actual do controlo (o que é apresentado ao utilizador)
*/
Control.prototype.getText = function()
{
	alert("Inherited method \"getText\" from Control requires implementation.");
}

Control.prototype.setText = function(newText)
{
	alert("Inherited method \"setText\" from Control requires implementation.");
}

Control.prototype.getValue = function()
{
	alert("Inherited method \"getValue\" from Control requires implementation on " + typeof (this));
}

Control.prototype.setValue = function(newValue)
{
	alert("Inherited method \"setValue\" from Control requires implementation.");
}

/**
* Selecciona o controlo
*/
Control.prototype.select = function()
{
	alert("Inherited method \"select\" from Control" + " requires implementation.");
}

/**
* Desselecciona o controlo
*/
Control.prototype.deselect = function()
{
	if (document.selection)
		document.selection.empty();
	else
		window.getSelection().removeAllRanges();
}

/**
* Actualiza os elementos HTML com os dados do objecto Javascript
*/
Control.prototype.setView = function()
{
	alert("Inherited method \"setView\" from Control" + " requires implementation.");
}

/**
* Actualiza o objecto Javascript com os dados do HTML
*/
Control.prototype.setModel = function()
{
	alert("Inherited method \"setModel\" from Control" + " requires implementation.");
}

/**
* Lista de controlos existentes
*/
Control.existent = new Array();

/**
* Funcao que regista a existencia de um controlo.
* Invocar quando se cria um controlo.
*/
Control.register = function(id, object)
{
	Control.existent[id] = object;
}

/**
* Funcao que devolve um controlo com base no id do elemento que o representa
*/
Control.get = function(id)
{
	return Control.existent[id];
}
