function cleanRadioOnSelect(table, index, fn) {
		jQuery(table).find('td :radio').each(function () {
			 if (this.value != index) {
			      this.checked = false;
			 }
		});
	    fn(index);
};

function checkUncheckAll(table, element) {
    jQuery(table).find('td :checkbox').each(function () {
    	this.checked = element.checked;
    });

    return true;
};

function uncheckAll(table) {
	jQuery(table).find('td :checkbox').each(function () {
		if (this.checked) {
			this.checked = false;
		}
	});

	return true;
};

function containsFilter(subString, value) {
    if (subString.length >= 1) {
        if (value.indexOf(subString) != -1)
            return true;
    } else
        return false;
};

(function($, rf){
	if (rf.ui.Select != undefined) {
		rf.ui.Select.prototype.__getClientItemFromCache_1 = function(inputLabel) {
            var value;
            var label;
            if (this.enableManualInput) {
                var items = this.cache.getItems(inputLabel, this.filterFunction);
                if (items && items.length > 0) {
                    var first = $(items[0]);
                    $.each(this.clientSelectItems, function() {
                        if (this.label == inputLabel) {
                            label = this.label;
                            value = this.value;
                            return false;
                        }
                    });
                } else {
                    this.container.removeClass("rf-sel-fld-err");

                    var prevValue = this.selValueInput.val();
                    if (prevValue && prevValue != "") {
                        $.each(this.clientSelectItems, function() {
                            if (this.value == prevValue) {
                                label = this.label;
                                value = this.value;
                                return false;
                            }
                        });
                    }
                }
            }

            if (label && value) {
                return {'label': label,'value': value};
            }
        };
	}
})(jQuery, RichFaces);

function blockBodyScroll(){
	$('body').css('overflow', 'hidden');
}

function allowBodyScroll(){
	$('body').removeAttr('style');
}
function preparePopups(maxUrl, restUrl){
	$('.rf-pp-cntr').each(function () {
	    var popup = $(this);
	    var innerPop = $(this).find('.rf-pp-shdw').get(0);
	    innerPop.style.display = 'none';
	    var contPop = $(this).find('.rf-pp-cnt-scrlr').get(0);
	    var headerHeight = $(this).find('.rf-pp-hdr').height() + 5;
	    $(this).find('.rf-pp-hdr-cntrls').each(function () {

	        if ($(this).children().size() == 1) {
	            var ctrlDiv = $(this).get(0);
	            var mode = 'min';
	            var originalData = '';
	            var imgCtnr = document.createElement('DIV');
	            imgCtnr.style.cssFloat = 'left';
	            imgCtnr.style.styleFloat = 'left';
	            imgCtnr.style.marginRight = '5px';
	            var img = document.createElement('IMG');
	            imgCtnr.appendChild(img);
	            img.style.cursor = 'pointer';
	            img.style.marginTop = '2px';
	            img.src = maxUrl;
	            img.onclick = function () {

	                if (mode == 'min') {
	                    originalData = $(popup).width() + '#' + $(popup).height() + '#' + $(popup).position().top + '#' + $(popup).position().left;
	                    $(popup).offset({
	                        top: 0 + $(window).scrollTop(),
	                        left: 0 + $(window).scrollLeft()
	                    });
	                    $(contPop).offset({
	                        top: 0 + $(window).scrollTop() + headerHeight,
	                        left: 0 + $(window).scrollLeft()
	                    });
	                    if ($(popup).height() < $(window).height()) {
	                        $(popup).height($(window).height());
	                        $(contPop).height($(window).height() - headerHeight);
	                    }
	                    if ($(popup).width() < $(window).width()) {
	                        $(popup).width($(window).width());
	                        $(contPop).width($(window).width());
	                    }
	                    mode = 'max';
	                    img.src = restUrl;
	                } else {
	                    var origDataArray = originalData.split("#");
	                    $(popup).width(origDataArray[0]);
	                    $(popup).height(origDataArray[1]);
	                    $(popup).offset({
	                        top: origDataArray[2],
	                        left: origDataArray[3]
	                    });
	                    $(contPop).width(origDataArray[0]);
	                    $(contPop).height(origDataArray[1] - headerHeight);
	                    $(contPop).offset({
	                        left: origDataArray[3]
	                    });
	                    mode = 'min';
	                    img.src = maxUrl;
	                }
	            };
	            if(ctrlDiv.firstChild){
	            	ctrlDiv.insertBefore(imgCtnr, ctrlDiv.firstChild);
	            } else {
	            	ctrlDiv.appendChild(imgCtnr);
	            }
	        }
	    });
	});
}
function showTreeSel(){
  try{
    $('.ui-layout-resizer.ui-layout-resizer-east.ui-layout-resizer-open.ui-layout-resizer-east-open').get(0).style.zIndex = 1;
    $('.pane.ui-layout-center.ui-layout-pane.ui-layout-pane-center').get(0).style.zIndex = 2;
    $('.rf-pp-hdr').each(function () {
        $(this).get(0).style.width = '99.4%';
      });
    $('.rf-ddm-lbl.rf-ddm-unsel').each(function () {
      $(this).get(0).style.zIndex = 1;
    });
  } catch(err) {
  }
}
function hideTreeSel(){
  try{
    $('.ui-layout-resizer.ui-layout-resizer-east.ui-layout-resizer-open.ui-layout-resizer-east-open').get(0).style.zIndex = 2;
    $('.pane.ui-layout-center.ui-layout-pane.ui-layout-pane-center').get(0).style.zIndex = 0;
    $('.rf-ddm-lbl.rf-ddm-unsel').each(function () {
      $(this).get(0).style.zIndex = 10;
    });
  } catch(err) {
  }
}