function trim(val)
{   if (val.length == 0) return '';
	if (val == '') return '';
    var lc = 0;
    var rc = 0;
    for (trim_i = 0; trim_i < val.length; trim_i++)
        if (val.charAt(trim_i) == ' ')
            lc++;
        else
            break;;

    for (trim_i = val.length - 1; trim_i >= 0; trim_i--)
        if (val.charAt(trim_i) == ' ')
            rc++;
        else
            break;

    return val.substr(lc, val.length - rc - lc);
}


function isDate(val)
{
    var re = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/
    val += ''

    if (!val.search(re)) 
    {
        var MatchStr = val.replace(re,'$1,$2,$3')
        var Matches = MatchStr.split(',')
        if (0+Matches[0] < 1 || 0+Matches[0] > 31) return false
        if (0+Matches[1] < 1 || 0+Matches[1] > 12) return false
        if (Matches[0].length == 1) Matches[0] = '0' + Matches[0]
        if (Matches[1].length == 1) Matches[1] = '0' + Matches[1]
        val = Matches.join('.')

        return val
    }
    else {
        return false
    }
}

function isInteger(val)
{
    var re = /^\d+$/
    val += ''

    if (!val.search(re)) {
        return true
    }
    else {
        return false
    }
}

function isFloat(val)
{
    var re = /^(\d+)?(\.\d+)?$/
    val += ''

    if (!val.search(re)) {
        return true
    }
    else {
        return false
    }
}

function isHttpUrl(val)
{
    var re = /^http(s?):\/\/[a-zA-Z0-9\.]+(\.[a-zA-Z]{2,})$/
    val += ''

    if (!val.search(re)) {
        return true
    }
    else {
        return false
    }
}

function isMail(val)
{
    var re = /^[a-zA-Z0-9\-\_\.]{2,}@[A-Za-z0-9\_\-\.]{2,}\.[A-Za-z]{2,4}$/
    val += ''

    if (!val.search(re)) { 
        return 0;
    }
    else {
        return 1;
    }
}

function isHex(val)
{
    var re = /^[\dA-Fa-f]+$/
    val += ''

    if (!val.search(re)) {
        return true
    }
    else {
        return false
    }
}