// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
    thisfield.value = "";
  }
}

function clickrecall(thisfield, defaulttext) {
  if (thisfield.value == "") {
    thisfield.value = defaulttext;
  }
}

function scrollToChild(parentID, childID, offset) {
  parent = $(parentID);
  child  = $(childID);
  parent.scrollTop = child.offsetTop + offset;
}

// Metadata functions
function updateByType(type) {
    if (type == 'Private or Country Club') {
        Element.show('sponsor');

        new Effect.Highlight('sponsor');
    } else {
        Element.hide('sponsor');
    }

    return true;
}

function updateByOnsiteCatering(yes_or_no, nest_check) {
    if (yes_or_no != "false") {
        Element.show('budget_per_guest');
        Element.show('offsite_catering');
        Element.show('offsite_catering_extension');
        Element.show('kosher');
        
        Element.hide('budget_site_rental');

        Element.hide('rental_price');
        Element.show('offsite_price');

        new Effect.Highlight('budget_per_guest');
        new Effect.Highlight('offsite_catering');
        new Effect.Highlight('offsite_catering_extension');
        new Effect.Highlight('kosher');
        
        if (nest_check) {
            updateByOffsiteCatering($('profile_allow_offsite_caterers').value);
        }
    } else {
        Element.hide('budget_per_guest');
        Element.hide('offsite_catering');
        Element.hide('offsite_catering_extension');
        Element.hide('kosher');

        Element.hide('offsite_price');
        Element.show('rental_price');
        
        Element.show('budget_site_rental');

        new Effect.Highlight('budget_site_rental');
    }

    return true;
}

function updateByOffsiteCatering(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('budget_site_rental');

        new Effect.Highlight('budget_site_rental');
        
        $('profile_allow_offsite_caterers_fee').disabled = false;
    } else {
        Element.hide('budget_site_rental');

        $('profile_allow_offsite_caterers_fee').checked  = false;
        $('profile_allow_offsite_caterers_fee').disabled = true;
    }

    return true;
}

function updateByBYOAlcohol(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('alcohol_types');

        new Effect.Highlight('alcohol_types');

        $('profile_byo_alcohol_fee').disabled = false;
    } else {
        Element.hide('alcohol_types');

        $('profile_byo_alcohol_fee').checked  = false;
        $('profile_byo_alcohol_fee').disabled = true;
    }

    return true;
}

function updateByPerCakeSlice(on_or_off) {
    if (on_or_off) {
        Element.hide('per_slice_price');
        Element.show('per_cake_price');

        new Effect.Highlight('per_cake_price');
    } else {
        Element.hide('per_cake_price');
        Element.show('per_slice_price');

        new Effect.Highlight('per_slice_price');
    }

    return true;
}

function updateByOtherProduct(on_or_off) {
    if (on_or_off) {
        Element.show('other_product');

        new Effect.Highlight('other_product');
    } else {
        Element.hide('other_product');
    }

    return true;
}

function updateByMultipleVideographers(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('guarantee');

        new Effect.Highlight('guarantee');
    } else {
        Element.hide('guarantee');

        $('profile_guarantee_videographer').checked = false;
    }

    return true;
}

function updateByMultiplePhotographers(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('guarantee');

        new Effect.Highlight('guarantee');
    } else {
        Element.hide('guarantee');

        $('profile_guarantee_photographer').checked = false;
    }

    return true;
}

function updateByCocktailHour(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('cocktail_rates');

        new Effect.Highlight('cocktail_rates');
    } else {
        Element.hide('cocktail_rates');
    }

    return true;
}

function updateByOtherGenre(on_or_off) {
    if (on_or_off) {
        Element.show('other_genre');

        new Effect.Highlight('other_genre');
    } else {
        Element.hide('other_genre');
    }

    return true;
}

function updateByMultipleMusicians(yes_or_no) {
    if (yes_or_no != "false") {
        Element.show('guarantee');

        new Effect.Highlight('guarantee');
    } else {
        Element.hide('guarantee');
    }

    return true;
}

function updateByStyle(style) {
    if (style == "Photojournalism") {
        Element.show('training');

        new Effect.Highlight('training');
    } else {
        Element.hide('training');
    }

    return true;
}

