
// changed bengine -> bengine2 
var uthema='';

function updateRegListe(TTREGS){
    g_nZiel=-1;    g_nRegion=-1;
    g_strZiel="";  g_strRegion="";
    UpdateRegionen(TTREGS);
}

function UpdateRegionen(rec)
{
        //alert('in fkt UpdateRegionen(rec)')
        if(rec){
                TTREGS = rec;
        } else {
                return false;
        }
        TTREGS=rec;
        uthema=(document.bengine2.uthema.options[document.bengine2.uthema.selectedIndex].value);
        HBit=uthema.split("_");

        /*
        alert('UpdateRegionen - uthema:'+uthema);
        alert('Welches HotelBit?: '+HBit[0]);
        alert('HotelBit: '+HBit[1]);
        alert('Bit: '+(1<<HBit[1]-1));
        */

        opt=document.bengine2.elements["region"].options;
        opt[0].value=-1;opt[0].text="<Alle Regionen>";

        opt=document.bengine2.elements["ziel"].options;
        opt[0].value=-1;opt[0].text="<Alle Reiseziele>";

        if(HBit[0]==1){
            tmp_val=3;
            tmp_HBit=1;

        }
        else{
            tmp_val=4;
            tmp_HBit=2;
        }
        found=1;
        for(i=0;i<TTREGS.length;i++){
                sr=TTREGS[i].split("|");
                if(sr[1]>=10000){
                    if( (sr[tmp_val]&(1<<HBit[1]-1)&& HBit[0]==tmp_HBit)  ||  uthema==''){
                        if(found>=opt.length){
                                opt[found++]=new Option(sr[0],sr[1]);
                        } else {
                                opt[found].text=sr[0];
                                opt[found++].value=sr[1];
                        }
                    }
                }
        }
        while(opt.length > found){
                opt[opt.length-1]=null;
        }
        FixRSel();
}

function RZC(ds)
{

        //alert('in fkt RZC(ds)')
        opt=document.bengine2.elements["ziel"].options;
        kenner=opt[opt.selectedIndex].value;
        g_nZiel=kenner;

        //HBit=uthema.split("_");

        //alert('RZC-uthema: '+uthema);

        if(opt.selectedIndex>0){
                g_strZiel=opt[opt.selectedIndex].text;
        } else g_strZiel="";
        gfilt=kenner!=-1;
        opt=document.bengine2.elements["region"].options;
        found=1;

        for(i=0;i<TTREGS.length;i++){
                sr=TTREGS[i].split("|");
                if(sr[1]<10000 && (kenner<0 || sr[2]==kenner)){
                    if( (sr[tmp_val]&(1<<HBit[1]-1)&& HBit[0]==tmp_HBit) || uthema==''){
                        txt=sr[0];
                        if(found>=opt.length){
                                opt[found++]=new Option(txt,sr[1]+"|"+sr[2]);
                        } else {
                                opt[found].text=txt;
                                opt[found++].value=sr[1]+"|"+sr[2];
                        }
                    }
                }
        }

        while(opt.length > found){
                opt[opt.length-1]=null;
        }

        if(ds){
                opt.selectedIndex=0;
                g_strRegion="";
                g_nRegion=-1;
        }

}

function REGC()
{
        //alert('in fkt REGC()')
        ropt=document.bengine2.elements["region"].options;
        kenner=ropt[ropt.selectedIndex].value.split("|");
        g_nRegion=kenner[0];
        if(ropt.selectedIndex>0){
                sr=ropt[ropt.selectedIndex].text;
                g_strRegion=sr.substr(0,sr.lastIndexOf("(")-1);
        } else g_strRegion="";

        if(!gfilt && kenner[0]>=0){
                opt=document.bengine2.elements["ziel"].options;
                for(i=1;i<opt.length;i++){
                        if(opt[i].value==kenner[1]){
                                opt.selectedIndex=i;
                                g_nZiel=kenner[1];
                                g_strZiel=opt[i].text;
                                break;
                        }
                }
        }
}
function FixRSel()
{
        //alert('in fkt FixRSel()')
        opt=document.bengine2.elements["ziel"].options;
        if(opt.selectedIndex<0 || opt[opt.selectedIndex].value!=g_nZiel){
                for(i=0;i<opt.length;i++)
                if(opt[i].value==g_nZiel){
                        opt.selectedIndex=i;break;
                }
                if(i==opt.length){
                        //alert(g_strZiel);
                        if(g_strZiel!=""){
                                opt[opt.length]=new Option(g_strZiel,g_nZiel,true,true);
                        } else {
                                opt.selectedIndex=0;
                                RZC();return;
                        }
                }
        }
        RZC();

        opt=document.bengine2.elements["region"].options;
        if(opt.selectedIndex<0 || opt[opt.selectedIndex].value.split("|")[0]!=g_nRegion){
                for(i=0;i<opt.length;i++)
                if(opt[i].value.split("|")[0]==g_nRegion){
                        opt.selectedIndex=i;break;
                }
                if(i==opt.length){
                        if(g_strRegion!=""){
                                opt[opt.length]=new Option(g_strRegion+" (keine Ang.)",g_nRegion+"|"+g_nZiel,true,true);
                        } else {
                                opt.selectedIndex=0;
                                g_nRegion=-1;
                                g_strRegion="";
                        }
                }
        }
}