

// define buildUp Methods for StandAloneElements
	function createLine(){
		myLine = new clsObject("OrderBody")
			myLine.LinePos						=	xmlOHeader.childNodes.length;
			myLine.ProductNo					=	"";
			myLine.Name							=	"";
			myLine.Description					=	"";
			myLine.PriceUserEntry				=	"";
			myLine.PriceUnit					=	"1";
			myLine.MinOrder						=	"1";
			myLine.QuantityUnit					=	"";
			myLine.QuantityAmount				=	"1";
			myLine.TaxClass						=	"0";
			myLine.TaxRate						=	"0";
			myLine.TaxAmountLineTotalLC			=	"0";
			myLine.TaxAmountLineTotalSC			=	"0";
			myLine.DiscountRate					=	"0";
			myLine.DiscountNetSingleUnitLC		=	"0";
			myLine.DiscountGrossSingleUnitLC	=	"0";
			myLine.DiscountNetLineTotalLC		=	"0";
			myLine.DiscountGrossLineTotalLC		=	"0";
			myLine.DiscountNetSingleUnitSC		=	"0";
			myLine.DiscountGrossSingleUnitSC	=	"0";
			myLine.DiscountNetLineTotalSC		=	"0";
			myLine.DiscountGrossLineTotalSC		=	"0";
			myLine.PriceNetSingleUnitLC			=	"0";
			myLine.PriceGrossSingleUnitLC		=	"0";
			myLine.PriceNetLineTotalLC			=	"0";
			myLine.PriceGrossLineTotalLC		=	"0";
			myLine.PriceNetSingleUnitSC			=	"0";
			myLine.PriceGrossSingleUnitSC		=	"0";
			myLine.PriceNetLineTotalSC			=	"0";
			myLine.PriceGrossLineTotalSC		=	"0";
			myLine.WeightUnit					=	"";
			myLine.WeightAmountSingleUnit		=	"0";
			myLine.WeightAmountLineTotal		=	"0";
			// remove
			myLine.addNode("Internal");
		// return Line-Object to Caller
		return myLine;
		};
// ** 0001
	function callParameters(){
		//myQueryStringData = xmlConfig.getFirstItem("QueryStringData").getValue();
		myQueryStringData = unescape(getParameterFromURL("defaultVariants"));
		if(myQueryStringData!=""&&myQueryStringData!=null){
			parameters = myQueryStringData.split("_AND_");
			};
		};
// ** 0002
function callpage(address, defValues, NavIndex){
	xmlConfig.getFirstItem("QueryStringData").putValue(defValues);
	xmlConfig.navIndex = NavIndex.toString();
	safeData();
	location.href = address;
	};
// ** 0003			
	function build(products,parIndex){
	var relProducts = new Array();
	var values = new Array();
		if (parameters.length > 0){
	  	var index = parameters[parIndex].charAt(parameters[parIndex].indexOf("_EQ_") - 1);
			var value = unescape(parameters[parIndex].substring(parameters[parIndex].indexOf("_EQ_")+4));
			// select * from products where field[index + 5] = item
			for(var i=0;i<products.length;i++){
				if(products[i][parseInt(index) + 5]==value){
					relProducts[relProducts.length] = products[i];
					};
				};
			// add values of specified item from relProducts
			for(var i=0;i<products.length;i++){
				// if values already defined
				if(values.length!=0){
					addValue = true
					for(var j=0;j<values.length;j++){
						if(products[i][parseInt(index) + 5]==values[j]){
							addValue = false;
							};
						};
					if(addValue) values[values.length] = products[i][parseInt(index) + 5]
					}
				// else add value to array
				else{
					values[values.length] = products[i][parseInt(index) + 5];
					};
				};
			// print routine
			globalValues[index] = values;
			parIndex++
			if(parIndex<parameters.length - 1){
				build(relProducts,parIndex)
				};
			};
		};

