/* Messages */
cookieMessage='Der IPURI Online Store ben&ouml;tigt "Cookies". Bei Ihrem Browser sind diese leider deaktiviert.\n Bitte aktivieren Sie diese und laden diese Seite erneut.<br>'
cookieMessageAlert='Der IPURI Online Store benoetigt "Cookies".\n Bei Ihrem Browser sind diese leider deaktiviert.\n Bitte aktivieren Sie diese und laden diese Seite erneut.'
oldBrowserMessage = 'Der Ipuri Online Store wird erst ab den Versionen Internet Exlorer 4.0 und Netscape 4.06 unterst&uuml;tzt.<br>'
alreadyMessage ='Dieser Artikel befindet sich schon in Ihrem Warenkorb.<br>M&ouml;chten Sie die Anzahl der Artikel auf #newAmount# erh&ouml;hen?<br>';
removeMessage='M&ouml;chten Sie diesen Artikel wirklich aus Ihrem Warenkorb l&ouml;schen?<br>';
wrongElementsMessageHeader='Bitte &uuml;berpr&uuml;fen bzw. erg&auml;nzen Sie folgende Informationen:<br><br>';
wrongDataMessageHeader = 'Bitte &uuml;berpr&uuml;fen bzw. erg&auml;nzen Sie folgende Felder:<br><br>';
missingNameMessage='<div class="warnTextBody">_<b>Artikelbezeichnung</b></div>';
missingAmountMessage='<div class="warnTextBody">_<b>St&uuml;ck</b></div>';
missingNumberMessage='<div class="warnTextBody">_<b>Bestellnummer</b></div>';
missingPriceMessage='<div class="warnTextBody">_<b>Einzelpreis</b></div>';
wrongAmountMessage='<div class="warnTextBody">_<b>St&uuml;ck</b> darf nur Zahlen und keine Buchstaben enthalten (d.h. 1,2,3...)</div>';
wrongPriceMessage='<div class="warnTextBody">_<b>Preis</b> darf nur Ziffern enthalten. Euro-Betr&auml;ge und Cent-Betr&auml;ge bitte mit einem Komma trennen (z.B. 199,90).</div>';
confusingPriceMessage = '<div class="warnTextBody">_Bitte angegebenen Preis &uuml;berpr&uuml;fen.<br>Ihre Eingabe konnte nicht verarbeitet werden.</div>'
basketEmpty = 'Ihr Warenkorb ist leider noch leer.<br>';
addedToBasketMessage = 'Wir haben den Artikel in Ihren Warenkorb gelegt.<br>Wenn Sie Artikel daraus bestellen m&ouml;chten, klicken Sie einfach <b>oben rechts</b> auf "Warenkorb".<br><br><a href="/warenkorb/warenkorb.html"><img src="/images/button_zum_warenkorb.gif" width=101 height=12 border=0 alt=""></a>';
minimumNotReached = '<div class="warnTextBody">_<b>#field#</b> enth&auml;lt zu wenig Zeichen. Dieses Feld ben&ouml;tigt mindestens <b>#minimum#</b> Zeichen.</div>';
missingChar = '<div class="warnTextBody">_<b>#field#</b> fehlt folgendes Zeichen: <b>#missing#</b></div>';
forbiddenChars = '<div class="warnTextBody">_<b>#field#</b> beinhaltet folgende unerlaubte Zeichen: <b>#forbidden#</b></div>';
requiredMessage = '<div class="warnTextBody">_<b>#field#</b></div>';
                                        
																
/*~~~~~~~*/
var warnTopForced=null;
var warnLeftFromBasketLink=100;
var gleaning = false;
var exp = new Date();
exp.setTime(exp.getTime() + (1000*60*60));
var del = new Date();
del.setTime(del.getTime() - (1000*60*60*24*365*3));

var confirmIt = false;
var versand = 4;
var finished = true;
var browser = new Browser();
function Browser()
        {
                this.version = parseFloat(navigator.appVersion);
                this.name = navigator.appName;
        }

var oldBrowser = findOldBrowser();

function findOldBrowser()
        {
                if (browser.version < 4) return true;
                if (browser.name == "Netscape" && browser.version < 4.06) return true;
                else return false;
        }

