////////////////////////////////////////////////////////////////
//
// Weblication® CMS Shop
// erstellt durch Scholl Communications AG, 77694 Kehl, www.scholl.de
// erstellt mit Weblication® Content Management Server, www.weblication.de
// Stand: Mai 2004
//
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Anzupassende Variablen:
//
// Vorlage fuer den Kopf der Bestellung
var orderHeaderTpl  = '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="shopping_cart">'+
                        '<tr>'+
                          '<th width="100" align="center" valign="top">Menge</th>'+
                          '<th width="220" align="left" valign="top">Bezeichnung</th>'+
                          '<th width="100" align="right" valign="top">Preis</th>'+
                          '<th width="150" align="right" valign="top">Gesamt</th>'+
                          '<th width="30">&nbsp;</td>'+
                        '</tr>';
//
// Zeilenvorlage eines Produktes in der Bestellung
var orderProductTpl  = '<tr>'+
                         '<td  width="30" align="center" valign="top"><input type="text" name="productAmount" value="$amount" onBlur="setProduct(\'$productId\', this.value,\'$productUrlName\',\'\');" style="width:32px;text-align:right;padding-right:2px"></td>'+
                         '<td width="255" align="left" valign="top"><h3>$productName</h3></td>'+
                         '<td width="70" align="right" valign="top">$price €</td>'+
                         '<td width="70" align="right" valign="top">$sum €</td>'+
                         '<td width="35" align="right" style="text-align:right;padding-right:2px;" valign="top"><input type="hidden" name="product_$productName_$productId" value="(Art.Nr. $productId) $productMeta1 $productMeta2 $amount Stueck à $price = $sum">'+
                           '<table cellpadding="4" cellspacing="0" border="0" width="98%">'+
                             '<tr>'+

                               '<td class="border" width="34%" align="right" style="text-align:right;"><a class="textDecorationNone" href="javascript:clearProduct(\'$productId\');" title="Produkt löschen"><img src="/wDeutsch/shop/img/loeschen.gif" title="Produkt löschen" alt="Produkt löschen" border="0" style="border-style:solid;border-width:1px;border-color:#000000;"></a></td>'+
                             '</tr>'+
                           '</table>'+
                         '</td>'+
                       '</tr>';
//
// Vorlage fuer die Summe der Bestellung
var orderSumNettoTpl = '<tr>'+
                         '<td class="text">&nbsp;</td>'+
                         '<td>Summe Netto</td>'+
                         '<td>&nbsp;</td>'+
                         '<td align="right" >$ordersum €<input type="hidden" name="orderSum" value="$ordersum"></td>'+
                         '<td>&nbsp;</td>'+
                       '</tr>';
//
// Vorlage fuer die Summe der Mehrwertsteuer
var orderSumTaxTpl = '<tr>'+
                       '<td class="border">&nbsp;</td>'+
                       '<td align="left" class="border">enthaltene 19% MwSt.</td>'+
                       '<td class="border">&nbsp;</td>'+
                       '<td align="right" class="border">$ordersumtax €<input type="hidden" name="orderSumTax" value="$ordersumtax"></td>'+
                       '<td class="border">&nbsp;</td>'+
                     '</tr>';
//
// Vorlage fuer die Summe der Bestellung
var orderSumBruttoTpl = '<tr>'+
                          '<td >&nbsp;</td>'+
                          '<td align="left"  style="padding-top:16px;"><strong>Gesamtbetrag (inkl. MwSt.)</strong></td>'+
                          '<td >&nbsp;</td>'+
                          '<td align="right" style="padding-top:16px;"><strong>$ordersum €</strong><input type="hidden" name="orderSum" value="$ordersum"></td>'+
                          '<td >&nbsp;</td>'+
                        '</tr>';
//
// Vorlage fuer den Fuss der Bestellung
var orderFooterTpl  = '</table>';
//
// Sind Preise Brutto [0|1] (0=Nettopreise, 1=Bruttopreise)
var productPricesBrutto = 0;
//
// Mindestbestellwert
var minOrderValue = 10;
//
// Ausgabe Mindestbestellwert
var minOrderTpl   = '<div class="fragmentWarningshop s_mg_t">Der Mindestbestellwert beträgt ' + minOrderValue + ',00 €!</div>';
//
// Ausgabe Mindestbestellwert in JavaScript Dialogfenster 
var minOrderAlert = 'Der Mindestbestellwert beträgt ' + minOrderValue + ',00 €!';
//
// Versandkostenmatrix           (Versandkosten, Wertuntergrenze, Wertobergrenze)
var freightCharges    = new Array()
    freightCharges[0] = new Array(5.95         ,  0              , 20);
    freightCharges[1] = new Array(3.95         , 20              , 50);
    freightCharges[2] = new Array(0            , 50              , 999999);
