

/********************/
/* Init Kundenlogin */
/********************/

function initLogin(){
	var sReturn = 'OK';
	var sTest_LI = '';
	try {
		sTest_LI = SMShop.getAttribute("UserLogin");
	} catch(e) { };
	if((sTest_LI.length==0) || (sTest_LI=="false")){
		SMShop.setAttribute("UserLogin", "false")
		SMShop.update();
		return('NO_USER');
	};
	sTest_LI = '';
	try {
		sTest_LI = SMShop.getAttribute("UserDiscount");
	} catch(e) { };
	if((sTest_LI.length==0) || (sTest_LI=="false")){
		SMShop.setAttribute("UserDiscount", "false")
		SMShop.update();
		return('NO_DISC');
	};
	return(sReturn);
};

function LogMeInData(sData){
	SMShop.setAttribute("UserLogin", sData);
	SMShop.update();
};

function LogMeInDiscount(sData){
	SMShop.setAttribute("UserDiscount", sData);
	SMShop.update();
};

/************/
/* Ultimate */
/************/

function LogMeInDiscountText(sData){
	SMShop.setAttribute("UserDiscountText", sData);
	SMShop.update();
};

function getUserDiscountText(sType){
	var sData = SMShop.getAttribute("UserDiscountText");
	var oData = sData.split("_X_");
	if(sType=="text") return(oData[0]);
	if(sType=="bool") return((oData[1]=="true" || oData[1]==true)?true:false);
	return("");
};

function SplitDiscounts(){
	var sData = SMShop.getAttribute("UserDiscount");
	var sDataNorm = sDataStff = '';
	var iDataNorm = iDataStff = 0;
	var aData = sData.split("_;_");
	for(var i=0; i<aData.length; i++){
		var aSet = aData[i].split("|");
		var aSetR = aSet[0].split("==");
		if(aSetR[0]=="manufacturer-stff" || aSetR[0]=="category-stff" || aSetR[0]=="product-stff"){
			if(iDataStff==0){
				sDataStff += String(aData[i]);
				iDataStff++;
			} else {
				sDataStff += '_;_';
				sDataStff += String(aData[i]);
			};
		} else {
			if(iDataNorm==0){
				sDataNorm += String(aData[i]);
				iDataNorm++;
			} else {
				sDataNorm += '_;_';
				sDataNorm += String(aData[i]);
			};
		};
	};
	SMShop.setAttribute("UserDiscount",sDataNorm);
	SMShop.setAttribute("StffDiscount",sDataStff);
	SMShop.update();
};

function LogMeInVAT(sData){
	if(sData.length==0){
		sData = SMShop.getAttribute(_SMAOutGross);
		sData = (sData=="1")?"vatincl":"vatexcl";
	};
	SMShop.setAttribute("UserVATtype", sData);
	SMShop.update();
};

function LogMeInPayShip(sData){
	SMShop.setAttribute("UserPayShip", sData);
	SMShop.update();
};

function LIsetVATstatus(){
	var sVAT = SMShop.getAttribute("UserVATtype");
	var iVATincl = 0;
	if(sVAT=="vatincl") iVATincl = 1;
	SMShop.setAttribute(_SMAOutGross, iVATincl);
	SMShop.update();
	SMShop.basket.update();
};

function LIprintVATstatusPDD(){
	var sIncl = 'inkl. MwSt';
	var sExcl = 'zzgl. MwSt';
	var oVATInfo = document.getElementById("VATinfo");
	if(!oVATInfo) return(0);
	if(bOutGross()){
		oVATInfo.innerHTML = sIncl;
	} else {
		oVATInfo.innerHTML = sExcl;
	};
};

function LIprintVATstatusPDL(){
	var sIncl = 'inkl. MwSt';
	var sExcl = 'zzgl. MwSt';
	var sVAT = SMShop.getAttribute("UserVATtype");
	var oElem = document.getElementsByTagName("div");
	var sElem = '';
	var sElem2 = '';
	for(var i=0; i<oElem.length; i++){
		sElem = oElem[i].innerHTML;
		if(sElem.indexOf(sIncl)>-1){
			if(sVAT=="vatexcl"){
				sElem2 = sElem.replace(sIncl,sExcl);
				oElem[i].innerHTML = sElem2;
			};
		};
		if(sElem.indexOf(sExcl)>-1){
			if(sVAT=="vatincl"){
				sElem2 = sElem.replace(sExcl,sIncl);
				oElem[i].innerHTML = sElem2;
			};
		};
	};
};

function LIhidePayMethodList(){
	var oPay = document.getElementById("paymethods");
	oPay.style.display = "none";
	oPay.style.visibility = "hidden";
};

function LIshowPayMethodList(){
	var oPay = document.getElementById("paymethods");
	oPay.style.display = "inline";
	oPay.style.visibility = "visible";
};

function LIhideShipMethodList(){
	var oPay = document.getElementById("shipmethodselector");
	oPay.style.display = "none";
	oPay.style.visibility = "hidden";
};

function LIshowShipMethodList(){
	var oPay = document.getElementById("shipmethodselector");
	oPay.style.display = "inline";
	oPay.style.visibility = "visible";
};

function LIsetPayShipStatus(sType){
	var oPayShip = SMShop.getAttribute("UserPayShip");
	var aPayShip = oPayShip.split("_;_");
	var aPS = new Array();
	var sDIVpay = "SMPAYMETHOD";
	var sDIVship = "shipmethods";
	var oDIVship = '';
	var bShipDefault = false;
	var sDIVid = '';
	var oDIV = null;
	for(var i=0; i<aPayShip.length; i++){
		aPS[i] = aPayShip[i].split("_|_");
		if(aPS[i][0]=="pay" && sType=="pay"){
			sDIVid = sDIVpay + String(aPS[i][1]);
			if(aPS[i][3]=="forbidden"){
				oDIV = document.getElementById(sDIVid);
				oDIV.style.display = "none";
				oDIV.style.visibility = "hidden";
			};
		};
		if(aPS[i][0]=="ship" && sType=="ship"){
			for (var j=0; j < document.forms.length; j++){
				if(document.forms[j].name == sDIVship){
					oDIVship = document.forms[j];
					break;
				};
			};
			for(var j=0; j<oDIVship.elements.length; j++){
				var oElem = oDIVship.elements[j];
  	 		if(oElem.type=="radio" && oElem.id==aPS[i][1]){
  	 			if(aPS[i][3]=="forbidden"){
						oElem.checked = false;
						oElem.disabled = true;
						var oElemParent = oElem.parentNode;
						var oElem2 = oElemParent.nextSibling;
						oElem2.innerHTML = oElem2.innerHTML + "<div><em>Diese Versandart steht Ihnen nicht zur Verfügung.</em></div>";
						oElem2 = oElem2.nextSibling;
						oElem2.innerHTML = "&nbsp;";
						break;
					} else if(!bShipDefault && SMShop.getActiveShipMethodId().length==0){
						oElem.checked = true;
					};
  	 		};
			};
		};
	};
};

function hideProductDiscounts(oProd){
	if(oProd.getAttribute("IndivProdDisc")=="false"){
		var $elem = document.getElementById("product_discounts");
		if($elem){
			$elem.style.display = "none";
			$elem.style.visibility = "hidden";
		};
	};
};

function getSerializedStff(sType){
	var sData = SMShop.getAttribute("StffDiscount");
	if(sData.length==0 || sData=="false"){
		return("none");
	};
	var aData = sData.split("_;_");
	var aMStff = new Array();
	var aCStff = new Array();
	var aPStff = new Array();
	var aSet = new Array();
	var aSetR = new Array();
	var bDouble = false;
	var sResult = '';
	for(var i=0; i<aData.length; i++){
		aSet[i] = aData[i].split("|");
		aSetR[i] = aSet[i][0].split("==");
		if(aSetR[i][0]=="product-stff"){
			if(aPStff.length==0){
				aPStff[aPStff.length] = aSetR[i][1];
			} else {
				for(var j=0; j<aPStff.length; j++){
					if(aPStff[j]==aSetR[i][1]){
						bDouble = true;
						break;
					};
				};
				if(!bDouble){
					aPStff[aPStff.length] = aSetR[i][1];
				} else {
					bDouble = false;
				};
			};
		};
		if(aSetR[i][0]=="category-stff"){
			if(aCStff.length==0){
				aCStff[aCStff.length] = aSetR[i][1];
			} else {
				for(var j=0; j<aCStff.length; j++){
					if(aCStff[j]==aSetR[i][1]){
						bDouble = true;
						break;
					};
				};
				if(!bDouble){
					aCStff[aCStff.length] = aSetR[i][1];
				} else {
					bDouble = false;
				};
			};
		};
		if(aSetR[i][0]=="manufacturer-stff"){
			if(aMStff.length==0){
				aMStff[aMStff.length] = aSetR[i][1];
			} else {
				for(var j=0; j<aMStff.length; j++){
					if(aMStff[j]==aSetR[i][1]){
						bDouble = true;
						break;
					};
				};
				if(!bDouble){
					aMStff[aMStff.length] = aSetR[i][1];
				} else {
					bDouble = false;
				};
			};
		};
	};
	if(sType=="product"){
		if(aPStff.length==0) return("none");
		for(var i=0; i<aPStff.length; i++){
			if(i>0) sResult += ", ";
			sResult += aPStff[i];
		};
	};
	if(sType=="category"){
		if(aCStff.length==0) return("none");
		for(var i=0; i<aCStff.length; i++){
			if(i>0) sResult += ", ";
			sResult += aCStff[i];
		};
	};
	if(sType=="manufacturer"){
		if(aMStff.length==0) return("none");
		for(var i=0; i<aMStff.length; i++){
			if(i>0) sResult += ", ";
			sResult += aMStff[i];
		};
	};
	return(sResult);
};

