// JAVASCRIPT FILE  - TIGER DATA ENTRY FIELD OBJECT

// TigerField object - when a field is added to the form, a corresponding javascript object should be
// 	created to contain full information about the field and the way it should behave. The name of the
// field should match the name of the main data field.
function TigerField(cName, cNiceName) { 
	this.FieldName = cName; 				// Name to identify the field. Must be specified.
	this.FieldType = eFieldType.Contact;	// Type of field, e.g. Contact/DPA/Demog
	this.DataEntryStyle = eDataEntryStyle.Text; 	// What type of data entry box. Default to textbox
	this.FormatType = eFormatType.None; 	// Which rules to format this data
	this.FormatTitleType = eFormatType.Standard; 	// Which sub-rules to format this data if title-case
	this.FieldElements = new Array(); 		// An array to store information about all related form elements
	this.IsAddressField = false;			// Set to specify address fields (up to, but not including postcode).
	this.IsPostcodeField = false;			// Set to specify postcode field
	this.LastRequestedPostcode = ""			// Last postcode requested from AJAX
	this.LastFetchedPostcode = ""			// Last postcode fetched through AJAX
	this.PostcodeFetchInProgress = false	// Flag to indicate if an AJAX fetch is currently in progress
	this.TabLastPressed = false				// For postcode field, to keep track if TAB was the last key pressed. To pass on to the 'blur' event
	this.HouseNumberID = ""					// The HTML ID of the whole span for 'House Number' - only used if IsPostcodeField is TRUE
	this.HouseNumberFieldName = ""			// The Field Name of the 'House Number' box - only used if IsPostcodeField is TRUE
	this.IsSelected = false;				// Keeps track of whether this field is currently selected for data entry
	this.IsVisible = true;					// Keeps track of whether this field is currently visble
	this.IsDisabled = false;				// Keeps track of whether this field is currently disabled (visible, but can't type in it)
	this.Compulsory = true;				// Sets whether this field is compulsory
	this.ValidType = eValidType.NoValidation;	// Specifies the validation rules to use
	this.Multiple = false;					// Specifies for demographics if the user is allowed to select multiple options
	this.InitialDisplayStatus = eDisplayStatus.Normal;	// Remembers how the control 'started out' - invisible, disabled, useable
	this.CurrentErrorMsg = "";				// Keeps track of the current error message being displayed
	this.NiceFieldName = cNiceName ? cNiceName : this.FieldName;				// A nice field name used for automatically-generated messages to the user
	this.ErrorMsgEmpty = this.NiceFieldName+" is empty";				// Text to prompt if the field is left empty
	this.LastVal = "";						// Keeps track of the value of a field before a user edited it, so that it can be compared afterwards
	this.OrigVal = "";						// Keeps track of the original value when the page was loaded
	this.LayoutStyle = eLayoutStyle.Standard;	// HTML layout style for the control - one of predefined templates
	this.IssueLevel = eIssueLevel.None;		// Keeps track of the current 'issue level' or 'error status'
	this.DemogOptions = new Array();		// An array to store information about each demog answer
	this.Conditionals = new Array();		// An array to store information about any conditionals arising from this field
	this.DisplayStatusIfActive = eDisplayStatus.Normal;	// For 'other text'
	this.DisplayStatusIfNotActive = eDisplayStatus.Disabled;	// For 'other text'
	this.RealField = true;					// special property to set to false for country fields that aren't actually on this form
	this.AllowFreeText = false;				// for choice lists where we have an 'other please specify' option
	this.FreeTextField = false;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////
// DATA FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////

// method to create a link to the HTML data field
TigerField.prototype.GetDataField = function () {
	return this.Form[this.FieldName]
}

// GetValue - fetches the value of the data. If there is more than one value, it is returned as an array
TigerField.prototype.GetValue = function () {

	if (!this.RealField) {
		return this.OrigVal;
	}

	oField = this.GetDataField();
	if (!this.Multiple) {
		if (this.DataEntryStyle==eDataEntryStyle.Radio || this.DataEntryStyle==eDataEntryStyle.Checkbox ) {
			return getCheckedValue(oField);
		} else {
			return oField.value;
		}
	} else {
		aValues = new Array();
		
		for ( var i=0; i < oField.length; i++ ) {
			if ( oField[i].selected || oField[i].checked ) {
				aValues[aValues.length] = oField[i].value;
			}
		}
		return aValues;
	}
}

// SetValue - writes the value of the field
TigerField.prototype.SetValue = function (cVal) {
	if (!this.Multiple) {
		this.GetDataField().value = cVal;
	}
}

// AddField - add a new TigerField object
TigerField.prototype.AddFreeTextField = function () {
	this.FreeTextField = new TigerField(this.cFieldName + "FREETEXT", this.NiceName);
	this.FreeTextField.parent = this;
	this.FreeTextField.Form = this.Form;
	return this.FreeTextField;
}


// Add a choice to a listbox
TigerField.prototype.AddChoice = function(cVal, cDisplay) {
	oField = this.GetDataField();
	var optionObject = new Option(cDisplay,cVal)
	oField.options[oField.options.length]=optionObject	
}

// Remove a choice to a listbox
TigerField.prototype.RemoveChoice = function(cVal) {
	oField = this.GetDataField();

	for( i=oField.options.length-1; i>=0; i--) {	
		if(oField.options[i].text==cVal) {
			oField.options[i]=null;
		}
	}
}

// FetchAddress

TigerField.prototype.FetchAddress = function (ev) {
	if (ev.type == "keydown") {
		if (ev.keyCode==9 && !ev.shiftKey) {
			this.TabLastPressed = true;
		} else {
			this.TabLastPressed = false;
		}
		return true;
	}
		
	if (ev.type == "focus") {
		this.LastRequestedPostcode = "";
	}

	if (this.parent.PAFLookup && !this.parent.AddressDataTouched) {
		var cCountry = this.parent.CountryField.GetValue();

		if (cCountry != "GB" && cCountry != "UK" && cCountry != "UNITED KINGDOM" && cCountry != "") return false;
		var cVal = this.GetValue();
		if (cVal.length < 5) {
//			this.HideHouseNumber();
			this.UpdateAddress("");
			this.LastRequestedPostcode = cVal;
			this.LastFetchedPostcode = "";
			return false;
		}
		if (ev.type == "blur") {
			if (this.TabLastPressed) {
				this.TabLastPressed = false;
				if (this.PostcodeFetchInProgress || cVal != this.LastRequestedPostcode) {
//					this.ShowHouseNumber();
//					SetFocusToControl(this.parent.Form[this.HouseNumberFieldName]);
				}
			}
		}

		if (!this.PostcodeFetchInProgress || cVal != this.LastRequestedPostcode) {
			var cURL = this.parent.PAFLookupURL + escape(cVal)
			xmlHTTP=GetXmlHttpObject(StateChanged);
			xmlHTTP.open("GET", cURL , true)
			xmlHTTP.send(null)
			this.LastRequestedPostcode = cVal;
			this.PostcodeFetchInProgress = true;
		}
	}
}




TigerField.prototype.UpdateAddress = function (cStream)
{
	this.PostcodeFetchInProgress = false;
	if (this.parent.AddressDataTouched) return false;
    var aResponse=cStream.split("|");
	if (aResponse[1]==undefined) aResponse[1]="";
	if (aResponse[2]==undefined) aResponse[2]="";
	if (aResponse[3]==undefined) aResponse[3]="";
	if (aResponse[4]==undefined) aResponse[4]="";
	if (aResponse[5]==undefined) aResponse[5]="";
    this.parent.Address1Field.SetValue(aResponse[1]);
    this.parent.Address1Field.LastVal=aResponse[1];
    this.parent.Address2Field.SetValue(aResponse[2]);
    this.parent.Address2Field.LastVal=aResponse[2];
    this.parent.TownField.SetValue(aResponse[3]);
    this.parent.TownField.LastVal=aResponse[3];
    this.parent.CountyField.SetValue(aResponse[4]);
    this.parent.CountyField.LastVal=aResponse[4];
    if (aResponse[5].length>0) {
    	this.SetValue(aResponse[5]);
    	this.LastVal=aResponse[5];
//    	this.ShowHouseNumber();
//    	if (aResponse[5] != this.LastFetchedPostcode) TigerReg.Form[this.HouseNumberFieldName].value="";
    } else {
//    	this.HideHouseNumber();
    }
    this.LastFetchedPostcode=aResponse[5];
}
//
//TigerField.prototype.FetchAddressOld = function () {
//	if (this.parent.PAFLookup && !this.parent.AddressDataTouched) {
//		var cVal = this.GetValue();
//		if (cVal.length < 5) {
//			this.HideHouseNumber();
//			return false;
//		}
////		if (this.LastRequestedPostcode.toUpperCase() != cVal.toUpperCase()) {
//			var cCountry = this.parent.CountryField.GetValue();
//			if (cCountry != "GB" && cCountry != "") return false;
//			var cURL = this.parent.PAFLookupURL + escape(cVal)
//			
//			xmlHTTP=GetXmlHttpObject(StateChanged);
//			xmlHTTP.open("GET", cURL , true)
//			xmlHTTP.send(null)
//			this.LastRequestedPostcode = cVal;
////		}
//	}
//}
//



TigerField.prototype.ShowHouseNumber = function () {
	document.getElementById(this.HouseNumberID).style.display="";
}
 
TigerField.prototype.HideHouseNumber = function () {
	document.getElementById(this.HouseNumberID).style.display="none";
}
 
TigerField.prototype.AppendHouseNumber = function () {
	// Get HouseNumber value and format it
	var cHN = AllTrim(titlecase(this.parent.Form[this.HouseNumberFieldName].value));
	var cOrigAdd1 = this.parent.Address1Field.GetValue();
	var cOrigAdd2 = this.parent.Address2Field.GetValue();
	var cAdd1 = "";
	var cAdd2 = "";
	// Merge in to Add1 & 2 as appropriate
	if (cHN.length == 0) {
			cAdd1 = cOrigAdd1;
			cAdd2 = cOrigAdd2;
	} else if (CountDigits(cHN)>=1 && CountAlpha(cHN)<=1) {
		cAdd1 = AllTrim(AllTrim(cHN) + " " + AllTrim(cOrigAdd1));
		cAdd2 = cOrigAdd2;
	} else {
		if (cOrigAdd1 == "") {
			cAdd1 = AllTrim(cHN);
			cAdd2 = cOrigAdd2;
		} else if (cOrigAdd2 == "") {
			cAdd1 = AllTrim(cHN);
			cAdd2 = cOrigAdd1;
		} else if (cHN.length > cOrigAdd2.length) {
			cAdd1 = AllTrim(cHN);
			cAdd2 = AllTrim(cOrigAdd1) + ", " + AllTrim(cOrigAdd2);
		} else {
			cAdd1 = AllTrim(cHN) + ", " + AllTrim(cOrigAdd1);
			cAdd2 = AllTrim(cOrigAdd2);
		}
	}
	this.parent.Address1Field.SetValue(cAdd1);
	this.parent.Address1Field.LastVal=cAdd1;
	this.parent.Address2Field.SetValue(cAdd2);
	this.parent.Address2Field.LastVal=cAdd2;
	this.HideHouseNumber();
}
 


//////////////////////////////////////////////////////////////////////////////////////////////////////
// DISPLAY FUNCTIONS - VISIBILITY & CLASSES
//////////////////////////////////////////////////////////////////////////////////////////////////////

// SetClasses - loops through each element, and each 'other text' element, cand calls its SetClasses method
TigerField.prototype.SetClasses = function (lIsListboxSelect) {
	for (FieldElement in this.FieldElements) {
		if (!lIsListboxSelect || this.FieldElements[FieldElement].ElementType != eElementType.Listbox) {
			this.FieldElements[FieldElement].SetClass();
		}
	}
	if (this.FieldType == eFieldType.Demog) {
		for (var DemogOption in this.DemogOptions) {
			if (this.DemogOptions[DemogOption].OtherTextAllowed) {
				this.DemogOptions[DemogOption].OtherText.SetClasses();
			}
		}
	}

};

// SetDisplayStatus - takes parameter of enum eDisplayStatus, and applies to the whole control
TigerField.prototype.SetDisplayStatus = function (DisplayStatus) {
	this.ShowHideFull(DisplayStatus != eDisplayStatus.Hidden);
	this.DisableControls(DisplayStatus == eDisplayStatus.Disabled);
	// Other text
	if (this.FieldType == eFieldType.Demog) {
		for (var DemogOption in this.DemogOptions) {
			this.DemogOptions[DemogOption].SetDisplayStatus(DisplayStatus);
		}
	}
	this.SetClasses();


}

// ShowHideFull - Locate elements of type 'Full' and show or hide as appropriate
TigerField.prototype.ShowHideFull = function (lShow) {
	for (FieldElement in this.FieldElements) {
		if (this.FieldElements[FieldElement].ElementType==eElementType.WholeField) {
			document.getElementById(this.FieldElements[FieldElement].ElementID).style.display = (lShow ? "" : "none");
		}
	}
	this.IsVisible = lShow;
}

// DisableControls - Locate all data controls, and disable/enable as appropriate
TigerField.prototype.DisableControls = function (lDisable) {
	for (FieldElement in this.FieldElements) {
		if (this.FieldElements[FieldElement].ElementType==eElementType.Textbox || this.FieldElements[FieldElement].ElementType==eElementType.Listbox || this.FieldElements[FieldElement].ElementType==eElementType.Radio || this.FieldElements[FieldElement].ElementType==eElementType.Checkbox) {
			document.getElementById(this.FieldElements[FieldElement].ElementID).disabled = lDisable;
			if (lDisable) {
				// Copy this.GetValue() into the hidden field
				document.getElementsByName(this.FieldName+TigerReg.HiddenFieldForDisabledDataSuffix)[0].value = this.GetValue();
			} else {
				// Blank the hidden field
				document.getElementsByName(this.FieldName+TigerReg.HiddenFieldForDisabledDataSuffix)[0].value = "";
			}
		}
	}
	this.IsDisabled = lDisable;
}

// SelectField - Mark this field as 'selected' so that it can be visually identified. Normally called from 'onFocus'
TigerField.prototype.SelectField = function () {
	this.IsSelected = true;
	this.SetClasses((this.DataEntryStyle == eDataEntryStyle.Listbox));
};

// UnselectField - Mark this field as 'no longer selected'. Normally called from 'onBlur'
TigerField.prototype.UnselectField = function () {
	this.IsSelected = false;
	this.SetClasses();
};

function disableAllButMe(objForm,objChkBox,bFlag)
{
	//disable or enable all the checkboxes except the objChkbox
	var elems = objForm.Form.elements;
								
		for (var ix=0; ix < elems.length; ix++)
		{
			var elem = elems[ix];
			if(elem.type == "checkbox")
			{
				if(elem.name != objChkBox.name)
					{
						if (bFlag == true)
						{
							if((elem.disabled == false) && (elem.checked == false))
							{
								elem.disabled = bFlag
							}
						}
						else
						{
							if((elem.disabled == true) && (elem.checked == false))
							{
								elem.disabled = bFlag
							}
							
						}
					}
					
			}
		}
}


function disableAllButMe2(objForm,bFlag)
{
	
	var elems = objForm.Form.elements;
	var flagCustom = false;
								
		for (var ix=0; ix < elems.length; ix++)
		{
			var elem = elems[ix];
			if(elem.type == "checkbox")
			{
				
				if (elem.id.indexOf("CUSTOM")>0)
					{
						if (bFlag == true)
						{
							elem.disabled = bFlag;
							
						}
						else
						{
							if(elem.checked == true)
							{
								elem.disabled = true;
							}
							else
							{
								elem.disabled = false;
							}
							
						}
					}					
					else
					{
						if((elem.checked == true)&& (elem.disabled == false))
						{
							//alert(elem.id);
							if(elem.visible == true)
							{								
								flagCustom = true;
								break;
							}
						}
						else
						{
							flagCustom = false;
							continue;
						}
						
					}
					
			}
		}
		
		if(flagCustom == true)
		{
			document.getElementById("TR-D-DPA_CUSTOM1").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM2").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM3").disabled = true;	
			document.getElementById("TR-D-DPA_CUSTOM4").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM5").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM6").disabled = true;	
			document.getElementById("TR-D-DPA_CUSTOM7").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM8").disabled = true;
			document.getElementById("TR-D-DPA_CUSTOM9").disabled = true;	
			
		}
		else
		{
			if(document.getElementById("TR-D-DPA_CUSTOM1").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM1").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM1").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM2").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM2").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM2").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM3").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM3").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM3").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM4").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM4").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM4").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM5").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM5").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM5").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM6").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM6").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM6").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM7").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM7").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM7").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM8").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM8").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM8").disabled = false;}
			
			if(document.getElementById("TR-D-DPA_CUSTOM9").checked== true)
			{document.getElementById("TR-D-DPA_CUSTOM9").disabled = true;}
			else
			{document.getElementById("TR-D-DPA_CUSTOM9").disabled = false;}
			
		}
}

