function go(form) {
   window.location = form.range.options[form.range.selectedIndex].value;

}

function trim() {
  // remove all spaces from aText text field 
  // and place the result into the right text field
  document.ship_form.gift_certificate.value = 
        document.ship_form.gift_certificate.value.replace(/ /g, "");
}


 
function preload_images () {
   var d = document;
	 if (!d.imgs) { d.imgs = new Array(); }
	 var j = d.imgs.length, args = preload_images.arguments, i;
	 for (i = 0; i < args.length; i++) {
		  d.imgs[j] = new Image;
			d.imgs[j].src = args[i];
			j++;
	 }
}


 function bookmark(title)
 {

   var urlAddress = location.href;
   var pageName = title;
   var browser = navigator.appName;

  if (browser == 'Microsoft Internet Explorer')
  {
     window.external.AddFavorite(urlAddress,pageName)
  }
  else if (browser == 'Netscape')
  { 
     alert("Your browser does not support this feature.  Use CTRL-D to bookmark this page");
  }
  else
  { 
   alert("Your browser does not support this feature.");
  }
 }



function textBuild() 
{
     document.quickfind.keyword.value = document.quickfind.elements[3].value + ' ' + document.quickfind.elements[4].value + ' ' + document.quickfind.elements[5].value + ' ' + document.quickfind.elements[6].value;
}


function checkCheckBoxforcheckout_shippingaddressTEMPLATE(f,ship_num){
  if (f.readShipping.checked == false) {
    alert('To complete your order, you must accept the Chukar Cherries Shipping Policy by selecting the checkbox above.');
    return false;
  } else {
    return concatGiftMessage(f,ship_num);
  }
}

function checkCheckBoxforcheckout_wholesale_order_form2TEMPLATE(f){
if (f.skipit != 1) {
if (f.readwholesale.checked == false )
{
alert('To complete your order, you must accept the Chukar Cherries Minimum Order Policy by selecting the checkbox above.');
return false;
}else
return true;
}else
return true;
}



/* ***************************************
   * verifyRecipients() function.        *
   * Checks the checkout_shippingdetail  *
   * page to ensure that a shipping      *
   * recipient was chosen for each       *
   * product and that there weren't any  *
   * missed recipients.  If gives the    *
   * customer the option of ignoring     *
   * missed ship-tos since that doesn't  *
   * break the checkout it just causes   *
   * blank spaces in some spots.         *
   *                                     *
   * ~Michael - 20060111                 *
   *************************************** */

function verifyRecipients(theForm) {
  var intLength = theForm.length;            // Grab the total length of the form.
  var firstStep = 1, shipTos = new Array();  // Initialize a couple vars to be used later.
  for(var i=0;i<intLength;i++) {             // Loop through the form elements.
    if(firstStep && theForm.elements[i].name.substr(0,4) == 'recp') {
      // If it's the first dropdown setup the number of ship-tos it contains to compare later
      var numShipTos = +theForm.elements[i].options.length;
      // Turn this off so it doesn't repeat this step (it won't hurt anything but would waste processing power).
      firstStep = 0;
    }
    if(theForm.elements[i].name.substr(0,4) == 'recp' && theForm.elements[i].value == '') {
      // If we encounter a dropdown that hasn't had a ship-to selected..
      alert('You must choose a recipient for each of the products you are purchasing.');
      return false;
    } else if (theForm.elements[i].name.substr(0,4) == 'recp') {
      // Otherwise add the item to an array to compare later.
      var shipTo = theForm.elements[i].selectedIndex;
      if(!in_array(shipTo, shipTos)) {
        // If the ship-to isn't in the array already, add it.
        var stLen = shipTos.length;
        shipTos.push(shipTo);
      }
    }
  }
  if(shipTos.length != numShipTos) {
    // If the # of ship-tos in the array don't match the number of ship-tos that exist, prompt the user
    var verifyShipTos = confirm("Some of your shipping address do not have products assigned to them.\n\nDo you wish to continue anyway?");
    if(verifyShipTos) {
      // User says it's OK
      return true;
    } else {
      // User says it's not OK
      return false;
    }
  }
  // If we've gotten this far, everything on the form has checked out OK.
  return true;
}