function SetProductStff(){
	var $g = SMProductLI;
	if(initLogin()=='NO_USER'){
		hideProductDiscounts($g);
		return(false);
	};
	var sProdManu = RemoveSpecialSigns(SX_uEsc($g.manufactName));
	var sPN1 = RemoveSpecialSigns($g.orgCode);
	var sPN2 = RemoveSpecialSigns($g.getAttribute(_SMACode));
	var sData = SMShop.getAttribute("StffDiscount");
	if(sData.length==0 || sData=="false"){
		hideProductDiscounts($g);
		return(false);
	};
	var aData = sData.split("_;_");
	var aSet = new Array();
	var aSetR = new Array();
	var bProdHasBaseDisc = false;
	var bCatDouble = false;
	var aMStff = new Array();
	var aCStff = new Array();
	var aPStff = new Array();
	var aCat = sProdToParentCats.split("_;_");
	var aCatDisc = new Array();
	for(var i=0; i<aCat.length; i++){
		aCatDisc[i] = aCat[i].split("_=_");
	};
	for(var i=0; i<aData.length; i++){
		aSet[i] = aData[i].split("|");
		aSetR[i] = aSet[i][0].split("==");
	};
	for(var i=0; i<aData.length; i++){
		if(aSetR[i][0]=="product-stff" && (aSetR[i][1]==sPN1 || aSetR[i][1]==sPN2)){
			aPStff[aPStff.length] = aData[i];
			if(aSet[i][2]==1) bProdHasBaseDisc = true;
		};
		if(aSetR[i][0]=="category-stff"){
			if(aCStff.length==0){
				for(var j=0; j<aCat.length; j++){
					for(var k=0; k<aData.length; k++){
						if(aCatDisc[j][0]==aSetR[k][1]){
							aCStff[aCStff.length] = aData[k];
							if(aSet[k][2]==1) bProdHasBaseDisc = true;
							break;
						};
					};
					if(aCStff.length>0) break;
				};
			} else {
				var aCPrior = aCStff[aCStff.length - 1].split("|");
				var sCPrior = aCPrior[0].split("==");
				if(sCPrior[1]==aSetR[i][1]){
					for(var j=0; j<aCStff.length; j++){
						if(aCStff[j]==aData[i]){
							bCatDouble = true;
							break;
						};
					};
					if(bCatDouble){
						bCatDouble = false;
					} else {
						aCStff[aCStff.length] = aData[i];
						if(aSet[i][2]==1) bProdHasBaseDisc = true;
					};
				};
			};
		};
		if(aSetR[i][0]=="manufacturer-stff" && aSetR[i][1]==sProdManu){
			aMStff[aMStff.length] = aData[i];
			if(aSet[i][2]==1) bProdHasBaseDisc = true;
		};
	};
	if(aMStff.length==0 && aCStff.length==0 && aPStff.length==0){
		hideProductDiscounts($g);
		return(false);
	};
	$g.discounts.remove('','','','','');
	$g.discounts.update();
	$g.update();
	var bDiscDone = false;
	if(aPStff.length>0 && !bDiscDone){
		for(var i=0; i<aPStff.length; i++){
			var oStff = aPStff[i].split("|");
			$g.discounts.addForLogin(oStff[2],oStff[3],oStff[4],String(oStff[5]),"false");
		};
		bDiscDone = true;
	};
	if(aCStff.length>0 && !bDiscDone){
		for(var i=0; i<aCStff.length; i++){
			var oStff = aCStff[i].split("|");
			$g.discounts.addForLogin(oStff[2],oStff[3],oStff[4],String(oStff[5]),"false");
			bDiscDone = true;
		};
	};
	if(aMStff.length>0 && !bDiscDone){
		for(var i=0; i<aMStff.length; i++){
			var oStff = aMStff[i].split("|");
			$g.discounts.addForLogin(oStff[2],oStff[3],oStff[4],String(oStff[5]),"false");
		};
		bDiscDone = true;
	};
	if(bProdHasBaseDisc){
		var oElem = document.getElementById("product_original_price");
		if(oElem){
			oElem.style.display = "inline";
			oElem.style.visibility = "visible";
		};
		bDiscDone = true;
	};
	$g.discounts.update();
	$g.setAttribute("HasStff","true");
	$g.update();
	var oProdDiscList = document.getElementById("product_discounts");
	if(oProdDiscList){
		oProdDiscList.style.display = "inline";
		oProdDiscList.style.visibility = "visible";
	};
	displayProductProperties($g);
};

function hideAllProductPrices(){
	if(initLogin()=='NO_USER'){
		//product-detail
		var oElem = document.getElementsByTagName("div");
		var sElem = '';
		for(var i=0; i<oElem.length; i++){
			sElem = oElem[i].id;
			if(sElem.indexOf("pdPrice")>-1){
				document.getElementById(sElem).innerHTML = "";
			};
		};
		var oElem = document.getElementById("product_discounts");
		if(oElem) oElem.innerHTML = "";
		//product-list
		var oElem = document.getElementsByTagName("script");
		var sElem = '';
		for(var i=0; i<oElem.length; i++){
			sElem = oElem[i].innerHTML;
			if(sElem.indexOf("SMProductList")>-1 && sElem.indexOf("t-price-list")>-1){
				var oElemP = oElem[i].parentNode;
				oElemP.style.display = "none";
				oElemP.style.visibility = "hidden";
			};
		};
	};
};

/************/
/* Ultimate */
/************/

function UserLogout(){
	var sPathLogout = SMShop.getAttribute("LIuserLogoutPath");
	SMShop.basket.LIreset(true);
	SMShop.basket.update();
	SMShop.setAttribute("UserLogin", "false");
	SMShop.setAttribute("UserDiscount", "false");
	SMShop.setAttribute("StffDiscount", "false");
	SMShop.update();
	removeLoginDiscounts();
	SMProduct = null;
	SMProductLI = null;
	SMSession.removeSession(SMShop.id);
	SMSession.save();

	var http_sl_request = false;
	http_sl_request = false;
	if(window.XMLHttpRequest){
		http_sl_request = new XMLHttpRequest();
		if(http_sl_request.overrideMimeType){
			http_sl_request.overrideMimeType("text/xml");
		};
	} else if(window.ActiveXObject){
		try {
			http_sl_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) { };
	} else try {
		http_sl_request = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) { };
	if (!http_sl_request) {
		//alert("Kann keine XMLHTTP-Instanz erzeugen");
	} else {;
		try{
			var url = "../../../modules/login/php/logout.php5";
			http_sl_request.open("GET",sPathLogout,true);
			http_sl_request.send(null);	
		} catch(e) { };
	};
	var oElem = document.getElementsByName("smartLog")[0];
	if(!oElem) var oElem = document.getElementById("smartLog");
	if(!oElem) location.href = location.href;
	oElem.src = sPathLogout;
};

function CancelLoginChangeUserData(){
	document.getElementsByName("UserChangeDataButton")[0].disabled = false;
	document.getElementById("LoginInlineFrame").innerHTML = "";
};

function LoginChangeUserData(sLink){
	sHTML = '';
	sHTML += '<br><div align="center"><button name="CancelUserChangeDataButton" type="button" value="abbrechen" onclick="CancelLoginChangeUserData();">abbrechen</button></div>';
	sHTML += '<br>&nbsp;<br>';
	sHTML += '<div align="center" style="border: solid 0px #000000;">';
	sHTML += '<iframe name="smartLog" src="'+ sLink + '" scrolling="no" frameborder="0"></iframe>';
	sHTML += '</div>';
	sHTML += '<br><div align="center"><button name="CancelUserChangeDataButton" type="button" value="abbrechen" onclick="CancelLoginChangeUserData();">abbrechen</button></div>';
	document.getElementsByName("UserChangeDataButton")[0].disabled = true;
	document.getElementById("LoginInlineFrame").innerHTML = sHTML;
};

