Event.observe(window, "load", init);

//function to initalize on page load
function init()
{
	//copy pages to bottom if they exist
	try{
		var pages = $("bread-crumbs").down(".right").innerHTML;
		var found = pages.indexOf("pagination");

		if(found > 0)
		{
			var lower = '<span class="right">' + pages + '</span>';

			$("marketing").next(".strip").down(".strip").innerHTML = lower;
		}
	}catch(e){}
	
}//end function init

// holds the original image so mouse-out
// goes back to original
var originalImg;

// gets the details from the img and link attributes,
// and shows the description/image on hover
function showDetails(link) {
	img = link.down();
	originalImg = $('prod-image').down().down().src;
	$('prod-image').down().down().src = img.src;
	if(link.title != "")
	{
		$('description').update("<span>Description</span>" + link.title);
		$('description').show();
	}

}

// hides the img on mouse out
// (add functionality here to restore original img, if needed)
function resetDetails(link) {
	$('description').hide();
	$('prod-image').down().down().src = originalImg;
}


/**
 * this function can be applied to a text field so that it
 * will only let the user type numbers, canceling the event
 * on any other key entries.  
 * syntax: onKeyPress="return onlyNumbers(event);"
 */
function onlyNumbers(e)
{
	var keynum;
	var keychar;
	var numcheck;
	
	
	
	if(window.event) //IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) //Netscape/Firefox/Opers
	{
		keynum = e.which;
	}
	
	keychar = String.fromCharCode(keynum);
	//numcheck = /\d/;
	//return numcheck.test(keychar);
	

	if(keynum >= 48 && keynum <= 57)
	{
		return true;
	}
	else
	{
		e.returnValue = false;
		return false;
	}
	
}//end function onlyNumbers




var requiredItems = [];
var requiredDesc = [];

/**
 * function to put required items into
 * the two global arrays above
 */
function addRequired(item_id, desc)
{
	requiredItems.push(item_id);
	requiredDesc.push(desc);
}


/**
 * function to validate any pao product selections
 * then add to cart
 */
function validateAndAdd()
{
	var pass = true;
	
	for(var i=0; i < requiredItems.length; i++)
	{
		try{
		
			if(document.getElementById(requiredItems[i]).value == "")
			{
				pass = false;
				alert('Please select a ' + requiredDesc[i] + ' to continue');
			}
		
		}catch(e){}
		
	}//end for
	
	if(pass == true)
	{
		addToCart(0);
	}
	
}//end function validateAndAdd



/**
 * function to validate any pao product selections
 * then submit the form
 */
function validateAndSubmit(btn)
{
	var pass = true;

	for(var i=0; i < requiredItems.length; i++)
	{
		try{
		
			if(document.getElementById(requiredItems[i]).value == "")
			{
				pass = false;
				alert('Please select a ' + requiredDesc[i] + ' to continue');
			}
		
		}catch(e){}
		
	}//end for
	
	
	//submit the form if all is good
	if(pass == true)
	{
		if(btn.id == "cart_item_add")
		{
			document.getElementById("cart_item_submit_type").value = "normal";
			btn.form.submit();
		}
		else if(btn.id == "cart_item_regsitry")
		{
			document.getElementById("cart_item_submit_type").value = "registry";
			btn.form.submit();
		}
		else if(btn.id == "cart_item_wish")
		{
			document.getElementById("cart_item_submit_type").value = "wish";
			btn.form.submit();
		}
		else
		{
			btn.form.submit();
		}
	}
	
}//end function validateAndAdd


//var to note if processing is running
var processingZipcode = false;

/**
 * function to process the entry of a zip code
 * used to estimate the shipping of an order
 */
