SearchWidget =
{
	renderForm: function(formName) {
		this.destinationChanged($(".destination").val());
		this.productTypeChanged($(".productType").val());	
	
		var totalChildren = 0;
		var formid = $('form[name=' + formName + ']').attr('id');
		var rooms = new Number($("#" + formid + ' .numRooms').val());
		
		// Hide all visible child age room info
		$('#' + formid + ' .childAge:visible, #' + formid + ' .childAgeBorder:visible, #' + formid + ' .childrenRoom:visible').each(function(){
			$(this).hide();
		});
		
		$('#' + formid).find('.room:lt(' + rooms + ')').each(function(i){
			$(this).show();
			$(this).find('.roomNum').text(i+1);
			$(this).find('.numChildren').each(function(){
				var numChildren = new Number($(this).val());
				totalChildren += numChildren;
				$('#' + formid + ' .childrenRoom:eq(' + i + ')').each(function(j){
					$(this)[numChildren > 0 ? "show" : "hide"]();
					$(this).find('.childAge:lt(' + (numChildren) + ')').each(function(k){
						$(this).show();
					});
					$(this).find('.childAgeBorder:lt(' + (numChildren) + ')').each(function(k){
						$(this).show();
					});				
				});
				$('#' + formid + ' .childAgesSpacer:eq(' + i + ')').each(function(l){
					$(this)[numChildren > 0 ? "hide" : "show"]();
				});
			});
		});
		$('#' + formid + ' .room:gt(' + (rooms-1) + ')').each(function(){
			$(this).hide();
		});
	
		
		$('#' + formid + ' .childListLabel').each(function(){
			$(this)[totalChildren > 0 ? "show" : "hide"]();
		});
		$('.occu').show();
		$('.childrenList').show();
	},
	
	productTypeChanged: function(prodType){
		searchParamsWrapId = ".hotelSearchParams";
		// Having the product type code hard coded here is bad...
		// possibly use this JS as a template and change the HOTEL 
		// type to be an interpolated variable.
		if (prodType == "HOTEL")
		{
			$(searchParamsWrapId).show();
		}
		else
		{
			$(searchParamsWrapId).hide();
		}
	},
	
	destinationChanged: function(selectedDestination){
			if (typeof selectedDestination != 'undefined' && typeof destProductTypes != 'undefined' && typeof allProductTypes != 'undefined')
			{
				var selectedPT = $(".productType").val();
				ptOpts = destProductTypes[selectedDestination];
				var options = "";
				if (typeof ptOpts != 'undefined')
				{
					$("#productTypeWrap").show();
					for(i = 0; i < ptOpts.length; i++)
					{
					    options += '<option value="' + ptOpts[i].code + '"';
					    if (ptOpts[i].code == selectedPT)
						    options += ' selected ';
					    options += '>' + allProductTypes[ptOpts[i].code] + '</option>';
					}
					$("select.productType").html(options);
				}
				else
					$("#productTypeWrap").hide();
			}
			else
				$("#productTypeWrap").show();
		}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}