function BuildResults() {
    jQuery('table#users tbody input').button();

    jQuery('table#users tbody tr a').click(function () {
        if (!jQuery(this).hasClass('realLink'))
            return false;
    });

    jQuery('table#users tbody tr input').click(function () {
        return false;
    });

    jQuery('.ui-rsf-nav button').click(function () {
        document.location = jQuery(this).attr('href');
        return false;
    });

    jQuery('.ui-rsf-nav').each(function () {
        jQuery(this).children('button:first').button({ icons: { primary: 'ui-icon-circle-triangle-w'} });
        jQuery(this).children('button:last').button({ icons: { secondary: 'ui-icon-circle-triangle-e'} });
    });


    jQuery('table#users>tbody>tr').mouseover(function () {
        jQuery(this).children('td').css({
            'background-color': rgb2hex(jQuery(this).parent('tbody').parent('table').css('background-color'))
        });
    });
    jQuery('table#users>tbody>tr').mouseout(function() {
        jQuery(this).children('td').css({
            'background-color': ''
        });
        //		jQuery('#ui-rsf-searchResultTip').remove();
    });

    jQuery('table#users tbody input[type="button"]').click(function () {
        if (jQuery(this).attr('href') && jQuery(this).attr('href').indexOf("Book.aspx") == -1) {
            /*
            jQuery('body').addClass('nooverflow');
            jQuery('body').append('<iframe frameborder="no" class="ui-rsf-newForm" src="' + jQuery(this).attr('href') + '"></iframe>');
            jQuery('.ui-rsf-newForm').css('top', jQuery(document).scrollTop());
            */
            if (jQuery('#ui-rsf-dialog').length) {
                jQuery('#ui-rsf-dialog iframe').removeAttr('src');
                jQuery('#ui-rsf-dialog').dialog('destroy');
            } else
                jQuery('body').append('<div id="ui-rsf-dialog" style="overflow:hidden;"><iframe SCROLLING="NO" style="overflow:hidden;border:none" src="about:blank" frameborder="no"></iframe></div>');

            jQuery('#ui-rsf-dialog iframe').load(function () {
                jQuery("#ui-formCloseButton").remove();
                jQuery(this).unbind('load');
                jQuery(this).next().remove();
            });

            jQuery('#ui-rsf-dialog').dialog({
                width: 900,
                height: 1100,
                modal: true,
                closeOnEscape: true,
                draggable: false,
                resizable: false,
                title: 'Заказ тура'
            });
            jQuery('#ui-rsf-dialog iframe').attr('src', jQuery(this).attr('href') + "&NOCLOSE=1");
            jQuery('#ui-rsf-dialog').css('overflow','hidden');
        } else {
            window.open(jQuery(this).attr('href'));
        }
    });
    jQuery('input[type="button"]').removeClass('hid');
    jQuery('#users-contain').css('visibility', 'visible');
};



function closeInnerIframe(){
	if (jQuery('#ui-rsf-dialog').length > 0) {
	    jQuery('#ui-rsf-dialog').last().remove();
	}
	else if (jQuery('.ui-rsf-newForm').length > 0) {
	    jQuery('.ui-rsf-newForm').remove();
	    jQuery('body').removeClass('nooverflow');
	}
}

function rgb2hex(rgb) {
    var rgb_ = rgb;
    var hd = 10;
    rgb = rgb_.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    if (rgb == null) {
        rgb = rgb_.match(/^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/);
        hd = 16;
    }
    var tt = 1;
    for (var i = 1; i <= 3; i++) {
        if ((rgb[i] = parseInt(rgb[i], hd)) + 15 >= 255)
            tt = -1;
    }
    for (i = 1; i <= 3; i++)
        rgb[i] = Math.min(255, rgb[i] + 30 * tt);
    return "#" +
  ("0" + Number(rgb[1]).toString(16)).slice(-2) +
  ("0" + Number(rgb[2]).toString(16)).slice(-2) +
  ("0" + Number(rgb[3]).toString(16)).slice(-2);
}

function GetNextPage(URL) {
    $.blockUI({ message: RSPreloadBlock, centerY: false, centerX: true, css: { top: '100px', border: 'none', backgroundColor: 'transparent', left: '30%' }, overlayCSS: { backgroundColor: '#eeeeee', opacity: '0.6'} });

    jQuery("#resultList").load(URL, function () {
        BuildResults();
        $.unblockUI();
        window.scroll(0, 1120);
    });
}

ScriptLoaded = "js_results_prof.js";
