
function TDCcheckLength(InputText, MinLength)
    {
	//alert(!(MinLength > 1))
	if(!(MinLength > 1)) MinLength = 1;
	if(InputText.length < MinLength) return false
	return true
    }

	
function TDCcheckEmail(InputText)
    {
	var iA=InputText.indexOf("@");
	var iP=InputText.indexOf(".");
	if (iA>0 & iP>(iA+1) & InputText.length>(iP+1))
		return true;
    return false;   
    }

function TDCcheckInteger(InputText)
    {
    //Returns true if value is an integer or is NULL
    //otherwise returns false   

    if (InputText.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
        var decimal_format = ".";
        var check_char;

    //The first character can be + -  blank or a digit.
        check_char = InputText.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
        return TDCchecknumber(InputText);
    else
        return false;
    }


function TDCcheckNumber(InputText)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false   

    if (InputText.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
        var start_format = " .+-0123456789";
        var number_format = " .0123456789";
        var check_char;
        var decimal = false;
        var trailing_blank = false;
        var digits = false;

    //The first character can be + - .  blank or a digit.
        check_char = start_format.indexOf(InputText.charAt(0))
    //Was it a decimal?
        if (check_char == 1)
            decimal = true;
        else if (check_char < 1)
                return false;
        
        //Remaining characters can be only . or a digit, but only one decimal.
        for (var i = 1; i < InputText.length; i++)
        {
                check_char = number_format.indexOf(InputText.charAt(i))
                if (check_char < 0)
                        return false;
                else if (check_char == 1)
                {
                        if (decimal)            // Second decimal.
                                return false;
                        else
                                decimal = true;
                }
                else if (check_char == 0)
                {
                        if (decimal || digits)  
                                trailing_blank = true;
        // ignore leading blanks

                }
                else if (trailing_blank)
                        return false;
                else
                        digits = true;
        }       
    //All tests passed, so...
    return true
    }



function TDCcheckRange(InputText, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (InputText.length == 0)
        return true;


    if (!TDCchecknumber(InputText))
        {
        return false;
        }
    else
        {
        return (SubNumberRange((eval(InputText)), min_value, max_value));
        }
        
    //All tests passed, so...
    return true;
    }

function SubNumberRange(InputText, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
        {
        if (InputText < min_value)
                return false;
        }

    // check maximum
    if (max_value != null)
        {
        if (InputText > max_value)
                return false;
        }
        
    //All tests passed, so...
    return true;
    }
