var searchFormUrl = ''; // global var place holder

$(document).ready(function(){
  search_div_functions();
  // auto-complete will only be defined in home_page.html.erb!
  if(window.autocomplete_init) {
      autocomplete_init();
    }
})

search_div_functions = function(){



$(function() {
  if (typeof $.fn.calendricalTimeRange == 'function') {
    $('#time_pickup, #time_dropoff').calendricalTimeRange({defaultTime:  {hour: 12, minute: 0}, timeInterval: 15});
  }

  $('#new_search #user_is_subscribed').click(function() {
    $('#new_search #user_is_subscribed').attr('checked', $(this).is(':checked'));
  });

  $('#contentMain #oneCol.home #search_submit').addClass('enabled');
  
  // save the form url for later in case we need to revert
  searchFormUrl = $('form#new_search,form.new_search').attr('action');
  
  // Initialize the date picker
  // Date.firstDayOfWeek = 7; // Sets sunday as first day
  $('#search_ride_date').datepicker({minDate:'0d',maxDate:'+1y',numberOfMonths:2});
  
  // Wire up more / less search results links
  $('#more_search_options_link').click(function(){
    // shows the more options div and turns on virt attr form_div
    // uncheck everything on the extended menu
    $('#search_more_options').toggle(true);
    $('#search_less_options').toggle(false);
    
    // $(":checkbox[id *= 'types_']").attr("checked", false);
    // for all checked boxes on short menu, check those boxes on the other menu
    $(":checkbox[id *= 'type_'][checked]").each(function(){
      var values = $(this).attr('value').split(',');
      jQuery.each(values , function(){
        $(":checkbox[id *= 'types_'][value = "+this+"]").attr("checked", true);
      });
    });
    
    $('#search_form_div').val('selected');
  });
  
  $('#less_search_options_link').click(function(){
    // shows the less options div and clears the virt attr form_div
    $('#search_less_options').toggle(true);
    $('#search_more_options').toggle(false);
    
    // for all checked boxes on short menu, check those boxes on the other menu
    $(":checkbox[id *= 'type_']").attr("checked", false);
    $(":checkbox[id *= 'types_'][checked]").each(function(){
      $(":checkbox[id *= 'type_'][value *= "+$(this).attr('value')+"]").attr("checked", true);
    });
    
    $('#search_form_div').val('');
  });
  
  // Disable drop off times and locations for air/cruiseports, enable only for hourly
  $('#service_type').change(function(){
    var service = parseInt($(this).val());
    var vehicle_list = "1,2,3,4,5,6,7";
    var trollyWorthy = [64, 16384, 4, 8192, 16, 32, 512, 2048];
    var classicWorthy = [4,8];
    var bizWorthy = [99,100,4096,131072];
    if( jQuery.inArray(service, trollyWorthy ) >= 0 ) vehicle_list += ",9,10";
    if( jQuery.inArray(service, classicWorthy ) >= 0 ) vehicle_list += ",8";    
    $('#search_vehicle_types').val(vehicle_list);    
    
    //show 'this is for business' checkbox if the right service is selected
    if( $('#isbiz').length == 1 && jQuery.inArray(service, bizWorthy ) >= 0 ) {
      $('#isbiz').show();
    } else {
      $('#isbiz').hide();
      $('#is_business').attr('checked',false);
      $('form#new_search').attr('action',searchFormUrl);
    }    
    show_hide_drop_offs(); show_hide_drop_location(); change_labels();
  });
  
  $('#search_pickup_time_minute').change(function(){
    changeSplitTimeSlots();
  });
  
  show_hide_drop_offs();
  show_hide_drop_location();
  change_labels();
  
  // Search submit needs to clear off various checkboxes on the hidden vehicles div
  $('#search_submit').click( function(){

		// If search form div field has a value, then clear the less options form
		if($('#search_form_div').val() == "selected"){
			$('#search_less_options :checkbox').each(function(){
				$(this).removeAttr('checked');
				$(this).checked=undefined;
			});
		}else{
			// Otherwise clear the more options form
			$('#search_more_options :checkbox').each(function(){
				$(this).removeAttr('checked');
				$(this).checked=undefined;
			});
		}
	});
	
	var skipValidation = false;
	$('#new_search,form.new_search,form.edit_search').submit(function(){
		if(ucsv==true || ucsv > 0 ) {
      if( skipValidation ) return true;

			formvalid = validate_form();
			if( !formvalid ) return false;
		  
			if (formvalid==true) {
			  shield('search_submit', 'cancelsearch', 'Searching    ', 'Searching ');
			}
		  
			// adding a slight delay before the actual submit to give time for the spinner to fully load up and start moving
			skipValidation = true;
			setTimeout("$('#new_search,form.new_search,form.edit_search').submit()",500);
		  
			return false;
		}
		else {
			submit_search();
		}
	});
	
	$('#search_user_tz').val((new Date()).getTimezoneOffset()/60);   // submit user's time zone
	
	var checked = false;
	// clicking on car image is same as clicking on checkbox
	$('.cartype').click(function(){
		if (checked) {checked=false; return true;}
		cartype = $(this).attr('cartype');
		chkd = $('#search_vehicle_type_'+cartype).attr('checked');
		if (chkd) $('#search_vehicle_type_'+cartype).removeAttr('checked').checked=undefined;
		else $('#search_vehicle_type_'+cartype).attr('checked', 'checked');
		return false;
	});
	// this needed to avoid interference between the checkbox click and div click
	$(':checkbox[cartype]').click(function() { checked = true; });
	$('#search_pickup_time').change(function() {changeTimeSlot();});
	$('#search_pickup_time_hour').change(function() {changeSplitTimeSlots();});
	$('#service_type').change(function(){
		if( $('#service_type').val() == '16384' ) {
			changeSplitTimeSlots();
			} 
	});
	
	$("input, select").blur(function(){$(this).removeClass('highlighted');});
	$("#contentMain input[type!=submit], #contentMain select").bind('focus', function(){$(this).addClass('highlighted');});	
	$('#service_type').focus();
	$('select').bind('change', function(){ 
	  $(this).removeClass('highlighted'); 
	  $(":input[type!=hidden]:eq("+ ($(":input[type!=hidden]").index(this)+1) +")").focus();
	});
	$('#search_ride_date').bind('change', function(){ 
	  if($(this).val().length==10){
	    $(this).removeClass('highlighted'); 
  	  $(":input[type!=hidden]:eq("+ ($(":input[type!=hidden]").index(this)+1) +")").focus();
  	}
	});
});
  $('#search_pickup_place').focus(function(){
    if ($('#search_pickup_place').val()=='Pickup location?') {
      $('#search_pickup_place').attr('value','');
    } 
  });
  $('#search_drop_off_place').focus(function(){
    if ($('#search_drop_off_place').val()=='Drop-off location?') {
      $('#search_drop_off_place').attr('value',''); 
    }
  });
}