function setCustom(objForm,elem)
{
	//Gets the form object and the chkbox element which is to be set
		var elemId = elem;
		
		//if the elem that is checked is one of the Custom chkboxes
		if (elemId.indexOf("CUSTOM")>0)
			{
				//check if it is enabled
				if(document.getElementById(elemId).disabled == false)
				{
					//then Disable all the other chkboxes except this one
					var oChkBox;
					oChkBox = document.getElementById(elemId);
					disableAllButMe(objForm,oChkBox, true);
				}
				
			}
		else
			{
				//if any of the other chkboxes are checked and enabled then disable all the custom chkboxes
				document.getElementById("TR-D-DPA_CUSTOM1").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM2").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM3").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM4").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM5").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM6").disabled = true;	
				document.getElementById("TR-D-DPA_CUSTOM7").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM8").disabled = true;
				document.getElementById("TR-D-DPA_CUSTOM9").disabled = true;
				
			}
		
	
}

// SetConditionals - apply any conditionals (including 'other text') for this field.
TigerField.prototype.SetConditionals2 = function (oId) {
	
	
	if(this.Form.hidSpecialField)
	{
		//OnClick of one of the checkboxes 
		//Chk if the chkbox is a Custom one
		if (oId.indexOf("CUSTOM")>0)
		{
			var oChkBox;
			oChkBox = document.getElementById(oId);
			
			//If the Custom chkbox is CHECKED
			if (oChkBox.checked == true)
			{
				//Custom chkbox CHECKED so disable all other chkboxes
				disableAllButMe(this,oChkBox, true);
			}
			else
			{
				
				disableAllButMe(this,oChkBox, false);	
			}
		}
		else
		{
			//Its one of the OTHER chkboxes clicked
			var oChkBox;
			oChkBox = document.getElementById(oId);
			
			//If the other chkboxes are checked
			if (oChkBox.checked == true)
			{
				//Disable all the custom chkoxes
				disableAllButMe2(this,true);
			}
			else
			{
				disableAllButMe2(this,false);	
			}
			
		}
	}
	else 
	{	//no hidden field so it's just normal DPA chkbox so call the original function	
		TigerField.prototype.SetConditionals();	
	}
	
}


