
function init(){$('loading').hide()
if(document.getElementById('cartdiv')){
	new Ajax.Request(homeurl+'ajax/cart.php?show=1',{
		method:'get',
		requestHeaders:{Accept:'application/json'},
		onSuccess:function(nom,json){
			if(json.length==0){
				$('cartdiv').innerHTML='<div class="Cart">'+lgInit_1+'</div>';
				$('searchAq').innerHTML='<input type="checkbox" name="sS" id="sS" value="" style="visibility: hidden;"/>&nbsp;';
			}else{
				output="";
				var seller="";
				var used="";
				var itemCnt=0;
				var minHeight=500;
				var searchSeller="";
				for(var i=0;i<json.length;i++){
					if(seller!=json[i].aqId||used!=json[i].used){
						output+='<div style="border-bottom: 2px #000000 solid; padding: 2px; font-size: 14px; margin-bottom: 2px;">';
						switch (json[i].warengruppe) {
							case "1":	if(json[i].used==1){
										searchSeller+=json[i].aqId+'.';
										output+='<img src="'+homeurl+'gfx/bookUsed.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgInit_2+'" title="'+lgInit_2+'" />'
									}else{
										output+='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgInit_3+'" title="'+lgInit_3+'" />'
									}
									break;
							case "2": output+='<img src="'+homeurl+'gfx/weine.gif" width="17px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgInit_3+'" title="'+lgInit_3+'" />';
									break;
						}
						
						if(json[i].used==1){
							output+='<a href="'+homeurl+'aq/'+json[i].aqId+'/'+json[i].sellerName+'" class="sellerLink">'+json[i].sellerName+'</a>';
						}else{
							output+=json[i].sellerName;
						}
						output+='</div>';
					}
					output+='<div id="'+json[i].buchId+'" class="cartEntry"';
					if(i<(json.length-1)){
						output+=' style="border-bottom: 1px dashed #990000; margin-bottom: 10px;"';
					}
					output+='>';
					output+='<span style="float: right; top: 0; margin-left: 3px;">[<a href="#" alt="'+lgInit_4+'" title="'+lgInit_4+'" class="cartOut" onclick="removeCart('+json[i].buchId+','+json[i].used2+')">x</a>]</span>';
					switch (json[i].warengruppe) {
						case "1": 	output+='<a href="'+homeurl+'productListing.php?used='+json[i].used2+'&productId='+json[i].buchId+'" class="productLink">'+json[i].orderNo+':</a> ';
									break;
						case "2":	output+='<a href="'+homeurl+'wein.php?weinId='+json[i].buchId+'" class="productLink">'+json[i].orderNo+':</a> ';
									break;
						case "3":	output+='<a href="'+homeurl+'spiel.php?spielId'+json[i].buchId+'" class="productLink">'+json[i].orderNo+':</a> ';
									break;
					}
					if(json[i].author!="")
						output+=json[i].author+' ';
					if(json[i].title!="")
						output+='<b>'+json[i].title+'</b>';
					output+='<br/>'+json[i].quantity+'x = '+formatZahl(json[i].quantity*json[i].price,2,true)+' '+json[i].currency;
					output+='</div>';
					seller=json[i].aqId;
					used=json[i].used
					minHeight+=100;
				}
				output+='<div align="center" style="height: 25px"><input type="image" src="'+homeurl+'gfx/goToCheckout'+buttonset+lgSuffix+'.gif" name="goCheckout" onclick="javascript:self.location.href=\''+homeurl+'checkout0.html\'" /></div>';
				if($('searchAq')){
					if(searchSeller!=""){
						$('searchAq').innerHTML='<input type="checkbox" name="sS" id="sS" value="'+searchSeller+'" /> '+lgInit_5;
					}else{
						$('searchAq').innerHTML='<input type="checkbox" name="sS" id="sS" value="" style="visibility: hidden;"/>&nbsp;';
					}
				}
				$('cartdiv').innerHTML=output;
				new Effect.Highlight(document.getElementById("cartdiv"),{
					startcolor:'#DCDCDC',endcolor:'#F8BD7B',restorecolor:'#F8BD7B'}
				);
			}
		},
		onFailure:function(){alert('Fehler bei Ajax Request')}
	})
}}