function show_hide_drop_offs() {
  var val=$('#service_type :selected').val();
  if(val == 99 || val == 100 || val == 101 || val == 102 || val == '131072' || val==''){
    $('#search_between_time_div').hide();
    $('#search_dropoff_time_div').hide();
  }else{
    $('#search_between_time_div').show();
    $('#search_dropoff_time_div').show();
  }
}

function show_hide_drop_location() {
  var val=$('#service_type :selected').val();
  if(val == 99 || val == 100 || val == 101 || val == 102 || val == 131072){
    $('#search_pickup_location_div').removeClass('wide');
    $('#search_dropoff_location_div').show();
  }else{  
    $('#search_dropoff_location_div').hide();
    $('#search_pickup_location_div').addClass('wide');
  }
}

function change_labels(only_labels) {
  // Any of the direct clearing of the value attributed on the drop off and pickup places 
  // will erase anything the user has added.
  var val=$('#service_type :selected').val();
  var pval=$('#search_pickup_place').val(); //attr('refid');
  var dval=$('#search_drop_off_place').val(); //attr('refid');
  var csz='Address, City, or Zip';
  var anc='Airport Name, Code or City';
  var cnc='Cruiseport Name or City';
  
  //use different default values on the home page
  var isHome = $('#search_home').length > 0 ? true : false; 

  // re-init the autocomplete to be sure its there if needed
  // auto-complete will only be defined in home_page.html.erb!
  if(window.autocomplete_init) {
      autocomplete_init();
    }

  // All the undefined checks allow us to segment off the onload vs a event call. When onload
  // happens (form submit or page load), we only want to change the text labels - this will 
  // allow and Airport To to have the labels updated correctly. Direct calls do not pass in 
  // the only_labels flag and therefore, blow away the values in the text field(s) directly.
  // Note: Don't forget that this works in conjunction with forms:update_fields
  if(val == 100) {
    // to airport
    $('#pickup_location_label').text('Pick-up address');
    $('#drop_off_location_label').text('Airport');
    if(only_labels == undefined){     
      if(isHome) {
        csz='Pickup: ' + csz;
        anc='Drop-off: ' + anc;
      }
      updatable_fields('#search_pickup_place',csz);
      updatable_fields('#search_drop_off_place',anc);
    }
    
    // auto-complete will only be defined in home_page.html.erb!
    if(window.autocomplete_init_to_airport){
      autocomplete_init_to_airport();
    }

  } else if ( val == 99 ) {
    // from airport
    $('#pickup_location_label').text('Airport');
    $('#drop_off_location_label').text('Drop-off Address');
    if(only_labels == undefined){
      if(isHome) {
        anc='Pickup: ' + anc;
        csz='Drop-off: ' + csz;
      }   
      updatable_fields('#search_pickup_place',anc);
      updatable_fields('#search_drop_off_place',csz);
    }
    // auto-complete will only be defined in home_page.html.erb!
    if(window.autocomplete_init_from_airport){
      autocomplete_init_from_airport();
    }
  } else if (val == 102) {
    // to cruise port
    $('#pickup_location_label').text('Pick-up address');
    $('#drop_off_location_label').text('Cruiseport');
    if(only_labels == undefined){   
      if(isHome) {
        csz='Pickup: ' + csz;
        cnc='Drop-off: ' + cnc;
      }
      updatable_fields('#search_pickup_place',csz);
      updatable_fields('#search_drop_off_place',cnc);
    }
  } else if (val == 101) {
    // from cruise port
    $('#pickup_location_label').text('Cruiseport');
    $('#drop_off_location_label').text('Drop-off Address');
    if(only_labels == undefined){
      if(isHome) {
        cnc='Pickup: ' + cnc;
        csz='Drop-off: ' + csz;
      }
      updatable_fields('#search_pickup_place',cnc);
      updatable_fields('#search_drop_off_place',csz);
    }
  } else {
    $('#pickup_location_label').text('Pick-up address');
    $('#drop_off_location_label').text('Drop-off Address');
    if(only_labels == undefined){
      if(isHome) {
        var cszPickup='Pickup: ' + csz;
        var cszDropoff='Drop-off: ' + csz;
        updatable_fields('#search_pickup_place',cszPickup);
        updatable_fields('#search_drop_off_place',cszDropoff);
      } else {
        updatable_fields('#search_pickup_place',csz);
        updatable_fields('#search_drop_off_place',csz);
      }
    }
  }
}

