function ValidateAsNotEmpty(value)
{
    if (value == "" || value == null)
    {
        return false;
    }
    return true;
}

function ValidateAsEmail(value, empty)
{
    if (value == "" || value == null) return empty;
    var r_email = new RegExp("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$","ig");
    var arr = r_email.exec(value);
    if (arr == null)
    {
        return false;
    }
    return true;
}

function ValidateMinLength(value, len)
{
    if (value.length < len)
    {
        return false;
    }
    return true;
}

function ValidateAsNum(value, empty)
{
    if (value == "" || value == null) return empty;
    var r_re = new RegExp('^[0-9]+$',"ig");
    var arr = r_re.exec(value);
    if (arr == null)
    {
        return false;
    }
    return true;
}

function ValidateMaxLength(value, len)
{
    if (value.length > len)
    {
        return false;
    }
    return true;
}

function ValidateAsEnNum(value, empty)
{
    if (value == "" || value == null) return empty;
    var r_re = new RegExp('^[a-zA-Z0-9]+$',"ig");
    var arr = r_re.exec(value);
    if (arr == null)
    {
        return false;
    }
    return true;
}

function ValidateAsRus(value, empty)
{
    if (value == "" || value == null) return empty;
    var r_re = new RegExp('^[à-ÿÀ-ß¸¨/-]+$',"ig");
    var arr = r_re.exec(value);
    if (arr == null)
    {
        return false;
    }
    return true;
}

function ValidateAsEqual(value1, value2, empty)
{
    if ((value1 == "" || value1 == null) && (value2 == "" || value2 == null)) return empty;
    if (value1 == value2)
    {
        return true;
    }
    return false;
}

function ValidateAsPicture(value)
{
    ext = value.substr(value.length - 3, 3).toLowerCase();
    if ((ext == 'gif') || (ext == 'jpg') || (ext == 'png'))
    {
        return true;
    }
    ext = value.substr(value.length - 4, 4).toLowerCase();
    if (ext == 'jpeg')
    {
        return true;
    }
    return false;
}

function ValidateAsFlashAndPicture(value)
{
    ext = value.substr(value.length - 3, 3).toLowerCase();
    if ((ext == 'swf') || (ext == 'gif') || (ext == 'jpg') || (ext == 'png'))
    {
        return true;
    }
    ext = value.substr(value.length - 4, 4).toLowerCase();
    if (ext == 'jpeg')
    {
        return true;
    }
    return false;
}

function ValidateAsInteger(val1, val2, val3)
{
    if (val1 == "") return true;
    if (isNaN(parseInt(val1, 10)) || (val2 != '') && (parseInt(val1, 10) >= val2) || (val3 != '') && (parseInt(val1, 10) <= val3))
    {
        return true;
    }
    return false;
}

function ValidateAsHexColor(value, empty)
{
    if (value == "" || value == null) return empty;
    var r_re = new RegExp('^[a-fA-F0-9]{6}$',"ig");
    var arr = r_re.exec(value);
    if (arr == null)
    {
        return false;
    }
    return true;
}
// -- OLD







function ValidateAsNotEmptyArray(ErrorMessage,form,elem)
{
    flag = false;
    var theElements = document.forms[form].elements[elem];
    for (var count = 0; count < theElements.length; count++) {
        if (theElements[count].checked) flag = true;
    }
    if (!flag)
    {
        alert(ErrorMessage);
    }
    return flag;
}

function ValidateAsURL(ErrorMessage, value)
{
    if (value=="") return true;
    var r_url = new RegExp("^(http|https|ftp)://(www\.)?.+([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$","ig");
    var arr = r_url.exec(value);
    if (arr == null)
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateAsWM(ErrorMessage, value)
{
    if (value=="") return true;
    var r_wm= new RegExp("^Z[0-9]{12}","ig");
    var arr = r_wm.exec(value);
    if (arr == null)
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateRegularExpression(ErrorMessage, value, reg)
{
    if (value=="") return true;
    var r_re = new RegExp(reg,"ig");
    var arr = r_re.exec(value);
    if (arr == null)
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateAsEqualTo(ErrorMessage, val1, val2)
{
    if ( val1 != val2 )
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateAsDifferentFrom(ErrorMessage, val1, val2)
{
    if ( val1 == val2 )
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateAsFloat(ErrorMessage, val1, val2, val3)
{
    if (val1=="") return true;
    if (isNaN(parseFloat(val1, 10)) || (val2 != '') && (parseFloat(val1, 10) < val2) || (val3 != '') && (parseFloat(val1, 10) > val3))
    //		if (isNaN(val1) || (val2 != '') && (val1 < val2) || (val3 != '') && (val1 > val3))
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

function ValidateMAX_FILE_SIZE(ErrorMessage, val1,val2)
{
    if (val1>val2)
    {
        alert(ErrorMessage);
        return false;
    }
    return true;
}

