﻿Type.registerNamespace("WM.SVR.Web");

WM.SVR.Web.RegistrationForm = function(options) {
    this.chkAcceptConditions = $get(options.chkAcceptConditions);
    this.txtMobilnr = $get(options.txtMobilnr);
    this.txtHemnr = $get(options.txtHemnr);
    this.chkStudent = $get(options.chkStudent);    
    this.currentView = options.view;
}

WM.SVR.Web.RegistrationForm.prototype = {
    cUniversity_Validate: function(source, args) {
        args.IsValid = (this.chkStudent.checked && args.Value.length > 0) || (!this.chkStudent.checked);
    },

    cEducationStartYear_Validate: function(source, args) {
        args.IsValid = (this.chkStudent.checked && args.Value.length > 0) || (!this.chkStudent.checked);
    },

    chkStudent_Checked: function(evt, cUniversity, cEducationStartYear, ddlExamensarID, ddlAcademicTitleID) {
        var sender = getEventTarget(evt);             
    
        ValidatorValidate(cUniversity);
        ValidatorValidate(cEducationStartYear);
        
        if (sender.checked)
            disableControls(ddlExamensarID, ddlAcademicTitleID);
        else
            enableControls(ddlExamensarID, ddlAcademicTitleID);
    },

    cGraduationYear_Validate: function(source, args) {
        if (this.currentView == "MemberJoin" || currentView == "MemberSelf")
            args.IsValid = (!this.chkStudent.checked && args.Value.length > 0) ||
                            this.chkStudent.checked;
        else
            args.IsValid = true;
    },

    cAcceptConditions_Validate: function(source, args) {        
        args.IsValid = this.chkAcceptConditions.checked;
    },

    chkAcceptConditions_Checked: function(cAcceptConditions) {
        ValidatorValidate(cAcceptConditions);        
    },

    ValidateMobilOrHem: function(source, args) {
        args.IsValid = (this.txtMobilnr.value.length > 0 || this.txtHemnr.value.length > 0);
    },
    
    DoEraseTextBoxValue: function(textboxID, defaultValue) {
        var textbox = $get(textboxID);
        if (textbox && textbox.value == defaultValue)
            textbox.value = '';
    }
}

WM.SVR.Web.RegistrationForm.registerClass("WM.SVR.Web.RegistrationForm");

if (typeof Sys != "undefined")
    Sys.Application.notifyScriptLoaded();