function updateByStyleAndTraining(style, training) {
    if (style == "Photojournalism" && training != "Learned on the job") {
        Element.show('training_details');

        new Effect.Highlight('training_details');
    } else {
        Element.hide('training_details');
    }

    return true;
}

function updateByOtherSpecialty(on_or_off) {
    if (on_or_off) {
        Element.show('other_specialty');

        new Effect.Highlight('other_specialty');
    } else {
        Element.hide('other_specialty');
    }

    return true;
}

function updateByLiveMusic(on_or_off) {
  if (on_or_off) {
      $( 'profile_live_music_low_end'  ).disabled = false;
      $( 'profile_live_music_high_end' ).disabled = false;
      $( 'no_live_music_minimum_spend' ).disabled = false;

      toggleDisabled('profile_live_music_minimum_spend', $('no_live_music_minimum_spend').checked);

      Element.show('musicians');

      new Effect.Highlight('musicians');
  } else {
      $( 'profile_live_music_low_end'       ).disabled = true;
      $( 'profile_live_music_high_end'      ).disabled = true;
      $( 'profile_live_music_minimum_spend' ).disabled = true;
      $( 'no_live_music_minimum_spend'      ).disabled = true;

      Element.hide('musicians');
  }

  return true;
}

function updateByDJ(on_or_off) {
  if (on_or_off) {
      $( 'profile_dj_low_end'  ).disabled = false;
      $( 'profile_dj_high_end' ).disabled = false;
      $( 'no_dj_minimum_spend' ).disabled = false;

      toggleDisabled('profile_dj_minimum_spend', $('no_dj_minimum_spend').checked);
  } else {
      $( 'profile_dj_low_end'       ).disabled = true;
      $( 'profile_dj_high_end'      ).disabled = true;
      $( 'profile_dj_minimum_spend' ).disabled = true;
      $( 'no_dj_minimum_spend'      ).disabled = true;
  }

  return true;
}

function updateByVehicleType(field, default_capacity, on_or_off) {
    if (on_or_off) {
        $( 'profile_' + field + '_low_end'  ).value    = '25';
        $( 'profile_' + field + '_low_end'  ).disabled = false;
        $( 'profile_' + field + '_high_end' ).value    = '125';
        $( 'profile_' + field + '_high_end' ).disabled = false;
        $( 'profile_' + field + '_capacity' ).value    = default_capacity;
        $( 'profile_' + field + '_capacity' ).disabled = false;
    } else {
        $( 'profile_' + field + '_low_end'  ).value    = '';
        $( 'profile_' + field + '_low_end'  ).disabled = true;
        $( 'profile_' + field + '_high_end' ).value    = '';
        $( 'profile_' + field + '_high_end' ).disabled = true;
        $( 'profile_' + field + '_capacity' ).value    = '';
        $( 'profile_' + field + '_capacity' ).disabled = true;
    }

    return true;
}

function updateByOtherVehicle(on_or_off) {
    if (on_or_off) {
        Element.show('other_vehicle');

        new Effect.Highlight('other_vehicle');
    } else {
        Element.hide('other_vehicle');
    }

    return true;
}

function updateByOtherDesigner(on_or_off) {
    if (on_or_off) {
        Element.show('other_designer');

        new Effect.Highlight('other_designer');
    } else {
        Element.hide('other_designer');
    }

    return true;
}

function updateByOtherPrinter(on_or_off) {
    if (on_or_off) {
        Element.show('other_printer');

        new Effect.Highlight('other_printer');
    } else {
        Element.hide('other_printer');
    }

    return true;
}

function updateByTravel(yes_or_no) {
    if (yes_or_no != 'false') {
        Element.show('area_served');
        Element.show('travel_fee');

        new Effect.Highlight('area_served');
        new Effect.Highlight('travel_fee');
    } else {
        Element.hide('area_served');
        Element.hide('travel_fee');
    }

    return true;
}

function updateByService(service, on_or_off, nest_check) {
    if (on_or_off) {
        $('profile_' + service + '_low_end').disabled  = false;
        $('profile_' + service + '_high_end').disabled = false;

        $('profile_trials_' + service).disabled = false;
    } else {
        $('profile_' + service + '_low_end').disabled  = true;
        $('profile_' + service + '_high_end').disabled = true;

        $('profile_trials_' + service).checked  = false;
        $('profile_trials_' + service).disabled = true;

		if (nest_check) {
			updateByTrials($('profile_trials_hair').checked || $('profile_trials_makeup').checked);
		}
    }

    return true;
}