function basket()
        {
                this.items = new Array();
                this.addItem = addItem;
                this.removeItem = removeItem;
                this.setCookie = setCookie;
                this.getCookie = getCookie;
                this.total=0;
                this.updateBasket=updateBasket;
                this.updateItem = updateItem;
        }

function updateBasket()
        {
                if(!oldBrowser)
                        {
							if (document.cookie=="")
								{
									document.cookie = 'shop=empty;path=/;';
							        if(document.cookie=="") {warnTopForced=50;warn(cookieMessage);} 
								}
							else
								{
                                
                                if(document.basketForm)
                                        {
                                                self.location.reload();
                                        }
								else 
									{
										this.total=0;
                               			for (i in this.items) this.total+=convertToNumber(this.items[i].total);
                                		this.total=convertToString(Math.round(this.total * 100)/100);
										changeItemCounter(warenkorb.items.length);
										if(gleaning && halted && successful) resume();
										
									}
								}
                           }
				
			
        }

function getCookie()
        {
				
                if(document.cookie)
                        {
                                cookieString = document.cookie;
								cookieString = cookieString.substring(cookieString.indexOf("shop=")+5,cookieString.length);
                                if (cookieString != "empty")
									{
									artikel = cookieString.split('~')
	                                for (i in artikel)
	                                        {
	                                                attr = artikel[i].split('|')
	                                                this.addItem(attr[0],attr[1],attr[2],attr[3],attr[4],attr[5],attr[6],attr[7],attr[8],attr[9])
	
	                                        }
									}

                        }
				

        }

function setCookie()
        {
                var cookieString="";
                for (i in this.items)
                        {
                                cookieString += this.items[i].identity + '|' + this.items[i].description + '|' + this.items[i].amount + '|' + this.items[i].posSizes + '|' + this.items[i].posColors + '|' + this.items[i].numberArray + '|' + this.items[i].priceArray + '|' + this.items[i].selectedColor + '|' + this.items[i].selectedSize +  '|' + this.items[i].changeable + '~';
                        }
                if (cookieString != "") document.cookie = "shop=" + cookieString.substring(0,cookieString.length-1) + ';path=/;'//expires=' + exp; 
				else document.cookie = 'shop=empty;path=/;'//expires=' + exp; 
                if(cookieString!="" && document.cookie=="") alert(cookieMessageAlert);
                               
        }
