// *---------Functions Stuff----------------------------------------------------------------------

function formatprice(aprice,uwaerung){
 var astr="";var sprice="";
 if(formatprice.arguments.length>1){awaerung=uwaerung;} else {awaerung=gwaerung;}
 aprice=Math.round(aprice/fwaerung[awaerung]*100)/100;
 astr+=aprice;
 astr=astr.split(".");
 if(astr.length==1){
   astr[1]="00";
 } else {
   if (astr[1].length==1){astr[1]=astr[1]+"0";}
 }
 sprice=astr.join(",");
 return swaerung[awaerung] + sprice;
}

function Price2HTML(aD_index){
 return Dary[aD_index].price;
}

function sumPricebyCindex(aC_index,amultiple){
 var aval=0;
  if (aC_index>-1) {
   if (amultiple==0) {aval=Cary[aC_index].price;} else {aval=Cary[aC_index].totprice;}
  } else {
    for (i=0;i < anz_C;i++){aval=aval+sumPricebyCindex(i);}
  }
  return Math.round(aval * 100)/100;
}

function iIndex(aindex)  {
   this.index=aindex;
}

function iValue(avalue)  {
   this.value=avalue;
}
function iStr(astr)  {
   this.str=astr;
}

function iA(aA_id)  {
   this.A_id=aA_id;
   this.Pname="-";
   this.Aname="-";
   this.img="";
   this.show_name=0;
   this.show_img=0;
   this.show_header=0;
   this.imgobj=new Image();
   this.Pary=new Array();
   this.Pary[0]=new iStr("-");
   this.anzP=1;
}

// *---------Category Stuff----------------------------------------------------------------------
function iH(aH_id,aname,ades,aldes,aicon,aimage,ahicon,aiconm)  {
   this.H_id=aH_id;
   this.name=aname;
   this.des=ades;
   this.ldes=aldes;
   this.H_index=anz_H;
   this.HDary=new Array();
   this.anz_HD=0;
   this.icon=aicon;
   this.hicon=ahicon;
   this.margin=new Array();
   for(k=0;k< 4;k++){
      this.margin[k]=0;
   }
   if(aiconm!="") {
     var astr=aiconm.split("°");
     for(k=0;k<astr.length;k++){
      this.margin[k]=astr[k];
     }        
   }
   if (aicon!="") {this.i_icon=new Image();this.i_icon.src=aicon;}
   if (ahicon!="") {this.i_hicon=new Image();this.i_hicon.src=ahicon;}
//   if (aimage!="") {this.i_image=new Image();this.i_image.src=aimage;}
   this.image=aimage;
   this.Aary=new Array();
   this.anz_A=0;
   anz_H++;
}
function addH(aid,aname,ades,aldes,aicon,aimage,ahicon,aiconm){
 Hary[anz_H]=new iH(aid,aname,ades,aldes,aicon,aimage,ahicon,aiconm);
}

function getHindex(aH_id) {
 for(i=0;i < anz_H;i++){
     if(Hary[i].H_id ==aH_id){ return i;break}
 }
 return -1;
}


function addHA(aH_id,aid,aname,aimg,ashow_name,ashow_img)  {
var i= getHindex(aH_id);
  if (i>-1) {
       var aHA_index=Hary[i].anz_A;
       Hary[i].Aary[aHA_index]=new iA(aid);
       with(Hary[i].Aary[aHA_index]) {
         Aname=aname;
         img=aimg;
         show_name=ashow_name;
	     show_img=ashow_img;
         if (aimg!="") imgobj.src=aimg;
       }
       Hary[i].anz_A++;
  }
}

function addHP(aH_id,aHA_id,aPname,acols,ashow_header)  {
  var i= getHindex(aH_id);
  if (i>-1) {
    for(j=0;j < Hary[i].anz_A;j++){
      if(Hary[i].Aary[j].A_id ==aHA_id){
        Hary[i].Aary[j].Pname=aPname;
        Hary[i].Aary[j].show_header=ashow_header;
        var astr=acols.split('°');
        for(k=0;k < astr.length;k++){
           if(astr[k].length !=0){
              if (k>0) {
                 Hary[i].Aary[j].Pary[k]=new iStr(astr[k]);
                 Hary[i].Aary[j].anzP++;
              } else {
                 Hary[i].Aary[j].Pary[k].str=astr[k];
              }
           }
        }
        break;
      }
    }
  }
}

