jQuery.noConflict();
var loader = '<img src=\"fileadmin/images/ajax-loader-big.gif\" class=\"load\" alt=\"Lade Bilder...\" />';
function change_bgimage(elem,boxtype){
    if (jQuery('#'+elem).hasClass(boxtype+'box_header_aktiv') == true){
        jQuery('#'+elem).removeClass(boxtype+'box_header_aktiv');      
        jQuery('#'+elem).addClass(boxtype+'box_header');
    } else {
        jQuery('#'+elem).removeClass(boxtype+'box_header');
        jQuery('#'+elem).addClass(boxtype+'box_header_aktiv');
    }
}

jQuery(function($){
	$.tools.validator.fn("[minlength]", function(input, value) {
		var min = input.attr("minlength");
		return value.length >= min ? true : {     
			en: "Please provide at least " +min+ " character" + (min > 1 ? "s" : ""),
			de: "Bitte tragen Sie mindestens " +min+ " Zeichen ein" 
		};
	});
	$.tools.validator.fn("[maxlength]", function(input, value) {
		var max = input.attr("maxlength");
		return value.length <= max ? true : {     
			en: "Please provide at maximum " +max+ " character" + (max > 1 ? "s" : ""),
			de: "Bitte tragen Sie maximal " +max+ " Zeichen ein" 
		};
	});
	$.tools.validator.localize("de", {
		"*": 'Bitte korrigieren Sie diesen Wert.',
		"[required]": 'Bitte füllen Sie dieses Pflichtfeld aus.',
		":email": 'Bitte geben Sie eine gültige E-Mail-Adresse ein.',
		":number": 'Bitte tragen Sie eine Nummer ein.',
		":digits": 'Bitte tragen Sie eine Nummer ohne Komma oder Punkt ein.'
	});
	$.tools.validator.localize("en", {
		"*": 'This is a required field.',
		"[required]": 'Please complete this mandatory field.',
		":email": 'Please provide a valid e-mail address.',
		":number": 'Please enter a valid number in this field.',
		":digits": 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.'
	});
	$.tools.validator.localize("fr", {
		"*": 'Veuillez corriger cette valeur.',
		"[required]": 'Ce champ est obligatoire.',
		":email": 'Merci d’indiquer une adresse e-mail valide.',
		":number": 'Veuillez entrer un chiffre valable dans ce champ.',
		":digits": 'Veuillez utiliser uniquement des chiffres dans ce champ. Evitez les espaces et d\'autres caractères comme les points ou les virgules.'
	});
	$.tools.validator.localize("ru", {
		"*": 'Исправьте это значение.',
		"[required]": 'Это необходимое поле.',
		":email": 'Пожалуйста, укажите действующий адрес E-Mail!',
		":number": 'Пожалуйста, введите правильное число в это поле.',
		":digits": 'Пожалуйста, используйте в этом поле лишь числа, избегите пробелов или других символов, таких как точки или запятые.'
	});
	$("#feedbackform").validator({
		lang: 'de',
		position: 'top left', 
		message: '<div><em/></div>',
		messageClass: 'validationerror'
	});
	
    $('.menubox').hide();
    $('.menuentry').hover(function(e){
      $('.menubox').stop(true);
      $('.menubox').hide();
      $('.menuentry a').height('17px');
      idelem = $(this).attr('id');          
      $('#'+idelem+' a').height('19px');
      idelemdiv = idelem.replace('menuentry_', 'menubox_');
      if($('#'+idelemdiv).is(":visible")) {
      } else {
          //$('#'+idelemdiv).slideDown('normal');
          $('#'+idelemdiv).show();
      }
    },function(e){
      $('.menubox').animate({opacity:1},500);
      $('.menubox').queue(function() {
        idelem = $(this).attr('id');
        idelemdiv = idelem.replace('menubox_', 'menuentry_');
        $('#'+idelemdiv+' a').height('17px');
        $(this).hide();
        $(this).dequeue();
      });
    });
    $('.menubox').hover(function(e){
      $(this).stop(true);
    },function(e){          
      $(this).animate({opacity:1},500);
      $(this).queue(function() {
        $('.menuentry a').height('17px');
        $('.menubox').hide();
        $(this).dequeue();
      });          
    });
    $('.filterbox_header').click(function(e){
        idelem = $(this).attr('id');
        idelemdiv = idelem.replace('boxhead_', 'boxcontent_');
        $('#'+idelemdiv).slideToggle('normal', function(e) {
          change_bgimage(idelem,'filter');
        });
    });
    $('.leftcolbox_header').click(function(e){
        idelem = $(this).attr('id');
        idelemdiv = idelem.replace('boxhead_', 'boxcontent_');
        $('#'+idelemdiv).slideToggle('normal', function(e) {
          change_bgimage(idelem,'leftcol');
        });
    });
    $('.contentbox_header').click(function(e){
        idelem = $(this).attr('id');
        idelemdiv = idelem.replace('boxhead_', 'boxcontent_');
      $('#'+idelemdiv).slideToggle('normal', function(e) {
        change_bgimage(idelem,'content');
      });
    });  
    
    $('#langmenu li a').each(function() {
    	$(this).attr('href',$(this).attr('href')+'?mls=1');
    });
    
    $('#langmenu').click(function(e) {
		if($(this).height() > 17) {
			hideCountryselect();
		} else {
			showCountryselect();
		}
	});
	
	$('#langmenu').hover(function(e){
		$('#langmenu').stop(true);
    },function(e){
      $('#langmenu').animate({opacity:1},500);
      $('#langmenu').queue(function() {
        hideCountryselect();
      });
    });	
	
	function hideCountryselect() {
		if($('#langmenu').height() > 17) {
			$('#langmenu').height('17px');
		}
	}
	
	function showCountryselect() {
		var lis = $('#langmenu li').length;
		var lisact = $('#langmenu li.active').length;
		var lisinact = $('#langmenu li.inact').length;
		var total = lis - lisact - lisinact;
		var ulheight = (total * 17);
		if($('#langmenu').height() < ulheight) {
			$('#langmenu').height(ulheight+'px');
		}
	}   
		
	$('#ersatzteileanfrage .sku input').attr('minlength',$('#ersatzteileanfrage #uid233').attr('maxlength'));
	$('#ersatzteileanfrage .sku input').attr('sku','sku');
	$('#ersatzteileanfrage .sku input').keyup( function() {
		if(!$(this).hasClass('invalid') && $(this).val().length == 7) {
			$(this).parent().next().children('input').focus();
		} else {
			$(this).parent().children('#articlename').remove();
		}
	});
	
	$.tools.validator.fn('[sku]', 
		function(input, value) { 
			if(value.length == 7) {
				is_valid = false;
				var message = 'Bitte geben Sie eine gültige Artikelnummer ein';
				$.ajax({
					url:"index.php",
					async:false,
					data:{
						eID: "skucheck",
			            sku: value
					},
					success: function(articlename) {
						if(articlename.length > 0) {
							is_valid = true;
							input.parent().children('#articlename').remove();
							input.parent().append('<div id="articlename">'+articlename+'</div>');
						}
					}
				});
				return is_valid ? true : message;
			} else return true;
		}
	);	
});