var warnString="";
var successful = false;
function addItem(identity,description,amount,size,color,number,price,selectedColor,selectedSize,changeable,replace)
        {
               	successful = false;
				if(!oldBrowser)
                        {
                                warnString="";
                                if(!identity) warnString+=missingNameMessage;
                                if(!amount) warnString+=missingAmountMessage;
                                if(!number) warnString+=missingNumberMessage;
                                if(!price) warnString+=missingPriceMessage;
                                if((wrongChars=checkValue(amount,"ziffer"))!="") warnString+=wrongAmountMessage;
                                if((wrongChars=checkValue(price,"preis,ziffer"))!="") warnString+=wrongPriceMessage;
                                if(warnString!="")
                                        {
                                                warn(wrongElementsMessageHeader + warnString);
                                                return;
                                        }

                                var posSizes = new Array();
                                if (size)
                                        {
                                                if(browser.version >= 5 && browser.name == "Netscape")
                                                        {
                                                                if(size[0].value)for (s=0;s<size.length;s++) posSizes[s] = size[s].value;
                                                                else posSizes = size.split(',');
                                                        }
                                                else
                                                        {
                                                                if(size.type=="select-one") for (s=0;s<size.length;s++) posSizes[s] = size[s].value;
                                                                else posSizes = size.split(',');
                                                        }
                                        }
                                 else posSizes[0] = "";
                                var posColors = new Array();
                                if (color)
                                        {
                                                if(browser.version >= 5 && browser.name == "Netscape")
                                                        {
                                                                 if(color[0].value)for (c=0;c<color.length;c++) posColors[c] = color[c].value;
                                                                 else posColors = color.split(',');
                                                        }
                                                else
                                                        {
                                                                if(color.type=="select-one") for (c=0;c<color.length;c++) posColors[c] = color[c].value;
                                                                else posColors = color.split(',');
                                                        }
                                        }
                                 else posColors[0] = "";
								
								var nr1=(number.indexOf('_')!=-1)?(splitVariable(number,selectedSize)):(number);
								var pr1 = (price.indexOf('_')!=-1)?(splitVariable(price,selectedSize)):(price);
							
                                for (i in this.items)
                                        {
												var nr2 =(this.items[i].numberArray.indexOf('_')!=-1)?(splitVariable(this.items[i].numberArray,selectedSize)):(this.items[i].numberArray);
												var pr2 = (this.items[i].priceArray.indexOf('_')!=-1)?(splitVariable(this.items[i].priceArray,selectedSize)):(this.items[i].priceArray);
												
                                                if(this.items[i].identity == identity && this.items[i].size  == posSizes[selectedSize] && this.items[i].color  == posColors[selectedColor] &&  nr2  == nr1 && pr2 == pr1 && this.items[i].description == description)
                                                        {
															
                                                                confirmString =alreadyMessage.replace('#newAmount#', this.items[i].amount + eval(amount));
                                                                funktion = 'increaseItem(warenkorb.items[' + i + '],' + amount + ',\'' + replace +'\')';
                                                                ask(confirmString,funktion);
                                                                return;
                                                              
                                                        }
                                        }
				
                                        if(replace || replace==0) this.updateItem(identity,description,amount,posSizes,posColors,number,price,selectedColor,selectedSize,replace);
                                        else this.items[this.items.length] = new item(identity,description,amount,posSizes,posColors,number,price,this,this.items.length,selectedColor,selectedSize,changeable);
										
										if (confirmIt) 
											{
												confirmMessage = addedToBasketMessage.replace('#item#',identity);
												warn(confirmMessage);
												confirmIt = false;
											}
                                        this.updateBasket();
										successful = true;
                        }
                else warnOldBrowsers();
        }

function updateRow(which)
        {
                var formular = document.basketForm;
                size=(formular.elements['size' + which].type == "select-one")?(formular.elements['size' + which].options):(formular.elements['size' + which].value);
                sizeIndex=(formular.elements['size' + which].type == "select-one")?(formular.elements['size' + which].selectedIndex):(0);
                color=(formular.elements['color' + which].type == "select-one")?(formular.elements['color' + which].options):(formular.elements['color' + which].value);
                colorIndex=(formular.elements['color' + which].type == "select-one")?(formular.elements['color' + which].selectedIndex):(0);
                identity = formular.elements['identity' + which].value
                description = ""//formular.elements['description' + which].value
                amount = formular.elements['amount' + which].value
                number =formular.elements['number' + which].value
                price =formular.elements['price' + which].value
                changeable = warenkorb.items[which].changeable;
                warenkorb.addItem(identity,description,amount,size,color,number,price,colorIndex,sizeIndex,changeable,which);

        }

function updateItem(identity,description,amount,posSizes,posColors,number,price,selectedColor,selectedSize,which)
        {
				 this.items[which].identity = identity;
                 this.items[which].description = description;
                 this.items[which].amount = amount;
                 this.items[which].posSizes = posSizes;
                 this.items[which].posColors = posColors;
				 this.items[which].numberArray = number;
                 this.items[which].number = number;
				 this.items[which].priceArray = price;
                 this.items[which].price = price;
                 this.items[which].selectedColor = selectedColor;
                 this.items[which].selectedSize = selectedSize;
                 this.updateBasket();
        }

function removeItem(which,dontAsk)
        {
                if (!dontAsk)
                        {
                                confirmString = removeMessage;
                                funktion = 'removeConfirm(' + which + ')';
                                ask(confirmString,funktion);
                                return;
                        }

                which=eval(which)

                var newCounter = 0;
                var newItems = new Array();
                for (i in this.items)
                        {
                                var nr = eval(i)
                                if(this.items[i].identity != which && nr != which)
                                        {
                                                newItems[newCounter] = this.items[i];
                                                newCounter++;
                                        }
                        }
                this.items = newItems;
                this.updateBasket();
        }

