var orig_service  = "";
var orig_pax      = "";
var orig_pick_up  = "";
var orig_drop_off = "";

// Generic form functions / events / behaviors
$(document).ready(function() {
	update_fields();
	
	$('#search_ride_date').attr('autocomplete','off');
		
	$('a.tip.clicktip').click(function() {
      $(this).removeClass('clicktip');
      $(this).blur( function() { $(this).addClass('clicktip')});
      return false;
    });

});

// This makes this global and callable from other functions
var update_fields = function(){
  
	// Look for any text fields that should maintain some default value
	$(".text_default").each(function(){
		// This is a weird check because if we use override, then we could have an empty 
		// field (in the case of an error on a reload)..
		if($(this).val() == ''){
			$(this).addClass('text-input-help');
			$(this).val($(this).attr('refid'));
		} else if ($(this).val() == $(this).attr('refid')) {
			$(this).addClass('text-input-help');
		} else {
			$(this).removeClass('text-input-help');
		}
	});
	$(".text_default").blur(function(){
		if($(this).val() == ''){
			$(this).addClass('text-input-help');
			$(this).val($(this).attr('refid'));
		}
		else $(this).removeClass('text-input-help');
	});
	$(".text_default").bind('focus', function(){
		if($(this).val() == $(this).attr('refid')){
			$(this).removeClass('text-input-help');
			$(this).val('');
		}
		return true;
	});
	// Hook up the text_default form button to clear the text_default fields so the vals don't get submitted
	var el=$(".text_default:first").parents('form');
	
	$(el).bind('submit', function(){ clear_all_text_default_fields() });
}

function reverseRes() {

  if (orig_service == 99) {
    $('#service_type').val(100);
    switchRes();
  }
  else if (orig_service == 100) {
    $('#service_type').val(99);
    switchRes();
  }
  else if (orig_service == 101) {
    $('#service_type').val(102);
    switchRes();
  }
  else if (orig_service == 102) {
    $('#service_type').val(101);
    switchRes();
  }
  else if (orig_service == 131072) {
    $('#service_type').val(131072);
    switchRes();
  }
  else {
    repeatRes();
  }
}

function switchRes() {
  $('#service_type').change();

  show_hide_drop_offs();
  show_hide_drop_location();
  change_labels();

  $('#search_pax').val(orig_pax);
  $('#search_pickup_place').val(orig_drop_off);
  $('#search_drop_off_place').val(orig_pick_up);
  clearDateTime();

}

function repeatRes(){
  $('#service_type').val(orig_service);
	$('#service_type').change();

  show_hide_drop_offs();
	show_hide_drop_location();
	change_labels();

  $('#search_pax').val(orig_pax);
  $('#search_pickup_place').val(orig_pick_up);
  $('#search_drop_off_place').val(orig_drop_off);
  clearDateTime();
}

function newRes() {
  $('#service_type').val("");
  $('#service_type').change();

  show_hide_drop_offs();
	show_hide_drop_location();
	change_labels();
  
  $('#search_pickup_place').val("");
  $('#search_drop_off_place').val("");
  $('#search_pax').val(1);
  clearDateTime();
}

function clearDateTime(){
  $('#time_pickup').val('');
  $('#time_dropoff').val('');
}


	