//
// Ausgabe Versandkosten
var freightChargesTpl = '<!-- <tr>'+
                          '<td >&nbsp;</td>'+
                          '<td align="left" >Versandkosten</td>'+
                          '<td >&nbsp;</td>'+
                          '<td  align="right">$freightCharges €<input type="hidden" name="freightChargesValue" value="$freightChargesValue"></td>'+
                          '<td >&nbsp;</td>'+
                        '</tr> -->';
//
// Mehrwehrtsteuersatz in Prozent
var taxValuePercent = 19;
//
// Anzeige von Preisen ohne Nachkommaangabe
var stringNoCent = ".00";
//
// Kleinster Wert auf den bei der MwSt gerundet werden soll
var roundValue = 0.01;
//
//erscheint wenn ein Pflichtfeld nicht ausgefüllt wurde
var messageObligation = " ist ein Pflichtfeld!\n"; 
//
//Id des Shops
var shopId = 'wShop';
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Globale Variablen (nicht ändern)
//
////////////////////////////////////////////////////////////////
//
var isMinOrderValue = "";
//
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Beschreibung: Zeigt den Inhalt des Warenkorbs an
//
////////////////////////////////////////////////////////////////

function showProducts(){
  showBasketInfo();
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Zeigt den Inhalt des Warenkorbs an
//
////////////////////////////////////////////////////////////////

function getBasketInfo(info){
  return showBasketInfo(info, 'return');
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Zeigt Informationen zum Warenkorb an
//
////////////////////////////////////////////////////////////////

  function showBasketInfo(info, option){

    var productStr = getCookie(shopId);
    var productRowTmp;
    var numberProducts = 0;
    var numberProductsTimeout = 64;

    if(! info){
      info = "";
    }  
    
    var entry = productStr;
  
    var productId      = "";
    var productName    = "";
    var productUrlName = "";
    var productMeta1   = "";
    var productMeta2   = "";
    var productAmount  = 1;
    var productPrice   = 0;    
    var productSum     = 0;
    var orderSum       = 0;
    var orderSumNetto  = 0;
    var orderSumBrutto = 0;    
    var orderSumTax    = 0;
    var productPricePrint = 0;
    var productSumPrint = 0;
    var i = 0;

    if(info == ""){                      
      document.write(orderHeaderTpl);    
    }  
  
    var products = productStr.split('~~~');
    
    for(var i = products.length - 1; i >= 0; i--){
      if(products[i] != ''){
        entry      = products[i].replace(/p:/, '');    
        //alert(entry);  
      
        productId     = entry.replace(/^([^\~]+)\~___.*/, '$1');
        if(productId == entry){
          productId = "";
        }
        productAmount = entry.replace(/.*\~___([^\~]+)\~__-.*/, '$1');    
        if(productAmount == entry){
          productAmount = "";
        }   
           
        productName   = entry.replace(/.*\~__-([^\~]+)\~_-_.*/, '$1');
        if(productName == entry){
          productName = "";
        }
        else
        {
         productName = productName.replace('%26','&');
        }
           
        productUrlName   = entry.replace(/.*\~__-([^\~]+)\~_-_.*/, '$1');
        if(productUrlName == entry){
          productUrlName = "";
        } 
        else
        {
         productUrlName = escape(productUrlName);
         productUrlName = productUrlName.replace('%27','\\\'');
        }
        
        productPrice  = entry.replace(/.*\~_-_([^\~]+)\~_--.*/, '$1');    
        if(productPrice == entry){
          productPrice = "";
        }    
        productMeta1  = entry.replace(/.*\~_--([^\~]+)\~-_-.*/, '$1');    
        if(productMeta1 == entry){
          productMeta1 = "";
        } 
        productMeta2  = entry.replace(/.*\~-_-([^\~]+)\~--_.*/, '$1');    
        if(productMeta2 == entry){
          productMeta2 = "";
        } 
        if(productPrice != ""){
          productPrice  = productPrice.replace(/\,/, ".");
          productPrice  = Math.round(parseFloat(productPrice)* 100)/100;
          productSum    = Math.round(productPrice * parseFloat(productAmount) * 100)/100;;
        }
        
        if(entry != "" && productPrice.toString() != ""){
          productPricePrint  = convertPrice(productPrice);    
          productSumPrint    = convertPrice(productSum);        
          productRowTmp = orderProductTpl.replace(/\$productId/g, productId);
          productRowTmp = productRowTmp.replace(/\$productName/g, productName);
          productRowTmp = productRowTmp.replace(/\$productUrlName/g, productUrlName);
          productRowTmp = productRowTmp.replace(/\$amount/g, productAmount);
          productRowTmp = productRowTmp.replace(/\$price/g, productPricePrint);
          productRowTmp = productRowTmp.replace(/\$sum/g, productSumPrint);    
          productRowTmp = productRowTmp.replace(/\$productMeta1/g, productMeta1); 
          productRowTmp = productRowTmp.replace(/\$productMeta2/g, productMeta2);     
          if(info == ""){
            document.write(productRowTmp);
          }  
          orderSum += productSum;
          if(entry != ""){
            numberProducts += parseInt(productAmount);
          }              
        }      
      }
    } 
    
    if(productPricesBrutto == 0){
      checkMinOrderValue(orderSum * (100 + taxValuePercent) / 100);
      if(info == "" && orderSum != 0){  
        if(freightCharges.length != -1){
          orderSum = orderSum + getFreightCharge(orderSum);
        }  
      }
      orderSumNetto = orderSum;
      orderSumNetto = convertPrice(orderSumNetto);    
      orderSumNettoTpl = orderSumNettoTpl.replace(/\$ordersum/g, orderSumNetto); 

      orderSumTax = orderSum * taxValuePercent / 100;
      orderSumTax = convertPrice(orderSumTax);
      orderSumTaxTpl = orderSumTaxTpl.replace(/\$ordersumtax/g, orderSumTax);        
    
      orderSumBrutto = orderSum * (100 + taxValuePercent) / 100;
      orderSumBrutto = convertPrice(orderSumBrutto);    
      orderSumBruttoTpl = orderSumBruttoTpl.replace(/\$ordersum/g, orderSumBrutto);    

      if(info == ""){      
        if(orderSum != 0){
          document.write(getFreightChargesTpl(orderSum));  
        }
        document.write(orderSumNettoTpl);    
        document.write(orderSumBruttoTpl);
        document.write(orderSumTaxTpl);   
      }  
    }
    else{
      checkMinOrderValue(orderSum);
      var freightChargesTemplate = getFreightChargesTpl(orderSum);
      if(info == "" && orderSum != 0){ 
        if(freightCharges.length != -1){
          orderSum = orderSum + getFreightCharge(orderSum);
        }
      }
      orderSumTax = orderSum / (100 + taxValuePercent) * taxValuePercent;
      orderSumTax = convertPrice(orderSumTax);
      orderSumTaxTpl = orderSumTaxTpl.replace(/\$ordersumtax/g, orderSumTax);        
    
      orderSumBrutto = orderSum;
      orderSumBrutto = convertPrice(orderSumBrutto);    
      orderSumBruttoTpl = orderSumBruttoTpl.replace(/\$ordersum/g, orderSumBrutto);    

      if(info == ""){ 
        if(orderSum != 0){
          document.write(freightChargesTemplate); 
        }   
        document.write(orderSumBruttoTpl);
        document.write(orderSumTaxTpl);    
      }  
    }    
    
    if(info == ""){                      
      document.write(orderFooterTpl);
      if(isMinOrderValue == false){
        document.write(minOrderTpl);
      }  
    }  
    else if(info == "numberProducts"){    
      if(option == "return"){                  
        return numberProducts;
      }
      else{
        document.write(numberProducts);      
      }  
    }      
    else if(info == "sumBrutto"){                      
      if(option == "return"){                  
        return orderSumBrutto;
      }
      else{
        document.write(orderSumBrutto);
      }        
    }       
  }      
    
////////////////////////////////////////////////////////////////
//
// Beschreibung: Konvertiert die Preise
//
////////////////////////////////////////////////////////////////  
  
  function convertPrice(price){

    price = Math.round(price * 100)/100;  
    
    if(parseInt(roundValue) != 0){
      var convertedRoundValue = 1 / roundValue;
      price = parseInt(price * convertedRoundValue + 0.5) / convertedRoundValue;
    }

    var priceInt = parseInt(price);

    
    if(price == priceInt){
      price += stringNoCent;    
      return price;
    }
   
    var testPrice = /\.(\d+)$/;
    testPrice.test(price);
    var result = RegExp.$1;
    if(result == ""){
      price += stringNoCent;
    }
    else if(result.length == 1){
      price += "0";
    }
    return price;
  }
  
////////////////////////////////////////////////////////////////
//
// Beschreibung: Fuegt ein neues Produkt dem Warenkorb hinzu
//
////////////////////////////////////////////////////////////////

  function addProduct (productId, productAmount, productName, productPrice, productMeta1, productMeta2){
  
    var productStr = getCookie(shopId);
    productName = productName.replace('%27','\'');
    //productName = productName.replace(/\+/,' ');
    productName = productName.replace(/\+/g,' ');
    
    if(!productMeta1){
      productMeta1 = '';
    }
    if(!productMeta2){
      productMeta2 = '';
    }
    
    if(isNaN(productAmount) == true || productAmount < 1){
      return;
    }
    
    var regExpStr;
    var existsProduct = new RegExp(":" + productId + "~___");
    if(existsProduct.test(productStr) == true){
      var numberProductsBasket    = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
      numberProductsBasket    = numberProductsBasket.replace(/.*\~\~\~\~\~\~\~\~/, "");    
      numberProductsBasket    = numberProductsBasket.replace(/^(\d+).*/, '$1');        

      var numberProductsBasketNew = parseInt(numberProductsBasket) + parseInt(productAmount);
      productStr       = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
      var dollar1      = productStr.replace(/\~\~\~\~\~\~\~\~(\d+).*$/, '');
      productStr       = productStr.replace(/(.*)\~\~\~\~\~\~\~\~(\d+)/, dollar1 + productId + "~___" +  numberProductsBasketNew);
      setProducts(productStr);
    }
    else{
      var productsFirst = new RegExp("p:");

      if(productsFirst.test(productStr) == true){
        productStr = "p:" + productId + "~___" + productAmount + "~__-" + productName + "~_-_" + productPrice + "~_--" + productMeta1 + "~-_-" + productMeta2 + "~--_" + "~~~" + productStr;
      }
      else{
        productStr = "p:" + productId + "~___" + productAmount + "~__-" + productName + "~_-_" + productPrice + "~_--" + productMeta1 + "~-_-" + productMeta2 + "~--_" + "~~~";      
      }     
      setProducts(productStr);
    }
    document.location.reload();

  }  
////////////////////////////////////////////////////////////////
//
// Beschreibung: Setzt eine bestimmte Anzahl eines Produktes
//
////////////////////////////////////////////////////////////////

  function setProduct (productId, productAmount, productName, productPrice, productMeta1, productMeta2){
  
    var productStr = getCookie(shopId);
    productName = productName.replace('%27','\'');
    
    var regExpStr;
    var existsProduct = new RegExp(":" + productId + "~___");
    if(existsProduct.test(productStr) == true){
      var numberProductsBasket    = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
      numberProductsBasket    = numberProductsBasket.replace(/.*\~\~\~\~\~\~\~\~/, "");
      numberProductsBasket    = numberProductsBasket.replace(/^(\d+).*/, '$1');          

      var numberProductsBasketNew = parseInt(productAmount);
      productStr       = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
      var dollar1      = productStr.replace(/\~\~\~\~\~\~\~\~(\d+).*$/, '');
      productStr       = productStr.replace(/(.*)\~\~\~\~\~\~\~\~(\d+)/, dollar1 + productId + "~___" +  numberProductsBasketNew);
      setProducts(productStr);
    }
    else{
      var productsFirst = new RegExp("p:");

      if(productsFirst.test(productStr) == true){
        productStr = "p:" + productId + "~___" + productAmount + "~__-" + productName + "~_-_" + productPrice + "~_--" + productMeta1 + "~-_-" + productMeta2 + "~--_" + "~~~" + productStr;
      }
      else{
        productStr = "p:" + productId + "~___" + productAmount + "~__-" + productName + "~_-_" + productPrice + "~_--" + productMeta1 + "~-_-" + productMeta2 + "~--_" + "~~~";      
      }     
      setProducts(productStr);
    }
    document.location.reload();
  }  
  
////////////////////////////////////////////////////////////////
//
// Beschreibung: Entfernt eine bestimmte Anzahl eines Produktes aus dem Warenkorb
//
////////////////////////////////////////////////////////////////

  function removeProduct (productId, productAmount){
  
    var productStr = getCookie(shopId);
    var regExpStr;
    var existsProduct = new RegExp(":" + productId + "~___");
    
    if(existsProduct.test(productStr) == true){
      productAmount    = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
      productAmount    = productAmount.replace(/.*\~\~\~\~\~\~\~\~/, "");
      productAmount    = productAmount.replace(/^(\d+).*/, '$1');          
      var productAmountNew = productAmount * 2;
      productAmountNew = productAmountNew/2-1;
      if(productAmountNew > 0){
        productStr       = productStr.replace(":" + productId + "~___", ":~~~~~~~~");
        var dollar1      = productStr.replace(/\~\~\~\~\~\~\~\~(\d+).*$/, '');
        productStr       = productStr.replace(/(.*)\~\~\~\~\~\~\~\~(\d+)/, dollar1 + productId + "~___" +  productAmountNew);
      }
      else{                      
        productStr       = productStr.replace(":" + productId + "~___", "~~~~~~~~");      
        productStr       = productStr.replace(/p\~\~\~\~\~\~\~\~[^:]*\~\~\~/ , "");
      }      
      setProducts(productStr);
      document.location.reload();
    }
  }

////////////////////////////////////////////////////////////////
//
// Beschreibung: Entfernt ein Produkt aus dem Warenkorb
//
////////////////////////////////////////////////////////////////

  function clearProduct (productId){
  
    var productStr = getCookie(shopId);
    var regExpStr;
    var existsProduct = new RegExp(":" + productId + "~___");
    
    if(existsProduct.test(productStr) == true){
      productStr       = productStr.replace(":" + productId + "~___", "~~~~~~~~");      
      productStr       = productStr.replace(/p\~\~\~\~\~\~\~\~[^:]*\~\~\~/ , "");
    }      
    setProducts(productStr);
	document.location.reload();
  }  
  
////////////////////////////////////////////////////////////////
//
// Beschreibung: Schreibt den Warenkorb
//
////////////////////////////////////////////////////////////////  

function setProducts (productStr){
  document.cookie = shopId + "=" + productStr + "; path=/;";
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Loescht den Warenkorb
//
////////////////////////////////////////////////////////////////  

function clearBasket (){
  
  document.cookie = shopId + "=; path=/;";
}
  
////////////////////////////////////////////////////////////////
//
// Beschreibung: Sendet die Bestellung
// 
// Parameter: form = Formular, das gesendet werden soll.
//
////////////////////////////////////////////////////////////////

function submitOrder(form, cacheMode){
  
  if(isMinOrderValue == false){
    alert(minOrderAlert);
    return;
  } 
  
	if(!form.productAmount){
	 alert ("Der Warenkorb ist leer!");
	 return false;
	}
  
  var messageEmail      = " enthält keine gültige Email Adresse!\n"; //erscheint wenn ein Pflichtfeld nicht ausgefüllt wurde

  var isObligation = /\|\w*o\w*$/i;  //Pflichtfeld, wenn Feldname am Schluss |o  enthaelt   (z.B.: "Strasse|o")
  var isEmail      = /\|\w*e\w*$/i;  //Emailfeld wenn Feldname am Schluss |e enthaelt       (z.B.: "eMail|e")
  var isCache      = /\|\w*c\w*$/i;  //Wird fuer weitere Formulare gespeichert am Schluss |c enthaelt       (z.B.: "eMail|c")
                    //Pflicht- und Emailfeld, wenn am Schluss |oe oder |eo (z.B.: "eMail|eo") 

  var checkEmail   = /.*\@.*\.\w+/i;
  var formElement;
  var formElementNameOrig;
  var alertStr = "";

  var cookieStr = "";

  for(var i = 0; i <= form.elements.length - 1; i++){
    var formElement = form.elements[i];
    if(formElement){
      if(formElement.type == "text" || formElement.type == "textarea"){
        formElementNameOrig = formElement.name.replace(/\|\w+/, ''); 
        if(isObligation.test(formElement.name) == true){  
          if(formElement.value == ""){
            alertStr += formElementNameOrig + messageObligation;                     
          }
        } 
        if(isEmail.test(formElement.name) == true){  
          if (checkEmail.test(formElement.value) == false){
            alertStr += formElementNameOrig + messageEmail;                     
          }
        }
        if(cacheMode == "1"){        
          if(isCache.test(formElement.name) == true){ 
            if(formElement.value != ""){
              cookieStr += "wFc_" + formElementNameOrig + "=" + formElement.value + ":";
            }
          }        
        }          
      }
      else if(formElement.type == "checkbox"){
        formElementNameOrig = formElement.name.replace(/\|\w+/, '');   
        if(isObligation.test(formElement.name) == true){  
          if(formElement.checked == false){
            alertStr += formElementNameOrig + messageObligation;                     
          }
        } 
      }
    }
  }

  if(alertStr != ""){
    alert(alertStr);  
  }
  else{
    if(cacheMode == "1"){      
      cookieStr += "; path=/";    
      document.cookie = cookieStr;  
    }
    clearBasket();
    form.submit();
  }
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Ermittelt ein Cookie
//
////////////////////////////////////////////////////////////////  

function getCookie(name){
  var cookieStr = document.cookie;
  if(name && name != ''){
    var nameReg = new RegExp('.*' + name + '=');
    cookieStr = cookieStr.replace(nameReg, '');
    cookieStr = cookieStr.replace(/;.*/, '');    
  }
  return cookieStr;
}

function getCookie(name){
  var cookieStr = document.cookie;
  if(name && name != ''){
        
    var nameReg = new RegExp(name + '=');
    
    cookiePos = cookieStr.search(nameReg);
    
    if (cookiePos != -1){
     cookieStr = cookieStr.substring(cookiePos);   
     cookieStr = cookieStr.replace(nameReg, '');
     cookieStr = cookieStr.replace(/;.*/, '');
    }
    else cookieStr="";
  }
  return cookieStr;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Prüft den Mindestbestellwert
//
////////////////////////////////////////////////////////////////  

function checkMinOrderValue(orderSum){
  if(orderSum < minOrderValue){
    isMinOrderValue = false;
  }
  else{
    isMinOrderValue = true;
  }
}


////////////////////////////////////////////////////////////////
//
// Beschreibung: Gibt das Template der Versandkosten zurück
//
////////////////////////////////////////////////////////////////  

function getFreightChargesTpl(orderSum){
  freightChargesTpl = freightChargesTpl.replace("$freightCharges", convertPrice(getFreightCharge(orderSum)));
  freightChargesTpl = freightChargesTpl.replace("$freightChargesValue", convertPrice(getFreightCharge(orderSum)));
  return freightChargesTpl;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Gibt die Versandkosten zurück
//
////////////////////////////////////////////////////////////////  

function getFreightCharge(orderSum){
  for(var i = 0; i < freightCharges.length; i++){
    if(orderSum >= freightCharges[i][1] && orderSum < freightCharges[i][2]){
      return freightCharges[i][0];
    }
  }
}

  ////////////////////////////////////////////////////////////////
//
// Beschreibung: Überprüft das Vorhandensein eines Wertes
//
// @params form = das Formular; checkNewValue = der Wert, der getestet werden soll;
//				checkOldValues = die Werte gegen welche geprüft werden soll;
//				notAllowedString = der String, der nicht zugelassen ist (z.B. "")
//				valueTitle = der Titel des zu erzeugenden Parameters
//
////////////////////////////////////////////////////////////////  

function checkValue(form, checkNewValue, checkOldValues, notAllowedString, valueTitle){
  
  if(checkNewValue == null) checkNewValue = "Category";
  if(checkOldValues == null) checkOldValues = "cats";
  if(notAllowedString == null) notAllowedString = "";
  if(valueTitle == null) valueTitle = "Kategorie";
  
  // Returnvariable
  var ret = true;
  var alertStr = "";
  
  // Lese die neu anzulegende Kategorie aus
  var newValue= form.elements[checkNewValue].value;
  if(newValue == notAllowedString) alertStr = "Bitte geben Sie eine " + valueTitle + " an.";
  
  // Lese die vorhandenen Kategorien aus dem Formular aus
  else if(form.elements[checkOldValues].value != ""){
    var oldValues = form.elements[checkOldValues].value;
    
    // Strip first "|" if any
    if(oldValues.indexOf("|") == 0) oldValues = oldValues.substr(1,oldValues.length-1);
    
    var presentValues = oldValues.split("|");
    
    // Prüfe ob vorhanden
    for(var i=0; i <= presentValues.length-1; i++){
      if(presentValues[i] == newValue) alertStr = valueTitle + " schon vorhanden";
    }
  }
  
  if(alertStr != ""){
    alert(alertStr);
    ret = false;
  }
  return ret;
}