function setIframeDimensions(n,iAddWidth,iAddHeight){
 	var args = arguments;
 	if(args.length == 1) var n = args[0];
	if(args.length == 2) var iAddWidth = args[1];
	if(args.length == 3) var iAddHeight = args[2];
	var d = 15;
 	if(iAddHeight>0) d = iAddHeight;
 	try {
	  var ifObj = document.getElementsByName(n)[0];
  	if(!ifObj) var ifObj = document.getElementById(n);
	  if(!ifObj) return(false);
  	var p = (document.all)?'scroll':'offset';
		if(iAddWidth > 0){
			ifObj.style.width = String(iAddWidth) + "px";
		} else {
			eval("ifObj.style.height=Math.max(1,window.frames[n].document.getElementsByTagName('body')[0]."+p+"Width+"+d+")+'px'");
		};
 		eval("ifObj.style.height=Math.max(1,window.frames[n].document.getElementsByTagName('body')[0]."+p+"Height+"+d+")+'px'");
	 	return(true);
	} catch(e) { };
};

/************************/
/* Kunden-Login im Shop */
/************************/

function LIExtractField(sChain, sPosit){
	var aChain = sChain.split("_;_");
	for(var i=0; i<aChain.length; i++){
		var aField = aChain[i].split("_=_");
		if(aField[0] == sPosit){return(aField[1]);};
	};
	return('');
};

function getUserName(){
	sLoginData = SMShop.getAttribute("UserLogin");
	return(LIExtractField(sLoginData, 'USERNAME'));
};

function LIUserIsIn(){
	sLoginData = SMShop.getAttribute("UserLogin");
	var sLI_Name = LIExtractField(sLoginData, 'BILLTO_LASTNAME');
	var sLI_Firstname = LIExtractField(sLoginData, 'BILLTO_FIRSTNAME');
	var sLI_Company = LIExtractField(sLoginData, 'BILLTO_COMPANY');
	var sLI_Salutation = LIExtractField(sLoginData, 'BILLTO_SALUTATION');
	var sLI_Prompt = '';
	var sLI_Result = '';
	if(sLI_Company.length>0) sLI_Prompt = sLI_Company;
	if(sLI_Name.length>0 && sLI_Firstname.length>0) sLI_Prompt = sLI_Firstname + ' ' + sLI_Name;
	if(sLI_Name.length>0 && sLI_Firstname.length==0 && sLI_Salutation.length>0) sLI_Prompt = sLI_Salutation + ' ' + sLI_Name;
	sLI_Result += 'Guten Tag_NAME_!<BR>Willkommen in unserem Shop!';
	if(sLI_Prompt.length>0){
		var userNameString = ' ' + sLI_Prompt;
	} else {
		var userNameString = sLI_Prompt;
	};
	sLI_Result = sLI_Result.replace(/_NAME_/,userNameString);
	//sLI_Result += '<div id="divUserLogoutButton" align="center"><button name="UserLogoutButton" type="button" value="Abmelden" onclick="UserLogout();">Abmelden</button></div>';
	//document.getElementsByName("LoginUserLogin")[0].innerHTML = sLI_Result;
	document.write(sLI_Result);
	return(LIExtractField(sLoginData, 'USERNAME'));
};

function printLoginToForms(sType,iLfdNr,sContent){
	try {
		if(sContent.length == 0){
			var sLogin = SMShop.getAttribute("UserLogin");
		} else {
			var sLogin = sContent;
		};
	} catch(e) { };
	if((sLogin.length==0) || (sLogin=="false")){
		return(false);
	};
	var aLogin = sLogin.split("_;_");
	var aUserData = new Array;
	for(var i=0; i<aLogin.length; i++){
		var aField = aLogin[i].split("_=_");
		aUserData[i] = new Array();
		aUserData[i][0] = aField[0];
		aUserData[i][1] = aField[1];
	};
	for(var i=0; i<aUserData.length; i++){
		try {
			if(document.getElementsByName(aUserData[i][0]).length > 0){
				if(aUserData[i][0].indexOf("COUNTRY") > 0 && aUserData[i][1].length > 2){
					//document.getElementsByName(aUserData[i][0])[0].value = LIgetRegion(aUserData[i][1]);
				} else if(aUserData[i][0].indexOf("SALUTATION") > 0 && document.getElementsByName(aUserData[i][0]).length > 0){
					var sDDElem = document.getElementsByName(aUserData[i][0]);
					for(var j=0; j<sDDElem.length; j++){
						if(sDDElem.options[j].value == aUserData[i][1]){
							sDDElem.options[j].selected = true;
							break;
						};
					};
				} else {
					document.getElementsByName(aUserData[i][0])[0].value = aUserData[i][1];
				};
			};
		} catch(e) { };
	};
	var bShipToDiff = false;
	for(var i=0; i<aUserData.length; i++){
		if(aUserData[i][0].indexOf("SHIPTO")>=0 && aUserData[i][1].length>0){
			if(aUserData[i][0].indexOf("COUNTRY")>=0 || aUserData[i][0].indexOf("SALUT")>=0){
				//nothing
			} else {
				bShipToDiff = true;
			};
		};
	};
	if(bShipToDiff){
		if(document.getElementsByName("BILLTO_SHIPTO_DIFFERS").length > 0){
			document.forms.BILLTO.BILLTO_SHIPTO_DIFFERS.checked = true;
		};
	};
	// Contact Form
	//if(document.getElementsByName("CONTACT").length > 0 || document.getElementsByName("CONTACT_MESSAGE").length > 0){
	if(iLfdNr == 1){
		sLogin = sLogin.replace(/BILLTO/g, "CONTACT");
		var sStreet1 = LIExtractField(sLogin, 'CONTACT_STREET_1');
		var sStreet2 = LIExtractField(sLogin, 'CONTACT_STREET_2');
		sLogin += '_;_CONTACT_STREET_=_';
		sLogin += sStreet1 + ' (' + sStreet2 + ')';
		printLoginToForms("CONTACT", 2, sLogin);
	};
	// Individual Form 1.Step
	//if(iLfdNr == 2 && (document.getElementsByName("MAILFORM").length > 0)){
	if(iLfdNr == 2){
		sLogin = sLogin.replace(/CONTACT/g, "MAILFORM");
		printLoginToForms("MAILFORM", 3, sLogin);
	};
	//  Individual Form 2.Step
	if(iLfdNr == 3){
		var sLI_Name_IMF = LIExtractField(sLogin, 'MAILFORM_LASTNAME');
		var sLI_Firstname_IMF = LIExtractField(sLogin, 'MAILFORM_FIRSTNAME');
		var sLI_Mail_IMF = LIExtractField(sLogin, 'MAILFORM_EMAIL');
		var sLI_NewName_IMF = sLI_Firstname_IMF + ' ' + sLI_Name_IMF;
		sLogin += '_;_FromName_=_' + sLI_NewName_IMF;
		sLogin += '_;_FromMail_=_' + sLI_Mail_IMF;
		printLoginToForms("MAILFORM", 4, sLogin);
	};
};

/*********************/
/* Discounts im Shop */
/*********************/

cSMGDiscounts.prototype.addForLogin = function(id,$2C,$2D,$x,$2E){
	var $g=this,$1c=$g.base,$1k=$g.xml,$2F="",$2G="",$2H="",$2y="",$2I="",$2J="";
	if($1c.raiseEvent(7,true,true,$g,$2C,$x,$2E)){
		$2F=$1k.getAttribute(_SMAUniqueID);
		$2G=$1k.getAttribute(_SMAAmount);
		$2H=$1k.getAttribute(_SMAMode);
		$2y=$1k.getAttribute(_SMAValue);
		$2I=$1k.getAttribute(_SMATextBuffer);
		$2J=$1k.text;
		if(SMShop.getAttribute("finit")=="1"){
			$2F+=(($2F.length>0)?";":"")+id;
			$2G+=(($2G.length>0)?";":"")+fnSMRndCur($2C);
			$2H+=(($2H.length>0)?";":"")+$2D;
			$2y+=(($2y.length>0)?";":"")+fnSMRndCur($x);
			$2I+=(($2I.length>0)?";":"")+$2E.length;
			$2J+=$2E;
		};
		$1k.setAttribute(_SMAUniqueID,$2F);
		$1k.setAttribute(_SMAAmount,$2G);
		$1k.setAttribute(_SMAMode,$2H);
		$1k.setAttribute(_SMAValue,$2y);
		$1k.setAttribute(_SMATextBuffer,$2I);
		$1k.text=$2J;
		$1c.raiseEvent(8,false,null,$g,$2C,$x,$2E);
	}else $1c.raiseEvent(10,false,null,$g,$2C,$x,$2E);
};

