﻿function IsEmpty(text) 
{
    if (text == "")
        return true;    
    return false;
}

function IsIllegalChar(text) 
{
    var illegalChars = "()/|?,;:'~<>\\+=.[]{}"
    var char;

    for (var i = 0; i < text.length; i++)
    {
        char = text.charAt(i);
        if (illegalChars.indexOf(char) != -1)
            return true;
    }
    return false;
}

function IsValidText(text, EmptyMsg, IllegalMsg) 
{
    if(IsEmpty(text))
    {
        ErrorMsg = EmptyMsg;
        return false;
    }
    if (IsIllegalChar(text)) 
    {
        ErrorMsg = IllegalMsg;
        return false;
    }
    return true;
}

function IsTextFilled(text, EmptyMsg) 
{
    if (IsEmpty(text)) 
    {
        ErrorMsg = EmptyMsg;
        return false;
    }
    return true;
}

function IsValidTextEmpty(text, IllegalMsg) 
{
    if (IsIllegalChar(text)) 
    {
        ErrorMsg = IllegalMsg;
        return false;
    }
    return true;
}

function IsComboSelected(ctrlCombo, SelectMsg) {
    if (ctrlCombo.selectedIndex <= 0)
    {
        ErrorMsg = SelectMsg;
        return false;
    }
    return true;
}


function IsCheckBoxChecked(checkBox, SelectMsg) {
    if (checkBox.checked ==false) {
        ErrorMsg = SelectMsg;
        return false;
    }
    return true;
}

function IsValidDecimalValue(text, msg) {
    if (!IsDecimalValue(text)) {
        ErrorMsg = msg;
        return false;
    }
    return true;
}

function IsValidIntValue(text, msg) {
    if (!IsIntValue(text)) {
        ErrorMsg = msg;
        return false;
    }
    return true;
}

function IsDecimalValue(text) {
    var regexDecimal = /^\d+(\,\d{3})*(\.\d)?$/;
    return text.match(regexDecimal);
}

function IsIntValue(text) 
{
    var regexDecimal = /^\d+(\,\d{3})*$/
    return text.match(regexDecimal);
}

function IsNumberKey(e) 
{
    var key = e.keyCode;

    if (key == 13 || key == 46 || key == 8 || key == 37 || key == 39 || key == 190 || key == 110 || (key > 95 && key < 106) || key == 9 || (key > 47 && key < 58))
        return true;
    else
        return false;
}

function IsIntNumberKey(e) {
    var key = e.keyCode;

    if (key == 13 || key == 46 || key == 8 || key == 37 || key == 39 || (key > 95 && key < 106) || key == 9 || (key > 47 && key < 58))
        return true;
    else
        return false;
}

function IsValidEmail(mail, EmptyMsg, InvalidEmail) {
    //var mail = document.getElementById('<%=txtEmail.ClientID %>').value;
    if (IsTextFilled(mail, EmptyMsg)) {
        var emailExp = /^([\w]+)(\.[\w]+)*@([\w\-]+)(\.[\w]{2,7})(\.[a-z]{2})?$/;
        if (!mail.match(emailExp)) {
            ErrorMsg = InvalidEmail;
            return false;
        }
        return true;
    }
    else
        return false;
}
