
$(document).ready(function(){
	
	$("#nav ul ul").hide();
	
	$("li.nlinks").hover(function(){
		$(this).find("ul").removeClass("inactive").stop().css("opacity","1").fadeIn();
	}, function(){
		$(this).find("ul").animate({
			opacity:"1"
		},1000,function(){
			$(this).addClass("inactive").fadeOut();
		});
	});
	
	$("#wines_detail h3 + div").addClass("panel").hide();
	$("#wines_detail h3").addClass("btn");
	$("#wines_detail h3 + div:first").show().addClass("active").prev("h3").addClass("current");
	$("#wines_detail h3").click(function(){
		$("#wines_detail h3 + div.active").hide().removeClass("active");
		$("h3.current").removeClass("current");
		$(this).addClass("current").next("div").fadeIn().addClass("active");
	});
	
	var _returnUrlWine = $("#returnLink").attr("value");
	
	$("#wines_detail h3 + div").append("<p><a href='/"+ _returnUrlWine +".html'><img src='/images/btn_return.gif' /></a></p>");
	

	$("#signup_form").submit(function(){
		
		var error = "";
		
		
		if($("#billing_name").attr("value") == "")
		{
			error += "Please enter your first name.\n";
		}
		if($("#billing_address").attr("value") == "")
		{
			error += "Please enter your billing address.\n";
		}
		if($("#billing_city").attr("value") == "")
		{
			error += "Please enter your first name.\n";
		}
		
		if($("#billing_state").attr("value") == "")
		{
			error += "Please select your billing state.\n";
		}
		if($("#billing_zip").attr("value") == "")
		{
			error += "Please enter your billing zip code.\n";
		}
		if($("#billing_phone").attr("value") == "")
		{
			error += "Please enter your billing phone number.\n";
		}
		if($("#email").attr("value") == "")
		{
			error += "Please enter your email address.\n";
		}
		
		if($(".cc_type").attr("value") == "" )
		{
			error += "Please select your credit card type.\n";
		}
		if($("#cc_number").attr("value") == "" )
		{
			error += "Please enter your credit card number.\n";
		}
		if($("#cc_exp").attr("value") == "" )
		{
			error += "Please enter your credit card expiration date.\n";
		}
		if($("#cc_code").attr("value") == "" )
		{
			error += "Please enter your credit card CCV Code.\n";
		}
		
		if($("#shipping_name").attr("value") == "")
		{
			error += "Please enter your name.\n";
		}
		if($("#shipping_address").attr("value") == "")
		{
			error += "Please enter your shipping address.\n";
		}
		if($("#shipping_city").attr("value") == "")
		{
			error += "Please enter your shipping city.\n";
		}
		
		if($("#shipping_state").attr("value") == "")
		{
			error += "Please select your shipping state.\n";
		}
		if($("#shipping_zip").attr("value") == "")
		{
			error += "Please enter your shipping zip code.\n";
		}
		if($("#shipping_phone").attr("value") == "")
		{
			error += "Please enter your shipping phone number.\n";
		}
		
		if($("#authorize_agree").attr("checked") !== true)
		{
			error += "You must agree to the terms and conditions.\n";
		}
		
		if($("#confirm_age").attr("checked") !== true)
		{
			error += "You must confirm your age.\n";
		}
		
		if(error == "")
		{
			return true;
		} else {
			
			alert(error);
			return false;
		}
	});
	
	$("#billing_same").click(function(){
		
		if($(this).attr("checked") === true)
		{
			$("#shipping_name").attr("value", $("#billing_name").attr("value"));
			$("#Shipping_Business_Name").attr("value", $("#Billing_Business_Name").attr("value"));
			$("#shipping_address").attr("value", $("#billing_address").attr("value"));
			$("#Shipping_Address_Line_2").attr("value", $("#Billing_Address_Line_2").attr("value"));
			$("#shipping_city").attr("value", $("#billing_city").attr("value"));
			$("#shipping_state").attr("value", $("#billing_state").attr("value"));
			$("#shipping_zip").attr("value", $("#billing_zip").attr("value"));
			$("#shipping_phone").attr("value", $("#billing_phone").attr("value"));
		} else {
			$("#shipping_name").attr("value", "");
			$("#Shipping_Business_Name").attr("value", "");
			$("#shipping_address").attr("value", "");
			$("#Shipping_Address_Line_2").attr("value", "");
			$("#shipping_city").attr("value", "");
			$("#shipping_state").attr("value", "");
			$("#shipping_zip").attr("value", "");
			$("#shipping_phone").attr("value", "");
		}
		
		
		
	});
	
	$("#maillingList").submit(function(){
		
		var error = "";
		
		
		if($("#first_name").attr("value") == "")
		{
			error += "Please enter your first name.\n";
		}
		if($("#last_name").attr("value") == "")
		{
			error += "Please enter your last name.\n";
		}
		if($("#address").attr("value") == "")
		{
			error += "Please enter your  address.\n";
		}
		if($("#city").attr("value") == "")
		{
			error += "Please enter your city.\n";
		}
		if($("#state").attr("value") == "")
		{
			error += "Please select your state.\n";
		}
		if($("#zip").attr("value") == "")
		{
			error += "Please enter your zip code.\n";
		}
		if($("#email").attr("value") == "")
		{
			error += "Please enter your email address.\n";
		}
		
		if(error == "")
		{
			return true;
		} else {
			
			alert(error);
			return false;
		}
		
	});
	
	$("#send_key").attr("value","29arOPCqui1NFtUIDxpSzh");

});