var zeichen	= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

function stoperror()
{
	return true;
}
//window.onerror=stoperror;
function bittewarten(s)
{
    s.value = 'Bitte warten ...';
	s.disabled = true;
    return true;
}
function click()
{ 
} 

function init()
{
	$("a.fancybox").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'      	: 'easeOutBack',
		'easingOut'     	: 'easeInBack',
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000000',
		'centerOnScroll'	: true,
		'cyclic'	: true
	});

	$("a.fancybox_payment").fancybox({
		'type'				: 'iframe',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'      	: 'easeOutBack',
		'easingOut'     	: 'easeInBack',
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000000',
		'centerOnScroll'	: true,
		'width'				: 620,
		'height'			: 630,
		onClosed			: function() {
        	window.location.href = bestellungen_url;
		}
	});

	// Diashow im Header
	$('#diashow').cycle({
		fx:			'fade',
		speed:		3000,
		timeout:	6000
	});
	
	// E-Mail Entschlüsselung
	$('body').find('a.mwesp').each(function() {
		var $this = $(this);
		var text = $this.text().split(':');
		var mailto = $this.attr('href').split(':');
		var return_html = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;:';
		for (i in mailto){ return_html += '&#' + (mailto[i] - 5) + ';'; }
		return_html += '" class="' + $this.attr('class') + '">';
		for (i in text){ return_html += '&#' + (text[i] - 5) + ';'; }
		return_html += '</a>';
		$this.html(return_html);
	});
	
	$('#positionen_neu').click(function() {
		$('#positionen_neu_form').show('fast');
	});

	$('#benutzer_menu_toggle').click(function(event) {
		$('#layout_benutzer_menu').slideToggle('fast');
		event.preventDefault();
		event.stopPropagation();
	});
	
	$('.ajax_form_to_content').live('submit', function(event) {
		var $this = $(this);
		$('#loading').show();
		
		$('.md5', this).attr('value', '1');

		//Einloggen mit MD5
		$('.benutzer_login_passwort_md5', this).attr('value', $.md5($('.benutzer_login_passwort', this).attr('value') + $.cookie('sid')));
		$('.benutzer_login_passwort', this).attr('value', '');

		//Passwort ändern
		$('.passwort_alt_c', this).attr('value', $.md5($('.passwort_alt', this).attr('value') + $.cookie('sid')));
		$('.passwort_neu_1_c', this).attr('value', mwpec($('.passwort_neu_1', this).attr('value')));
		$('.passwort_neu_2_c', this).attr('value', mwpec($('.passwort_neu_2', this).attr('value')));
		$('.passwort_alt', this).attr('value', '');
		$('.passwort_neu_1', this).attr('value', '');
		$('.passwort_neu_2', this).attr('value', '');
		
		$.get($this.attr('action'), $this.serialize() + '&ajax=1&rand=' + Math.floor(Math.random()*99999999999), function(data) {
			$('#layout_content').html(data);
			$('#loading').hide();
		});
		event.preventDefault();
		event.stopPropagation();
	});
	
	$('.ajax_form_to_body').live('submit', function(event) {
		var $this = $(this);
		$('#loading').show();
		$.post($this.attr('action'), $this.serialize() + '&ajax=1&rand=' + Math.floor(Math.random()*99999999999), function(data) {
			$('body').append(data);
			$('#loading').hide();
		});
		event.preventDefault();
		event.stopPropagation();
	});

	$('.ajax_a_to_content').live('click', function(event) {
		$('#loading').show();
		$.get($(this).attr('href') + '&ajax=1&rand=' + Math.floor(Math.random()*99999999999), function(data){
			$('#layout_content').html(data);
			$('#loading').hide();
		});
		event.preventDefault();
		event.stopPropagation();
	});
	
	$('.ajax_a_to_body').live('click', function(event) {
		$('#loading').show();
		$.get($(this).attr('href') + '&ajax=1&rand=' + Math.floor(Math.random()*99999999999), function(data){
			$('body').append(data);
			$('#loading').hide();
		});
		event.preventDefault();
		event.stopPropagation();
	});
}

function mwpec(value_uc)
{
	var value_c = '';
	if (value_uc)
	{
		for (var i = 0; i < value_uc.length; i++)
		{
			if ($.cookie('sid').charAt(zeichen.indexOf(value_uc.charAt(i))))
			{
				value_c += $.cookie('sid').charAt(zeichen.indexOf(value_uc.charAt(i)));
			}
			else
			{
				value_c += value_uc.charAt(i);
			}
		}
	}
	return value_c;
}

function notification(msg)
{
	if (msg) $.jGrowl(msg);
}

function tabs_change(tab)
{
	for(var i = 0; i < tabs.length; i++)
	{
		if (tabs[i] != tab)
		{
			$('#tabs_content_'+tabs[i]).hide();
			$('#tabs_tab_'+tabs[i]).attr('class', 'tab');
		}
	}
	
	$('#tabs_content_'+tab).show();
	$('#tabs_tab_'+tab).attr('class', 'tabaktiv');
}


