/*
* mootools v.1.11 classes
* Core(Core)
* Class(Class, Class.Extras)
* Native(Array, String, Function, Number, Element)
* Element(Element.Event, Element.Filters, Element.Selectors, Element.Form)
* Window(Window.DomReady, Window.Size)
* Effects(Fx.Base, Fx.CSS, Fx.Style, Fx.Styles)
*/

window.addEvent('domready',function() {
  $$('.imagelink').addEvents({
    'mouseover': function() {this.addClass('imagelinkhover');},
    'mouseout': function() {this.removeClass('imagelinkhover');}
  });
  
  // Make png's transparent
  $$('img[src$=.png]').each(function(png) {
    png.setStyle('behavior','url(/_include/pngFix.htc)');
  });
  // External links open in new window
  $$('a[rel=external]').each(function(extLink) {
    extLink.setProperty('target','_blank');
  });
  
  if($$('form')[0]) {
    var myForm = new Form();
  }
  
  // Route popup
  if($('routeform')) {
    $('routeform').addEvent('submit',function(e) {
      var e = new Event(e);
      e.stop();

      // Haal het vertrekpunt uit het formulier en vervang de spaties door + tekens
      var vertrekpunt = $('postcode').getValue()
    
      // Adres
      var straat = 'hofcampweg+71g';
      var postcode = '2241+ke'
      var plaats = 'wassenaar'
      var adres = straat+','+postcode+'+'+plaats

	  var urlGoogle;

	  if ($('domain').getValue() == 'nl') {
		urlGoogle = "google.nl";
	  } else {
		urlGoogle = "google.com";
	  }
    
      // Open een nieuw venster met de routebeschrijving
      window.open("http://maps." + urlGoogle + "/maps?f=d&hl=nl&saddr="+ vertrekpunt +"&daddr="+ adres +"&ie=UTF8&om=1","_blank","directories=0, location=0, menubar=0, status=0, toolbar=0, resizable=1, height=750, width=1000")
    });
  }
  
  if($('linkSENS')) {
    $('linkSENS').addEvent('click',function() {
      window.open('/tmpsens.asp','','width=300,height=150');
    });
  }
  
  if(location.href.test('sens') == true && $$('table tfoot')) sensTable();
});

var Form = new Class({
  initialize: function() {
    this.form = $$('form')[0];
    
    this.activateActions();
    
    this.form.addEvent('submit',this.frmCheck);
  },
  
  activateActions: function() {
    $$('input[type=radio]').each(function(radio) {
      radio.addEvent('click',function() {
        if(this.getProperty('id') == 'referentie') {
          $('branche').setProperty('disabled',false);
        } else {

			if (this.getProperty('id') == 'itsm') {

			}

		  $('branche').setProperty('disabled',true);
        }
        if(this.getProperty('id') == 'anders') {
          $('bericht').setProperty('disabled',false);
        } else {
          $('bericht').setProperty('disabled',true);
        }
      });
    });
  },
  
  frmCheck: function(ev) {
    var misFld;
    var e = new Event(ev);
    e.stop();
    
    $$('.reqFld').each(function(fld) {
      fld.removeClass('missingField');
      if(fld.getValue() == '') {
        fld.addClass('missingField');
        misFld = true;
      }
    });
    if(misFld == true && document.getElementById("rareid").value == 'nl') {
      alert('De gekleurde velden zijn verplicht.');
	} else if (misFld == true) {
		return false;
    } else {
	  this.submit();
    }
  }
});

function sensTable() {
  // Als de broswer anders is dan IE
  if(!(navigator.userAgent.toLowerCase().indexOf('msie') > 0 && navigator.platform == 'Win32' ? true : false)) {
    var tds = [$('po'),$('fac'),$('ict'),$('fin'),$('km'),$('sp'),$('bb'),$('bc'),$('np')];
    var ob = new Element('object',{
      'type':'image/svg+xml',
      'width':25
    });
    var obClone;
    
    tds.each(function(td) {
      td.empty();
      obClone = ob.clone();
      obClone.setProperty('data','/_components/'+ td.id +'.xml').injectInside(td);
    });
  }
  // Einde browser check
  
  // Animeer mouseovers
  $$('tbody td').addEvents({
    'mouseover': function() {
      if(this.getText() == 'V') {
        this.addClass('highlight');
        this.getParent().getFirst().addClass('highlight');
        $$('tfoot td')[this.getParent().getChildren().indexOf(this)].addClass('highlight');
      }
    },
    'mouseout': function() {
        this.removeClass('highlight');
        this.getParent().getFirst().removeClass('highlight');
        $$('tfoot td')[this.getParent().getChildren().indexOf(this)].removeClass('highlight');      
    }
  });

}