/**
 * @class Constructor of the MandatoriesFields object<br>
 * This is used to manage mandatories fields in an obect update
 *
 * @return The created MandatoriesFields object
 * @constructor
 */
function MandatoriesFields() {

	/**
	 * Table with all mandatories fields
	 * @type Array
	 */
	this.mandatories = new Array();



	/**
	 * Add a mandatory field
	 *
	 * @param {String} id Id of the mandatory field (name of the field in the form - the span containing the mandatory star must be named name_mandatory)
	 */
	this.add = function(id) {		
		for (x = 0 ; x < this.mandatories.length ; x++) {
			if (this.mandatories[x] == id) {
				return;
			}	
		}
		this.mandatories[this.mandatories.length] = id;
		document.getElementById(id + "_mandatory").style.display = 'inline';
	}



	/**
	 * Remove a mandatory field
	 *
	 * @param {String} id Id of the mandatory field
	 */
	this.remove = function(id) {
		var index = -1;
		for (x = 0 ; x < this.mandatories.length ; x++) {
			if (this.mandatories[x] == id) {
				index = x;
			}	
		}
		if (index != -1) {
			this.mandatories.splice(index,1);
			document.getElementById(id + "_mandatory").style.display = 'none';
		}
	}	



	/**
	 * Verify all mandatory fields (runs on date, text, combobox and lists)
	 *
	 * @return {Boolean} True if all mandatory fields are filled, false else
	 */
	this.verify = function() {
		var result = true;
		for (x = 0 ; x < this.mandatories.length ; x++) {
			if(((document.getElementById(this.mandatories[x]).type)?(document.getElementById(this.mandatories[x]).type.toString().charAt(0) == "s" && document.getElementById(this.mandatories[x]).selectedIndex == -1):false)
				 	|| (document.getElementById(this.mandatories[x]).value == "")
				 	|| (document.getElementById(this.mandatories[x]).tagName == "TABLE" && document.getElementById(this.mandatories[x]).tBodies[0].childNodes[0].className == "empty")) {
				document.getElementById((this.mandatories[x]) + "_mandatory").parentNode.className = "titleError";
				result = false;
			}
			else
				document.getElementById((this.mandatories[x]) + "_mandatory").parentNode.className = "title";
		}
		return result;
	}
}