// ** 0004
function printVariants(){
var rString = "";
var u = 0;
var v = 0;
if(globalValues){
if(globalValues.length>0){
rString += "<form name=\"variants\"><tr>";
for(var i=0;i<globalValues.length;i++){
rString += "<td ><table width='180' border='0' cellspacing='1' cellpadding='1'><tr><font face='Arial' size='1'></font><td style='color:#000000;'><b><u>" + items[i] + " </b></td></tr>";
if(globalValues[i].length>0){
for(var j=0;j<globalValues[i].length;j++){
rString += "<tr><td bgcolor='#FFFFF9'><a href='javascript:resetPage("
if(i == 0)
{
w = i + 1;
x = j + 1;
y = 0;
z = 0;
}
else
{
w = i + 1;
x = j + 1;
y = u;
z = v;
};
rString += w + "," + x + "," + y + "," + z + ");' style='text-decoration:none;";
// check for selected item
var c = 0;
if(parameters.length>0)
{
for(var k=0;k<parameters.length-1;k++)
{
var parIndex = parameters[k].charAt(parameters[k].indexOf("_EQ_") - 1 );
var parValue = unescape(parameters[k].substring(parameters[k].indexOf("_EQ_")+4));
if(((parIndex==i)&&(globalValues[i][j]==parValue))||((parValue=="no"))&&(j==0)&&(i>0))
{
vario = globalValues[i][j];
globalvariant += items[i] + ";" + globalValues[i][j] + "@";
rString += "font-weight:bold;";
if(i==0)
{
u = i + 1;
v = j + 1;
}
c=1;
} 
};
};
rString += "'>";
if(c == 1)
{
rString += "<img src='assets/own/checked.gif' width='14' height='14' border='0'> ";
}
else
{
rString += "<img src='assets/own/unchecked.gif' width='14' height='14' border='0'> ";
}
rString += globalValues[i][j] + "</a></td></tr>";
};
};
rString += "</table></td>";
};
rString += "</tr></form>";
};
};
return(rString);
};



// ** 0005
function resetPage(i,j,k,l){
var pathname = "";
i--;
j--;
k--;
l--;
if(k < 0)
{
if(globalValues.length > 1)
{
var addText = "search0_EQ_" + escape(globalValues[i][j]) + "_AND_search1_EQ_no_AND_";
pathname += addText;
}
else
{
var addText = "search0_EQ_" + escape(globalValues[i][j]) + "_AND_";
pathname += addText;
}
}
else
{
var addText = "search0_EQ_" + escape(globalValues[k][l]) + "_AND_search1_EQ_" + escape(globalValues[i][j]) + "_AND_";
pathname += addText;
};
pathname += "{EOL}";
safeData();
location.replace(location.href.substring(0, location.href.indexOf("?")) + "?defaultVariants=" + escape(pathname) + "&categoryId=" + getParameterFromURL("categoryId"));
};


// ** 0006
	function detectActProd(){
		// detect values
		if(globalValues.length>0){
			for(var i=0;i<globalValues.length;i++){
				if(globalValues[i].length>0){
					var valFound = false;
					for(var j=0;j<globalValues[i].length;j++){
						// check for selected item
						if(parameters.length>0){
							for(var k=0;k<parameters.length-1;k++){
								var parIndex = parameters[k].charAt(parameters[k].indexOf("_EQ_") - 1);
								var parValue = unescape(parameters[k].substring(parameters[k].indexOf("_EQ_")+4));
								if((parIndex==i)&&(globalValues[i][j]==parValue)){
									valFound = true;
									values[i] = parValue;
									};
								};
							};
						};
					if(!valFound) values[i] = globalValues[i][0];
					};
				};
			};
		// detecting actual ProductCombination
		if(proComb.length>0){
			for(var i=0;i<proComb.length;i++){
				if(values.length>0){
					var prodFound = true;
					for(var j=0;j<values.length;j++){
						if(values[j]!=proComb[i][j+5]){
							prodFound = false
							};
						};
					if(prodFound) actualProd = proComb[i];
					}
				else{
					actualProd = proComb[0];
					};
				};
			};
		};




