$(document).ready(function() {	
//Nicht uebersetzte Seiten kicken	
	$("#leftnav ul li ul li").each(function(index) {
		if($(this).text().trim().charAt(0) == "("){
				$(this).css('display','none');
			}
	});
	
	$("#navi_content ul ul li").each(function(index) {
		if($(this).text().trim().charAt(0) == "("){
				$(this).css('display','none');
			}
	});
	
	$("#footer_content ul li").each(function(index) {
		if($(this).text().trim().charAt(0) == "("){
				$(this).css('display','none');
			}
	});

//Minigallery by HL
	 $('.rahmen').click(function(){
		var neu = $(this).children('img').attr('src');
		$('span').removeClass('rahmen_active');
		$(this).addClass('rahmen_active');
	   	$("#refbig").attr('src',neu).stop(true,true).hide().fadeIn(500);
	 });
//Navi-FadeOut by HL
	$('#navi_content ul li:first-child').hover(
		function(){
			$(this).children('ul').stop(true,true).hide().fadeIn(0);
			$(this).children('ul').css('z-index','200');
		},
		function(){
			$(this).children('ul').stop(true,true).show().fadeOut(500);
			$(this).children('ul').css('z-index','100');
		}
	);
	
//Form validation by HL

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

	var counter = 0;
	var check = 0;
	var mandatory_input = $('#formbg span.pflicht input').length;
	var mandatory_select = $('#formbg span.pflicht select').length;
	var mandatory = mandatory_input+mandatory_select;
	
	$('#formbg input.mehr').attr('disabled','disabled');
	$('#formbg input.mehr').attr('style','opacity:0.3;filter:alpha(opacity = 30)');
	
	$('#formbg span.pflicht input,#formbg span.pflicht select').focusout(function(){
		var value = $(this).val(); 
		var bad = 'border:2px solid #FF0000';
		var good = 'border:2px solid #66f000';
		if (value == "" || value == " " || value == "-"){
			if($(this).attr('style') == good){
				check = check - 1;
			}
			$(this).attr('style','border:2px solid #FF0000');
			$('#formbg input.mehr').attr('disabled','disabled');
			$('#formbg input.mehr').attr('style','opacity:0.3;filter:alpha(opacity = 30)');
			
		} else {
			
			if($(this).parent('span').hasClass('validmail') || $(this).parent('span').parent('span').hasClass('validmail')){
				if(isValidEmailAddress(value)){
					if($(this).attr('style') != good){
						check = check + 1;
					}
					$(this).attr('style','border:2px solid #66f000');
					counter = 0;
				} else {
					if($(this).attr('style') == good){
						check = check - 1;
					}
					$(this).attr('style','border:2px solid #FF0000');
					counter = 1;
				}
			} else {
				if($(this).attr('style') != good){
					check = check + 1;
				}	
				$(this).attr('style','border:2px solid #66f000');
			}
			
			if(counter == 0 && check == mandatory){
				$('#formbg input.mehr').removeAttr('disabled','disabled');
				$('#formbg input.mehr').removeAttr('style','opacity:0.3;filter:alpha(opacity = 30)');
			} else {
				$('#formbg input.mehr').attr('disabled','disabled');
				$('#formbg input.mehr').attr('style','opacity:0.3;filter:alpha(opacity = 30)');	
			}
		} 
		
	});
	 
});