function updateByTrials(any_on) {
    if (any_on) {
        Element.show('trial_fee');
        Element.show('trial_fee_credit');

        new Effect.Highlight('trial_fee');
        new Effect.Highlight('trial_fee_credit');
    } else {
        Element.hide('trial_fee');
        Element.hide('trial_fee_credit');
    }

    return true;
}

function toggleDisabled(fieldID, on_or_off) {
    if (on_or_off) {
        $(fieldID).value    = '';
        $(fieldID).disabled = true;
    } else {
        $(fieldID).disabled = false;
    }

    return true;
}

function validateSearch() {
  if ( ( $('h_drop').options[$('h_drop').selectedIndex].value == '' ||
         $('i_getmarr').value == 'City and State or ZIP' )          &&
       $('h_inputer').value == 'Search by Business Name' ) {
    alert( 'Please select a category and enter a location, ' +
           'or provide a name to search by.' );
    return false;
  } else {
    if ($('h_drop').options[$('h_drop').selectedIndex].value == '') {
      $('h_drop').disabled = true;
    }
    if ($('h_inputer').value == 'or by Business Name') {
      $('h_inputer').disabled = true;
    }
    if ($('i_getmarr').value == 'City, State or ZIP') {
      $('i_getmarr').disabled = true;
    }
    $('h_sgo').disabled = true;
    return true;
  }
}

function validateHotelSearch() {
  if ($('search_hotel').value == '') {
    alert('Please enter the name of your reception site.');
    return false;
  } else {
    return true;
  }
}

function purchaseCredits() {
    $('save').disabled = true;
    return true;
}

function setSiteBudgetFilters(site_type) {
  if (site_type == 'Catering Plus Site Rental') {
    $('budget_description').innerHTML                = 'Fee Per Guest';
    $('min_example').innerHTML                       = 'eg. $80';
    $('max_example').innerHTML                       = 'eg. $110';
    $('filters_allow_offsite_caterers_fee').disabled = true;
    $('filters_site_budget_low_end').disabled        = false;
    $('filters_site_budget_high_end').disabled       = false;
  } else if (site_type == 'Site Rental Only') {
    $('budget_description').innerHTML                = 'Site Rental Fee';
    $('min_example').innerHTML                       = 'eg. $2,000';
    $('max_example').innerHTML                       = 'eg. $3,000';
    $('filters_allow_offsite_caterers_fee').disabled = false;
    $('filters_site_budget_low_end').disabled        = false;
    $('filters_site_budget_high_end').disabled       = false;
  } else {
    $('budget_description').innerHTML                = '<em>Select Catering &amp; Site Rental Above</em>';
    $('min_example').innerHTML                       = 'eg. $80';
    $('max_example').innerHTML                       = 'eg. $110';
    $('filters_allow_offsite_caterers_fee').disabled = true;
    $('filters_site_budget_low_end').disabled        = true;
    $('filters_site_budget_high_end').disabled       = true;
  }
}

function setGuaranteePhotographers(yes_or_no) {
  if (yes_or_no == 'Yes') {
    $('filter_guarantee_photographer').disabled = false;
  } else {
    $('filter_guarantee_photographer').disabled = true;
  }
}