// ** 0007
	function Element(Prod_nr,Title,Subtitle,Price,Tax,PriceUnit,Unitdesc,Variants,LnkAdress,Discount,Minorder,catDiscount){
		this.Prod_nr = Prod_nr;
		this.Title = Title;this.Subtitle = Subtitle;
		this.Price = Price;this.Tax = Tax;
		this.PriceUnit = PriceUnit;this.Unitdesc = Unitdesc;
		this.Variants = Variants;
		this.LnkAdress = LnkAdress;
		this.Discount = Discount;
		this.Minorder = Minorder;
		this.catDiscount = catDiscount;
		};
// ** 0008
	function addToBag(anElement,Amount){
		var tmpMultiSelectValue = "";
		Amount = parseInt(Amount);
		with(this){
			var taxamount = taxarea[parseInt(xmlConfig.taxarea)][parseInt(anElement.Tax) + 1];
			var update = -1;
			myLines = xmlOHeader.childNodes
			for(var i=0;i<myLines.length;i++){
				if(myLines[i].ProductNo==actualProd[0]){
					update = i;
					break;
					};
				};
			// update user attributes
			var userAttribs = new clsObject("userAttributes");
			if(document.userAttributes){
				for(var q=0; q<document.userAttributes.elements.length; q++){
					userAttrib = userAttribs.addNode("userAttrib");
					userAttrib.type = document.userAttributes.elements[q].type;
					userAttrib.caption = encryptTextData(document.userAttributes.elements[q].name);
					if(userAttrib.type=="select-one"){
						userAttrib.value = encryptTextData(document.userAttributes.elements[q][document.userAttributes.elements[q].selectedIndex].text);
						}
					else if(userAttrib.type=="select-multiple"){
						tmpMultiSelectValue = ""; mMultipleSelectorActive = false;
						for(var i=0; i<document.userAttributes.elements[q].options.length; i++){
							if(document.userAttributes.elements[q].options[i].selected){
								tmpMultiSelectValue += encryptTextData(document.userAttributes.elements[q].options[i].text) + ", ";
								mMultipleSelectorActive = true;
								};
							};
						if(mMultipleSelectorActive){
							tmpMultiSelectValue = tmpMultiSelectValue.substring(0, tmpMultiSelectValue.length - 2);
							};
						userAttrib.value = tmpMultiSelectValue;
						}
					else{
						userAttrib.value = encryptTextData(document.userAttributes.elements[q].value);
						};
					};
				};
			// product already in shoppingcard
			if(update>-1){
				// delete product and restart AddToBag;
				var newLines = new Array();
				for(var i=0; i<myLines.length; i++){
					if(myLines[i].ProductNo!=actualProd[0]){
						newLines[newLines.length] = myLines[i];
						};
					};
				xmlOHeader.childNodes = newLines;
				addToBag(anElement, Amount);
				}
			// add product to shoppingcart
			else{
				myLine = createLine();

				// add user Attributes
				curUserAttribs = myLine.getFirstItem("userAttributes");
				if(curUserAttribs!=null) curUserAttribs = userAttribs
				else myLine.addObject(userAttribs);

					myLine.ProductNo = actualProd[0];
					myLine.Name = actualProd[1];
					myLine.Description = actualProd[2];
					myLine.QuantityAmount = Amount;
					myLine.QuantityUnit = anElement.Unitdesc;

				myInternal = myLine.getFirstItem("Internal")
myInternal.price = actualProd[3];
myInternal.address = anElement.LnkAdress;
myInternal.navIndex = getParameterFromURL("categoryId");
myInternal.discount = anElement.Discount;
myInternal.minOrder = anElement.Minorder;
myInternal.catDiscount = anElement.catDiscount;
					myVariants = "";
					if(document.variants){
						for(var i=0;i<document.variants.elements.length;i++){
							document.variants.elements[i].blur();
							myVariants += items[i] + ";" + document.variants.elements[i][document.variants.elements[i].selectedIndex].text + "@";
							};
						};
					myInternal.variants = globalvariant + "{EOL}";
myLine.WeightUnit = objWeight.charSymbol;
myLine.WeightAmountSingleUnit = actualProd[4];
myLine.TaxClass = anElement.Tax;
myLine.TaxRate = taxamount;
					
					myLine.PriceUnit = anElement.PriceUnit;
	
				if(boolPriceTaxIncl){
					myLine.PriceNetSingleUnitLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * ( 1 - taxamount/( 100 + taxamount ) ), objLeadCurrency );
					myLine.PriceNetLineTotalLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * Amount * ( 1 - taxamount/( 100 + taxamount ) ), objLeadCurrency );
					myLine.PriceGrossSingleUnitLC = TFormatCurrencyValue( parseFloat(actualProd[3]), objLeadCurrency );
					myLine.PriceGrossLineTotalLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * Amount, objLeadCurrency );
					}
				else{
					myLine.PriceNetSingleUnitLC = TFormatCurrencyValue( parseFloat(actualProd[3]), objLeadCurrency );
					myLine.PriceNetLineTotalLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * Amount, objLeadCurrency );
					myLine.PriceGrossSingleUnitLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * ( 1 + taxamount/100 ), objLeadCurrency );
					myLine.PriceGrossLineTotalLC = TFormatCurrencyValue( parseFloat(actualProd[3]) * Amount * ( 1 + taxamount/100 ), objLeadCurrency );
					};
				myLines[myLines.length] = myLine;
				};
			safeData();
			var dummyQueryString = "";
			if(myLine){
				dummyQueryString += "productId=" + myLine.ProductNo + "&quantity=" + myLine.QuantityAmount;
				};
			location.href="orderform.html?" + dummyQueryString;
			};
		};
