/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});

		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});

	}

	return jQuery;

};

})(jQuery);


function loading(mode) {
    var bg = (mode == 'on') ? 'url("/gfx/ajax-loader.gif")' : '';
    $('#loading').css('background', bg)
}
function get_id(what) {
    var id = $('.chosen', what).attr('id');
    return id.substr(4)
}
function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

function bind_formsubmit()
{
	var errors = new Array();
	errors[0] = new Object();
	errors[0]['email'] = 'Die angegebene Emailadresse ist bereits in Benutzung! Bitte loggen Sie sich ein!';
	errors[0]['adress'] ='Nicht alle erforderten Felder sind richtig ausgef&uuml;llt worden!';
	errors[0]['flood'] ='Von ihrer IP aus wurde vor kurzem bereits eine Bestellung abgegeben. Bitte rufen Sie f&uuml;r &Auml;nderungen 03834/501501 an';
	errors[0]['fine'] ='Die Bestellung wurde angenommen und wird demn&auml;chst auf dem Weg zu Ihnen sein!';
	errors[0]['sql'] = 'Es gab einen Fehler bei der &Uuml;bertragung der Bestellung. Der Vorgang wurde komplett abgebrochen. Bitte versuchen Sie es sp&auml;ter noch einmal';

	$('#cart_adress_submit', '#cart_adress').bind('click', function (e) {
		loading('on');
		// validate and process form here
 		$('#error_').hide().removeClass('dn');
 		$('#error_box').html('');



		var bk_karte = ($("#bk_karte_1:checked").val() == 1) ?  1 : 0 ;
			

  var mode_user = $('#mode_user').val();
	if (mode_user == 'buy')
	{
		var exit = false;
	}
	else
	{
		 	var bk_name = $('#bk_name').val();
	   		var	bk_firma = $('#bk_firma').val();
			var	bk_abteilung = $('#bk_abteilung').val();
			var bk_anrede = ($("#bk_anrede_herr:checked").val() == "Herr") ? 'Herr' : 'Frau';
			var check = ($("#check:checked").val() == "yes") ? 'yes' : '';
			var bk_vorname = $('#bk_vorname').val();
			var bk_nachname = $('#bk_nachname').val();
			var bk_strasse = $('#bk_strasse').val();
			var bk_hausnr = $('#bk_hausnr').val();
			var bk_plz = $('#bk_plz').val();
			var bk_ort = $('#bk_ort').val();
			var bk_sonder = $('#bk_sonder').val();
			var bk_vorwahl = $('#bk_vorwahl').val();
			var bk_telefon = $('#bk_telefon').val();
			var bk_email = $('#bk_email').val();
			var password = $('#cart_adress_password').val();
			password = (password.length > 0) ? MD5(password): '';
	
	
	
		var std = new Array('bk_vorname','bk_nachname','bk_strasse','bk_hausnr','bk_plz','bk_ort','bk_vorwahl','bk_telefon');
	
		for (var i = 0;i<8;i++)
		{ var test = $('#'+std[i]).val();
			if (test.length <1)
			{
				var exit = true;
			}
		}
	}

	if (exit)
	{
		show_error(errors[0]['adress']);
	}
	else
	{
	
    $.ajax({
        type: "POST",
        scriptCharset: "ISO-8859-1",
        url: "/shop_cart.php",
        data: {
            'mode': 'buy',
		  	'check': check,
			'bk_firma':bk_firma,
			'bk_karte':bk_karte,
			'bk_abteilung':bk_abteilung,
			'bk_anrede':bk_anrede,
			'bk_vorname':bk_vorname,
			'bk_nachname':bk_nachname,
			'bk_strasse':bk_strasse,
			'bk_hausnr':bk_hausnr,
			'bk_plz':bk_plz,
			'bk_ort':bk_ort,
			'bk_sonder':bk_sonder,
			'bk_telefon':bk_telefon,
			'bk_vorwahl':bk_vorwahl,
			'bk_email':bk_email,
			'password':password
        },
        success: function (msg) {
						if (msg.length > 0)
						{
							if (strpos (msg, ';;', 0))
							{
								var problems = msg.split(';;');
						        for (var _key in problems){
											show_error(errors[0][_key]);
						        }
							}
							else
							{
								if (msg.search(/ratinghash.+/) != -1)
								{
									msg = msg.substr(10);
									show_error('<b>'+errors[0]['fine']+'</b><br /><br />Wir w&uuml;rden uns sehr freuen, wenn sie nach der Bestellung eine <b>Bewertung</b> abgeben.<br />Dies ist <a href="/bewerte/'+msg+'/">hier</a> m&ouml;glich oder in ihrer Bestellungs&uuml;bersicht, falls Sie registrierter Kunde sind.');
									cart_load();
								}
								else
								{
									show_error(errors[0][msg]);		
								}

							}
						}
						else
						{
							show_error(errors[0]['fine']);
							cart_load();
						}
        }
    });
    

	}
		loading('off');
	});
}