// Updates a field(s) refid and value attributes to val param based on id param.
function updatable_fields(id,val){
  var oldRefid = $(id).attr('refid');
  $(id).attr('refid',val);
  if( $(id).val() == '' || $(id).val() == oldRefid ){$(id).val(val);}
}

//If first time is set, change second time to an hour later
function changeTimeSlot() {
  
  var index_offset = 8; // half hour increments = 3 hours
  
  // put 6 hours for prom
  if( $('#service_type').val() == '16384' ){ index_offset = 12; }
  
  var hs = $('#search_pickup_time')[0].selectedIndex;
  var et = $('#search_drop_off_time')[0].selectedIndex;


  var do_time_idx = hs+index_offset;
  //if (do_time_idx>48) {do_time_idx=48;}
  if (do_time_idx >= 48) {
    $('#search_drop_off_time')[0].selectedIndex =  (do_time_idx - 48);
  } else {
    $('#search_drop_off_time')[0].selectedIndex = do_time_idx;
  }

}

// If first time is set
function changeSplitTimeSlots() {
  var index_offset = 4; // half hour increments = 3 hours
  
  // put 6 hours for prom
  if( $('#service_type').val() == '16384' ){ index_offset = 6; }
  
  var pickup_minutes = $('#search_pickup_time_minute').val();
  $('#search_drop_off_time_minute').val(pickup_minutes);
  
  var hs = $('#search_pickup_time_hour').val();

  var do_time_idx = parseInt(hs, 10)+index_offset;

  // wrap around midnight which has the value '00'
  if (do_time_idx > 23) { do_time_idx=do_time_idx-24; }

  // left pad with zero if necessary
  if (do_time_idx < 10) { do_time_idx = '0' + do_time_idx; }

  $('#search_drop_off_time_hour').val(do_time_idx);

}


