﻿function RegistrationStep1() {
    this.chkTerm = new Object();
    this.ddlBirthDateDay = new Object();
    this.ddlBirthDateDay2 = new Object();
    this.ddlBirthDateMon = new Object();
    this.ddlBirthDateMon2 = new Object();
    this.ddlBirthDateYear = new Object();
    this.ddlBirthDateYear2 = new Object();
    this.ddlHearAbout = new Object();
    this.ddlMemberType = new Object();
    this.ddlSuburb = new Object();
    this.DivPartnerBirthday = new Object();
    this.hdnCity = new Object();
    this.hdnSuburb = new Object();
    this.MyBday = new Object();
    this.PartnerBday = new Object();
    this.txtOther = new Object();
    this.txtPostCode = new Object();
    
    this.memberTypeChange = function(inVal) {
        try {
            if (inVal == 4 || inVal == 16 || inVal == 32) {
                this.DivPartnerBirthday.style.display = "";
                
                if (inVal == 4) //cpl mf
                {
                    this.MyBday.innerHTML = "His birthday:";
                    this.PartnerBday.innerHTML = "Her birthday:";
                }
                else if (inVal == 16) //cpl ff
                {
                    this.MyBday.innerHTML = "My birthday:";
                    this.PartnerBday.innerHTML = "Her birthday:";
                }
                else if (inVal == 32) //cpl mm
                {
                    this.MyBday.innerHTML = "My birthday:";
                    this.PartnerBday.innerHTML = "His birthday:";
                }
                else {
                    this.MyBday.innerHTML = "My birthday:";
                    this.DivPartnerBirthday.style.display = "none";
                }
            }
            else {
                this.MyBday.innerHTML = "My birthday:";
                this.DivPartnerBirthday.style.display = "none";
            }
        }
        catch (e) { }
    };



    this.Birthdate_Validation = function(source, args) {
        var bReturnValue = true;
        var Now = new Date();

        if (Number(this.ddlMemberType.value) == 4
                        || Number(this.ddlMemberType.value) == 16
                        || Number(this.ddlMemberType.value) == 32) {
            if (Number(this.ddlBirthDateYear.value) >= Now.getFullYear() - 18) {
                if (Now.getMonth() + 1 < Number(this.ddlBirthDateMon.value)) {
                    bReturnValue = false;
                }
                else if (Now.getMonth() + 1 == Number(this.ddlBirthDateMon.value)) {
                    if (Now.getDate() < Number(this.ddlBirthDateDay.value)) {
                        bReturnValue = false;
                    }
                }
            }

            if (Number(this.ddlBirthDateYear2.value) >= Now.getFullYear() - 18) {
                if (Now.getMonth() + 1 < Number(this.ddlBirthDateMon2.value)) {
                    bReturnValue = false;
                }
                else if (Now.getMonth() + 1 == Number(this.ddlBirthDateMon2.value)) {
                    if (Now.getDate() < Number(this.ddlBirthDateDay2.value)) {
                        bReturnValue = false;
                    }
                }
            }
        }
        else {
            if (Number(this.ddlBirthDateYear.value) >= Now.getFullYear() - 18) {
                if (Now.getMonth() + 1 < Number(this.ddlBirthDateMon.value)) {
                    bReturnValue = false;
                }
                else if (Now.getMonth() + 1 == Number(this.ddlBirthDateMon.value)) {
                    if (Now.getDate() < Number(this.ddlBirthDateDay.value)) {
                        bReturnValue = false;
                    }
                }
            }
        }

        args.IsValid = bReturnValue;
    };





    this.Terms_ClientValidation = function(source, args) {
        args.IsValid = this.chkTerm.checked;
    };

    this.MyBirthDate_ClientValidation = function(source, args) {
        var year = this.ddlBirthDateYear;
        var month = this.ddlBirthDateMon;
        var day = this.ddlBirthDateDay;

        args.IsValid = this.isDate(year.value, month.value, day.value);
    };

    this.PartnerBirthDate_ClientValidation = function(source, args) {
        var memberType = this.ddlMemberType;
        var year = this.ddlBirthDateYear2;
        var month = this.ddlBirthDateMon2;
        var day = this.ddlBirthDateDay2;
        var inVal = memberType.value;

        if (inVal == 4 || inVal == 16 || inVal == 32) {
            args.IsValid = this.isDate(year.value, month.value, day.value);
        }
        else {
            args.IsValid = true;
        }
    };

    this.CustomFeedBack_ClientValidation = function(source, args) {

        var retVal = true;
        var ddl = this.ddlHearAbout;
        var txt = this.txtOther;

        if (String(ddl.value).toLowerCase() == "void") {
            retVal = false;
        }
       
        args.IsValid = retVal;
    };

    this.CustomFeedBackOther_ClientValidation = function(source, args) {

        var retVal = true;
        var ddl = this.ddlHearAbout;
        var txt = this.txtOther;

       if (String(ddl.value) == "Other") {
            if (txt.value.length < 2) {
                retVal = false;
            }
        }

        args.IsValid = retVal;
    };

    this.customSuburb_ClientValidation = function(source, args) {

        var retVal = true;
        var valid = "0123456789";
        var isValid = true;
        var temp;
        var val;

        val = this.txtPostCode.value;

        if (val.length == 4) {
            for (var i = 0; i < val.length; i++) {
                temp = val.substring(i, i + 1);
                if (valid.indexOf(temp) == "-1") {
                    isValid = false;
                }
            }

            if (isValid && String(this.hdnSuburb.value) == "0") {
                retVal = false;
            }
        }
        args.IsValid = retVal;
    };

    this.isDate = function(year, month, day) {
        // month argument must be in the range 1 - 12
        month = month - 1; // javascript month range : 0- 11
        var tempDate = new Date(year, month, day);
        if (((tempDate.getFullYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate())) {
            return true;
        }
        else {
            return false;
        }
    };

    this.ddlSuburb_OnChange = function(val) {

        var w = this.ddlSuburb.selectedIndex;
        var selected_text = this.ddlSuburb.options[w].text;

        this.hdnSuburb.value = val;
        this.hdnCity.value = selected_text;
    };


    this.suburbInit = function(val) {
        var valid = "0123456789";
        var isValid = true;
        var w;
        var selected_text;
        var temp;


        if (val.length == 4) {

            for (var i = 0; i < val.length; i++) {
                temp = val.substring(i, i + 1);
                if (valid.indexOf(temp) == "-1") {
                    isValid = false;
                }
            }

            if (isValid) {
                if (this.ddlSuburb.value != null) {
                    w = this.ddlSuburb.selectedIndex;
                    selected_text = this.ddlSuburb.options[w].text;
                    this.hdnSuburb.value = this.ddlSuburb.value;
                    this.hdnCity.value = selected_text;
                }

            }
        }
    };
}