cSMGDiscounts.prototype.remove = function(id,$2C,$2D,$x,$2E){
	var $g=this,$1c=$g.base,$1k=$g.xml,$2F="",$2G="",$2H="",$2y="",$2I="",$2J="";
	if($1c.raiseEvent(7,true,true,$g,$2C,$x,$2E)){
		$2F = id;
		$2G = fnSMRndCur($2C);
		$2H = $2D;
		$2y = fnSMRndCur($x);
		$2I = $2E.length;
		$2J = $2E;
		$1k.setAttribute(_SMAUniqueID,$2F);
		$1k.setAttribute(_SMAAmount,$2G);
		$1k.setAttribute(_SMAMode,$2H);
		$1k.setAttribute(_SMAValue,$2y);
		$1k.setAttribute(_SMATextBuffer,$2I);
		$1k.text=$2J;
		$1c.raiseEvent(8,false,null,$g,$2C,$x,$2E);
	}else $1c.raiseEvent(10,false,null,$g,$2C,$x,$2E);
};

function setLoginDiscounts(){
	removeLoginDiscounts();
	var sData = SMShop.getAttribute("UserDiscount");
	if((sData.length==0) || (sData=="false")){return(false);};
	var aDiscounts = sData.split("_;_");
	SMShop.setAttribute("finit", "1");
	SMShop.update();
	for(var i=0; i<aDiscounts.length; i++){
		var aFields = aDiscounts[i].split("|");
		if(aFields[0].length == 0){
			// set only global discounts, avoid rule discounts
			if(aFields[2] == 0 && aFields[4] != 0){aFields[2] = 0.01;};
			with(SMShop.basket.discounts){addForLogin(aFields[1], aFields[2], (aFields[3] - 1), aFields[4], aFields[5]);};
			SMShop.basket.discounts.update();
			SMShop.basket.update();
			SMShop.update();
		};
	};
	SMShop.setAttribute("finit", "0");
	SMShop.update();
};

function removeLoginDiscounts(){
	SMShop.basket.discounts.remove(0,0,0,0,"");
	SMShop.basket.discounts.update();
	SMShop.basket.update();
	SMShop.update();
};

function printLoginDiscountsDetail(sLink){
	var sHTMLh = sHTMLb = sHTMLf = '';
	sHTMLh += '<br>&nbsp;<br>';
	sHTMLh += '<div align="center">';
	sHTMLb += ' sent.discounts.offerDiscountsForCustomer';
	sHTMLb = sHTMLb.replace(/_START_LINK_/,'<a href="' + sLink + '">');
	sHTMLb = sHTMLb.replace(/_END_LINK_/,'</a>');
	sHTMLf += '</div>';
	sHTMLf += '<span id="LoginInlineFrame">&nbsp;</span>';
	var sData = '';
	try {
		sData = SMShop.getAttribute("UserDiscount");
	} catch(e) { };
	if((sData.length==0) || (sData=="false") || (sData==false)){
		try {
			sData = SMShop.getAttribute("StffDiscount");
		} catch(e) { };
		if(sData.length>0){
			//document.write("<br>&nbsp;<br>Sie erhalten auf verschiedene Hersteller, Kategorien oder Produkte gesonderte Rabattstaffeln. Diese werden bei den entsprechenden Produkten angezeigt. Details finden Sie auch auf der Login-Seite.");
			//return(false);
		} else {
			document.write(sHTMLb);
			return(false);
		};
	};
	var aDiscounts = sData.split("_;_");
	if(aDiscounts.length == 1){
		var aFields = aDiscounts[0].split("|");
		if(aFields[4] == 0){
			document.write(sHTMLh + sHTMLb + sHTMLf);
			return(false);
		};
	};
	if(getUserDiscountText("text").length>0){
		document.write('<br>&nbsp;<br>' + getUserDiscountText("text") + '<br>&nbsp;');
	};
	if(!getUserDiscountText("bool")){
		document.write(sHTMLh + sHTMLf);
		return(false);
	};
	sHTMLb = '';
	sHTMLb += 'Sie erhalten folgende Rabatte:<br>&nbsp;<br>';
	sHTMLb += '<table id="LIDiscTab" border="0" cellspacing="0" cellpadding="3">';
	sHTMLb += '	<tr>';
	sHTMLb += '		<td class="LIDiscTabHead">Beschreibung</td>';
	sHTMLb += '		<td class="LIDiscTabHead">Ab Wert</td>';
	sHTMLb += '		<td class="LIDiscTabHead">Rabatt-Art</td>';
	sHTMLb += '		<td class="LIDiscTabHead">Rabatt</td>';
	sHTMLb += '	</tr>';
	for(var i=0; i<aDiscounts.length; i++){
		var aFields = aDiscounts[i].split("|");
		aFields[2] = cprimary.format(aFields[2], SM_CGROUP + SM_CSYMBOL);
		aFields[2] = aFields[2].replace("&nbsp;", " ");
		if(String(aFields[3]) == "1"){
			aFields[4] = cprimary.format(aFields[4], SM_CGROUP + SM_CSYMBOL);
			aFields[4] = aFields[4].replace("&nbsp;", " ");
		} else if(String(aFields[3]) == "2"){
			aFields[4] = cprimary.format(aFields[4]) + "%";
			//aFields[4] = String(aFields[4]) + "%";
		};
		if(String(aFields[3]) == "1"){
			aFields[3] = "Fester Wert";
		} else if(String(aFields[3]) == "2"){
			aFields[3] = "Rabatt %";
		};
		if(aFields[0].indexOf("product-price-sug")<0){
			sHTMLb += '	<tr>';
			sHTMLb += '		<td class="LIDiscTabBody">' + aFields[5] + '</td>';
			sHTMLb += '		<td class="LIDiscTabBody" align="right">' + aFields[2] + '</td>';
			sHTMLb += '		<td class="LIDiscTabBody">' + aFields[3] + '</td>';
			sHTMLb += '		<td class="LIDiscTabBody_R" align="right">' + aFields[4] + '</td>';
			sHTMLb += '	</tr>';
		};
	};
	sHTMLb += '	</table>';
	try {
		sData = SMShop.getAttribute("UserDiscount");
	} catch(e) { };
	if((sData.length==0) || (sData=="false") || (sData==false)){
		sHTMLb = 'Sie erhalten folgende Rabatte::<br>&nbsp;<br>';
	};
	document.write(sHTMLh + sHTMLb + sHTMLf);
	sData = SMShop.getAttribute("StffDiscount");
	if(sData.length>0 && sData!="false"){
		var sStffP = getSerializedStff("product");
		var sStffC = getSerializedStff("category");
		var sStffM = getSerializedStff("manufacturer");
		sHTMLb = '';
		sHTMLb += '<div style="padding:20px" align="center"><table id="LIDiscTab" style="border-right:2px solid #000000" border="0" cellspacing="0" cellpadding="3">';
		sHTMLb += '<tr>';
		if(sStffM!="none") sHTMLb += '<td class="LIDiscTabHead" align="center">Hersteller-Staffeln</td>';
		if(sStffC!="none") sHTMLb += '<td class="LIDiscTabHead" align="center">Kategorie-Staffeln</td>';
		if(sStffP!="none") sHTMLb += '<td class="LIDiscTabHead" align="center">Produkt-Staffeln</td>';
		sHTMLb += '</tr><tr>';
		if(sStffM!="none"){
			var aStffM = sStffM.split(", ");
			sHTMLb += '<td class="LIDiscTabBody" style="padding:5px;vertical-align:top">';
			sHTMLb += '<p><UL>';
			for(var i=0; i<aStffM.length; i++){
				sHTMLb += '<LI>' + aStffM[i] + '</LI>';
			};
			sHTMLb += '</UL></p>';
			sHTMLb += '</td>';
		};
		if(sStffC!="none"){
			var aStffC = sStffC.split(", ");
			var sCatList = '38==Alpha Noble_;_39==Belvedere_;_219==Camitz_;_206==Monnet_;_207==Lanson_;_213==Weinbrand_;_216==Aquavit_;_175==Tabu_;_190==Parliament_;_191==Bücher_;_192==Zubehör_;_193==Vivus_;_122==Wein_;_245==Black Bottle_;_239==No. 209_;_165==Gorbatschow_;_166==Grasovka_;_167==Spanien_;_202==Energy-Drinks_;_20==Moet Chandon_;_21==Taittinger_;_22==Absolut_;_24==Heidsieck_;_25==Laurent Perrier_;_26==Louis Roederer_;_27==Mumm_;_28==Piper - Heidsieck_;_29==Ruinart_;_30==Smirnoff_;_135==Giffard_;_136==Ziegler_;_273==Tradewinds_;_274==Cocktails / Mixgetränke_;_276==Snapple_;_277==Ardbeg_;_278==Ardmore_;_279==The Dalmore_;_280==Pircher_;_89==Jose Cuervo_;_90==Olmeca_;_91==Sauza_;_92==Sierra_;_93==Tabay_;_94==Cusano Rojo_;_133==Obstbrand_;_55==Tullamore Dew_;_177==Ciroc_;_241==Sotol_;_242==Zeitgeist_;_126==Südafrika_;_128==Rotwein_;_129==Weißwein_;_130==Pampero_;_131==Geschenkservice_;_189==Dimple_;_2==Wodka_;_209==Geschenke_;_56==The Macallan_;_57==Talisker Skye_;_58==Royal Lochnagar_;_59==Oban_;_63==Johnnie Walker_;_106==Chopin_;_107==Xellent_;_108==Wyborowa_;_109==Highland Park_;_110==Bombay Sapphire_;_111==Bulldog_;_112==Beefeater_;_113==Hendricks_;_114==Gordons_;_115==Finsbury_;_116==Boudier_;_152==Toskana_;_153==Edle Brände_;_172==Pussers_;_173==The Duke_;_179==The Famous Grouse_;_180==Four Roses_;_182==William Grants_;_184==Cachaca_;_132==Premium Wasser_;_9==Champagner_;_16==Prosecco_;_17==Canard-Duchene_;_18==Dom-Perignon_;_19==Veuve Clicquot_;_218==Lantenhammer_;_36==Whisky / Whiskey_;_258==Brecon_;_259==London Hill_;_260==Lubuski_;_3==Rum_;_4==Gin_;_7==Cognac / Brandy_;_8==Tequila / Mezcal_;_217==Wermut_;_223==Veuve Emille_;_224==Sekt_;_225==Fürst von Metternich_;_226==Henkell_;_227==Old Pascas_;_228==Elements 8_;_86==Sets und Partypacks_;_168==Myerss Rum_;_169==Ron Varadero_;_170==Appleton_;_171==Lemon Hart_;_243==Germain_;_244==Seriously_;_157==Corralejo_;_158==Skorppio_;_60==Laphroaig_;_246==Creme-Liköre_;_247==Frucht-Limes_;_248==Lafontan_;_249==Hacienda de Chihuahua_;_61==Lagavulin_;_62==Knockando_;_250==Geldermann_;_120==Bitter / Kräuterliköre_;_71==Cragganmore_;_72==Chivas_;_73==Caol Ila_;_123==Italien_;_124==Sizilien_;_125==Apulien_;_185==Anisliköre_;_186==Ballantines_;_201==Brugal_;_40==Finlandia_;_41==Grey Goose_;_42==Russian Standard_;_43==Level Imported_;_44==Skyy_;_45==Ron Caney_;_46==Havana Club_;_47==Captain Morgan_;_48==Bacardi_;_49==Hennessy_;_50==Remy Martin_;_51==Davidoff_;_52==Courvoisier_;_53==Glenfiddich_;_54==Wild Turkey_;_148==Trentino_;_159==Brokers_;_117==Tanqueray_;_235==Monin_;_236==Riemerschmid_;_237==Hardy_;_255==Suntory_;_256==Auchentoshan_;_257==Glen Garioch_;_118==Hans Reisetbauer_;_119==The London Gin_;_229==Bols_;_230==Armagnac_;_231==Botran_;_232==Diplomatico_;_233==La Fee_;_234==Henri Giraud_;_160==Nicolas Feuillatte_;_161==Kampanien_;_162==Aha Toro_;_102==Snow Queen_;_210==Whisky Geschenke_;_211==Champagner Geschenke_;_212==Cognac Geschenke_;_140==Likör_;_178==Schlehen Gins / Liköre_;_194==alkoholfreie Getränke_;_195==Schladerer_;_220==Perrier Jouet_;_221==Puriste Premium_;_222==Don Julio_;_163==Friaul / Lombardei_;_103==Stolichnaya_;_104==Kauffman_;_105==Moskovskaya_;_85==Sondergrößen_;_64==Jim Beam_;_65==Glenlivet_;_66==Glenmorangie_;_67==Glenkinchie_;_187==De Kuyper_;_200==Tequila Rose_;_240==Sherry_;_100==Oval_;_74==Canadian Club_;_75==Bushmills_;_76==Bowmore_;_77==Jack Daniel`s_;_78==Scavi  Ray_;_79==Martini_;_80==Cinzano_;_81==VALDO_;_83==Three Sixty_;_251==Bollinger_;_252==Mozart_;_253==Eistee_;_254==AriZona_;_174==Absinth_;_134==Sirup_;_188==Bols_;_142==Cardenal Mendoza_;_147==Grappa_;_272==Jameson_;_149==nach Ländern sortiert_;_150==Venetien_;_151==Rosé_;_68==Glendronach_;_69==Glen Moray_;_70==Dalwhinnie_;_164==Piemont_;_261==Glen Elgin_;_262==Singleton_;_263==Clynelish_;_264==Crown Royal_;_265==Balvenie_;_266==Weinschorle_;_267==Ron Zacapa_;_268==Orangen Liköre_;_269==Pommery_;_270==Kornbrand_;_271==Cadenheads_;_281==Esperanto_;_282==Ketel One';
			var aCatList = sCatList.split("_;_");
			var oCatList = new Array();
			for(var i=0; i<aCatList.length; i++){
				oCatList[i] = aCatList[i].split("==");
			};
			sHTMLb += '<td class="LIDiscTabBody" style="padding:5px;vertical-align:top">';
			sHTMLb += '<p><UL>';
			for(var i=0; i<aStffC.length; i++){
				for(var j=0; j<aCatList.length; j++){
					if(aStffC[i]==oCatList[j][0]){
						aStffC[i] = oCatList[j][1];
						break;
					};
				};
				sHTMLb += '<LI>' + aStffC[i] + '</LI>';
			};
			sHTMLb += '</UL></p>';
			sHTMLb += '</td>';
		};
		if(sStffP!="none"){
			var aStffP = sStffP.split(", ");
			sHTMLb += '<td class="LIDiscTabBody" style="padding:5px;vertical-align:top">';
			sHTMLb += '<p><UL>';
			for(var i=0; i<aStffP.length; i++){
				sHTMLb += '<LI>' + aStffP[i] + '</LI>';
			};
			sHTMLb += '</UL></p>';
			sHTMLb += '</td>';
		};
		sHTMLb += '</tr>';
		sHTMLb += '</table></div>';
		document.write(sHTMLb);
	};

	return(true);
};