function processEstZip()
{
	var zip = $('shipping_est_zip').value;
	var subtotal = $('_subtotal').innerHTML;
	
	if (zip.length == 5)
	{
		if (!isNaN(zip))
		{
			if(processingZipcode == false)
			{
			
				//log that we are processing
				processingZipcode = true;
			
				Effect.Appear("updating_cart", {duration: 1});
			
				var actionUrl = '/cart/apply_est_zip?zipcode=' + zip + '&subtotal=' + subtotal;

				new Ajax.Request(actionUrl,
				{
				  asynchronous:true,
            
				  onFailure: function(){ 
            
				    alert("ERROR: There was an error calculating shipping\nwith the zip code you provided"); 
	            	Effect.Fade("updating_cart", {duration: 1});
					//log that we are no longer processing
					processingZipcode = false;

				  }//end onFailure function of Ajax.Request
            
				});//end Ajax.Request
			
			}//end if processingZipcode
			
		}//end isNaN
	
	}//end length check
	
}//end function processEstZip





/**
 * function to validate the mini-window before a submit
 * from the mini-window for a remote-add to cart
 */
function validateRemoteAdd(product_id, product_variation_id, submitBtn, token)
{
	var proceed = true;
	var pv_id = $F(product_variation_id);
	var actionUrl = '/cart/check_options/' + pv_id;
	
	if(pv_id == "")
	{
		alert("Please select the item to add");
		return;
	}
	
	if(token != "")
	{
		actionUrl += "?token=" + token;
	}

	new Ajax.Request(actionUrl,
	{
	  asynchronous:true,
	
	  onSuccess: function(t){
		
		var ids = []; //array to hold js ids of required elements 
		var des = []; //array to hold descriptions of the same required elements
		
		var po_ids = []; //array to hold JS ids of option elements
		var co_ids = []; //array to hold JS ids of custom option elements
		
		var result = t.responseText.split("!@!")
		var pao_text = result[0];
		var po_text = result[1];
		var pco_text = result[2];
		
		//handle any products as options
		if(pao_text != "")
		{
        
			var options = pao_text.split("|");
	    
			for(var i=0; i < options.length; i++)
			{
				ids.push(options[i].split("~")[0]);
				des.push(options[i].split("~")[1]);
			}
	    
			//require paov's
			// for(var j=0; j < ids.length; j++)
			// {
			// 	if($(ids[j]).value == "")
			// 	{
			// 		proceed = false;
			// 		alert('Please select a ' + des[j] + ' to continue.');
			// 	}
		    // 
			// }
	    
		}//end if pao_text != ""
		
		
		//handle any product options
		if(po_text != "")
		{
			var po_options = po_text.split("|");
			
			for(var i=0; i < po_options.length; i++)
			{
				if($(po_options[i]).value != "")
				{
					po_ids.push(po_options[i]);
				}
			}
			
		}//end if po_text != ""
		
		
		//handle any custom options
		if(pco_text != "")
		{
			var pco_options = pco_text.split("|");
			
			for(var i=0; i < pco_options.length; i++)
			{
				var pco_option = pco_options[i].split("~")[0];
				var pco_value = pco_options[i].split("~")[1];
				if($(pco_value).value != "")
				{
					co_ids.push(pco_options[i]);
				}
			}
			
		}//end if pco_text != ""
		
		
		//submitBtn.form.submit();
		remoteAddToCart(product_id, pv_id, $('cart_item_quantity').value, ids, po_ids, co_ids);

		
	  },//end on Success function
    
	  onFailure: function(){ 
    
	  	alert('Error validating product to add');
	
	  }//end onFailure function of Ajax.Request
    
	});//end Ajax.Request
	
}//end function



/**
 * function to be called from validateRemoteAdd.  That function is used to add a product
 * to the cart from the grid display of products using the light window.  This function takes
 * the outputs and creates a request to add them.
 *
 * @param Integer id - the ID of the product getting added to the cart
 * @param Integer pv_id - the ID of the variation of product being added
 * @param Integer qty - the quantity of the product to add to the cart
 * @param Array values - an array of JS ids that are PAOVs which we will pass in to add as well
 * @param Array options - an array of JS ids that are POVs which we will pass in to add as well
 * @param Array custom_options - an array JS ids that are custom option values
 *
 */
