/*
Shop - range of functions for shop module only

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!DO NOT CHANGE THIS FILE!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


* functionality on startup
* fn max()			- checks if articles in stock are more than requested articles
* fn inWarenKorb()	- tooks article in the cart (ajax!)
* fn sendChange()	- refresh cart (ajax!)
* fn loginWK()		- authorisize user for order

*/


$(document).ready(function(){
	//wenn Artikel nicht lieferbar, dann Fehlermeldung beim Klick auf den BestellButton anzeigen
	$('.inaktiv img').attr("title","Niedostepne");
	$('.inaktiv').click(function(){alert("Ten produkt nie jest dost\u0119pny w tej chwili!"); return false;});
});

function max(lager,ele){
	anz=ele.value;	
	
	if(anz>lager){
		alert("Nie mo\u017Cna zam\u00F3wi\u0107 tak du\u017Cej liczby produkt\u00F3w!");
		ele.value=lager;
		return false;
	}
}

function inWarenKorb(id, sid, ele){
	$('body').append('<div id="bb"></div><div id="info">Aktualizacja koszyka</div>');
	$('#bb').fadeTo(400, '0.5');
	$('#info').fadeIn(500);
	anz=1;
		
	url=DBName + "/(indenKorb)?OpenAgent";
	txt= "&" + sid + "&" + id + "&" + anz;
	
	$.ajax({
		url: url + txt,
  		cache: false,
  		processData: false,
  		  	
  		success: function(html){
  			wert=html.split("$$");
  			$("#WKBetrag").html(wert[1] + " \u20AC");
  			$("#Warenkorb").html(wert[0]);
  			$("#bb, #info").delay(1200).fadeOut(300, function(){$("#bb,#info").remove();})
  	}})

}

function sendChange(id,wert, sid){

	if(wert==0) {
	url=DBName + "/(changeKorb)?OpenAgent";
	txt= "&" + sid + "&" + id + "&" + wert;
		
	$.ajax({
		url: url + txt,
  		cache: false,
  		processData: false,
  		  	
  		success: function(html){
  		
  			$("#" + id).remove();
  			$("#gesamtPreis").html(html);
  			if(html=="")
  				$(".weiter").css("display","none")
  		
  	}})
  	}else{
  	
  	anz=wert;
	
	if(anz=="") {
		alert("Bitte geben Sie erst die Menge an!");
		return false;
	}else{
		if(isNaN(anz)){
			alert("Bitte geben Sie nur Zahlen ein!");
			return false;
		}
	}
	
  	url=DBName + "/(changeKorb)?OpenAgent";
	txt= "&" + sid + "&" + id + "&" + anz;
	
	$.ajax({
		url: url + txt,
  		cache: false,
  		processData: false,
  		  	
  		success: function(html){
  			wert=html.split("$$");
  			$(".WKorb_Artikel").children("tbody").html(wert[0]);
  			$("#gesamtPreis").html(wert[1]);
  		
  	}})
  	}
  	
}

function loginWK(){
			url="http://www.ito-consult.de/names.nsf?login";
			txt= "&username=" + $("#LoginNameShop").val() + "&password=" + $("#LoginPWShop").val()
		
			$.ajax({
			url: url + txt,
  			cache: false,
  			processData: false,
  		  	
  		 	success: function(html){
  		  		if(html.search(/names.nsf/)== -1){
  					location.reload();
  				}else{
  					$("#LoginNameShop").val("");
  					$("#LoginPWShop").val("");
  					$('#Login_Fehler').slideDown(300);
  				}
  			}
  			});
}

function WarenKorb(){}
