﻿g_iType = "";

function InitaliseSearch() {

    arrElems = document.getElementsByName("itype");
    for(var i = 0;i < arrElems.length;i++) arrElems[i].onchange = ChangeSearchType;

    oForm = document.forms['formSP'];
    if (! oForm) return;
    if (oForm.infx_transport_type) oForm.infx_transport_type.onchange = ChangeSearchType;
    if (oForm.infx_cruise_type) oForm.infx_cruise_type.onchange = ChangeSearchType;
    if (oForm.infx_departure_code) oForm.infx_departure_code.onchange = ClearSelectedValues;

        bLoadDates = true;
        if (isB2B) document.getElementById("ifDatePicker").style.left = "450px";

    if (arguments[0] == "POST") {

        bLoadDates = true;

        if (oForm.infx_period) {
            oForm.infx_period.onclick = ShowDatePicker;
            oForm.infx_period.onchange = SetDays;
        }
        return;
    }

    if (oForm.infx_departure_code) {
        oForm.infx_departure_code.options.length = 0;
    }

    if (oForm.infx_period) {
        oForm.infx_period.options.length = 0;
        oForm.infx_period.options.add(new Option(msgSelect,''));
        oForm.infx_period.onclick = ShowDatePicker;
    }

    if (oForm.infx_days) {
        oForm.infx_days.options.length = 0;
        oForm.infx_days.options.add(new Option(msgSelect,''));
        oForm.infx_days.onclick = Message;
    }

    SetDepartureCodes();
}

function ClearSelectedValues(e) {
    oForm = document.forms['formSP'];
    oForm.infx_period.length = 0;
    oForm.infx_period.options.add(new Option(msgSelect,''));
    oForm.infx_days.length = 0;
    oForm.infx_days.options.add(new Option(msgSelect,''));
    
    HideDatePicker();
}


function Message(e) {

    if (!e) e = window.event;
    oSelect = (e.target ? e.target : e.srcElement);

    if (! oSelect) return;
    oTxt = document.getElementById('Message');

    if (oTxt.value == "") return;

    if (oSelect.type == "select-one") {
        if (oSelect.options.length == 0)
            alert(oTxt.value);
        else if (oSelect.options.length == 1 && oSelect.options[0].value == '')
            alert(oTxt.value);
    }
}


function SelectedOptions() {
    oForm = document.forms['formSP'];

    var selectedOptions = "";

    for (var i = 0;i < oForm.elements.length;i++) {

        oElem = oForm.elements[i];

        if (oElem.type != 'select-one') continue;
        selectedOptions += oElem.name + ":";

        sOptions = "";
        for (var j = 0;j < oElem.options.length;j++) {
            oOption =  oElem.options[j];
            sOptions += '&lt;option ' + (oElem.value == oOption.value ? 'selected' : '') + ' value="' + oOption.value + '"&gt;' +  oOption.text + '&lt;/option&gt;';
        }
        selectedOptions += sOptions + "\n";
    }

    return selectedOptions;
}


function ReloadData() {
	
    ax = new AjaxRequest();
    ax.AddParam("itype",GetSelectedInfxType());
    ax.AddParam("aid","data");
    ax.AddParam("infx_wellness",document.forms['formSP'].infx_wellness.value);
    ax.AddParam("infx_all_inclusive",document.forms['formSP'].infx_all_inclusive.value);
    if (document.forms['formSP'].infx_cruise_type)
        ax.AddParam("infx_cruise_type",document.forms['formSP'].infx_cruise_type.value);

    //alert(ax.QueryString());
    
    ax.OnRequestDone = function() {
        //ShowLoadingLayer(false);
        spd = eval("(" + arguments[0].responseText + ")")
    }

    ShowLoadingLayer(true);
    ax.SendPostRequest("/SearchEngine.aspx");
}

function ChangeSearchType(e) {

    HideDatePicker();

    if (!e) e = window.event;

    oSource = (e.target ? e.target : e.srcElement);

    if (oSource.name == "itype") {
        document.forms['formSP'].infx_transport_type.value = "";
    }

    ReloadData();
    
    ax = new AjaxRequest();
    ax.AddParam("aid","template");
    ax.AddParam("itype",GetSelectedInfxType());
    ax.AddParam("infx_wellness",document.forms['formSP'].infx_wellness.value);
    ax.AddParam("infx_all_inclusive",document.forms['formSP'].infx_all_inclusive.value);
    ax.AddParam("b2b",document.forms['formSP'].b2b.value);
    
    if (document.forms['formSP'].tabs)
        ax.AddParam("tabs",document.forms['formSP'].tabs.value);

    if (document.forms['formSP'].infx_cruise_type)
        ax.AddParam("infx_cruise_type",document.forms['formSP'].infx_cruise_type.value);

    ax.OnRequestDone = function() {
        document.getElementById('sp').innerHTML = arguments[0].responseText;
        InitaliseSearch();
        ShowLoadingLayer(false);
    }

    ShowLoadingLayer(true);
    ax.SendPostRequest("/SearchEngine.aspx");
}