function remoteAddToCart(id, pv_id, qty, values, options, custom_options)
{

	var requestUrl = '/cart/remote_add/' 	+ id + '?';
	requestUrl += 'cart_item[product_variation_id]=' + pv_id;
	requestUrl += '&cart_item[quantity]=' 	+ qty;
	requestUrl += '&cart_item[product_id]=' + id;
	

	//add the PAOVs to the request string
	for(var i=0; i < values.length; i++)
	{
		requestUrl += '&' + $(values[i]).name + '=' + $(values[i]).value;
		
	}//end for
	
	//add the POVs to the request string
	for(var i=0; i < options.length; i++)
	{
		requestUrl += '&' + $(options[i]).name + '=' + $(options[i]).value;
		
	}//end for
	
	//add the COVs to the request string
	for(var i=0; i < custom_options.length; i++)
	{
		var name  = custom_options[i].split("~")[0];
		var value = custom_options[i].split("~")[1];
		
		requestUrl += '&' + $(name).name + '=' + $(name).value;
		requestUrl += '&' + $(value).name + '=' + $(value).value;
		
	}//end for
	

	new Ajax.Request(requestUrl,
	{
	  asynchronous:true,
	
	  onSuccess: function(t){

		//t.responseText
		
	  },//end on Success function
    
	  onFailure: function(){ 
    
	  	alert('Error adding product to cart');
	
	  }//end onFailure function of Ajax.Request
    
	});//end Ajax.Request
	
}//end function remoteAddToCart


/**
 * generic function to make a ajax call
 */
function ajaxCall(url)
{
	new Ajax.Request(url,
	{
	  asynchronous:true,
	  onFailure: function(){ 
	  	alert('Error calling ajax URL');
	  }//end onFailure function of Ajax.Request
    
	});//end Ajax.Request
	
}//end function ajaxCall


/**
 * function used to show the coupon form at checkout
 */
function useCoupon()
{
	Effect.Fade('cf_1', {duration: 0.75});
	new Effect.Morph('c_area', {style: 'height: 70px;', duration: 0.50, delay: 0.70})
	Effect.Appear('cf_2', {duration: 0.75, delay: 1.25});
}//end useCoupon



/** 
 * function used to show the gift card form at checkout
 */
function useGiftcard()
{
	Effect.Fade('gc_1', {duration: 0.75});
	new Effect.Morph('gc_area', {style: 'height: 80px;', duration: 0.50, delay: 0.70})
	Effect.Appear('gc_2', {duration: 0.75, delay: 1.25});
}//end useGiftcard



/**
 * function to expose the correct shipping
 * address form in the checkout process
 */
function exposeShippingForm(checkbox)
{
	var SAME = 1;
	var DIFF = 2;
	var DORM = 3;
	
	if(Number(checkbox.value) == SAME)
	{
		//if($('shipping_form').style.display != 'none') Effect.SlideUp('shipping_form', {duration: 0.5});
		//if($('dorm_shipping_form').style.display != 'none') Effect.SlideUp('dorm_shipping_form', {duration: 0.5});
		if($('shipping_form').style.display != 'none') $('shipping_form').style.display = 'none';
		if($('dorm_shipping_form').style.display != 'none') $('dorm_shipping_form').style.display = 'none';
	}		
	
	else if(Number(checkbox.value) == DIFF)
	{		
		//if($('shipping_form').style.display == 'none') Effect.SlideDown('shipping_form', {duration: 0.5});
		//if($('dorm_shipping_form').style.display != 'none') Effect.SlideUp('dorm_shipping_form', {duration: 0.5});
		if($('shipping_form').style.display == 'none') $('shipping_form').style.display = 'block';
		if($('dorm_shipping_form').style.display != 'none') $('dorm_shipping_form').style.display = 'none';
	}
	
	else if(Number(checkbox.value) == DORM)
	{
		//if($('shipping_form').style.display != 'none') Effect.SlideUp('shipping_form', {duration: 0.5});
		//if($('dorm_shipping_form').style.display == 'none') Effect.SlideDown('dorm_shipping_form', {duration: 0.5});
		if($('shipping_form').style.display != 'none') $('shipping_form').style.display = 'none';
		if($('dorm_shipping_form').style.display == 'none') $('dorm_shipping_form').style.display = 'block';
	}		
	
}//end function exposeShippingForm



