var ArtikelMerklistePopup = {

	active: false,

	elm: {
		'merklistePopupContainer': new ElementActivation('merklistePopupContainer'),
		'ml_menu': new ElementActivation('ml_menu'),
		'ajax_loginForm': new ElementActivation('ajax_loginForm')
	},

	lagerbestaende: {

	},

	isActive: function() {

		return ArtikelMerklistePopup.active;

	},

	activate: function(evt) {

		if( ArtikelMerklistePopup.isActive() == true ) {

			Event.stop(evt);
			return false;

		}

		if( LightboxOverlay.isActive() == false ) {

			LightboxOverlay.activate();

		}

		ArtikelMerklistePopup.init();

		Event.stop(evt);

	},

	deactivate: function(evt) {

		ArtikelMerklistePopup.shutdown(evt);

	},

	init: function() {

		if( ArtikelMerklistePopup.elm['merklistePopupContainer'].isAvailable() == false ) {
			$('BodyOverlayContainer').insert({
				bottom:'<div id="merklistePopupContainer" style="display:none"><div id="merklistePopup"></div></div>'
			});
		}

		new Ajax.Updater('merklistePopup', '/?view=merkliste&'+rahmenGlobal.SID, {
			parameters: {
				ajax:'true'
			},
			onLoading: function(){
				if( !ArtikelMerklistePopup.elm['ajax_loginForm'].isAvailable() ) {
					$('merklistePopupContainer').style.display = '';
					$('merklistePopup').style.width = '120px';
					$('merklistePopup').insert({
						bottom:'<div id="merkliste_preloading_marker"><img src="/bilder/loader.gif" alt="loading" id="merkliste_loading_marker"></div>'
					});
				}
			},
			onComplete: function() {
				$('merklistePopup').style.width = '680px';
				if( ArtikelMerklistePopup.elm['merklistePopupContainer'].isActive() == false ) {

					ArtikelMerklistePopup.elm['merklistePopupContainer'].activate();
				}

				$$('a.schliessenButton').each(function(pe) {
					Event.observe(pe, 'click', ArtikelMerklistePopup.shutdown);
				});

				$$('a.merkzettelOeffnenLink').each(function(pe){
					Event.observe(pe,'click',ArtikelMerklistePopup.activate);
				});

				if( AjaxLogin.isActive() ) {
					AjaxLogin.checkFor(ArtikelMerklistePopup.init);
				} else {
					ArtikelMerklistePopup.applyHandler();
				}


				if( ArtikelMerklistePopup.elm['ml_menu'].isAvailable() ) {

					Event.observe($('mz_showALL'),'click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						$('produktAnz').innerHTML = $('anzAll').innerHTML;
					evt.stop();
					});

					Event.observe($('womenLink'),'click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzWomen';
						var linkField = 'womenLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms3').each(function(pe) {pe.hide();});
						$$('.ms4').each(function(pe) {pe.hide();});
						$$('.ms1210').each(function(pe) {pe.hide();});
						$$('.ms79').each(function(pe) {pe.hide();});
						$$('.ms14').each(function(pe) {pe.hide();});
						evt.stop();
					});

					$('menLink').observe('click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzMen';
						var linkField = 'menLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms2').each(function(pe) {pe.hide();});
						$$('.ms4').each(function(pe) {pe.hide();});
						$$('.ms1210').each(function(pe) {pe.hide();});
						$$('.ms79').each(function(pe) {pe.hide();});
						$$('.ms14').each(function(pe) {pe.hide();});
						evt.stop();
					});

					$('kidsLink').observe('click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzKids';
						var linkField = 'kidsLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms2').each(function(pe) {pe.hide();});
						$$('.ms3').each(function(pe) {pe.hide();});
						$$('.ms1210').each(function(pe) {pe.hide();});
						$$('.ms79').each(function(pe) {pe.hide();});
						$$('.ms14').each(function(pe) {pe.hide();});
						evt.stop();
					});

					$('shoesLink').observe('click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzShoes';
						var linkField = 'shoesLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms2').each(function(pe) {pe.hide();});
						$$('.ms4').each(function(pe) {pe.hide();});
						$$('.ms3').each(function(pe) {pe.hide();});
						$$('.ms79').each(function(pe) {pe.hide();});
						$$('.ms14').each(function(pe) {pe.hide();});
						evt.stop();
					});

					$('accLink').observe('click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzAcc';
						var linkField = 'accLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms2').each(function(pe) {pe.hide();});
						$$('.ms4').each(function(pe) {pe.hide();});
						$$('.ms3').each(function(pe) {pe.hide();});
						$$('.ms1210').each(function(pe) {pe.hide();});
						$$('.ms14').each(function(pe) {pe.hide();});
						evt.stop();
					});

					$('bbLink').observe('click', function(evt){
						ArtikelMerklistePopup.showAll(evt);
						var anzField = 'anzBB';
						var linkField = 'bbLink';
						ArtikelMerklistePopup.checkOnlyOne(evt,anzField,linkField);

						$$('.ms2').each(function(pe) {pe.hide();});
						$$('.ms4').each(function(pe) {pe.hide();});
						$$('.ms3').each(function(pe) {pe.hide();});
						$$('.ms79').each(function(pe) {pe.hide();});
						$$('.ms1210').each(function(pe) {pe.hide();});
						evt.stop();
					});

					// Event Löschen des Artikels von der Merkliste
					$$('a.entferne_von_merkliste_link').each(function(pe) {
						Event.observe(pe, 'click', function(evt){
							new Ajax.Request(
								pe.getAttribute('href')+'&ajax=true',
								{
									onComplete: function(transport) {
										currentCount = pe.getAttribute('href').match(/currentCount=([0-9]+)/)[1];
										$$('.produkt_'+currentCount).each(function(pe){pe.remove()});
										currentDivision = pe.getAttribute('href').match(/div=([0-9]+)/)[1];

										if(currentDivision==2){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzWomen').innerHTML = $('anzWomen').innerHTML - 1;
											var anzField = 'anzWomen';
											var linkField = 'womenLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}
										if(currentDivision==3){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzMen').innerHTML = $('anzMen').innerHTML - 1;
											var anzField = 'anzMen';
											var linkField = 'menLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}
										if(currentDivision==4){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzKids').innerHTML = $('anzKids').innerHTML - 1;
											var anzField = 'anzKids';
											var linkField = 'kidsLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}
										if(currentDivision==1210){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzShoes').innerHTML = $('anzShoes').innerHTML - 1;
											var anzField = 'anzShoes';
											var linkField = 'shoesLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}
										if(currentDivision==79){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzAcc').innerHTML = $('anzAcc').innerHTML - 1;
											var anzField = 'anzAcc';
											var linkField = 'accLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}
										if(currentDivision==14){
											$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
											$('anzBB').innerHTML = $('anzBB').innerHTML - 1;
											var anzField = 'anzBB';
											var linkField = 'bbLink';
											ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
										}

									}
								}
							);
							$('produktAnz').innerHTML = $('produktAnz').innerHTML - 1;
							evt.stop();

						});
					});

					//Event Neuberechnung Mengendropdown
					$$('select.groessenSelect').each(function(pe){
						Event.observe(pe,'change',function(evt){

							var groessenSelect = Event.element(evt);
							var mengenSelect = $('anzahl_'+groessenSelect.id.match(/groesse_([0-9])+/)[1]);
							var currentEan = groessenSelect.value;
							var maxAnzahl = $(currentEan).value;

							maxAnzahl = (maxAnzahl > 3 ? 3 : maxAnzahl);
							mengenSelect.innerHTML = '';

							for(var i=maxAnzahl;i>=1;i--){
								mengenSelect.insert({bottom:'<option value="'+i+'">'+i+'</option>'});
							}
							evt.stop();
						});

					});

					// Hinzufügen des Artikels zum Warenkorb; entfernen des Artikels aus Merkliste
					$$('img.inKorb').each(function(pe) {
						Event.observe(pe, 'click', function(evt){

							var inKorb = Event.element(evt);
							var currentCount = inKorb.id.match(/inKorb_([0-9]+)/)[1];
							var mengenSelect = $('anzahl_'+currentCount).value;
							var currentEan = $('groesse_'+currentCount).value;

							new Ajax.Request('/?view=crossellingajax',{
								method:'get',
								parameters:{
									s:rahmenGlobal.SID,
									method:'bestellen',
									bestellen:currentEan+';'+mengenSelect,
									tt_ic:'17'
								},
								onSuccess: function(transport){
									$('HeadContainer').innerHTML = transport.responseText;

									$('feedback_inKorb').style.display = 'block';
									$('f_bild').innerHTML = $('produktBild_'+currentCount).innerHTML;
									$('f_info_anr').innerHTML = $('pi_anr_'+currentCount).innerHTML;
									$('f_info_bez').innerHTML = $('pi_zumP_link_'+currentCount).innerHTML;

									$('f_info_g').innerHTML = "&nbsp;"+$('groesse_'+currentCount).options[$('groesse_'+currentCount).selectedIndex].text;
									$('f_info_m').innerHTML = "&nbsp;"+$('anzahl_'+currentCount).options[$('anzahl_'+currentCount).selectedIndex].text;

									setTimeout("$('feedback_inKorb').style.display = 'none'", 2000);

									$$('.merkzettelOeffnenLink').each(function(pe){
										Event.observe(pe,'click',ArtikelMerklistePopup.activate);
									});

									new Ajax.Request(
										$('entferne_von_merkliste_link_'+currentCount).readAttribute('href')+'&ajax=true',
										{
											onComplete: function(transport) {
												$$('.produkt_'+currentCount).each(function(pe){pe.remove()});
											}
										}
									);

									currentDivision = $('entferne_von_merkliste_link_'+currentCount).readAttribute('href').match(/div=([0-9]+)/)[1];
									if(currentDivision==2){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzWomen').innerHTML = $('anzWomen').innerHTML - 1;
										if($('womenLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzWomen').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzWomen';
										var linkField = 'womenLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									if(currentDivision==3){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzMen').innerHTML = $('anzMen').innerHTML - 1;
										if($('menLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzMen').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzMen';
										var linkField = 'menLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									if(currentDivision==4){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzKids').innerHTML = $('anzKids').innerHTML - 1;
										if($('kidsLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzKids').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzKids';
										var linkField = 'kidsLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									if(currentDivision==1210){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzShoes').innerHTML = $('anzShoes').innerHTML - 1;
										if($('shoesLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzShoes').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzShoes';
										var linkField = 'shoesLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									if(currentDivision==79){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzAcc').innerHTML = $('anzAcc').innerHTML - 1;
										if($('accLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzAcc').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzAcc';
										var linkField = 'accLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									if(currentDivision==14){
										$('anzAll').innerHTML = $('anzAll').innerHTML - 1;
										$('anzBB').innerHTML = $('anzBB').innerHTML - 1;
										if($('bbLink').style.fontWeight == 'bold'){
											$('produktAnz').innerHTML = $('anzBB').innerHTML;
										}else{
											$('produktAnz').innerHTML = $('anzAll').innerHTML;
										}
										var anzField = 'anzBB';
										var linkField = 'bbLink';
										ArtikelMerklistePopup.checkOnlyOneOnDelete(anzField,linkField);
									}
									//$('produktAnz').innerHTML = $('produktAnz').innerHTML - 1;

								}
							});

							//evt.stop();
    					});

					});
				}

				ArtikelMerklistePopup.active = true;


			}
		});

	},

	applyHandler: function(evt) {

	},

	shutdown: function(evt) {

		if( LightboxOverlay.isActive() == true ) {

			LightboxOverlay.deactivate();

		}
		if( ArtikelMerklistePopup.isActive() == true ) {

			ArtikelMerklistePopup.elm['merklistePopupContainer'].remove();

			ArtikelMerklistePopup.active = false;

		}

		if( evt != null ) {
			Event.stop(evt);
		}

	},

	showAll: function(evt){
		$$('.ms2').each(function(pe) {pe.show();});
		$$('.ms3').each(function(pe) {pe.show();});
		$$('.ms4').each(function(pe) {pe.show();});
		$$('.ms1210').each(function(pe) {pe.show();});
		$$('.ms79').each(function(pe) {pe.show();});
		$$('.ms14').each(function(pe) {pe.show();});
		$('womenLink').style.fontWeight = 'normal';
		$('menLink').style.fontWeight = 'normal';
		$('kidsLink').style.fontWeight = 'normal';
		$('shoesLink').style.fontWeight = 'normal';
		$('accLink').style.fontWeight = 'normal';
		$('bbLink').style.fontWeight = 'normal';
		if($('produktAnz').innerHTML == '0'){
			$('keinArtikelText').style.display = 'block';
		}

		if($('anzAll').innerHTML == 1){
			$('moreProducts').style.display = 'none';
			$('produktAnz').style.display = 'none';
			$('onlyOneProduct').style.display = '';
		}else{
			$('moreProducts').style.display = '';
			$('produktAnz').style.display = '';
			$('onlyOneProduct').style.display = 'none';
		}
		if($('anzAll').innerHTML == 0){
			$('produktAnz').innerHTML = $('anzAll').innerHTML;
			$('ProductHead').style.display = 'none';
			$('noProductHead').style.display = 'block';
		}
	},

	checkOnlyOne: function(evt,anzField,linkField){
		$(linkField).style.fontWeight = 'bold';
		$('produktAnz').innerHTML = $(anzField).innerHTML;

		if($(anzField).innerHTML == 1){
			$('moreProducts').style.display = 'none';
			$('produktAnz').style.display = 'none';
			$('onlyOneProduct').style.display = '';
		}
		if($(anzField).innerHTML == 0){
			$(linkField).style.display = 'none';
			$('produktAnz').innerHTML = $('anzAll').innerHTML;

			if($('anzAll').innerHTML == 0){
				$('ProductHead').style.display = 'none';
				$('noProductHead').style.display = 'block';
			}
		}
	},

	checkOnlyOneOnDelete: function(anzField,linkField){
		if($(anzField).innerHTML < 2){
			if($(anzField).innerHTML == 1){
				$('moreProducts').style.display = 'none';
				$('produktAnz').style.display = 'none';
				$('onlyOneProduct').style.display = '';
			}
			if($(anzField).innerHTML == 0){
				$(linkField).style.display = 'none';
				$('produktAnz').innerHTML = $('anzAll').innerHTML;

				if($('anzAll').innerHTML == 0){
					$('ProductHead').style.display = 'none';
					$('noProductHead').style.display = 'block';
				}
				ArtikelMerklistePopup.showAll();
			}
		}
	}


}