function printLoginDiscountsSummary(sLink){
	var sHTMLb = '';
	sHTMLb += '<br>sent.discounts.noDiscountsForCustomer sent.discounts.offerDiscountsForCustomer';
	sHTMLb = sHTMLb.replace(/_START_LINK_/,'<a href="' + sLink + '">');
	sHTMLb = sHTMLb.replace(/_END_LINK_/,'</a>');
	var sData = '';
	try {
		sData = SMShop.getAttribute("UserDiscount");
	} catch(e) { };
	if((sData.length==0) || (sData=="false") || (sData==false)){
		try {
			sData = SMShop.getAttribute("StffDiscount");
		} catch(e) { };
		if(sData.length>0){
			document.write("<br>&nbsp;<br>Sie erhalten auf verschiedene Hersteller, Kategorien oder Produkte gesonderte Rabattstaffeln. Diese werden bei den entsprechenden Produkten angezeigt. Details finden Sie auch auf der Login-Seite.");
			return(false);
		} else {
			document.write(sHTMLb);
			return(false);
		};
	};
	var aDiscounts = sData.split("_;_");
	if(aDiscounts.length == 1){
		var aFields = aDiscounts[0].split("|");
		if(aFields[4] == 0){
			document.write(sHTMLb);
			return(false);
		};
	};

	if(getUserDiscountText("text").length>0){
		document.write('<br>&nbsp;<br>' + getUserDiscountText("text") + '<br>&nbsp;');
	};
	if(!getUserDiscountText("bool")){
		return(false);
	};
	var	sHTMLb = '';
	sHTMLb += '<br>Sie erhalten folgende Rabatte:';
	for(var i=0; i<aDiscounts.length; i++){
		var aFields = aDiscounts[i].split("|");
		var aRule = aFields[0].split("==");
		aFields[2] = cprimary.format(aFields[2], SM_CGROUP + SM_CSYMBOL);
		aFields[2] = aFields[2].replace("&nbsp;", " ");
		if(String(aFields[3]) == "1"){
			aFields[4] = cprimary.format(aFields[4], SM_CGROUP + SM_CSYMBOL);
			aFields[4] = aFields[4].replace("&nbsp;", " ");
		} else if(String(aFields[3]) == "2"){
			aFields[4] = cprimary.format(aFields[4]) + "%";
			//aFields[4] = String(aFields[4]) + "%";
		};
		if(aRule[0]=="manufacturer"){
			sHTMLb += '<p>' + aFields[5] + ': ' + aFields[4] + '</p>';
		} else if(aRule[0]=="category"){
			sHTMLb += '<p>' + aFields[5] + ': ' + aFields[4] + '</p>';
		} else if(aRule[0]=="product"){
			sHTMLb += '<p>' + aFields[5] + ': ' + aFields[4] + '</p>';
		} else if(aRule[0]=="product-new-price"){
			sHTMLb += '<p>' + aFields[5] + ': ' + aFields[4] + '</p>';
		} else if(aRule[0]=="product-price-sug"){
			//do not print
		} else if(aRule[0]=="spaceline"|| aRule[0]=="spaceline2" || aRule[0]=="spaceline3"){
			sHTMLb += '';
		} else {
			sHTMLb += '<p>' + aFields[5] + ':<br>ab ' + aFields[2] + ' Warenwert: ' + aFields[4] + '</p>';
		};
	};
	sData = SMShop.getAttribute("StffDiscount");
	if(sData.length>0 && sData!="false"){
		sHTMLb += '<p>Sie erhalten auf verschiedene Hersteller, Kategorien oder Produkte gesonderte Rabattstaffeln. Diese werden bei den entsprechenden Produkten angezeigt. Details finden Sie auch auf der Login-Seite.</p>';
	};
	document.write(sHTMLb);
	return(true);
};

