﻿globalVars['servicesUrl'] = '../services/DataServices.asmx';
globalVars['webMethod'] = 'Register';
globalVars['errorMessage'] = 'Registration failed, please try again or contact the site administrator.';
globalVars['successMessage'] = '*** Registration submitted successfully. ***';

$(document).ready(function() {
    $.validity.setup({ outputMode: "modal", defaultFieldName: "" });
    $.extend($.validity.messages, {
        require: "This field is required.",
        // Format validators:
        match: "This field is in an invalid format.",
        integer: "This field must be a positive, whole number.",
        date: "This field must be formatted as a date.",
        email: "This field must be formatted as an email.",
        usd: "This field must be formatted as a US Dollar amount.",
        url: "This field must be formatted as a URL.",
        number: "This field must be formatted as a number.",
        zip: "This field must be formatted as a zipcode ##### or #####-####.",
        phone: "This field must be formatted as a phone number ###-###-####.",
        guid: "This field must be formatted as a guid like {3F2504E0-4F89-11D3-9A0C-0305E82C3301}.",
        time24: "This field must be formatted as a 24 hour time: 23:00.",
        time12: "This field must be formatted as a 12 hour time: 12:00 AM/PM",

        // Value range messages:
        lessThan: "This field must be less than #{max}.",
        lessThanOrEqualTo: "This field must be less than or equal to #{max}.",
        greaterThan: "This field must be greater than #{min}.",
        greaterThanOrEqualTo: "This field must be greater than or equal to #{min}.",
        range: "This field must be between #{min} and #{max}.",

        // Value length messages:
        tooLong: "This field cannot be longer than #{max} characters.",
        tooShort: "This field cannot be shorter than #{min} characters.}",

        // Aggregate validator messages:
        equal: "Values don't match.",
        distinct: "A value was repeated.",
        sum: "Values don't add to #{sum}.",
        sumMax: "The sum of the values must be less than #{max}.",
        sumMin: "The sum of the values must be greater than #{min}.",

        nonHtml: "This field cannot contain Html characters.",

        generic: "Invalid."
    });
    $('#submit').click(function() {
    if (com.ctc.validated()) {
            com.ctc.submitForm();
        }
    });
    $('#jsWarning').toggleClass('hide', true);
    com.ctc.set_captchaTimestamp(new Date());
    com.ctc.fillLocations();
});

com.ctc.fillLocations = function() {
    var locList = $('#location');
    jQuery.each(locations, function() {
        locList.append("<option value='" + this + "'>" + this + "</option>");
    });
}

com.ctc.validated = function() {
    //Check payment type
    var payment = false;
    $(':input[type=radio]').each(function() {
        var obj = $(this);
        if (obj.is(':checked')) {
            payment = true; 
            return;
        }
    });

    $.validity.start();
    $(".require").require();
    $('#paymentReq').assert(payment, 'Payment type is required.');
    var result = $.validity.end();

    return (result.valid && payment);
}