// *---------Item Stuff----------------------------------------------------------------------
function iD(aD_id,aH_id,aA_id,aOH_ids,aname,aprices,ades,aldes,aicon,aimage,apdefault)  {
   this.H_id=aH_id;
   this.D_id=aD_id;
   this.A_id=aA_id;
   this.name=aname;
   this.des=ades;
   this.ldes=aldes;
   this.H_index=-1;
   this.D_index=anz_D;
   this.anz_OH=0;
   this.Pary=new Array();
   this.anz_P=0;
   this.P_idefault=apdefault-1;
   this.icon=aicon;
   this.image=aimage;
   var astr=aprices.split('°');
   for(k=0;k < astr.length;k++){
      if(astr[k].length !=0){
       this.Pary[this.anz_P]=new iValue(parseFloat(astr[k]));
       this.anz_P++;  
      }
   }
   for(i=0;i < anz_H;i++){
     if(Hary[i].H_id ==this.H_id){ 
        this.H_index=i;
        Hary[i].HDary[Hary[i].anz_HD]= new iIndex(this.D_index);
        Hary[i].anz_HD++;
        break;
     }
   }
   this.A_index=0;
   for(i=0;i < Hary[this.H_index].anz_A;i++){
     if(Hary[this.H_index].Aary[i].A_id ==this.A_id){this.A_index=i; break;}
   }
   if(aOH_ids){
    this.OH_indexes=new Array();
    this.OH_ids=new Array();
    if(aOH_ids.length > 1){
     var astr=aOH_ids.split('°');
     for(i=0;i < astr.length;i++){
        if(astr[i].length !=0){ 
           this.OH_ids[i]= new iStr(astr[i]);
		   for(j=0;j < anz_OH;j++){if(OHary[j].OH_id ==astr[i]){this.OH_indexes[i]= new iIndex(j);this.anz_OH++;break;}}
        } 
     }
    }
   }

   anz_D++;
}

function addD(aid,aH_id,aA_id,aOH_id,aname,aprices,ades,aldes,aicon,aimage,apdefault){
 Dary[anz_D]=new iD(aid,aH_id,aA_id,aOH_id,aname,aprices,ades,aldes,aicon,aimage,apdefault);
}

// *---------Selection Stuff----------------------------------------------------------------------
function iOH(aOH_id,aname,ades,amandatory)  {
   this.OH_id=aOH_id;
   this.name=aname;
   this.des=ades;
   this.mandatory=amandatory;
   this.OH_index=anz_OH;
   this.ODary=new Array();
   this.anz_OD=0;
   anz_OH++;
}
function addOH(aid,aname,ades,amandatory){
 OHary[anz_OH]=new iOH(aid,aname,ades,amandatory);
}
function iOD(aOD_id,aOH_id,aname,aprice,ades)  {
   this.OH_id=aOH_id;
   this.OD_id=aOD_id;
   this.name=aname;
   this.price=parseFloat(aprice);
   this.des=ades;
   this.OH_index=-1;
   this.OD_index=anz_OD;
   for(i=0;i < anz_OH;i++){
     if(OHary[i].OH_id ==this.OH_id){ 
        this.OH_index=i;
        OHary[i].ODary[OHary[i].anz_OD]= new iIndex(this.OD_index);
        OHary[i].anz_OD++;
        break;
     }
   }
   anz_OD++;
}
function addOD(aid,aOH_id,aname,aprice,ades){
 ODary[anz_OD]=new iOD(aid,aOH_id,aname,aprice,ades);
}
function iC(aH_index,aD_index,aanz_CD,aOptions,aP_index)  {
   this.H_index=aH_index;
   this.D_index=aD_index;
   this.anz_CD=aanz_CD;
   this.ODary=new Array();
   this.price=0;
   this.totprice=0;
   this.anz_OD=0;
   this.P_index=aP_index;
   if(aOptions.length > 1){
     var astr=aOptions.split('°');
     for(i=0;i < astr.length;i++){
        if(astr[i].length !=0){this.ODary[i]= new iIndex(astr[i]);this.anz_OD++;} 
     }
    }
   anz_C++;
}

function find_inCbyD_index(aD_index){
   var found=-1;
   for(i=0;i < anz_C;i++){
     if(Cary[i].D_index ==aD_index){ 
        found=i
        break;
     }
   }
   return  found;
}