// ** 0009
	function displPrice(anEntry){
		var taxamount = taxarea[xmlConfig.taxarea][parseInt(Product.Tax) + 1];
		if(boolDisplTaxIncl){
			if(boolPriceTaxIncl) return(anEntry[3] / Product.PriceUnit)
			else return(anEntry[3] * ( 1 + taxamount/100 ) / Product.PriceUnit);
			}
		else{
			if(boolPriceTaxIncl) return(anEntry[3] * ( 1 - taxamount/( 100 + taxamount ) ) / Product.PriceUnit)
			else return(anEntry[3] / Product.PriceUnit);
			};
		};
// **
// **
	function formatTextualCrossProductPrice(productPrice, priceUnit, productDiscount, displayMode, productTaxclass){
		return(baseFormatCrossProductPrice(productPrice, priceUnit, productDiscount, displayMode, productTaxclass, true));
		};
// **
	function formatCrossProductPrice(productPrice, priceUnit, productDiscount, displayMode, productTaxclass){
		return(baseFormatCrossProductPrice(productPrice, priceUnit, productDiscount, displayMode, productTaxclass, false));
		};
// **
	function baseFormatCrossProductPrice(productPrice, priceUnit, productDiscount, displayMode, productTaxclass, textLayout){
	var tmpValue = "";
	var taxAmount = taxarea[parseInt(xmlConfig.taxarea)][parseInt(productTaxclass) + 1];
		if(displayMode==1){
			return("");
			}
		else{
			if(!textLayout) tmpValue += "<tr><td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
			if(displayMode==0||displayMode==2){
				if(productDiscount==0){
					if(!textLayout) tmpValue += "<tr valign=\"top\">";
					if(!textLayout) tmpValue += "<td width=\"100%\" nowrap class=\"PRDETAILPROMOPRICE\">";
					if(textLayout) tmpValue += "<span nowrap class=\"PRDETAILPROMOPRICE\">";
					if(boolPriceTaxIncl&&!boolDisplTaxIncl) productPrice = productPrice * 100 / (100 + taxAmount)
					else if(!boolPriceTaxIncl&&boolDisplTaxIncl) productPrice = productPrice * ( 1 + ( taxAmount / 100 ));
					tmpValue += TFormatCurrency(productPrice / priceUnit, objPriCurrency);
					if(!textLayout){ if(boolDisplSecCurr) tmpValue += charSecCurrDelimiter + TFormatCurrency(productPrice / priceUnit, objSecCurrency) }
					else{ if(boolDisplSecCurr) tmpValue += "&nbsp;" + TFormatCurrency(productPrice, objSecCurrency) };
					if(textLayout) tmpValue += "</span>";
					if(!textLayout) tmpValue += "</td>";
					if(!textLayout) tmpValue += "</tr>";
					}
				else{
					if(!textLayout) tmpValue += "<tr valign=\"top\">";
					if(!textLayout) tmpValue += "<td width=\"100%\" nowrap class=\"PRDETAILPROMOPRICESTROKEN\">";
					if(textLayout) tmpValue += "<span nowrap class=\"PRDETAILPROMOPRICESTROKEN\">";
					if(boolPriceTaxIncl&&!boolDisplTaxIncl) productPrice = productPrice * 100 / (100 + taxAmount)
					else if(!boolPriceTaxIncl&&boolDisplTaxIncl) productPrice = productPrice * ( 1 + ( taxAmount / 100 ));
					tmpValue += TFormatCurrency(productPrice / priceUnit, objPriCurrency);
					if(textLayout) tmpValue += "</span>";
					if(!textLayout) tmpValue += "</td>";
					if(!textLayout) tmpValue += "</tr>";
					if(!textLayout) tmpValue += "<tr valign=\"top\">";
					if(!textLayout) tmpValue += "<td width=\"100%\" nowrap class=\"PRDETAILPROMOPRICE\">";
					if(textLayout) tmpValue += "<span nowrap class=\"PRDETAILPROMOPRICE\">";
					tmpValue += TFormatCurrency(productPrice * ( 1 - productDiscount / 100 ) / priceUnit, objPriCurrency);
					if(!textLayout){ if(boolDisplSecCurr) tmpValue += charSecCurrDelimiter + TFormatCurrency(productPrice / priceUnit, objSecCurrency) }
					else{ tmpValue += TFormatCurrency(productPrice * ( 1 - productDiscount / 100 ) / priceUnit, objPriCurrency) };
					if(textLayout) tmpValue += "</span>";
					if(!textLayout) tmpValue += "</td>";
					if(!textLayout) tmpValue += "</tr>";
					};
				}
			else if(displayMode==3){
				if(!textLayout) tmpValue += "<tr valign=\"top\">";
				if(!textLayout) tmpValue += "<td width=\"100%\" nowrap class=\"PRDETAILPROMOPRICE\">";
				if(textLayout) tmpValue += "<span nowrap class=\"PRDETAILPROMOPRICE\">";
				tmpValue += "Preis auf Anfrage";
				if(textLayout) tmpValue += "</span>";
				if(!textLayout) tmpValue += "</td>";
				if(!textLayout) tmpValue += "</tr>";
				};
			if(!textLayout) tmpValue += "</table></td></tr>";
			};
		return(tmpValue);
		};
// **
	function formatCrossProductVariants(txtVariants){
	var _variants = null
	var tmpHTML = "";
		tmpHTML += "<br>";
		_variants = txtVariants.split("@");
		for(var i=0; i<_variants.length - 1; i++){
			tmpHTML += ("<nobr><strong>" + _variants[i].split(";")[0] + ": " + _variants[i].split(";")[1] + "</strong></nobr>");
			if(i<_variants.length-2) tmpHTML += ", ";
			};
		return(tmpHTML);
		};
// ** 0010
	var parameters = new Array();
// ** 0011
	var values = new Array();
// ** 0012
var globalValues = new Array();
var globalvariant = "";
// ** 0013
	var proComb = new Array();
// ** 0014
	var actualProd;
// ** 0016
	callParameters();
// ** 0017
	function backToPrIndex(){
	var mCategoryId = getParameterFromURL("categoryId");
		if(mCategoryId!=""){
			location.href = navigation[parseInt(mCategoryId)].linkUrl + "?categoryId=" + mCategoryId;
			};
		};
