/*
 * onload functions
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 *
 */
function init_dynforms() {
	init_togglecbs();
}

var ar_statecb = new Array();
function init_togglecbs () {
	ar_testcb = document.getElementsByTagName("input");
	for (i=0; i<ar_testcb.length; i++) {
		if (ar_testcb[i].checked && ar_testcb[i].name) {
			ar_statecb[ar_testcb[i].name] = true;
		}
	}
}



/*
 * sets / unsets checkboxes with the same name depending on their previous state
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	string st_cbname		name of checkbox
 *
 */
function togglecbs(st_cbname) {
	if (ar_statecb[st_cbname] == true) {
		bl_setcb = false;
	} else {
		bl_setcb = true;
	}
	ar_togglecb = document.getElementsByName(st_cbname);
	for (i=0; i<ar_togglecb.length; i++) {
		if (bl_setcb) {
			ar_togglecb[i].checked = true;
		} else {
			ar_togglecb[i].checked = false;
		}
	}
	if (bl_setcb) {
		ar_statecb[st_cbname] = true;
	} else {
		ar_statecb[st_cbname] = false;
	}
}

/*
 * shows an element by id, hides element(s) by name
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	string st_showid		id of object to show
 * @param	string st_hidename		name of object(s) to hide
 *
 */
var obj_prevshown;
function togglevisibility (st_showid,st_hideclass) {
	obj_toshow = document.getElementById(st_showid);
	obj_toshow.style.display='block';
	ar_objtohide = getElementsByClassName(st_hideclass);
	for (i=0; i<ar_objtohide.length; i++) {
		if(ar_objtohide[i] == obj_toshow) {
			continue;
		} else {
			ar_objtohide[i].style.display='none';
		}
	}
	if (obj_prevshown && obj_prevshown!=obj_toshow) {
		obj_prevshown.style.display='none';
	}
	obj_prevshown = obj_toshow;
}

/*
 * sets class of an element by id to mc_active, sets class of element(s) by name to mc_passive
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	string st_showid		id of object to show
 * @param	string st_hidename		name of object(s) to hide
 *
 */
var obj_prevactive;
function toggleactclass (st_activeid,st_passiveclass) {
	obj_toactive = document.getElementById(st_activeid);
	obj_toactive.className='mc_active';
	ar_objtopassive = getElementsByClassName(st_passiveclass);
	for (i=0; i<ar_objtopassive.length; i++) {
		if(ar_objtopassive[i] == obj_toactive) {
			continue;
		} else {
			ar_objtopassive[i].className='mc_passive';
		}
	}
	if (obj_prevactive && obj_prevactive!=obj_toactive) {
		obj_prevactive.className='mc_passive';
	}
	obj_prevactive = obj_toactive;
}




/*
 * focus the first input field by a given name
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @ param	st_fname string		name of input field(s); first field found will be focussed
 * @ param	st_dfname string	name of default field to focus
 *
 */
function focusfield(st_fname,st_dfname) {
	if (st_fname) {
		document.getElementsByName(st_fname)[0].focus();
	} else {
		if (st_dfname) {
			document.getElementsByName(st_dfname)[0].focus();
		}
	}
}



/*
 * sets class of an element by id to mc_active, sets class of element(s) by name to mc_passive
 *
 * @author 	unknown (taken from some public website)
 * @param	string 	class_name
 * @return	array of objects
 *
 */
function getElementsByClassName (class_name) {
	var ar_allobj, ar_retobj = new Array(), j=0;
	if (document.all) {
		ar_allobj=document.all;
	} else {
		if (document.getElementsByTagName && !document.all) {
			ar_allobj = document.getElementsByTagName("*");
		}
	}
	for(i=0; i<ar_allobj.length; i++) {
		if (ar_allobj[i].className==class_name) {
			ar_retobj[j]=ar_allobj[i];
			j++;
		}
	}
	return ar_retobj;
}
