/* ========================================================
Marco Bevilacqua 20050323
Oggetto di tipo wordedit 
 ======================================================== */
function BaseElement(IDElement,IDElementFocus,Label,Posizione,Obbligatorio,Lingua) {
   this.IDElement = IDElement || null;				// Campo principale associato all'elemento. Esempio: Testo1
   this.IDElementFocus = IDElementFocus || null;	// Campo a cui verrā dato il focus
   this.PopupUpload = false;						// Indica se il campo richiede la visualizzazione del popup di Upload
   // Informazioni per i messaggi di output
   this.Label = Label  || '-';						// Label associata al campo
   this.Posizione = Posizione || '-';				// Posizione dell'elemento nella object
   this.Obbligatorio = Obbligatorio;				// Indica se occorre compilare il campo
   this.Lingua = Lingua || null;					// Lingua associata al campo
	 this.IDTab = null;	// Tab di appartenenza del controllo
}

function baseElement_focus() {
  if (this.IDElementFocus != null)
		this.IDElementFocus.focus();
}

// Indica se il campo č stato compilato
function baseElement_isCompiledElement() {
  if (this.IDElement == null) {
  	return false;
  }else  if (eval(this.IDElement.value != "")) {
		return true;
  }  
  return false;
}

// Indica se il campo č stato compilato correttamente
function baseElement_checkElement() {
  return true;
}

function baseElement_impostaElement() {
	return true;
}

// Indica se il componente č stato caricato
function baseElement_isLoad() {
	return true;
}

// Inizializza l'elemento
function baseElement_init() {
}

// Clear dell'elemento
function baseElement_clear() {
	this.IDElement.value = "";
}
 
 new BaseElement(null,null,null,null,false,null);
 BaseElement.prototype.isCompiledElement = baseElement_isCompiledElement;
 BaseElement.prototype.checkElement = baseElement_checkElement;
 BaseElement.prototype.impostaElement = baseElement_impostaElement;
 BaseElement.prototype.isLoad = baseElement_isLoad;
 BaseElement.prototype.init = baseElement_init;
 BaseElement.prototype.focus = baseElement_focus;
 BaseElement.prototype.clear = baseElement_clear;
 
 // CAMPO RELAZIONE
 /*
 	IDTemplateField = identifica la relazione
 */
function RelazioneElement(IDTemplateField, IDFolder, IDOggetto, IDElementCollection, TypeCollection, txtStrAgganciati, Label, Posizione, Obbligatorio, Lingua) {
	this.IDTemplateField = IDTemplateField || null;
	this.IDFolder = IDFolder || null;
	this.IDOggetto = IDOggetto || null;
	this.IDElementCollection = IDElementCollection || null;
	this.TypeCollection = TypeCollection || null;
	this.txtStrAgganciati = txtStrAgganciati || null;
	// Ereditarietā del controllo
	this.base = BaseElement;
	this.base(this.IDTemplateField, null, Label, Posizione, Obbligatorio, Lingua);
}

// Imposta gli oggetti collegati alla relazione
function relazioneElement_setBoundElements(idElementCollection, typeCollection, strAgganciati) {
	this.IDElementCollection.value = idElementCollection;
	this.TypeCollection.value = typeCollection;
	this.txtStrAgganciati.innerHTML = strAgganciati;
}

// Restituisce l'elenco degli oggetti collegati alla relazione
/*
function relazioneElement_getBoundElements(idElementCollection, typeCollection) {
	idElemenCollection = this.IDElementCollection.value;
	typeCollection = this.TypeCollection.value;
}
*/

// Indica se il campo č stato compilato
function relazioneElement_isCompiledElement() {
  if (this.IDElementCollection.value == '') {
  	return false;
  } else {
	  return true;
	}
}

function relazioneElement_clear() {
	this.SetBoundElements('','', '');
}

// Apre la maschera di impostazione della relazione
function relazioneElement_openSetElementsWindow(lingua) {
	var url = '/admin/impostaRelazione.asp?LN=' + lingua + '&IDTemplateField=' + this.IDTemplateField + '&IDFolder=' + this.IDFolder + '&IDOggetto=' + this.IDOggetto + '&IDElementCollection=' + this.IDElementCollection.value + '&TypeCollection=' + this.TypeCollection.value;
	window.showModalDialog('container.asp?src=' + escape(url), this, 'dialogHeight:600px;dialogWidth:750px;resizable:yes;unadorned:yes');
}

