// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// toggle a few address fields if this is a national service
function toggle_city_state_zip() {
	document.getElementById('review_street').disabled = document.getElementById('review_nationwide').checked;
	document.getElementById('review_city').disabled = document.getElementById('review_nationwide').checked;
	document.getElementById('review_state').disabled = document.getElementById('review_nationwide').checked;
	document.getElementById('review_postal_code').disabled = document.getElementById('review_nationwide').checked;
	if (document.getElementById('review_nationwide').checked) {
		document.getElementById('switchable_street').className = "inactive";
		document.getElementById('switchable_city').className = "inactive";
		document.getElementById('switchable_state').className = "inactive";
		document.getElementById('switchable_zip').className = "inactive";
		document.getElementById('review_street').value = 'Nationwide';
	}
	else {
		document.getElementById('switchable_street').className = "";
		document.getElementById('switchable_city').className = "";
		document.getElementById('switchable_state').className = "";
		document.getElementById('switchable_zip').className = "";
		document.getElementById('review_street').value = '';
	}
}

function redirect_me(list) {
	// only forward if the prompt value wasn't selected
	if(list.selectedIndex != 0)
		document.location.href=list.options[list.selectedIndex].value;
}

function toggle_state_dropdown(country) {
	if(country.options[country.selectedIndex].value == 'United States' || 
	  country.options[country.selectedIndex].value == 'Canada'){	
		Element.show('state_dropdown');
		Element.hide('disabled_state_dropdown');
	}
	else {
		Element.hide('state_dropdown')
		Element.show('disabled_state_dropdown');
	}
}

function toggle_gluten_free_fields(is_gluten_free) {
  if (is_gluten_free) {
    Effect.BlindUp(  'is_not_gluten_free_fields', {duration:.5});
    Effect.BlindDown('is_gluten_free_fields',     {duration:.5});
    Effect.BlindDown('shared_fields',             {duration:.5});
	Element.show('product_is_also');
  } else {
    Effect.BlindUp(  'is_gluten_free_fields',     {duration:.5});
    Effect.BlindDown('is_not_gluten_free_fields', {duration:.5});
    Effect.BlindDown('shared_fields',             {duration:.5});
	Element.show('product_is_also');
  }
}

function show_edit_product_purchase_url(show) {
  if (show) {
    Element.hide('edit_product_purchase_show_link');
	Element.hide('buy_now_link');
    Effect.BlindDown('edit_product_purchase_url', {duration:.5});
  } else {
    Effect.BlindUp  ('edit_product_purchase_url', {duration:.5});
	Element.show('buy_now_link');
    Element.show('edit_product_purchase_show_link');
  }
}

function show_members_search_field(show) {
	if (show) {
		Element.show('search_text');
		Effect.BlindDown('search_text', {duration:.5});
	} else {
		Element.BlindUp('search_text', {duration:.5});
		Element.hide('search_text');
	}
	
}

jQuery(document).ready(function(){
  jQuery('.rating_star').rating({
    required: true
  });
});

function preloadRollovers(){
	var toPreload = new Array();
	toPreload = ["../images/nv_active_invite_home.gif",
		"../images/nv_active_invite.gif",
		"../images/nv_active_profile_home.gif",
		"../images/nv_active_profile.gif",
		"../images/nv_active_review_home.gif",
		"../images/nv_active_review.gif",
		"../images/nv_active_search.gif",
		"../images/nv_active_welcome.gif",
		"../images/nv_hov_celiac_home.gif",
		"../images/nv_hov_celiac.gif",
		"../images/nv_hov_invite_home.gif",
		"../images/nv_hov_invite.gif",
		"../images/nv_hov_profile_home.gif",
		"../images/nv_hov_profile.gif",
		"../images/nv_hov_review_home.gif",
		"../images/nv_hov_review.gif",
		"../images/nv_hov_search.gif",
		"../images/nv_hov_welcome.gif",
		"../images/nv_reg_celiac_home.gif",
		"../images/nv_reg_celiac.gif",
		"../images/nv_reg_invite_home.gif",
		"../images/nv_reg_invite.gif",
		"../images/nv_reg_profile_home.gif",
		"../images/nv_reg_profile.gif",
		"../images/nv_reg_review_home.gif",
		"../images/nv_reg_review.gif",
		"../images/nv_reg_search.gif",
		"../images/nv_reg_welcome.gif",
		"../images/celiac_tab_bg.gif",
		"../images/celiac_tab_fg.gif",
		"../images/celiac_tab_hover.gif",
		"../images/online_tab_bg.gif",
		"../images/online_tab_fg.gif",
		"../images/online_tab_hover.gif"];
	var preloadArray = new Array();
		for (x=0; x<toPreload.length; x++){
			preloadArray[x] = new Image();
			preloadArray[x].src = toPreload[x];
		}
}

function attachGhosts(){
	alert(document.getElementById("location_terms"));
	if (document.getElementById("location_terms")) {
		boxx.className = "subsearchcityzip ghosted";
		boxx.setAttribute('value', 'City, Postal Code');
	}
}

function ghostSearchBox() {
	var boxx = document.getElementById('location_terms');
	if (boxx.value == '' || boxx.value == 'City, Postal Code') {
		boxx.className = 'subsearchcityzip ghosted';
		boxx.setAttribute('value', 'City, Postal Code');
	}
}

function unghostSearchBox() {
	var boxx = document.getElementById('location_terms');
	if (boxx.value == '' || boxx.value == 'City, Postal Code') {
		boxx.className = 'subsearchcityzip';
		boxx.setAttribute('value', '');
	}
}