function in_array(item, arr) {

	for(p=0;p<arr.length;p++)
	{
		if (item == arr[p])
		{
      return true;
		}
	}
	return false;
}

function show_error(text)
{
	block_ui(text);
}

	function init_stars()
	{
		$('#star_rating').mouseleave(function(){
			var i = 1;
			while (i<=5)
			{
				$('#star_'+i,'#star_rating').removeClass('star-rating-hover');
				i++;
			}
		});
		
		$('a','#star_rating')
		.bind('click', function(e){
			$('div','#star_rating').removeClass('star-rating-on');
			var number = $(this).html();
			var i = 1;
			while (i<=number)
			{
				$('#star_'+i,'#star_rating').removeClass('star-rating-hover').addClass('star-rating-on');
				i++;
			}
			$('#input_rating','#star_rating').attr('value', number);
		})
		.hover(function(e)
		{
			$('div','#star_rating').removeClass('star-rating-hover');
			var number = $(this).html();
			var i = 1;
			while (i<=number)
			{
				$('#star_'+i,'#star_rating').addClass('star-rating-hover');
				i++;
			}

			var element = $(this).parent();
			
			if ($(element).hasClass('star-rating-hover'))
			{
			
			}
		});
	}




function check_for_open()
{
  var datum = new Date();
  var day = datum.getDay();
  var hour = datum.getHours();
  var opening = new Array();
  opening[0] = new Array(0, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[1] = new Array(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[2] = new Array(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[3] = new Array(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[4] = new Array(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[5] = new Array(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
  opening[6] = new Array(0, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
   
  if (!in_array(hour, opening[day]))
  {
		show_error('Sie besuchen unseren Shop ausserhalb der <a href="/impressum/">Lieferzeiten</a>. Sie k&ouml;nnen aber gerne schon eine Bestellung im Voraus abgeben');
	}
}

function check_length(where) {
    var p = $(where);
    if (p.length > 0) {
        return true
    } else {
        return false
    }
}
function check_for_min() {	
    if (check_length('#cartsum')) {
        var price = $('#cartsum').html();
        price = price.slice(0, price.length-1);
        price = price.replace(/,/, '.');
        price = parseFloat(price);
        if (price > 8.5) {
            $('#cart_m').remove();
            $('#cart_adress_submit', '#cart_adress').removeAttr("disabled");
						bind_formsubmit();
        } else {
            $('#cart_adress_submit', '#cart_adress').attr("disabled", "disabled")
        }
    }
}
function menu_init_options(group) {
    $('input:checkbox', '#' + group + '_options').change(function () {
        var option = $(this).attr('id');
        option = option.split('_');
        var i = option[1];
        var field = ($('#field_' + group + '_' + i).val()) ? parseInt($('#field_' + group + '_' + i).val()) : 0;
        var option = $('#to_' + group + '_' + i, '#' + group + '_options').val();
        var cost = parseFloat($('#price_' + option, '#' + group + '_options').html());
        if (this.checked) {
            var weight = 700;
            var newcost = cost.toFixed(2) + '&euro;';
            newcost = newcost.replace(/\./g, ",")
        } else {
            var weight = 400;
            var newcost = '0,00&euro;'
        }
        $('#option_' + option, '#' + group + '_options').html(newcost).css('font-weight', weight);
        menu_process_price()
    });
    $('input:radio', '#' + group + '_options').change(function () {
        var option = $(this).attr('id');
        option = option.split('_');
        var i = option[2];
        var field = ($('#field_' + group + '_' + i).val()) ? parseInt($('#field_' + group + '_' + i).val()) : 0;
        var option = $('#to_' + group + '_' + i, '#' + group + '_options').val();
        var cost = parseFloat($('#price_' + option, '#' + group + '_options').html());
        if (this.checked) {
            var weight = 700;
            var newcost = cost.toFixed(2) + '&euro;';
            newcost = newcost.replace(/\./g, ",")
        } else {
            var weight = 400;
            var newcost = '0,00&euro;'
        }
        $('#option_' + option, '#' + group + '_options').html(newcost).css('font-weight', weight);
        menu_process_price()
    });
    $('input:text', '#' + group + '_options').focus(function () {
        if ($(this).val() == 0) {
            $(this).val('')
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('0')
        }
    }).keyup(function () {
        var option = '';
        var field = 0;
        var sum = 0;
        for (var i = 0; i <= 2; i++) {
            field = ($('#' + group + '_' + i, '#' + group + '_options').val()) ? parseInt($('#' + group + '_' + i, '#' + group + '_options').val()) : 0;
            option = $('#to_' + group + '_' + i, '#' + group + '_options').val();
            var cost = parseFloat($('#price_' + option, '#' + group + '_options').html());
            sum += field;
						var weight = 700;
						
            if (field > 0) {
            	/*

							--if (sum > 1 && field > 0) {--
                if (sum - field < 1) {
                    var difference = sum - 1;
                    cost = difference * cost;
                    var newcost = cost.toFixed(2) + '&euro;';
                    newcost = newcost.replace(/\./g, ",")
                } else {
								*/
                    cost = cost * field;
                    var newcost = cost.toFixed(2) + '&euro;';
                    newcost = newcost.replace(/\./g, ",");
								/*
								}
				            */
            } else {
                cost = 0.0;
                var weight = 400;
                var newcost = '0,00&euro;';
            }

            $('#option_' + option, '#' + group + '_options').html(newcost).css('font-weight', weight)
        }
        menu_process_price()
    })
}
function cart_load() {
    $("#cart_details").load("/shop_cart.php", {
        mode: 'view'
    },
    function () {
        cart_init();
        check_for_min();
        if ($('#cartsum').html() != '0,00€') {
            $('#cart_adress').removeClass('dn')
        } else {
            $('#cart_adress').addClass('dn')
        }
    });
    loading('off')
}
function add_to_cart() {
    var options = '';
    loading('on');
    $('input', '#burger_options').each(function (e) {
        var option = $(this).attr('id');
        option = option.split('_');
        i = option[1];
        field = ($('#burger_' + i).val()) ? parseInt($('#burger_' + i).val()) : 0;
        option = $('#to_burger_' + i, '#burger_options').val();
        if ($(this).attr('type') == "checkbox") {
            if (this.checked) {
                options += option + ','
            }
        }
    });
    $('input', '#side_options').each(function (e) {
        var option = $(this).attr('id');
        option = option.split('_');
        i = option[1];
        field = ($('#side_' + i, '#side_options').val()) ? parseInt($('#side_' + i, '#side_options').val()) : 0;
        option = $('#to_side_' + i, '#side_options').val();
        var type = $(this).attr('type');
        if (type == "text") {
            field = (field) ? parseInt(field) : 0;
            if (field) {
                for (var i = 0; i < field; i++) {
                    options += option + ','
                }
            }
        }
        if (type == "checkbox" || type == "radio") {
            if (this.checked) {
                options += option + ','
            }
        }
    });
    $('input', '#drink_options').each(function (e) {
        var option = $(this).attr('id');
        option = option.split('_');
        i = option[1];
        field = ($('#drink_' + i, '#drink_options').val()) ? parseInt($('#drink_' + i, '#drink_options').val()) : 0;
        option = $('#to_drink_' + i, '#drink_options').val();
        var type = $(this).attr('type');
        if (type == "text") {
            field = (field) ? parseInt(field) : 0;
            if (field) {
                for (var i = 0; i < field; i++) {
                    options += option + ','
                }
            }
        }
        if (type == "checkbox") {
            if (this.checked) {
                options += option + ','
            }
        }
    });
    var note = $('#note', '#menuconfig').val();
    var burgerid = get_id('#burger');
    var drinkid = get_id('#drink');
    var sideid = get_id('#side');
    var menutype = $('#menutype', '#menuconfig').val();
    options = options.slice(0, -1);
    $.ajax({
        type: "POST",
        url: "/shop_cart.php",
        data: {
            'menuid': burgerid,
            'menutyp': menutype,
            'drinkid': drinkid,
            'sideid': sideid,
            'note': note,
            'options': options
        },
        success: function (msg) {
            loading('off');
            window.location = location.href
        }
    })
};
function menu_process_price() {
    var start = parseFloat($('#price', '#burger_options').html());
    var field = '';
    var option = '';
    start = (start > 0) ? start : 0;
    $('input', '#burger_options').each(function (e) {
        var option = $(this).attr('id');
        option = option.split('_');
        i = option[1];
        field = ($('#burger_' + i).val()) ? parseInt($('#burger_' + i).val()) : 0;
        option = $('#to_burger_' + i, '#burger_options').val();
        if ($(this).attr('type') == "checkbox") {
            if (this.checked) {
                var cost = parseFloat($('#price_' + option, '#burger_options').html());
                start += cost
            }
        }
    });
    var sum = 0;
    for (var i = 0; i <= 2; i++) {
        field = ($('#side_' + i, '#side_options').val()) ? parseInt($('#side_' + i, '#side_options').val()) : 0;
        option = $('#to_side_' + i, '#side_options').val();
        field = (field) ? parseInt(field) : 0;
        sum += field;
        if (field) {
            var cost = parseFloat($('#price_' + option, '#side_options').html());
            var whole = cost * field;
            start += whole
        }
    }
    /*
    if (sum >= 1) {
        start -= cost
    }
		*/
    for (var i = 0; i <= 2; i++) {
        field = ($('#drink_' + i, '#drink_options').val()) ? parseInt($('#drink_' + i, '#drink_options').val()) : 0;
        option = $('#to_drink_' + i, '#drink_options').val();
        field = (field) ? parseInt(field) : 0;
        if (field) {
            var cost = parseFloat($('#price_' + option, '#drink_options').html());
            var whole = cost * field;
            start += whole
        }
    }
    start = start.toFixed(2) + '&euro;';
    start = start.replace(/\./g, ",");
    $('#compl').html(start)
}
function check_for_submit() {
    var p = $('.chosen', '#menuconfig');
    if (p.length == 3) {
        $('#submit', '#menuconfig').removeAttr("disabled")
    } else {
        $('#submit', '#menuconfig').attr("disabled", "disabled")
    }
}
function menu_click(p, group) {
    var id = $(p).attr('id').substr(1);
    if (!$('#prod' + id, group).hasClass('chosen')) {
        loading('on');
        $('li:not(#prod' + id + ')', group).fadeTo("fast", 0.250).removeClass('chosen');
        $('#prod' + id, group).fadeTo("fast", 1).addClass('chosen');
        var group2 = group.substr(1);
        $(group + '_options').load("/shop_cart.php", {
            mode: 'options',
            note: group2,
            options: id
        },
        function (e) {
            $(document).ready(function () {
                menu_init_options(group2);
                menu_process_price();
                loading('off')
            })
        })
    }
    check_for_submit()
}
function menues_init() {
    if (check_length('#menuconfig')) {
        $('a', '#burger').bind('click', function (e) {
            menu_click(this, '#burger');
            return false
        });
        $('a', '#side').bind('click', function (e) {
            menu_click(this, '#side');
            return false
        });
        $('a', '#drink').bind('click', function (e) {
            menu_click(this, '#drink');
            return false
        });
        $('#submit', '#menuconfig').bind('click', function (e) {
            add_to_cart();
            return false
        });
        check_for_submit()
    }
}
function products_init() {
    if (check_length('#productlist li')) {
        $('#productlist li a').each(function () {
            var id = $(this).attr('id');
            id = id.substr(2);
            if ($(this).hasClass('options')) {
                $(this).bind('click', function (e) {
              			var count = parseInt($('#count'+id).val());
              			if (count > 0)
              			{
											tb_show(null, '/shop_cart.php?height=350&width=280&modal=true&show=' + id + '&count=' + count, false);
              			}
										return false
                    
                })
            } else {
                $(this).bind('click', function (e) {
                    loading('on');
              			var count = parseInt($('#count'+id).val());
              			if (count > 0)
                 		{
                    $.ajax({
                        type: "POST",
                        url: "/shop_cart.php",
                        data: {
                            'add': id,
                            'count2': count
                        },
                        success: function (msg) {
                            cart_load()
                        }
                    });
                    }
                    return false
                })
            }
        })
    }
}
function cart_bind_buttons(where, what) {
    $(where, '#cart_details').unbind().bind('click', function (e) {
        loading('on');
        var itemid = $(this).attr('class').split(' ').slice(-1);
        $.ajax({
            type: "POST",
            url: "/shop_cart.php",
            data: {
                mode: what,
                itemid: itemid
            },
            success: function (msg) {
                cart_load();
                loading('off')
            }
        });
        return false
    })
}
function cart_init() {
    if (check_length('#cart_details')) {
        var array = new Array('succ', 'pred', 'del');
        for (var _key in array) {
            var key = '.' + array[_key] + '_link';
            cart_bind_buttons(key, array[_key])
        }
    }
}


function block_ui(message)
{	
  $.blockUI({ 
            message: message+"<br /><a id=\"blockuiclose\" href=\"?\">schliessen</a>", 
            showOverlay: true, 
            fadeIn: 700, 
            fadeOut: 700, 
            timeout: 20000,
            centerY: false, 
            overlayCSS: { backgroundColor: '#EFE8DE'},
            css: {
            	top: '30px',
                width: '350px', 
                border: 'none', 
                padding: '5px', 
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                color: '#fff' 
            }
        });
		$('#blockuiclose').attr('title','Klicken um das Popup zu schliessen!').click(function(e){
			$.unblockUI();
			return false;
		}); 
    
		$('.blockOverlay').attr('title','Klicken um das Popup zu schliessen!').click($.unblockUI); 
}

function product_init() {
    if (check_length('#productadd')) {
        $('#exit', '#productadd').bind('click', function (e) {
            tb_remove()
        });
        $('#submit', '#productadd').bind('click', function (e) {
            var options = '0';
            for (var i = 0; i <= 10; i++) {
                var p = $('#' + i, '#productadd');
                if (p.length > 0) {
                    var name = p.attr('name');
                    name = name.split('_');
                    var type = name[1];
                    var id = name[2];
                    var option = $('#to_' + type + '_' + id, '#productadd').val();
                    if (p.attr('type') == 'checkbox') {
                        if (p.is(':checked')) {
                            options += ',' + option
                        }
                    } else { if (p.val() > 0) {
                            for (var z = 0; z < p.val(); z++) {
                                options += ',' + option
                            }
                        }
                    }
                }
            }
            options = options.substr(2);
            options += '';
            var note = $('#note', '#productadd').val();
            var id = $('#productid', '#productadd').val();
            var count = $('#prodcount', '#productadd').val();
            $.ajax({
                type: "POST",
                url: "/shop_cart.php",
                data: {
                    'add': id,
                    'note': note,
                    'count2' : count,
                    'options': options
                },
                success: function (msg) {
                    cart_load();
                    tb_remove()
                }
            })
        });
        $('input:checkbox', '#productadd').change(function () {
            var price = $('#compl', '#productadd').html();
            price = price.slice(0, -1);
            price = parseFloat(price.replace(/,/, '.'));
            var name = $(this).attr('name');
            name = name.split('_');
            var type = name[1];
            var id = name[2];
            var option = $('#to_' + type + '_' + id, '#productadd').val();
            var cost = parseFloat($('#price_' + option + '_' + id, '#productadd').html());
            if (this.checked) {
                var newprice = price + cost;
                var newcost = cost.toFixed(2) + '&euro;';
                var weight = 700;
                newcost = newcost.replace(/\./g, ",")
            } else {
                var weight = 400;
                var newprice = price - cost;
                var newcost = '0,00&euro;'
            }
            newprice = newprice.toFixed(2);
            newprice += '&euro;';
            newprice = newprice.replace(/\./g, ",");
            $('#compl', '#productadd').html(newprice);
            $('#option_' + option + '_' + id, '#productadd').html(newcost).css('font-weight', weight)
        });
        $('input:text', '#productadd').focus(function () {
            if ($(this).val() == 0) {
                $(this).val('')
            }
        }).blur(function () {
            if ($(this).val() == '') {
                $(this).val('0')
            }
        }).keyup(function () {
            var count = parseInt($('#count', '#productadd').html());
            var price = parseFloat($('#price', '#productadd').html());
            var max_count = parseInt($('#max_count', '#productadd').html());
            max_count = (max_count > 0) ? max_count : 0;
            var field = 0;
            var sum = 0;
            var option = '';
            var extra = 0.0;
            for (i = 0; i < 5; i++) {
                field = ($('#' + i).val()) ? parseInt($('#' + i).val()) : 0;
                option = $('#to_s_' + i, '#productadd').val();
                var cost = parseFloat($('#price_' + option + '_' + i, '#productadd').html());
                sum += field;
                if (sum > max_count && field > 0) {
                    var weight = 700;
                    if (sum - field < max_count) {
                        var difference = sum - max_count;
                        cost = difference * cost;
                        var newcost = cost.toFixed(2) + '&euro;';
                        newcost = newcost.replace(/\./g, ",")
                    } else {
                        cost = cost * field;
                        var newcost = cost.toFixed(2) + '&euro;';
                        newcost = newcost.replace(/\./g, ",")
                    }
                } else {
                    cost = 0.0;
                    var weight = 400;
                    var newcost = '0,00&euro;'
                }
                extra += cost;
                $('#option_' + option + '_' + i, '#productadd').html(newcost).css('font-weight', weight)
            }
            extra = price + extra;
            extra = extra.toFixed(2) + '&euro;';
            extra = extra.replace(/\./g, ",");
            $('#compl').html(extra)
        });
        $('input:radio', '#' + group + '_options').change(function () {
            var option = $(this).attr('id');
            option = option.split('_');
            var i = option[2];
            var field = ($('#field_' + group + '_' + i).val()) ? parseInt($('#field_' + group + '_' + i).val()) : 0;
            var option = $('#to_' + group + '_' + i, '#' + group + '_options').val();
            var cost = parseFloat($('#price_' + option, '#' + group + '_options').html());
            if (this.checked) {
                var weight = 700;
                var newcost = cost.toFixed(2) + '&euro;';
                newcost = newcost.replace(/\./g, ",")
            } else {
                var weight = 400;
                var newcost = '0,00&euro;'
            }
            $('#option_' + option, '#' + group + '_options').html(newcost).css('font-weight', weight);
            menu_process_price()
        });
        $('input:text', '#' + group + '_options').focus(function () {
            if ($(this).val() == 0) {
                $(this).val('')
            }
        }).blur(function () {
            if ($(this).val() == '') {
                $(this).val('0')
            }
        }).keyup(function () {
            var option = '';
            var field = 0;
            var sum = 0;
            for (var i = 0; i <= 2; i++) {
                field = ($('#field_' + group + '_' + i).val()) ? parseInt($('#field_' + group + '_' + i).val()) : 0;
                option = $('#to_' + group + '_' + i, '#' + group + '_options').val();
                var cost = parseFloat($('#price_' + option, '#' + group + '_options').html());
                sum += field;
                if (sum > 1 && field > 0) {
                    var weight = 700;
                    if (sum - field < 1) {
                        var difference = sum - 1;
                        cost = difference * cost;
                        var newcost = cost.toFixed(2) + '&euro;';
                        newcost = newcost.replace(/\./g, ",")
                    } else {
                        cost = cost * field;
                        var newcost = cost.toFixed(2) + '&euro;';
                        newcost = newcost.replace(/\./g, ",")
                    }
                } else {
                    cost = 0.0;
                    var weight = 400;
                    var newcost = '0,00&euro;'
                }
                $('#option_' + option, '#' + group + '_options').html(newcost).css('font-weight', weight)
            }
            menu_process_price()
        })
    }
}
function array(n) {
    for (i = 0; i < n; i++) this[i] = 0;
    this.length = n
}
function integer(n) {
    return n % (0xffffffff + 1)
}
function shr(a, b) {
    a = integer(a);
    b = integer(b);
    if (a - 0x80000000 >= 0) {
        a = a % 0x80000000;
        a >>= b;
        a += 0x40000000 >> (b - 1)
    } else a >>= b;
    return a
}
function shl1(a) {
    a = a % 0x80000000;
    if (a & 0x40000000 == 0x40000000) {
        a -= 0x40000000;
        a *= 2;
        a += 0x80000000
    } else a *= 2;
    return a
}
function shl(a, b) {
    a = integer(a);
    b = integer(b);
    for (var i = 0; i < b; i++) a = shl1(a);
    return a
}
function and(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0) if (t2 >= 0) return ((t1 & t2) + 0x80000000);
    else return (t1 & b);
    else if (t2 >= 0) return (a & t2);
    else return (a & b)
}
function or(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0) if (t2 >= 0) return ((t1 | t2) + 0x80000000);
    else return ((t1 | b) + 0x80000000);
    else if (t2 >= 0) return ((a | t2) + 0x80000000);
    else return (a | b)
}
function xor(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0) if (t2 >= 0) return (t1 ^ t2);
    else return ((t1 ^ b) + 0x80000000);
    else if (t2 >= 0) return ((a ^ t2) + 0x80000000);
    else return (a ^ b)
}
function not(a) {
    a = integer(a);
    return (0xffffffff - a)
}
var state = new array(4);
var count = new array(2);
count[0] = 0;
count[1] = 0;
var buffer = new array(64);
var transformBuffer = new array(16);
var digestBits = new array(16);
var S11 = 7;
var S12 = 12;
var S13 = 17;
var S14 = 22;
var S21 = 5;
var S22 = 9;
var S23 = 14;
var S24 = 20;
var S31 = 4;
var S32 = 11;
var S33 = 16;
var S34 = 23;
var S41 = 6;
var S42 = 10;
var S43 = 15;
var S44 = 21;
function F(x, y, z) {
    return or(and(x, y), and(not(x), z))
}
function G(x, y, z) {
    return or(and(x, z), and(y, not(z)))
}
function H(x, y, z) {
    return xor(xor(x, y), z)
}
function I(x, y, z) {
    return xor(y, or(x, not(z)))
}
function rotateLeft(a, n) {
    return or(shl(a, n), (shr(a, (32 - n))))
}
function FF(a, b, c, d, x, s, ac) {
    a = a + F(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a
}
function GG(a, b, c, d, x, s, ac) {
    a = a + G(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a
}
function HH(a, b, c, d, x, s, ac) {
    a = a + H(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a
}
function II(a, b, c, d, x, s, ac) {
    a = a + I(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a
}
function transform(buf, offset) {
    var a = 0,
    b = 0,
    c = 0,
    d = 0;
    var x = transformBuffer;
    a = state[0];
    b = state[1];
    c = state[2];
    d = state[3];
    for (i = 0; i < 16; i++) {
        x[i] = and(buf[i * 4 + offset], 0xff);
        for (j = 1; j < 4; j++) {
            x[i] += shl(and(buf[i * 4 + j + offset], 0xff), j * 8)
        }
    }
    a = FF(a, b, c, d, x[0], S11, 0xd76aa478);
    d = FF(d, a, b, c, x[1], S12, 0xe8c7b756);
    c = FF(c, d, a, b, x[2], S13, 0x242070db);
    b = FF(b, c, d, a, x[3], S14, 0xc1bdceee);
    a = FF(a, b, c, d, x[4], S11, 0xf57c0faf);
    d = FF(d, a, b, c, x[5], S12, 0x4787c62a);
    c = FF(c, d, a, b, x[6], S13, 0xa8304613);
    b = FF(b, c, d, a, x[7], S14, 0xfd469501);
    a = FF(a, b, c, d, x[8], S11, 0x698098d8);
    d = FF(d, a, b, c, x[9], S12, 0x8b44f7af);
    c = FF(c, d, a, b, x[10], S13, 0xffff5bb1);
    b = FF(b, c, d, a, x[11], S14, 0x895cd7be);
    a = FF(a, b, c, d, x[12], S11, 0x6b901122);
    d = FF(d, a, b, c, x[13], S12, 0xfd987193);
    c = FF(c, d, a, b, x[14], S13, 0xa679438e);
    b = FF(b, c, d, a, x[15], S14, 0x49b40821);
    a = GG(a, b, c, d, x[1], S21, 0xf61e2562);
    d = GG(d, a, b, c, x[6], S22, 0xc040b340);
    c = GG(c, d, a, b, x[11], S23, 0x265e5a51);
    b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aa);
    a = GG(a, b, c, d, x[5], S21, 0xd62f105d);
    d = GG(d, a, b, c, x[10], S22, 0x2441453);
    c = GG(c, d, a, b, x[15], S23, 0xd8a1e681);
    b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8);
    a = GG(a, b, c, d, x[9], S21, 0x21e1cde6);
    d = GG(d, a, b, c, x[14], S22, 0xc33707d6);
    c = GG(c, d, a, b, x[3], S23, 0xf4d50d87);
    b = GG(b, c, d, a, x[8], S24, 0x455a14ed);
    a = GG(a, b, c, d, x[13], S21, 0xa9e3e905);
    d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8);
    c = GG(c, d, a, b, x[7], S23, 0x676f02d9);
    b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8a);
    a = HH(a, b, c, d, x[5], S31, 0xfffa3942);
    d = HH(d, a, b, c, x[8], S32, 0x8771f681);
    c = HH(c, d, a, b, x[11], S33, 0x6d9d6122);
    b = HH(b, c, d, a, x[14], S34, 0xfde5380c);
    a = HH(a, b, c, d, x[1], S31, 0xa4beea44);
    d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9);
    c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60);
    b = HH(b, c, d, a, x[10], S34, 0xbebfbc70);
    a = HH(a, b, c, d, x[13], S31, 0x289b7ec6);
    d = HH(d, a, b, c, x[0], S32, 0xeaa127fa);
    c = HH(c, d, a, b, x[3], S33, 0xd4ef3085);
    b = HH(b, c, d, a, x[6], S34, 0x4881d05);
    a = HH(a, b, c, d, x[9], S31, 0xd9d4d039);
    d = HH(d, a, b, c, x[12], S32, 0xe6db99e5);
    c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8);
    b = HH(b, c, d, a, x[2], S34, 0xc4ac5665);
    a = II(a, b, c, d, x[0], S41, 0xf4292244);
    d = II(d, a, b, c, x[7], S42, 0x432aff97);
    c = II(c, d, a, b, x[14], S43, 0xab9423a7);
    b = II(b, c, d, a, x[5], S44, 0xfc93a039);
    a = II(a, b, c, d, x[12], S41, 0x655b59c3);
    d = II(d, a, b, c, x[3], S42, 0x8f0ccc92);
    c = II(c, d, a, b, x[10], S43, 0xffeff47d);
    b = II(b, c, d, a, x[1], S44, 0x85845dd1);
    a = II(a, b, c, d, x[8], S41, 0x6fa87e4f);
    d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0);
    c = II(c, d, a, b, x[6], S43, 0xa3014314);
    b = II(b, c, d, a, x[13], S44, 0x4e0811a1);
    a = II(a, b, c, d, x[4], S41, 0xf7537e82);
    d = II(d, a, b, c, x[11], S42, 0xbd3af235);
    c = II(c, d, a, b, x[2], S43, 0x2ad7d2bb);
    b = II(b, c, d, a, x[9], S44, 0xeb86d391);
    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d
}
function init() {
    count[0] = count[1] = 0;
    state[0] = 0x67452301;
    state[1] = 0xefcdab89;
    state[2] = 0x98badcfe;
    state[3] = 0x10325476;
    for (i = 0; i < digestBits.length; i++) digestBits[i] = 0
}
function update(b) {
    var index, i;
    index = and(shr(count[0], 3), 0x3f);
    if (count[0] < 0xffffffff - 7) count[0] += 8;
    else {
        count[1]++;
        count[0] -= 0xffffffff + 1;
        count[0] += 8
    }
    buffer[index] = and(b, 0xff);
    if (index >= 63) {
        transform(buffer, 0)
    }
}
function finish() {
    var bits = new array(8);
    var padding;
    var i = 0,
    index = 0,
    padLen = 0;
    for (i = 0; i < 4; i++) {
        bits[i] = and(shr(count[0], (i * 8)), 0xff)
    }
    for (i = 0; i < 4; i++) {
        bits[i + 4] = and(shr(count[1], (i * 8)), 0xff)
    }
    index = and(shr(count[0], 3), 0x3f);
    padLen = (index < 56) ? (56 - index) : (120 - index);
    padding = new array(64);
    padding[0] = 0x80;
    for (i = 0; i < padLen; i++) update(padding[i]);
    for (i = 0; i < 8; i++) update(bits[i]);
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            digestBits[i * 4 + j] = and(shr(state[i], (j * 8)), 0xff)
        }
    }
}
function hexa(n) {
    var hexa_h = "0123456789abcdef";
    var hexa_c = "";
    var hexa_m = n;
    for (hexa_i = 0; hexa_i < 8; hexa_i++) {
        hexa_c = hexa_h.charAt(Math.abs(hexa_m) % 16) + hexa_c;
        hexa_m = Math.floor(hexa_m / 16)
    }
    return hexa_c
}
var ascii = "01234567890123456789012345678901" + " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
function MD5(nachricht) {
    var l, s, k, ka, kb, kc, kd;
    init();
    for (k = 0; k < nachricht.length; k++) {
        l = nachricht.charAt(k);
        update(ascii.lastIndexOf(l))
    }
    finish();
    ka = kb = kc = kd = 0;
    for (i = 0; i < 4; i++) ka += shl(digestBits[15 - i], (i * 8));
    for (i = 4; i < 8; i++) kb += shl(digestBits[15 - i], ((i - 4) * 8));
    for (i = 8; i < 12; i++) kc += shl(digestBits[15 - i], ((i - 8) * 8));
    for (i = 12; i < 16; i++) kd += shl(digestBits[15 - i], ((i - 12) * 8));
    s = hexa(kd) + hexa(kc) + hexa(kb) + hexa(ka);
    return s
}