function clearList(cb) {
	$('#' + cb).remove('option');
}

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) {
	if (text) {
		if ((maxAllowedLength != 0) && (text.length > maxAllowedLength))
			$('#' + lengthContainer).html('<span style="color: #d00;">' + text.length + '</span>');
		else
			$('#' + lengthContainer).html("" + text.length);
	} else {
		$('#' + lengthContainer).html("0");
	}
}

function hideElement (o) {
	o.style.visibility = "hidden";
	o.style.position = "absolute";
}

function moveSelectedOptions(a, b) {
	// moves selected rows from a to b select-element
	a = document.getElementById(a);
	b = document.getElementById(b);
	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(); }

	/*
	    Shadowbox.open({
    	    content:    '<iframe style="width: ' + w + 'px; height: ' + h + 'px; margin: 0; border: 0;" src="' + link + '"></iframe>',
        	player:     "html",
	        title:      "123",
    	    height:     h,
        	width:      w
    	});
    */
}

function removeDuplicates(a, b) {
	// remove rows from a if exist in b
	a = document.getElementById(a);
	b = document.getElementById(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);
}