var val_pmnt = true; //var to tell if we want to val payment

/**
 * function to validate the billing & shipping form before submit
 */
function validateOrderForm(submitBtn)
{
	//array of form errors
	var errors = [];
	
	//How heard values that require extra info
	var how_heard_vals = new Array();
	how_heard_vals.push(3);	//HIGHSCHOOL
	how_heard_vals.push(4);	//COLLEGE
	how_heard_vals.push(5);	//NEWSPAPPER
	how_heard_vals.push(6);	//OTHERWEBSITE
	how_heard_vals.push(7);	//TVRADIOMAGAZINE
	how_heard_vals.push(8);	//OTHER
	

	
	//check that the cart has some items
	if(Number($('cart_items_count').value) <= 0)
	{
		errors.push("Cart must have at least one item");
	}


	//### VALIDATE BILLING FORM ###
	//validate billing first name
	if($('billing_profile_first_name').value == "")
	{
		errors.push("Billing First Name field is required");
	}
	
	//validate billing last name
	if($('billing_profile_last_name').value == "")
	{
		errors.push("Billing Last Name field is required");
	}
	
	//validate billing address
	if($('billing_profile_address').value == "")
	{
		errors.push("Billing Address field is required");
	}
	
	//validate billing city
	if($('billing_profile_city').value == "")
	{
		errors.push("Billing City field is required");
	}
	
	//validate billing state
	if($('billing_profile_state_id').value == "")
	{
		errors.push("Billing State field is required");
	}
	
	//validate billing zipcode
	if($('billing_profile_zipcode').value == "")
	{
		errors.push("Billing Zip Code field is required");
	}
	
	//validate billing phone
	if($('billing_profile_phone').value == "")
	{
		errors.push("Billing Phone field is required");
	}
	
	//validate billing phone format
	if($('billing_profile_phone').value != "")
	{
		if($('billing_profile_phone').value.length < 10 || $('billing_profile_phone').value.length > 16)
		{
			errors.push("Billing Phone must be between 10 and 16 characters");
		}
	}
	
	
	//validate the billing email
	if($('order_email').value == "")
	{
		errors.push("Billing Email field is required");
	}
	
	//validates_format_of :email
	if ( $('order_email').value != "")
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var eml = $('order_email').value;
		if( reg.test(eml) == false)
		{
			errors.push("Billing Email is invalid format");
		}
	}
	
	//validate billing country
	if($('billing_profile_country_id').value == "")
	{
		errors.push("Billing Country field is required");
	}

	
	
	
	
	//###[VALIDATE THE SHIPPING FORM]###
	//we validate the shipping form in the situations where the bill & ship are different & thats it
	if($('profile_type_2').checked)
	{
		
		//validate shipping first name
		if($('shipping_profile_first_name').value == "")
		{
			errors.push("Shipping First Name field is required");
		}
		
		//validate shipping last name
		if($('shipping_profile_last_name').value == "")
		{
			errors.push("Shipping Last Name field is required");
		}
		
		//validate shipping address
		if($('shipping_profile_address').value == "")
		{
			errors.push("Shipping Address field is required");
		}
		
		//validate shipping city
		if($('shipping_profile_city').value == "")
		{
			errors.push("Shipping City field is required");
		}
		
		//validate shipping state
		if($('shipping_profile_state_id').value == "")
		{
			errors.push("Shipping State field is required");
		}
		
		//validate shipping zipcode
		if($('shipping_profile_zipcode').value == "")
		{
			errors.push("Shipping Zip Code field is required");
		}
		
		//validate shipping country
		if($('shipping_profile_country_id').value == "")
		{
			errors.push("Shipping Country field is required");
		}
		
		//validate shipping phone
		if($('shipping_profile_phone').value == "")
		{
			errors.push("Shipping Phone field is required");
		}
		
		
	}//end shipping_form validation
	
	
	
	//###[VALIDATE DORM SHIPPING FORM]###
	//we only validate the dormshipping form when dorm shipping
	if($('profile_type_3').checked)
	{
		
		//validate dorm shipping first name
		if($('dorm_shipping_profile_first_name').value == "")
		{
			errors.push("Dorm Shipping First Name field is required");
		}
		
		//validate dorm shipping last name
		if($('dorm_shipping_profile_last_name').value == "")
		{
			errors.push("Dorm Shipping Last Name field is required");
		}
		
		//validate dorm shipping address
		if($('dorm_shipping_profile_address').value == "")
		{
			errors.push("Dorm Shipping Address field is required");
		}
		
		//validate dorm shipping city
		if($('dorm_shipping_profile_city').value == "")
		{
			errors.push("Dorm Shipping City field is required");
		}
		
		//validate dorm shipping state
		if($('dorm_shipping_profile_state_id').value == "")
		{
			errors.push("Dorm Shipping State field is required");
		}
		
		//validate dorm shipping zipcode
		if($('dorm_shipping_profile_zipcode').value == "")
		{
			errors.push("Dorm Shipping Zip Code field is required");
		}
		
		//validate dorm shipping country
		if($('dorm_shipping_profile_country_id').value == "")
		{
			errors.push("Dorm Shipping Country field is required");
		}
		
		//validate dorm shipping phone
		if($('dorm_shipping_profile_phone').value == "")
		{
			errors.push("Dorm Shipping Phone field is required");
		}
		
		//validate dorm shipping time
		if($('order_dorm_ship_time_id').value == "")
		{
			errors.push("Dorm Shipping Time is required");
		}
		
	}//end dorm_shipping_form validation
	


	if(val_pmnt == true)
	{

		//validate the payment information
		if($('order_payment_provider_id_1').checked)
		{
			//validate name on card
			if($('creditcard_name_on_card').value == "")
			{
				errors.push("Payment Information - Name on card field is required");
			}
		
			//validate card number
			if($('creditcard_card_number').value == "")
			{
				errors.push("Payment Information - Card number is required");
			}
			else
			{
				if($('creditcard_card_number').value.length != 16)
				{
					errors.push("Payment Information - Card number is invalid");
				}
			
				if(isNaN(Number($('creditcard_card_number').value)))
				{
					errors.push("Payment Information - Card number must be numeric")
				}
			}
		
			//validate expiration date
			if($('creditcard_expiration_date_2i').value == "" || $('creditcard_expiration_date_1i').value == "")
			{
				errors.push("Payment Information - Expiration Date is invalid");
			}
		
			//validate card type
			if($('creditcard_card_type').value == "")
			{
				errors.push("Payment Information - Card Type is required");
			}
		
			//validate verification code
			if($('creditcard_vcode').value == "")
			{
				errors.push("Payment Information - Verification code is required");
			}
			else
			{
				if($('creditcard_vcode').value.length != 3)
				{
					errors.push("Payment Information - Verification code is invalid");
				}
			
				if(isNaN(Number($('creditcard_vcode').value)))
				{
					errors.push("Payment Information - Verification code must be numeric")
				}
			
			}
		
		
		}//end credit card validations
		
	}//end if we val pmnt
	
	
	
	//check how-did-you-hear-about-us ddl
	if($('order_how_heard_option_id').value == "")
	{
		errors.push("'How did you hear about us' is required");
	}
	

	//check how-did-you-hear-about-us value
	for(var i=0; i < how_heard_vals.length; i++)
	{
		if(Number($('order_how_heard_option_id').value) == how_heard_vals[i])
		{
			if($('order_how_heard_option_value').value == "")
			{
				errors.push("You must provide a descriptive option for how you heard about us");
				break;
			}
		}
	}
	
	
	
	
	//check the zipcode before moving forward
	var zip_to_check = "";
	if($('profile_type_1').checked)
	{
		zip_to_check = $('billing_profile_zipcode').value;
	}
	else if($('profile_type_2').checked)
	{
		zip_to_check = $('shipping_profile_zipcode').value;
	}
	else if($('profile_type_3').checked)
	{
		zip_to_check = $('dorm_shipping_profile_zipcode').value;
	}
	
	//now we have a zipcode to check lets do it
