// common.js
// jno's library of common javascript routines

var isDOM= document.getElementById ? true : false;
var hasAll= document.all ? true : false;
var isMSIE= hasAll && (document.all.item!=null);
var isMSIE5= isDOM && isMSIE && (window.opera==null);
function getElement(eid) {
    var ret = null;
    if(isDOM) ret = document.getElementById(eid);
    else if(isMSIE) ret = document.all[eid];
    return(ret);
}

function getSelectedText() {
    // best called with 'onMouseDown' event (not 'onClick')
	var txt = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
	}
	else return false;
	return txt;
}

function only_digits(field) {
    // usage: <input type=text onKeyUp="only_digits(this)" ... />
    var errors = 0;
    var tmp = '';
    for(i=0; i<field.value.length; i++) {
        c = field.value[i];
        if((c >= '0') && (c <= '9'))
            tmp += c;
        else
            errors += 1;
    }
    field.value = tmp;
    if( errors ) alert( 'Only digits allowed here!' );
}

// EOF common.js
