var doErrorFlash = function() {
	
	var effects1 = [];
	
	$$('div.error').each(function(el, i) {
		effects1[i] = new Fx.Morph(el, {
			link:'chain',
			duration:500
		});
		effects1[i].start({'opacity': [0, 1]}).chain(function(){effects1[i].start({'opacity': [1, 0]});}).chain(function(){effects1[i].start({'opacity': [0, 1]});});
	});
	
}


var doStudentCheckOnLoad = function() {
	if ($('enquiry_usertype')) {
		doStudentCheckBound = doStudentCheck.bind($('enquiry_usertype'));
		doStudentCheckBound();
		$('enquiry_usertype').addEvent('change',doStudentCheck);
	}
	
	if ($('usertype')) {
		doStudentCheckBound = doStudentCheck.bind($('usertype'));
		doStudentCheckBound();
		$('usertype').addEvent('change',doStudentCheck);	
	}
}

var doStudentCheck = function() {
	
	if (this.value == 'Student') {
		
		
		
		if (!$('myStudentBox')) {
			myStudentBox = new Element('div', {
				'id': 'myStudentBox',
				'class': 'error',
				'html' : 'If you are a student, please make sure you enter your parent/carer\'s email address and not your own',
				'styles' : {
					'opacity' : 0,
					'marginTop' : 5,
					'marginBottom' : 5
				}
			}).inject(this, 'after');
			
			//The remaining parts here with positioning are to force IE 6 to move the absolutely positioned elements down the page to make room for the new div
			$('maincontainerbg').setStyle('bottom', 86);
			if ($('content_right')) {
				$('content_right').getFirst('span.bglower').setStyle('bottom', -1);			
			}
			if ($('passmasters_footer')) {
				$('passmasters_footer').setStyle('bottom',15);
				////
			}
			if ($('swirl_bl')) {
				$('swirl_bl').setStyle('bottom',11);
			}
			if ($('column_full_passmasters')) {
				$('column_full_passmasters').getFirst('span.bg_bottom').setStyle('bottom',69);
			}
			
		} else {
			$('myStudentBox').setStyle('opacity',0);
		}
		
		studentBoxFlash = new Fx.Morph($('myStudentBox'), {
			link:'chain',
			duration:500
		});
		studentBoxFlash.start({'opacity': [0, 1]}).chain(function(){studentBoxFlash.start({'opacity': [1, 0]});}).chain(function(){studentBoxFlash.start({'opacity': [0, 1]});});
	
	} else {
		if ($('myStudentBox')) {
			$('myStudentBox').destroy();
			//The remaining parts here with positioning are to force IE 6 to move the absolutely positioned elements up the page not the div has been deleted
			$('maincontainerbg').setStyle('bottom', 85);
			if ($('content_right')) {
				$('content_right').getFirst('span.bglower').setStyle('bottom', 0);			
			}
			if ($('passmasters_footer')) {
				$('passmasters_footer').setStyle('bottom',16);
			}
			if ($('swirl_bl')) {
				$('swirl_bl').setStyle('bottom',10);
			}
			if ($('column_full_passmasters')) {
				$('column_full_passmasters').getFirst('span.bg_bottom').setStyle('bottom',70);
			}			
		}
	}
}
	

window.addEvent('domready', doErrorFlash);
window.addEvent('domready', doStudentCheckOnLoad);