function clearList(cb) {
	if (cb != null) while (cb.length > 0) cb.remove(0);	// removing old list
}

function confirmAndDo (msg, action) {
	if (confirm (msg)) eval(action);
}

function confirmAndGo (msg, url) {
	if (confirm (msg)) location.href = url;
}

function compareOptionText (a, b) {
	compareOptionText (a, b, false);	// Case insensitive call
}

function compareOptionText (a, b, isCaseSensitive) {
	/*
	 * return > 0 if a > b
	 * 0 if a = b
	 * < 0 if a < b
	 */
	a0 = (isCaseSensitive) ? a.text : a.text.toUpperCase();
	b0 = (isCaseSensitive) ? b.text : b.text.toUpperCase();
	return a0 != b0 ? a0 < b0 ? -1 : 1 : 0;
}

function compareOptionValue (a, b) {
	/*
	 * return > 0 if a > b
	 * 0 if a = b
	 * < 0 if a < b
	 */
	return a.value != b.value ? a.value < b.value ? -1 : 1 : 0;
}

function displayTextLength(text, lengthContainer, maxAllowedLength) {
	var length = text.length;
	var lengthHTML = length;
	if ((maxAllowedLength != 0) && (length > maxAllowedLength)) lengthHTML = '<span style="color: #d00;">' + length + '</span>';
	lengthContainer.innerHTML = lengthHTML;
}

function fbmlValidate(o) {
	// var o = document.getElementsByTagName("body");
	for(i = 0; i < o.length; i++) {
		r = o[i].innerHTML;
		r = r.replace(/<!-- FBML /g, "");
		r = r.replace(/ FBML -->/g, "");
   		o[i].innerHTML = r;
	}
}

function hideElement (o) {
	o.style.visibility = "hidden";
	o.style.position = "absolute";
}

function moveSelectedOptions(a, b) {
	// moves selected rows from a to b select-element
	for (i = 0; i < a.length; i++)
		if (a.options[i].selected) {
			option = document.createElement('option');
			option.text = a.options[i].text;
			option.value = a.options[i].value;
			try {	// for Firefox, Opera
				b.add(option, null);
			} catch(ex) {	// for IE
				b.add(option);
			}
		}
	for (i = a.length; i > 0; i--) if (a.options[i - 1].selected) a.remove(i - 1);
//	sortOptions(b);
}

function newWindow (link, handle, w, h, scroll, resize) {
	oWindow = window.open(link, handle, "left=20, top=20, toolbar=0, status=0, location=0, scrollbars=" + scroll + ", resizable=" + resize + ", width=" + w + ", height=" + h);
	if (window.focus) { oWindow.focus(); }

}

function removeDuplicates(a, b) {
	// remove rows from a if exist in b
	for (i = a.length; i > 0; i--)
		for (j = 0; j < b.length; j++)
			if (compareOptionValue(a.options[i - 1], b.options[j]) == 0)
				a.remove(i - 1);

}

function selectAllOptions(list){
	for (i = 0; i < list.options.length; i++) list.options[i].selected = true;
}

function showElement (o) {
	o.style.visibility = "visible";
	o.style.position = "static";
}


function sortOptions (list) {
	var items = list.options.length;
	// create array and make copies of options in list
	var tmpArray = new Array(items);
	for (i = 0; i < items; i++) tmpArray[i] = new Option(list.options[i].text,list.options[i].value);
	// sort options using given function
	tmpArray.sort(compareOptionText);
	// make copies of sorted options back to list
	for (i = 0; i < items; i++) list.options[i] = new Option(tmpArray[i].text,tmpArray[i].value);
}

