// Allows only numeric characters [0-9]
// if the argument isInteger is false, than additionaly the character "." (keycode 46) 
// is allowed
function isNumeric(char, mozChar, isInteger) {
    if(mozChar != null) { 
	    // Mozilla-compatible browser
        if((mozChar >= 48 && mozChar <= 57) || mozChar == 0 || char == 8 || mozChar == 13 || mozChar == 46) {
        	if ( mozChar == 46 && isInteger) {
        	    RetVal = false; 
        	} else {
        	    RetVal = true;
        	}
        } else {
            RetVal = false;
        }
    } else { 
        // IE-compatible Browser
        if((char >= 48 && char <= 57) || char == 13) {
            if (char == 46 && isInteger) {
                RetVal = false;  
            } else {
                RetVal = true;
            }
        } else {
            RetVal = false;
        }
    }
    return RetVal;
}

// Checks the length of the field specified by elementId. 
function checkLength(elementId, errMessage, minLength, maxLength) {
    var element = document.getElementById(elementId);
    
    if (element) {
        var elementLength = element.value.length;
        if (elementLength >= minLength && elementLength <= maxLength) {
            return true;
        } else {
            alert(errMessage);
            document.getElementById(elementId).focus();
            
            return false;
        }
    } else {
        return false;
    }
}

// Checks if the value of the field specified by elementId matches the
// given pattern.
function checkPattern(elementId, errMessage, pattern) {
    var element = document.getElementById(elementId);
    
    if (element) {
        var elementValue = element.value;
        if (elementValue.match(pattern)) {
            return true;
        } else {
            alert(errMessage);
            element.focus();

            return false;
        }
    } else {
        return false;
    }
}

