﻿function ValidateField(s, e) {
    var message = "";
    if (s.name == "btnSendContact") {
        if (clientName.GetText() == "") {
            message += "Name" + '\n';
        }
        if(company.GetText() == "" ) {
            message += "Company" + '\n';
        }
        if (phoneNumber.GetText() == "") {
            message += "Phone Number" + '\n';
        }
        if (email.GetText() == "") {
            message += "Email" + '\n';
        }
        if (email.GetText() != "") {
            if (CheckEmail(email.GetText()) == false) {
                message += "Invalid Email" + '\n';
            }
        }
        if (comments.GetText() == "") {
            message += "Comments" + '\n';
        }
    }
    else if (s.name == "btnSendDemo") {
        if (clientName.GetText() == "") {
            message += "Name" + '\n';
        }
        if (company.GetText() == "") {
            message += "Company" + '\n';
        }
        if (phoneNumber.GetText() == "") {
            message += "Phone Number" + '\n';
        }
        if (email.GetText() == "") {
            message += "Email" + '\n';
        }
        if (email.GetText() != "") {
            if (CheckEmail(email.GetText()) == false) {
                message += "Invalid Email" + '\n';
            }
        }
        if (country.GetText() == "") {
            message += "Country" + '\n';
        }
        if (state.GetText() == "") {
            message += "State" + '\n';
        }
        if (demoDate.GetText() == "") {
            message += "Demo Date" + '\n';
        }
        if (time.GetText() == "") {
            message += "Demo Time" + '\n';
        }
    }
    else if (s.name == "btnSendTry") {
        if (firstName.GetText() == "") {
            message += "First Name" + '\n';
        }
        if (lastName.GetText() == "") {
            message += "Last Name" + '\n';
        }
        if (company.GetText() == "") {
            message += "Company" + '\n';
        }
        if (country.GetText() == "") {
            message += "Country" + '\n';
        }
        if (state.GetText() == "") {
            message += "State" + '\n';
        }
        if (phoneNumber.GetText() == "") {
            message += "Phone Number" + '\n';
        }
        if (email.GetText() == "") {
            message += "Email" + '\n';
        }
        if (email.GetText() != "") {
            if (CheckEmail(email.GetText()) == false) {
                message += "Invalid Email" + '\n';
            }
        }
        if (expenseFilers.GetText() == "") {
            message += "Expense Filers" + '\n';
        }
        if (password.GetText() == "") {
            message += "Password" + '\n';
        }
        if (password.GetText() != "") {
            if (password.GetText().length < 6) {
                message += "Password must be at least 6 characters" + '\n';
            }else {
                if (password.GetText() != passwordConfirm.GetText()) {
                    message += "Passwords do not match" + '\n';
                    e.processInServer = false;
                }
            }
        }


    }
    if (message != "") {
        alert("Please fill out the following field(s):" + '\n' + '\n' + message);
        e.processOnServer = false;
    } else {
        e.processOnServer = true;
    }
}

function CheckEmail(value) {
    var objRegExp = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (objRegExp.test(value) == true) {
        return true;
    }
    else {
        return false;
    }
}

//function CheckEmail1(value) {
//    return CheckRegExp("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/", value);
//}

//function CheckRegExp(pattern, value) {
//    var reg = new RegExp(pattern);
//    return reg.exec(value) != null ? true : false;
//}


//function TextBox_OnChange() {
//    if (IsErrorVisible())
//        ValidateField();
//}
//function ValidateField1() {
//    var name = document.getElementById('name');
//    var company = document.getElementById('company');
//    var phoneNumber = document.getElementById('phoneNumber');
//    var email = document.getElementById('email');
//    var comments = document.getElementById('comments');
//    var isName = Check(name.GetValue());
//    var isCompany = Check(company.GetValue());
//    var isPhoneNumber = Check(phoneNumber.GetValue());
//    var isEmail = CheckEmail(email.valueGetValue());
//    var isComments = Check(comments.GetValue());
//    var errorText = '';
//    if (!isName)
//        errorText += 'Invalid login.';
//    if (!isCompany) {
//        if (errorText != '')
//            errorText += '<br /><br />';
//        errorText += 'Invalid password.';
//    }
//    if (!isEmail) {
//        if (errorText != '')
//            errorText += '<br /><br />';
//        errorText += 'Invalid email address.';
//    }
//    if (isName && isCompany && isPhoneNumber && isEmail && isComments) {
//        SetErrorVisible(false);
//    } else {
//        SetErrorString(errorText);
//        SetErrorVisible(true);
//    }
//}
//function Check(value) {
//    return CheckRegExp("^[a-z]+$", value);
//}

