// global variable
window.choice = window.choice || {};

choice.is_ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
choice.is_ie  = navigator.userAgent.toLowerCase().indexOf('msie')   != -1;

jQuery(document).ready(function(){

	if (window.location.protocol == 'https:'){
		jQuery('<script/>')
		   .attr('src', 'https://5004b3a0-3228-42e6-b717-82ed668db73a.statcamp.net/logging/js/tracker.js')
		   .appendTo('footer');
	} else {
		jQuery('<script/>')
		   .attr('src', 'http://5004b3a0-3228-42e6-b717-82ed668db73a.statcamp.net/logging/js/tracker.js')
		   .appendTo('footer');
	} 
	
  /* NEW CODE FROM VIGET 2010-12-20 */
	if ( choice.is_ie6 ){

    choice.$nearbySelects = choice.getNearbySelects();

		jQuery('.room-edit-dates .check-out-day, .room-edit-dates .check-out-day + img').live('click', function(){
	    choice.$nearbySelects.css('visibility', 'hidden');
	  });    
		
  }    
  /* END NEW CODE */

  if ( choice.is_ie ){
    choice.formatForErrors('.form-fields');
  }

		//Logo Drop Down Menu
	  jQuery('#logo-menu').click(function() {
	    jQuery(this).next().toggle();
	    jQuery(this).toggleClass('open');
	    return false;
	  });
	
	  //Language dropdown
	  jQuery('#cur-lang').click(function() {
	    jQuery(this).next().toggle();
	    jQuery(this).toggleClass('open');
	    return false;
	  });
	
		//Selects range for date picker
		// function customRange(input) { 
		//     return {
		//       minDate: (input.id == "check-out" ? jQuery("#check-in").datepicker("getDate") : null), 
		//       maxDate: (input.id == "check-in" ? jQuery("#check-out").datepicker("getDate") : null)
		//     }; 
		// }
	
	  //Flex room detail price slider
	  var priceSize_flex = jQuery('.room-slider-flex:first li').size();
	  if (jQuery('.table-top-flex').hasClass('mult-room')) {
	    var priceRemainder_flex = priceSize_flex-5;
	  } else {
	    var priceRemainder_flex = priceSize_flex-7;    
	  }
	  var firstSlider_flex = jQuery('.room-slider-flex:first');
	  jQuery('#room-back-flex').hide();
	  firstSlider_flex.attr('rel', priceSize_flex);  
	  jQuery('#room-forward-flex').click(function() {
	    jQuery('#room-back-flex').show();      
	    curRel_flex = firstSlider_flex.attr('rel')-1;
	    firstSlider_flex.attr('rel', curRel_flex);
	    jQuery('.room-slider-flex').animate({ left: '-=58px' }, 350);      
	    if(firstSlider_flex.attr('rel') == priceSize_flex-priceRemainder_flex) {
	      jQuery(this).hide();
	    }
	    return false;
	  });
	  jQuery('#room-back-flex').click(function() {
	    jQuery('#room-forward-flex').show();
	    curRel_flex = firstSlider_flex.attr('rel');
	    curRel_flex++;
	    firstSlider_flex.attr('rel', curRel_flex);
	    jQuery('.room-slider-flex').animate({ left: '+=58px' }, 350);      
	    if(firstSlider_flex.attr('rel') == priceSize_flex) {
	      jQuery(this).hide();
	    }    
	    return false;
	  });

	  //Prepaid room detail price slider
	  var priceSize_prepaid = jQuery('.room-slider-prepaid:first li').size();
	  if (jQuery('.table-top-prepaid').hasClass('mult-room')) {
	    var priceRemainder_prepaid = priceSize_prepaid-5;
	  } else {
	    var priceRemainder_prepaid = priceSize_prepaid-7;    
	  }
	  var firstSlider_prepaid = jQuery('.room-slider-prepaid:first');
	  jQuery('#room-back-prepaid').hide();
	  firstSlider_prepaid.attr('rel', priceSize_prepaid);  
	  jQuery('#room-forward-prepaid').click(function() {
	    jQuery('#room-back-prepaid').show();      
	    curRel_prepaid = firstSlider_prepaid.attr('rel')-1;
	    firstSlider_prepaid.attr('rel', curRel_prepaid);
	    jQuery('.room-slider-prepaid').animate({ left: '-=58px' }, 350);      
	    if(firstSlider_prepaid.attr('rel') == priceSize_prepaid-priceRemainder_prepaid) {
	      jQuery(this).hide();
	    }
	    return false;
	  });
	  jQuery('#room-back-prepaid').click(function() {
	    jQuery('#room-forward-prepaid').show();
	    curRel_prepaid = firstSlider_prepaid.attr('rel');
	    curRel_prepaid++;
	    firstSlider_prepaid.attr('rel', curRel_prepaid);
	    jQuery('.room-slider-prepaid').animate({ left: '+=58px' }, 350);      
	    if(firstSlider_prepaid.attr('rel') == priceSize_prepaid) {
	      jQuery(this).hide();
	    }    
	    return false;
	  });
	
	 	
		// Add utility first/last/alt classes to LIs.
		jQuery("ul li:first-child").addClass("first");
		jQuery("ul li:last-child").addClass("last");
		jQuery("ul li:nth-child(even)").addClass("alt");
		jQuery("table tr:nth-child(even)").addClass("alt");
		
		// Replace HRs with Divs in IE
	  	if (jQuery.browser.msie) {
			jQuery("hr").wrap("<div class='hr'></div>");
		}
		
		//Input focus and blur
		function switchText()
		{
			if (jQuery(this).val() == jQuery(this).attr('title')){
				jQuery(this).val('').removeClass('blur');
			}
			else if (jQuery.trim(jQuery(this).val()) == ''){
				jQuery(this).addClass('blur').val(jQuery(this).attr('title'));
				if (jQuery(this).attr('value') == 'dd/mm/yyyy'){
					jQuery(this).removeClass('blur');
				}
			}
		}
		jQuery('input[@type=text][title!=""]').each(function() {
			if (jQuery.trim(jQuery(this).val()) == '') jQuery(this).val(jQuery(this).attr('title'));
			if (jQuery(this).val() == jQuery(this).attr('title')) jQuery(this).addClass('blur');
		}).focus(switchText).blur(switchText);
		
		//Questions/Input toggle
		jQuery("a.showInput").click(function(){
			jQuery(this).toggleClass("hide").next().toggleClass("hide");		
			return false; 
		});
		jQuery("a.hideInput").click(function(){
			jQuery(this).parent().parent().toggleClass("hide").prev().toggleClass("hide");
			return false; 
		});
		

		// Tab_options and Tabs: Two DIVs that interact using Rels and IDs
//		jQuery(".tabs li:first-child a").each(function(){
//			jQuery(this).addClass("current");
//		});
//		jQuery(".tab-content").each(function(){
//			jQuery(this).children(":not(:first)").hide();	
//		});
		jQuery(".tabs a").click(function(){
			if (jQuery(this).hasClass("current") == false)
				{
					var thisTarget = jQuery(this).attr("href");
					jQuery(this).parents(".tabs").find('a.current').removeClass('current');
					jQuery(this).addClass('current');
                    if(jQuery(this).parents(".tabs").attr("class").match("^club")=="club"){
                        jQuery('.col-tab').toggle();
                    }
                    else{
                        jQuery('.resv-box').toggle();
                    }
			}
			if(jQuery.browser.msie && jQuery.browser.version == '6.0') {
    		jQuery(this).blur();
			}
			return false; 
		});
		
		jQuery(".tab-controller").click(function(){
					var thisTarget = jQuery(this).attr("href");
					if (jQuery(".tabs a[href='"+ thisTarget +"']").hasClass("current") == false) 
						{
							jQuery(".tabs a[href='"+ thisTarget +"']").parents(".tabs").find('a.current').removeClass('current');
							jQuery(".tabs a[href='"+ thisTarget +"']").addClass('current');
							
							jQuery(".tab-content").children(":visible").fadeOut(1, function() {
								jQuery(thisTarget).fadeIn("fast");
							});
						}
					return false;
		});
		
		attachShowMoreRooms();
		attachEditDates();
		attacheMapLink();
		//Ameneties tooltip
		tooltip();				
});