/*****************
	var check_zip_url = '/cart/validate_zip/' + zip_to_check;

	new Ajax.Request(check_zip_url,
	{
	  asynchronous: false,
	
	  onSuccess: function(t){

		if(t.responseText == "valid")
		{
			//zip was good, do nothing
		}
		else if(t.responseText == "invalid")
		{
			errors.push("The the zip code you provided could not be found");
		}

	  },//end on Success function
    
	  onFailure: function(){ 
    
	  	alert('Error validating zip code');
	
	  }//end onFailure function of Ajax.Request
    
	});//end Ajax.Request
****************/
	
	
	
	
	//compose the error message to the user
	var errorText = "Errors: \n\n";
	
	for(var i=0; i < errors.length; i++)
	{
		errorText += errors[i] + "\n";
	}
	
	
	//logic on return value
	if(errors.length > 0)
	{
		alert(errorText);
	}
	else
	{
		//disable the submit button that was passed with the form
		submitBtn.disabled = true;
		submitBtn.form.submit();
	}
	
	
}//end function validateOrderForm




/**
 * function used in the checkout order form for applying
 * a coupon to the order.  The js code validates the 
 * form fields required and formulates an AJAX call to 
 * apply the coupon
 */
function applyCoupon()
{
  if ($('coupon_code').value == "")
  {
    alert('You must provide a Coupon code');
    return;
  }
  
  
  var requestUrl = "?coupon_code=" + $('coupon_code').value;

  new Ajax.Request('/checkout/apply_coupon' + requestUrl,
  {
    asynchronous:true,
    
    onFailure: function(){ 
    
      alert('ERROR: There was an error applying the Coupon'); 
    
    }//end onFailure function of Ajax.Request
    
  });//end Ajax.Request
  

}//end function applyCoupon



