//

function TigerColleague(cID) {
	this.id = cID;
//	this.ColleagueNumber = 0;
	this.Compulsory = false;
	this.IsVisible = true;
	this.IsDisabled = false;
	this.Fields = new Array();

}


TigerColleague.prototype.Remove = function () {
	document.getElementById(this.id).style.display = "none";
}

// AddField - add a new TigerField object
TigerColleague.prototype.AddField = function (cFieldName, cNiceName) {
	this.Fields[cFieldName] = new TigerField(cFieldName, cNiceName);
	this.Fields[cFieldName].parent = this;
	this.Fields[cFieldName].Form = this.Form;
	return this.Fields[cFieldName];
}

// SetAllConditionals - loop through all fields, and call the SetConditionals method
TigerColleague.prototype.SetConditionals = function () {
	for (var Field in this.Fields) {
		this.Fields[Field].SetConditionals();
	}
}


// SetAllClasses - loop through all fields, and call the SetClasses method
TigerColleague.prototype.SetAllClasses = function () {
	for (var Field in this.Fields) {
		this.Fields[Field].SetClasses();
	}
}




TigerColleague.prototype.Validate = function () {
	// Loop through all fields
	// If compulsory or validation required, validate. Store results in array, and keep highest issue level
	// set control classes as you go along
	// at the end, if anything to report, set main validation message and pop-up messagebox as appropriate

	var fld, nIssueLevel = 0, nErrorCount = 0;
	var MinIssueLevelToAlert = this.parent.MinIssueLevelToAlert;
	var aErrorMessages = new Array();
	var aErrorLevels = new Array();


	for (var Field in this.Fields) {
		var MyField = this.Fields[Field]
		if (MyField.IsVisible && !MyField.IsDisabled) {
			MyField.ValidateOnFly(true);
			if (MyField.IssueLevel >= MinIssueLevelToAlert) {
				nErrorCount++;
				if (MyField.IssueLevel > nIssueLevel) nIssueLevel = MyField.IssueLevel;
				aErrorMessages[nErrorCount] = MyField.CurrentErrorMsg;
				aErrorLevels[nErrorCount] = MyField.IssueLevel;
			}
			if (MyField.FieldType == eFieldType.Demog) {
				for (var DemogOption in MyField.DemogOptions) {
					if (MyField.DemogOptions[DemogOption].OtherTextAllowed) {
						MyOther = MyField.DemogOptions[DemogOption].OtherText;
						if (MyOther.IsVisible && !MyOther.IsDisabled) {
							MyOther.ValidateOnFly(true);
							if (MyOther.IssueLevel >= MinIssueLevelToAlert) {
								nErrorCount++;
								if (MyOther.IssueLevel > nIssueLevel) nIssueLevel = MyOther.IssueLevel;
								aErrorMessages[nErrorCount] = MyOther.CurrentErrorMsg;
								aErrorLevels[nErrorCount] = MyOther.IssueLevel;
							}
						}
					}
				}
			}
		}
	}
	
	return { ErrorCount: nErrorCount, IssueLevel: nIssueLevel, ErrorMessages: aErrorMessages, ErrorLevels: aErrorLevels }

}



TigerColleague.prototype.ClearValidation = function () {

	for (var Field in this.Fields) {
		var MyField = this.Fields[Field]
		if (MyField.IsVisible && !MyField.IsDisabled) {
			MyField.IssueLevel = eIssueLevel.None;
			MyField.CurrentErrorMsg = "";
			MyField.SetClasses();
		}
	}
	
}