function validate_timepicker(time) {

  // make sure the entry passes a general regex
  if (time.match(/^(\d{1,2}):(\d{2})(?:[ap]m)?$/i)) {
    // split into array
    var picker = time.split(":");
  } else {
    return 1;
  }

  // array should have two elements
  if ($(picker).size() == 2) {
    // check that hour is between 0 and 23
    if (!(parseInt(picker[0], 10) >= 0 && parseInt(picker[0], 10) <= 23)) {
      return 1;
    }
    // if am/pm is on the end ensure it doesnt exist on a 24 hour value (13:00pm,etc)
    if (picker[1].length == 4 && parseInt(picker[0], 10) <= 12 && parseInt(picker[0], 10) != 0) {
      // check that the mins are in a proper range
      if (!(parseInt(picker[1].substr(0, 2), 10) >= 0 && parseInt(picker[1].substr(0, 2), 10) <= 59)) {
        return 1;
      }
    } else {
      // if here this should be a 24 hour formated time, check mins and make sure am/pm doesnt exist
      if (picker[1].match(/(?:[ap]m)$/i) || !(parseInt(picker[1], 10) >= 0 && parseInt(picker[1], 10) <= 59)) {
        return 1;
      }
    }
  } else {
    return 1;
  }
  // otherwise all is well, return 0
  return 0;
}

