var validateOtherBox = false;
function showError(errorText) {
    wb = document.getElementById('warningBox');
    wb.innerHTML = errorText;
    wb.style.display = '';
}
function hideError() {
    wb = document.getElementById('warningBox');
    wb.style.display = 'none';
}
function validateName() {
    nameBox = document.getElementById('firstName');
    if(nameBox.value == '') {
        validateOtherBox = true;
        showError('Please enter your name.');
        nameBox.focus();
    } else {
        hideError();
    }
}
function validateEmail() {
    if(!validateOtherBox) {
        emailBox = document.getElementById('email');
        if(emailBox.value != "") {
            if(emailBox.value.indexOf('@') != -1 && emailBox.value.indexOf('.') != -1 && emailBox.value.indexOf('\'') == -1 && emailBox.value.indexOf(';') == -1) {
                //Call the webservice to make sure this e-mail isn't already in use.
                checkEmailOnServer(emailBox.value);
                //hideError();
            } else {
                validateOtherBox = true;
                showError('Please enter a valid e-mail address (with no apostrophes or semi-colons)');
                emailBox.focus();
            }
        }
    } else {
        validateOtherBox = false;
    }
}
function validatePasswords() {
    if(!validateOtherBox) {
        pw1 = document.getElementById('password1');
        pw2 = document.getElementById('password2');
        
        if(pw1.value != pw2.value) {
            validateOtherBox = true;
            showError('Your passwords do not match.  Please go back and try again.');
            pw1.focus();
        } else {
            hideError();
        }
    } else {
        validateOtherBox = false;
    }
}
function checkEmailOnServer(emailAddress) {
    var soaprequest, param;

	param = AddXMLParameter("emailAddress", emailAddress);
	param = WrapXML("CheckEmailAddress", "xmlns='http://webservice.lifepics.com'", param);

	soaprequest = CreateSOAPRequestXML(param);

	SubmitSOAPRequest(soaprequest, "http://webservice.lifepics.com/CheckEmailAddress", getEmailResponse);
}
function getEmailResponse() {
    if(GotGoodResponse()) {
        var dom = http.responseXML;
        var emailStatusNode = dom.getElementsByTagName("EmailStatus")[0];
        var emailStatus = emailStatusNode.firstChild.nodeValue;

	    if(emailStatus == "valid") {
	        showError("I'm sorry, this e-mail address is currently in use.");
		    document.getElementById('email').focus();
	    } else {
	        hideError();
	    }
    }
}
function ValidateRegistration() {
    var nameBox = document.getElementById("firstName");
    var emailBox = document.getElementById("email");
    var pass1Box = document.getElementById("password1");
    var pass2Box = document.getElementById("password2");

    var validForm = true;
    if(emailBox.value.indexOf('@') == -1 || emailBox.value.indexOf('.') == -1) {
        showError("Please enter a valid e-mail address.");
        validForm = false;
    }
    if(nameBox.value == "") {
        showError("Please enter your first name.");
        validForm = false;
    }
    if(pass1Box.value == "" || pass2Box.value == "") {
        showError("Please enter your password.");
        validForm = false;
    }
    if(pass1Box.value != pass2Box.value) {
        showError("Your passwords do not match.");
        validForm = false;
    }
    
    return validForm;
}