/* ***************************************
   * in_array() function for JS.         *
   * Works the same as the PHP function. *
   *                                     *
   * ~Michael - 20060111                 *
   * ~Michael - Fixed undefined vars     *
   *            20060111                 *
   *************************************** */

function in_array(needle, haystack) {
  if(typeof needle == undefined) {
    // If needle is undefined:
    alert("Needle is undefined.\nError: in_array");
    return false;
  } else if(typeof haystack == undefined) {
    alert("Needle is undefined.\nError: in_array");
    return false;
  }
  for(i=0,n=haystack.length;i<n;i++) {
    // Loop through the array.
    if(haystack[i] == needle) {
      // If the needle was found:
      return true;
    }
  }
  // If the code reaches this point, needle wasn't found:
  return false;
}

//check for text in search box before submitting
function search_help() {
  //conditions for most searched for terms
  //to help aid navigation
  //first 3 forward user to relevant pages in site
  //next 2 fix terms to produce better search results
  if(document.searchform.keyword.value.toLowerCase() == 'shipping')
  {
     forward_this("shipping");
     return false;
  }

  if(document.searchform.keyword.value.toLowerCase() == 'kosher')
  {
     forward_this("kosher");
     return false;
  }

  if(document.searchform.keyword.value.toLowerCase() == 'dried fruit')
  {
     forward_this("dried fruit");
     return false;
  }

  if(document.searchform.keyword.value.toLowerCase() == 'chocolate covered cherries')
  {
     document.searchbar.keyword.value = "chocolate cherries"
     return true;
  }

  if(document.searchform.keyword.value.toLowerCase() == 'jams' || document.searchbar.keyword.value.toLowerCase() == 'jam')
  {
     document.searchform.keyword.value = "preserve"
     return true;
  }

}

//used to forward certain search terms to relevant page
function forward_this(here) {
  if(here == 'shipping') {
     window.location = "http://www.chukar.com/faqchukar#about03";
  }
  if(here == 'kosher') {
     window.location = "http://www.chukar.com/faqchukar#about04";
  } 
  if(here == 'dried fruit') {
     window.location = "http://www.chukar.com/ShowView/category/26";
  }
}

function concatGiftMessage(theForm,sNum) {
  var numFields = 5; // Number of giftmessage fields.
  for (var i=1;i<=sNum;i++) {
    document.getElementById('gift_message'+i).value = '';
    for (var x=1;x<=numFields;x++) {
      if (x<5) {
        document.getElementById('gift_message'+i).value += document.getElementById('gm'+x+'_'+i).value + '|';
      } else {
        document.getElementById('gift_message'+i).value += document.getElementById('gm'+x+'_'+i).value;
      }
    }
  }
  return true;
}


/**************************************************************
 * Generic toggle button
 * usage: test_id = id for testing (ex: select box)
 *        change_id = id for displaying (ex: div)
 *        change_val = toggle the display of the change_id depending on what value to set the test_id has when the test_id = change_val
 *        display_val = 'none' or 'block' depending on which should be used when test_id = change_val
 **************************************************************/
function toggleBlock(test_id,change_id,change_val,display_val) {
  if (document.getElementById(test_id).value == change_val) {
    var set_display = display_val;
  } else {
    var set_display = (display_val == 'block') ? 'none' : 'block';
  }
  document.getElementById(change_id).style.display=set_display;

  return false;
}


/********************************************************** 
*
*	SearchField - written by Alen Grakalic, edited 6-1-09 TCO
*	
************************************************************/