function item(identity,description,amount,size,color,number,price,basket,nr,selectedColor,selectedSize,changeable)
        {
                this.changeable = changeable;
                this.amount=eval(amount);
                this.posSizes = size;
                this.selectedColor = selectedColor;
                this.selectedSize = selectedSize;
                this.size=(size[selectedSize])?(size[selectedSize]):("");
                this.posColors = color;
                this.color=(color[selectedColor])?(color[selectedColor]):("");
				this.numberArray = number;
				this.priceArray = (price.indexOf('_')!=-1)?(price):(convertToString(convertToNumber(price)));
                this.number=(number.indexOf('_')!=-1)?(splitVariable(number,selectedSize)):(number);
				this.price = (price.indexOf('_')!=-1)?(splitVariable(price,selectedSize)):(price);
				this.price = convertToString(convertToNumber(this.price));
                this.total = convertToString(convertToNumber(this.price) * this.amount);
                this.description=description;
                this.identity = identity;
                this.basket = basket;
                this.nr = nr;
                this.changeAmount = changeAmount;
        }

function splitVariable(which,index)
	{
		var multiple = which.split('_');
		return multiple[index];
	}

function changeAmount(amount)
        {
                warnString="";
                if((wrongChars=checkValue(amount,"ziffer"))!="") warnString+=wrongAmountMessage;
                if(warnString!="")
                        {
                                warn(wrongElementsMessageHeader + warnString);
                                return;
                        }
                amount = eval(amount);
                if(amount == 0)
                        {
                                this.basket.removeItem(this.nr);
                                return;
                        }
                else
                        {
                                this.amount = amount;
                                this.total = convertToString(convertToNumber(this.price) * this.amount);
                                this.basket.updateBasket();
                        }
        }

function convertToNumber(what)
                {
                        what = filterPrice(what);
                        what = what + '';
                        if (what.indexOf(',')!=-1) what = what.replace(',',".")
                        what = eval(what);
                        return what;
                }

        function convertToString(what)
                {
                        what = what + '';
                        if (what.indexOf('.')!=-1)
                                {
                                        what1 = what.substring(0,what.indexOf('.'));
                                        what2 =what.substring(what.indexOf('.')+1,what.length);
                                        what=what1 + ',' + what2;
                                        if(what.indexOf(',')==(what.length-2)) what+="0";
                                        if(what.indexOf(',')<(what.length-3)) what = what.substring(0,what.indexOf(',') + 3);
                                }
                        else what+=",00";
                        if(what.indexOf(',')>=5)
                                {
                                        what1 = what.substring(0,what.indexOf(',')-3);
                                        what2 =what.substring(what.indexOf(',')-3,what.length);
                                        what=what1 + '.' + what2;
                                }
                        if(what.indexOf(',')>=8)
                                {
                                        what1 = what.substring(0,what.indexOf(',')-7);
                                        what2 =what.substring(what.indexOf(',')-7,what.length);
                                        what=what1 + '.' + what2;
                                }
                        return what;
                }

function filterPrice(price)
        {
				while (price.match(',')) price = price.replace(',',".")
                if (price.indexOf('.') != -1)
                        {
                                var m = price.indexOf('.');
                                var end = price.lastIndexOf('.');

                                while (m <= end && m != -1)
                                        {

                                                
												if(price.indexOf('.')<(price.length-3) || price.lastIndexOf('.')!=price.indexOf('.'))
                                                        {
                                                                price1 = price.substring(0,price.indexOf('.'));
                                                                price2 =price.substring(price.indexOf('.')+1,price.length);
                                                                price=price1  + price2;
                                                                m = price.indexOf('.');
                                                        }
												
                                                else m=-1;
												//alert(price)
                                        }
									
                        }
/*
                if (price.indexOf(',') != -1)
                        {
                                if(price.indexOf(',')<(price.length-3))
                                        {
                                                if (price.indexOf('.')<(price.length-3))
                                                        {
                                                                warn(confusingPriceMessage + '\n' + price)
                                                        }
                                                price1 = price.substring(0,price.indexOf(','));
                                                price2 =price.substring(price.indexOf(',')+1,price.length);
                                                price=price1  + price2;
                                        }
                        }
*/
                return price;
        }

var warenkorb = new basket();

function warnOldBrowsers()
        {
                alert(oldBrowserMessage)
        }