function checkFloristBudgetInputs() {
  if ($('filters_florist_low_end').value != '' || $('filters_florist_high_end').value != '') {
    if ($('filters_reception_tables').value == '0' && $('filters_bridesmaid_bouquets').value == '0' && $('filters_ceremony_flowers').value == 'No') {
	  alert('Please select a number of reception tables, a number of bridesmaid bouquets, or indicate that you need ceremony flowers as these are the categories we will check your budget against.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function checkMusicBudgetInputs() {
  if ($('filters_music_low_end').value != '' || $('filters_music_high_end').value != '') {
    if (!$('filters_music_budget_for_reception').checked && !$('filters_music_budget_for_cocktail').checked) {
	  alert('Please select at least one time requirement as these are the categories we will check your budget against.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function checkWeddingBudgetInputs() {
  if ($('filters_wedding_budget_low_end').value != '' || $('filters_wedding_budget_high_end').value != '') {
    if ($('filters_wedding_guests').value == 'Any') {
	  alert('Please select a number of guests as this will be used in your budget comparison.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function checkCateringBudgetInputs() {
  if ($('filters_catering_budget_low_end').value != '' || $('filters_catering_budget_high_end').value != '') {
    if ($('filters_catering_guests').value == 'Any') {
	  alert('Please select a number of guests as this will be used in your budget comparison.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function checkCeremonyBudgetInputs() {
  if ($('filters_ceremony_low_end').value != '' || $('filters_ceremony_high_end').value != '') {
    if ($('filters_ceremony_hours').value == 'Any') {
	  alert('Please select a number of hours as this will be used in your budget comparison.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function checkInvitationBudgetInputs() {
  if ($('filters_invitation_low_end').value != '' || $('filters_invitation_high_end').value != '') {
    if ($('filters_invitation_count').value == 'Any') {
	  alert('Please select a number of guests as this will be used in your budget comparison.');
	  return false;
	} else {
	  return true;
	}
  } else {
    return true;
  }
}

function setGuaranteeMusicians(yes_or_no) {
  if (yes_or_no == 'Yes') {
    $('filters_guarantee_musicians').disabled = false;
  } else {
    $('filters_guarantee_musicians').disabled = true;
  }
}

function setGuaranteeVideographers(yes_or_no) {
  if (yes_or_no == 'Yes') {
    $('filter_guarantee_videographer').disabled = false;
  } else {
    $('filter_guarantee_videographer').disabled = true;
  }
}

function setHairSpecialty(hair_or_makeup) {
  if (hair_or_makeup == 'Hair' || hair_or_makeup == 'Makeup') {
    $('filters_hair_specialists').disabled = false;
  } else {
    $('filters_hair_specialists').disabled = true;
  }
}

function setTravelFee(will_travel) {
  if (will_travel != 'Won\'t Travel to Bride') {
    $('filters_hair_travel_fee').disabled = false;
  } else {
    $('filters_hair_travel_fee').disabled = true;
  }
}

function show_hide(fieldID, claimed){
    if(claimed && $(fieldID).style.display == 'none'){
        var agree = confirm("Are you sure you want to edit this content?");
        if(agree){
            if ($(fieldID).style.display == 'none'){
                Element.show(fieldID)
            }else{
                Element.hide(fieldID);
            }
        }else{
            return false;
        }
    }else{
        if ($(fieldID).style.display == 'none'){
            Element.show(fieldID)
        }else{
            Element.hide(fieldID);
        }
    }
}

function check_claimed(claimed){
    if(claimed){
        confirm("Yes or No");
    }
    else{
        confirm("Holla");
    }
}

function toggle_url_for_this_page(){
  $('link_to_this_page').toggle();
  $('link_to_this_page').select('form/input')[0].select();
  $('link_to_this_page').select('form/input')[0].focus();
  return false;
}

function category_nav_search(category){
  $('category_nav_search_hidden_field').value = category;
  $('category_nav_search').submit();
}

function PadDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    }

function prepareHotelSubmit() {
  var check_in = $('check_in_year').value  + '-' + PadDigits($('check_in_month').value, 2)  + '-' + PadDigits($('check_in_day').value, 2);
  var check_out = $('check_out_year').value  + '-' + PadDigits($('check_out_month').value, 2)  + '-' + PadDigits($('check_out_day').value, 2);
  var now = new Date();
  var today = now.getFullYear() + '-' + PadDigits(now.getMonth() + 1, 2) + '-' + PadDigits(now.getDate(), 2);
  var rooms = parseInt($('00N30000000c0KM').value);
  if ($('phone').value == null || $('phone').value == '') {
	alert('Please enter a phone number where you can be reached.');
	return false;
  } else if (check_in <= today) {
	alert('Check in date must be in the future.');
	return false;
  }	else if (check_out <= check_in) {
	alert('Check out date must be later than check in date.');
	return false;
  } else if (rooms < 9 || rooms > 50) {
	alert('Number of rooms must be between 9 and 50.');
	return false;
  }

  $('final_check_in').value  = $('check_in_month').value  + '/' + $('check_in_day').value  + '/' + $('check_in_year').value;
  $('final_check_out').value = $('check_out_month').value + '/' + $('check_out_day').value + '/' + $('check_out_year').value;
  return true;
}
