function verifyFE (strFE, strCrit)
{
	objFE = eval ('document.' + strFE);
	
	if (objFE.type == 'select-one' || objFE.type == 'select-multiple') {
		if (eval (eval (objFE.options.selectedIndex) + strCrit)) {
			return true;
		}
		else {
			return false;
		}
	}
	
	if (objFE.type == 'checkbox') {
		if (strCrit == '.checked == true') {
			if (eval ('objFE' + strCrit)) {
				return true;
			}
			else {
				return false;
			}
		}
		if (strCrit == '.value == ') {
		
		}
	}
	
	if (objFE.type == 'radio') {
		if (strCrit == '.checked == true') {
			if (eval ('objFE' + strCrit)) {
				return true;
			}
			else {
				return false;
			}
		}
		if (strCrit == '.value == ') {
		
		}
	}
	
	if (eval ('objFE.value' + strCrit)) {
		return true;
	}
	else {
		return false;
	}
	
	return true;
}

function filterChildAssoc1 (intLevel, strObjik, strForm, childActiv, select_2_fill, array_name, strHasChild, strNoChild)
{
	if (array_name.length) {
		frm = eval ('document.' + strForm);
		objik = eval ('frm.' + strObjik);
		selectObj = eval ('frm.' + select_2_fill);
		
		var filterVal = objik.options[objik.selectedIndex].value;
		var varrChild = Array ();
		var strArrayName = '';
		if (intLevel < varrCurrIDs.length) {
			looper = varrCurrIDs.length - intLevel;
			for (i = 0 ; i < looper ; i++) {
				delete varrCurrIDs[varrCurrIDs.length - 1];
				varrCurrIDs.length = varrCurrIDs.length - 1;
			}
		}
		if (varrCurrIDs.length == 0) {
			strArrayName = 'array_name';
		}
		else {
			strArrayName = 'array_name[' + (varrCurrIDs.join('].children[')) + '].children';
		}
		array_name = eval (strArrayName);
		for (i = 0 ; i < array_name.length ; i++) {
			if (array_name[i].id == filterVal) {
				varrCurrIDs[varrCurrIDs.length] = i;
				if (intLevel == 0) {
					strCurrId = array_name[i].id;
					strCurrChild = i;
				}
				varrChild = array_name[i].children;
				i = array_name.length;
			}
		}
		if (varrChild.length == 0) {
			selectObj.length = 0;
			selectObj.options[0] = new Option(strNoChild);
			selectObj.options[0].value = '-1';
		}
		else {
			// varrOtherLevel
			selectObj.length = 0;
			selectObj.options[0] = new Option(strHasChild);
			selectObj.options[0].value = '-1';
			for (j = 0 ; j < varrChild.length ; j++) {
				if (childActiv == varrChild[j].id) {
					selectObj.options[j + 1] = new Option(varrChild[j].name);
					selectObj.options[j + 1].value = varrChild[j].id;
					selectObj.options[j + 1].selected = true;
				}
				else {
					selectObj.options[j + 1] = new Option(varrChild[j].name);
					selectObj.options[j + 1].value = varrChild[j].id;
				}
			}
		}
		return;
	}
	return;
}

function filterChildAssocLookup (intLevel, strObjik, strForm, array_name, strNoChild)
{
	if (array_name.length) {
		frm = eval ('document.' + strForm);
		objik = eval ('frm.' + strObjik);
		var found_it = false;
		var filterVal = objik.options[objik.selectedIndex].value;
		var varrChild = Array ();
		var strArrayName = '';
		if (intLevel < varrCurrIDs.length) {
			looper = varrCurrIDs.length - intLevel;
			for (i = 0 ; i < looper ; i++) {
				delete varrCurrIDs[varrCurrIDs.length - 1];
				varrCurrIDs.length = varrCurrIDs.length - 1;
			}
		}
		if (varrCurrIDs.length == 0) {
			strArrayName = 'array_name';
		}
		else {
			strArrayName = 'array_name[' + (varrCurrIDs.join('].children[')) + '].children';
		}
		array_name = eval (strArrayName);
		for (i = 0 ; i < array_name.length ; i++) {
			if (array_name[i].id == filterVal) {
				varrCurrIDs[varrCurrIDs.length] = i;
				if (intLevel == 0) {
					strCurrId = array_name[i].id;
					strCurrChild = i;
				}
				int_curr_alloc = Math.round (array_name[i].alloc);
				int_ucost = format (array_name[i].ucost, 2);
				frm.item_cost.value = int_ucost;
				found_it = true;
				i = array_name.length;
			}
		}
		if (!found_it) {
			frm.item_cost.value = '';
			calc_calcs (frm.item_cost);
		}
		return;
	}
	return;
}

