__ = new tmlib();
//var cfg.formname = "contact";
__.cfg.radioIds = ["participant_type_sa","participant_type_a","participant_type_c","participant_type_food","participant_type_np"];
__.cfg.subjectId = "subject";
__.cfg.subjectValue = "AitS Online Application";
__.cfg.catFieldId = "cats2";
__.cfg.catAttribute = "data-catid";
function scrOnload(){
	formHandler = new clsChangeField({"radioIds":__.cfg.radioIds, "changeFieldId": __.cfg.subjectId, "changeFieldPrefix":__.cfg.subjectValue+" (", "changeFieldPostfix":")", "changeField2Id":__.cfg.catFieldId, "changeField2Attribute": __.cfg.catAttribute});
}

/*****
formhandler
*****/
/*
arguments:
	radioIds: array(strings): ids of radio buttons for onchange
	changFieldId: string: id of (subject) field to change
	changeFieldPrefix: string: string to prepend to current radio value
	changeFieldPostfix: string: string to append to current radio value
	changeField2Id: string: id of second (cat) field to change
result: 
	modifies changefield to proper initial value
	>attaches listeners to 
*/
function clsChangeField(arguments){
	this.elmChangeField = document.getElementById(arguments.changeFieldId);
	this.changeFieldPrefix = arguments.changeFieldPrefix;
	this.changeFieldPostfix = arguments.changeFieldPostfix;
	this.elmChangeField2 = document.getElementById(arguments.changeField2Id);
	this.changeField2Attribute = arguments.changeField2Attribute;
	this.elmsRadios = this.setRadios(arguments.radioIds);
	if(this.elmChangeField && this.elmChangeField2 && this.elmsRadios)
		this.setupRadioElements();
	else
		return false;
}
	/*
	return array of elements for onchange events
	argument: array(string): ids of radio buttons for onchange
		OR	string: id of radio button for onchange
	*/
	clsChangeField.prototype.setRadios = function(argRadioIds){
		var returnArray = [];
		if(typeof argRadioIds == 'object'){
			for(var i in argRadioIds){
				returnArray.push(document.getElementById(argRadioIds[i]));
			}
		}else{
			returnArray.push(document.getElementById(argRadioIds));
		}
		return returnArray;
	}
	/*
	result:
		attaches listeners to this's elmsRadios to modify elmChangField
		modifies changefield to initial checked value
		
	*/
	clsChangeField.prototype.setupRadioElements = function(){
		fncThis = this;
		for(var i in this.elmsRadios){
			// set initial changefield value
			this.setChangeFieldToElementValue(this.elmsRadios[i]);
			this.setCatFieldToElementCat(this.elmsRadios[i]);
			// attach listener
			var callback = function(fncThis, fncElement){
				return function(){
					fncThis.setChangeFieldToElementValue(fncElement);
					fncThis.setCatFieldToElementCat(fncElement);
				}
			}(fncThis, this.elmsRadios[i]);
			__.addListener(this.elmsRadios[i], "change", callback, false);
		}
	}
	/*
	result: modifies changefield to element value if checked
	*/
	clsChangeField.prototype.setChangeFieldToElementValue = function(argElement){
		if(argElement.checked){
			this.elmChangeField.value = this.changeFieldPrefix + argElement.getAttribute("value") + this.changeFieldPostfix;
		}
	}
	/*
	result: modifies changefield to element value if checked
	*/
	clsChangeField.prototype.setCatFieldToElementCat = function(argElement){
		if(argElement.checked){
			this.elmChangeField2.value = argElement.getAttribute(this.changeField2Attribute);
		}
	}
/*
tmlib/init
*/
function tmlib(){
		this.cfg = new Function();
	}
	tmlib.prototype.addListener = function(argElement, argEvent, argFunction, argBubble){
		var fncBubble = (argBubble)?argBubble : false;
		if(argElement.attachEvent)
			argElement.attachEvent("on"+argEvent, argFunction);
		else
			argElement.addEventListener(argEvent, argFunction, fncBubble);
	}
	tmlib.prototype.isIE = function(){
		if(this.isievar)
			return this.isie;
		else{
			this.initUA();
			if(this.browser.indexOf("Internet Explorer", 0) == -1) return 0;
			else return 1;
		}
	}
	tmlib.prototype.initUA = function(){
		if(!this.browser) this.browser = navigator.appName;
		if(!this.verion) this.version = parseFloat(navigator.appVersion);
	}
	tmlib.prototype.message = function(argument){
		if(window.console) 
			console.log(argument);
		else alert(argument);
	}
__.addListener(window, "load", scrOnload, false);