function validate_form() {

  $('.formError').remove(); /* clear out old errors */
	$('.errorRed').removeClass('errorRed');
	
	
	var alertmsg = '';
	var errfields = new Array();
	var extraerrs = new Array();
		
	var isHome = $('#search_home').length > 0 ? true : false; 
		
	svctype = $('#service_type').val();
	sdop = $('#search_drop_off_place').val();
	spup = $('#search_pickup_place').val();
	
	if($('#passenger_first_name').val()=="")
	{
	  alertmsg += " 'First name'\n";
	  errfields.push('#passenger_first_name');
	}
	if($('#passenger_email').val()=="" && $('#passenger_email_needs_validation').val()=="true")
	{
	  alertmsg += " 'First name'\n";
	  errfields.push('#passenger_email');
	}
	if (svctype=='')
	{ 
		alertmsg += " 'Type of Service'\n";
		errfields.push('#service_type');
    }
  if ($('#search_pax').val()=='')
  {
      alertmsg += " 'Passengers'\n";
    errfields.push('#search_pax');
  }
  if ($('#search_ride_date').val()=='' || $('#search_ride_date').val()=='Select Date' || $('#search_ride_date').val()=='On what date?')
  {
    alertmsg += " 'Date of service'\n";
    errfields.push('#search_ride_date');
  }

  // make sure time_pickup is not blank
  if( $('#time_pickup').val() == '') {
    alertmsg += " 'Time of Pickup'\n";
    errfields.push('#time_pickup');
  }

  // make sure time_drop off is not blank when svctype is of type with drop off
  if( $('#time_dropoff').val() == '' && (svctype!="99" && svctype!="100" && svctype!="101" && svctype!="102" && svctype != "131072")) {
    alertmsg += " 'Time of Drop off'\n";
    errfields.push('#time_dropoff');
  }

  // make sure time_pickup is validated, if undefined then its not on the page and we dont check
  if ($('#time_pickup').val() != undefined) {
    var tp_err = 0;
    // get rid of white space
    var tp = $('#time_pickup').val().replace(/\s/g,'');
    // put the white spaced stripped value back in textbox
    $('#time_pickup').val(tp);

    // method call returns back validation code
    tp_err = validate_timepicker(tp);

    if (tp_err == 1) {
      alertmsg += " 'Time of Pickup'\n";
      errfields.push('#time_pickup');
      extraerrs.push("Please provide time in valid format (HH:MM pm)");
    }
  }

  // make sure time_dropoff is validated
  if ($('#time_dropoff').val() != undefined && (svctype != "99" && svctype != "100" && svctype != "101" && svctype != "102" && svctype != "131072")) {
    var td_err = 0;
    // get rid of white space
    var td = $('#time_dropoff').val().replace(/\s/g, '');
    // put the white spaced stripped value back in textbox
    $('#time_dropoff').val(td);

    // method call returns back validation code
    td_err = validate_timepicker(td);

    if (td_err == 1) {
      alertmsg += " 'Time of Drop off'\n";
      errfields.push('#time_dropoff');
      if (!tp_err == 1) {
        extraerrs.push("Please provide time in valid format (HH:MM pm)");
      }
    }
  }

   if ($('#time_pickup').val() == $('#time_dropoff').val() && $('#time_dropoff').val() != '' && ($('#time_pickup').val() != undefined && $('#time_dropoff').val() != undefined)){
      alertmsg += " 'Time of Dropoff:'\n";
      extraerrs.push("Pickup and drop off times cannot be the same.")
   }

  if(isHome) {
    if ($('#search_pickup_time_hour').val()=='')
      {
        alertmsg += " 'Time of Pickup'\n";
        errfields.push('#search_pickup_time_hour');
      }
    if ($('#search_drop_off_time_hour').val()=='' && (svctype!="99" && svctype!="100" && svctype!="101" && svctype!="102") )
      {
        alertmsg += " 'Time of Drop off'\n";
        errfields.push('#search_drop_off_time_hour');
      }
  } 
  if ($('#search_pickup_time').val()=='')
  {
    alertmsg += " 'Time of Pickup'\n";
    errfields.push('#search_pickup_time');
  }
  
  if ( $('#search_drop_off_time').val()=='' && (svctype!="99" && svctype!="100" && svctype!="101" && svctype!="102") )
  {
    alertmsg += " 'Expected drop-off Time'\n";
    errfields.push('#search_drop_off_time');
  }

if(isHome) {
  if (spup==''||spup=='Pickup: Address, City, or Zip'||spup=='Pickup: Airport Name, Code or City'||spup=='Pickup location?')
  {
    alertmsg += " 'Pick-up address'\n";
    errfields.push('#search_pickup_place');
  } 
  
} else {
  if (spup==''||spup=='Address, City, or Zip'||spup=='Airport Name, Code or City')
  {
    alertmsg += " 'Pick-up address'\n";
    errfields.push('#search_pickup_place');
  }
}

if(isHome) {
  if ((svctype=="99"||svctype=="100"||svctype=="101"||svctype=="102"||svctype=="131072") && (sdop==''||sdop=='Drop-off: Address, City, or Zip'||sdop=='Drop-off: Airport Name, Code or City'||sdop=='Drop-off location?')) 
  {
  alertmsg += " 'Drop-off address'\n";
  errfields.push('#search_drop_off_place');
  }

} else {
  if ((svctype=="99"||svctype=="100"||svctype=="101"||svctype=="102"||svctype=="131072") && (sdop==''||sdop=='Address, City, or Zip'||sdop=='Airport Name, Code or City')) 
  {
    alertmsg += " 'Drop-off address'\n";
    errfields.push('#search_drop_off_place');
  }
}


  // make sure pickup is at least 1 hour in the future
  var one_hour_from_now = new Date(+(new Date()) + (1000 * 60 * 60)); // add 1 hour's worth of milliseconds
  var ride_time;
  if ($('#search_pickup_time').length) {
    ride_time = $('#search_pickup_time').val();
  } else {
    ride_time = $('#search_pickup_time_hour').val()+":"+$('#search_pickup_time_minute').val();
  }
  // some browsers have a hard time without a full 4-digit year format, so tack on the "20" to make 2011 -- I doubt this code will be around in 89 years to cause a bug
  var ride_date = $('#search_ride_date').val();
  var ride_date_ar = [];
  // ride date may be in 3 formats: 10/11/11, 10/11/2011, or 2011-10-11
  if( ride_date.match('/') ){
    ride_date_ar = ride_date.split('/');
    if(ride_date_ar[2].length == 2 ) ride_date_ar[2] = "20"+ride_date_ar[2];
  } 
  else if( ride_date.match('-') ){
    ride_date_ar = ride_date.split('-');
    ride_date_ar = [ride_date_ar[1],ride_date_ar[2],ride_date_ar[0]];
  }
  ride_date = ride_date_ar.join('/');
  var ride_date_time = new Date(ride_date+" "+ride_time);
  if( alertmsg=='' && ride_date_time < one_hour_from_now ){
    alertmsg += " 'Time of Pickup:'\n";
    errfields.push('#search_pickup_time_hour');
    extraerrs.push("The ride must be at least one hour in the future.");
  }



  if ( alertmsg=='' && svctype!="99" && svctype!="100" && svctype!="101" && svctype!="102" && svctype!="131072" ) 
  { 
    var drophour = pickhour = dropminute = pickminute = timediff = 0;
    if ($('#search_drop_off_time').length) {
      drophour = parseInt($('#search_drop_off_time').val().substring(0,2),10);
      if( $('#search_drop_off_time').val().substring(3)=="30" ) drophour += 0.5;
      pickhour = parseInt($('#search_pickup_time').val().substring(0,2),10);
      if( $('#search_pickup_time').val().substring(3)=="30" ) pickhour += 0.5;
    } else {
      drophour = parseInt($('#search_drop_off_time_hour').val(), 10); 
      var dropminute = $('#search_drop_off_time_minute').val();
      if( dropminute=="15" ) drophour += 0.25;
      else if( dropminute=="30" ) drophour += 0.5;
      else if( dropminute=="45" ) drophour += 0.75;
      pickhour = parseInt($('#search_pickup_time_hour').val(), 10);
      var pickminute = $('#search_pickup_time_minute').val();
      if( pickminute=="15" ) pickhour += 0.25;
      else if( pickminute=="30" ) pickhour += 0.5;
      else if( pickminute=="45" ) pickhour += 0.75;
    }
    timediff = drophour - pickhour;
    
    if( timediff == 0 && svctype != "131072" ) {
      alertmsg += " 'Time of Dropoff:'\n";
      errfields.push('#search_drop_off_time_hour');
      extraerrs.push("Pickup and drop off times cannot be the same.")
    }

    if( timediff < 1 && timediff > 0 ) {
      alertmsg += " 'Time of Dropoff:'\n";
      errfields.push('#search_drop_off_time_hour');
      extraerrs.push("Minimum ride duration is 1 hour.");
    }

		if( timediff < 0 ){ timediff += 24; /* account for times spanning midnight */ }
		
		// special circumstance for prom
		if( $('#service_type').val() == '16384' && timediff < 6 && $.cookie('promTimeWarning') != 1 ) {
		  if( confirm('Prom Tip! Limo companies generally require 6+ hours for prom.\nClick OK to see the best deals for 6+ hour rides.') ){ 
	       changeTimeSlot(); // update back to 6 hours and continue;
	       $.cookie('promTimeWarning', 1); // set a cookie so we only show them the warning once.
	    }
		}
		
		if( timediff >= 12 && !confirm( 'You have selected a ride duration of '+timediff+' hours. Is this correct?\n\nClick OK to continue.' ) )
		{
	 	   alertmsg += " 'Time of Pickup'\n";
		   
			if(isHome) {
				errfields.push('#search_pickup_time_hour');
				errfields.push('#search_pickup_time_minute');
				errfields.push('#search_drop_off_time_hour');
				errfields.push('#search_drop_off_time_minute');
			} else {
				errfields.push('#search_pickup_time');
			}
		   extraerrs.push("Please select a valid time span.");
		}
		
	}

	if (alertmsg!='' && ucsv == 2 ) {
		var extraerr = '';
		if( extraerrs.length > 0 ) extraerr = "<br/>"+extraerrs.join('<br/>');
		msg = "<div class='formError'><strong>Please provide all information below for accurate results.</strong>"+extraerr+"</div>";
		$(msg).prependTo('#homeFormTop');
		$(errfields.toString()).each( function(){ 
			$(this).parent().addClass('errorRed'); 
			$(this).change(function(){
				$(this).parent().removeClass('errorRed');
			});
		});
		
		if(isHome) {
			if ($('#search_ride_date').val()=='') {
				$('#search_ride_date').attr('value','On what date?'); 
			};
			if ($('#search_pickup_place').val()=='') {
				$('#search_pickup_place').attr('value','Pickup location?'); 
			};
				if ((svctype=="99"||svctype=="100"||svctype=="101"||svctype=="102"||svctype=="131072") && ($('#search_drop_off_place').val()=='')) {
				$('#search_drop_off_place').attr('value','Drop-off location?'); 
			};
		};
		
		return false;
	}
	else if (alertmsg!='') {
		alert('Please complete all of the following fields:\n\n'+alertmsg+''+extraerr);
		return false;
	}
	return true;
}

$(window).unload(function() {
  $('#search_submit').removeAttr('disabled');
  if (!($('#search_home').length > 0)) {
    $('#search_submit').attr('value','Find a limo');
  } 
});

