window.onload = function() {
    //select the first button
    var button1 = $('openrefinesearch');
    var button2 = $('closerefinesearch');
    var button3 = $('btnRHSRefine');
    //select the first content element
    var content1 = $('refinesearchbox');

    if (button1) {
        //The height transition we attach to 'contentElement1'
        var b1Toggle = new Fx.Tween('refinesearchbox', { duration: 1000 });


        //add an onclick event listener to button1
        button1.addEvent('click', function() {
            //toggle height transition (hide-show)
            if (content1.getStyle('height').toInt() > 0) {
                //hide
                b1Toggle.start('height',0);
            } else {
                //show
                b1Toggle.start('height',c1Height);
            }
            return false;
        });

        if (button3) {
            //add an onclick event listener to button3
            button3.addEvent('click', function() {
                //toggle height transition (hide-show)
                if (content1.getStyle('height').toInt() > 0) {
                    //hide
                    b1Toggle.start('height',0);
                } else {
                    //show
                b1Toggle.start('height', c1Height);
                }
                return false;
            });
        }

        button2.addEvent('click', function() {
            //toggle height transition (hide-show)
            if (content1.getStyle('height').toInt() > 0) {
                //hide
                b1Toggle.start('height', 0);
            } else {
                //show
                b1Toggle.start('height', c1Height);
            }
            return false;
        });



        //set css display:block for the contentElements
        content1.setStyle('display', 'block');

        //get the scrollSize of the contentElements
        var c1Height = content1.getScrollSize().y;
    }
};

function goToPropertyDetails(propertyid,el) {
    document.location.href='/property-details/'+propertyid+'?search=true';
}

function searchnearbylocation(location)
{       
    document.location.href=replaceQueryString(document.location.href,'location',location);
}

function replaceQueryString(a,k,v) {
   var re = new RegExp("([?|&])" + k + "=.*?(&|$)","i");   
   if (a.match(re))
       return a.replace(re,'$1' + k + "=" + v + '$2');
   else
       return a + '&' + k + "=" + v;
}