﻿function CustomValidator(validatorSummaryId, customValidatorId, mode, ControlToFocus, emailAddress) {
    var myControls = new Array();
    myControls[0] = validatorSummaryId;
    myControls[1] = customValidatorId;
    myControls[2] = mode;
    myControls[3] = ControlToFocus;
    var service = new CoffeeHub.Web.UI.ValidationService();
    service.CheckExistingEmail(emailAddress, onValidEmail, null, myControls);
}

function onValidEmail(result, myControls) {
    document.getElementById(myControls[0]).innerHTML = "";
    var mode = myControls[2];
    var controlToFocus = myControls[3]
    if (result) {
        var validated = Page_ClientValidate(mode + 'ValidationPage1');
        if (validated) {
            document.getElementById(mode + 'firstFormDetails').style.display = 'none';
            document.getElementById(mode + 'secondFormDetails').style.display = 'block';
            document.getElementById(mode + 'thirdFormDetails').style.display = 'none';
            document.getElementById(mode + 'page1buttons').style.display = 'None';
            document.getElementById(mode + 'page2buttons').style.display = '';
            document.getElementById(mode + 'page3buttons').style.display = 'None';
            if (mode == 'Register') {
                setStep(2);
            }
            document.getElementById(controlToFocus).focus();
        }
        else {
            Page_ClientValidate(mode + 'ValidationPage1');
            document.getElementById(myControls[0]).style.display = 'block';
            document.getElementById(myControls[0]).style.visibility = 'visible';
        }
    }
    else {
        document.getElementById(myControls[0]).style.display = 'block';
        document.getElementById(myControls[0]).style.visibility = 'visible';
        document.getElementById(myControls[0]).innerHTML += 'This email address is already registered please try another<br />';
    }
}

function SetSessionValue(sessionVal)
{
    var service = new CoffeeHub.Web.UI.ValidationService();
    service.SetSessionVal(sessionVal);
}