/**
 * function used in the checkout order form for applying
 * a gift card to the order.  The js code validates the 
 * form fields required and formulates an AJAX call to 
 * apply the gift card
 */
function applyGiftCard()
{

  if ($('gift_card_number').value == "" || $('gift_card_pin').value == "")
  {
    alert('You must provide a Gift Card Number and its Pin');
    return;
  }
  
  
  var requestUrl = "?gift_card_number=" + $('gift_card_number').value + "&gift_card_pin=" + $('gift_card_pin').value;

  new Ajax.Request('/checkout/apply_gift_card' + requestUrl,
  {
    asynchronous:true,

    onFailure: function(){ 
    
      alert('ERROR: There was an error applying the Gift Card'); 
    
    }//end onFailure function of Ajax.Request
    
  });//end Ajax.Request
  

}//end function applyGiftCard


/**
 * function to validate the billing & shipping 
 * forms in the myAccount area
 */
function validateAddressInfo(submitBtn)
{
	//array of form errors
	var errors = [];
	
	//### VALIDATE BILLING FORM ###
	//validate billing first name
	if($('billing_profile_first_name').value == "")
	{
		errors.push("Billing First Name field is required");
	}
	
	//validate billing last name
	if($('billing_profile_last_name').value == "")
	{
		errors.push("Billing Last Name field is required");
	}
	
	//validate billing address
	if($('billing_profile_address').value == "")
	{
		errors.push("Billing Address field is required");
	}
	
	//validate billing city
	if($('billing_profile_city').value == "")
	{
		errors.push("Billing City field is required");
	}
	
	//validate billing state
	if($('billing_profile_state_id').value == "")
	{
		errors.push("Billing State field is required");
	}
	
	//validate billing zipcode
	if($('billing_profile_zipcode').value == "")
	{
		errors.push("Billing Zip Code field is required");
	}
	
	//validate billing phone
	if($('billing_profile_phone').value == "")
	{
		errors.push("Billing Phone field is required");
	}
	
	//validate billing country
	if($('billing_profile_country_id').value == "")
	{
		errors.push("Billing Country field is required");
	}

	
	
	
	
	//###[VALIDATE THE SHIPPING FORM]###
	//we validate the shipping form in the situations where the bill & ship are different & thats it
	if($('profile_type_2').checked)
	{
		
		//validate shipping first name
		if($('shipping_profile_first_name').value == "")
		{
			errors.push("Shipping First Name field is required");
		}
		
		//validate shipping last name
		if($('shipping_profile_last_name').value == "")
		{
			errors.push("Shipping Last Name field is required");
		}
		
		//validate shipping address
		if($('shipping_profile_address').value == "")
		{
			errors.push("Shipping Address field is required");
		}
		
		//validate shipping city
		if($('shipping_profile_city').value == "")
		{
			errors.push("Shipping City field is required");
		}
		
		//validate shipping state
		if($('shipping_profile_state_id').value == "")
		{
			errors.push("Shipping State field is required");
		}
		
		//validate shipping zipcode
		if($('shipping_profile_zipcode').value == "")
		{
			errors.push("Shipping Zip Code field is required");
		}
		
		//validate shipping country
		if($('shipping_profile_country_id').value == "")
		{
			errors.push("Shipping Country field is required");
		}
		
		//validate shipping phone
		if($('shipping_profile_phone').value == "")
		{
			errors.push("Shipping Phone field is required");
		}
		
		
	}//end shipping_form validation
	
	
	
	//###[VALIDATE DORM SHIPPING FORM]###
	//we only validate the dormshipping form when dorm shipping
	if($('profile_type_3').checked)
	{
		
		//validate dorm shipping first name
		if($('dorm_shipping_profile_first_name').value == "")
		{
			errors.push("Dorm Shipping First Name field is required");
		}
		
		//validate dorm shipping last name
		if($('dorm_shipping_profile_last_name').value == "")
		{
			errors.push("Dorm Shipping Last Name field is required");
		}
		
		//validate dorm shipping address
		if($('dorm_shipping_profile_address').value == "")
		{
			errors.push("Dorm Shipping Address field is required");
		}
		
		//validate dorm shipping city
		if($('dorm_shipping_profile_city').value == "")
		{
			errors.push("Dorm Shipping City field is required");
		}
		
		//validate dorm shipping state
		if($('dorm_shipping_profile_state_id').value == "")
		{
			errors.push("Dorm Shipping State field is required");
		}
		
		//validate dorm shipping zipcode
		if($('dorm_shipping_profile_zipcode').value == "")
		{
			errors.push("Dorm Shipping Zip Code field is required");
		}
		
		//validate dorm shipping country
		if($('dorm_shipping_profile_country_id').value == "")
		{
			errors.push("Dorm Shipping Country field is required");
		}
		
		//validate dorm shipping phone
		if($('dorm_shipping_profile_phone').value == "")
		{
			errors.push("Dorm Shipping Phone field is required");
		}
		
	}//end dorm_shipping_form validation
	
	

	
	//compose the error message to the user
	var errorText = "Errors: \n\n";
	
	for(var i=0; i < errors.length; i++)
	{
		errorText += errors[i] + "\n";
	}
	
	
	//logic on return value
	if(errors.length > 0)
	{
		alert(errorText);
	}
	else
	{
		//disable the submit button that was passed with the form
		submitBtn.disabled = true;
		submitBtn.form.submit();
	}
	
	
}//end function validateAddressInfo


//function used to determine wether to show howheard (other) box
function showHowHeard(ddl)
{
	var options = new Array();
	options.push(3);	//HIGHSCHOOL
	options.push(4);	//COLLEGE
	options.push(5);	//NEWSPAPPER
	options.push(6);	//OTHERWEBSITE
	options.push(7);	//TVRADIOMAGAZINE
	options.push(8);	//OTHER
	
	var found = false;
	
	for(var i=0; i < options.length; i++)
	{
		if(ddl.value == options[i])
		{
			$('hh_row').style.display = "";
			found = true;
			return
		}
	}
	
	//nothing matched
	$('hh_row').style.display = 'none';
	
}//end function showHowHeard


//function used to commit the final payment on the front-end checkout
function final_commit()
{
	$("commit_top").innerHTML = '<img src="/images/progress.gif" />';
	$("commit_bottom").innerHTML = '<img src="/images/progress.gif" />';
	var t = setTimeout("window.location.href = '/checkout/commit';", 1500);
	
}//end function final_commit