// JavaScript Document (jQuery)

function configureAjaxContent() {
  $('a.photos-link').click(function() {
	window.open(this.href,'_blank','height=400,width=600,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	return false;
  });
  $('div[id^=offer-]').click(function() {
	$(this).siblings().css('background','#d5e2e3');
	$(this).css('background','#a8c0e6');
	$(this).children('input').attr('checked','checked');
	var offer_details = $(this).attr('id').split('-');  // offer_details[1] is the number ('one', 'two', or 'three'); offer_details[2] is the prop_id
	$(this).parent().next().load(offer_details[2],{'fx':'get_offer','offer_num':offer_details[1]});
  });
}

$(function() {

  $('select#country').change(function() {
	if (this.value != 0) {
		var dataString = 'fx=get_states';
		$.ajax({
		  type: 'POST',
		  url: this.value,
		  data: dataString,
		  success: function(content) {
			if (content.length > 1) {
				$('select#state').removeAttr('disabled').html(content);
			} else {
				$('select#state').attr('disabled','disabled').html('<option value="0">State</option>');
			}
		  }
		});
		var dataString = 'fx=get_cities';
		$.ajax({
		  type: 'POST',
		  url: this.value,
		  data: dataString,
		  success: function(content) {
			if ($('select#state option').size() <= 1) {
				$('select#city').removeAttr('disabled').html(content);
			} else {
				$('select#city').attr('disabled','disabled').html('<option value="0">City</option>');
			}
		  }
		});
	} else {
		$('select#state').attr('disabled','disabled').html('<option value="0">State</option>');
		$('select#city').attr('disabled','disabled').html('<option value="0">City</option>');
	}
    return false;
  });
  
  $('select#state').change(function() {
	var url = ($('select#country').val() != 0) ? $('select#country').val() + '/' : '';							   
	if (this.value != 0) {
		var dataString = 'fx=get_cities';
		$.ajax({
		  type: 'POST',
		  url: url + this.value,
		  data: dataString,
		  success: function(content) {
			$('select#city').removeAttr('disabled').html(content);
		  }
		});
	} else {
		$('select#city').attr('disabled','disabled').html('<option value="0">Select a City</option>');
	}
    return false;
  });
  
  $('a#find-hotel').click(function() {
	var city = $('select#city').val();
	if (city != 0) {
		var url = ($('select#country').val() != 0) ? $('select#country').val() + '/' : '';
		url = ($('select#state').val() != 0) ? url + $('select#state').val() + '/' : url;
		var dataString = 'fx=get_content';
		$.ajax({
		  type: 'POST',
		  url: url + city,
		  data: dataString,
		  success: function(content) {
			$('#search-results').html(content);
		  }
		});
	} else {
		alert('Please select a city.');
	}
    return false;
  });
  
});