

/********************/
/* 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("");
};

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

function UserLogout(){
	var sPathLogout = SMShop.getAttribute("LIuserLogoutPath");
	SMShop.basket.LIreset(true);
	SMShop.basket.update();
	SMShop.setAttribute("UserLogin", "false");
	SMShop.setAttribute("UserDiscount", "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){
		var oElem = document.getElementById("smartLogOut");
		if(!oElem){
			location.href = location.href
			return(true);
		} else {
			oElem.innerHTML = '<iframe name="smartLog" id="smartLog" src="' + sPathLogout + '" scrolling="no" frameborder="0"></iframe>';
		};
	} else {
		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 #2F5770;">';
	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);
	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){
				} 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(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){
		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){
			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,"Sie erhalten keine Rabatte.");
	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 += 'Sie erhalten keine Rabatte. Wenn Sie an einer persönlichen Rabatt-Staffelung interessiert sind, _START_LINK_setzen Sie sich bitte mit uns in Verbindung_END_LINK_.';
	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)){
		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]) + "%";
		};
		if(String(aFields[3]) == "1"){
			aFields[3] = "Fester Wert";
		} else if(String(aFields[3]) == "2"){
			aFields[3] = "Rabatt %";
		};
		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);
	return(true);
};

function printLoginDiscountsSummary(sLink){
	var sHTMLb = '';
	sHTMLb += '<br>Sie erhalten keine Rabatte. Wenn Sie an einer persönlichen Rabatt-Staffelung interessiert sind, _START_LINK_setzen Sie sich bitte mit uns in Verbindung_END_LINK_.';
	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)){
		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]) + "%";
		};
		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]=="spaceline"|| aRule[0]=="spaceline2" || aRule[0]=="spaceline3"){
			sHTMLb += '';
		} else {
			sHTMLb += '<p>' + aFields[5] + ':<br>ab ' + aFields[2] + ' Warenwert: ' + aFields[4] + '</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();
	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();
	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 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 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 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] == 'manufacturer' && aRule[1] == sProdManu){
				bIsDiscounted = true;
			};
			if(aRule[0] == 'product' && (aRule[1] == sProdNumber1 || aRule[1] == sProdNumber2)){
				bIsDiscounted = true;
			};
			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;
	};
};