Event.observe(window,'load',function() {

	$$('a.merkzettelOeffnenLink').each(function(pe){
		Event.observe(pe,'click',ArtikelMerklistePopup.activate);
	});

	// Event Löschen des Artikels von der Merkliste
	$$('a.von_merkliste_productsite').each(function(pe) {
		Event.observe(pe, 'click', function(evt){
			new Ajax.Request(
				pe.getAttribute('href')+'&ajax=true',
				{
					onComplete: function(transport) {
						$('von_merkliste_link').style.display = 'none';
						$('merklisteContainer').style.display = 'none';
						$('zur_merkliste_link').style.display = 'block';
					}
				}
			);

			evt.stop();

		});
	});

	// Hinzufügen des Artikels zur Merkliste; ausgabe kleines POPUP mit info und link zur Merkliste
	$$('a.zur_merkliste_productsite').each(function(pe) {
		Event.observe(pe, 'click', function(evt){

			if( AjaxLogin.isActive() == false ) {

				new Ajax.Request(
					pe.getAttribute('href')+'&ajax=true',
					{
						onComplete: function(transport) {
						var CurrentEan = pe.getAttribute('href').match(/ean=([0-9]+)/)[1];
						$('von_merkliste_link').style.display = 'block';
						$('zur_merkliste_link').style.display = 'none';

						new Ajax.Request('/?view=produkt_merkliste',{
							method:'get',
							parameters:{
								s:rahmenGlobal.SID,
								ean:CurrentEan
							},
							onSuccess: function(transport){
								$('merklisteContainer').style.display = "block";
								$('merklisteContainer').innerHTML = transport.responseText;

								$$('.merkzettelOeffnenLink').each(function(pe){
									Event.observe(pe,'click',ArtikelMerklistePopup.activate);
								});

								$$('a.schliessenButton').each(function(pe) {
									Event.observe(pe, 'click', function(evt){
										$('merklisteContainer').style.display = 'none';
										evt.stop();
									});
								});
							}
						});

						}
					}
				);
				evt.stop();

			}else{
				$('zur_merkliste_link').style.display = 'block';
			}

		});
	});

});

