jQuery(function($){
	$.ajaxSetup ({
		cache: false
	});
	var value = $(".coupon-code").val();
	$(".coupon-code").focus(function(e){
		if(this.value == "Enter Coupon Code" || this.value == "Insertar Cupón"){
			this.value = "";
			$(this).css("color","#000");
		}
	});
	
	$(".coupon-code").blur(function(e){
		if(this.value == ""){
			this.value = value;
			$(this).css("color","#999");
		}
	});
	
	$(".cart-submit").click(function(e){
		if($(".coupon-code").val() == "") return;
		if($(".coupon-code").val() == "Enter Coupon Code" || $(".coupon-code").val() == "Insertar Cupón") return;
		e.preventDefault();
		$.post("http://"+window.location.hostname+"/ajax/get_coupon_value/", { code: $(".coupon-code").val(),products: $("input[name$='custom']").val() }, function(data){
			if(data.error){
				alert(data.error);
			}else{
				$("input[name$='amount']").val(data.newvalue);
				$("form[name$='paypal_form']").submit();
				//alert(data);
			}
		},'json');
	})
	.ajaxError(function(e, xhr, settings, exception) {
		alert('error in: ' + settings.url + ' \n'+'error:\n' + xhr.responseText );
	});
	
	$(".topic_link").click(function(e){
		e.preventDefault();
		var id = $(this).attr("id");
		$("#products_container").fadeOut(200,function(){
			$(this).html($("#products_"+id).html()).fadeIn(200);
		});
	});
});
