$('head').append('<style>.js-nohaz{display:none}</style>')

$(document).ready(function(){

	$('.js-haz').show();
	
	$('a.thickbox').click(function(){
		$('.promo-wrap').remove();
	});
					
	// when one of the gift option select menus change
	$('select.giftOption').live('change', function(){
		
		// get the form name that this select menu belongs to
		formName = $(this).parent().attr('name');

		// get the value of the index -- Using this because when the options are loaded into the div, we need them to have the correct name to go along with the product id (e.g. PRODUCT_OPTION_ID#ThisRow#)
		var ThisRow = $('form[name='+formName+'] input[name=ThisRow]').val();
								
		// get the product ID that was selected
		var productID = $(this).val();
																										
		// empty the div
		$('form[name='+formName+'] div.optionDiv').empty();
				
		// if there is a product ID to work with
		if( productID > 0 ){
			
			// show the message div
			$('form[name='+formName+'] div.messageDiv').show();
			
			// get the product options
			$.ajax({
			   type: 'GET',
			   url: '/cart/action/api.cfm',
			   cache: false,
			   data: 'method=displayProductOptions&product_id='+productID+'&ThisRow='+ThisRow+'',
			   success: function(data){
					$('form[name='+formName+'] div.optionDiv').empty().append(data);
					$('#TB_closeWindowButton').focus();
			   }
			 });						
									
		}
		else{
			// hide the message div
			$('form[name='+formName+'] div.messageDiv').hide();
		};
		
	});
	
	$('form[name=giftOptionForm]').live('submit', function(){
							
		giftFormData = $(this).serialize();
		
		$('form.giftOptionForm').each(function(){
			giftFormData = giftFormData + '&' + $(this).serialize();
		});
				
		$('#resultData').empty(giftFormData);
		
		/* get the product options */
		$.ajax({
		   type: 'POST',
		   url: '/cart/action/api.cfm',
		   cache: false,
		   data: giftFormData,
		   success: function(data){
			 $('#resultData').append(data);
			 window.location = "/cart/index.cfm?message=Gift options were successfully updated";
			 }
		 });
		 
		 return false;
	
	});	
									
});