new RelazioneElement(null, null, null, null, null, null, null, null, null);
RelazioneElement.prototype = new BaseElement;
RelazioneElement.prototype.SetBoundElements = relazioneElement_setBoundElements;
//RelazioneElement.prototype.GetBoundElements = relazioneElement_getBoundElements;
RelazioneElement.prototype.OpenSetElementsWindow = relazioneElement_openSetElementsWindow;
RelazioneElement.prototype.isCompiledElement = relazioneElement_isCompiledElement;
RelazioneElement.prototype.clear = relazioneElement_clear;

 // WORDEDIT ELEMENT
 
function WordEditElement(formField,frame) {
	// Campo hydden in cui č memorizzato il contenuto del wordedit
	this.formField = formField;

	// Frame di appoggio per la visualizzazione della preview
	this.frame = frame;

	// Href per l'eventuale foglio di stile
	this.stylesheet = null;
	// Elenco degli stili utilizzabili
	this.enstyles = null;
	
  // Ereditarietā del controllo
	this.base = BaseElement;
  this.base(this.formField,null,null,null,null,null);

}	 


// Dā il fuoco al controllo
function wordeditElement_focus() {
}

// Indica se il controllo č stato inizializzato
function wordeditElement_isLoad() {
	return true;
}

// Inializzazione del controllo
function wordeditElement_init() {
	this.sincroFrame();
}

// Legge il contenuto attuale del wordedit
function wordeditElement_read() {
	return this.formField.value;
}

// Scrivi l'HTML indicato nel wordedit
function wordeditElement_write(myHTML) {
	// Impostazione del campo nel form
	this.formField.value = myHTML;
	
	// Impostazione del frame di preview
	this.sincroFrame();
}

// Allinea il contenuto del frame al contenuto del campo hydden
function wordeditElement_sincroFrame() {
	this.frame.window.document.open();
	if (this.stylesheet != null)
		this.frame.window.document.writeln('<link rel="stylesheet" type="text/css" href="' + this.stylesheet + '">');
	this.frame.window.document.write(this.formField.value);
	this.frame.window.document.close();
}

// Clear del controllo
function wordeditElement_clear() {
	this.write('');
}

new WordEditElement(null,null);
WordEditElement.prototype = new BaseElement;
WordEditElement.prototype.focus =  wordeditElement_focus;
WordEditElement.prototype.isLoad = wordeditElement_isLoad;
WordEditElement.prototype.init = wordeditElement_init;
WordEditElement.prototype.read =  wordeditElement_read;
WordEditElement.prototype.write =  wordeditElement_write;
WordEditElement.prototype.sincroFrame =  wordeditElement_sincroFrame;
WordEditElement.prototype.clear = wordeditElement_clear;

/*==========================================================
	Oggetto tipo Radio
	=========================================================== */
function RadioElement(IDElement,IDElementFocus,Label,Posizione,Obbligatorio,Lingua) {
  this.base = BaseElement;
  this.base(IDElement,IDElementFocus,Label,Posizione,Obbligatorio,Lingua);
}

// Indica se il campo č stato compilato
function radioElement_isCompiledElement() {
  if (this.IDElement == null) {
  	return false;
  } else {
		var compilato = false;
		for (var count = 0; count < this.IDElement.length; count++)
			compilato = compilato || this.IDElement[count].checked;		
		if (compilato)
			return true;
		else
			return false;
  }
}

// Clear del controllo
function radioElement_clear() {
	for (var count = 0; count < this.IDElement.length; count++)
		this.IDElement[count].checked = false;	
}

new RadioElement(null,null,null,null,false,null);
RadioElement.prototype = new BaseElement;
RadioElement.prototype.isCompiledElement = radioElement_isCompiledElement;
RadioElement.prototype.clear = radioElement_clear;

/* ========================================================
	NODE LIST
======================================================== */
function NodeListALivelli(Level,IDNode,Name,ParentNode) {
	this.Level = Level;							// Livello raggiunto nella struttura ad albero
	this.IDNode = IDNode;						// Identificativo - assieme al livello - del nodo corrente
	this.Name = Name;								// Nome associato al nodo corrente
	this.ParentNode = ParentNode;		// Nodo padre
	this.Child = new Array();				// Figli del nodo
}

// Aggiunge un nodo figlio
// children = oggrtto del tipo NodeListALivelli
function NodeList_addChild(children) {
	this.Child[this.Child.length] = children;
}