// SetConditionals - apply any conditionals (including 'other text') for this field.
TigerField.prototype.SetConditionals = function () {
	var flag;
	// Standard conditionals
	for (Condition in this.Conditionals) {
		this.Conditionals[Condition].Set();
	}
	

		// DPA Field Validations
	if(this.Form.hidSpecialField)
	{
		document.getElementById("TR-CONTROLDPA").Compulsory = true;				
		document.getElementById("hidImage").style.visibility = "hidden";	
		//var flagCustom;
		//Iterate through the form collection & pick out the DPA fields
		if (this.FieldType == eFieldType.DPA) 
		{
		
			for (FieldElement in this.FieldElements) 
			{
					//Pick out only the DPA Chkboxes
					if (this.FieldElements[FieldElement].ElementType==eElementType.DPACheckbox)
					{
						//Get the DPA Chkboxes that are disabled or not
						if(document.getElementById(this.FieldElements[FieldElement].ElementID).disabled==false)
						{
							
							//Pick out the ENABLED DPA Chkboxes that are checked
							if(document.getElementById(this.FieldElements[FieldElement].ElementID).checked == true)
							{
								//This one is ENABLED and CHECKED
								//Then set the Control chkbox compulsory to false
								//And set the Control chkbox to checked
								//Error message is NOT DISPLAYED
								//You then pass the form object to enable or disable the Custom checkboxes
								document.getElementById("TR-CONTROLDPA").Compulsory = false;
								document.getElementById("TR-CONTROLDPA").checked = true;	
								document.getElementById("hidImage").style.visibility = "hidden";
								setCustom(this,this.FieldElements[FieldElement].ElementID);								
								//flagCustom = true;
//								break;
							}
							else
							{//Pick out if the ENABLED DPA Chkboxes are NOT CHECKED 
								
								
								var elems = this.Form.elements;
								var elemChecked;
									for (var ix=0; ix < elems.length; ix++)
									{
										var elem = elems[ix];
										if(elem.type == "checkbox")
										{
											
											if(elem.name != "TR_CXONTROLDPA")
											{
												
												if(elem.disabled == false)
												{	
													
													if(elem.checked == true)
													{
														var flagCustom;
														flagCustom = true;
														elemChecked = elem.id;														
														document.getElementById("TR-CONTROLDPA").Compulsory = false;
														document.getElementById("TR-CONTROLDPA").checked = true;														
														document.getElementById("hidImage").style.visibility = "hidden";
														
														break;
														
													}
													else
													{
														flagCustom = false;																
														document.getElementById("TR-CONTROLDPA").Compulsory = true;
														document.getElementById("TR-CONTROLDPA").checked = false;
														document.getElementById("hidImage").style.visibility = "visible";														
														continue;
														
													}
												}
											}
										}
									}
									
									if (flagCustom == true)
									{
										setCustom(this,elemChecked);	
									
									}
									
								}
							
						}
					}
				}
			}
	}



	// Other text
	if (this.FieldType == eFieldType.Demog) {
		for (var DemogOption in this.DemogOptions) {
			if (this.DemogOptions[DemogOption].OtherTextAllowed) {
				this.DemogOptions[DemogOption].SetConditionals();
			}
		}
	}

	// Free text on choices
	if (this.AllowFreeText) {
		var cVal;
		cVal = this.GetValue();
		if (cVal == "Other") {
			this.FreeTextField.SetDisplayStatus(eDisplayStatus.Normal);
		} else {
			this.FreeTextField.SetDisplayStatus(eDisplayStatus.Hidden);
		}
	}

};

