(function(A){A.fn.jSuggest=function(D){var F=A.extend({},A.fn.jSuggest.defaults,D);var G=".jSuggestHover";var H="jSuggestHover";var E=this.value;var I=this;var C=this.value;var B="#jSuggestContainer";A("body").append('<div id="jSuggestContainer"></div>');A(B).hide();A(this).bind("keyup click",function(K){I=this;C=this.value;if(this.value.length>=F.minchar&&A.trim(this.value)!="Search Terms"){var J=A(this).offset();A(B).css({position:"absolute",top:J.top+A(this).outerHeight()+"px",left:J.left,width:A(this).outerWidth()-2+"px",opacity:F.opacity,zIndex:F.zindex}).show();if(K.keyCode==27){A(B).hide()}else{if(K.keyCode==13){if(A(G).length==1){A(I).val(A(G).text())}A(B).hide();E=I.value}else{if(K.keyCode==40){if(A(G).length==1){if(!A(G).next().length==0){A(G).next().addClass(H);A(".jSuggestHover:eq(0)").removeClass(H);if(F.autoChange){A(I).val(A(G).text())}}}else{A("#jSuggestContainer ul li:first-child").addClass(H);if(F.autoChange){A(I).val(A(G).text())}}}else{if(K.keyCode==38){if(A(G).length==1){if(!A(G).prev().length==0){A(G).prev().addClass(H);A(".jSuggestHover:eq(1)").removeClass(H);if(F.autoChange){A(I).val(A(G).text())}}else{A(G).removeClass(H);A(I).val(E)}}}else{if(I.value!=E){E=I.value;if(A(".jSuggestLoading").length==0){A('<div class="jSuggestLoading"><img src="'+F.loadingImg+'" align="bottom" /> '+F.loadingText+"</div>").prependTo("#jSuggestContainer")}A(".jSuggestLoading").show();A(B).find("ul").remove();if(F.data==""){F.data=A(this).serialize()}else{F.data=F.data+"="+A(this).val()}setTimeout(function(){A.ajax({type:F.type,url:F.url,data:F.data,success:function(L){A(B).find("ul").remove();A(B).append(L);A("#jSuggestContainer ul li").bind("mouseover",function(){A(G).removeClass(H);A(this).addClass(H);C=A(this).text();if(F.autoChange){A(I).val(A(G).text())}});A("#jSuggestContainer ul li").click(function(){A(this).addClass(H);A(I).val(C)});A(".jSuggestLoading").hide()}})},F.delay)}}}}}}else{A(G).removeClass(H);A(B).hide()}return false});A(document).bind("click",function(){A(B).hide();E=I.value})};A.fn.jSuggest.defaults={minchar:3,opacity:1,zindex:20000,delay:2500,loadingImg:"ajax-loader.gif",loadingText:"Loading...",autoChange:false,url:"",type:"GET",data:""}})(jQuery);

function checkcompany(sender) {
	if ($('.stateinput0').val() == 'Italy' || $('.stateinput1').val() == 'Italien' || $('.stateinput2').val() == 'Italia') {
		$('#taxcodetd').show();
	}
	else $('#taxcodetd').hide();
	if (sender.checked) {
		$('#companyadditional1').show();
		$('#companyadditional2').show();
		var text = $('#firstnameinput').val() + $('#lastnameinput').val();
		$('#companyadditional1 input').val(text);
	}
	else {
		$('#companyadditional1').hide();
		$('#companyadditional2').hide();
	}
}

function tip () {
	var ind = Math.floor(Math.random() * 3) + 1;
	var content = document.getElementById("a" + ind);
	if(content) content.style.display = "block";
}
function setwindow () {
	MeinFenster =
	window.open("/index.php?id=anfahrt", "Anfahrt", "width=600,height=439,scrollbars=false");
	MeinFenster.focus();
}
function changecolor(sender) {
	var title = sender.title;
	var fontselect = document.getElementById('menu2color');
	if (fontselect) {
		for (var i = 0; i < fontselect.options.length; i++) {
			if (fontselect.options[i].value == title) fontselect.selectedIndex = i;
		}
	}
}
function callLink(sender) {
	var html = sender.innerHTML;
	var ergebnis = html.match(/href="(.*)">/);
	if (ergebnis.length > 0) {
		var chunks = ergebnis[0].split("\"");
		if (chunks.length > 1) {
			var newurl = unescape(chunks[1]);
			newurl = newurl.replace(/&amp;/, "&");
			window.location.href = "/" + newurl;
		}
	}
}

function tx_ratings_submit(ext, rating, type, id) {
	$('#'+id).val(rating);
	var width = 11 * (6 - rating);
	$('.tx-ratings-display .tx-ratings-gold-bar').css('width', width + 'px');
}

function loadspinner(sender) {
	$('#tx-ttproducts-pi1-list').html('<div class="spinner"><img src="fileadmin/templates/pic/spinner.gif" alt="wait a moment" /></div>');
}

window.setTimeout("tip()", 1000);

$(document).ready(function() {
	if (navigator.userAgent.toLowerCase().match('chrome') || navigator.userAgent.toLowerCase().match('safari')) {
		$('.tx-ratings-display').css('top', '18px');
	}
	$("a[rel]").overlay({
		expose: {
			color: '#333',
			loadSpeed: 200,
			opacity: 0.9
		},
		closeOnClick: true 
	});
	$("a[rel]").css('text-decoration', 'underline');
	if (document.getElementById('thePrice')) $("ul#sizetabs").hide();
	else {
		$("ul#sizetabs").tabs("#tx-ttproducts-pi1-list", {effect: 'ajax'});
	}
	size = gup('tx_ttproducts_pi1[size]');
	if (size != '') {
		//activate tab
		$('#sizetabs .current').removeClass('current');
		$('#sizetabs li').each(function(i) {
			text = $(this).html();
			if (text.indexOf(size) > 0) {
				$(this).find('a').addClass('current');
			}
		});
		//activate right option in select
		$('#menu3sizes option').each(function(i) {
			text = $(this).html();
			if (text.indexOf(size) != -1) $(this).attr('selected', 'selected');
		});
		calcPrice('menu3');
	}
	$('.stateinput0').jSuggest({
         url: "/fileadmin/templates/countries-en.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   $('.stateinput1').jSuggest({
         url: "/fileadmin/templates/countries-de.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   $('.stateinput2').jSuggest({
         url: "/fileadmin/templates/countries-it.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   if ($.trim($('#realcompanydata').text()) != '') $('#companydata').show();
   $('.lupe').each(function(i) {
        if (!$(this).prev().attr('href')) $(this).remove();
   });
   $('.lupe').click(function() {
        $(this).prev().click();
   });
});

function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
