function showField(fieldName, display) {

	child = $(fieldName).up('div.field');

	if (display) {
		child.style.position = '';
		child.style.visibility = '';
		child.style.display = '';
	} else {
		child.style.position = 'absolute';
		child.style.visibility = 'hidden';
		child.style.display = 'none';
	}
}

function showElement(fieldsetName, display) {
	elem = document.getElementById(fieldsetName);

	if (display) {
		elem.style.position = '';
		elem.style.visibility = '';
		elem.style.display = '';
	} else {
		elem.style.position = 'absolute';
		elem.style.visibility = 'hidden';
		elem.style.display = 'none';
	}
}

function showTab(fieldsetName, display) {
	elem = document.getElementById(fieldsetName);

	if (display) {
		elem.style.position = '';
		elem.style.visibility = '';
		elem.style.display = '';
	} else {
		elem.style.position = 'absolute';
		elem.style.visibility = 'hidden';
		elem.style.display = 'none';

		if (elem.hasClassName('active')) {
			if (siblings = elem.nextSiblings()) {
				siblings[0].down('a').onclick();
			} else if (siblings = elem.previousSiblings()) {
				siblings[siblings.length-1].down('a').onclick();
			}
		}
	}
}

function requiredField(fieldName, display) {

	child = $(fieldName).up('div.field');

	if (display) {
		child.addClassName('req');
		if(!child.down('label span.req')) {
			child.down('label').insert(  new Element('span', { 'class': 'req' }).update('*') );
		}
	} else {
		child.removeClassName('req');
		if(child.down('label span.req')) {
			child.down('label span.req').remove();
		}
	}
}

function count(values) {
	if (Object.isArray(values)) {
		return values.length;
	}
	if ($H(values)) {
		return $H(values).values().length;
	}
	return 1;
}

function in_array(needle, values) {
	if (Object.isArray(values)) {
		return values.indexOf(needle.toString()) > -1;
	}
	return false;
}

function array_filter(array) {
	var array2 = {};
	$H(array).each(function(pair) {
		if (pair.value == 1) {
			array2[pair.key] = 1;
		}
	});
	return array2;
}

function valueFromArray(array, key) {
	var hash = $H(array);
	if (hash) {
		return hash.get(key);
	}
	return null;
}

function array_key_exists(key, array) {
	return !Object.isUndefined($H(array).get(key));
}

function substr(string, start, length)
{
	return string.substring(start, length);
}