this.attachShowMoreRooms = function() {
	//show more room types
	jQuery('.view-room-types').click(function() {
		if (Prototype.Browser.IE) {
			jQuery(this).prev().find('.hiddenRooms').show();
		}else {
			jQuery(this).prev().find('.hiddenRooms').fadeIn();
		}
		jQuery(this).toggleClass('open');
		if (jQuery(this).hasClass('open')) {
            jQuery(this).html(msgHideMoreRooms);
		} else {
			jQuery(this).prev().find('.hiddenRooms').hide();
            jQuery(this).html(msgSeeMoreRooms);
		}
		return false; 
	});
}

this.attacheMapLink = function () {
	//sorting actions for hotel listing pages
	  var sortSlideSpeed = 500;
	  jQuery('#sorting p.right a').click(function() {
	    if (jQuery('#sorting p.right').children().hasClass('sort-open')) {
	      if (jQuery(this).hasClass('sort-open')) {
	        jQuery('#sort-map,#sort-names').slideUp(sortSlideSpeed%2);
	        jQuery('.sort-open').removeClass('sort-open');
	      } else {
	        jQuery('#sort-map,#sort-names').slideUp(300);
	        jQuery('.sort-open').removeClass('sort-open');
	        var callback = null;
		    if (jQuery(this).attr('rel') == 'sort-map' && !map) {
		   		callback = initMap;
		   	}
	        jQuery('#'+jQuery(this).attr('rel')).show().hide().css({margin: 0}).slideDown(sortSlideSpeed, callback);
	        jQuery(this).addClass('sort-open');
	      }
	    } else {
  	  var callback = null;
		    if (jQuery(this).attr('rel') == 'sort-map' && !map) {
		   		callback = initMap;
		   	}
		  jQuery('#'+jQuery(this).attr('rel')).show().hide().css({margin: 0}).slideDown(sortSlideSpeed, callback);
	      jQuery(this).addClass('sort-open');      
	    }
	    return false;
	  });
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 50;
		yOffset = -20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	jQuery("li.amenity").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append("<p class='tooltip'><span></span>"+ this.t +"</p>");
		jQuery(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		jQuery(".tooltip").remove();
    });	
	jQuery("li.amenity").mousemove(function(e){
		jQuery(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


CHICalendar=Class.create();
Object.extend(CHICalendar.prototype,{initialize:function(id, fid, forinput, frominput, isCheckout){
	this.id=id;
	this.fid=fid.slice(0, fid.length-4);
	this.forinput=forinput;
	this.frominput=frominput;
	this.isCheckout=isCheckout=='true'?true:false;
	this.date = null;
	this.firststart = true;
	this.isVisible = false;
	if($(this.forinput).value!=''){
		$(this.fid+'calendar1').component.selectDate($(this.forinput).value, true);
		$(this.fid+'calendar2').component.selectDate($(this.forinput).value, true);
		this.date = $(this.fid+'calendar1').component.getSelectedDate();
        if (this.date != null) {
            $(this.fid + 'calendar1').component.currentDate = this.date;
            $(this.fid+'calendar2').component.currentDate = this.date;
        }
        else{
            this.date = $(this.fid + 'calendar1').component.currentDate;
        }
        $(this.fid+'calendar1').component.nextMonth();
		$(this.fid+'calendar1').component.prevMonth();
		$(this.fid+'calendar2').component.nextMonth();
	}
	$(this.fid+'calendar1').component.params.isDayEnabled = isCalendarDayEnabled;
	$(this.fid+'calendar2').component.params.isDayEnabled = isCalendarDayEnabled;
	$(this.fid+'calendar1').component.params.frominput = frominput;
	$(this.fid+'calendar2').component.params.frominput = frominput;
	$(this.fid+'calendar1').component.render();
	$(this.fid+'calendar2').component.render();
	this.shouldSendEvent=true;
	this.checkDate();
	this.collapse = this.doCollapseCalendar.bindAsEventListener(this);
	this.show = this.show.bindAsEventListener(this);
	Event.observe($(this.forinput),'focus', this.show, false);
	Event.observe($(this.fid+'ico'),'click', this.show, false);
//	Event.observe($(this.forinput),'change', function(){alert(0)}, false);
	if(this.isCheckout){
		this.checkinDateSelected = this.checkinDateSelected.bindAsEventListener(this);
		Event.observe(document,'checkin:date:selected', this.checkinDateSelected, false);
	}
},

checkinDateSelected:function(e){
	if (!e) var e = window.event;
	var dt = new Date(e.memo.date);
	dt.setDate(dt.getDate()+1);
	if(dt>=this.date && eval(this.frominput+".forinput")==e.memo.forinput){
		$(this.fid+'calendar1').component.selectDate(dt, true);
	}else{
		$(this.fid+'calendar1').component.render();
	}
},

checkDate:function(){
	if(this.frominput && this.frominput!=null && this.frominput!=''){
		var fromdate = eval(this.frominput+".date");
		if(fromdate>=this.date){
			var dt = new Date(fromdate);
			dt.setDate(dt.getDate()+1);
			$(this.fid+'calendar1').component.selectDate(dt, true);
		}else{
			if(this.isCheckout){
				$(this.fid+'calendar1').component.render();
			}
		}
	}
},

move:function(){
	Richfaces.Calendar.clonePosition($(this.fid+'group'), $(this.forinput));
	$(this.fid+'group').style.top = parseInt($(this.fid+'group').style.top)+$(this.forinput).getDimensions().height+'px';
},

cumulativeOffset:function() {
	element = $(this.forinput);
    var valueT = 0, valueL = 0;
    do {
        valueT += element.scrollTop  || 0;
        valueL += element.scrollLeft || 0;
      element = element.parentNode;
    } while (element && element != document.body);
    return Element._returnOffset(valueL, valueT);
},

doCollapseCalendar:function(e){
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if(tg.id == this.forinput || tg.id == (this.fid+'ico')){
		return;
	}

  // we use a DOM method to get the element, because jQuery doesn't like the name:name:name ID treatment
  var $elem      = jQuery( document.getElementById( this.fid+'grid' ) ),
  
      // use jQuery's offset to get the correct offset
      offset     = $elem.offset(),
      leftEdge   = offset.left,
      rightEdge  = leftEdge + $elem.width(),
      topEdge    = offset.top,
      bottomEdge = topEdge + $elem.height(),
      
      // check the event position against our edges
      within     = ( ( Event.pointerX(e) > leftEdge   ) &&
                     ( Event.pointerX(e) < rightEdge  ) &&      
                     ( Event.pointerY(e) > topEdge    ) &&      
                     ( Event.pointerY(e) < bottomEdge ) );      
    
  if ( !within ){
    
   this.hide();
   
   // in IE6, re-show the hidden selects
   if ( choice.is_ie6 ){
     choice.$nearbySelects.css('visibility', 'visible');
   }
   
  }
  
},

hide:function(){
	$(this.fid+'group').style.display = 'none';
	this.isVisible = false;
	Event.stopObserving(window.document,'click', this.collapse, false);
	
},

show:function(){
	if(this.firststart){
		this.move();
//		$(this.fid+'calendar2').component.nextMonth();
	}
//	this.checkDate();
//	$(this.fid+'calendar1').component.showSelectedDate();
//	$(this.fid+'calendar2').component.showSelectedDate();
//	$(this.fid+'calendar2').component.nextMonth();
    var dateCal1 = $(this.fid+'calendar1').component.currentDate;
    if ((dateCal1.getMonth() != this.date.getMonth() && dateCal1.getFullYear() == this.date.getFullYear()) || dateCal1.getFullYear() != this.date.getFullYear()) {
        $(this.fid+'calendar1').component.currentDate = this.date;
        $(this.fid+'calendar1').component.prevMonth();
        $(this.fid+'calendar1').component.nextMonth();
        $(this.fid+'calendar2').component.currentDate = this.date;
        $(this.fid+'calendar2').component.nextMonth();
    }

	$(this.fid+'header1').innerHTML=$(this.fid+'calendar1').component.getCurrentMonth(true)+" "+$(this.fid+'calendar1').component.getCurrentYear();
	$(this.fid+'header2').innerHTML=$(this.fid+'calendar2').component.getCurrentMonth(true)+" "+$(this.fid+'calendar2').component.getCurrentYear();

    // CHSSEAM-516 fix. Grow function Overloaded
    Effect.Grow = function(C) {
        C = $(C);
        var B = Object.extend({direction:"center",moveTransition:Effect.Transitions.sinoidal,scaleTransition:Effect.Transitions.sinoidal,opacityTransition:Effect.Transitions.full}, arguments[1] || {});

        var A = {top:C.style.top,left:C.style.left,height:C.style.height,width:C.style.width,opacity:C.style.opacity};
        var G = C.getDimensions();
        var H,F;
        var E,D;
        switch (B.direction) {case"top-left":H = F = E = D = 0;
            break;
            case"top-right":H = G.width;
                F = D = 0;
                E = -G.width;
                break;
            case"bottom-left":H = E = 0;
                F = G.height;
                D = -G.height;
                break;
            case"bottom-right":H = G.width;
                F = G.height;
                E = -G.width;
                D = -G.height;
                break;
            case"center":H = G.width / 2;
                F = G.height / 2;
                E = -G.width / 2;
                D = -G.height / 2;
                break
        }
        return new Effect.Move(C, {x:H,y:F,duration:0.01,beforeSetup:function(I) {
            I.element.hide().makeClipping().makePositioned()
        },afterFinishInternal:function(I) {
            new Effect.Parallel([new Effect.Opacity(I.element, {sync:true,to:1,from:0,transition:B.opacityTransition}),new Effect.Move(I.element, {x:E,y:D,sync:true,transition:B.moveTransition}),new Effect.Scale(I.element, 100, {scaleMode:{originalHeight:G.height,originalWidth:G.width},sync:true,scaleFrom:window.opera ? 1 : 0,transition:B.scaleTransition,restoreAfterFinish:true})], Object.extend({beforeSetup:function(J) {
                J.effects[0].element.setStyle({height:"0px"}).show()
            },afterFinishInternal:function(J) {
                J.effects[0].element.undoClipping().undoPositioned().setStyle(A)
            }}, B))
        }})
    };
	Effect.Grow(this.fid+'group',{direction: 'top-left', duration: 0.8});

	if(this.firststart){
		this.firststart = false;
	}
	this.isVisible = true;
	Event.observe(window.document,'click', this.collapse, false);
},

toggle:function(){
	if(this.isVisible){
		this.hide();
	}else{
		this.show();
	}
},

selectdate:function(e){
	if (!e) var e = window.event;
	$(this.forinput).value=Richfaces.Calendar.formatDate(e.rich.date, e.rich.component.params.datePattern);
	this.hide();
	this.date = e.rich.date;
	if(e.rich.component.id==this.fid+'calendar1'){

		if(!this.isCheckout){
			document.fire("checkin:date:selected", { date: e.rich.date, forinput: this.forinput });
		}
		$(this.fid+'calendar2').component.selectDate($(this.forinput).value, false);
		$(this.fid+'calendar2').component.render();
		$(this.fid+'calendar2').component.nextMonth();
	}else{
		$(this.fid+'calendar1').component.selectDate($(this.forinput).value, false);
		$(this.fid+'calendar1').component.render();
	}
	this.hide();
	if ( choice.is_ie6 ){
    jQuery('table.listing-rooms select').css('visibility', 'visible');
  }
},

switchmonth:function(np){
	if(np){
		$(this.fid+'calendar1').component.nextMonth();
		$(this.fid+'calendar2').component.nextMonth();
	}else{
		$(this.fid+'calendar1').component.prevMonth();
		$(this.fid+'calendar2').component.prevMonth();
	}
	$(this.fid+'header1').innerHTML=$(this.fid+'calendar1').component.getCurrentMonth(true)+" "+$(this.fid+'calendar1').component.getCurrentYear();
	$(this.fid+'header2').innerHTML=$(this.fid+'calendar2').component.getCurrentMonth(true)+" "+$(this.fid+'calendar2').component.getCurrentYear();
}
});

function isCalendarDayEnabled(dataobj){
	var today = new Date();
	today.setDate(today.getDate()-1);
	if(this.frominput && this.frominput!=null && this.frominput!=''){
		var fromdate = eval(this.frominput+".date");
		if(fromdate>today){
			today=new Date(fromdate);
			today.setDate(today.getDate()+1);
		}
	}

	if(dataobj.date < today || dataobj.date.getTime() - new Date().getTime() > 31449600000){
		return false;
	}else{
		return true;
	}
}

function getCalendarStyle(dataobj){
	var today = new Date();
	today.setDate(today.getDate()-1);

	if(this.frominput && this.frominput!=null && this.frominput!=''){
		var fromdate = eval(this.frominput+".date");
		
		if(fromdate>today){
			today=new Date(fromdate);
			today.setDate(today.getDate()+1);
		}
	}

	if(dataobj.date < today || dataobj.date.getTime() - new Date().getTime() > 31449600000){
		return "rich-calendar-cell-disabled";
	}else{
		return "rich-calendar-cell";
	}
}

function onNoneThemeSelect(evt) {
	if (evt.checked == false && getCheckedThemesCount() == 0) {
		evt.checked = true;
	}
	var ch = $('themesList').getElementsByTagName('input');
	for (var i in ch) {
		if (ch[i].className != 'noneTheme') 
		ch[i].checked = false;
	}
}

function getCheckedThemesCount() {
	var ch = $('themesList').getElementsByTagName('input');
	var c=0;
	for (var i in ch) {
		if (ch[i].className != 'noneTheme' && ch[i].checked == true)
			c++;
	}	
	return c;
}

function onThemeSelect (evt) {
	if (evt.checked == true) {
		jQuery("input.noneTheme").attr('checked',false);
	}else if(getCheckedThemesCount() == 0) {
		jQuery("input.noneTheme").attr('checked',true);
	}
}

this.attachEditDates = function() {
	jQuery(".edit-dates").click(function(){
		if(jQuery(this).parents(".room-dates").parent().hasClass("selected-room-dates")) {
			jQuery(this).parents(".room-dates").parent().removeClass("selected-room-dates").addClass("selected-cancel-dates");
		}return false;
	});
	jQuery(".cancel-dates").click(function(){
		if(jQuery(this).parents(".room-edit-dates").parent().hasClass("selected-cancel-dates")) {
			jQuery(this).parents(".room-edit-dates").parent().removeClass("selected-cancel-dates").addClass("selected-room-dates");
		}return false;
	});
	
}

/*
   Fuction for search menu. Search button will be clicked by pressing enter only if
    suggestion box is hidden
 */
function pressEnter(event) {
    var suggestion = document.getElementById('search_form_room:suggestionBoxId');
    if (event.keyCode == 13) {
        var hidden = false;

        if (suggestion == null) {
            hidden = true;
        } else {
            if (navigator.userAgent.indexOf ("MSIE") >= 0) {  // internet explorer case
                hidden = suggestion.getAttribute('style').getAttribute('display') == 'none';
            }
            else {
                hidden = suggestion.getAttribute('style').indexOf('display: none') != -1;
            }
        }

        if (hidden) {
            document.getElementById('search_form_room:searchButton').click();
        }
    }
}

// If a from has errors, set the z-index on all the LIs to make sure errors overlap correctly
choice.formatForErrors = function( selector ){

  jQuery( selector ).each(function(){
    var $this = jQuery( this ),
        has_errors = $this.find('.error-cont').length > 0;        
    if ( has_errors ) {
      $this.children().each( choice.formatForErrors.setZIndexOnLis );
    }  
  });
  
}

choice.formatForErrors.setZIndexOnLis = function( i ){
  jQuery( this ).css({
    'position' : 'relative',
    'zIndex' : 10000 - i
  });  
}

/* NEW CODE FROM VIGET 2010-12-20 */

// grab selects that collide with the calendar
choice.getNearbySelects = function(){
  var $table = jQuery('table.listing-rooms'),
    $selects = jQuery([]);
  if ( $table.length >= 1 ) {
    table_y_position = $table.offset().top;
    jQuery('table.listing-rooms select').each(function(){
      var $this = jQuery( this );
      if ( $this.offset().top < table_y_position + 160 ) {
        $selects = $selects.add( $this );
      }
    });
  }
  return $selects;
}

/* END NEW CODE */