this.searchfield = function(){
	
	// CONFIG 
	
	// this is id of the search field you want to add this script to. 
	// You can use your own id just make sure that it matches the search field in your html file.
	var id = "keyword";
	
	// Text you want to set as a default value of your search field.
	var defaultText = "";	
	
	// set to either true or false
	// when set to true it will generate search suggestions list for search field based on content of variable below
	var suggestion = true;
	
	// static list of suggestion options, separated by comma	
	var suggestionText = "All Occasion Basket,All Occasion Gift Tower,Amaretto Rainiers,Berry & Almond Mix,Berry & Nut Mix Classic Tin,Berry & Pecan Mix,Berry & Pistachio Mix,Berry Medley Mix,Bing Chocolate Cherries,Black Cherry Cocoa Mix,Black Forest Brownie Mix,Black Forest Cackles 3 Pack of Treats,Black Forest Cherries,Blueberry Cherry Preserve & Topping,Bountiful Chocolate Cherry Basket,Bountiful Northwest Basket,Breakfast & Brunch Basket,Bridge Mix,Cabernet Cherries,Cackle Crunch Basket,Cherry & Almond Mix,Cherry & Pistachio Classic Tin,Cherry & Pistachio Mix,Cherry Almond Caramel Corn,Cherry Amaretto Preserve & Topping,Cherry Apple Slices,Cherry Blossom Tea,Cherry Blossoms,Cherry Blueberry Pie & Cobbler Filling,Cherry Brandy Dessert Sauce,Cherry Chipotle BBQ Sauce,Cherry Chocolate Nut Mix,Cherry Jubilee Dessert Sauce,Cherry Medley Mix,Cherry Pancake & Waffle Mix,Cherry Peach Pie & Cobbler Filling,Cherry Pecan Caramel Corn,Chipotle Chocolate Cherries,Chocolate Blueberries,Chocolate Bridge Mix Classic Tin,Chocolate Cherry & Nut Assortment,Chocolate Cherry Assortment 2 Pack,Chocolate Cherry Assortment box,Chocolate Cherry Blossom,Chocolate Cherry Crunch Tower,Chocolate Cherry Dessert Sauce,Chocolate Cherry Favorites Basket,Chocolate Cherry Quartet,Chocolate Cherry Quartet Classic Tin,Chocolate Cherry Trio Red Tin,Chocolate Honey Pecans,Chocolate Macadamia Nut,Chocolate Nut Assortment 2 Pack,Chocolate Nut Assortment box,Choice Cherry Classic Tin,Choice Cherry Basket,Chukar Best Logo Box,Chukar Cap,Chukar Cherries Bowl,Chukar Gift Card,Chukar Logo Cloth Bag,Chukar Mug,Chukar Northwest Logo Box,Chukar's Finest Basket,Cinnamon Dulce Espresso Beans,Cocoa Pecans,Columbia River Strawberry,Columbia River Tart Cherries,Cream Scone Mix,Create Your Own Trio,Crunch Munch Basket,Curried Cherry Chutney,Dark Chocolate Assortment box,Dark Chocolate Cherries,Dark Chocolate Cherries,Favor & Wedding Boxes,Fruitful Treasures Basket,Good Taste Tin Tower,Grand Gift Tower,Have a Cherry Holiday Basket,Heart of Seattle Basket,Holiday Favorites Red Tin,Holiday Hug Basket	,Marry Cherries,Milk and Dark Chocolate Assortment box,Milk Chocolate Cherries,Milk Chocolate Honey Pecans,Mocha Cherries,Mocha Latte Espresso Beans,Nature's Own Basket,North Cove Cranberry,Northwest Bing Cherries,Northwest Rainier Cherries,Nuts over Bings Mix,Organic Rainier Cherries,Original Assortment Box,Peach Cherry Salsa,Pike Market Christmas Basket,Pike Market Goodies Basket,Pike Market Hits Trio Gift,Pike Market Salute Basket,Pike Market Souvenir 3 Pack,Pike Place Market Logo Box,Pinot Noir Cherries,Puget Sound Blueberry,Raspberry Cherry Preserve & Topping,Raspberry Truffles,Red Sour Cherry Preserve & Topping,Signature Tin Cherries & Pecans,Signature Tin Chocolate Cherries,Signature Tin Chukar Mix,Signature Tin Energy Favorites,Signature Tin Truffles & Cherries,Sour Cherry Pie & Cobbler Filling,Spiced Hazelnut,Sweet Festivities Basket,The Sumptuous Assortment box,Top Notch Basket,Totally Tart Cherries, no sugar added,Treats A Plenty Hostess Gift,Triple Cherry Nut Classic Tin,Triple Cherry Nut Mix,Triple Cherry Pie & Cobbler Filling,Truffle Cherries,Vanilla Almonds,Vanilla Peach Preserve & Topping,Vanilla Peach Preserve & Topping,Variety Snack Packs,White Chocolate Berry Truffle,White Chocolate Blueberry,Winter Cheers Basket,Wood Cherry Cluster"; 
	
	// END CONFIG 

	var field = document.getElementById(id);	
	var classInactive = "sf_inactive";
	var classActive = "sf_active";
	var classText = "sf_text";
	var classSuggestion = "sf_suggestion";
	//this.safari = ((parseInt(navigator.productSub)>=20020000)&&(navigator.vendor.indexOf("Apple Computer")!=-1));
	if(field){      //&& !safari){
		field.value = defaultText;
		field.c = field.className;		
		field.className = field.c + " " + classInactive;
		field.onfocus = function(){
			this.className = this.c + " "  + classActive;
			this.value = (this.value == "" || this.value == defaultText) ?  "" : this.value;
		};
		field.onblur = function(){
			this.className = (this.value != "" && this.value != defaultText) ? this.c + " " +  classText : this.c + " " +  classInactive;
			this.value = (this.value != "" && this.value != defaultText) ?  this.value : defaultText;
			clearList();
		};
		if (suggestion){
			
			var selectedIndex = 0;
						
			field.setAttribute("autocomplete", "off");
			var div = document.createElement("div");
			var list = document.createElement("ul");
			list.style.display = "none";
			div.className = classSuggestion;
			list.style.width = field.offsetWidth + "px";
			div.appendChild(list);
			field.parentNode.appendChild(div);	

			field.onkeypress = function(e){
				
				var key = getKeyCode(e);
		
				if(key == 13){ // enter
					selectList();
					selectedIndex = 0;
					return false;
				};	
			};
				
			field.onkeyup = function(e){
			
				var key = getKeyCode(e);
		
				switch(key){
				case 13:
					return false;
					break;			
				case 27:  // esc
					field.value = "";
					selectedIndex = 0;
					clearList();
					break;				
				case 38: // up
					navList("up");
					break;
				case 40: // down
					navList("down");		
					break;
				default:
					startList();			
					break;
				};
			};
			
			this.startList = function(){
				var arr = getListItems(field.value);
				if(field.value.length > 0){
					createList(arr);
				} else {
					clearList();
				};	
			};
			
			this.getListItems = function(value){
				var arr = new Array();
				var src = suggestionText;
				var src = src.replace(/, /g, ",");
				var arrSrc = src.split(",");
				for(i=0;i<arrSrc.length;i++){
					if(arrSrc[i].substring(0,value.length).toLowerCase() == value.toLowerCase()){
						arr.push(arrSrc[i]);
					};
				};				
				return arr;
			};
			
			this.createList = function(arr){				
				resetList();			
				if(arr.length > 0) {
					for(i=0;i<arr.length;i++){				
						li = document.createElement("li");
						a = document.createElement("a");
						a.href = "javascript:void(0);";
						a.i = i+1;
						a.innerHTML = arr[i];
						li.i = i+1;
						li.onmouseover = function(){
							navListItem(this.i);
						};
						a.onmousedown = function(){
							selectedIndex = this.i;
							selectList(this.i);		
							return false;
						};					
						li.appendChild(a);
						list.setAttribute("tabindex", "-1");
						list.appendChild(li);	
					};	
					list.style.display = "block";				
				} else {
					clearList();
				};
			};	
			
			this.resetList = function(){
				var li = list.getElementsByTagName("li");
				var len = li.length;
				for(var i=0;i<len;i++){
					list.removeChild(li[0]);
				};
			};
			
			this.navList = function(dir){			
				selectedIndex += (dir == "down") ? 1 : -1;
				li = list.getElementsByTagName("li");
				if (selectedIndex < 1) selectedIndex =  li.length;
				if (selectedIndex > li.length) selectedIndex =  1;
				navListItem(selectedIndex);
			};
			
			this.navListItem = function(index){	
				selectedIndex = index;
				li = list.getElementsByTagName("li");
				for(var i=0;i<li.length;i++){
					li[i].className = (i==(selectedIndex-1)) ? "selected" : "";
				};
			};
			
			this.selectList = function(){
				li = list.getElementsByTagName("li");	
				a = li[selectedIndex-1].getElementsByTagName("a")[0];
				field.value = a.innerHTML;
				clearList();
			};			
			
		};
	};
	
	this.clearList = function(){
		if(list){
			list.style.display = "none";
			selectedIndex = 0;
		};
	};		
	this.getKeyCode = function(e){
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		return code;
	};
	
};

