/**
 * General triggered behaviour on document load
 */
var general_rules = {
		'#analytics_placeholder' : function() {
			var params = Element.getClassParameters(this);

			if (params.sid) {

				var pageTracker = _gat._getTracker(params.sid);
				if (params.target) {
					pageTracker._trackPageview(unescape(params.target));
				} else {
					pageTracker._trackPageview();
				}
			}

		},
		'.hilite_keywords' : function() {
       var hiliter = new KeywordHiliter("ajax.php",this);
       hiliter.options.elementTag = 'ABBR';
       hiliter.fetchKeywords();
    },
    '.no_javascript' : function() {
      this.hide();
    },
    '.show_no_javascript' : function() {
      this.show();
    }
}
Event.addBehavior(general_rules);

/**
 * Rules for hyperlink behaviour
 */
var hyperlink_rules = {
    'a.void:click' : function(e) {
      return false;
    },

    'a.popup:click' : function(e) {

        /**
         * Event:  click
         * Action: open a popup window
         */
        var params = Element.getClassParameters(this);
        var width = params.width || 684;
        var height = params.height || 350;
        var top = params.top || 200;
        var left = params.left || (screen.width - width) / 2;
        window.open(this.href,
            'PopUp',
            'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',scrollbars=0,status=no,resizable=0,toolbar=0,titlebar=0,menubar=0,location=0');
        return false;
    },

    'a.external:click' : function(e) {

        /**
         * Event:  click
         * Action: open a new window
         */
        if (!e.ctrlKey && !e.altKey && !e.shiftKey) {
          window.open(this.href);
          return false;
        }
    },

    'a.status:mouseover' : function(e) {

        /**
         * Event:  mouseover
         * Action: display the hyperlinks title in the status bar
         */
        window.status=this.title;
        return true;
    },
    'a.status:mouseout' : function(e) {

        /**
         * Event:  mouseout
         * Action: clear the status bar
         */
        window.status='';
        return true;
    },
	'a.selector:mouseover': function(e) {
        /**
         * Event:  click
         * Action: show / hide the tab with the same ID minus "_switch"
         */
        var c = $(this.id.replace('_selector',''));  
	
			var w = document.getElementById('selector_text1');
			var x = document.getElementById('selector_text2');
			var y = document.getElementById('selector_text3');

		  if ( w.style.visibility != c.style.visibility ) {
		    w.style.visibility = 'hidden';
    	  }

 		  if ( x.style.visibility != c.style.visibility ) {
		    x.style.visibility = 'hidden';
    	  }

		  if ( y.style.visibility != c.style.visibility ) {
		    y.style.visibility = 'hidden';
    	  }	
		  
		 if ( c.style.visibility == 'hidden' ) { 	  
		    c.style.visibility = 'visible';
          }	
        return false;
    },

 'a.switcher:click': function(e) {
        /**
         * Event:  click
         * Action: show / hide the tab with the same ID minus "_switch"
         */
        var c = $(this.id.replace('_switch',''));
        var w = document.getElementById('item1');
		if (document.getElementById('item2')){
		  var x = document.getElementById('item2');
		}
	    if (document.getElementById('item3')){
		  var y = document.getElementById('item3');
		}		  
		if ( w.style.display != c.style.display ) {
		  w.style.display = 'none';
    	}

 		if ( x.style.display != c.style.display ) {
		  x.style.display = 'none';
    	}
		if ( y.style.display != c.style.display ) {
		  y.style.display = 'none';
    	}

		if (c) { /* if c is true then toggle */
          c.toggle();		 
        }
        return false;
    },
    'a.tabswitch:click' : function(e) {
        /**
        * Event: click
        * Action: hide related div, show related div's related element
        */
        var container = $(this.getAttribute('rel'));
        if(container) {
          var other = $(container.getAttribute('rel'));
          if (other) {
            container.addClassName('hide');
            other.removeClassName('hide');
          }
        }
        return false;
    },

    'a.submit' : function(e) {
        /**
        * Event: click
        * Action: submit the form given as a param. (used by captcha)
        */
        var params = Element.getClassParameters(this);
        var form = $(params.form);
        if (form){
          form.submit();
        }
        return false;
    }
}
Event.addBehavior(hyperlink_rules);

var intro_rules = {
    'ul.nav a:click' : function(el) {
		/**
       * Event:  mouseclick
       * Action: show div with intro
       */
		// remove active state from nav
		if ($$('ul.nav li.active')[0]) {
			var oldactivenav = $$('ul.nav li.active')[0];
			oldactivenav.removeClassName('active');
		}
		// set active state to nav
		if (oldactivenav != this.up()) {
			this.up().addClassName('active');
		}
		
		// remove active state from nav
		if ($$('ul.content-intro li.active')[0]) {
			var oldactive = $$('ul.content-intro li.active')[0];
			oldactive.removeClassName('active');
		}
		
		// set active state to intro-div
		var params = Element.getClassParameters(this);
		if (params.intro) {
			if (oldactive != $(params.intro)) {
				$(params.intro).addClassName('active');
			}
		}
		return false;
  },
  'a.close-intro:click' : function(el) {
		  /**
       * Event:  mouseclick
       * Action: close current open div
       */
		// remove active state from nav
		if ($$('ul.nav li.active')[0]) {
			var oldactivenav = $$('ul.nav li.active')[0];
			oldactivenav.removeClassName('active');
		}
		// remove active state from intro-div
		if ($$('ul.content-intro li.active')[0]) {
			var oldactive = $$('ul.content-intro li.active')[0];
			oldactive.removeClassName('active');
		}		
		return false;		
	}
}
Event.addBehavior(intro_rules);

/**
 * Behaviour rules for form elements
 */

var form_rules = {
    'form.auto_submit' : function(e) {
      this.submit();
    },
    'select.auto_submit:change' : function(e) {
      this.form.submit();
    },
    /**
     * Event:  blur
     * Action: convert field value to upper case
     */
    'input.auto_upper:blur' : function(e) {
      this.value = this.value.toUpperCase();
    },

    /**
     * Event:  change
     * Action: convert field value to upper case
     */
    'input.auto_upper:change' : function(e) {
      this.value = this.value.toUpperCase();
    },

    'input.auto_blur:focus' : function(e) {

      /**
       * Event:  focus
       * Action:
       *   - replace field's classname from "_off" to "_on"
       *   - if labeled, replace label's classname from "_off" to "_on"
       *   - if label is image, replace image with "_hover" version
       */
        this.className = this.className.replace('_off','_on');
        var fieldLabel = $(this.id + '_label');
        if (fieldLabel) {
            fieldLabel.className = fieldLabel.className.replace('_off','_on');
            var image = fieldLabel.getElementsByTagName('img')[0];
            if (image) {
                image.src = image.src.replace('_normal','_hover');
            }
        }
    },
    'input.auto_blur:blur' : function(e) {

        /**
         * Event:  blur
         * Action:
         *   - replace field's classname from "_on" to "_off"
         *   - if labeled, replace label's classname from "_on" to "_off"
         *   - if label is image, replace image with "_normal" version
         */
        this.className = this.className.replace('_on','_off');
        var fieldLabel = $(this.id + '_label');
        if (fieldLabel) {
              fieldLabel.className = fieldLabel.className.replace('_on','_off');
            var image = fieldLabel.getElementsByTagName('img')[0];
            if (image) {
                image.src = image.src.replace('_hover','_normal');
            }
        }
    },
    'input.auto_clear:focus' : function(e) {

        /**
         * Event:  focus
         * Action:
         *   - clear value
         *   - remove auto_clear class
         */
        if (Element.hasClassName(this,'auto_clear')) {
            this.value='';
        }
        Element.removeClassName(this,'auto_clear');
    },
    'input.auto_blur_multiple:focus' : function(el) {

      /**
       * This is the multiple variant of auto_blur. It will highlight the
       * label of replace the image. The id of the label must be the same
       * as the id of the field, minus the last underscore and digits.
       * Now you can do those fancy multiple fields with one label :)
       */
        this.className = this.className.replace('_off','_on');
        var fieldLabel = $(this.id.sub(/_\d+$/, '') + '_label');
        if (fieldLabel) {
            fieldLabel.className = fieldLabel.className.replace('_off','_on');
            var image = fieldLabel.getElementsByTagName('img')[0];
            if (image) {
                image.src = image.src.replace('_normal','_hover');
            }
        }
    },
    'input.auto_blur_multiple:blur' : function(el) {
        this.className = this.className.replace('_on','_off');
        var fieldLabel = $(this.id.sub(/_\d+$/, '') + '_label');
        if (fieldLabel) {
            fieldLabel.className = fieldLabel.className.replace('_on','_off');
            var image = fieldLabel.getElementsByTagName('img')[0];
            if (image) {
                image.src = image.src.replace('_hover','_normal');
            }
        }
    },
    'input.rollover:mouseover' : function(el) {

        /**
         * Event:  mouseover
         * Action:
         *   - if not "active", replace classname by "_hover" classname
         *   - if type is "image", replace image by "_hover" version
         */
        if (!Element.hasClassName(this,'active')) {
            this.className = this.className.replace('_normal','_hover');
            if (this.type == 'image') {
                this.src = this.src.replace('_normal','_hover');
            }
        }
    },
    'input.rollover:mouseout' : function(e) {
        /**
         * Event:  mouseout
         * Action:
         *   - replace classname by "_hover" classname
         *   - if type is "image", replace image by "_hover" version
         */
        if (!Element.hasClassName(this,'active')) {
            this.className = this.className.replace('_hover','_normal');
            if (this.type == 'image') {
                this.src = this.src.replace('_hover','_normal');
            }
        }
    },
    'input#search_site:click' : function(e) {
        /**
         * Event:  click
         * Action: change form action 
         */
        var params = Element.getClassParameters(this); 
        if(!$('search_site').checked){
            // not checked > results in banner
            $('form_search').action = '/index.php?pageID=' + params.pageID;
        } else{
            // checked > resultpage 
            $('form_search').action = '/index.php?pageID=' + params.resultpageID;
        }
    },
    'select#search_competence:change' : function(e) {
        /**
         * Event:  change
         * Action: fill results div with ajax 
         */
        if(!$('search_site').checked){
            var container = $('search_results_banner');
            var updater = new Ajax.Updater(
              container,
              'ajax.php',
              {
                parameters: {
                  action: 'search_by_competence',
                  search_competence: $('search_competence').getValue(),
                  searchstring: $('searchstring').getValue()
                }
              }
            );//*/
            container.show(); 
            return false;
        }
    },
    'input#searchstring:keyup' : function(e) {
        /**
         * Event:  on key up
         * Action: fill results div with ajax 
         */
        if(!$('search_site').checked){
            var container = $('search_results_banner');
            var updater = new Ajax.Updater(
              container,
              'ajax.php',
              {
                parameters: {
                  action: 'search_by_competence',
                  search_competence: $('search_competence').getValue(),
                  searchstring: $('searchstring').getValue()
                }
              }
            );//*/
            container.show(); 
            return false;
        }
    },
    'input#program_searchstring:keyup' : function(e) {
        /**
         * Event:  on key up
         * Action: fill results div with ajax 
         */
        var container = $('program_results');
        var updater = new Ajax.Updater(
            container,
            'ajax.php',
            {
                parameters: {
                  action: 'search_program',
                  searchstring: $('program_searchstring').getValue()
                }
              }
         );
         return false;
    },
    'select#program_selector:change' : function(e) {
        /**
         * Event:  on change
         * Action: open window for the program 
         */
        window.location = this.getValue();
        return false;
    }
}
Event.addBehavior(form_rules);

var rollover_rules = {
    'img.rollover:mouseover' : function(el) {
      /**
       * Event:  mouseover
       * Action: show hover version
       */
    this.src = this.src.replace('_normal','_hover');
    return false;

  },
    'img.rollover:mouseout' : function(el) {
      /**
       * Event:  mouseout
       * Action: show normal version
       */
    this.src = this.src.replace('_hover','_normal');
    return false;
  }
}
Event.addBehavior(rollover_rules);

var spotlight_main_rules = {
    'table#spotlight-main-nav a:mouseover' : function(el) {
      /**
       * Event:  mouseover
       * Action: show hover version
       */
		var params = Element.getClassParameters(this);

		// remove active state from nav
		if ($$('div.spotlight-main div.active')[0]) {
			var oldactive = $$('div.spotlight-main div.active')[0];
			oldactive.removeClassName('active');
		}

		if(params.linkID == 1) {
			$('mainspotlight_content1').addClassName('active');
			$('spotlight-main-overlay1').style.backgroundPosition = '0 0';
		}
		if(params.linkID == 2) {
			$('mainspotlight_content2').addClassName('active');
			$('spotlight-main-overlay2').style.backgroundPosition = '-141px 0';
		}
		if(params.linkID == 3) {
			$('mainspotlight_content3').addClassName('active');
			$('spotlight-main-overlay3').style.backgroundPosition = '-282px 0';
		}
		if(params.linkID == 4) {
			$('mainspotlight_content4').addClassName('active');
			$('spotlight-main-overlay4').style.backgroundPosition = '-423px 0';
		}
    return false;
  }
}
Event.addBehavior(spotlight_main_rules);

var flash_rules = {
    '#videoplayer' : function(el) {
        var FO = {
          movie:"/flash/videoplayer.swf",
          width: "480",
          height: "390",
          menu:"false",
          xi:"false",
          majorversion:"9",
          build:"28",
          allowfullscreen: "true"
        }
        UFO.create(FO,this.id);
    },
	  '#spijkerspel' : function(el) {
        var FO = {
          movie:"/flash/spijkerspel.swf",
          width: "640",
          height: "480",
          menu:"false",
          xi:"false",
          majorversion:"9",
          build:"28",
          allowfullscreen: "true"
        }
        UFO.create(FO,"spijkerspel");
    },
	'#gevangenis' : function(el) {
        var FO = {
          movie:"/flash/gevangenisspel.swf",
          width: "480",
          height: "360",
          menu:"false",
          xi:"false",
          majorversion:"9",
          build:"28",
          allowfullscreen: "true"
        }
        UFO.create(FO,"gevangenis");
    },
	'#kees_boef' : function(el) {
        var FO = {
          movie:"/flash/player.swf",
          width: "470",
          height: "320",
          menu:"false",
          xi:"false",
          majorversion:"9",
          build:"28",
          allowfullscreen: "true",
		  flashvars: "&file=/images/filmpjes/Kees_Boef.flv"
        }
        UFO.create(FO,"kees_boef");
    },
	'#learningonline' : function(el) {
		var FO = {
			movie: '/flash/banner_elearning.swf',
			width: '170',
			height: '180',
			menu: 'false',
			xi: 'false',
			majorversion: '9',
			build: '28',
			allowfullscreen: 'false',
			flashvars: "&flashvars=http://www.learningonline.nu/roi/index.asp"
		}
		UFO.create(FO, "learningonline");
	},
	/*
	 * Partner banner Flash versions
	 * zie voor implementatie details: K:\ROI Opleidingen\ROIO0005 (aanpassing banners)\07_development\banner implementatie.txt
	 */
	'#partner_banner' : function(el) {
		var params = Element.getClassParameters(this)
		var FO = {
			movie: params.flashfile,
			width: '234',
			height: '60',
			menu: 'false',
			xi: 'false',
			majorversion: '9',
			build: '28',
			allowfullscreen: 'false'
		}
		UFO.create(FO, 'partner_banner');
	}
}
Event.addBehavior(flash_rules);
function is_digit (data) {
  var result = true;
  for (var i=0;i<data.length;i++) {
    var digit = data.charAt(i);
  if (digit <"0" || digit > "9") {
    result = false;
  }
  }
  return result
}