function printLoginButtons(sURL2){
	var sHTMLf = '';
	sHTMLf += '<div id="divUserLogButtons" align="center">';
	sHTMLf += '<a href="javascript:UserLogout()"><img src="' + sURL2 + '" alt="abmelden"></a>';
	sHTMLf += '<br>abmelden';
	sHTMLf += '</div>';
	document.write(sHTMLf);
};

function printLoginButtonsAdmin(sURL2){
	var sHTMLf = '';
	sHTMLf += '<div style="padding-top:20px" align="center">&nbsp;</div>';
	sHTMLf += '<div id="divUserLogButtonsAdmin" style="width:250px;overflow:show;padding:10px" align="center">';
	sHTMLf += '<a href="javascript:UserLogout()"><img src="' + sURL2 + '" alt="abmelden"></a>';
	sHTMLf += '<br>abmelden';
	sHTMLf += '</div>';
	sHTMLf += '<div style="padding-bottom:20px" align="center">&nbsp;</div>';

	sHTMLf += '<div id="2ndLogoutButton" style="z-index:99999999; position:absolute; right:15px; top:20px; width:60px; height:60px" align="center">';
	sHTMLf += '<a href="javascript:UserLogout()"><img src="' + sURL2 + '" alt="abmelden"></a>';
	sHTMLf += '</div>';

	return(sHTMLf);
};

/***************************************/
/* Regel-Discounts über _SMAPrdDiscount*/
/***************************************/

function setLIProductDiscount(){
	var $g = SMProductLI;
	var iDiscAmount = getProdLIDiscount();
	if(iDiscAmount < 0){return(false);};
	$g.setAttribute(_SMAPrdDiscount,iDiscAmount);
	$g.variants.update();
	$g.discounts.update();
	$g.update();
	displayProductProperties($g);
};

/*******************/
/* Regel-Discounts */
/*******************/

cSMVariants.prototype.updateLI=function(iNewPrice2){
	var $g=this,$1c=$g.base,$1k=$g.xml,$38=null,$39=null,$3a=null,$1V=$g.parent,$2P=0,$3b=false,$3c=null;
	if($1c.raiseEvent(4,true,true,$g)){
		$39=$g.getActVariant();
		if($39!=null){
			$38=$39.xml;
			$38.setAttribute(_SMAPrice,iNewPrice2);
		};
	}else $1c.raiseEvent(6,false,null,$g)
};

function CheckVariants(){
	var sResult = 'NO_VARIANTS';
	var iCntForms = document.forms.length;
	var sFormName = '';
	var i = 0;
	while (i < iCntForms) {
  	sFormName = document.forms[i].name;
  	if(sFormName.indexOf("PD") == 0 && sFormName.indexOf("variants") > 0){
  		sResult = sFormName;
  		break;
  	};
  	i++;
	};
	return(sResult);
};

function reinitVariants(sFormName){
	var frm1 = document[sFormName];
	if(frm1!=null){
 		for(var i=0; i<frm1.elements.length; i++){
		  var elem1 = frm1.elements[i];
  	 	if(elem1.type=="select-one"){
  	 		var sFunc = String(elem1.onchange);
  	 		var iFunc = sFunc.indexOf("{");
  	 		sFunc = sFunc.substr(iFunc + 1);
  	 		iFunc = sFunc.lastIndexOf("}");
  	 		sFunc = sFunc.substring(0, iFunc);
  	 		eval('elem1.onchange = function(){MakeLIPriceReset();' + sFunc + ';MakeLIPriceReinit();};');
  		};
  	};
  	return(sFunc);
 	} else {
 		return('NO_VARIANTS');
 	};
};

function resetVariants(sFormName,sFunc){
	var frm1 = document[sFormName];
	if(frm1!=null){
 		for(var i=0; i<frm1.elements.length; i++){
		  var elem1 = frm1.elements[i];
  	 	if(elem1.type=="select-one"){
  	 		eval('elem1.onchange = function(){' + sFunc + ';};');
  		};
  	};
  	return('OK');
 	} else {
 		return('NO_VARIANTS');
 	};
};

function MakeLIPrice_init(){
	var $g=SMProductLI;
	var iCatDiscount = parseFloat($g.getAttribute(_SMAPrdDiscount));
	if(isNaN(iCatDiscount)){iCatDiscount = 0;};
	if(iCatDiscount > 0){
		$g.setAttribute("CatDiscount",iCatDiscount);
		$g.setAttribute(_SMAPrdDiscount,0);
		$g.update();
	};
	var iOrgPrice = $g.getPrice();
	//var iOrgPrice = $g.getAttribute(_SMAPrice);
	if(bInGross() != bOutGross()){
		var iTax = getVAT();
		if(!bInGross()){
			iOrgPrice = iOrgPrice / (1 + iTax);
		} else {
			iOrgPrice = iOrgPrice * (1 + iTax);
		};
	};
	$g.setAttribute("OrgPriceLI",iOrgPrice);
	$g.setAttribute("VeryOrgPriceLI",iOrgPrice);
	$g.update();
};

function MakeLIPriceReset(){
	var $g=SMProductLI;
	var iOrgPrice = $g.getAttribute("VeryOrgPriceLI");
	var iOrgDisc = $g.getAttribute("CatDiscount");
	$g.setAttribute(_SMAPrice,iOrgPrice);
	$g.setAttribute(_SMAPrdDiscount,iOrgDisc);
	$g.variants.updateLI(iOrgPrice);
	$g.update();
};

function MakeLIPriceReinit(){
	var $g=SMProductLI;
	var iCatDiscount = parseInt($g.getAttribute(_SMAPrdDiscount), 10);
	if(isNaN(iCatDiscount)){iCatDiscount = 0;};
	if(iCatDiscount > 0){
		$g.setAttribute("CatDiscount",iCatDiscount);
		$g.setAttribute(_SMAPrdDiscount,0);
		$g.update();
	};
	var iOrgPrice = $g.getPrice();
	//var iOrgPrice = $g.getAttribute(_SMAPrice);
	if(bInGross() != bOutGross()){
		var iTax = getVAT();
		if(!bInGross()){
			iOrgPrice = iOrgPrice / (1 + iTax);
		} else {
			iOrgPrice = iOrgPrice * (1 + iTax);
		};
	};
	$g.setAttribute("OrgPriceLI",iOrgPrice);
	$g.setAttribute("VeryOrgPriceLI",iOrgPrice);
	$g.update();
	MakeLIPrice(true);
};

function MakeLIPrice(bProductHasVariants){
	var $g=SMProductLI;
	//var iOrgPrice = $g.getPrice();
	var iNewPrice = getProdLIDiscount();
	if(iNewPrice < 0){
		var iOrgDisc = $g.getAttribute("CatDiscount");
		$g.setAttribute(_SMAPrdDiscount,iOrgDisc);
		$g.update();
		displayProductProperties($g);
		return(false);
	};
	$g.setAttribute(_SMAPrice,iNewPrice);
	if(bProductHasVariants){$g.variants.updateLI(iNewPrice);};
	$g.update();
	displayProductProperties($g);
	//var sOrgPrice = cprimary.format($g.getAttribute("VeryOrgPriceLI"), SM_CGROUP + SM_CSYMBOL);
	//		sOrgPrice = sOrgPrice.replace("&nbsp;", " ");
	var iOrgPrice = parseFloat($g.getAttribute("VeryOrgPriceLI"));
	if(bInGross() != bOutGross()){
		var iTax = getVAT();
		if(!bInGross()){
			iOrgPrice = iOrgPrice * (1 + iTax);
		} else {
			iOrgPrice = iOrgPrice / (1 + iTax);
		};
	};
	var sOrgPrice = cprimary.format(iOrgPrice, SM_CGROUP + SM_CSYMBOL);
	var sHTML = sHTMLOrg = sHTMLDisc = '';
	if(document.getElementById("product_original_price")){
		showIdTag("product_original_price",sOrgPrice);
		//showPriceTag("product_price_prefix","Bei uns statt:&nbsp;");
		//showPriceTag("product_price_prefix2","Ihr Preis:&nbsp;");
	} else {
		sHTMLOrg = document.getElementById("product_price").innerHTML;
		sHTML = '<div class="t-small t-em" style="text-decoration:line-through;" id="product_original_price">' + sOrgPrice + '</div>';
		sHTML += sHTMLOrg;
		document.getElementById("product_price").innerHTML = sHTML;
		//showPriceTag("product_price",sHTML);
		//showPriceTag("product_price_prefix","Bei uns statt:&nbsp;");
		//showPriceTag("product_price_prefix2","Ihr Preis:&nbsp;");
	};
	return(true);
};

