﻿function refSearchAll(){
    var btnReferentieZoeken = document.getElementById("btnReferentieZoeken");
    var modal_reference = document.getElementById("modal_reference");
    
    btnReferentieZoeken.onmousedown = function() 
    {
        if ((txtSearch.value != 'Buscar por referência') && (txtSearch.value.length > 1))
        {
            Ajax_Search.SearchAllReferences(txtSearch.value, btnReferentieZoeken.callBack);
        }
    }
    btnReferentieZoeken.callBack = function(result) 
    {
        try {
            if (modal_reference.hasChildNodes()) {
                while (modal_reference.childNodes.length >= 1) 
                {modal_reference.removeChild(modal_reference.firstChild);}
            }
            
            var div = document.createElement("div");
            div.setAttribute("height", "20px");
            div.innerHTML = "&nbsp;";
            modal_reference.appendChild(div);
            
            if (result.length == 0)
            {
                return false;
            }
            if (result.length == 1)
            {
                window.location = "detalhe_imovel.aspx?pandid=" + result[0].Key;
                return false;
            }
               
            for (var i = 0; result.length > i; i++) 
            {
                var child = document.createElement("div");
                child.style.paddingLeft= "10px";
                var a = document.createElement("a");
                a.innerHTML = result[i].Value;
                
                if (navigator.userAgent.indexOf('MSIE 7') != -1 || navigator.userAgent.indexOf('MSIE 6') != -1)
                {   
                a.setAttribute('className', 'hypReference');
                }
                else
                {
                a.setAttribute("class", "hypReference");
                }
                a.href = "detalhe_imovel.aspx?pandid=" + result[i].Key;
                child.appendChild(a);
                modal_reference.appendChild(child);
            }
            //modal_reference.style.display = "block";
            searchBox.style.display = "none";
            $jq('#modal_reference').dialog('open');
        } 
        catch (ex) 
        { }
    }
}
addLoadEvent(refSearchAll);


var $jq = jQuery.noConflict();
$jq(document).ready(function() 
{
        $jq("#modal_reference").dialog
        ({
            modal: true,
            autoOpen: false,
            resizable: false,
            width: 620,
            minHeight: 300,
            maxHeight: 500,
            open: function(type, data) {
                $jq(this).parents(".ui-dialog").wrap(
                  '<div class="modal_class"></div>'
                );
                $jq("div.scrollable").scrollable({ 
                    vertical:true,
                    size: 10});  
            },
            close: function(type, data) {
                var wrapper = $jq(this).parents(".modal_class");
                wrapper.replaceWith(wrapper.children());
            },
            buttons:
            {
                "Cancelar": function() {
                    $jq(this).dialog("close");
                }
            }
        });
});