﻿var 
 isDOM=document.getElementById?1:0,
 isIE=document.all?1:0,
 isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,
 isOp=self.opera?1:0,
 isDyn=isDOM||isIE||isNS4;

function getRef(i, p)
{
 p=!p?document:p.navigator?p.document:p;
 return isIE ? p.all[i] :
  isDOM ? (p.getElementById?p:p.ownerDocument).getElementById(i) :
  isNS4 ? p.layers[i] : null;
};

/* trims the string */
function trim(str) {
    return str.replace(/(^\s+)([^\s]*)(\s+$)/, '$2');
}


/* tests if the value is a float number */
function isFloat(s)
{
	s = trim(s);
    if (isEmpty(s)) {
        return false;
    }

    var seenDecimalPoint = false;
    if (s == '.') {
        return false;
    }
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (var i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (c == '-' && i > 0) return false;
        if (c == '-') continue;
        if (c == ' ') continue;
        if ((c == '.') && !seenDecimalPoint) {
            seenDecimalPoint = true;
        } else if (!isDigit(c)) {
            return false;
        }
    }

    // All characters are numbers.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isDigit(c)
{
    return ((c >= "0") && (c <= "9"));
}