function $_(a) { return document.getElementById(a); }

function isBrowserIE() { if (document.all) { return true; } }

function toggleImgSrc(imgID, src1, src2) { var oImg = $_(imgID); if (oImg.src.search(src1) > 0) { oImg.src = src2; } else { oImg.src = src1; } }

function formatPrice(o) { var price = o.value; var regex = new RegExp("[^0-9.,]", "ig"); price = price.replace(regex, ""); price = price.replace(",", "."); price = new Number(price); var price = (price.toFixed(2)); o.value = price; }

function switchTree(a) {
	var b = $_('node'+a);
	if (b.className.indexOf('minus') > -1) {
		rollTree(a);
	} else {
		unrollTree(a);
	}
}

function rollTree(a) {
	$_('tree'+a).style.display = 'none';
	$_('node'+a).className = 'plus';
}
function unrollTree(a) {
	$_('tree'+a).style.display = 'block';
	$_('node'+a).className = 'minus';
}

function changeInputType(o, oType) {
	var o2 = document.createElement('input');
	o2.type = oType;
	if(o.size) o2.size = o.size;
	if(o.value) o2.value = o.value;
	if(o.name) o2.name = o.name;
	if(o.id) o2.id = o.id;
	if(o.className) o2.className = o.className;
	o.parentNode.replaceChild(o2,o);
	return o2;
}

function getSelectedOptionValue(sid) { if ($_(sid).selectedIndex >= 0) return $_(sid).options[$_(sid).selectedIndex].value; }

function removeSelectOptions(selectID) { var selectbox = $_(selectID); var i; for(i=selectbox.options.length-1;i>=0;i--) { selectbox.remove(i); } selectbox.options.length = 0; }

function addOptionToSelect(selectID, value, text, selected) { var el = document.createElement('option'); el.text = text; el.value = value; el.selected = selected; var elSelect = $_(selectID); try { elSelect.add(el, null); } catch(ex) { elSelect.add(el); } }

function clearoectHTML(oid) { $_(oid).innerHTML = ''; }

function addoectHTML(oid, value) { $_(oid).innerHTML += value; }

function isTrue(a) { var value = $_(a).Value; if (value) { return true; } return false; }

function confirmLink(href, message) { var confirmBox = confirm(message); if (confirmBox) { location = href; } }

function confirmForm(formId, message) { confirmBox = confirm(message); if (confirmBox) $_(formId).submit(); }
	
function getDisplayType(el) { var tag = el.tagName.toLowerCase() ; var displayType = ''; if (isBrowserIE()) { switch (tag) { case 'span': displayType = 'inline'; break; default: displayType = 'block'; } } else { switch (tag) { case 'tr': displayType = 'table-row'; break; case 'tbody': case 'thead': case 'tfoot': displayType = 'table-row-group'; break; case 'table': displayType = 'table'; break; case 'span': displayType = 'inline'; } } return displayType; }

function hideElement(a) { $_(a).style.display = 'none'; }

function showElement(a) { var el = $_(a); var displayType = getDisplayType(el); el.style.display = displayType; }

function toggleElement(a) { var el = $_(a); if(el.style.display == 'none'){showElement(a);}else hideElement(a); }

function visibleElement(a) { $_(a).style.visibility = 'visible'; }

function invisibleElement(a) { $_(a).style.visibility = 'hidden'; }

var slide_timer = new Array();
var slide_timer2 = new Array();

function slideOutElement(a,b) {
	clearTimeout(slide_timer2[a]);
	var o = $_(a);
	var h = parseInt(o.scrollHeight);
	var h2 = parseInt(o.style.height);
	var c = 25;
	if (h2 < h) {
		visibleElement(a);
		if (h2+c > h) {
			c = h2+c-h;
		}
		o.style.height = (h2 + c) + 'px';
		slide_timer[a] = setTimeout('slideOutElement(\''+a+'\',\''+b+'\');',20);
	} else {
		o.style.height = h + 'px';
		clearTimeout(slide_timer[a]);
	}
}

function slideInElement(a,b) {
	clearTimeout(slide_timer[a]);
	var o = $_(a);
	var h = 0;
	var h2 = parseInt(o.style.height);
	var c = 25;
	if (h2 > h) {
		if (h2 - c < h) {
			c = h2;
		}
		o.style.height = (h2 - c) + 'px';
		slide_timer2[a] = setTimeout('slideInElement(\''+a+'\',\''+b+'\')',20);
	} else {
		o.style.height = 0+'px';
		invisibleElement(a);
	}
}

function addElement(parentId, tagName, a, name, value, type) { var parent = $_(parentId); var newElement = document.createElement(tagName); newElement.setAttribute('id', a); if (type != '') newElement.setAttribute('type', type); if (value != '') newElement.setAttribute('value', value); if (name != '') newElement.setAttribute('name', name); parent.appendChild(newElement); }

function focusElement(a) { $_(a).focus(); }
	
function unCheckElement(a) { $_(a).checked=false; }

function checkElement(a) { $_(a).checked=true; }

function switchCheckElement(a) { var o = $_(a); if (o.checked) unCheckElement(a); else checkElement(a)};

function copyInputValue(to, from) { $_(to).value = $_(from).value; }

function setInputValue(a, value) { $_(a).value = value; }

function isChecked(a) { if ($_(a).checked || $_(a).checked == 'true') return 1; return 0; } 

function isCheckedOne(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) { if (o[j].checked) { return 1; } } return 0; }

function isElementEmpty(a) { return ($_(a).value == ''); }

function removeElement(parentId, a) { var parent = $_(parentId); var element = $_(a); parent.removeChild(element); }

function inputCheck(inputId, parentId, tagName, a, name, value, type) { var input = $_(inputId); if (input.checked == true) { addElement(parentId, tagName, a, name, value, type); } else { removeElement(parentId, a); } }

function enableElement(a) { $_(a).disabled = false; }

function disableElement(a) { $_(a).disabled = true; }

function toggleEnableElement(a) { if ($_(a).disabled == true) { $_(a).disabled = false; } else { $_(a).disabled = true; } } 

function enableAll(options) { for(var i=0; i < options.length; i++) { options[i].style.color = 'black'; } }

function disableSelectedOnOther(select, otherSelect) { var index = select.selectedIndex; otherSelect[index].style.color = 'white'; }

function selectAll(options) { for(var i=0; i < options.length; i++) { options[i].selected = true; } }

function clearSelect(a) { var element = $_(a); element.options.selectedIndex = 0; }

function clearInput(a) { var element = $_(a); element.value = ''; }

function copySelectedIndex(a, toId) { var from = $_(a); var to = $_(toId); to.options.selectedIndex = from.options.selectedIndex; }

function trim(str, chars) { return ltrim(rtrim(str, chars), chars); }

function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); }

function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); }

function checkAll(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) o[j].checked = true ; }

function uncheckAll(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) o[j].checked = false ; }

function reverseAll(field) { var o = document.getElementsByName(field); for (i = 0; i < o.length; i++) { if (o[i].checked == false) { o[i].checked = true; } else { o[i].checked = false; } } }