function filterList (str_objik, str_form, select_2_fill, array_name, filter_found, filter_not_found)
{
	var frm = eval ('document.' + str_form);
	var objik = eval ('frm.' + str_objik);
	var select_obj = eval ('frm.' + select_2_fill);
	var varrChild = Array ();
	var varrCurrIDs = Array ();
	myRE = new RegExp (objik.value, 'gi');
	for (i = 0 ; i < array_name.length ; i++) {
		if (array_name[i].filterer.search (myRE) != -1) {
			varrCurrIDs[varrCurrIDs.length] = i;
		}
	}
	if (varrCurrIDs.length > 0) {
		if (varrCurrIDs.length == 1) {
			select_obj.length = 0;
			select_obj.options[0] = new Option(array_name[varrCurrIDs[0]].name);
			select_obj.options[0].value = array_name[varrCurrIDs[0]].id;
		}
		else {
			select_obj.length = 0;
			select_obj.options[0] = new Option(filter_found);
			select_obj.options[0].value = '-1';
			for (j = 0 ; j < varrCurrIDs.length ; j++) {
				select_obj.options[j + 1] = new Option(array_name[varrCurrIDs[j]].name);
				select_obj.options[j + 1].value = array_name[varrCurrIDs[j]].id;
			}
		}
	}
	else {
		select_obj.length = 0;
		select_obj.options[0] = new Option(filter_not_found);
		select_obj.options[0].value = '-1';
	}
}

function addOther (objik, prompt, varr_name, val_2_match)
{
	frm = objik.form;
	if (objik.options[objik.selectedIndex].value == val_2_match) {
		otherNum = window.prompt(prompt, "");
		if (otherNum != "" && otherNum != null) {
			tmp = objik.options.length;
			objik.options[tmp] = new Option(otherNum);
			objik.options[tmp].value = otherNum;
			objik.selectedIndex = tmp;
		}
		else if (checkForDup (otherNum, varr_name)) {
			for (i = 0 ; i < objik.length ; i++) {
				if (objik.options[i].value == otherNum) {
					objik.options[objik.selectedIndex].text = "Other...";
					objik.selectedIndex = i;
				}
			}
		}
		else {
			objik.selectedIndex = 0;
		}
	}
}

function checkForDup (otherNum, varr_name)
{
	for (i = 0 ; i < varr_name.length ; i++) {
		if (varr_name[i] == otherNum) {
			return false;
		}
	}
	return true;
}

function pop_window (page_name, limit_id_name, limit_id, window_name, window_atts, use_comm_atts)
{
	comm_atts = 'menubar=no,statusbar=no,location=no,toolbar=no';
	if (pop_window.arguments.length > 5 && use_comm_atts == 'yes') {
		if (window_atts != '') {
			window_atts = window_atts + ',' + comm_atts;
		}
		else {
			window_atts = comm_atts;
		}
	}
	if (glob_sess_id) {
		page_name = page_name + '?PHPSESSID=' + glob_sess_id;
	}
	if (limit_id_name != '' && limit_id != '') {
		page_name = page_name + '&' + limit_id_name + '=' + limit_id;
	}
	window.open (page_name, window_name, window_atts);
	return false;
}

function pop_window_x (page_name, limit_id_name, limit_id, window_name, window_atts, use_comm_atts)
{
	comm_atts = 'menubar=no,statusbar=no,location=no,toolbar=no';
	if (pop_window_x.arguments.length > 5 && use_comm_atts == 'yes') {
		if (window_atts != '') {
			window_atts = window_atts + ',' + comm_atts;
		}
		else {
			window_atts = comm_atts;
		}
	}
	var id_names = (limit_id_name.split ('|'));
	var id_vals = (limit_id.split ('|'));
	for (i = 0 ; i < id_names.length ; i++) {
		page_name = page_name + '&' + id_names[i] + '=' + id_vals[i];
	}
	window.open (page_name, window_name, window_atts);
	return false;
}

function toggle_all_cbs (objik, crit) // toggle all checkboxes that the beginning of the name starts with "crit"
{
	frm = objik.form;
	on_or_off = objik.checked ? true : false;
	elem_count = frm.elements.length;
	
	for (i = 0 ; i < elem_count ; i++) {
		if (frm.elements[i].type == 'checkbox' && frm.elements[i].name.substr (0, crit.length) == crit) {
			frm.elements[i].checked = on_or_off;
		}
	}
}