function checkBasket()
        {
				
                if(warenkorb.total!=0) 
					{
						var persDataUrl = 'https://www.ipuri.de/warenkorb/order/step_one.html?' + escape(document.cookie.substring(document.cookie.indexOf('shop=')+5,document.cookie.length));
						//var persDataUrl = '/warenkorb/order/step_one.html?' + escape(document.cookie.substring(document.cookie.indexOf('shop=')+5,document.cookie.length));
						self.location.href = persDataUrl;
					}
                else warn(basketEmpty);
				
        }




function warn(message)
        {
                okButton = okButtonTemplate.replace('#text#','Close');
                okButton = okButton.replace('#function#','');
                okButton = okButton.replace('#value#','true');
                warning = warnTemplate;
				if (document.documentElement) 
					{
						if (document.getElementById('yesBut')) document.getElementById('yesBut').innerHTML = '';
						if (document.getElementById('noBut')) document.getElementById('noBut').innerHTML = '';
						if (document.getElementById('okBut')) document.getElementById('okBut').innerHTML = okButton;
						if (document.getElementById('wText')) document.getElementById('wText').innerHTML = message;
					}
				else
					{
                		while(warning.match('#message#')) warning=warning.replace('#message#',message);
               	 		while(warning.match('#yesButton#')) warning=warning.replace('#yesButton#',"");
               	 		while(warning.match('#okButton#')) warning=warning.replace('#okButton#',okButton);
               	 		while(warning.match('#noButton#')) warning=warning.replace('#noButton#',"");
					}
				
                showMessage();
        }


var schalter = false;

function ask(message,funktion)
        {
                answer = null;
                warning = warnTemplate;
                jaButton = yesButtonTemplate.replace('#text#','Ja');
                jaButton = jaButton.replace('#function#',funktion);
                jaButton = jaButton.replace('#value#','true');

                neinButton = noButtonTemplate.replace('#text#','Nein');
                neinButton = neinButton.replace('#function#',funktion);
                neinButton = neinButton.replace('#value#','false');
				if (document.documentElement)  
					{
						
						if (document.getElementById('yesBut')) document.getElementById('yesBut').innerHTML = jaButton;
						if (document.getElementById('noBut')) document.getElementById('noBut').innerHTML = neinButton;
						if (document.getElementById('okBut')) document.getElementById('okBut').innerHTML = '';
						if (document.getElementById('wText')) document.getElementById('wText').innerHTML = message;
					}	
              else
			  	{
				    while(warning.match('#message#')) warning=warning.replace('#message#',message);
	                while(warning.match('#yesButton#')) warning=warning.replace('#yesButton#',jaButton);
	                while(warning.match('#okButton#')) warning=warning.replace('#okButton#',"");
	                while(warning.match('#noButton#')) warning=warning.replace('#noButton#',neinButton);
              	}
				
			    showMessage();

        }

function increaseItem(which,amount,replace)
        {
				successful=true;
				hideMessage();
                if (replace == "undefined") replace = null;
                else eval(replace);
                if(schalter)
                        {
                                which.changeAmount(which.amount + eval(amount));
                                if(replace || replace==0) warenkorb.removeItem(replace,true);
                                warenkorb.updateBasket();
                        }
                else warenkorb.updateBasket();
				
        }

function removeConfirm(which)
        {
				successful=true;
				hideMessage();
			    if(schalter) warenkorb.removeItem(which,true);
                else warenkorb.updateBasket();
				
        }