//////////////////////////////////////////////////////////////////////////////////////////////////////
// CHILD OBJECT CREATION
//////////////////////////////////////////////////////////////////////////////////////////////////////

// Create a new 'demog answer' object
TigerField.prototype.AddDemogOption = function (cOptionID) {
	this.DemogOptions[cOptionID] = new TigerDemogOption(cOptionID);
	this.DemogOptions[cOptionID].parent = this;
	this.DemogOptions[cOptionID].Form = this.Form;
	return this.DemogOptions[cOptionID];
}

// Create a new conditional, where this is the source field
TigerField.prototype.AddConditional = function (cTargetField, nConditionType, ValueList, nActionIfFalse, nActionIfTrue) {
	var i = this.Conditionals.length;
	this.Conditionals[i] = new TigerConditional(this, this.parent.Fields[cTargetField], nConditionType, ValueList, nActionIfFalse, nActionIfTrue);
	this.Conditionals[i].parent = this;
	this.Conditionals[i].Form = this.Form;
	return this.Conditionals[i];
}



// AddFieldElement - method to register a new element relating to the field. ID and type must be specified
TigerField.prototype.AddFieldElement = function (cElementID, nElementType) {
	this.FieldElements[cElementID] = new TigerFieldElement(cElementID, nElementType) ;
	this.FieldElements[cElementID].parent = this;
	this.FieldElements[cElementID].Form = this.Form;
}
