/*
	name			: ClassBehaviours, the javascript framework based on class-name parsing
	update			: 9.11.9
	author			: Maurice van Creij
	dependencies	: jquery.classbehaviours.js
	info			: http://www.classbehaviours.com/

    This file is part of jQuery.classBehaviours.

    ClassBehaviours is a javascript framework based on class-name parsing.
    Copyright (C) 2008  Maurice van Creij

    ClassBehaviours is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClassBehaviours is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClassBehaviours. If not, see http://www.gnu.org/licenses/gpl.html.
*/

	// create the jQuery object if it doesn't already exist
	if(typeof(jQuery)=='undefined') jQuery = function(){};

	// create the root classbehaviours object if it doesn't already exist
	if(typeof(jQuery.classBehaviours)=='undefined') jQuery.classBehaviours = function(){};

	// create the handlers child object if it doesn't already exist
	if(typeof(jQuery.classBehaviours.handlers)=='undefined') jQuery.classBehaviours.handlers = function(){}

	// Change a Form's Layout Based on its Values
	jQuery.classBehaviours.handlers.displayOnValue = {
	    // properties
	    name: 'displayOnValue',
	    index: 0,
	    // methods
	    start: function (node) {
	        // find the refered input field
	        referedIds = jQuery.classBehaviours.utilities.getClassParameter(node, 'id', '').split(',');
	        for (var a = 0; a < referedIds.length; a++) {
	            if (referedIds[a] != '') {
	                referedField = document.getElementById(referedIds[a]);
	                if (referedField == null) return;
	                // add all the elements belonging to this input field to an array
	                referedObjs = (referedField.type == 'radio') ? document.getElementsByName(referedField.name) : new Array(referedField);
	                // set event handlers for every element in the array
	                for (var b = 0; b < referedObjs.length; b++) {
	                    if (referedObjs[b].type == 'radio') {
	                        referedObjs[b].onclick = this.changed;
	                        referedObjs[b].onchange = this.changed;
	                    } else {
	                        referedObjs[b].onfocus = this.changed;
	                        referedObjs[b].onchange = this.changed;
	                    }
	                }
	                // delay and check the initial value
	                this.update(node);
	                node.id = (node.id) ? node.id : this.name + this.index++;
	                setTimeout('jQuery.classBehaviours.handlers.displayOnValue.update(document.getElementById("' + node.id + '"))', 256);
	            }
	        }
	    },
	    update: function (objNode) {
	        // compare element
	        compareIds = jQuery.classBehaviours.utilities.getClassParameter(objNode, 'id', 'undefined').split(',');
	        // get the required value
	        compareValues = jQuery.classBehaviours.utilities.getClassParameter(objNode, 'value', 'undefined').split(',');
	        // for all id value pairs
	        compareDisplay = true;
	        for (var a = 0; a < compareIds.length; a++) {
	            if (compareIds[a] != '') {
	                // get the refered input
	                compareObj = document.getElementById(compareIds[a]);
	                // get the input value
	                if (compareObj != null) {
	                    compareValue = compareObj.value;
	                    // get the checked status (if applicable)
	                    // TODO: virtualize a group of radios the return its value
	                    compareChecked = (typeof (compareObj.checked) != 'undefined') ? compareObj.checked : compareValue == compareValues[a];
	                    // decide on the visibility of this form part
	                    compareDisplay = (compareChecked && compareDisplay);
	                }
	                else {
	                    compareDisplay = false;
	                }
	            }
	        }
	        // show or hide the form part
	        objNode.style.display = (compareDisplay) ? jQuery.classBehaviours.utilities.getVisibleState(objNode) : 'none';
	        // apply new odd and even pattern
	        //tableNode = jQuery.classBehaviours.utilities.rootNode(objNode, 'TABLE');
	        //jQuery.classBehaviours.handlers.zebraTable.process(tableNode);
	    },
	    // events
	    changed: function (that) {
	        var objNode = (typeof (this.nodeName) == 'undefined') ? that : this;
	        var dov = jQuery.classBehaviours.handlers.displayOnValue;
	        // find the root of the form
	        rootNode = jQuery.classBehaviours.utilities.rootNode(objNode, 'FIELDSET');
	        // get all the elements of this class
	        allNodes = jQuery.classBehaviours.utilities.getElementsByClassName(dov.name, rootNode);
	        // ask them to update themselves
	        for (var a = 0; a < allNodes.length; a++) dov.update(allNodes[a]);
	    }
	}

	 

	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.displayOnValue = function(){
			return this.each(
				function(){
				    jQuery.classBehaviours.handlers.displayOnValue.start(this);
				  
				}
			);
		};
    
		// extend jQuery with this method
		jQuery.fn.displayIfChecked = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.displayIfChecked.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function () {

			    $(".displayOnValue").displayOnValue();

			    $(".displayIfChecked").displayIfChecked();
			    if ($('#C42_Aanmeldformulier1_uxTypeContracts').val() == "NLE_V_STD_VAR")
			        $('.switchBox').hide();
			    else
			        $('.switchBox').show();
			    $('#C42_Aanmeldformulier1_uxTypeContracts').change(function () {
			      
			        if ($('#C42_Aanmeldformulier1_uxTypeContracts').val() == "NLE_V_STD_VAR")
			            $('.switchBox').hide();
			        else
			            $('.switchBox').show();
			    });
			}
		);
	}

