function jsMail(address) {
	address = address.split('?').join('@');
	address = address.split('!').join('.');
	address = address.split('*').join('e');
	address = address.split('=').join('c');
	document.write('<a href="mailto:'+address+'">'+address+'</a>');
}

window.addEvent('domready', function() {
	$('stomach').setStyle('visibility', 'visible');
	var search = $('heart').value;
	var last_req = $('heart').value;
	var req = new Request.HTML({url:'/search.php',  method:'post', autoCancel:true,
		onSuccess: function(html) {
			$('stomach').set('text', '');
			$('stomach').adopt(html);
			stomachSlider.slideIn();
			
			$$('tr.jobtr').addEvents({
				'mouseenter': function(){
					this.set('morph', {duration: '250'}).morph({color: '#909'});
				},
				'mouseleave': function(){
					this.set('morph', {duration: '750'}).morph({color: '#333'});
				}
			});
		},
		onFailure: function() {
			$('stomach').set('text', 'Die Suche ist fehlgeschlagen.<br />Bitte versuchen Sie es erneut.');
		}
	});

	$('heart').addEvent('keyup', function() {
		if (last_req != $('heart').value) {
			req.cancel();
			req.send('q='+$('heart').value);
			last_req = $('heart').value;
		}
	});
	$('heart').addEvent('focus', function() {
		if ($('heart').value == 'neue Jobs') {
			$('heart').value = '';
		}
	});
	$('heart').addEvent('blur', function() {
		if ($('heart').value == '') {
			$('heart').value = search;
		}
	});

	if ($('editform')) {
		$('editform').addEvent('submit', function(e) {
			new Event(e).stop();
			var req = new Request({
				url: '/edit_check.php?j='+$('job_id').value+'&p='+$('passwort').value,
				onSuccess: function(txt){
					if (txt == '1') {
						stomachSlider.slideOut();
						$('editform').submit.delay(500, $('editform'));
					} else {
						alert('Leider sind die eingegeben Daten nicht korrekt.\nBitte versuchen Sie es erneut oder wenden Sie\nsich an: info@netjobs.de');
					}
				},
				onFailure: function(){
					window.location.href = '/editieren/';
				}
			});
			req.send();
		});
	}

	if ($('postform')) {
		$('postform').addEvent('submit', function(e) {
			new Event(e).stop();
			if ($('email').value == '') {
				$('email').setStyle('border-color', '#909');
				$('email').setStyle('background-color', '#fdf');
				$('email').addEvent('focus', function() {
					$('email').setStyle('border-color', '#ccc');	
					$('email').setStyle('background-color', '#fff');
				});
				new Fx.Scroll(window).toElement('stomach');
				alert('Bitte geben Sie eine Emailadresse an.');
				$('email').focus();
			} else if ($('password').value != $('password2').value) {
				$('password').setStyle('border-color', '#909');
				$('password').setStyle('background-color', '#fdf');
				$('password2').setStyle('border-color', '#909');
				$('password2').setStyle('background-color', '#fdf');
				$('password').addEvent('focus', function() {
						$('password').setStyle('border-color', '#ccc');
						$('password').setStyle('background-color', '#fff');
						$('password2').setStyle('border-color', '#ccc');
						$('password2').setStyle('background-color', '#fff');
				});
				new Fx.Scroll(window).toElement('stomach');
				alert(unescape('Die Passw%F6rter stimmen nicht %FCberein.'));
				$('password').focus();
			} else if ($('position').value == '') {
				$('position').setStyle('border-color', '#909');
				$('position').setStyle('background-color', '#fdf');
				$('position').addEvent('focus', function() {
						$('position').setStyle('border-color', '#ccc');
						$('position').setStyle('background-color', '#fff');
				});
				new Fx.Scroll(window).toElement('stomach');
				alert('Bitte geben Sie die zu besetzende Position an.');
				$('position').focus();
			} else if ($('content').value.length < 5) {
				$('content').setStyle('border-color', '#909');
				$('content').setStyle('background-color', '#fdf');
				$('content').addEvent('focus', function() {
						$('content').setStyle('border-color', '#ccc');
						$('content').setStyle('background-color', '#fff');
				});
				new Fx.Scroll(window).toElement('stomach');
				alert('Bitte beschreiben Sie den Job.');
				$('content').focus();
			} else if ($('apply').value == '') {
				$('apply').setStyle('border-color', '#909');
				$('apply').setStyle('background-color', '#fdf');
				$('apply').addEvent('focus', function() {
						$('apply').setStyle('border-color', '#ccc');
						$('apply').setStyle('background-color', '#fff');
				});
				alert('Bitte geben Sie an, auf welchem Weg sich Bewerber bei Ihnen melden sollen.');
				$('apply').focus();
			} else {
				stomachSlider.slideOut();
				$('postform').submit.delay(500, $('postform'));
			}
		});

		if ($('email')) {
			$('email').addEvent('blur', function() {
				if ($('apply').value == '') {
					$('apply').value = 'Senden Sie Ihre Bewerbung an '+$('email').value;
				}
			});
		}

		if ($('password') && $('password2')) {
			$('password').addEvent('blur', function() {
				if ($('password').value != '' && $('password').value != $('password2').value) {
					$('pass_ggf').setStyle('display', 'none');
					$('pass_again').setStyle('font-weight', 'bold');
					$('pass_again').setStyle('color', '#333');
				} else {
					$('pass_ggf').setStyle('display', 'inline');
					$('pass_again').setStyle('font-weight', 'normal');
					$('pass_again').setStyle('color', '#777');				
				}
			});		
		}
	}

	
	var stomachSlider = new Fx.Slide('stomach', {transition: Fx.Transitions.Cubic.easeOut});
	//var footSlider = new Fx.Slide('foot');
	/*
	if (noslide == false) {
		stomachSlider.hide().slideIn.delay(500, stomachSlider);
		//footSlider.hide().slideIn.delay(1000, footSlider);
	}
	*/

	$$('tr.jobtr').addEvents({
		'mouseenter': function(){
			this.set('morph', {duration: '250'}).morph({color: '#909'});
		},
		'mouseleave': function(){
			this.set('morph', {duration: '750'}).morph({color: '#333'});
		}
	});
});
