						function zamien_input(id){
							if(id == 'label_login'){
								$('label#label_login input#login').attr('value','');
								$('label#label_login input#login').attr('onclick','');
								$('label#label_login input#login').attr('onkeyup','');
								$('label#label_login input#login').attr('onchange','');
								$('label#label_login input#login').attr('class','');
								$('label#label_login input#login').focus();
							}else if(id == 'label_pass'){
								document.getElementById(id).innerHTML='<input id="pass" type="password" name="pass" value=""/>';
								setTimeout(function() { document.getElementById('pass').focus(); }, 10);
							}else if(id == 'label_search'){
								$('label#label_search input#search').attr('value','');
								$('label#label_search input#search').attr('onclick','');
								$('label#label_search input#search').attr('onkeyup','');
								$('label#label_search input#search').attr('onchange','');
								$('label#label_search input#search').attr('class','');
								$('label#label_search input#search').focus();
							}
                            /*$("#login_form_2").submit(function() { return false; });
                            $("#login").keydown(function(event) {
                                if (event.keyCode == 13) {
                                    event.stopPropagation();
                                    do_password_magic();
                                }
                            });
                            $("#pass").keydown(function(event) {
                                if (event.keyCode == 13) {
                                    event.stopPropagation();
                                    do_password_magic();
                                }
                            });*/
						}
                        /*function do_password_magic() {
                            // ajax call to check if user is staff-user
                            var login = $('#login_form_1 #login').val();
                            var pass = $('#login_form_1 #pass').val();

                            $.post('/user/check/', {
                                    login: login,
                                    pass: pass
                            }, function(ret) {
                                if (ret == '2') {
                                    $('#login_form_2 #login_2').val($("#login").val());
                                    $('#login_form_2 #pass_2').val($("#pass").val());
                                    $('#login_form_2').submit();
                                }
                            });
                            return false;
                        }
                        $(document).ready(function() {
                        });
                        */


// ------------------------- dla select lokalizacji (wyszukiwarka) na stronie glownej -----------
var $_GET = {};

document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) {
        return decodeURIComponent(s.split("+").join(" "));
    }

    $_GET[decode(arguments[1])] = decode(arguments[2]);
});




// czyszczenie zaznaczonych lokalizacji podrzednych po zaznaczeniu nadrzednej
function clear_multiple_other_location(val_arr){
    // usuwamy zaznaczenia
    $('input.search_loc_checkbox').each(function() {
        $(this).attr('checked', '');
        var temp_a = $(this).parent().find("a");
        if (temp_a.hasClass('hiLiteX')){
            temp_a.removeClass('hiLiteX');
        }
    });
    window.multiple_other_location_val = new Array();
    $('input[name=multiple_other_location]').val('');
    $('select[name=other_location]').next().find('div.selectedTxt').html(window.selected_locations_trans+' <strong>'+window.multiple_other_location_val.length+'</strong>');
    
    
    // uzupelniamy zaznaczenia (wszystkie lokalizacje podrzedne dla zaznaczonej nadrzednej)
    $('select[name=other_location]').next().find('ul > li > input').each(function() {
        if (jQuery.inArray(parseInt($(this).val()), val_arr)!=-1 && jQuery.inArray(parseInt($(this).val()), val_arr)!=undefined){
            $(this).attr('checked', 'checked');
            $(this).parent().find('a').addClass('hiLiteX');
            $(this).addClass('hiLiteX');
                
            if (jQuery.inArray($(this).val(), window.multiple_other_location_val)==-1 || jQuery.inArray($(this).val(), window.multiple_other_location_val)==undefined){
                 window.multiple_other_location_val.push($(this).val());
             }
        }
    });
    $('input[name=multiple_other_location]').val(window.multiple_other_location_val.join("_"));
    $('select[name=other_location]').next().find('div.selectedTxt').html(window.selected_locations_trans+' <strong>'+window.multiple_other_location_val.length+'</strong>');
}

// odznaczenie lokalizacji przeslanych w formularzu (get)
function load_multiple_other_location(){
    $('select[name=other_location]').next().find('ul > li > input').each(function() {
        if (window.location.toString().search("multiple_other_location")>-1){
            //if (jQuery.inArray($(this).val(), $_GET["multiple_other_location"].split('_'))!=-1 && jQuery.inArray($(this).val(), $_GET["multiple_other_location"].split('_'))){
            if (jQuery.inArray($(this).val(), $_GET["multiple_other_location"].split('_'))>-1 && jQuery.inArray($(this).val(), $_GET["multiple_other_location"].split('_'))!=undefined){
                $(this).attr('checked', 'checked');
                $(this).addClass('hiLiteX');
                $(this).parent().find('a').addClass('hiLiteX');
                
                if (jQuery.inArray($(this).val(), window.multiple_other_location_val)==-1 || jQuery.inArray($(this).val(), window.multiple_other_location_val)==undefined){
                    window.multiple_other_location_val.push($(this).val());
                }
            }
            else{
                if ($(this).parent().find('a').hasClass('hiLiteX')){
                    $(this).parent().find('a').removeClass('hiLiteX');
                }
                if ($(this).parent().find('input').hasClass('hiLiteX')){
                    $(this).parent().find('input').removeClass('hiLiteX');
                }
                $(this).attr('checked', '');
                var val_arr_pos = jQuery.inArray($(this).val(), window.multiple_other_location_val);
                
                //if (val_arr_pos>=-1 && val_arr_pos!=undefined && val_arr_pos){
                if (val_arr_pos>-1 && val_arr_pos!=undefined){
                    window.multiple_other_location_val.splice(val_arr_pos, 1);
                }
            }
        }
    });
    $('input[name=multiple_other_location]').val(window.multiple_other_location_val.join("_"));
    $('select[name=other_location]').next().find('div.selectedTxt').html(window.selected_locations_trans+' <strong>'+window.multiple_other_location_val.length+'</strong>');
}

