/**
 * Supports these field types: "Bool" | "Gender" | "FKey" | "FKeySet"
 * @constructor
 * @base Agent
 * @param {String} id This Agent's field reference
 */
function CheckBoxAgent(id) {

	this.init(id);

	// procedure callbacks implemented in modRec, filter & collection
	this.onLogin = AgentPCB.onLogin;
	this.update = AgentPCB.update;

	this.submitValue = function(obj) {

		var xmlValue = '<NullValue/>';
		var ov = obj.value;
		if (ov!='null') switch (this.fieldType) {
			case 'FKey' : xmlValue = '<FKey recId="'+ov+'"/>'; break;
			case 'FKeySet' :
				if (this.recId || this.mmrId) {
					Manager.getAgent('link_'+this.fieldRef).addFKey(ov);
					this.reset();
					return}
				else xmlValue = '<FKey recId="'+ov+'"/>';
				break;

			default : // Bool | Gender
				if (obj.type=='checkbox') {
					var vals = ov.split('|');
					ov = (obj.checked) ? vals[0] : vals[1];}
				xmlValue = '<'+this.fieldType+' value="'+ov+'"/>'}

		var xeValue = new ParsedXMLElement(xmlValue);

		var xeCommand;
		if (this.recId) xeCommand = this.xeSetFieldValue(xeValue);
		else if (this.mmrId) xeCommand = this.xeSetMMRFieldValue(xeValue);
		else xeCommand = this.xeGetPSValueLabel(xeValue);

		var xeWidgetResult = this.xeWidgetResult(xeCommand);
        this.update(xeWidgetResult)}

    this.reset = function() {
    	var rbs = d.forms[0][this.id];
    	for (var i=0; i<rbs.length; i++) {
			if (rbs[i].checked) rbs[i].checked = false;}}

	this.toString = function() {
		return 'CheckBoxAgent: {agentPrefix: ' + this.agentPrefix + '; fieldRef: ' + this.fieldRef + '}'}
}

CheckBoxAgent.prototype = new LoginPanelAgent();
