var $ = jQuery;


$(document).ready(function(){
		
	
	// set default credit card AND customer address
	jQuery( '#inner-content input[type=radio]:not( :checked )' ).change(function(){  app.submitForm( {triggeredObject: this, actionName: jQuery( this ).attr( 'value' ), actionValue : this.id } ); return false; });
	
	
	$('.delete-address').click( function() {
	
		var form = jQuery($(this)).parents('form:last');
		
		if ( form != null )
		{
		
			var url = form[0].action;
			var data = form.serialize();
			var thisaddress = $(this).attr('id');
			var delBtn = $(this).attr('name');
			data += "&" + delBtn + "=" + thisaddress;	
			
			$.post(url, data, function() { 
			
				var sURL = unescape(window.location.pathname);
				window.location.href = sURL;
				
			});
		
		}
	
	});
	
	$('button.print').unbind();
	$('button.print').click(function(e){
		//e.preventDefault();
		//e.stopPropagation();
		window.print();
		return false;
	});
	
	
	
	//Wishlist Email button
	$("#email-wishlist").focus(function () {
		
		
		var form = jQuery($(this)).parents('form:last');
		if ( form != null )
		{
		
			var url = form[0].action;
			var data = form.serialize();
			var thisaddress = $(this).attr('id');
			var wishlistBtn = $(this).attr('name');
			data += "&" + wishlistBtn + "=" + thisaddress;
			
			$.ajax({
		         type: "POST",
		         url: url,
		         data: data,
		         success: function(response)
		         {
		     		
		     		$().colorbox({
		     			width:550,
						html:response,
						onComplete:function(){ setWishlistFormJS();}
					});
		     		
		         }
		     });
		
		}
	
	});
	
	
	
});