var warnTop=0;
function showMessage()
        {
				if(document.all)
                        {
							if(document.all.warnLayer)
								{
                                if (!document.getElementById)  document.all.warnLayer.innerHTML = warning;
                                document.all.warnLayer.style.left = (document.all.tags("TABLE")[0].offsetLeft+document.all.tags("TABLE")[0].offsetWidth-80)-warnLeftFromBasketLink;
                                document.all.warnLayer.style.top = (warnTopForced)?(warnTopForced):(warnTop);//document.body.scrollTop + parseInt((document.body.offsetHeight/2)-(document.all.warnLayer.offsetHeight/2));
								if (navigator.userAgent.indexOf('Mac')==-1)	document.all.warnLayer.style.setAttribute("filter","Alpha(opacity=95, finishopacity=85, style=2)","false");
								document.all.warnLayer.style.visibility = "visible"; 
								}
                        }
                else if(document.layers)
                        {
							if(document.warnLayer)
								{
                                document.warnLayer.document.open();
                                document.warnLayer.document.write(warning);
                                document.warnLayer.document.close();
                                document.warnLayer.left = document.basketLink.x-warnLeftFromBasketLink;
                                document.warnLayer.top = (warnTopForced)?(warnTopForced):(warnTop);//top.pageYOffset + parseInt((window.innerHeight/2)-(document.warnLayer.clip.height/2));
                                document.warnLayer.visibility = "show";
								}
                        }
				else if(document.documentElement)
                        {
							if(document.getElementById('warnLayer'))
								{
								var wLayer = document.getElementById('warnLayer');                               
								wLayer.style.left = document.basketLink.offsetLeft-warnLeftFromBasketLink;
                                wLayer.style.top = (warnTopForced)?(warnTopForced):(warnTop);
								wLayer.style.visibility = "visible";
								}
                        }
        }
		
if(!document.all)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = findY;
function findY(e)
	{
		if(!document.all)warnTop = e.y - 150;
		else {
			e=window.event;
			warnTop = e.clientY + document.body.scrollTop - 150;
			}
	}

function hideMessage()
        {
				if(document.all)
                        {
								if (navigator.userAgent.indexOf('Mac')==-1)	document.all.warnLayer.style.removeAttribute("filter","false");
								document.all.warnLayer.style.visibility = "hidden";
								if (!document.getElementById) document.all.warnLayer.innerHTML = "";
                        }
                else if(document.layers)
                        {
                                document.warnLayer.document.open();
                                document.warnLayer.document.write("");
                                document.warnLayer.document.close();
                                document.warnLayer.visibility = "hide";
                        }
				else if(document.documentElement)
                        {
                                document.getElementById('warnLayer').style.visibility = "hidden";
                        }
        }
		
function changeItemCounter(amount)
	{
		if (document.layers)
			 {
			 	if (document.layers.artikelZaehler)
					{
						document.layers['artikelZaehler'].left = document.images.basketLink.x + document.images.basketLink.width + 5;
						document.layers['artikelZaehler'].top = document.images.basketLink.y + 2;
		
					 	document.layers['artikelZaehler'].document.open();
						document.layers['artikelZaehler'].document.write('<span class="counter">' + amount + '</span>');
						document.layers['artikelZaehler'].document.close();
					}
			 }
			 
		else if (document.getElementById)
			{
				if (document.getElementById('artikelZaehler'))
					{
						obj = document.getElementById('artikelZaehler');
						nr = document.createTextNode(amount);
						obj.replaceChild(nr,obj.childNodes[0]);
					}
			} 
		
		else if (document.all)
			{
				if (document.all.artikelZaehler) document.all.artikelZaehler.innerText =amount;
			}
	}
	
function filterForm(which)
	{
		var identity = which.identity.value;
		var description = (which.description)?(which.description.value):("");
		var amount = (which.amount)?(which.amount.value):("");
		var size = "";
		var sizeIndex = 0;
		if(which.size)
			{
				if (which.size.type=="select-one")
					{
						size = which.size.options;
						sizeIndex=which.size.selectedIndex;
					}
				else size = which.size.value;
			}
		var color = "";
		var colorIndex = 0;
		if(which.color)
			{
				if (which.color.type=="select-one")
					{
						color = which.color.options;
						colorIndex=which.color.selectedIndex;
					}
				else color = which.color.value;
			}
		
		var number = (which.number)?(which.number.value):("");
		var price = (which.price)?(which.price.value):("");
		
		warenkorb.addItem(identity,description,amount,size,color,number,price,colorIndex,sizeIndex);
	}
	
function makeNew(init) 
{ 
  if (init==true) 
  	{
    	document.pageWidth=window.innerWidth; 
		document.pageHeight=window.innerHeight;  
		window.onresize=makeNew;		
	}
  else if (window.innerWidth != document.pageWidth || window.innerHeight != document.pageHeight) self.location.reload();
}

if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==4)) makeNew(true);

	