// script initiates on page load. 

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",searchfield);
/********************************************************** 
* END SearchField 
************************************************************/


function cartChange(id,num,qty,total,name) {

 // Cart Change v1.4:
 // id = an id to represent the price and qty (so we know what qty box and price to update).
 // num = the original cost of the item(s) (if there were 3x a 10-dollar item, num would = 30.00).
 // qty = the original quantity that existed in the cart before modification
 // total = the original total of the cart items before modification.
 // 
 // --[ Revisions ]--
 // 20050620 - Original Script Creation ~Michael@ColorMaria
 // 20050629 - Added a line to change the color of the update cart message ~Michael@ColorMaria
 // 20050705 - Added code (accompanied by cookies) to check the quantities of items in the cart
 //          - to see whether they match what the user entered for better checking to see if 
 //          - the update cart button needs to be pressed.
 //          - 
 //          - Please note: This update requires the cookie functions above the priceChange
 //          - function. ~Michael@ColorMaria
 // 20050722 - Added error handling for NaN errors.
 // 20051215 - Fixed a bug with commas
 ///////////////////////////////////////////////////////////////////////////////////////////////
 // Setup our Variables:
  var num2 = 0;
  var qty2 = document.getElementById('qty_' + id).value;
  if(isNaN(qty2)) { // If qty2 isNaN that means someone's made a typo and hit a letter or other non-number key
    document.getElementById('qty_' + id).value = '';
    qty2 = '';
  }
  var num3 = document.getElementById('price_' + id).value.split("$");
  var num3 = num3[1].replace(',','');
  // Check to see if we're dividing by 0:
  if(qty != '0' || !qty) {
    // If not, get the real price (rPrice):
    var rPrice = num.replace(',','') / qty;
  } else {
    // If we are, set the total price for that item to 0:
    document.getElementById('price_' + id).value = '$0.00';
  }
  // Setup our new prices:
  num2 = (rPrice * qty2);
  document.getElementById('price_' + id).value = '$' + num2.toFixed(2);
  // We gotta do this differently depending on if the total we're modifying 
  // is the REAL total or if it's one that was previously modified.
  if(total == document.getElementById('total').value) {
    // If we are modifying the current REAL total, do it this way:
    // Figure out what total would be if the item we're modifying didn't exist.
    total = total - num3;
    // Add the new value to the total:
    total = total + num2;
    document.getElementById('total').value = '$' + total.toFixed(2);
  } else {
    // Setup our fake_total variable so we can essentially do the same 
    // thing we did with the real total
    var fake_total = document.getElementById('total').value.split("$");
    fake_total = fake_total[1].replace(',','');
    // Figure out what the total would be without this product.
    total = fake_total - num3;
    // Readd the new value to the total.
    total = total + num2;
    document.getElementById('total').value = '$' + total.toFixed(2);
  }
  // Just in case they think this will automagically update the real prices for them,
  // setup a fail safe the function below will read and evaluate:
  var nQty = getCookie(name);
  arQty = nQty.split('|');
  // Note: the last element of the array will be empty, so ignore it.
  cntQty = arQty.length - 1;
  for(i=0;i<cntQty;i++) {
    arID = arQty[i].split(','); // Hoo Hoo (owl)
    if(document.getElementById('qty_'+arID[0]).value == arID[1]) {
      // It equals the default quantity, yay! No need to update cart.
      document.getElementById('hasUpdated').value = '1';
      // Change the color of the update cart message.
      document.getElementById('update_msg').style.color = '#000';
      continue;
    } else {
      // It doesn't, they need to update.  No need to check further since if one hasn't been updated
      // the whole cart needs to be updated.
      document.getElementById('hasUpdated').value = '0';
      // Change the color of the update cart message so it stands out after a change to the qty is made.
      document.getElementById('update_msg').style.color = '#F00';
      // Break the loop.
      break;
    }
  }
}

function updateRecipient(pid) {
  document.getElementById('recipient_mapping'+pid).value = document.getElementById('recipient_mapping').value;
  document.getElementById('new_recipient_mapping'+pid).value = document.getElementById('new_recipient_mapping').value;
}