﻿function singleClick(controlID,postBackEvent)
{
    if (typeof (Page_ClientValidate) == 'function') {if (Page_ClientValidate() == false) { return false; }} 
    //document.getElementById(controlID.id).value = 'please wait';
    document.getElementById(controlID.id).disabled = true;
}

function contact_validateEmail(control) {
    var strControl = control.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    var regEx = new RegExp(/^([a-zA-Z0-9]{1,})(((\.|\-|\_)[a-zA-Z0-9]{2,})+)?@([a-z]{3,})(\-[a-z0-9]{3,})?(\.[a-z]{2,})+$/);
    if (strControl == '') {
        control.className = 'textbox';
        return true;
    }
    else {
        if (regEx.test(strControl)) {
            control.className = 'textbox';
            return true;
        }
        else {
            control.className = 'textbox_validate';
            return false;
        }
    }
}

function contact_emailCompare(email1, email2) {
    var strEmail1 = email1.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    var strEmail2 = email2.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    if (strEmail1 != strEmail2) {
        email1.className = 'textbox_validate';
        email2.className = 'textbox_validate';
        return false;
    } else {
        email1.className = 'textbox';
        email2.className = 'textbox';
        return true;
    }
}

function contact_validateOnBlur(control) {
    var strControl = control.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    if (strControl.length > 0) {
        control.className = 'textbox';
    }
}

function contact_validatePost(email_name,email_address,email_confirm,email_query) {
    var alertMessage = "";
    var strFullName = email_name.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    var strEmailAddress = email_address.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    var strConfirmEmailAddress = email_confirm.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    var strQuery = email_query.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');    

    //Verify all mandatory fields have been populated
    if (strFullName.length <= 0) { alertMessage = alertMessage + '* Fullname must have a value\n\r'; email_name.className = 'textbox_validate'; }
    if (strEmailAddress.length <= 0) { alertMessage = alertMessage + '* Email Address must have a value\n\r'; email_address.className = 'textbox_validate'; }
    else if (!contact_validateEmail(document.getElementById('email_address'))) { alertMessage = alertMessage + '* The Email Address you have entered is not valid\n\r'; email_address.className = 'textbox_validate'; }
    if (strConfirmEmailAddress.length <= 0) { alertMessage = alertMessage + '* Confirm email address must have a value\n\r'; email_confirm.className = 'textbox_validate'; }
    else if (!contact_emailCompare(document.getElementById('email_address'), document.getElementById('email_confirm'))) { alertMessage = alertMessage + '* Your email addresses do not match\n\r'; email_address.className = 'textbox_validate'; }
    if (strQuery.length <= 0) { alertMessage = alertMessage + '* Your Comment/Query must have a value\n\r'; email_query.className = 'textbox_validate'; }

    if (alertMessage.length <= 0) {
        return true;
    } else {
        alert(alertMessage)
        return false;
    }
}
