// ShowKomment
function showKommentarMod(e,obj,beschr,preis,isimg)
{
        backcolor        = '#FFFFFF';
        if (typeof(ColorRGB) == "undefined") ColorRGB = "";
        bordercolor = (ColorRGB) == "" ? '#f1f1f1' : ColorRGB;
        tablewidth        = '210';

         var preis_line = "";
        var html = new String(obj.innerHTML);
        if (html.indexOf("src=") != -1)
        {
                html = html.substr(html.indexOf('src="')+5);
                html = html.substr(0, html.indexOf('"'));
                if (html != "") html = "<img src='" + html + "' >";
        }
        else html = "";

         if(preis != '')
          preis_line = "<br>Preis: " + preis;

         html = "<div align='center'><b>" + beschr + preis_line +"</b>"+ "</div>"+html ;

        if(isimg==true)
        showKommentar2(e,html,250);
        else showKommentar2(e,html,10);

        backcolor        = '#ffffe1';
        bordercolor        = '#000';
        tablewidth        = '230';
}


function Otkroikartinku(ImgURL)
{
        if (ImgURL != "")
                DoBild(ImgURL);
        else
                alert('Zur Zeit gibt es keine Grossansicht fÃ¼r dieses Bild.');
}

function OeffnenFenster(fU,fN,fF)
{
        window.open(fU,fN,fF);
}



// Ebene auf-/ zuklappen
    function switchLayer(nframe, nbutton, ivisible, ihidden) {
                mframe=document.getElementById(nframe)

        if (mframe)
                {
                var mtarget = mframe.style.display == "none" ? "block" : "none";
                mframe.style.display = String(mtarget);

                if (nbutton != "" && nbutton != "undefined")
                        {
                        var button=document.getElementById(nbutton)

                        if (button)
                                        button.src = mtarget == "none" ? ivisible : ihidden;
                        }
                }
        }


function ShowVarianteAll (GroupID)
{
        if (GroupID != "" && document.getElementById)
        {
                if(document.getElementById('tr_'+GroupID))
                {
                        if(document.getElementById('tr_'+GroupID).className == 'varhide')
                        {//alert('show');
                                document.getElementById('tr_'+GroupID).className= 'varvisible';
                                if(document.images["content_btn_"+GroupID])document.images["content_btn_"+GroupID].src="{http_host}navigation/shop/pfeil-variante_a.gif";
                        }
                         else
                        {//alert('hide');
                                document.getElementById('tr_'+GroupID).className= 'varhide';
                                if(document.images["content_btn_"+GroupID])
                   document.images["content_btn_"+GroupID].src="{http_host}navigation/shop/variante_pfeil_.gif";
                        }
                }
        }
}

/////////////////////////////////////////////////////////////////////////////////