/*
function openOverlay(url) {
	new Ajax.Request(url,{
			method: 'get',
			onSuccess: function (t, json){
				$('BodyOverlayContainer').innerHTML = t.responseText;
				$('BodyOverlayBackground').style.display='none';
				$('BodyOverlayBackground').style.backgroundColor='#999';
				$('BodyOverlayBackground').style.zIndex='99998';
				$('merklisteContainerBorder').style.zIndex='99999';
				$('BodyOverlayBackground').style.height=$$('body')[0].getHeight()+24+'px';
				//$('BodyOverlayBackground').appear({to:0.6});
				$('merklisteContainer').appear();

			}
		});
}

function closeOverlay() {
	new Effect.Morph('merklisteContainerBorder', {
	  style: 'height:0px;',
	  duration: 0.8 // Core Effect properties
	});
	$('BodyOverlayBackground').fade({duration:0.8});
	window.setTimeout(function(){$('BodyOverlayContainer').innerHTML='';$('BodyOverlayContainer').height='0px';},0.8);
}

function clickOnMerkliste(event){
	var Elmt = $('zur_merkliste_link');

	var url = Elmt.href.replace("?","?ajax=true&");
	var merklisteLink = Elmt.getAttribute('merklistelink');

	if( Elmt.getAttribute('li') == 'nli' ) {
		openOverlay(merklisteLink);
	} else {
		Elmt.style.display="none";

		$('merkliste_container').style.backgroundImage='url("/bilder/loader_20x20.gif")';
		$('merkliste_container').style.backgroundRepeat='no-repeat';

		new Ajax.Request(url,{
				method:'get',
				onSuccess: function(transport) {
					$('merkliste_container').style.backgroundImage='none';
					$('merkliste_container').update('<div>Dieser Artikel wurde zu Ihrer <a href="'+merklisteLink+'" id="merkliste_link">Merkliste</a> hinzugefÃ¼gt</div>');
					setMerklisteLinkObserver();
				}
			});
	}
	if( event != null )	{
		event.stop();
			return false;
	}

}

function setMerklisteLinkObserver(){
	if( $('merkliste_link') != null )
	{
		Event.stopObserving($('merkliste_link'));
		Event.observe($('merkliste_link'),'click',function(event){

			var Elmt = event.element();

			var url = Elmt.href.replace("?","?ajax=true&");

			openOverlay(url);
			event.stop();
			return false;
		});
	}
}


function setMerklisteObserver() {

	if( $('zur_merkliste_link') != null )
	{
		Event.observe($('zur_merkliste_link'),'click',clickOnMerkliste);
	}

	$('BodyOverlayContainer').observe('overlay:close',function(event){
		if( event.memo == '1' )	{
			$('zur_merkliste_link').setAttribute('li','li');
			new Ajax.Request('/index.php?view=crossellingajax',{
				method:'get',
				parameters:{
					s:produktGlobal.SID,
					method:'bestellen',
					bestellen:'404213445214,1'
				},
				onSuccess: function(transport){
					$('HeadContainer').innerHTML = transport.responseText;
				}
			  });
		}

		closeOverlay();
		clickOnMerkliste(null);
	});

}
var ean = 0;
function getAnzahl(Elmt) {

	//var Elmt = event.element();

	var artikelid = Elmt.getAttribute('artikelid');
	var farbnummer = Elmt.getAttribute('farbnummer');
	var groesse = Elmt.value;
	ean = Elmt.getAttribute('ean');
	var url = '/index.php?view=mein_konto_merkliste_ajax&query=getAnzahl&'+'&artikelid='+artikelid+'&farbnummer='+farbnummer+'&groesse='+groesse+'&'+produktGlobal.SID;

	new Ajax.Request(url,{
		method:'get',
		onSuccess: function(transport) {
			var options = '<select id="Anzahl_'+ean+'" class="mlAnzahlSelect" name="anzahl">';
			var disable = false;
			if( parseInt(transport.responseText) != 0 ) {
				for(var i=1; i <= parseInt(transport.responseText); i++) {
					options = options+'<option value="'+i+'">'+i+'</option>';
				}
			} else {
				options = options+'<option value="-">-</option>';
				disable = true;
			}
			options = options + '</select>';

			$('AnzahlContainer_'+ean).update(options);

			if( disable ) {
				$('Submit_'+ean).disabled = true;
				$('Anzahl_'+ean).disabled = true;
			} else {
				$('Submit_'+ean).disabled = false;
			}
		}
	});

}

function changeSize(Elmt){

	produktGlobal.currentElmt = Elmt;

	var artikelid = Elmt.getAttribute('artikelid');
	var farbnummer = Elmt.getAttribute('farbnummer');
	var neue_groesse = Elmt.value;
	var alte_groesse = Elmt.getAttribute('groesse');

	var update = true;

	if( $$('tr[SKU="'+[artikelid,farbnummer,neue_groesse].join("_")+'"]').size() > 0 ) {

		if( confirm('Diese GrÃ¶sse ist bereits in Ihrer Merkliste vorhanden, soll der doppelte Eintrag gelÃ¶scht werden?') ) {
			entfernen(Elmt);
		}
		update = false;
	}

	if( update ) {
		var ean = Elmt.getAttribute('ean');

		$('Submit_'+ean).disabled = "disabled";
		$('Anzahl_'+ean).disabled = "disabled";

		var url = '/index.php?action=update_merkliste&'+'&artikelid='+artikelid+'&farbnummer='+farbnummer+'&alte_groesse='+alte_groesse+'&neue_groesse='+neue_groesse+'&'+produktGlobal.SID;

		Elmt.groesse = neue_groesse;

		new Ajax.Request(url,{
			method:'get',
			onSuccess: function(transport) {
				getAnzahl(produktGlobal.currentElmt);
				produktGlobal.currentElmt = { };
			}
		});
	}
	else
	{
		Elmt.value = Elmt.getAttribute('groesse');
	}
}

function bestellen(Elmt) {

	ean = Elmt.getAttribute('ean');
	anzahl = $('Anzahl_'+ean).value;

	new Ajax.Request('/index.php?' + produktGlobal.SID,{
		method:'get',
		parameters:{
			view:'crossellingajax',
			method:'bestellen',
			bestellen:ean+';'+anzahl,
			wk_popup: true
		},
		onSuccess: function(transport){
			$('HeadContainer').innerHTML = transport.responseText;
			$('wk_image').src='/bilder/produktbilderIM/b/'+transport.headerJSON.uuid+'.jpg';
			$('wk_image').width=transport.headerJSON.width;
			$('wk_image').height=transport.headerJSON.height;
			$('wk_image').src='/bilder/produktbilderIM/b/'+transport.headerJSON.uuid+'.jpg';
			$('wk_produktname').innerHTML = $('Row_'+ean).select('a.produktname')[0].innerHTML;
			$('wk_artikelnummer').innerHTML = transport.headerJSON.artikelnummer;
			$('wk_groesse').innerHTML = transport.headerJSON.groesse;
			$('wk_menge').innerHTML = anzahl;
			$('wk_summe').innerHTML = transport.headerJSON.summe.replace(".",",");
			$('wk_artikelanzahl').innerHTML = $('HWarenkorbArtikel').innerHTML.replace(/[^0-9]/gi,"");
			$('wk_warenkorbwert').innerHTML = $('HWarenkorbPreis').innerHTML.replace(/[^0-9,]/gi,"");
			play_wkpopup();
		}
	  });
}

function entfernen(Elmt) {

	ean = Elmt.getAttribute('ean');

	var artikelid = Elmt.getAttribute('artikelid');
	var farbnummer = Elmt.getAttribute('farbnummer');
	var groesse = Elmt.getAttribute('groesse');

	new Ajax.Request('/index.php?' + produktGlobal.SID,{
		method:'get',
		parameters:{
			action:'entferne_von_merkliste',
			artikelid:artikelid,
			farbnummer:farbnummer,
			groesse:groesse,
			ajax:'true'
		},
		onSuccess: function(transport){
			$('Row_'+ean).remove();
		}
	  });
}



Event.observe(window,'load',setMerklisteObserver);
Event.observe(window,'load',setMerklisteLinkObserver);

*/
