(function ($) {
    $(document).ready(function () {
		    $('#fitCode').focus(function () {
				    if($(this).val() == 'Enter Your Coupon to Redeem') $(this).val(''); 
				});
				$('#fitCode').click(function () {
				    if($(this).val() == 'Enter Your Coupon to Redeem') $(this).val(''); 
				});
				$('#fitUpdate').click(function () {
				    var op = $('#fitOriginalPrice').val();
						var dc = $('#fitCode').val();
						 var save=parseFloat($('#saved').val());
						
						
						if ($('#fitCode').val() == '' || $('#fitCode').val() == 'Enter Your Coupon to Redeem') {
						    $('#fitMsg').html('Please Enter Coupon Code');
								return false;
						}
						if ($('#fitCode').val()==$('#saleNumber').val()) {
						    $('#fitMsg').html('Coupon Code valid');
								return false;
						}
						
						
						
						$.ajax({
						    type: 'POST', 
								url: '../configs/ajax/fit.discount.ajax.php', 
								data: {'dc':dc, 'op':op}, 
								dataType: 'json', 
								error: function (a, b) {
								    alert(b);
								}, 
								beforeSend: function () {
								    $('#fitMsg').html('Please wait...');
								}, 
								success: function (data) {
										if (data['flag'] == 0) {
										    $('#fitMsg').html('Coupon Code is invalid');
												$('#fitDiscountedPrice').html(op);
												$('#salesPriceGold').val(op);
										} else {
										    $('#saleNumber').val(dc);
												$('#salesPriceGold').val(data['price']);
												$('#fitDiscountedPrice').html(data['price']);
										    $('#fitMsg').html('Coupon Code valid');
											
											$('#save').html(Math.round((parseFloat(op)-parseFloat(data['price'])+parseFloat(save))*100)/100);
										}
								}
						});
				});
		});
})(jQuery);