function showIdTag(sTag,sCont){
	var oElem = document.getElementById(sTag);
	if(oElem){
		oElem.style.display = "inline";
		oElem.style.visibility = "visible";
		if(sCont.length>0) oElem.innerHTML = sCont;
	};
};

function hideIdTag(sTag,sCont){
	var oElem = document.getElementById(sTag);
	if(oElem){
		oElem.style.display = "none";
		oElem.style.visibility = "hidden";
		if(sCont.length>0) oElem.innerHTML = sCont;
	};
};

function bInGross(){
	var bTest = (SMShop.getAttribute(_SMAInGross)=="1")?true:false;
	return(bTest);
};
function bOutGross(){
	var bTest = (SMShop.getAttribute(_SMAOutGross)=="1")?true:false;
	return(bTest);
};
function getVAT(){
	var aRegion = SMShop.getActiveRegion();
	if(SMProductLI){
		var iRegSet = parseInt(SMProductLI.getAttribute(_SMARegion), 10);
	} else {
		var iRegSet = parseInt(SMProduct.getAttribute(_SMARegion), 10);
	};
	var iActTax = parseFloat(aRegion[iRegSet + 2]) / 100;
	return(iActTax);
};

function RemoveSpecialSigns(sText){
	sText = sText.replace(/"/g, '');
	sText = sText.replace(/'/g, '');
	sText = sText.replace(/&/g, '');
	sText = sText.replace(/§/g, '');
	sText = sText.replace(/\\/g, '');
	sText = sText.replace(/²/g, '');
	sText = sText.replace(/³/g, '');
	sText = sText.replace(/\|/g, '');
	sText = sText.replace(/°/g, '');
	return(sText);
};

function CheckPriceSuggestion(oDiv,sVal){
	var $g = SMProductLI;
	var aVal = sVal.split("_|_");
	var sObj = "SugPrice_" + oDiv;
	var oDate = new Date();
	var oNow = oDate.getTime();
	var iTime = parseFloat(aVal[0]);
	var iPmin = parseFloat(aVal[1].replace(",","."));
	var sPsug = document.getElementById("ipt_PDPriceSug").value;
	sPsug = sPsug.replace(",",".");
	var iPsug = parseFloat(sPsug);
	if(isNaN(iPsug)){
		alert("Bitte geben Sie nur Zahlen ein.");
		//location.href = location.href;
		document.getElementById("ipt_PDPriceSug").value = "";
		document.getElementById("ipt_PDPriceSug").focus();
		return(false);
	};
	var iTimeO = 0;
	try {
		iTimeO = parseFloat(SMShop.getAttribute(sObj));
	} catch(e) { };
	if(isNaN(iTimeO)){
		//first call -> no action
	} else if((oNow - iTimeO) < (iTime * 1000)){
		var sMsg = "Ihr nächstes Angebot können Sie in %time abgeben.";
		var iSek = Math.floor(((iTime * 1000) - (oNow - iTimeO)) / 1000);
		var iMin = Math.floor(iSek / 60);
		iSek = iSek - (iMin * 60);
		var sDif = '';
		if(iMin>0){
			if(iMin==1) sDif += iMin + " Minute und ";
			if(iMin>1) sDif += iMin + " Minuten und ";
		};
		if(iSek==1){
			sDif += iSek + " Sekunde";
		} else {
			sDif += iSek + " Sekunden";
		};
		sMsg = sMsg.replace("%time",sDif);
		alert(sMsg);
		location.href = location.href;
		return(false);
	};
	SMShop.setAttribute(sObj,oNow);
	SMShop.update();
	if(iPsug<iPmin){
		var sMsg1 = "Ihr Angebot wurde abgelehnt.";
		var sMsg2 = "Ihr nächstes Angebot können Sie in %time abgeben.";
		var iSek = iTime;
		var iMin = Math.floor(iSek / 60);
		iSek = iSek - (iMin * 60);
		var sDif = '';
		if(iMin>0){
			if(iMin==1) sDif += iMin + " Minute und ";
			if(iMin>1) sDif += iMin + " Minuten und ";
		};
		if(iSek==1){
			sDif += iSek + " Sekunde";
		} else {
			sDif += iSek + " Sekunden";
		};
		sMsg2 = sMsg2.replace("%time",sDif);
		alert(sMsg1 + "\n" + sMsg2);
		location.href = location.href;
		return(false);
	};
	$g.setAttribute(_SMAPrice,iPsug);
	if(sVariants != 'NO_VARIANTS'){$g.variants.updateLI(iPsug);};
	$g.update();
	displayProductProperties($g);
	var sHTML = String(SMBasket_onAfterAdd);
	if(sHTML.indexOf("alert")>=0){
		sHTML = sHTML.substring(sHTML.indexOf("{")+1,sHTML.lastIndexOf("}"));
		var sHTML2 = "SMBasket_onAfterAdd = function(args){"
		sHTML2 += sHTML + ";";
		sHTML2 += "location.href = location.href;";
		sHTML2 += "};";
		eval(sHTML2);
	};
	document.getElementById(oDiv).innerHTML = "";
	sHTML = 'CoDoSug_' + oDiv + ' = window.setInterval(\'CountdownSuggestion("' + oDiv + '","' + sVal + '")\', 1000);';
	eval(sHTML);
	sHTML = 'SMBasket_onBeforeAdd = function(args){alert("Die Wartezeit bis zu Ihrer nächsten Angebotsmöglichkeit ist noch nicht abgelaufen.");return(false);};';
	eval(sHTML);
	alert("Ihr Angebot wurde angenommen.");
	return(true);
};

function CountdownSuggestion(oDiv,sVal){
	var oTGT = document.getElementById(oDiv);
	var aVal = sVal.split("_|_");
	var sObj = "SugPrice_" + oDiv;
	var oDate = new Date();
	var oNow = oDate.getTime();
	var iTime = parseFloat(aVal[0]);
	var iPmin = parseFloat(aVal[1].replace(",","."));
	var iTimeO = 0;
	try {
		iTimeO = parseFloat(SMShop.getAttribute(sObj));
	} catch(e) { };
	if(isNaN(iTimeO)){
		//first call -> no action
	} else if((oNow - iTimeO) < (iTime * 1000)){
		var sMsg = "Ihr nächstes Angebot können Sie in %time abgeben.";
		var iSek = Math.floor(((iTime * 1000) - (oNow - iTimeO)) / 1000);
		var iMin = Math.floor(iSek / 60);
		iSek = iSek - (iMin * 60);
		var sDif = '';
		if(iMin>0){
			if(iMin==1) sDif += iMin + " Minute und ";
			if(iMin>1) sDif += iMin + " Minuten und ";
		};
		if(iSek==1){
			sDif += iSek + " Sekunde";
		} else {
			sDif += iSek + " Sekunden";
		};
		sMsg = sMsg.replace("%time",sDif);
		oTGT.innerHTML = sMsg;
	} else {
		// Clear Countdown
		var sHTML = 'window.clearInterval(CoDoSug_' + oDiv + ');';
		eval(sHTML);
		location.href = location.href;
	};
};

function SetPriceSuggestion(oDiv,sVal){
	$g = SMProductLI;
	var sHTML = '';
	var sHTML2 = '';
	var aVal = sVal.split("_|_");
	var sObj = "SugPrice_" + oDiv;
	var oDate = new Date();
	var oNow = oDate.getTime();
	var iTime = parseFloat(aVal[0]);
	var iPmin = parseFloat(aVal[1].replace(",","."));
	var iTimeO = 0;
	try {
		iTimeO = parseFloat(SMShop.getAttribute(sObj));
	} catch(e) { };
	if(isNaN(iTimeO)){
		//first call -> no action
	} else if((oNow - iTimeO) < (iTime * 1000)){
		// Show Countdown;
		document.getElementById(oDiv).innerHTML = "";
		sHTML = 'CoDoSug_' + oDiv + ' = window.setInterval(\'CountdownSuggestion("' + oDiv + '","' + sVal + '")\', 1000);';
		eval(sHTML);
		sHTML2 = 'SMBasket_onBeforeAdd = function(args){alert("Die Wartezeit bis zu Ihrer nächsten Angebotsmöglichkeit ist noch nicht abgelaufen.");return(false);};';
		eval(sHTML2);
		return(false);
	};
	sHTML += '<form name="frm_PDPriceSug" id="frm_PDPriceSug">';
	sHTML += '<label name="lbl_PDPriceSug" id="lbl_PDPriceSug">Ihr Preisvorschlag:</label>';
	sHTML += '<br />';
	sHTML += '<input id="ipt_PDPriceSug" size="15">';
	sHTML += '</form>';
	document.getElementById(oDiv).innerHTML = sHTML;
	sHTML = String(SMBasket_onBeforeAdd);
	sHTML = sHTML.substring(sHTML.indexOf("{")+1,sHTML.lastIndexOf("}"));
	sHTML2 = "SMBasket_onBeforeAdd = function(args){"
	sHTML2 += "var bPriceSug = CheckPriceSuggestion(\"" + oDiv + "\",\"" + sVal + "\");";
	sHTML2 += "if(!bPriceSug){location.href = location.href;return(false);};";
	sHTML2 += sHTML + ";";
	sHTML2 += "};";
	eval(sHTML2);
};

function getProdLIDiscount(){
	var sLogin = initLogin();
	if(sLogin != 'OK'){return(-1);};
	var $g = SMProductLI;
	var iProdPrice = $g.getAttribute("OrgPriceLI");
	var iCatDiscount = parseFloat($g.getAttribute("CatDiscount"));
	if(isNaN(iCatDiscount)){iCatDiscount = 0;};
	var sProdManu = RemoveSpecialSigns(SX_uEsc($g.manufactName));
	var sProdNumber1 = RemoveSpecialSigns($g.orgCode);
	var sProdNumber2 = RemoveSpecialSigns($g.getAttribute(_SMACode));
	var sData = SMShop.getAttribute("UserDiscount");
	var aDiscounts = sData.split("_;_");
	var aFields = new Array();
	var bIsDiscounted = false;
	var bDiscountDone = false;
	var bProdNewPrice = false;
	var iProdNewPrice = 0;
	var iDiscAmntTyp1 = 0;
	var iDiscAmntTyp2 = 0;
	iDiscAmntTyp2 += iCatDiscount;
	for(var i=0; i<aDiscounts.length; i++){
		aFields[i] = aDiscounts[i].split("|");
		if(aFields[i][0].length>0){
			var aRule = aFields[i][0].split("==");
			if(aRule[0] == 'product-price-sug' && (aRule[1] == sProdNumber1 || aRule[1] == sProdNumber2)){
				$g.setAttribute("suggestion",String(aFields[i][2] + "_|_" + aFields[i][4]));
				$g.update();
				return(-1);
			};
			if(aRule[0] == 'manufacturer' && aRule[1] == sProdManu){
				bIsDiscounted = true;
			};
			if(aRule[0] == 'product' && (aRule[1] == sProdNumber1 || aRule[1] == sProdNumber2)){
				bIsDiscounted = true;
			};
			if(aRule[0] == 'product-new-price' && (aRule[1] == sProdNumber1 || aRule[1] == sProdNumber2)){
				bIsDiscounted = true;
				bProdNewPrice = true;
				iProdNewPrice = aFields[i][4];
			};
			if(aRule[0] == 'category'){
				var aCat = sProdToParentCats.split("_;_");
				var aCatDisc = new Array();
				for(var j=0; j<aCat.length; j++){
					aCatDisc[j] = aCat[j].split("_=_");
				};
				for(var j=0; j<aCat.length; j++){
					if(aRule[1] == aCatDisc[j][0] || aRule[1] == aCatDisc[j][1]){
						bIsDiscounted = true;
						break;
					};
				};
			};
			// Summiere Einzeldiskounts
			if(bIsDiscounted){
				// DiscountTyp, DiscountValue
				// Typ: 1=Fix
				//      2=%
				var iDiscType = aFields[i][3];
				var iDiscAmou = aFields[i][4];
				iDiscAmou = iDiscAmou.replace(",",".");
				iDiscAmou = parseFloat(iDiscAmou);
				if(isNaN(iDiscAmou)){iDiscAmou = 0;};
				if(iDiscType == 1){
					iDiscAmntTyp1 += iDiscAmou;
				};
				if(iDiscType == 2){
					iDiscAmntTyp2 += iDiscAmou;
				};
			};
			bIsDiscounted = false;
		};
	};
	// Typ: 1=Fix
	//      2=%
	if(iDiscAmntTyp1 > 0){
		if(bInGross() != bOutGross()){
			var iTax = getVAT();
			if(!bInGross()){
				iProdPrice = iProdPrice * (1 + iTax);
			} else {
				iProdPrice = iProdPrice / (1 + iTax);
			};
		};
		iProdPrice = iProdPrice - iDiscAmntTyp1;
		if(bInGross() != bOutGross()){
			var iTax = getVAT();
			if(!bInGross()){
				iProdPrice = iProdPrice / (1 + iTax);
			} else {
				iProdPrice = iProdPrice * (1 + iTax);
			};
		};
		if(iProdPrice < 0){iProdPrice = 0;};
		bDiscountDone = true;
	};
	if(iDiscAmntTyp2 > 0){
		iProdPrice = Math.round((iProdPrice*((100 - iDiscAmntTyp2) / 100)) / 0.01) * 0.01;
		if(iProdPrice < 0){iProdPrice = 0;};
		bDiscountDone = true;
	};
	if(bProdNewPrice){
		iProdPrice = iProdNewPrice;
		bDiscountDone = true;
	};
	if(bDiscountDone){
		return(iProdPrice);
	} else {
		return(-1);
	};
};

/*********************/
/* Basket-Procedures */
/*********************/

cSMBasket.prototype.LIreset=function(){
	var $g=this,$t=arguments,$1c=$g.base,$1k=$g.xml,$2n=($t[0])?$t[0]:false;
	//if(!$2n)$2n=$1c.raiseEvent(12,true,true,$g);
	if($2n){
		while($1k.selectNodes(_SMPrd).length()>0){
			$1k.removeChild($1k.selectSingleNode(_SMPrd));
		};
		//$g.update();
		//$1c.raiseEvent(13,false,null,$g,$2n);
	}//else $1c.raiseEvent(14,false,null,$g);
};

function LIFindHeight(){
	var y;
	if (self.innerHeight){
		y = self.innerHeight;
	}	else if (document.documentElement && document.documentElement.clientHeight){
		y = document.documentElement.clientHeight;
	} else if (document.body){
		y = document.body.clientHeight;
	};
	return(y);
};

function LIFindWidth(){
	var x;
	if (self.innerHeight){
		x = self.innerWidth;
	}	else if (document.documentElement && document.documentElement.clientHeight){
		x = document.documentElement.clientWidth;
	} else if (document.body){
		x = document.body.clientWidth;
	};
	return(x);
};

function ReloadLoginWindow(){
	location.href = location.href;	
};

function ShowAdminFrame(sURL){
	var oFrame = document.getElementsByTagName("body")[0];
	oFrame.style.overflow = "hidden";

	var oFrame = document.getElementById("SmartLogBackgroundFrame");
	var iScreenX = LIFindWidth();
	var iScreenY = LIFindHeight();
	oFrame.style.zIndex = "99999997";
	oFrame.style.position = "absolute";
	oFrame.style.left = "0px";
	oFrame.style.top = "0px";
	oFrame.style.width = String(iScreenX)+"px";
	oFrame.style.height = String(iScreenY)+"px";
	oFrame.style.backgroundImage = "url('" + sURL + "')";
	oFrame.style.backgroundRepeat = "repeat";
	oFrame.style.overflow = "hidden";

	var oFrame = document.getElementById("SmartLogAdminFrame");
	var iScreenX = LIFindWidth();
	var iScreenY = LIFindHeight();
	oFrame.style.zIndex = "99999998";
	oFrame.style.position = "absolute";
	oFrame.style.left = "0px";
	oFrame.style.top = "0px";
	oFrame.style.width = String(iScreenX)+"px";
	oFrame.style.height = String(iScreenY)+"px";
	oFrame.style.overflow = "scroll";
};

function setLogoutBackground(){  
	var sColor = "";
	try {
		sColor = SMShop.getAttribute("LIbgColor");
	} catch(e) { };
	if(sColor != ""){
		document.getElementById("divUserLogButtonsAdmin").style.backgroundColor = sColor;
	};
};
