//Initialise
function FormSpecial_initialise(name_form, special_checkboxes) {
    //Setup Exclusion List
    var include_checkboxes = new Array();
    var exclude_checkboxes = new Array();
    if (special_checkboxes != null) {
        //Add Included Checkboxes to Inclusion List
        if (special_checkboxes.include != null) {
           for (ci=0; ci < special_checkboxes.include.length; ci++) {
        			if (special_checkboxes.include[ci] == null) continue;
           		include_checkboxes[include_checkboxes.length] = special_checkboxes.include[ci];
           }
        }

        //Add Excluded Checkboxes to Exclusion List
        if (special_checkboxes.exclude != null) {
           for (ce=0; ce < special_checkboxes.exclude.length; ce++) {
        			if (special_checkboxes.exclude[ce] == null) continue;
           		exclude_checkboxes[exclude_checkboxes.length] = special_checkboxes.exclude[ce];
           }
        }

        //Initialise Reference Checkbox and add it to Exclusion List
        if (special_checkboxes.ref != null) {
           this.Checkbox_Ref = this.getCheckbox(special_checkboxes.ref);
           exclude_checkboxes[exclude_checkboxes.length] = special_checkboxes.ref;
        }
    }

    //Initialise Parent Class
    Form.prototype.initialise.call(
        this, 
        name_form, 
        {exclude: exclude_checkboxes, include: include_checkboxes}
    );
}

//Adjust Checked Status of Reference Checkbox
//Neglect Reference Checkbox when Counting checked Checkboxes
function FormSpecial_adjustReferenceCheckbox() {    
    //Only perform Adjustment if a Reference Checkbox is given
    if (this.Checkbox_Ref != null) {
    	  var checkboxes_enabled  = this.findCheckboxes({enabled:false});
        var checkboxes_checked  = this.findCheckboxes({ticked:true, enabled:true});
        var checkboxes_disabled = this.findCheckboxes({enabled:false});

			//Disable Reference Checkbox if no other Checkboxes are enabled
			if (this.FormCheckboxes.length == checkboxes_disabled.length ) {
				this.Checkbox_Ref.disabled = true;
				return;
			}

        //Adjust Reference Checkbox
        if (checkboxes_checked.length == this.FormCheckboxes.length - checkboxes_disabled.length) {
            this.Checkbox_Ref.checked = true;
        } else {
            this.Checkbox_Ref.checked = false;
        }
    } 
} 



//--- CONSTRUCTUR AND PROTOTYPING ------------------------------------------------------------

//Constructor
function FormSpecial(form_name, special_checkboxes) {
    if (form_name != null) {
        this.initialise(form_name, special_checkboxes);
    }
}

//Prototyping
FormSpecial.prototype            = new Form();
FormSpecial.prototype.initialise = FormSpecial_initialise;

FormSpecial.prototype.adjustReferenceCheckbox = FormSpecial_adjustReferenceCheckbox;



