

/* SmartLog-Version: 4.0.0 S */

var s_glo_OldPrice = "Alter Preis:";
var s_glo_NewPrice = "Ihr Preis:";
var s_glo_YourSaving = "Sie sparen:";

function LISort1(a, b){
	var x = a[iLI2sort1];
	var y = b[iLI2sort1];
	var t1 = parseFloat(x);
	var t2 = parseFloat(y);
	return(t1 > t2 ? 1 :	t1 < t2 ? -1 : x > y ? 1 : x < y ? -1 :	0);
};
var iLI2sort1 = 0;
function LIsortAry1(aA,iField,iR){
	iLI2sort1 = iField;
	aA = aA.sort(LISort1);
	if(iR == 1) aA = aA.reverse();
	return(aA);
};

cSMBasket.prototype.LIreset=function(){
	var $g=this,$t=arguments,$1c=$g.base,$1k=$g.xml,$2n=($t[0])?$t[0]:false;
	if($2n){
		while($1k.selectNodes(_SMPrd).length()>0){
			$1k.removeChild($1k.selectSingleNode(_SMPrd));
		};
	};
};

function initLogin(){
	var sReturn = 'OK';
	var sTest_LI = '';
	sTest_LI = SMShop.getAttribute("UserLogin");
	if((sTest_LI.length==0) || (sTest_LI=="false")){
		SMShop.setAttribute("UserLogin", "false");
		SMShop.update();
		return('NO_USER');
	};
	sTest_LI = '';
	sTest_LI = SMShop.getAttribute("UserDiscount");
	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 UserLogout(){
	var sPathLogout = SMShop.getAttribute("LIuserLogoutPath");
	SMShop.basket.LIreset(true);
	SMShop.basket.update();
	SMShop.setAttribute("UserLogin", "false");
	SMShop.setAttribute("UserDiscount", "false");
	SMShop.update();
	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){
		oElem.src = sPathLogout;
	} else if(arguments.length > 0){
		var sHTML = '<iframe name="FrmSmartLogInfoLogout" id="FrmSmartLogInfoLogout" src="' + arguments[0] + '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
		document.getElementById("smartLogInfoLogout").innerHTML = sHTML;
	} else {
		location.href = location.href;
	};
};

SMShop.base.addMember("osetIframeDimensions");
function osetIframeDimensions_windowOnLoad(args){
	setIframeDimensions(false,false,false,1);
};

function setIframeDimensions(n,iAddWidth,iAddHeight,iEvent){
	if(n) SMShop.setAttribute("LI_iframeDim_n",n);
	if(iAddWidth) SMShop.setAttribute("LI_iframeDim_W",iAddWidth);
	if(iAddHeight) SMShop.setAttribute("LI_iframeDim_H",iAddHeight);
	if(! n) n = SMShop.getAttribute("LI_iframeDim_n");
	if(! iAddWidth) iAddWidth = SMShop.getAttribute("LI_iframeDim_W");
	if(! iAddHeight) iAddHeight = SMShop.getAttribute("LI_iframeDim_H");
	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) { };
};

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 printLoginButtons(sURL2){
	var sHTMLf = '';
	sHTMLf += '<div id="divUserLogButtons" align="center"><button class="LIbutLogout" name="but" type="button" value="" onclick="UserLogout()">';
	sHTMLf += '<img src="' + sURL2 + '" alt="abmelden">';
	sHTMLf += '<br>abmelden';
	sHTMLf += '</button></div>';
	document.write(sHTMLf);
};

function printLoginButtonsAdmin(sURL2){
	var sHTMLf = '';
	sHTMLf += '<div style="padding-top:10px" align="center">&nbsp;</div>';
	sHTMLf += '<div id="divUserLogButtonsAdmin" align="center">';
	sHTMLf += '<button class="LIbutLogout" type="button" onclick="UserLogout()"><img src="' + sURL2 + '" alt="abmelden">';
	sHTMLf += '<br>abmelden</button>';
	sHTMLf += '</div>';
	sHTMLf += '<div style="padding-bottom:10px" 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 += '<button class="LIbutLogout" type="button" onclick="UserLogout()"><img src="' + sURL2 + '" alt="abmelden"></button>';
	sHTMLf += '</div>';
	return(sHTMLf);
};

function RemoveSpecialSigns(sText){
	if(sText == null) return("");
	if(sText.length == 0) return("");
	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 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";
};