// ---------------------------------------------------------------------------------






// skrypt do aktualizacji select z lokalizacjami (na podstawie lokalizacji glownych z checkbox) - wyszukiwarka             
            
            // pobiera liste lokalizacji podrzednych dla zaznaczonych elementow i aktualizuje select
            function mainLocOnChange(locationsString){
                $.get('/realestate/location_list/'+locationsString, function(data) {
		   
                    var el_arr = new Array();
                    var arr = data.split("\n");
                    window.keys_arr = new Array();
                    var val_arr = new Array();
                     
                     
                    for (el in arr){
                        el_arr = arr[el].toString().split(";");
                        if (el_arr.length==2){
                            window.keys_arr.push(el_arr[1].toLowerCase());
                            val_arr.push(parseInt(el_arr[0]));
                        }                        
                    }
                    window.keys_arr.push("-----");
                    
                    $('#id_other_location ~ .newListSelected:eq(0) > ul.newList li, #id_other_location_left ~ .newListSelected:eq(0) > ul.newList li').each(function() {
                        $(this).css("display", "block");
                        
                        var el_text = $(this).find("a").text();
                        var el_pos = $.inArray(el_text.toLowerCase(), window.keys_arr);

                        if ((el_pos==-1 || el_pos==undefined) && window.keys_arr.length>0){
                            $(this).css("display", "none");
                        }
                        else{
                            if (window.keys_arr[el_pos].toUpperCase() == el_text){
                                $(this ).css("text-align", "center").css("background", "#C92724");
                                $(this ).find("a").css("font-weight", "bold").css("color", "#fff");
                            }
                        }
                        
                    });
                    clear_multiple_other_location(val_arr);   
                });
            }
            
            // akcja aktualizacji listy podrzednych lokalizacji
            function prepareLocations(){
                var locationsString = '';
                    
                $("input[name$='locations']:checked").each(function() {
                    locationsString+=$(this).val();
                    locationsString+="_";
                });
                    
                mainLocOnChange(locationsString);
            }            
            
            $(document).ready(function(){
                prepareLocations();
                
                
                $("input[name$='locations']").change(function(){
                    prepareLocations();
                });
                
                
                // set default values
                window.info_opis_content_size = parseInt($('.info_opis_content').css('font-size'));
                window.info_dane_td_size = parseInt($('.info_dane').find('td').css('font-size'));
                window.info_opis_build_td_size = parseInt($('.info_opis_build').find('td').css('font-size'));
                
                register_tooltips();
                
                setTimeout('load_multiple_other_location()', 1000);
                
                
                
                $('div.search_mag_right_txt').find('input[type=submit]').click(function() {
                    $("select[name='other_location']").val('');
                    return false;
                });
            });
            
            
            
            function font_size(s)
            {
                x = 2;
                s = parseInt(s)-1;
                
                if (s>0 && s<=2) {
                    // set
                    
                    $('.info_opis_content').css('font-size', window.info_opis_content_size+s*x+'px');
                    $('.info_dane').find('td').css('font-size', window.info_dane_td_size+s*x+'px');
                    $('.info_opis_build').find('td').css('font-size', window.info_opis_build_td_size+s*x+'px');
                }
                else {
                    // reset
                    
                    $('.info_opis_content').css('font-size', window.info_opis_content_size+'px');
                    $('.info_dane').find('td').css('font-size', window.info_dane_td_size+'px');  
                    $('.info_opis_build').find('td').css('font-size', window.info_opis_build_td_size+'px');                   
                }
            }
        


            function register_tooltips()
            {
                // show
                $('#view_list').mouseover(function() {show_tooltip("view_list_tooltip");});
                $('#view_details').mouseover(function() {show_tooltip("view_details_tooltip");});
                $('#view_map').mouseover(function() {show_tooltip("view_map_tooltip");});

                // hide
                $('#view_list').mouseout(function() {hide_tooltip("view_list_tooltip");});
                $('#view_details').mouseout(function() {hide_tooltip("view_details_tooltip");});
                $('#view_map').mouseout(function() {hide_tooltip("view_map_tooltip");});
            }
            function show_tooltip(id)
            {
                $('#'+id).css('display', 'block');
            }
            function hide_tooltip(id)
            {
                $('#'+id).css('display', 'none');
            }






 function ukryj(tag){
                with(document.getElementById('body_'+tag)){className=className=='ukryj'?'pokaz':'ukryj';}
                with(document.getElementById('left_'+tag)){className=className=='main_box_left'?'main_box_left_active':'main_box_left';}
                with(document.getElementById('title_'+tag)){className=className=='main_box_title_h'?'main_box_title_active_h':'main_box_title_h';}
                with(document.getElementById('char_'+tag)){className=className=='main_box_char'?'main_box_char_active':'main_box_char';}
                with(document.getElementById('next_'+tag)){className=className=='main_box_next'?'main_box_next_active':'main_box_next';}
                with(document.getElementById(tag)){className=className=='main_box'?'main_box_active':'main_box';}
                
                //with(document.getElementById(id)){className=='h'? document.getElementById(id2).style.fontWeight='normal':document.getElementById(id2).style.fontWeight='bold';}
                }

                function active(tag,click){
                if(click){
                $('div.other_mag_gallery_middle').find('div.one_photo_txt_active2').attr('class', 'one_photo_txt');
                $('div.other_mag_gallery_middle').find('div.border_top_a_active2').attr('class', 'border_top_a');
                $('div.other_mag_gallery_middle').find('div.border_top_active2').attr('class', 'border_top');
                $('div.other_mag_gallery_middle').find('div.border_middle_active2').attr('class', 'border_middle');
                $('div.other_mag_gallery_middle').find('div.border_bottom_a_active2').attr('class', 'border_bottom_a');
                $('div.other_mag_gallery_middle').find('div.border_bottom_active2').attr('class', 'border_bottom');
                with(document.getElementById('border_top_a_'+tag)){className=className=='border_top_a'?'border_top_a_active2':'border_top_a';}
                with(document.getElementById('border_top_'+tag)){className=className=='border_top'?'border_top_active2':'border_top';}
                with(document.getElementById('border_middle_'+tag)){className=className=='border_middle'?'border_middle_active2':'border_middle';}
                with(document.getElementById('border_bottom_a_'+tag)){className=className=='border_bottom_a'?'border_bottom_a_active2':'border_bottom_a';}
                with(document.getElementById('border_bottom_'+tag)){className=className=='border_bottom'?'border_bottom_active2':'border_bottom';}
                with(document.getElementById('one_photo_txt_'+tag)){className=className=='one_photo_txt'?'one_photo_txt_active2':'one_photo_txt';}
                }else{
                    if(document.getElementById('border_top_a_'+tag).className!='border_top_a_active2'){
                    with(document.getElementById('border_top_a_'+tag)){className=className=='border_top_a'?'border_top_a_active':'border_top_a';}
                    with(document.getElementById('border_top_'+tag)){className=className=='border_top'?'border_top_active':'border_top';}
                    with(document.getElementById('border_middle_'+tag)){className=className=='border_middle'?'border_middle_active':'border_middle';}
                    with(document.getElementById('border_bottom_a_'+tag)){className=className=='border_bottom_a'?'border_bottom_a_active':'border_bottom_a';}
                    with(document.getElementById('border_bottom_'+tag)){className=className=='border_bottom'?'border_bottom_active':'border_bottom';}
                    with(document.getElementById('one_photo_txt_'+tag)){className=className=='one_photo_txt'?'one_photo_txt_active':'one_photo_txt';}
                    }
                }
                }






                function slider_search(s1,id,id2,id3,min,max,start,tmp){
								if(s1==0){
									var s1 = new Slider(document.getElementById(id), document.getElementById(id2));
									if(tmp==1){
										s1.setMinimum(parseInt(min)*2);
										s1.setMaximum(parseInt(max)*2);
									}else if(tmp==2){
										s1.setMinimum(parseInt(min)/5);
										s1.setMaximum(parseInt(max)/5);
									}else if(tmp==3){
										s1.setMinimum(parseInt(min)/500);
										s1.setMaximum(parseInt(max)/500);
									}else{
										s1.setMinimum(parseInt(min));
										s1.setMaximum(parseInt(max));
									}
									s1.onchange = function () {
										if(tmp==1)
											document.getElementById(id3).value = s1.getValue2();
										else if(tmp==2)
											document.getElementById(id3).value = s1.getValue3();
										else if(tmp==3)
											document.getElementById(id3).value = s1.getValue4();
										else
											document.getElementById(id3).value = s1.getValue();
									};
									if(tmp==1)
										s1.setValue(start*2);
									else if(tmp==2)
										s1.setValue(start/5);
									else if(tmp==3)
										s1.setValue(start/500);
									else
										s1.setValue(start);

									window.onresize = function () {
										s1.recalculate();
									};
									return s1;
								}else{
									return s1;
								}
								}
								function change(s1,liczba,tmp){
									if(tmp==1)
										s1.setValue(liczba*2);
									else if(tmp==2)
										s1.setValue(liczba/5);
									else if(tmp==3)
										s1.setValue(liczba/500);
									else
										s1.setValue(liczba);
									window.onresize = function () {
										s1.recalculate();
									};
								}