function SetDepartureCodes() {
    oForm = document.forms['formSP'];
    if (! oForm.infx_departure_code) return;
    oForm.infx_departure_code.options.length = 0;
    //oForm.infx_departure_code.options.add(new Option('',''));

    for (var i = 0;i < spd.departure.length;i++) {
        oForm.infx_departure_code.options.add(
            new Option(spd.departure[i].name,spd.departure[i].departure_code)
        );
    }
}

function getElementX(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function ShowDatePicker(e) {
    
    if (!e) e = window.event;
    obj = (e.target ? e.target : e.srcElement);

    if (bLoadDates) {
        SetDates();
        bLoadDates = false;
    }

    iFrame = document.getElementById('ifDatePicker');

    iFrame.style.height = "202px";
    if (document.all) iFrame.style.width = "183px";
    else iFrame.style.width = "180px";

    xPos = getElementX(obj);
    if (! isNaN(xPos)) iFrame.style.left = xPos + "px";

    iFrame.style.visibility = "visible";


    if (e.target) e.target.blur();
    if (e.srcElement) document.getElementById('ifDatePicker').focus();

}


function HideDatePicker() {
    iFrame = document.getElementById('ifDatePicker');

    iFrame.style.visibility = "hidden";
    iFrame.style.height = "1px";
    iFrame.style.width = "1px";
    
    if (! bLoadDates) {
        //alert("SetDays");
        SetDays();
    }
}


function SetSelectedDate(dp) {
    oForm = document.forms['formSP'];
    oForm.infx_period.options.length = 0;
    oForm.infx_period.options.add(
        new Option(
            dp.getSelectedDate('D.M.Y'),
            dp.getSelectedDate('Y-M-D')
        ));

    HideDatePicker();
}

function SetRegions(e) {

    oForm = document.forms['formSP'];
    if (! oForm.infx_region_code) return;

    oForm.infx_region_code.options.length = 0;
    oForm.infx_region_code.options.add(new Option('',''));
    var itype = GetSelectedInfxType();
    var arrRegDest = new Array();

    switch(itype) {
        case "FK":
        case "K":
            arrRgeDest = spd.destination;
        break;

        default:
            arrRgeDest = spd.regions;
        break;
    }

    var  regForDays =  spd.days[oForm.infx_days.selectedIndex].region;

    for (var i = 0;i < arrRgeDest.length;i++) {
        if (regForDays.indexOf(arrRgeDest[i].id) < 0) continue;
        oForm.infx_region_code.options.add(new Option(arrRgeDest[i].name,arrRgeDest[i].id));
    }
}

//#############
function SetDays() {

    oForm = document.forms['formSP'];
    
    iType = GetSelectedInfxType();
    
    ax = new AjaxRequest();
    ax.AddParam("aid","days");
    ax.AddParam("itype",iType);

    if (oForm.infx_departure_code)
        ax.AddParam("infx_departure_code",oForm.infx_departure_code.value);

    if (oForm.infx_period) {

        if (oForm.infx_period.value != "")
            ax.AddParam("infx_period",oForm.infx_period.value);
        else return;
    }
    
    //alert(GetSelectedInfxType());


    ax.OnRequestDone = function() {
        ShowLoadingLayer(false);
        oForm.infx_days.options.length = 0;
        oForm.infx_days.options.add(new Option(msgSelect,''));
        arrDays = eval("(" + arguments[0].responseText + ")");
        spd.days = arrDays;

        oForm.infx_days.options.length = 0;
        oForm.infx_days.options.add(new Option(msgSelect,''));

        for(var i = 0;i < arrDays.length;i++) {
        	
        	if (iType.substring(0,1) == "B" && arrDays[i].value < 7) continue;
        	
            opt = new Option(arrDays[i].text,arrDays[i].value);
            if (arguments.length == 2) {
                if (arrDays[i].value == arguments[1]) opt.selected = true;
            }
            oForm.infx_days.options.add(opt);
        }
    }
    
    /*
    switch(window.location.host) {
    	case "idriva.apps.systechmedia.net":
    	case "www.idriva.loc":
    			alert(ax.QueryString());
    		break;
    }
    */
    
    ShowLoadingLayer(true);
    ax.SendPostRequest("/SearchEngine.aspx");
}

function SetDates() {

    HideDatePicker();
    oForm = document.forms['formSP'];

    tmpAction = oForm.action;
    tmpTarget = oForm.target;

    ShowLoadingLayer(true);

    if (oForm.infx_service) oForm.infx_service.options.length = 0;
    oForm.target = "ifDatePicker";
    oForm.method = "POST";
    oForm.action = "/DatePicker.aspx";
    oForm.submit();
    oForm.action = tmpAction;
    oForm.target = tmpTarget;
    
    ShowLoadingLayer(false);
}


function SubmitForm() {

    oForm = document.forms['formSP'];
    if (! oForm.infx_days.value) {

        oTxt = document.getElementById('Message');
        if (oTxt.value == "") alert(msgSelectPeriod);
        else alert(oTxt.value);

        return;
    }
    else {

        ShowLoadingLayer(true);
        oForm.selected_options.value = SelectedOptions();
        oForm.action = formAction;
        oForm.submit();
        //ShowLoadingLayer(false);
    }
}

function GetSelectedInfxType() {
    
    itype = document.forms['formSP'].itype.value;
    ttype = document.forms['formSP'].infx_transport_type.value;
    
    /*
	if (itype.length == 2 && (itype.substring(0,1) == 'F' || itype.substring(0,1) == 'B') && ttype == '') {
        //alert(12);
        itype = itype.substring(1);
        //itype = document.forms['formSP'].itype.value = itype;
        document.forms['formSP'].itype.value = itype;
        return itype;
    }
    */
    
    if (itype.length > 1) {
    	switch(itype.substring(0,1)) {
    		case "F":
    		case "B":
    				itype = itype.substring(1);
    			break;
    	}
    }
    
    document.forms['formSP'].itype.value = itype;
    
    itype = ttype + itype;
        //document.forms['formSP'].infx_transport_type.value +
        //document.forms['formSP'].itype.value;
    
    // if (itype.indexOf('FF') > -1) itype = itype.substring(1);
    //alert(itype);
    
    return itype;
}


/****************************************************
                FILTERING FUNCTIONS
*****************************************************/
var arrSelFilters = new Array();
var filterObject = new Object();
var arrFilterData = new Array();
var arrAllFilterData = new Array();
var bAddExtraFilters = false;
var bAddExtraFilterObjects = true;

function ResetFilters() {
    
    dataList = allData;
    arrSelFilters = new Array();
    filterObject = new Object();
    arrFilterData = arrAllFilterData;

    ShowResults();
    SetNumberOfPages();
    SetFilterOptions();
}

function SetFilterOptions() {

    if (typeof(dataList) == "undefined") {
        setTimeout('SetFilterOptions()',500);
        return;
    }
    
    // set loading image
    // document.getElementById('divFilters').innerHTML = "<img src='/images/loader.gif' border='0' />";

    filterObject = new Object();
    var oOffersData = dataList;
    SetFilterData();


    arrCodeList = new Array();
    for (var i = 0;i < oOffersData.length;i++) {
        /*
        switch(oOffersData[i].object_code.substring(0,1)) {
            case 'H':
            case 'A':
            case 'M':
                //giata_code
                arrCodeList.push(oOffersData[i].object_code.substr(0,5));
            break;

            default:
                arrCodeList.push(oOffersData[i].object_code);
            break;
        }
        */
        arrCodeList.push(oOffersData[i].object_code);
    }

    codeList = arrCodeList.join(',');
    tmpInfxType = GetSelectedInfxType();
    
    //alert(codeList);

    for(var i = 0;i < arrFilterData.length;i++) {
        
        for (var x in  arrFilterData[i]) {

            switch(x) {
                case 'id':
                case 'type':
                case 'name':
                case 'active':
                case 'code':
                    continue;
                break;
            }

            if (! arrFilterData[i][x] || arrFilterData[i][x] == 'no' || arrFilterData[i][x] == 'some') continue;

            switch(tmpInfxType) {
                case "P":
                case "FP":
                case "L":
                case "FL":

                    bAddExtraFilters = true;
                    if (! arrFilterData[i][x] || arrFilterData[i][x] == '0') continue;
                break;
            }

            switch(x) {
                
                case "type_of_beach":
                case "service":
                case "x_bedrooms_app":

                    if (! filterObject[x]) filterObject[x] = new Object();
                    arrOptions = arrFilterData[i][x].split(',');
                    o = filterObject[x];

                    for (var j = 0;j < arrOptions.length;j++) {
                        if (! o[arrOptions[j]]) o[arrOptions[j]] = new Array();
                        if (InCodeList(codeList,arrFilterData[i].code)) o[arrOptions[j]].push(arrFilterData[i].code);
                    }

                break;

                case "port":
                    if (! filterObject[x]) filterObject[x] = new Object();
                    arrOptions = arrFilterData[i][x].split(',');
                    o = filterObject[x];

                    if (! o["port_R"]) o["port_R"] = new Array();
                    if (! o["port_Z"]) o["port_Z"] = new Array();
                    if (! o["port_T"]) o["port_T"] = new Array();
                    if (! o["port_D"]) o["port_D"] = new Array();

                    if (InCodeList(codeList,arrFilterData[i].code)) o[arrFilterData[i].port].push(arrFilterData[i].code);
                    
                    /*
                    switch(arrFilterData[i].port) {
                        case "port_R": if (InCodeList(codeList,arrFilterData[i].code)) o["port_R"].push(arrFilterData[i].code); break;
                        case "port_Z": if (InCodeList(codeList,arrFilterData[i].code)) o["port_Z"].push(arrFilterData[i].code); break;
                        case "port_T": if (InCodeList(codeList,arrFilterData[i].code)) o["port_T"].push(arrFilterData[i].code); break;
                        case "port_D": if (InCodeList(codeList,arrFilterData[i].code)) o["port_D"].push(arrFilterData[i].code); break;
                    }
                    */
                break;
                
                case "ctype":
                    if (! filterObject[x]) filterObject[x] = new Object();
                    arrOptions = arrFilterData[i][x].split(',');
                    o = filterObject[x];
                    
                    if (! o["type_W"]) o["type_W"] = new Array();
                    if (! o["type_B"]) o["type_B"] = new Array();
                    if (! o["type_S"]) o["type_S"] = new Array();
                    
                    if (InCodeList(codeList,arrFilterData[i].code)) o[arrFilterData[i].ctype].push(arrFilterData[i].code); break;
                    
                    /*
                    switch(arrFilterData[i].ctype) {
                        case "type_W": if (InCodeList(codeList,arrFilterData[i].code)) o["type_W"].push(arrFilterData[i].code); break;
                        case "type_B": if (InCodeList(codeList,arrFilterData[i].code)) o["type_B"].push(arrFilterData[i].code); break;
                        case "type_S": if (InCodeList(codeList,arrFilterData[i].code)) o["type_S"].push(arrFilterData[i].code); break;
                    }
                    */

                break;


                case "region":

                    if (! filterObject[x]) filterObject[x] = new Object();
                    arrOptions = arrFilterData[i][x].split(',');
                    o = filterObject[x];

                    if (! o["reg_1"]) o["reg_1"] = new Array();
                    if (! o["reg_2"]) o["reg_2"] = new Array();
                    if (! o["reg_4"]) o["reg_4"] = new Array();
                    if (! o["reg_si"]) o["reg_si"] = new Array();
                    if (! o["reg_mk"]) o["reg_mk"] = new Array();
                    if (! o["reg_me"]) o["reg_me"] = new Array();
                    if (! o["reg_d"]) o["reg_d"] = new Array();
//                    if (! o["reg_3"]) o["reg_3"] = new Array();
//                    if (! o["reg_5"]) o["reg_5"] = new Array();
//                    if (! o["reg_6"]) o["reg_6"] = new Array();

                    if (InCodeList(codeList,arrFilterData[i].code)) {

                        try {
                            switch(arrFilterData[i].region) {
                                case "reg_1":
                                case "reg_2":
                                case "reg_4":
                                case "reg_si":
                                case "reg_me":
                                case "reg_mk":
                                	
                                    o[arrFilterData[i].region].push(arrFilterData[i].code);
                                break;

                                default:
                                    o["reg_d"].push(arrFilterData[i].code);
                                break;
                            }

                        } catch(e) {
                            //alert(arrFilterData[i].region.toSource());
                            //return;
                        }
                    }

                break;


                case "category":
                    // categroy starts from 1 to 3, 3 to 4 , from 4 to 5
                    if (! filterObject[x]) filterObject[x] = new Object();
                    arrOptions = arrFilterData[i][x].split(',');
                    o = filterObject[x];

                    if (! o["1_3"]) o["1_3"] = new Array();
                    if (! o["3_4"]) o["3_4"] = new Array();
                    if (! o["4_5"]) o["4_5"] = new Array();
                    // cruises category
                    if (! o["cat_APLUS"]) o["cat_APLUS"] = new Array();
                    if (! o["cat_A"]) o["cat_A"] = new Array();
                    if (! o["cat_B"]) o["cat_B"] = new Array();
                    
                    if (InCodeList(codeList,arrFilterData[i].code)) {
                        switch(arrFilterData[i].category) {
    
                            case "1":
                            case "2":
                                o["1_3"].push(arrFilterData[i].code);
                            break;

                            case "3":
                                o["1_3"].push(arrFilterData[i].code);
                                o["3_4"].push(arrFilterData[i].code);
                            break;

                            case "4":
                                o["3_4"].push(arrFilterData[i].code);
                                o["4_5"].push(arrFilterData[i].code);
                            break;

                            case "5":
                                o["4_5"].push(arrFilterData[i].code);
                            break;

                            case "cat_APLUS":   o["cat_APLUS"].push(arrFilterData[i].code);   break;
                            case "cat_A":       o["cat_A"].push(arrFilterData[i].code);       break;
                            case "cat_B":       o["cat_B"].push(arrFilterData[i].code);       break;
                        }
                    }

                break;

                default:

                    if (! filterObject[x]) filterObject[x] = new Array();
                    if (InCodeList(codeList,arrFilterData[i].code)) filterObject[x].push(arrFilterData[i].code);

                break;
            }
        }
    }

    AddExtraFilters(filterObject);
    
    // check for no rendering
    try { if (arguments[0] == true) return; /* if no renderign exit function */ } catch(e) {}
    
    
    
    
    RenderFilterOptions(filterObject);

    SetSelectedFilters();
    SetContentHeight();
}

function InCodeList(list,code) {

    /*
    giata_code
    switch(code.substring(0,1)) {
        case "H":
        case "A":
        case "M":
            code = code.substr(0,5);
        break;
    }
    */

    return list.indexOf(code) > -1;
}

function AddExtraFilters(oFilters){

    if (! bAddExtraFilters) return;

    oArr_1_5 =  new Array();
    oArr_6_8 =  new Array();
    oArr_9_0 =  new Array();


    if (g_lang == 'nl' || g_lang == 'en') {

        arrPrice_000_100 =  new Array();
        arrPrice_000_200 =  new Array();
        arrPrice_100_250 =  new Array();
        arrPrice_200_350 =  new Array();
        arrPrice_300_500 =  new Array();
    }


    for(var i = 0;i < dataList.length;i++) {
    	
    	/*
        if (dataList[i].tot_allowed_persons < 6) oArr_1_5.push(dataList[i].object_code);
        else if (dataList[i].tot_allowed_persons >= 6 && dataList[i].tot_allowed_persons <= 8) oArr_6_8.push(dataList[i].object_code);
        else if (dataList[i].tot_allowed_persons >= 9) oArr_9_0.push(dataList[i].object_code);
        */
        if (dataList[i].max_allowed_persons < 6) oArr_1_5.push(dataList[i].object_code);
        else if (dataList[i].max_allowed_persons >= 6 && dataList[i].max_allowed_persons <= 8) oArr_6_8.push(dataList[i].object_code);
        else if (dataList[i].max_allowed_persons >= 9) oArr_9_0.push(dataList[i].object_code);

        // add price filter for holland
        if (g_lang == 'nl' || g_lang == 'en') {
            fPrice = (dataList[i].price * dataList[i].tot_allowed_persons)/ dataList[i].days;

            if (fPrice <= 100) arrPrice_000_100.push(dataList[i].object_code);
            if (fPrice <= 200) arrPrice_000_200.push(dataList[i].object_code);
            if (fPrice >= 100 && fPrice < 250) arrPrice_100_250.push(dataList[i].object_code);
            if (fPrice >= 200 && fPrice < 350) arrPrice_200_350.push(dataList[i].object_code);
            if (fPrice >= 300) arrPrice_300_500.push(dataList[i].object_code);
        }


    }

    oFilters['pers_1_5'] = oArr_1_5;
    oFilters['pers_6_8'] = oArr_6_8;
    oFilters['pers_9_0'] = oArr_9_0;

    if (g_lang == 'nl' || g_lang == 'en') {
        oFilters['price_000_100'] = arrPrice_000_100;
        oFilters['price_000_200'] = arrPrice_000_200;
        oFilters['price_100_250'] = arrPrice_100_250;
        oFilters['price_200_350'] = arrPrice_200_350;
        oFilters['price_300_500'] = arrPrice_300_500;
    }

    bAddExtraFilters = false;
}

function RenderFilterOptions(filterObject) {

    strHTML = "";

    var iRowCount = 0;
    var iRowsPerCols = 9;
    var arrFilterOptions = new Array();

    arrOptions = new Array('id','code','type','name','region','category','service','type_of_beach',
        'sep_content','wellness','fitness','tv','aircondition','wlan_hotspot','internet_corner','family_rooms','swimmingpool_indoor','swimmingpool_outdoor','swimmingpool_indoor_salt','swimmingpool_outdoor_salt','swimmingpool_indoor_sweet','swimmingpool_outdoor_sweet',
		'sep_other','pets_allowed','childfriendly','animation','cultural_options',
        'sep','parking_posibilities','direct_near_the_beach','beach_within_1km','fkk_beach_within_1km','centre_within_1km','restaurant_within_1km','supermarket_within_1km','docterservice_within_1km','laundry_service',
  		'sep','sportfacilities','tennis','bicycle_to_rent_within_1km','horse_riding_within_1km','watersport',
		'sep','x_bedrooms_app','microwave','oven','BBQ');
    
    g_iType = GetSelectedInfxType();

    switch(g_iType) {
        
        case "H":
        case "A":
        case "M":
        case "FH":
        case "FA":
        case "FM":
              ;;
        break;
        
        case "P":
        case "FP":
        case "L":
        case "FL":
            arrOptions = new Array('id','code','name','region',
              'sep_accommodation','is_house','is_app','is_room',
              'sep_content','has_sattv','has_wash_machine','has_owen','has_microwave_owen','has_dish_washer',
              'has_swimmingpool','has_indoor_swimmingpool','has_whirlpool',
              'has_child_bed','has_playground','has_grill',
              'sep_other','pets_allowed','pets_not_allowed',
              'has_biking','has_horse_riding',
              'sep_persons','pers_1_5','pers_6_8','pers_9_0');


            if (g_lang == 'nl' || g_lang == 'en') {
                arrOptions.push('sep_price');
                arrOptions.push('price_000_100');
                arrOptions.push('price_000_200');
                arrOptions.push('price_100_250');
                arrOptions.push('price_200_350');
                arrOptions.push('price_300_500');
            }


        break;

        default:
            arrOptions = new Array();
            for (var z in filterObject)  arrOptions.push(z);

        break;

    }

    for (var i = 0;i < arrOptions.length;i++) {

        var x = arrOptions[i];
        sFilterOption = FromFilterDictionary(x);

        if (x.indexOf('sep') >= 0) {

            if (x.indexOf('_') > -1) strHTML = "<li class='sep'>" + sFilterOption + ":</li>";
            else strHTML = "";
            //else strHTML = "<li class='empty'>" + "&nbsp;" + "</li>";

            arrFilterOptions.push(strHTML);
            continue;
        }

        if (! filterObject[x]) continue;

        if (filterObject[x].constructor.toString().indexOf('Array') > -1 ) {

            if (arrSelFilters.toString().indexOf(x) >-1) continue;
            if (filterObject[x].length == 0) continue;

            strHTML = "<li>" + FilterInfo(x) + " <a onClick='javascript:FilterResults(\"" + x + "\");' href='#'>" + sFilterOption + "</a> (" + filterObject[x].length + ")</li>";
            arrFilterOptions.push(strHTML);
        }
        else {

            if (arrSelFilters.toString().indexOf(x) >-1) continue;

            strHTML = "<li class='sep'>" + sFilterOption + ":</li>";
            arrFilterOptions.push(strHTML);

            for (y in filterObject[x]) {

                if (arrSelFilters.toString().indexOf(y) >-1) continue;
                if (filterObject[x][y].length == 0) continue;

                sFilterOption = FromFilterDictionary(y);

                strHTML = "<li> " +  FilterInfo(y) + "<a onClick='javascript:FilterResults(\"" + x + "\",\"" + y + "\");' href='#'>" + sFilterOption + "</a> (" + filterObject[x][y].length + ")</li>";
                arrFilterOptions.push(strHTML);
            }
        }
    }

    // render options
    iRowsPerCols = Math.round(arrFilterOptions.length / 3);
    strHTML = "";
    for (var i = 0;i < arrFilterOptions.length;i++) {
        strHTML += arrFilterOptions[i];
        iRowCount = (i+1);
        if (isB2B && (iRowCount % iRowsPerCols == 0)) strHTML += "</ul></td><td><ul>";
    }

    if (strHTML.indexOf('<ul') == -1 && (! isB2B)) strHTML = "<h2 align='left' style='font-size:" + (g_lang != "de" ? "20" : "13")  + "px;'>" + FromFilterDictionary("fine_search") + " </h2><ul>" + strHTML + "</ul>";
    if (isB2B && strHTML != "") strHTML = "<table width='100%'><tr><td colspan='3'><h2 align='left' style='font-size:20px;'>&nbsp;" + FromFilterDictionary("fine_search") + " </h2></td></tr><tr><td><ul>" + strHTML + "</ul></td></tr></table>";

    //alert(strHTML);
    
    document.getElementById('divFilters').innerHTML = strHTML;
}


function FilterInfo(o) {

    switch(g_iType) {
        case "M":
        case "A":
        case "H":
        case "FM":
        case "FA":
        case "FH":

            if (o == "pets_allowed") return "";

        break;
    }

    for (var i = 0;i < oFilterInfo.length;i++) {
        if (oFilterInfo[i].key == o) {

            sInfo = "<img src=\"/images/info.gif\" width=\"17\" style=\"vertical-align:bottom;\" alt=\"|INFO|\" title=\"|INFO|\" />";
            sInfo = sInfo.replace("|INFO|",oFilterInfo[i].value);
            sInfo = sInfo.replace("|INFO|",oFilterInfo[i].value);

            return sInfo;
        }
    }
    return "";
}

function FromFilterDictionary(o) {

    for (var i = 0;i < oFilterDictionary.length;i++)
        if (oFilterDictionary[i].key == o) return oFilterDictionary[i].value;

    return o;
}

function SetSelectedFilters() {
    
    //alert('SetSelectedFilters');

    var strHTML = "";
    document.getElementById('divSelFilters').innerHTML = strHTML;

    for (var i = 0;i < arrSelFilters.length;i++) {
                                                                                                               //<img src=\"/images/remove1.gif\" width=\"16\" style=\"vertical-align:top;\" alt=\"|INFO|\" title=\"|INFO|\" />
        if (arrSelFilters[i].indexOf(':') > -1) {
            tmpSelFilter = arrSelFilters[i].split(':');
            strHTML += "<a href=\"#\" onClick=\"javascript:RemoveFilter('" + tmpSelFilter[0] + ":" + tmpSelFilter[1] + "');\" ><span style='font-weight:bold;color:red;'>x</span></a> ";
            strHTML += FromFilterDictionary(tmpSelFilter[0]) + ": ";
            strHTML += FromFilterDictionary(tmpSelFilter[1]) + (isB2B ? ", " : "<br/>");
            continue;
        }

        strHTML += "<a href=\"#\" onClick=\"javascript:RemoveFilter('" + arrSelFilters[i] + "');\" ><span style='font-weight:bold;color:red;'>x</span></a> " +  FromFilterDictionary(arrSelFilters[i]) + (isB2B ? ", " : "<br/>");
    }

    if (strHTML == "") {
        document.getElementById('divSelFilters').innerHTML = "";
        return;
    }

    strHTML += "<br/><a href='javascript:ResetFilters();'>" + FromFilterDictionary('reset_filters') + "</a><br/>";
    document.getElementById('divSelFilters').innerHTML = "<b>" + FromFilterDictionary('filtered_by') + ":</b><br/>"  + strHTML;
}

// show the filtered resutls in the list
function FilterResults(filter) {

    //alert('FilterResults');
    dataList = [];
    arrCodes = new Array();

    if (arguments.length == 1) {
        arrCodes = filterObject[filter];
        arrSelFilters.push(filter);
    }
    else {
        arrCodes = filterObject[filter][arguments[1]];
        arrSelFilters.push(filter + ":" +  arguments[1]);
    }
    sCodes = arrCodes.join(',');

    //alert("sCodes = "  + sCodes);

    var count = 0;
    for(var i = 0;i < allData.length;i++) {

        //giata
        tmpCode = allData[i].object_code;
        /*
        switch(tmpCode.substring(0,1)) {
            case 'H':
            case 'A':
            case 'M':
                tmpCode = allData[i].object_code.substr(0,5);
            break;
        }
        */
        
        //if (sCodes.indexOf(allData[i].object_code) == -1) continue;
        if (sCodes.indexOf(tmpCode) == -1) continue;
        dataList[count] =  allData[i];
        count += 1;
    }

    ShowResults();
    SetNumberOfPages();
    SetFilterOptions();
}

function clone(o) {
    
    function c(o) {
        for (var i in o) {
            this[i] = o[i];
        }
    }
    return new c(o);
}


function SetFilterData() {

    // set specila offer filtes

    if (bAddExtraFilterObjects) {
        var iLen = arrFilterData.length;

        for (var i = 0;i < iLen;i++) {
            switch(arrFilterData[i].code.substring(0,1)) {
                case 'H':
                case 'A':
                case 'M':

                    if (arrFilterData[i].code.substr(5,1) == 'A') {
                        tmpObj = clone(arrFilterData[i]);
                        tmpObj.code = tmpObj.code.substr(0,5) + 'G';
                        arrFilterData.push(tmpObj);
                    }

                break;
            }
        }
        bAddExtraFilterObjects = false;
    }


    var oOffers = dataList;
    var arrOfferCodes = new Array();
    for (var i = 0;i < oOffers.length;i++)
        arrOfferCodes[i] = oOffers[i].object_code;

    var sCodes = arrOfferCodes.join(',');
    var tmpFilterData = new Array();

    for (var i = 0;i < arrFilterData.length;i++) {
        
        /*
        switch(arrFilterData[i].code.substring(0,1)) {
            case 'H':
            case 'A':
            case 'M':
                arrFilterData[i].code = arrFilterData[i].code.substr(0,5);
            break;
        }
        */


        if (sCodes.indexOf(arrFilterData[i].code) == -1) continue;
        tmpFilterData.push(arrFilterData[i]);
    }

    arrFilterData = tmpFilterData;
}


function RefilterResults(filter) {

    dataList = [];
    arrCodes = new Array();

    if (arguments.length == 1) {
        arrCodes = filterObject[filter];
        arrSelFilters.push(filter);
    }
    else {
        arrCodes = filterObject[filter][arguments[1]];
        arrSelFilters.push(filter + ":" +  arguments[1]);
    }

    try { sCodes = arrCodes.join(',');
    } catch(e) {
        alert("err: \n filter:\n " + filter + "\n args: " + arguments.length);
    }

    var count = 0;
    for(var i = 0;i < allData.length;i++) {

        if (sCodes.indexOf(allData[i].object_code) == -1) continue;
        dataList[count] =  allData[i];
        count += 1;
    }

    SetFilterData();
}


function RemoveFilter() {

    tmpSelFilters = arrSelFilters;
    var iIndex = -1;

    for (var i = 0;i < tmpSelFilters.length;i++) {
        if (tmpSelFilters[i] != arguments[0]) continue;
        iIndex = i;
        break;
    }

    if (iIndex == -1) return;
    tmpSelFilters.splice(iIndex,1);
    
    //**************** reset all filters ***************
    dataList = allData;
    arrSelFilters = new Array();
    filterObject = new Object();
    arrFilterData = arrAllFilterData;
    //**************************************************

    SetFilterOptions(true); // true == no rendering filter options

    for (var i = 0;i < tmpSelFilters.length;i++) {

        if (tmpSelFilters[i].indexOf(':') > -1) {
            params = tmpSelFilters[i].split(':');
            RefilterResults(params[0],params[1]);
        }
        else RefilterResults(tmpSelFilters[i]);
    }

    SetSelectedFilters();
    ShowResults();
    SetNumberOfPages();
    SetFilterOptions();
}

function SetContentHeight() {
    
    //if (g_bResized == true) return;

    oTbls = document.getElementsByTagName("table");
    oTbl = null;

    for(var i = 0;i < oTbls.length;i++) {
        if (oTbls[i].className == 'ContentTable') {
            oTbl = oTbls[i];
            break;
        }
    }

    if (! oTbl) return;
    if (oTbl.rows[0].cells[0].className != "Stupac44") return;

    var oDivs = document.getElementsByTagName("div");
    var ooDivs = new Object();
    var iContentHeight = 0;
    var iMenuHeight = 0;

    for (var i = 0;i <  oDivs.length;i++) {

        switch(oDivs[i].className) {
            case "Header":
            case "Content":
                iContentHeight += oDivs[i].offsetHeight;
                ooDivs[oDivs[i].className] = oDivs[i];
            break;

            case "LjeviStupac":
                iMenuHeight += oDivs[i].offsetHeight;
                ooDivs[oDivs[i].className] = oDivs[i];
            break;
        }

    }

    oDivFilters = document.getElementById("divFilters");
    iMenuHeight += oDivFilters.offsetHeight;
    //alert(iMenuHeight + "," + iContentHeight);

    if (iMenuHeight > iContentHeight) {

        sHeight = (ooDivs["Content"].offsetHeight + (iMenuHeight-iContentHeight) / 1.5) + "px";
        ooDivs["Content"].style.height = sHeight;
    }
    /*
    else if (iMenuHeight < iContentHeight) {
            alert(2);
        sHeight = (ooDivs["Content"].offsetHeight + (iContentHeight-iMenuHeight) / 4) + "px";
        ooDivs["Content"].style.height = sHeight;
    }
    */
}



function ShowLoadingLayer(bShow) {

    if (isB2B) return;
    if (! document.getElementById('divLoader')) return;

    if (! bShow) {
        document.getElementById('divLoader').style.visibility = 'hidden';
        document.getElementById('divLoader').style.width = '0px';
        document.getElementById('divLoader').style.height = '0px';
        document.getElementById('sp').style.visibility = 'visible';
        return;
    }

    document.getElementById('sp').style.visibility = 'hidden';
    document.getElementById('divLoader').style.visibility = 'visible';
    document.getElementById('divLoader').style.width = '100%';
    document.getElementById('divLoader').style.height = (isB2B ? '200px' : '100px');
}

/*
jsc = new JSCalendar();
jsc.startingWeekday = 1;
jsc.daysOfWeek = new Array('SO','MO','DI','MI','DO','FR','SA');
jsc.months = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
jsc.date = null;
jsc.closeButton = "Schließen";
*/