function calC(aC_index){
 var aD_index=Cary[aC_index].D_index;
 var aval=Dary[aD_index].Pary[Cary[aC_index].P_index].value;
 for(i=0;i < Cary[aC_index].anz_OD;i++){aval=aval+ODary[Cary[aC_index].ODary[i].index].price;}
 Cary[aC_index].price=Math.round(aval * 100)/100;
 Cary[aC_index].totprice=Math.round(aval*Cary[aC_index].anz_CD * 100)/100;
}

function addC(aH_index,aD_index,aC_index,aanz_CD,aOptions,aP_index){
if ((aC_index==-1) && (aanz_CD>0)) {
 if (Dary[aD_index].anz_OH==0) {
   aC_index=find_inCbyD_index(aD_index);
   if (aC_index==-1) {aC_index=anz_C;Cary[anz_C]=new iC(aH_index,aD_index,aanz_CD,aOptions,aP_index);} else { Cary[aC_index].anz_CD++;}
 } else {
   aC_index=anz_C;
   Cary[anz_C]=new iC(aH_index,aD_index,aanz_CD,aOptions,aP_index);
 }
 calC(aC_index);
} else {
 if (aanz_CD>0) {
   Cary[aC_index].ODary=Cary[aC_index].ODary.slice(0,0);
   Cary[aC_index].anz_CD=aanz_CD;
   Cary[aC_index].anz_OD=0;
   Cary[aC_index].P_index=aP_index;
   if(aOptions.length > 1){
     var astr=aOptions.split('°');
     for(i=0;i < astr.length;i++){
       if(astr[i].length !=0){Cary[aC_index].ODary[i]= new iIndex(astr[i]);Cary[aC_index].anz_OD++;} 
     }
   }
   calC(aC_index);
 } else {
 removeC(aC_index,false);
 }
}
Bon2HTML();
}


function setC(aC_index,anz){
 if (anz>0) {Cary[aC_index].anz_CD=anz; calC(aC_index);} else {removeC(aC_index,0);}
 Bon2HTML();
}

function incC(aC_index,ainc){
 if (ainc<0 && Cary[aC_index].anz_CD>0) {ainc=0;}
 if (ainc!=0) {
    Cary[aC_index].anz_CD +=ainc; calC(aC_index); 
 } else {
    removeC(aC_index,0);
 }
 Bon2HTML();
}

function removeC(aC_index,update){
 if (aC_index <anz_C-1) {
  var aC=Cary;
  Cary=Cary.slice(0,aC_index);
  aC=aC.slice(aC_index+1,aC.length);
  Cary=Cary.concat(aC);
 } else { 
  Cary=Cary.slice(0,aC_index);
 }
 anz_C--;
 if (update!=0) { Bon2HTML();}
}


// *---------Cookie/Form Stuff----------------------------------------------------------------------


function ico_item(aids,aname,ades,amandatory,atype,avalue,asize,amaxlen,awidth,adesb,aerrormsg){
 this.ids=aids;
 this.value=avalue;
 this.des=ades;
 this.type=atype;
 this.desb=adesb;
 this.name=aname;
 this.size=asize;
 this.maxlen=amaxlen;
 this.width=awidth;
 this.errormsg=aerrormsg;
 this.mandatory=amandatory;
}
function addfco_item(aids,aname,ades,amandtory,atype,avalue,asize,amaxlen,awidth,adesb,aerrormsg){
 fco_items[fco_items.length]=new ico_item(aids,aname,ades,amandtory,atype,avalue,asize,amaxlen,awidth,adesb,aerrormsg);
}

function fixDate(date) {
  var base = new Date(0);var skew = base.getTime()
  if (skew > 0) {date.setTime(date.getTime() - skew);}
}


function saveDocCo(){
 var now = new Date();fixDate(now);now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
 snow="; expires=" + now.toGMTString();
 for(i=0;i < fco_items.length;i++){
    document.cookie=fco_items[i].ids+ "=" + escape(fco_items[i].value) + snow;
 }
}

function readDocCo(){
 if (document.cookie) {
  var acookie=document.cookie.split("; ");
  for(i=0;i < acookie.length;i++) {
   var cti=acookie[i].split("=");
   for(j=0;j < fco_items.length;j++) {if (fco_items[j].ids==cti[0]) {if (cti[1]) {fco_items[j].value=unescape(cti[1]);}else{fco_items[j].value="";} break;}}
  }
 }
}

