$(document).ready(function() {
		
	/*$("a#did_coupon_work").live("click",function(){
		var container = jQuery(this);
		//mine
		$.ajax({
			type: 'POST',
			url: 'b.php',
			data: 'vars='+this.name,
			success: function(response) {
				container.parent().html(response);
			},
			error: function() {
				//$(container).parent().html("Thanks");
				container.parent().html(response);
			}
		});
		//container.parent().html("Thanks");
		//container.parent().html.append(this.name);
		return false;
	});*/
	
	$("button#bidnow_button").live("click",function() {
		//alert("div[id="+$(this).parents().parents('div').attr("id")+"]");
		//container = "div[id="+$(this).parents().parents('div').attr("id")+"]";
		//id = $(this).parents().parents('div').attr("id");
		var pid = this.name;
		//var form_data = $('form#coupon_management_'+id).serialize();
		$.ajax({
			type: 'POST',
			url: 'php/b.php',
			data: 'vars='+this.name,
			//data: form_data,
			success: function(response) {
				//$(this).parents().parents('div').html(response);
				//$("#"+$(this).parents().parents('div').attr("id")).html(response);
				//$("#bid_result").html("bid placed");
				eval("var update="+response);
				if (update["b"] != '') $("#user_bids_top").html(update["b"]);
				if (update["m"] == 'ERROR: No bids available') $("#user_bids_msg").html(update["m"]);
				if (update["m"] == 'not_logged_in') $("#user_bids_msg").html("You are not logged in. Click <a href=\"/login.php?p="+update["a"]+"\">here</a> to login.");
				//alert(response);
			}
		});
		
		//window.location="http://www.salebuddy.com/"+this.value;
	});
	
	$("#signupalerts").click(function(){
		$(".error").hide();
		var hasError = false;

		var signupemail = $('#emailsignup_email').val();
			
		if(signupemail  == '') {
			$("#error_signupalerts").css({
				'display': 'block'
			})
			$("#error_signupalerts").html("<p>Please enter a valid email address.</p>");
			hasError = true;
		}
		
		if (hasError == false) {
			var dataString = 'email='+signupemail+'&submit=submit';
			$.ajax({
				type: 'POST',
				url: '/supdate.php',
				data: dataString,
				success: function(response) {
					eval("var sresponse="+response);
					if(sresponse["r"] == "") $('#emailsignup').html("<p>Thanks for signing up for email updates. Look out for our emails soon!</p>");
					if(sresponse["r"] == "empty") $("#error_signupalerts").html("<p>Please enter a valid email address.</p>");
					if(sresponse["r"] == "invalid") $("#error_signupalerts").html("<p>Please enter a valid email address.</p>");
					//.append(response); // Shows response
				},
				error: function() {
					$('#error_signupalerts').html("oops");
				}
			});
		}
		return false;
	});
	

});
