
//----PRESET CHECKBOXES-----//

//On seed depot page load, set all checkboxes to unchecked and all item quantities
//to zero.

jQuery(document).ready(function(){
        jQuery('#seedForm input:checkbox:checked').removeAttr("checked");
	jQuery('#seedForm input[name$=quantity]').val(0);
});


//-----SET ALL CHECKBOXES-----////this script is run as an onclick event for a checkbox to set all//checkboxes in form "FormName" whose names are "FieldName" to //the value "CheckValue". Usually CheckValue is set to 'this.value'function SetAllCheckboxes(FormName, FieldName, clickState) {        if(!document.forms[FormName])		return;	var objCheckBoxes = document.forms[FormName].elements[FieldName];	if(!objCheckBoxes)		return;	var countCheckBoxes = objCheckBoxes.length;	if(!countCheckBoxes)		objCheckBoxes.checked = clickState;	else	   for(var i = 0; i < objCheckBoxes.length; i++) if (objCheckBoxes[i].checked != clickState)objCheckBoxes[i].click();}

//-----CHECKBOX UPDATES SIBLING QUANTITY-----//

//this jquery script applies an onclick event to all checkboxes on page
//which sets the quantity to one of checkbox is checked and 0 if not

jQuery(document).ready(function(){

jQuery('input[@type=checkbox]').change(function(){

if (jQuery(this).is(':checked')) {
	jQuery(this).siblings('input[name$=quantity]').val(1);} 

else{
	jQuery(this).siblings('input[name$=quantity]').val(0);}

});});

//-----PREPROCESS SEED FORM-----//
//ensures that something has been selected before//posting to the cart. If you send no items to the cart, you get an errorfunction fc_PreProcess() {
	if (jQuery("div#seedTable").length > 0 ) {   
		//check for seed table and only operate on seed table		if (jQuery('#seedTable input[@type=checkbox]:checked').length > 0) {
		return true; 
	} 	else {	
		alert('You have no seeds selected, so nothing was added to your cart.');
		return false;  }	}}

//----Post big form ajax-style----//

//this script, along with an iframe on the page, allows us to 
//get around the 2K url limit of the get method used by FoxyCart
//to post the form.
jQuery(document).ready(function(){

	// Fix the form action for users with 3rd party cookies disabled

	action = jQuery('form.foxycart_json').attr('action') + '?' + fc_AddSession();
	jQuery('form.foxycart_json').attr('action', action);
	// Fake a callback onload	
	jQuery('#cart_iframe').load(function(){
		fc_UpdateCart(FoxyDomain);
		jQuery('a#fcCaller').click();  
		jQuery("#loading-gif").hide();
	});
});

//need to bind an event to the submit button to first run the fc_PreProcess()
//subroutine, and then to it's prescribed action.

jQuery(document).ready(function(){
	
	jQuery('#seedSubmit').click(function(event) {
		event.preventDefault();	//prevent submit button from doing anything
		
		if (fc_PreProcess() != false)	{		//run fc_PreProcess function
			jQuery('#seedForm').trigger("submit");	//trigger submit only if PreProcess checks out

		//SHOW LOADING GIF NEXT TO SUBMIT BUTTON
		//get the position of the submit buttom
	 		 var pos = jQuery(this).offset();  
 			 var width = jQuery(this).width();
  		//show the loader gif directly over the placeholder
	  		jQuery("#loading-gif").css( { "left": (pos.left + width + 30) + "px", "top": (pos.top - 3) + "px" });
  			jQuery("#loading-gif").show();
		}	//close if

	}); 	//close click function

}); //close ready function

