$(document).ready(function() {
	
	var myRating = 0;
	
	$(".Sizes").click(function() {
		intProductSizeID = $(this).attr("id");
		//alert("SIZE: " + intProductSizeID);
		$.ajax({
			url: "/submit_Product.asp",
			type: 'post',
			data: $('form').serialize() + '&ProductSizeID=' + intProductSizeID,
			success: function(response) {
				if (response == 'Success') {
					window.location = '/cart/';
				}
			}}); //END ajax
		});
	
	$("#CommentText").focus(function() {
		if (this.defaultValue=="Say what you gotta say...(optional)") {
			this.value="";
		}
	});
	
	$(".rating").click(function() {
		$(".rating").removeClass('Rating_Selected').addClass('blue');
		$(this).removeClass('blue').addClass('Rating_Selected');
		myRating = $(this).attr("id");
	});
	
	$("#myComment").click(function() {
		$('#MessageBar').empty();
		CommentText = $("#CommentText").val();
		ProductID = $("#ProductID").val();
	
		if(myRating > 0) {
			myDataString = 'Rating=' + myRating + '&Comment=' + CommentText + '&ProductID=' + ProductID;
			//alert("MY: " + myDataString);
			$.ajax({
				url: "/submit_Comment.asp",
				data: myDataString,
				success: function(response) {
					if (response == 'Success') {
						$('#MessageBar').append("<div class='SuccessBar'></div>");
						$(window).scrollTop(0);
						strMsg = "<div style='width:850px; margin:0 auto;'>"
						strMsg = strMsg + "<div class='ErrorBar_L'><img src='/images/icon-donut.png' width='39' height='35'></div>"
						strMsg = strMsg + "<div class='ErrorBar_R'>Thanks for the comment! Enjoy a donut.</div>"
						strMsg = strMsg + "<div class='clear'></div></div>";
						$(".SuccessBar").html(strMsg);
						$('#MessageBar').delay(1000).slideDown('slow');
					} else if (response == 'Error') {
						$('#MessageBar').append("<div class='ErrorBar'></div>");
						$(window).scrollTop(0);
						strError = "<div style='width:850px; margin:0 auto;'>"
						strError = strError + "<div class='ErrorBar_L'><img src='/images/icon-error-lg.png' width='39' height='35'></div>"
						strError = strError + "<div class='ErrorBar_R'>Your comment didn't go through for some reason. Try again.</div>"
						strError = strError + "<div class='clear'></div></div>";
						$(".ErrorBar").html(strError);
						$('#MessageBar').delay(1000).slideDown('slow');
					}
				}}); //END ajax
		} else {
			$('#MessageBar').append("<div class='ErrorBar'></div>");
			$(window).scrollTop(0);
			strError = "<div style='width:850px; margin:0 auto;'>"
			strError = strError + "<div class='ErrorBar_L'><img src='/images/icon-error-lg.png' width='39' height='35' align='left'></div>"
			strError = strError + "<div class='ErrorBar_R'>You have to give it a rating. Try again.</div>";
			strError = strError + "<div class='clear'></div></div>";
			$(".ErrorBar").html(strError);
			$('#MessageBar').delay(1000).slideDown('slow');
		}
	});
	
	$('#Product_SM_1').click(function() {
		$('#Product_Big').attr("src", $(this).attr("src"));									 
	});
	$('#Product_SM_2').click(function() {
		$('#Product_Big').attr("src", $(this).attr("src"));									 
	});
	$('#Product_SM_3').click(function() {
		$('#Product_Big').attr("src", $(this).attr("src"));									 
	});
	$('#Product_SM_4').click(function() {
		$('#Product_Big').attr("src", $(this).attr("src"));									 
	});
}); //END Document