function resizeImage(name,newHeight){eval("document."+name+".height=newHeight")}
function addToCart(element){$('loading').show();new Ajax.Request(homeurl+'ajax/cart.php?add=1',{method:'get',parameters:Form.serialize($('input'+element.id)),onSuccess:function(nom,json){init();},onFailure:function(){alert('Fehler bei Ajax Request')}})
$('loading').hide();}
function removeCart(buchId,used){$('loading').show();new Ajax.Request(homeurl+'ajax/cart.php?remove=1&buchId='+buchId+'&used='+used,{method:'get',onSuccess:function(nom,json){init();},onFailure:function(){alert('Fehler bei Ajax Request')}})
$('loading').hide();}
var SIs
var SItxt
var inputID="q"
var maxcount=5
var newdiv=document.createElement("DIV")
if(document.attachEvent)
document.attachEvent("onclick",hideSelect)
if(document.captureEvents){document.captureEvents(Event.CLICK);document.onclick=hideSelect;}
function hideSelect(){newdiv.style.display="none"}
function updateSuggestNew(query,cnt){new Ajax.Request(homeurl+'ajax/updateDb.php?suggest=1&q='+escape(query)+'&cnt='+cnt,{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){return true;},onFailure:function(){alert('Fehler bei Ajax Request')}})}
function queryBuchfreund(){return true;}
function queryNeubuch(str){$('loaderNeubuch').show();var newCnt=0;var reg='';url=location.search;query=url.replace(/\?/,"");query=query.replace(/&page=\d*/,"");query=query.replace(/&x=\d*/,"");query=query.replace(/&y=\d*/,"");query=query.replace(/&used=\d*/,"");query=query.replace(/used=\d*/,"");query=query.replace(/&auctions=\d*/,"");query=query.replace(/auctions=\d*/,"");if(query==""){url=location.href;url=url.replace(/http:\/\/www.buchfreund.de\//,"");query="q="+url.replace(/tag\//,"");query=query.replace(/\/$/,"");}
if(str!=""){new Ajax.Request(homeurl+'ajax/searchNeubuch.php?q='+str+'&cnt=1',{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){newCnt=json[0].quantity;if(newCnt==0){$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuch_1+'" title="'+lgQueryNeubuch_1+'" /> '+lgQueryNeubuch_2+' (0)';}else{$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuch_1+'" title="'+lgQueryNeubuch_1+'" /> <a href="'+homeurl+'results.php?'+query+'&used=0" class="flag">'+lgQueryNeubuch_2+' ('+json[0].quantity+')</a>';}
$('loaderNeubuch').hide();updateSuggestNew(str,newCnt);},onFailure:function(){alert('Fehler bei Ajax Request')}});}else{$('loaderNeubuch').hide();$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuch_1+'" title="'+lgQueryNeubuch_1+'" /> '+lgQueryNeubuch_2+' (0)';}}
function queryNeubuchDetail(){$('loaderNeubuch').show();var newCnt=0;	var reg='';url = location.search;query = url.replace(/\?/,"");query = query.replace(/&page=\d*/,"");query=query.replace(/&used=\d*/,"");query=query.replace(/used=\d*/,"");query = query.replace(/&x=\d*/,"");query = query.replace(/&y=\d*/,"");new Ajax.Request(homeurl+'ajax/searchNeubuch.php?detail=1',{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){newCnt=json[0].quantity;if(newCnt==0){$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuch_1+'" title="'+lgQueryNeubuch_1+'" /> '+lgQueryNeubuch_2+' (0)';}else{$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuch_1+'" title="'+lgQueryNeubuch_1+'" /> <a href="'+homeurl+'results.php?' + query + '&used=0" class="flag">'+lgQueryNeubuch_2+' ('+json[0].quantity+')</a>';}
$('loaderNeubuch').hide();},onFailure:function(){alert('Fehler bei Ajax Request')}});}
function queryNeubuchAuthor(str){$('loaderNeubuch').show();var newCnt=0;var reg='';url=location.search;url=url.replace(/\?/,"");url=url.replace(/&page=\d*/,"");url=url.replace(/&x=\d*/,"");url=url.replace(/&y=\d*/,"");url=url.replace(/&used=\d*/,"");url=url.replace(/used=\d*/,"");url=url.replace(/&auctions=\d*/,"");url=url.replace(/auctions=\d*/,"");if(str!=""){new Ajax.Request(homeurl+'ajax/searchNeubuchAuthor.php?authorId='+str+'&cnt=1',{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){newCnt=json[0].quantity;if(newCnt==0){$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuchAuthor_1+'" title="'+lgQueryNeubuchAuthor_1+'" /> neu (0)';}else{$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuchAuthor_1+'" title="'+lgQueryNeubuchAuthor_1+'" /> <a href="'+homeurl+'resultsAuthor.php?authorId='+str+'&used=0" class="flag">'+lgQueryNeubuchAuthor_2+' ('+json[0].quantity+')</a>';}
$('loaderNeubuch').hide();},onFailure:function(){alert('Fehler bei Ajax Request')}});}else{$('loaderNeubuch').hide();$('neubuchResults').innerHTML='<img src="'+homeurl+'gfx/bookNew.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryNeubuchAuthor_1+'" title="'+lgQueryNeubuchAuthor_1+'" /> '+lgQueryNeubuchAuthor_2+' (0)';}}
function queryAuctions(str){$('loaderAuctions').show();var aucCnt=0;var reg='';url=location.search;query=url.replace(/\?/,"");query=query.replace(/&page=\d*/,"");query=query.replace(/&x=\d*/,"");query=query.replace(/&y=\d*/,"");query=query.replace(/&used=\d*/,"");query=query.replace(/used=\d*/,"");query=query.replace(/&auctions=\d*/,"");query=query.replace(/auctions=\d*/,"");if(query==""){url=location.href;url=url.replace(/http:\/\/www.buchfreund.de\//,"");query="q="+url.replace(/tag\//,"");query=query.replace(/\/$/,"");}
if(str!=""){new Ajax.Request(homeurl+'ajax/searchAuktionen.php?q='+str+'&cnt=1',{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){newCnt=json[0].quantity;if(newCnt==0){$('auctionsResults').innerHTML='<img src="'+homeurl+'gfx/auctions.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryAuctions_1+'" title="'+lgQueryAuctions_1+'" /> '+lgQueryAuctions_1+' (0) <a href="'+homeurl+'auktionshaeuser/" class="flag">'+lgQueryAuctions_2+'</a>';}else{$('auctionsResults').innerHTML='<img src="'+homeurl+'gfx/auctions.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryAuctions_1+'" title="'+lgQueryAuctions_1+'" /> <a href="'+homeurl+'results.php?'+query+'&auctions=1" class="flag">'+lgQueryAuctions_1+' ('+json[0].quantity+')</a>';}
$('loaderAuctions').hide();},onFailure:function(){alert('Fehler bei Ajax Request')}});}else{$('loaderAuctions').hide();$('auctionsResults').innerHTML='<img src="'+homeurl+'gfx/auctions.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryAuctions_1+'" title="'+lgQueryAuctions_1+'" /> '+lgQueryAuctions_1+' (0)';}}
function queryAuctionsDetail(){$('loaderAuctions').show();var aucCnt=0;var reg='';$('loaderAuctions').hide();$('auctionsResults').innerHTML='<img src="'+homeurl+'gfx/auctions.gif" width="23px" height="21px" style="float: left; margin-right: 3px;" alt="'+lgQueryAuctions_1+'" title="'+lgQueryAuctions_1+'" /> '+lgQueryAuctions_1+' (0)';}
function ckLogin(ck){if(ck.checked){document.getElementById('addLogin').style.display='block';}else{document.getElementById('addLogin').style.display='none';}}
function checkUserName(){var str=escape($('cuLogin').value);if(str!=""){new Ajax.Request(homeurl+'ajax/checkUser.php?uN='+str,{method:'get',requestHeaders:{Accept:'application/json'},onSuccess:function(nom,json){if(json==true){$('userFlag').innerHTML='<img src="'+homeurl+'gfx/available.gif" width="20" height="19" alt="'+lgCheckUserName_1+'" title="'+lgCheckUserName_1+'" />';}else{$('userFlag').innerHTML='<img src="'+homeurl+'gfx/notAvailable.gif" width="20" height="18" alt="'+lgCheckUserName_2+'" title="'+lgCheckUserName_2+'" />';}},onFailure:function(){$('userFlag').innerHTML='';}})}else{$('userFlag').innerHTML='';}}
function toggle_visibility(id){var e=document.getElementById(id);if(e.style.display=='block')
e.style.display='none';else
e.style.display='block';}
function updateLoginForm(){switch($('loginArea').value){case"Kunde":$('loginLabel').innerHTML='<b>Benutzername: </b>';$('button').value='Kunden-Login';break;case"Antiquariat":$('loginLabel').innerHTML='<b>Kundennummer: </b>';$('button').value='Antiquariats-Login';break;case"Neubuchhändler":$('loginLabel').innerHTML='<b>Kundennummer: </b>';$('button').value='Neubuchhändler-Login';break;default:$('loginLabel').innerHTML='<b>Benutzername: </b>';$('button').value='Kunden-Login';}}
function formatZahl(zahl,k,fix){if(!k)k=0;var neu='';var f=Math.pow(10,k);zahl=''+parseInt(zahl*f+(.5*(zahl>0?1:-1)))/f;var idx=zahl.indexOf('.');if(fix)
{zahl+=(idx==-1?'.':'')
+f.toString().substring(1);}
idx=zahl.indexOf('.');if(idx==-1)idx=zahl.length;else neu=','+zahl.substr(idx+1,k);while(idx>0)
{if(idx-3>0)
neu='.'+zahl.substring(idx-3,idx)+neu;else
neu=zahl.substring(0,idx)+neu;idx-=3;}
return neu;}
function showAntiquar(eventAntiquarian){if(!eventAntiquarian)
eventAntiquarian=window.event;if(document.getElementById){document.getElementById("antiquarBox").style.left=eventAntiquarian.clientX+"px";document.getElementById("antiquarBox").style.top=eventAntiquarian.clientY+"px";}else if(document.all){document.all.antiquarBox.style.left=eventAntiquarian.clientX;document.all.antiquarBox.style.top=eventAntiquarian.clientY;}}
function hideAntiquar(){document.getElementById("antiquarBox").style.left=-5000+"px";document.getElementById("antiquarBox").style.top=-5000+"px";}
var currentAd=0;function lastAd(element){new Ajax.Request(homeurl+'ajax/serveAds.php?previous=1&current='+currentAd,{method:'get',parameters:'',onSuccess:function(nom,json){currentAd=json.id;$('adBox').innerHTML=json.ad;},onFailure:function(){alert('Fehler bei Ajax Request')}})}
function nextAd(element){new Ajax.Request(homeurl+'ajax/serveAds.php?next=1&current='+currentAd,{method:'get',parameters:'',onSuccess:function(nom,json){currentAd=json.id;$('adBox').innerHTML=json.ad;},onFailure:function(){alert('Fehler bei Ajax Request')}})}