//############################################################################################################
function setNewVariant(newVarID, GroupID)
{
 tmpNewVarID=newVarID;
 tmpGroupID=GroupID;

 /*Pricecalc*/
 SelectedVariantsIDs = new Array();

 for (i = 0; i < document.product.elements.length; i++)
 {
   if (document.product.elements[i].type == "radio" && document.product.elements[i].checked == true)
   {
      SelectedVariantsIDs[SelectedVariantsIDs.length] = document.product.elements[i].value; 
   }
 }

 if(!pricecalcCalculated)
 {//alert("!pricecalcCalculated");
  pricecalcCalculatePrices("changevar");
  pricecalcCalculated=true;
  return false;
 }
 else
 {
  pricecalcCalculated=false;
  price_base = parseFloat(price_base.replace(",","."));
 }
		
 if(Vollpreis!="true")
 {//Aufpreis
   if(NettoShop!="true")
   {//Brutto
      var total = parseFloat(BasisPreisBrutto);
      var total_nd = parseFloat(BasisPreisBruttoND);

/*
      if(typeof(arrPricecalcPrices["brutto"])!="undefined")
        total += arrPricecalcPrices["brutto"];
      if(typeof(arrPricecalcPrices["bruttoND"])!="undefined")
        total_nd += arrPricecalcPrices["bruttoND"];
*/    
      total = total_nd = price_base;
 
      bprice=total; 

      count_variants=0;
	 
      for (i = 0; i < document.product.elements.length; i++)
      {
	   if (document.product.elements[i].type == "radio" && document.product.elements[i].checked == true)
	   {
              count_variants++; 
	      aufpreis = eval("document.product.varpriceBrutto_" + document.product.elements[i].value).value;
	      aufpreis = parseFloat(aufpreis);
	      total += aufpreis;
	   }
      }

         if(count_variants > 0)
	  document.getElementById("gesamtpreis").innerHTML =  FormatZahl(total,2,',','') + " "+Currency;
         if(document.getElementById("priceND"))
          document.getElementById("priceND").innerHTML =  FormatZahl(total_nd,2,',','') + " "+Currency;
         if(document.getElementById("price"))
         document.getElementById("price").innerHTML =  FormatZahl(bprice,2,',','') + " "+Currency;
	 PriceVal=total;
   }
   else
   {//Netto

     var total = parseFloat(BasisPreisNetto);
     var totalB = parseFloat(BasisPreisBrutto);
     
     total = total_nd = price_base;
     bprice=total; 
     count_variants=0;

     for (i = 0; i < document.product.elements.length; i++)
     {
	   if (document.product.elements[i].type == "radio" && document.product.elements[i].checked == true)
	   {
               count_variants++; 
	   	  aufpreis = eval("document.product.varpriceNetto_" + document.product.elements[i].value).value;
		  aufpreis = parseFloat(aufpreis);
		  total += aufpreis;
	          aufpreisB = eval("document.product.varpriceBrutto_" + document.product.elements[i].value).value;
		  aufpreisB = parseFloat(aufpreisB);
		  totalB += aufpreisB;
	   }
     }
         
     if(document.getElementById("gesamtpreis"))
	  document.getElementById("gesamtpreis").innerHTML =  FormatZahl(total,2,',','') + " "+Currency;
     if(document.getElementById("gesamtpreis_brutto"))
	  document.getElementById("gesamtpreis_brutto").innerHTML =  FormatZahl(totalB,2,',','') + " "+Currency;
     if(document.getElementById("price"))
         document.getElementById("price").innerHTML =  FormatZahl(bprice,2,',','') + " "+Currency;
     PriceVal=total;
   }
 }
 else
 {//Vollpreis
   if(NettoShop!="true")
   {//Brutto
     for (i = 0; i < document.product.elements.length; i++)
	 {
	   if (document.product.elements[i].type == "radio" && document.product.elements[i].checked == true)
	   {
	      totalND = eval("document.product.varpriceNDbrutto_" + document.product.elements[i].value).value;
		  totalND = parseFloat(totalND);
		  total = eval("document.product.varpriceBrutto_" + document.product.elements[i].value).value;
		  total = parseFloat(total);
	   }
	 }
	 if(document.getElementById("priceND"))document.getElementById("priceND").innerHTML =  FormatZahl(totalND,2,',','') + " "+Currency;
	 document.getElementById("price").innerHTML =  FormatZahl(total,2,',','') + " "+Currency;
	 PriceVal=total;
   }
   else
   {//Netto
     for (i = 0; i < document.product.elements.length; i++)
	 {
	   if (document.product.elements[i].type == "radio" && document.product.elements[i].checked == true)
	   {
	      totalND = eval("document.product.varpriceNDnetto_" + document.product.elements[i].value).value;
		  totalND = parseFloat(totalND);
		  total = eval("document.product.varpriceNetto_" + document.product.elements[i].value).value;
		  total = parseFloat(total);
		  totalB = eval("document.product.varpriceBrutto_" + document.product.elements[i].value).value;
		  totalB = parseFloat(totalB);
	   }
	 }
	 if(document.getElementById("priceND"))document.getElementById("priceND").innerHTML =  FormatZahl(totalND,2,',','') + " "+Currency;
	 document.getElementById("price").innerHTML =  FormatZahl(total,2,',','') + " "+Currency;
	 document.getElementById("price_b").innerHTML =  FormatZahl(totalB,2,',','') + " "+Currency;
	 PriceVal=total;
   }
 } 
 
 if(document.getElementById("varname_"+GroupID))document.getElementById("varname_"+GroupID).innerHTML = document.getElementById("allvarname_"+newVarID).innerHTML;
 if(document.getElementById("aufpreis_"+GroupID) && document.getElementById("allaufpreis_"+newVarID))document.getElementById("aufpreis_"+GroupID).innerHTML = document.getElementById("allaufpreis_"+newVarID).innerHTML;

 if ( document.getElementById("Thumbnail_orig_" + GroupID) && document.getElementById("Thumbnail_" + newVarID))
 {
   var ImgParam = 'height';
                             
   if(typeof(VarImagesArray[GroupID]) !='undefined' && typeof(VarImagesArray[GroupID][newVarID])!='undefined' && VarImagesArray[GroupID][newVarID]['height']<VarImagesArray[GroupID][newVarID]['width'])ImgParam='width';
   var re = new RegExp(">","g");
   var myhtmlstring = document.getElementById("Thumbnail_" + newVarID).innerHTML;
   myhtmlstring = myhtmlstring.replace(re, " "+ImgParam+"=80>")
   document.getElementById("Thumbnail_orig_" + GroupID).innerHTML = myhtmlstring;
 }

}
//#####################################################################################################################


function FormatZahl( number,laenge,sep, th_sep ) 
{
  number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
  str_number = number+"";
  arr_int = str_number.split(".");
  if(!arr_int[0]) arr_int[0] = "0";
  if(!arr_int[1]) arr_int[1] = "";
  if(arr_int[1].length < laenge){
    nachkomma = arr_int[1];
    for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
    arr_int[1] = nachkomma;
  }
  if(th_sep != "" && arr_int[0].length > 3){
    Begriff = arr_int[0];
    arr_int[0] = "";
    for(j = 3; j < Begriff.length ; j+=3){
      Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
      arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
    }
    str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
    arr_int[0] = str_first + arr_int[0];
  }
  return arr_int[0]+sep+arr_int[1];
}


function getMonthRate(PriceVal,CreditInfo_Period,CreditInfo_effZ_Val)
{
  //alert(PriceVal+","+CreditInfo_Period+","+CreditInfo_effZ_Val);

  q=CreditInfo_effZ_Val/100+1;
  pow_val=1/CreditInfo_Period;
  mq=Math.pow(q,pow_val);
  mq_pow_period = Math.pow(mq,CreditInfo_Period);
  tmp_erg_1 = mq_pow_period/(mq_pow_period-1);
  mRate = PriceVal*tmp_erg_1*(mq-1);
  //alert(mRate);
  return mRate;
}
