
function getTime() {
	var dt = new Date();
	
	var hh = dt.getHours();
	var mm = dt.getMinutes();
	var ss = dt.getSeconds();

	if (hh<10) hh = "0"+hh;
	if (mm<10) mm = "0"+mm;
	if (ss<10) ss = "0"+ss;

	return hh+":"+mm+":"+ss;
}

function ge(id) {
	return document.getElementById(id);
}

function ltrim(str) { 
	for (var k=0; k<str.length && str.charAt(k)<=" " ; k++);

	return str.substring(k,str.length);
}

function rtrim(str) {
	for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;

	return str.substring(0,j+1);
}

function trim(str) {
	return ltrim(rtrim(str));
}

function isDefined(v) {
    return (typeof(v)=="undefined") ? false : true;
}

function clearDiv(str) {
	var div = ge(str);
	div.innerHTML = '';
}

function removeAllOptions(sel) {
	while (sel.length>0) {
		sel.remove(0);
	}
}

function appendOption(sel, text, value) {
	sel.options[sel.length] = new Option(text, value);
}

function serialize_select(sel) {
	var res = "";

	for (var i=0; i<sel.options.length; i++) {
		if (sel.options[i].selected) {
			if (res!="")
				res += "," + sel.options[i].value;
			else
				res = sel.options[i].value;
		}
	}

	return res;
}

function serialize_select_ns(sel) {
	var res = "";

	for (var i=0; i<sel.options.length; i++) {
		if (res!="")
			res += "," + sel.options[i].value;
		else
			res = sel.options[i].value;
	}

	return res;
}

function count_selected(sel) {
	var count = 0;

	for (var i=0; i<sel.options.length; i++) {
		if (sel.options[i].selected) {
			count++;
		}
	}

	return count;
}

function clearTable(tbl) {
	while (tbl.rows.length>1) {
		tbl.deleteRow(1);
	}
}

function submit_form(frmName) {
	var frm = ge(frmName);
	frm.submit();
}

function checkAll(obj, objArray) {
	var els = document.getElementsByTagName("input");
	var c;

	for (i=0; i<els.length; i++) {
		if (in_array(objArray, els[i].name)) {
			c = !(els[i].checked);
			break;
		}
	}

	for (i=0; i<els.length; i++) {
		if (in_array(objArray, els[i].name)) {
			els[i].checked = c;
		}
	}
}

function in_array(arr, val) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i]==val)
			return true;
	}
	return false;
}

function moveUp(strList) {
	var list = ge(strList);

	if (list.selectedIndex!=0) {
		var opt1 = list.options[list.selectedIndex-1];
		var opt2 = list.options[list.selectedIndex];

		var tmpv = opt1.value;
		var tmpt = opt1.text;

		opt1.value = opt2.value;
		opt1.text = opt2.text;

		opt2.value = tmpv;
		opt2.text = tmpt;

		list.selectedIndex--;
	}
}


function moveDown(strList) {
	var list = ge(strList);

	if (list.selectedIndex<list.length-1) {
		var opt1 = list.options[list.selectedIndex];
		var opt2 = list.options[list.selectedIndex+1];

		var tmpv = opt1.value;
		var tmpt = opt1.text;

		opt1.value = opt2.value;
		opt1.text = opt2.text;

		opt2.value = tmpv;
		opt2.text = tmpt;

		list.selectedIndex++;
	}
}


