function CleanMultipleSelect(objID) {
	obj = document.getElementById(objID);
	if (obj) {
		for (i = 0; i < obj.options.length; i++) {
			if (obj.options[i].selected) {
				obj.options[i].selected = false;
			}
		}
	}
}

function fnc_popupAruodas(deal) {

	url = "";
    var firstPageSearch = false;
	// creting array to recode IDs of parishes from edomus.lt to aruodas.lt style
	ar_parishes = new Array ();
	ar_parishes[542]	= 260; 		// "Akmenės r. sav."
	ar_parishes[561]	= 2; 		// "Alytaus m. sav."
	ar_parishes[562]	= 4;		// "Alytaus r. sav."
	ar_parishes[582] 	= 393;		// "Anykščių r. sav."
	ar_parishes[516] 	= 42;		// "Birštono sav."
	ar_parishes[554] 	= 206;		// "Biržų r. sav."
	ar_parishes[563] 	= 3; 		// "Druskininkų sav."
	ar_parishes[502] 	= 1191;		// "Elektrėnų sav."
	ar_parishes[586] 	= 413;		// "Ignalinos r. sav."
	ar_parishes[519] 	= 44;		// "Jonavos r. sav."
	ar_parishes[543] 	= 267;		// "Joniškio m. sav."
	ar_parishes[544] 	= 267;		// "Joniškio r. sav."
	ar_parishes[602] 	= 346;		// "Jurbarko r. sav."
	ar_parishes[521] 	= 53;		// "Kaišiadorių r. sav."
	ar_parishes[571] 	= 1192;		// "Kalvarijos sav."
	ar_parishes[514] 	= 43;		// "Kauno m. sav."
	ar_parishes[515] 	= 63;		// "Kauno r. sav."
	ar_parishes[573] 	= 1193;		// "Kazlų Rūdos sav."
	ar_parishes[523] 	= 215;		// "Kėdainių r. sav."
	ar_parishes[545] 	= 278;		// "Kelmės r. sav."
	ar_parishes[528] 	= 112;		// "Klaipėdos m. sav."
	ar_parishes[529] 	= 115;		// "Klaipėdos r. sav."
	ar_parishes[534] 	= 127;		// "Kretingos r. sav."
	ar_parishes[556] 	= 228;		// "Kupiškio r. sav."
	ar_parishes[566] 	= 27;		// "Lazdijų r. sav."
	ar_parishes[569] 	= 162;		// "Marijampolės sav."
	ar_parishes[594] 	= 359;		// "Mažeikių r. sav."
	ar_parishes[584] 	= 426;		// "Molėtų r. sav."
	ar_parishes[530] 	= 113;		// "Neringos sav."
	ar_parishes[603] 	= 1196;		// "Pagėgių sav."
	ar_parishes[548] 	= 289;		// "Pakruojo r. sav."
	ar_parishes[531] 	= 114;		// "Palangos m. sav."
	ar_parishes[551] 	= 205;		// "Panevėžio m. sav."
	ar_parishes[552] 	= 235;		// "Panevėžio r. sav."
	ar_parishes[558] 	= 247;		// "Pasvalio r. sav."
	ar_parishes[596] 	= 367;		// "Plungės r. sav."
	ar_parishes[525] 	= 86;		// "Prienų r. sav."
	ar_parishes[550] 	= 298;		// "Radviliškio r. sav."
	ar_parishes[527] 	= 98;		// "Raseinių r. sav."
	ar_parishes[597] 	= 1197;		// "Rietavo sav."
	ar_parishes[598] 	= 1197;		// "Rietavo r sav."
	ar_parishes[559] 	= 438;		// "Rokiškio m. sav."
	ar_parishes[560] 	= 438;		// "Rokiškio r. sav."
	ar_parishes[535] 	= 136;		// "Skuodo m. sav."
	ar_parishes[536] 	= 136;		// "Skuodo r. sav."
	ar_parishes[576] 	= 187;		// "Šakių r. sav."
	ar_parishes[505] 	= 513;		// "Šalčininkų r. sav."
	ar_parishes[539] 	= 259;		// "Šiaulių m. sav."
	ar_parishes[540] 	= 311;		// "Šiaulių r. sav."
	ar_parishes[606] 	= 332;		// "Šilalės r. sav."
	ar_parishes[538] 	= 146;		// "Šilutės r. sav."
	ar_parishes[507] 	= 539;		// "Širvintų r. sav."
	ar_parishes[509] 	= 526;		// "Švenčionių r. sav."
	ar_parishes[600] 	= 323;		// "Tauragės r. sav."
	ar_parishes[592] 	= 381;		// "Telšių r. sav."
	ar_parishes[513] 	= 487;		// "Trakų r. sav."
	ar_parishes[511] 	= 501;		// "Ukmergės r. sav."
	ar_parishes[580] 	= 449;		// "Utenos r. sav."
	ar_parishes[567] 	= 16;		// "Varėnos m. sav."
	ar_parishes[568] 	= 16;		// "Varėnos r. sav."
	ar_parishes[578] 	= 163;		// "Vilkaviškio r. sav."
	ar_parishes[500] 	= 461;		// "Vilniaus m. sav."
	ar_parishes[501] 	= 462;		// "Vilniaus r. sav."
	ar_parishes[587] 	= 459;		// "Visagino sav."
	ar_parishes[590] 	= 403;		// "Zarasų r. sav."

	// get common fields
	if (document.searchform.parish) {
		// parish_id
		parish_id = document.searchform.parish.options[document.searchform.parish.selectedIndex].value;
		// recode parish id to the aruodas codes
		aruodas_parish_id = ar_parishes[parish_id];
	} else {
		aruodas_parish_id = "";
	}

	// other fields
	
	// price min/max
	price_min = parseInt(document.searchform.price_min.value, 10);
	price_max = parseInt(document.searchform.price_max.value, 10);
	
	if (isNaN(price_min) || price_min == 0) {
		price_min = "";
	}

	if (isNaN(price_max) || price_max == 0) {
		price_max = "";
	}

	if (price_min.length > 0 && price_max.length > 0) {
		if (price_max < price_min) {
			price_tran = price_max;
			price_max = price_min;
			price_min = price_tran;
		}
	}

	// only with pictures
	if (document.searchform.images_only.checked) {
		images_only = 1;
	} else {
		images_only = 0;
	}

    //if deal undefined then search is submitted from index page - no other values
    if(deal == undefined){
        var sel = document.getElementsByName('deal_type')[0];
        deal = sel.options[sel.selectedIndex].value;
        firstPageSearch = true;
    } else {
        // order by
        order_by = document.ordering_form.selected_order.options[document.ordering_form.selected_order.selectedIndex].value;

        switch (order_by) {
            case "pa":
            case "pd":
                order = "Price";
            break;

            case "ch": // newest
                order = "";
            break;
        }

        // check type of deal and read all the data from the corresponding fields
        if (deal == 1 || deal == 2) {
            // apartments
            // we are not setting condition while condition for edomus is multiple and condition for aruodas is single. so by not setting anything - we are avoiding a lot of mess.

            // roooms min/max
            room_min = parseInt(document.searchform.rooms_min.value, 10);
            if (isNaN(room_min) || room_min == 0) {
                room_min = "";
            }

            room_max = parseInt(document.searchform.rooms_max.value, 10);
            if (isNaN(room_max) || room_max == 0) {
                room_max = "";
            }

            // area min/max
            area_min = parseInt(document.searchform.area_min.value, 10);
            if (isNaN(area_min) || area_min == 0) {
                area_min = "";
            }

            area_max = parseInt(document.searchform.area_max.value, 10);
            if (isNaN(area_max) || area_max == 0) {
                area_max = "";
            }

        } else if (deal == 3 || deal == 4 || deal == 11 || deal == 12) {
            // houses, sharehouses
            // house area
            area_min = parseInt(document.searchform.area_total_min.value, 10);
            if (isNaN(area_min) || area_min == 0) {
                area_min = "";
            }

            area_max = parseInt(document.searchform.area_total_max.value, 10);
            if (isNaN(area_max) || area_max == 0) {
                area_max = "";
            }

            // land area
            area_ground_min = parseInt(document.searchform.area_ground_min.value, 10);
            if (isNaN(area_ground_min) || area_ground_min == 0) {
                area_ground_min = "";
            }

            area_ground_max = parseInt(document.searchform.area_ground_max.value, 10);
            if (isNaN(area_ground_max) || area_ground_max == 0) {
                area_ground_max = "";
            }

        } else if (deal == 7 || deal == 6) {
            // premises
            // premises area
            area_min = parseInt(document.searchform.area_total_min.value, 10);
            if (isNaN(area_min) || area_min == 0) {
                area_min = "";
            }

            area_max = parseInt(document.searchform.area_total_max.value, 10);
            if (isNaN(area_max) || area_max == 0) {
                area_max = "";
            }
        } else if (deal == 8 || deal == 9) {
            // garages
            // area is not set
            area_min = "";
            area_max = "";
        } else if (deal == 5){
            // plots
            // land area
            area_min = parseInt(document.searchform.area_ground_min.value, 10);
            if (isNaN(area_min) || area_min == 0) {
                area_min = "";
            }

            area_max = parseInt(document.searchform.area_ground_max.value, 10);
            if (isNaN(area_max) || area_max == 0) {
                area_max = "";
            }
        } else {
            // do nothing
        }
    }

	if (deal == 1) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=Butai";
	} else if (deal == 2) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=ButaiNuoma";
	} else if (deal == 3 || deal == 11) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=Namai";
	} else if (deal == 4 || deal == 12) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=NamaiNuoma";
	} else if (deal == 7 || deal == 8) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=Patalpos";
	} else if (deal == 6 || deal == 9) {
		url = "http://www.aruodas.lt/index.php?lng=Lt&mod=Siulo&act=PatalposNuoma";
    } else if (deal == 5) {
        url = "http://www.aruodas.lt/sklypai/";
	} else {
		// do nothing
	}

    if(!firstPageSearch){
        // total area
        url	+=	"&FAreaOverAllMin=" + area_min;
        url	+=	"&FAreaOverAllMax=" + area_max;

        // for houses only
        if (deal == 3 || deal == 4) {
            url	+=	"&FAreaLotMin=" + area_ground_min;
            url	+=	"&FAreaLotMax=" + area_ground_max;
        }

        // min/max number of rooms (for apartments only)
        if (deal == 1 || deal == 2) {
            url	+=	"&FRoomNumMin=" + room_min;
            url	+=	"&FRoomNumMax=" + room_max;
        }

        // order by
        url	+=	"&FOrder=" + order;
    }
    
    url	+=	"&FOrdDir=did";
    url	+=	"&redirect_edomus=";
    url	+=	"&FRegion=" + aruodas_parish_id;
    url	+=	"&FDistrict=0";
    
	// min/max price
	url	+=	"&FPriceMin=" + price_min;
	url	+=	"&FPriceMax=" + price_max;
	
	// only with images
	if (images_only == 1) {
		url += "&FImages=1";
	}

	// some not settable variables
	url += 	"&FBuildYear=";
	url += 	"&FHouseType=0";
	url += 	"&FWarmSystem=0";
	url += 	"&FHouseStat=0";
	url += 	"&FAddDate=0";

	window.open(url, "aruodasSearch", "status=1, toolbar=1, location=1, menubar=1, resizable=1, scrollbars=1, width=640, height=400");

}
