// JavaScript Document
ilExpandable = Class.create({
							
	initialize: function(){
		this.speed = 0.5;
		this.current = null;
		this.expandables = [];
		var eL = $$('.il-expandable');
		if(eL.first()){
			this.buildCells(eL.first());
		}
		var eF = $('webinarSignupBox');
		if(eF){
			this.buildForm(eF);
		}
	},
	buildCells: function(a){
		Event.observe(a, 'click', (function(event){
			var e = event.findElement('.il-expandable-cell') || event.findElement('.il-small-expandable-cell');
			var s = event.findElement('.il-expand-button') || event.findElement('.il-expandable-button');
			if(e && s) event.stop();
			if(this.current != e){
				this.show(e);
			}
		}).bind(this));
	},
	buildForm: function(f){
		this.noDate = $('ilNoDate');
		this.msDate = $('ilMSDate');
		this.masDate = $('ilMASDate');
		this.contactDate = $('ilContactDate');
		Event.observe(f, 'click', (function(event){
			var e = event.findElement('#ilSystem input[type=checkbox]');
			if(e){
				this.showDate(e);
			}
		}).bind(this));
	},
	show: function(e){	
		this.current = e;
		var o = e.up().select('.il-expanded').first();
		if(o){
			Effect.BlindUp(o, {duration: this.speed})
			o.removeClassName('il-expanded');
		}	
		var s = e.select('.il-collapsed').first()
		Effect.BlindDown(s, {duration: this.speed});
		s.addClassName('il-expanded');
	},
	showDate: function(g){
		var a = $('ilSystem').select('input[type=checkbox]');
		var ms = false;
		var mas = false;
		if(a){
			a.each(function(item) {				
				if(item.value.include('Microsoft') && item.checked){
					ms = true
				} else if(item.value.include('MAS') && item.checked){
					mas = true
				}
			});



			if(mas){
				this.masDate.show();	
			} else {
				this.masDate.hide();
			}
			if(ms){
				this.msDate.show();
			} else {
				this.msDate.hide();
			}
			if(mas || ms){
				this.noDate.hide();
				this.contactDate.show();
			} else {
				this.noDate.show();
				this.contactDate.hide();
			}
		}
	}
});

document.observe('dom:loaded', function () { new ilExpandable(); });
