var s_id=0;
var r_id=0;
function print_this_page()
{
	$('#navigation').hide();
	$('#pageContent > div:last').hide();
	$('#footer').hide();
	$('#mainContent').css('width', 900);
	$('p.print').hide();

	window.print();

	setTimeout("show_this_page()",5000);
}

function show_this_page()
{
	$('#navigation').show();
	$('#pageContent > div:last').show();
	$('#footer').show();
	$('#mainContent').css('width', 650);
	$('p.print').show();
}

function registry_remove(registry_id, a)
{
	if( confirm("Are you sure to remove this registry?") )
	{
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			data: "ajax=true&request=66&registry_id="+ registry_id,
			success: function (r)
			{
				r = eval(r);

				if(r.status == 'OK')
				{
					display_popup("Registry has been removed successfully");
					$(a).parent().parent().parent().parent().remove();
				}
			}
		 });
	 }
}

function mini_registration()
{
	var data = "";

 	if( $('#firstName').val() == '' )
 	{
	 	$('#firstName').parent().addClass('error');
	 	$('#firstName').focus();
 		alert("Please enter your first name");
 		return 0;
 	}
 	else
 	{
		data += "&firstName="+ $('#firstName').val();
	 	$('#firstName').parent().removeClass('error');
 	}

 	if( $('#lastName').val() == '' )
 	{
	 	$('#lastName').parent().addClass('error');
	 	$('#lastName').focus();
 		alert("Please enter your last name");
 		return 0;
 	}
 	else
 	{
		data += "&lastName="+ $('#lastName').val();
	 	$('#lastName').parent().removeClass('error');
 	}


   if ( $('#lightbox_email').val() == '')
	{
      	$('#lightbox_email').parent().addClass('error');
	 	$('#lightbox_email').focus();
 		alert("Please enter your email");
 		return 0;
	}
 
	else if( $('#lightbox_email').val() != '' &&!(check_email($('#lightbox_email').val())) )
 	{
	 	$('#lightbox_email').parent().addClass('error');
	 	$('#lightbox_email').focus();
 		alert("Please enter your correct email");
 		return 0;
 	}
 	else
 	{
		data += "&email="+ $('#lightbox_email').val();
	 	$('#lightbox_email').parent().removeClass('error');
 	}

 	if( $('#month').val() == '0' || $('#day').val() == '0' || $('#year').val() == '0' )
 	{
	 	$('#month').parent().addClass('error');
 		alert("Please enter your birthday");
 		return 0;
 	}
 	else
 	{
		data += "&birthday="+ $('#year').val()+'-'+$('#month').val()+'-'+$('#day').val();
	 	$('#month').parent().removeClass('error');
 	}

 	if( $('#zip').val() == '' )
 	{
	 	$('#zip').parent().addClass('error');
	 	$('#zip').focus();
 		alert("Please enter your postal code");
 		return 0;
 	}
 	else
 	{
		data += "&zip="+ $('#zip').val();
	 	$('#zip').parent().removeClass('error');
 	}

	$.ajax(
	{
		type: "POST",
		//url: "/daily-sip-landing",
		url: "/the-daily-sip",
		data: "action=mini-registration"+ data,
		success: function (r)
		{
		   r = eval(r);

			if( r.code == 0 )
			{
				$("#mini-registration").hide();

				alert("You have been successfully registered. Please check your email "+ $('#lightbox_email').val());

				$("#mini-registration input").val('');
				$("#mini-registration select > option:first").attr('selected', 1);
			}
			else
			{
				alert(r.msg);
			}
		}
	});
}

function send_request_about_expert_advice()
{
	if( $('#noteTextarea').val() == "" )
	{
		alert("Please enter your note");
		$('#noteTextarea').parent().addClass('error');
		$('#noteTextarea').focus();
		return 0;
	}

    if( $('#sender').val() == "" )
	{
		alert("Please enter your email");
		$('#sender').parent().addClass('error');
		$('#sender').focus();
		return 0;
	}

 	$.ajax(
	{
		type: "POST",
		url: window.location.pathname,
		data: "action=get_advice&from="+ $('#sender').val() + "&note="+ $('#noteTextarea').val(),
		success: function (r)
		{
		   $('#advice').hide();
		}
	});
}

function check_email(email)
{
	var exp = RegExp("^[0-9a-zA-Z][-_.0-9a-zA-Z]*@[-.0-9a-zA-Z]+\.[a-zA-Z]{2,4}$");
	return exp.test(email);
};

function log_out_check()
{
	httpRefer = document.location.href;

	if ( httpRefer.indexOf('/note/add/') != -1 )
	{
		$('#score > p:first').html('You must be logged in to leave a note.');
		$('#score').show().animate({'opacity': 1}, 3000, function() { $(this).hide(); document.location.href = '/log-out'; });		
	} else { document.location.href = '/log-out'; }	
}

function ShowWhereWeShip()
{
	$("select").hide();
	$("#weship").show();
	$("#shade").css('height', $(document).height());
	$("#shade").show();
	
}

function HideWhereWeShip()
{
	$("select").show();
	$("#shade").hide();
	$("#weship").hide();
}
function ShowTheContest()
{
	$("select").hide();
	$("#shadecontest").css('height', $(document).height());
	$("#shadecontest").show();
	$("#contestbanner").show();	
}

function HideContestBanner()
{
	$.ajax({
		type: "POST",
		url: "/myajax.php",
		success: function (r)
		{
			$("select").show();
	        $("#contestbanner").hide();
	        $("#shadecontest").hide();
		}
	 });
}
function contestclick()
{
	$.ajax({
		type: "POST",
		url: "/myajax.php",
		success: function (r)
		{
			window.location="/contest";
		}
	 });
}

function RulesClick()
{
	$.ajax({
		type: "POST",
		url: "/myajax.php",
		success: function (r)
		{
			window.location="/terms-and-conditions";
			//window.open ("/terms-and-conditions","Terms"); 
		}
	});
}

function remove_item_from_registry(a, id)
{
	$.ajax(
	{
		type: "POST",
		url: window.location.pathname,
		data: "action=remove_item_from_registry&item_id="+ id,
		success: function (r)
		{
			r = eval(r);

			if(r.code == 0 )
			{
				$(a).parent().parent().parent().remove();
			//	display_popup(r.msg);
			}
		}
	});
}

function checkout(order_id)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=checkout&order_id="+ order_id,
		success: function (r)
		{
			r = eval(r);

			if(r.code == 0 ) window.location.href = "/order-confirmation";
		}
	 });
}

function check_search_form()
{
	if( $("#firstName").val() == "" && $("#lastName").val() == "" )
	{
		$("#firstName").parent().addClass("error");
		$("#lastName").parent().addClass("error")

		alert("Please enter First or Last Name");
	}
	else
	{
		window.location.href = "/registry/search/?firstName="+ $("#firstName").val()+ "&lastName="+ $("#lastName").val();
	}
}

function enable_coregistrant(a)
{
	var div = $(a).parent().parent().children('div:first');

	if( !div.is(':visible') )	div.show();
	else						div.hide();
}

function check_registry_create_info()
{
	
	$('input,select').parent().removeClass("error");

	var errors = "";

	if( $('#event_type').val() == "0" )
	{
		errors +=  "Please, choose registry event type\n";
		$('#event_type').parent().addClass("error");
		$('#event_type').focus();
	}

	if( $('#month').val() == "0" )
	{
		errors += "Please, choose registry event month\n";
		$('#month').parent().addClass("error");
		$('#month').focus();
	}

	if( $('#day').val() == "0" )
	{
		errors += "Please, choose registry event day\n";
		$('#day').parent().addClass("error");
		$('#day').focus();
	}

	if( $('#year').val() == "0" )
	{
		errors += "Please, choose registry event year\n";
		$('#year').parent().addClass("error");
		$('#year').focus();
	}

	if( $('#eventCity').val() == "" )
	{
		errors += "Please, choose registry event location\n";
		$('#eventCity').parent().addClass("error");
		$('#eventCity').focus();
	}

	if( $('#eventStateProvence').val() == "0" )
	{
		errors += "Please, choose registry event state\n";
		$('#eventStateProvence').parent().addClass("error");
		$('#eventStateProvence').focus();
	}

	if( $('#eventCountry').val() == "0" )
	{
		errors += "Please, choose registry event country\n";
		$('#eventCountry').parent().addClass("error");
		$('#eventCountry').focus();
	}

	if( $('#coregistrant').val() != "" )
	{
        $.ajax({
			type: "POST",
			async: false,
			url: window.location.pathname,
			data: "action=check_coregistrant&coregistrant="+ $('#coregistrant').val(),
			success: function (r)
			{
				r = eval(r);

				if( r.code != 0) errors += "Please, provide valid coregistrant username or email\n";
			}
		});
	}

	if( $('#shippingAddressInfo').val() == "" )
	{
		errors += "Please, choose shiping address\n";
		$('#shippingAddress').parent().addClass("error");
		$('#shippingAddress').focus();
	}

	if ($('#newCoReg').is(':visible') )
	{
		if( $('#newCoReg #firstName').val() == "" )
		{
			alert("Please, enter first name");
			$('#newCoReg #firstName').parent().addClass("error");
			$('#newCoReg #firstName').focus();
			return 0;
		}

		if( $('#newCoReg #lastName').val() == "" )
		{
			alert("Please, enter last name");
			$('#newCoReg #lastName').parent().addClass("error");
			$('#newCoReg #lastName').focus();
			return 0;
		}

		if( $('#comonth').val() == "" || $('#coday').val() == "" || $('#coyear').val() == "" )
		{
			alert("Please, choose birthday date");
			$('#comonth').parent().addClass("error");
			$('#comonth').focus();
			return 0;
		}

		if( $('#newCoReg #username').val() == "" )
		{
			alert("Please, enter Username");
			$('#username').parent().addClass("error");
			$('#username').focus();
			return 0;
		}

		if( $('#email').val() == "" )
		{
			alert("Please, enter Email");
			$('#email').parent().addClass("error");
			$('#email').focus();
			return 0;
		}
		else
		{
			if (check_email($('#email1').val()))
			{
				var r = eval($.ajax({
					type: "POST",
					async: false,
					url: window.location.pathname,
					data: "action=check_coregistrant&newcoreg=1&coregistrant="+ $('#email1').val()
				}).responseText);

				if( r.code != 0) {
					alert("This Email already exists");
					$('#email').parent().addClass("error");
					$('#email').focus();
					return false;
				}
			}
			else
			{
				alert("Please, provide valid Email");
				$('#email').parent().addClass("error");
				$('#email').focus();
				return 0;
			}
		}

		if( $('#pass11').val() == "" )
		{
			alert("Please, enter Password");
			$('#pass11').parent().addClass("error");
			$('#pass11').focus();
			return 0;
		}

		if( $('#pass22').val() == "" )
		{
			alert("Please, enter Password");
			$('#pass22').parent().addClass("error");
			$('#pass22').focus();
			return 0;
		}

		if( $('#pass11').val() != $('#pass22').val() )
		{
			alert("Please, enter equal Passwords");
			$('#pass11').parent().addClass("error");
			$('#pass22').parent().addClass("error");
			$('#pass11').focus();
			return 0;
		}
	}

	if( $('#event_type').val() == "WEDDING" && $('#coregistrant').val() == "" && $('#newCoReg #firstName').val() == "" )
	{
		alert("For wedding event you must choose co-registrant");
		return 0;
	}

	if( ! $('#shippingAddressTable input:radio:checked').size() )
	{
		alert("Please, choose your registry shipping address");
		return false;
	}

	//-------------------------------------------------------------------------

	if( errors != "" )
	{
		alert(errors);
		return;
	}
	else
	{
		var act='create_registry';

		if ($('#isedit').val() > 0)
		{
			act='edit_registry&registry_id='+$('#isedit').val();
		}

		var data1 = "action="+act
				+"&event_type="+ $('#event_type').val()
				+"&event_date="+ $('#year').val() +'-'+ $('#month').val() +'-'+$('#day').val()
				+"&location="+ $('#eventCity').val()
				+"&state="+ $('#eventStateProvence').val()
				+"&country="+ $('#eventCountry').val()
				+"&coregistrant="+ $('#coregistrant').val()
				+"&shipping="+$('#shippingAddressInfo').val();

		if ( $('#newCoReg').is(':visible') )
		{
			data1 += "&firstName="+$('#newCoReg #firstName').val()
				+"&lastName="+$('#newCoReg #lastName').val()
				+"&comonth="+$('#comonth').val()
				+"&coday="+$('#coday').val()
				+"&coyear="+$('#coyear').val()
				+"&username="+$('#newCoReg #username').val()
				+"&email="+$('#email1').val()
				+"&pass="+$('#pass11').val()
				+"&displayname="+$('#displayName').val();

		}
 
	    $.ajax({
			type: "POST",
			url: window.location.pathname,
			data: data1,
			success: function (r)
			{
				r = eval(r);
				if( r.code == 0 )  window.location.href = r.msg;
			}
		});

	}

}

function show_bin_map()
{
	$('#shade').show();
	$('#dialogueContainer').show();
}

function display_popup(msg)
{
	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1}, 3000, function() { $(this).hide(); $("#shade").hide(); });
}

function shade_hide()
{
$("#shade").hide();
}

function add_to_cart(wine_id)
{
	var ul = $('ul.cart');
	var msg = ul.find('a:first').get(0).firstChild;
	var qnt = $('#qnt_'+wine_id).val();
	var quantity = $('div.quantity:last > select').val();
	if(qnt=="undefined")
	{
		qnt=quantity;
	}
	if( qnt == 0 )
	{
		alert('Please select quantity');
		return false;
	}

	display_popup("The item has been added to your cart.");
	setTimeout('',5000);

	$.ajax({
		type: "POST",
		url: "/wine/te-awa-farms-sauvignon-blanc-2003",
		data: "action=add_to_cart&item_id="+ wine_id + "&qnt="+ qnt,
		success: function (r)
		{
			r = eval(r);

			if ( r.code == 0 )
			{
				msg.nodeValue = msg.nodeValue.replace(/(\d+)/g,  function(a, n) { return Math.floor(n) + 1; });
			}

			// display_popup(r.msg);
			window.location.href = '/shopping-cart';
		}
	 });
}

var multicart = new Array();
var multicart_add_cnt=0;

function del_from_multicart(wine_id)
{
	for (var i = 0; i < multicart.length; i++)
	{
		if (multicart[i][0] == wine_id)
		{
			multicart[i][0]=0;
			multicart[i][1]=0;
			multicart[i][2]=0;
		}
	}
}

function add_to_multicart(wine_id,registry_id)
{
	del_from_multicart(wine_id);
	if (wine_id>0 && registry_id>0)
	{
		multicart[multicart.length]=new Array(wine_id,registry_id);
	}
}

function add_to_cart_multi(wine_id,cnt,registry_id,canned_registry_id)
{
	var count=0;
	var req='';

	if (wine_id==0 && cnt==0 && registry_id==0 && canned_registry_id>0)
	{
		req='action=add_all_to_cart&&canned_registry_id='+ canned_registry_id;
		count=1;
	}
	else
	{
		req='action=add_to_cart';

		if (wine_id && cnt)
		{
			req+="&wine_id="+ wine_id + "&cnt="+ cnt;
			if (registry_id)
			{
				req+= "&registry_id=" + registry_id;
			}
			count=1;
		}
		else
		{
			for (var i = 0; i < multicart.length; i++)
			{
				if (multicart[i][0]>0)
				{
					count++;
					var cnt = document.getElementById('wine_cnt_'+multicart[i][1]).value;
					req+="&wine_id" + count + "="+ multicart[i][0] + "&cnt" + count + "="+ cnt + "&registry_id" + count + "=" + multicart[i][1];
				}
			}
		}

	}

	if (count > 0)
	{
		req+="&count=" + count;
		//alert(req);
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			data: req,
			success: function (r)
			{
				r = eval(r);
				var msg = $('ul.cart').find('a:first').get(0).firstChild;
				var add_cnt='';
				var re = new RegExp("[0-9]+$");
				var m = re.exec(r.msg);
				if (m != null) {
					for (i = 0; i < m.length; i++) {
						add_cnt = add_cnt + m[i];
					}
				}
				multicart_add_cnt=add_cnt;
				r.msg = r.msg.replace(/-[0-9]+$/,"");
				if (r.code==0) msg.nodeValue = msg.nodeValue.replace(/(\d+)/g,  function(a, n) { return Math.floor(n) + Math.floor(multicart_add_cnt); });
				display_popup(r.msg);

				window.location.href = "/shopping-cart";
			}
		 });
	}
	else
	{
		alert('Please, choose at least one product')
	}
}

function add_all_to_cart(canned_registry_id)
{
	add_to_cart_multi(0,0,0,canned_registry_id);
}

function add_all_to_registry(canned_registry_id)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=add_all_to_registry&canned_registry_id="+ canned_registry_id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
		}
	 });
}

function add_to_registry(wine_id, cnt,div)
{
	var qnt = cnt;

	if( !cnt ) qnt = $('div.quantity > select').val();

	$.ajax({
		type: "POST",
		url: "/wine/te-awa-farms-sauvignon-blanc-2003",
		data: "action=add_to_registry&item_id="+ wine_id + "&qnt_requested="+ qnt,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
//			if( window.location.pathname != '/suggested-registries' ) update_document(div,wine_id);
		}
	 });
}

function add_to_wishlist(wine_id)
{
	$.ajax({
		type: "POST",
		url: "/wine/te-awa-farms-sauvignon-blanc-2003",
		data: "action=add_to_wishlist&wine_id="+ wine_id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
		}
	 });
}

function add_to_cellar(wine_id)
{
	var qnt = $('div.quantity > select').val();

	 $.ajax({
		type: "POST",
		url: "/wine/te-awa-farms-sauvignon-blanc-2003",
		data: "action=add_to_cellar&wine_id="+ wine_id +"&qnt="+ qnt,
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
		}
	  });
}

function toggle_block(div)
{
	$(div).toggleClass('contracted');
}

function show_web_user_taste_profile_map(id)
{
 	$('#shade').show();
 	$('#webuserid_'+ id).parent().show();
}

function rate_item(item_id, score)
{
 	var span = $('#rating > img');

 	span.each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star0_1/, 'star1_1') : this.src.replace(/star0_2/, 'star1_2') ) });
	span.slice(0, score).each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star1_1/, 'star0_1') : this.src.replace(/star1_2/, 'star0_2') ) });

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "item_id="+ item_id + "&score="+ (score/2),
		success: function (r)
		{
			r = eval(r);

			if( r && r.code == 0)
			{
                //display_popup(r.msg);
				//$('#score > p:first').html(r.msg);
				//$('#score').show().animate({"opacity": 1}, 3000, function() { $(this).hide() });
			}
			else
			{
				display_popup(r.msg);
				return;
			}
		}
	 });
}

function rate_winery(winery_id, score)
{

	var span = $('#rating > img');

	span.each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star0_1/, 'star1_1') : this.src.replace(/star0_2/, 'star1_2') ) });
	span.slice(0, score).each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star1_1/, 'star0_1') : this.src.replace(/star1_2/, 'star0_2') ) });
	//alert(window.location.pathname);
	
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "winery_id="+ winery_id + "&score="+ (score/2),
		success: function (r)
		{
			r = eval(r);
			
			if( r && r.code == 0)
			{
				
				display_popup(r.msg);
				$('#score > p:first').html(r.msg);
				$('#score').show().animate({"opacity": 1}, 3000, function() { $(this).hide() });
				document.location.reload();
			}
			else
			{
				display_popup(r.msg);
				return;
			}
		}
	 });
}



function rate_item_search(item_id, score)
{
	var id = '#rating'+item_id+' > img';
 	var span = $(id);

 	span.each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star0_1/, 'star1_1') : this.src.replace(/star0_2/, 'star1_2') ) });
	span.slice(0, score).each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star1_1/, 'star0_1') : this.src.replace(/star1_2/, 'star0_2') ) });

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "item_id="+ item_id + "&score="+ (score/2),
		success: function (r)
		{
			r = eval(r);

			if( r && r.code == 0)
			{
				$('#score > p:first').html(r.msg);
				$('#score').show().animate({"opacity": 1}, 3000, function() { $(this).hide() });
			}
			else
			{
				alert(r.msg);
				return;
			}
		}
	 });
}

function toggle_star(img, star)
{
	if( star == 1 )
	{
		img.src = img.src.replace(/1/, 0);
	}
	else
	{
		img.src = img.src.replace(/0/, 1);
	}
}

function show_popup(id)
{
	$('#'+ id).show();
	$('#shade').show();
}

function choose_helpfulness(note_id, choice, a)
{
	$.ajax({
		type: "POST",
		url: "/wine/details/",
		data: "action=add_helpfulness&note_id="+ note_id +"&choice="+ choice,
		success: function (r)
		{
			r = eval(r);

		  	var val = a.parentNode.firstChild.nodeValue.replace(/Was this helpful\?/, '');

			if( choice == 'Y' ) val = val.replace(/(\d+)/g,  function(a, n) { return Math.floor(n) + 1; });

			if( choice == 'N' ) val = val.replace(/out of (\d+)/, function(a, n) { return "out of "+(Math.floor(n) + 1); });

		  	$(a).parent().html(val);

			//display_popup(r.msg);
		}
	});
}

function choose_helpfulness_daily(note_id, choice, a)
{
	$.ajax({
		type: "POST",
		url: "/the-daily-sip",
		data: "action=add_helpfulness&note_id="+ note_id +"&choice="+ choice,
		success: function (r)
		{
			r = eval(r);

		  	var val = a.parentNode.firstChild.nodeValue.replace(/Was this helpful\?/, '');

			if( choice == 'Y' ) val = val.replace(/(\d+)/g,  function(a, n) { return Math.floor(n) + 1; });

			if( choice == 'N' ) val = val.replace(/out of (\d+)/, function(a, n) { return "out of "+(Math.floor(n) + 1); });

		  	$(a).parent().html(val);

			//display_popup(r.msg);
		}
	});
}

function share_with_friend(a, wine_id)
{

 	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=get_winery_story&wine_id="+ wine_id,
		success: function (r)
		{
			r = eval(r);

			if( r.code == 0 )
			{
				$('#send-popup-form1 #story').val(Base64.decode(r.story));
				$('#send-popup-form1 #wine').val(r.wine);
				$('#send-popup-form1 #url').val(r.url);
			  	$('#send-popup-form1').show();
				$('#send-popup-form1 #to').focus();
			}
		}
	});
}

function  share_winery_with_friend(a, winery_id)
{
	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=get_story4_winery&winery_id="+ winery_id,
		success: function (r)
		{
			r = eval(r);
			if( r.code == 0 )
			{	
			
				$('#send-popup-form1 #story').val(Base64.decode(r.story));
				$('#send-popup-form1 #url').val(r.url);
				$('#send-popup-form1').show();
				$('#send-popup-form1 #to').focus();
			}
		}

	});

}
function  share_restaurant_with_friend(a, rest_id)
{
	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=get_rest_desc&rest_id="+ rest_id,
		success: function (r)
		{
			r = eval(r);
			if( r.code == 0 )
			{		
				$('#send-popup-form1 #story').val(Base64.decode(r.desc));
				$('#send-popup-form1 #url').val(r.url);
				$('#send-popup-form1').show();
				$('#send-popup-form1 #to').focus();
			}
		}
	});
}

function share_event_with_friend(a, id)
{
	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=get_event_description&id="+id,
		success: function (r)
		{
			r = eval(r);

			if( r.code == 0 )
			{
				
				$('#send-popup-form1 #story').val(Base64.decode(r.description));
				$('#send-popup-form1 #event').val(r.event);
				$('#send-popup-form1 #url').val(r.url);
			  	$('#send-popup-form1').show();
				$('#send-popup-form1 #to').focus();
			}
		}
	});
}

function share_note()
{
	var to = $('#send-popup-form1 #to');
	var from = $('#send-popup-form1 #from');
	var note = $('#send-popup-form1 #story');
	var username = $('#send-popup-form1 #username');
	var wine = $('#send-popup-form1 #wine');
	var url = $(' #send-popup-form1 #url');

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

 	$('#send-popup-form1').hide();

	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=share_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val())+"&username="+ username.val() +"&wine="+ wine.val() +"&url="+ url.val(),
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
		}
	});
}

function share_event_note()
{
	var to = $('#send-popup-form1 #to');
	var from = $('#send-popup-form1 #from');
	var note = $('#send-popup-form1 #story');
	var username = $('#send-popup-form1 #username');
	var event = $('#send-popup-form1 #event');
	var url = $(' #send-popup-form1 #url');

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

 	$('#send-popup-form1').hide();

	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=share_event_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val())+"&username="+ username.val() +"&wine="+ event.val() +"&url="+ url.val(),
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
		}
	});
}

function send_note_to_friend_dailysip(a,note_id)
{	
	var note = $(a).parent().parent().parent().parent().find('div.note > div:first').html();
	$('#noteDaily').get(0).value = note;
    var textareaNote = $('#noteDaily').get(0);
 	document.getElementById('noteid').value = note_id;
    //$(textareaNote).tinymce().execCommand('mceInsertContent',false,note);
 	$('#send-popup-form').show();
}

function send_note_to_friend(a,note_id)
{
	var url = window.location.pathname;
	var note = $(a).parent().parent().parent().parent().find('div.note > div:first').html();

	if (url.indexOf('dailysip') != -1) {
		$('#noteDaily').get(0).value = note;
        var textareaNote = '#noteDaily';
	} else {
		$('#note').get(0).value = note;
        var textareaNote = '#note';
	}

    if(url=='/note/list/recent-notes'){
        var winename = $('#winename');
        var noteurl = $('#noteurl');
        var link = $(a).parent().parent().parent().parent().find('div.note > p:first > a:last');

        winename.val(link.text());
        noteurl.val(link.attr('href'));
    }
    
 	document.getElementById('noteid').value = note_id;    

    if(! $.browser.msie){
        $(textareaNote).tinymce().execCommand('mceInsertContent',false,note);
    }
        
 	$('#send-popup-form').show();
}

function send_winery_note_to_friend(a,note_id)
{

	var url = window.location.pathname;
	//alert(url);
	var note = $(a).parent().parent().parent().parent().find('div.note > div:first').html();
	//alert(url.indexOf('dailysip'));
	if (url.indexOf('dailysip') != -1) {
		
		$('#noteDaily').get(0).value = note;
        var textareaNote = '#noteDaily';
	} else {
		$('#note').get(0).value = note;
        var textareaNote = '#note';
	}

    if(url=='/note/list/recent-notes'){
		
        var winename = $('#winename');
        var noteurl = $('#noteurl');
        var link = $(a).parent().parent().parent().parent().find('div.note > p:first > a:last');

        winename.val(link.text());
        noteurl.val(link.attr('href'));
    }
    
 	document.getElementById('noteid').value = note_id;    
   //$('#send-popup-form').show();
    if(! $.browser.msie){
	
    $(textareaNote).tinymce().execCommand('mceInsertContent',false,note);
    }
        
 	$('#send-popup-form').show();
}


function send_note()
{
	var url = window.location.pathname;	
	var to = $('#to');
	var from = $('#from');
	
	if (url.indexOf('dailysip') != -1) {
		var note = $('#noteDaily'); 
	} else {
		var note = $('#note');
	}
//	var note = $('#note');
	var username = $('#username');
	var winename = $('#winename');
	var noteurl = $('#noteurl');
	var noteid = $('#noteid');

    if(url=='/note/list/recent-notes'){
        url = noteurl.val();
    }

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

	if( note.val() == '' )
	{
		note.focus();
		note.parent().addClass('error');
		alert('Please, enter note to be sent');
		return 0;
	}

 	$('#send-popup-form').hide();

	$.ajax({
		type: "POST",
		url: '/wine',
		data: "action=send_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val()) +"&username="+ username.val() +"&winename="+ Base64.encodeAndEscape(winename.val()) +"&noteurl="+ url+"#note"+noteid.val(),
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
		}
	});

}


function send_winery_note()
{
	var url = window.location.pathname;	
	var to = $('#to');
	var from = $('#from');
	
	if (url.indexOf('dailysip') != -1) {
		var note = $('#noteDaily'); 
	} else {
		var note = $('#note');
	}
//	var note = $('#note');
	var username = $('#username');
	var wineryname = $('#wineryname');
	var noteurl = $('#noteurl');
	var noteid = $('#noteid');

    if(url=='/note/list/recent-notes'){
        url = noteurl.val();
    }

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

	if( note.val() == '' )
	{
		note.focus();
		note.parent().addClass('error');
		alert('Please, enter note to be sent');
		return 0;
	}

 	$('#send-popup-form').hide();

	$.ajax({
		type: "POST",
		url: '/winery',
		data: "action=send_winery_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val()) +"&username="+ username.val() +"&wineryname="+ Base64.encodeAndEscape(wineryname.val()) +"&noteurl="+ url+"#note"+noteid.val(),
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
		}
	});


}


function delete_my_topic_confirm(id){
    var msg = "Are you sure you want to delete this topic?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_topic('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_topic(id){
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=delete_my_topic&topic_id="+ id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            //document.location.reload();
            document.location.href = "/bottletalk/view";
		}
	});    
}

function delete_my_note_confirm(id){
    var msg = "Are you sure you want to delete this note?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_note(id){
	$.ajax({
		type: "POST",
		url: '/wine',
		data: "action=delete_my_note&note_id="+ id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            document.location.reload();
		}
	});    
}


function delete_my_winery_note_confirm(id)
{
	var msg = "Are you sure you want to delete this note?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_winery_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_winery_note(id)
{
	$.ajax({
		type: "POST",
		url: '/winery',
		data: "action=delete_my_winery_note&note_id="+ id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            document.location.reload();
		}
	});    



}


function delete_my_note_confirm_daily(id){
    var msg = "Are you sure you want to delete this note?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_note_daily('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_note_daily(id){
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=delete_my_note&note_id="+ id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            document.location.reload();
		}
	});    
}

function send_event_note()
{
	
	var to = $('#to');
	var from = $('#from');
	var note = $('#note');
	var username = $('#username');
	var eventname = $('#eventname');
	var noteurl = $('#noteurl');
	var noteid = $('#noteid');

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

	if( note.val() == '' )
	{
		note.focus();
		note.parent().addClass('error');
		alert('Please, enter note to be sent');
		return 0;
	}

 	$('#send-popup-form').hide();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=send_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val()) +"&username="+ username.val() +"&eventname="+ Base64.encodeAndEscape(eventname.val()) +"&noteurl="+ noteurl.val()+"#note"+noteid.val(),
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
		}
	});

}



function check_user()
{
  $.ajax({
	type: "POST",
	url: window.location.pathname,
	data: "email="+ $('#email').val()+"&pwd="+ $('#pwd').val(),
	success: function (r)
	{
		r = eval(r);

		if ( r.code == 0 )
		{
   			$('#loginModule').submit();
		}
		else
		{
			//alert(r.msg);
            display_popup(r.msg);
            if(r.code == 3) {
                document.location.href = '/mybottlenotes';
                return 0;
            }
		}

	}
  });
}

function remove_line(a, item_id)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=remove_from_cart&item_id="+ item_id,
		success: function (r)
		{
			r = eval(r);
            //display_popup("Item has been removed from cart.");   
			var item_total = $(a).parent().parent().prev().children('p');
			var subtotal = $('#subtotal');
			var tax = $('#tax');
			var shipping = $('#shipping');
			var total = $('#total');
			var adjtotal = $('#adjtotal');
			 
			 if($('#shoppingCart tbody tr td:first-child').find('b')!=null)
			{
			 $("#shoppingCart tbody tr td:first-child").each (function (){
			 if($(this).find('b').html()!=null)
			 $(this).find('b').show();
			 });
			}
			if($('#mainTableFoot b').html()=='Add Gift Card')
			{
				$('#mainTableFoot b').show();
			}
			
			
			subtotal.text('$'+(subtotal.text().substr(1) - item_total.text().substr(1)).toFixed(2));
			total.text('$'+ (parseFloat(subtotal.text().substr(1)) + parseFloat(tax.text().substr(1)) + parseFloat(shipping.text().substr(1))).toFixed(2));
			adjtotal.text('$'+ total.text().substr(1));

			$(a).parent().parent().parent().remove();

			var msg = $('ul.cart').find('a:first').get(0).firstChild;
			msg.nodeValue = msg.nodeValue.replace(/(\d+)/g,  function(a, n) { return Math.floor(n) - 1; });
			setTimeout("window.location.reload()",500);
		}
	 });


}

function update_registry_line(registry_item_id, a)
{
	var qnt = $(a).parent().prev().children('input:first').val();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=update_qnt_in_registry&item_id="+ registry_item_id + "&qnt="+ qnt,
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);

        	$(a).parent().parent().parent().next().children('p:first').html(r.needed+"");
		}
	 });

}

function update_line(line_id, a)
{
	var qnt = $(a).parent().prev().children('input:first').val();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=update_qnt_in_cart&line_id="+ line_id + "&qnt="+ qnt,
		success: function (r)
		{
			r = eval(r);
			if(r.code =='4')
			{
			display_popup_apply_coupon(r.msg);
			}
			else if(r.code =='5')
			{
			(a).addClass("error");
			display_popup_apply_coupon(r.msg);
			}
			else
			{
			display_popup(r.msg);
        	var item_total = $(a).parent().parent().parent().next().children('p');
        	item_total.html('$'+ r.total.toFixed(2) +'');
			setTimeout("window.location.reload()",3000);
			}

		}
	 });

}

function recalculate_order(a)
{
 	var table = $('#shoppingCart');

	var sum = 0;

 	table.find('tbody > tr').each( function () { sum += parseFloat($(this).find('td > p.itemTotalPrice').text().substr(1)) } );

	$('#subtotal').text('$'+ sum.toFixed(2));
	$('#total').text('$'+ sum.toFixed(2));
	$('#adjtotal').text('$'+ sum.toFixed(2));
}
function apply_coupon(order_id)
{
	var coupon_code = $('#coupon_code').val();
	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=apply_coupon&coupon_code="+ Base64.encodeAndEscape(coupon_code) +"&order_id="+ order_id,
		success: function (r)
		{
			r = eval(r);
			//alert(r.msg);
			if (r.code == '3')
			{
			 display_popup_apply_coupon(r.msg);
			}
			else
			{
			display_popup(r.msg);
			}

			if (r.code == '0')
			{
			setTimeout("window.location.reload()",1000);
			}
		}
	  });

}
function apply_coupon_c(order_id)
{
	var coupon_code = $('#coupon_code').val();
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=apply_coupon&coupon_code="+ coupon_code +"&order_id="+ order_id,
		success: function (r)
		{
		r = eval(r);
		//alert(r.msg);
		display_popup(r.msg);

		if (r.code == '0')
		{
			setTimeout("ShowNextTab('confirmation')",1000);
		}
		}
	});

}
function remove_coupon(order_id)
{

	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=remove_coupon&order_id="+ order_id,
		success: function (r)
		{
			r = eval(r);
			//alert(r.msg);
			display_popup(r.msg);
		}
	  });
	  setTimeout("window.location.reload()",1000);
}

function save_winecyclopedia_topic(topic_id)
{
	var title = $('#Title').val();
	var content = $('#Content').val();
	var urlalias = $('#URLAlias').val();
	//added on 10/03/2010 for meta title, keyword and description change
	var metakeywords = $('#MetaKeywords').val();
	var metadescription = $('#MetaDescription').val();
	
	content = escape(content);
     // added on 10/03/2010 for meta title, keyword and description change
	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=save_winecyclopedia_topic&topic_id="+ topic_id + "&title=" + title + "&content=" + content + "&urlalias=" + urlalias+ "&metakeywords="+ metakeywords + "&metadescription=" +metadescription,
		success: function (r)
		{
			r = eval(r);

			alert(r.msg);

				if( r.code == "2" )
				{
					$('#URLAlias').parent().addClass("error");
					$('#URLAlias').focus();

				}

				if( r.code == "3" )
				{
					$('#Content').parent().addClass("error");
					$('#Content').focus();

				}

				if( r.code == "4" )
				{
					$('#Title').parent().addClass("error");
					$('#Title').focus();

				}

				if( r.code == "0" )
				{
					window.location.reload()

				}
		}
	  });
}

function change_user_password()
{
	var name = $('#name').val();
	var pass1 = $('#pass1').val();
	var pass2 = $('#pass2').val();
	var error = '';


	if (pass1 != pass2)
	{
		alert('Check pass');
		$('#pass1').parent().addClass("error");
		$('#pass1').focus();
		$('#pass2').parent().addClass("error");
		error=1;

	}
	if (name == "")
	{
		alert('Name empty');
		$('#name').parent().addClass("error");
		$('#name').focus();
		error=1;
	}


	if (error!=1)
	{
	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=change_user_password&name="+ name + "&pass=" + pass1,
		success: function (r)
		{
			r = eval(r);

			alert(r.msg);

				if( r.code == "1" )
				{
					$('#name').parent().addClass("error");
					$('#name').focus();

				}
		}
	  });
	}

}

function delete_winecyclopedia_topic(topic_id)
{

	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=delete_winecyclopedia_topic&topic_id="+ topic_id,
		success: function (r)
		{
			r = eval(r);

			alert(r.msg);
window.location.reload();

		}
	  });

}

function LightboxLoginSubmitNote(urlNote)
{
	$.ajax(
	{
		url: "/log-in",
		type: "post",
		data: "email="+ $('#lightbox_email').val()+"&pwd="+ $('#lightbox_pass').val(),
		beforeSend: Util.StartWaiting,
		success: function(r)
		{
			r = eval(r);

			if ( r.code == 1 )
			{
				alert(r.msg);
				$('#pwd').val('');
				 Util.StopWaiting();
			}

			if ( r.code == 2 || r.code == 0 )
			{
				$.ajax(
				{
					url: "/log-in",
					type: "post",
					data: "login_from_forum=true&email="+ $('#lightbox_email').val()+"&pwd="+ $('#lightbox_pass').val(),
					success: function(r)
					{  
					    Util.StopWaiting();
						location.href=urlNote;
					}
				});
			}
		}
	});
}

function ForgotPassSubmit()
{
	if( $('#forgot_pass_email').val() == '' )
	{
        $('#ForgotPass').hide().animate({"opacity": 1}, 3000, function() { $("#ForgotPass").show(); });
        display_popup('Please enter your email');
		$('#forgot_pass_email').focus().parent().addClass("error");
		return false;
	}
	else
	{
		$('#forgot_pass_email').parent().removeClass("error");

		var email = $('#forgot_pass_email').val();

		$.ajax({
			type: "POST",
			url: "/log-in",
			data: "action=reset_pass_request&email="+ email,
			success: function (r)
			{
				r = eval(r);

				if (r.code == 1)
				{
				    $('#ForgotPass').hide().animate({"opacity": 1}, 3000, function() { $("#ForgotPass").show(); });
					display_popup(r.msg);
					$('#forgot_pass_email').parent().addClass("error");
					$('#forgot_pass_email').focus();
				}
				if (r.code == 0)
				{
					$('#ForgotPass').hide();
                    display_popup(r.msg);
				}
			}
		});
	}
}

function reset_user_password(hash)
{

	var pass1 = $('#pass1').val();
	var pass2 = $('#pass2').val();
	var error = '';


	if (pass1 != pass2)
	{
		alert('Check pass');
		$('#pass1').parent().addClass("error");
		$('#pass1').focus();
		$('#pass2').parent().addClass("error");
		error=1;

	}


	if (error!=1)
	{
	 $.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=reset_user_password&pass=" + pass1 + "&p=" + hash,
		success: function (r)
		{
			r = eval(r);

			alert(r.msg);

			if(r.code == 0)
			{
				window.location = "/user/profile";
			}

		}
	  });
	}

}

function is21year(year,month,day)
{
	var myDate=new Date();
	myDate.setFullYear(year,month,day);
	var today = new Date();
	var age=(today-myDate)/1000/60/60/24/365;
	if (age<21)
        {
            return false;
        }
        else
        {
            return true;
        }
}

function activateSubscription(hash)
{
	if($('#firstName').val() == '')
	{
		alert('Please enter first name');
		$('#firstName').parent().addClass("error");
		$('#firstName').focus();
		return;
	}

	if($('#lastName').val() == '')
	{
		alert('Please enter last name');
		$('#lastName').parent().addClass("error");
		$('#lastName').focus();
		return;
	}

	if($('#email').val() == '')
	{
		alert('Please enter email address');
		$('#email').parent().addClass("error");
		$('#email').focus();
		return;
	}

	if($('#address1').val() == '')
	{
		alert('Please enter shipping address');
		$('#address1').parent().addClass("error");
		$('#address1').focus();
		return;
	}

	if($('#city').val() == '')
	{
		alert('Please enter city');
		$('#city').parent().addClass("error");
		$('#city').focus();
		return;
	}

	if($('#zip').val() == '')
	{
		alert('Please enter zip code');
		$('#zip').parent().addClass("error");
		$('#zip').focus();
		return;
	}

	if($('#month').val() == '' | $('#day').val() == '' | $('#year').val() == '')
	{
		alert('Please enter birth date');
		$('#month').parent().addClass("error");
		$('#month').focus();
		return;
	}
	if ($('#pass1').val() != $('#pass2').val())
	{
		alert('Check password');
		$('#pass1').parent().addClass("error");
		$('#pass1').focus();
		$('#pass2').parent().addClass("error");
		return;
	}
		if ($('#pass1').val() == '' | $('#pass2').val() == '')
	{
		alert('Check password');
		$('#pass1').parent().addClass("error");
		$('#pass1').focus();
		$('#pass2').parent().addClass("error");
		return;
	}

			var data = "ajax=true&hash="+ hash +
			"&firstname=" + $('#firstName').val() +
			"&lastname=" + $('#lastName').val() +
			"&email=" + $('#email').val() +
			"&birthdate=" + $('#year').val() +"-"+ $('#month').val() +"-"+ $('#day').val() +
			"&pass=" + $('#pass1').val() +
			"&address1=" + $('#address1').val() +
			"&address2=" + $('#address2').val() +
			"&city=" + $('#city').val() +
			"&state=" + $('#stateProvence').val() +
			"&status=" + $('#status').val() +
			"&user_id=" + $('#user_id').val() +
			"&zip=" + $('#zip').val()
			;

			jQuery.ajax(
			{
			url: "/activate-subscription",
			type: "post",
			data: data,
			numTab: 2,
			success: function (r)

		{
			r = eval(r);
			if (r.code != 0)
			{
			alert(r.msg);
			return;
			}
			else
			{
				alert(r.msg);
				location.href='/user/profile/taste';
			}

		}});

}


function DisableCalendar()
{
	$('#day').attr("disabled", 1);
	$('#month').attr("disabled", 1);
	$('#year').attr("disabled", 1);

	$('#day').attr("value", '');
	$('#month').attr("value", '');
	$('#year').attr("value", '');

}

function EnableCalendar()
{
	$('#day').attr("disabled", 0);
	$('#month').attr("disabled", 0);
	$('#year').attr("disabled", 0);
}

function PrintReciept()
{
	window.print();
}

function nl2br (str)
{
    return (str + '').replace(/([^>]?)\n/g, '$1'+ '<br>' +'\n');
}

function tospaces(str)
{
	return str.replace(/\s/g, '&nbsp;');
}

function process_out_of_stock_items()
{
	$('#shoppingCart tbody > tr > td > p.itemStatus:contains("OUTOFSTOCK")').parent().parent().addClass("error");
	alert("Sorry, your cart contains out of stock items. Please remove them from your cart to proceed.");
}

// ##### Comment block begin #####
function delete_my_comment_confirm(a,id){
    var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_comment_on_tasting_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}


function delete_comment_on_tasting_note(comment_id){
	$.ajax({
		type: "POST",
		url: '/wine',
		beforeSend: Util.StartWaiting,
		data: "action=delete_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});    
}


 function delete_my_winery_comment_confirm(a,id){
    var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_winery_comment_on_tasting_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}


function delete_winery_comment_on_tasting_note(comment_id){
	$.ajax({
		type: "POST",
		url: '/winery',
		beforeSend: Util.StartWaiting,
		data: "action=delete_winery_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});    
}



function edit_comment_on_tasting_note(comment_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
          
	$.ajax({
		type: "POST",
		url: '/wine',
		beforeSend: Util.StartWaiting,
		data: "action=edit_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}


function edit_winery_comment_on_tasting_note(comment_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
          
	$.ajax({
		type: "POST",
		url: '/winery',
		beforeSend: Util.StartWaiting,
		data: "action=edit_winery_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{

			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}




function delete_my_comment_confirm_daily(a,id)
{
    var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_comment_on_tasting_note_daily('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_winery_comment_confirm_daily()
{
	var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_winery_comment_on_tasting_note_daily('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    

}



function delete_my_comment_confirm_forum(a,id,title){
    var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide(); delete_comment('+id+',\''+title+'\')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}


function delete_comment_on_tasting_note_daily(comment_id){
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=delete_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});    
}

function delete_winery_comment_on_tasting_note_daily(comment_id)
	{
		$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=delete_winery_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});  
	
	
	
	}



function edit_comment_on_tasting_note_daily(comment_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
          
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=edit_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}




function edit_winery_comment_on_tasting_note_daily(comment_id, user_id, a)
	{
		var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
          
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=edit_winery_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});



	}


// ##### Comment block end #####

function save_comment_on_tasting_note(note_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');
  	
	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
  
	$.ajax({
		type: "POST",
		url: '/wine',
		beforeSend: Util.StartWaiting,
		data: "action=add_comment&user_id=" + user_id + "&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()) + "&urlLink=" + window.location.pathname,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
//				if( $('#comments > div.recentNote:first > p:contains("No comments")') ) $('#comments > div.recentNote:first').remove();

				$(a).parent().parent().parent().parent().append( r.res );
				note.val('');

				$(a).parent().parent().parent().hide();
			}
		}
	});
}


function save_winery_comment_on_tasting_note(note_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');
	
	if( note.val()== '' )
		{
			alert('Please enter some comment');
			return false;	
		
		}
  
	$.ajax({
		type: "POST",
		url: '/winery',
		beforeSend: Util.StartWaiting,
		data: "action=add_winery_comment&user_id=" + user_id + "&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()) + "&urlLink=" + window.location.pathname,
		success: function (r)
		{
			//alert(r);
			
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().append( r.res );
				note.val('');

				$(a).parent().parent().parent().hide();
			}
		}
	});
}



function save_comment_on_tasting_note_daily(note_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');
  	
	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}
  
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=add_comment&user_id=" + user_id + "&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()) + "&urlLink=" + window.location.pathname,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
//				if( $('#comments > div.recentNote:first > p:contains("No comments")') ) $('#comments > div.recentNote:first').remove();

				$(a).parent().parent().parent().parent().append( r.res );
				note.val('');

				$(a).parent().parent().parent().hide();
			}
		}
	});
}

function save_my_note_daily(note_id, a)
{
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=save_comment&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().parent().find('div.note > #noteDailySip').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}

function save_my_note(note_id, a)
{
	var note = $(a).parent().parent().prev().find('textarea:first');
	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}

	$.ajax({
		type: "POST",
		url: '/wine',
		beforeSend: Util.StartWaiting,
		data: "action=save_comment&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().parent().find('div.note > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}

function save_my_topic(note_id, a, cat_id, topic_title)
{
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=edit_my_topic&topic_id=" + note_id + "&msg="+ Base64.encodeAndEscape(note.val())+ "&topic-category="+ cat_id + "&topic-title="+ topic_title,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
			     display_popup(r.msg);
			     document.location.reload();
			}else{
			     display_popup("Your topic Updated error!!!");
			}
		}
	});
}

function delete_friend_confirm(user_id, friend_id, a) {
	$("#shade").hide();
	$("#popup").hide();
	
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=delete_friend&user_id=" + user_id + "&friend_id=" + friend_id,
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
					$("#addFriendButtonDiv_"+friend_id).parent().remove();
				}
			}
		});
}

function delete_friend(user_id, friend_id, a)
{
	var name = $(a).parent().parent().parent().find('h3:first > a').html();
	var rem_a = $(a).parent().parent().parent();

	msg = "Are you sure you want to delete "+ name +" as a friend.<br /><a href=\"javascript:void(0)\" onclick=\"delete_friend_confirm("+ user_id +","+ friend_id +", this)\">Yes</a>";
	msg += "| <a onclick=\"javascript: $('#shade').hide(); $(this).parent().parent().hide();\" href=\"javascript:void(0);\">No</a>";
	
	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});
	
/*	if( confirm("Are you sure you want to delete "+ name +" as a friend") )
	{
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=delete_friend&user_id=" + user_id + "&friend_id=" + friend_id,
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
					$(a).parent().parent().parent().remove();
				}
			}
		});
	} */
}

function remove_wine_from_cellar(wine_id, a)
{
	if( confirm("Are you sure you want to delete this wine from your cellar") )
	{
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=remove_wine_from_cellar&wine_id=" + wine_id,
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
					$(a).parent().parent().parent().parent().parent().remove();
					display_popup("This wine has been successfully removed from your cellar");
				}
			}
		});
	}
}

function hold_club(a, club_id)
{
	
	if( confirm("Are you sure you want to put this subscription on hold?") )
	{
		start_date = $(a).parent().prev().prev().find('input:first');

		if( start_date.val() == '' )
		{
			alert('Please, enter start date');
			start_date.parent().addClass('error');
			return false;
		}
		else
		{
			start_date.parent().removeClass('error');
		}

		end_date = $(a).parent().prev().find('input:first');

		if( end_date.val() == '' )
		{
			alert('Please, enter end date');
			end_date.parent().addClass('error');
			return false;
		}
		else
		{
			end_date.parent().removeClass('error');
		}

    		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=hold_club&id=" + club_id + "&start_date="+ start_date.val() + "&end_date="+ end_date.val(),
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
					$(a).parent().parent().next().show();
					$(a).parent().parent().prev().hide();
					$(a).parent().parent().hide();
					 jQuery("#expired"+club_id).empty();
					 jQuery("#expired"+club_id).append('Hold');
					//jQuery("#renewId"+club_id).show();
					jQuery("#cancelId"+club_id).show();
					alert('Your subscription is hold');
				}
			}
		});
	}
}

function unhold_club(a, club_id)
{
	
	if( confirm("Are you sure you want to reactivate your club subscription?") )
	{
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=unhold_club&id=" + club_id,
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
					$(a).parent().hide();
					$(a).parent().prev().prev().show();
					$(a).parent().prev().find('input[type="text"]').val('');
					jQuery("#expired"+club_id).empty();
					jQuery("#expired"+club_id).append('Active');
					jQuery("#renewId"+club_id).hide();
					jQuery("#cancelId"+club_id).show();
                    alert('Your subscription has been reactivated.');
				}
			}
		});
    }
}
function cancel_club(a, club_id)
{
	if( confirm("Are you sure you want to cancel this subscription?") )
	{
		$.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=cancel_club&id=" + club_id,
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{  
					
					$(a).parent().hide();
					jQuery("#holdId"+club_id).hide();
					jQuery("#holdIdsecond"+club_id).hide();
					jQuery("#unholdId"+club_id).hide();
					jQuery("#unholdIdsecond"+club_id).hide();

					$(a).parent().prev().find('input[type="text"]').val('');
                    jQuery("#expired"+club_id).empty();
					jQuery("#expired"+club_id).append('Expired');
					jQuery("#renewId"+club_id).show();
					alert('Your subscription is canceled.');
				}
			}
		});
    }
}
function show_edit_gift_card_form(a)
{
	$(a).parent().parent().prev().children('textarea:first').attr('disabled', '').focus();
	$(a).parent().next().show();
	$(a).parent().hide();
}

function save_gift_card(a, line_id)
{
	var msg = $(a).parent().parent().prev().children('textarea:first').val();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=save_gift_card&id=" + line_id + "&msg="+ Base64.encodeAndEscape(msg),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().prev().show();
				$(a).parent().hide();
				$(a).parent().parent().prev().children('textarea:first').attr('disabled', 1);

				display_popup("Your gift message has been saved.");
			}
		}
	});
}

function save_club(sub_id)
{
	   
         $.ajax({
			type: "POST",
			url: window.location.pathname,
			beforeSend: Util.StartWaiting,
			data: "action=save_club&id=" + sub_id+"&freq="+$('#freq'+sub_id).val()+"&clubLine="+$('#clubLine'+sub_id).val()+"&shipAdd="+$('#shipAddress'+sub_id).val()+"&billAdd="+$('#billAddress'+sub_id).val(),
			success: function (r)
			{
				r = eval(r);

				Util.StopWaiting();

				if( r.code == 0 )
				{
						alert('Changes Saved.');
				}
			}
		});

}
function update_cellar(user_id, wine_id, a)
{
	var qnt = $(a).parent().parent().prev().find('select:first').val();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=update_cellar&user_id=" + user_id + "&wine_id="+ wine_id +"&qnt="+ qnt,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().prev().show();
				//$(a).parent().hide();
				$(a).parent().parent().prev().children('textarea:first').attr('disabled', 1);

				display_popup("Your cellar has been update successfully");
			}
		}
	});
}

function send_message_to_user(sender_id, reciver_id)
{
	
	var msg = $('#msg');
    var url= window.location.pathname;
	if( msg.val() == '' )
	{
		alert('Please, enter your message');
		return false;
	}
	
	if(sender_id==0 && reciver_id==0)
	{
       sender_id=s_id;
       reciver_id=r_id;
       url="people/details";
	}
	
    $('#message').hide();
 	$.ajax({
		type: "POST",
		url: url,
		beforeSend: Util.StartWaiting,
		data: "action=send_message&sender_id=" + sender_id + "&reciver_id="+ reciver_id +"&msg="+ Base64.encodeAndEscape(msg.val()),
			
		success: function (r)
		{
			
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				msg.val('');
				$('#message').hide();
				display_popup("Your message has been successfully sent");
			}else{
			     display_popup(r.msg);			 
			}
		}
	});
}

function show_text_area(sender_id, reciver_id)
{
		s_id=sender_id;
		r_id=reciver_id;
		 $('#msg').val('');
       	$('#message').show();
}

function close_text_area()
{
		s_id=0;
		r_id=0;

		$('#message').hide();
}

function close_message(id, a)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=close_message&id=" + id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().hide();
			}
		}
	});
}

function reply_to_message(sender_id)
{
	var msg = $('#msg');

	if( msg.val() == '' )
	{
		alert('Please, enter your message');
		return false;
	}

	var reciver_id = $('#reciver').val();

	$('#message').hide();

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=send_message&sender_id=" + sender_id + "&reciver_id="+ reciver_id +"&msg="+ Base64.encodeAndEscape(msg.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				msg.val('');
				display_popup("Your message has been successfully sent");
			}
		}
	});
}

function accept_friend(user_id, friend_id, a)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=accept_friend&user_id=" + user_id + "&friend_id="+ friend_id,
		success: function (r)
		{
			r = eval(r);
			Util.StopWaiting();
				
			if( r.code == 0 )
			{
				if(r.pendingfriendcount == 0)
				{
					window.location.href = '/mybottlenotes';
					return;
				}
				$(a).parent().parent().parent().remove();
				
			}
		}
	});
}

function ignore_friend(user_id, friend_id, a)
{
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=ignore_friend&user_id=" + user_id + "&friend_id="+ friend_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				if(r.pendingfriendcount == 0)
				{
					window.location.href = '/mybottlenotes';
					return;
				}
			
				$(a).parent().parent().parent().remove();
				
			}
		}
	});
}
 function message_show(sourceDiv,targetDivId){
      var y=findPosY(document.getElementById(sourceDiv));
      var x=findPosX(document.getElementById(sourceDiv));
      y=eval(y-50);
      x=eval(x-210); 
       document.getElementById(targetDivId).style.top=y +"px";
       document.getElementById(targetDivId).style.left=x+"px";
       document.getElementById(targetDivId).style.display = "block";   
     }
  function message_hide(divid) {
	 document.getElementById(divid).style.display = "none";
  }
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

 function accept_friend_by_search(user_id, friend_id, a)
{
	
	$.ajax({
		type: "POST",
		url:"/my-pending-friends",
		beforeSend: Util.StartWaiting,
		data: "action=accept_friend&user_id=" + user_id + "&friend_id="+ friend_id,
		success: function (r)
		{
			r = eval(r);
			Util.StopWaiting();
				
			if( r.code == 0 )
			{
			jQuery("#addFriendButtonDiv_" +user_id ).html("<p>Existing Friend</p>");
			     //window.location.href = window.location.pathname;
							
			}
		}
		
	});
}


function ignore_friend_by_search(user_id, friend_id, a)
{
	$.ajax({
		type: "POST",
		url:"/my-pending-friends",
		beforeSend: Util.StartWaiting,
		data: "action=ignore_friend&user_id=" + user_id + "&friend_id="+ friend_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
			jQuery("#addFriendButtonDiv_" + user_id).html("<p>Not Approved Friend</p>");
				//window.location.href = window.location.pathname;							
			}
		}	
	});
}
function show_my_rating(item_id)
{
  $("#avgrating"+item_id).hide();
  $("#myrating"+item_id).show();
}
function rate_item_for_list_page(item_id, score)
{
 	var span = $('#rating'+item_id+' > img');

 	span.each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star0_1/, 'star1_1') : this.src.replace(/star0_2/, 'star1_2') ) });
	span.slice(0, score).each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star1_1/, 'star0_1') : this.src.replace(/star1_2/, 'star0_2') ) });
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "item_id="+ item_id + "&score="+ (score/2),
		success: function (r)
		{
			r = eval(r);

			if( r && r.code == 0)
			{
				$('#score > p:first').html(r.msg);
				$('#score').show().animate({"opacity": 1}, 3000, function() { $(this).hide() });
			}
			else
			{
				alert(r.msg);
				return;
			}
		}
	 });
}

function save_my_blog_comment(comment_id, a)
{     
	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}
         
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=save_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
              
		success: function (r)
		{
                  r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
                           
				$(a).parent().parent().parent().parent().parent().find('div.note > #noteDailySip').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}
function delete_my_blog_comment_confirm(id){
    var msg = "Are you sure you want to delete this note?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_blog_comment('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});
}

function delete_my_blog_comment(id){
      
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=delete_my_comment&comment_id="+ id,
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            document.location.reload();
		}
	});
}

function send_comment_to_friend(a,comment_id)
{   
	var url = window.location.pathname;
	var comment = $(a).parent().parent().parent().parent().find('div.note > div:first').html();
       
	if (url.indexOf('blog') != -1) {
            
		$('#noteDaily').get(0).value = comment;
        var textareaComment = '#noteDaily';
	} else {
		$('#note').get(0).value = comment;
        var textareaComment = '#note';
	}

 /* if(url=='/note/list/recent-notes'){
        var winename = $('#winename');
        var noteurl = $('#noteurl');
        var link = $(a).parent().parent().parent().parent().find('div.note > p:first > a:last');

        winename.val(link.text());
        noteurl.val(link.attr('href'));
    }*/

 	document.getElementById('noteid').value = comment_id;

    if(! $.browser.msie){
        $(textareaComment).tinymce().execCommand('mceInsertContent',false,comment);
    }

 	$('#send-popup-form').show();
}

function LightboxLoginSubmit(UrlAlias)
{
	$.ajax(
	{
		url: "/log-in",
		type: "post",
		data: "email="+ $('#lightbox_email').val()+"&pwd="+ $('#lightbox_pass').val(),
		beforeSend: Util.StartWaiting,
		success: function(r)
		{	r = eval(r);

			if ( r.code == 1 )
			{ 
				alert(r.msg);
				$('#pwd').val('');
				 Util.StopWaiting();
			}

			if ( r.code == 2 || r.code == 0 )
			{
				$.ajax(
				{
					url: "/log-in",
					type: "post",
					data: "login_from_forum=true&email="+ $('#lightbox_email').val()+"&pwd="+ $('#lightbox_pass').val(),
					success: function(r)
					{  
					    Util.StopWaiting();
						location.href='/blog/comment/add/'+UrlAlias;
					}
				});
			}
		}
	});
}



function blog_comment_to_friend_submit() // comment: will see later
{
	var url = window.location.pathname;
	var to = $('#to');
	var from = $('#from');

	if (url.indexOf('blog') != -1) {
		var comment = $('#noteDaily');
	} else {
		var comment = $('#note');
	}
//	var note = $('#note');
	var username = $('#username');
	var blogname = $('#blogname');
	var blogurl = $('#commenturl');
	var commentid = $('#commentid');

   /* if(url=='/note/list/recent-notes'){  //no such thing for now
        url = noteurl.val();
    }*/

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}

	if( comment.val() == '' )
	{
		note.focus();
		note.parent().addClass('error');
		alert('Please, enter comment to be sent');
		return 0;
	}

 	$('#send-popup-form').hide();

	$.ajax({
		type: "POST",
		url: '/wine',
		data: "action=send_blog_comment_to_friend&to="+ to.val() +"&from="+ from.val() +"&comment="+ Base64.encodeAndEscape(note.val()) +"&username="+ username.val() +"&blogname="+ Base64.encodeAndEscape(blogname.val()) +"&commenturl="+ url+"#note"+commentid.val(),
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
		}
	});

}

function display_popup_apply_coupon(msg)
{
	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});
}

function save_my_note_tag(note_id, a)
{
	var note = $(a).parent().parent().prev().find('textarea:first');
	tag_id = $("#tags"+note_id);
	var tag = tag_id.val();
	
	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}
	$.ajax({
		type: "POST",
		url: '/wine',
		beforeSend: Util.StartWaiting,
		data: "action=save_comment&note_id=" + note_id + "&comment="+Base64.encodeAndEscape(note.val()) + "&tag=" + Base64.encodeAndEscape(tag),
	success: function (r)
		{
			r = eval(r);
			
			Util.StopWaiting();

			if( r.code == 0 )
			{    
			    var linkval="";
				linkval=$("#link-"+note_id).val();
				var notval=note.val().replace(/\n/g, '<br>');
			    if(linkval!='' && linkval!='undefined')
				{
				notval=notval.substr(0,120);
				notval+="<span id='more_link'>...<a href='"+linkval+"'>more</a></span>";
				$(a).parent().parent().parent().parent().parent().find('div.note > div:first').html(notval);
				}
				else
				{
				$(a).parent().parent().parent().parent().parent().find('div.note > div:first').html(notval);
				}
				
				$("#tagspan"+note_id).html(r.msg);
				$(a).parent().parent().parent().hide();
			}
			
		}
	});
}



function save_my_winery_note(note_id, a)
{
    //alert(1);
	var note = $(a).parent().parent().prev().find('textarea:first');
	//tag_id = $("#tags"+note_id);
	//var tag = tag_id.val();
	
	//alert(1);
	//alert(note.val());
	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}
	$.ajax({
		type: "POST",
		url: '/winery',
		beforeSend: Util.StartWaiting,
		data: "action=save_winery_note&note_id=" + note_id + "&comment="+Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			// alert(r);
			// exit;
			r = eval(r);
			
			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().parent().find('div.note > div:first').html(note.val().replace(/\n/g, '<br>'));
				//$("#tagspan"+note_id).html(r.msg);
				$(a).parent().parent().parent().hide();
			}
			
		}
	});


}

function message_show2(sourceDiv,targetDivId)
{
	var y=findPosY(document.getElementById(sourceDiv));
	var x=findPosX(document.getElementById(sourceDiv));
	y=eval(y+20);
	x=eval(x-90); 
	document.getElementById(targetDivId).style.top=y +"px";
	document.getElementById(targetDivId).style.left=x+"px";
	document.getElementById(targetDivId).style.display = "block";   
}


function deactivate_my_account()
{	
$.ajax({
		type: "POST",
		url: '/mybottlenotes',
		data: "action=deactivate_account",
		success: function (r)
		{
		r = eval(r);
			if(r.code==0)
			{
			window.location.href='/log-out';
			}
		}
	});
}


function confirmDeactive()
{

display_popup_apply_coupon("<br/><p >Are you sure you want to deactivate this account? Deactivating will delete all friend relationships and notes of this account will be removed.</p><p align='center'><a href='javascript:void(0)' onClick='deactivate_my_account();' >Yes</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' onclick='$(\"#shade\").hide();$(\"#popup\").hide();'>No</a></p>");
}

function save_rest_comment_on_tasting_note(note_id, user_id, a)
{	
	
	var note = $(a).parent().parent().prev().find('textarea:first');
	
	if( note.val()== '' )
		{
			alert('Please enter some comment');
			return false;	
		
		}
  
	$.ajax({
		type: "POST",
		url: '/restaurant',
		beforeSend: Util.StartWaiting,
		data: "action=add_rest_comment&user_id=" + user_id + "&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()) + "&urlLink=" + window.location.pathname,
		success: function (r)
		{
			//alert(r);
			
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().append( r.res );
				note.val('');

				$(a).parent().parent().parent().hide();
			}
		}
	});
}

function delete_my_rest_note_confirm(id)
{
	var msg = "Are you sure you want to delete this note?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_my_rest_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});    
}

function delete_my_rest_note(id)
{
	$.ajax({
		type: "POST",
		url: '/restaurant',
		data: "action=delete_my_rest_note&note_id="+ id,
		
		success: function (r)
		{
			r = eval(r);

			display_popup(r.msg);
            document.location.reload();
		}
	});    

}

function save_my_rest_note(note_id, a)
{
    //alert(1);
	var note = $(a).parent().parent().prev().find('textarea:first');
	//tag_id = $("#tags"+note_id);
	//var tag = tag_id.val();
	
	//alert(1);
	//alert(note.val());
	if( note.val() == '' )
	{
		note.parent().addClass('error');
		note.focus();
		alert('Please enter some note');
		return false;
	}
	else
	{
		note.parent().removeClass('error');
	}
	$.ajax({
		type: "POST",
		url: '/restaurant',
		beforeSend: Util.StartWaiting,
		data: "action=save_rest_note&note_id=" + note_id + "&comment="+Base64.encodeAndEscape(note.val()),
		
		success: function (r)
		{
			r = eval(r);
			
			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().parent().find('div.note > div:first').html(note.val().replace(/\n/g, '<br>'));
				//$("#tagspan"+note_id).html(r.msg);
				$(a).parent().parent().parent().hide();
			}
			
		}
	});

}


function share_restaurant_note()
{
	var to = $('#send-popup-form1 #to');
	var from = $('#send-popup-form1 #from');
	var note = $('#send-popup-form1 #story');
	var username = $('#send-popup-form1 #username');
	var hotelname = $('#send-popup-form1 #hotelname');
	var url = $(' #send-popup-form1 #url');

	if( to.val() == '' )
	{
		to.focus();
		to.parent().addClass('error');
		alert('Please, enter email of your friend');
		return 0;
	}

	if( from.val() == '' )
	{
		from.focus();
		from.parent().addClass('error');
		alert('Please, enter your email');
		return 0;
	}
      
 	$('#send-popup-form1').hide();

	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=share_rest_note_to_friend&to="+ to.val() +"&from="+ from.val() +"&note="+ Base64.encodeAndEscape(note.val())+"&username="+ username.val() +"&hotelname="+ hotelname.val() +"&url="+ url.val(),
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
		}
	});
}


function delete_my_rest_comment_confirm(a,id){
    var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_rest_comment_on_tasting_note('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});

}
	function delete_rest_comment_on_tasting_note(comment_id){
	$.ajax({
		type: "POST",
		url: '/restaurant',
		beforeSend: Util.StartWaiting,
		data: "action=delete_rest_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});
}



function edit_rest_comment_on_tasting_note(comment_id, user_id, a)
{

	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}

	$.ajax({
		type: "POST",
		url: '/restaurant',
		beforeSend: Util.StartWaiting,
		data: "action=edit_rest_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{

			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});
}



function delete_my_rest_comment_confirm_daily()
{
	var msg = "Are you sure you want to delete this comment?";
    msg += '<br/><a href="javascript:void(0)" onclick="delete_rest_comment_on_tasting_note_daily('+id+')">yes</a> | <a href="javascript:void(0)" onclick="javascript: $(this).parent().parent().hide(); $(\'#shade\').hide();">no</a>';
   	$("#shade").css('height', $(document).height());
	$("#shade").show();
	$('#popup').show().find('p:first').html(msg).end().animate({"opacity": 1});

}



function delete_rest_comment_on_tasting_note_daily(comment_id)
	{
		$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=delete_rest_comment&comment_id=" + comment_id,
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

            display_popup(r.msg);
			if( r.code == 0 )
			{
				$("#comment"+comment_id).remove();
			}
		}
	});



	}



	function edit_rest_comment_on_tasting_note_daily(comment_id, user_id, a)
	{
		var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val() == '' )
	{		alert('Please enter some comment');
		return false;	}

	$.ajax({
		type: "POST",
		url: window.location.pathname,
		beforeSend: Util.StartWaiting,
		data: "action=edit_rest_comment&comment_id=" + comment_id + "&comment="+ Base64.encodeAndEscape(note.val()),
		success: function (r)
		{
			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().find('div.comment > div:first').html(note.val().replace(/\n/g, '<br>'));
				$(a).parent().parent().parent().hide();
			}
		}
	});



	}



	function save_rest_comment_on_tasting_note(note_id, user_id, a)
{

	var note = $(a).parent().parent().prev().find('textarea:first');

	if( note.val()== '' )
		{
			alert('Please enter some comment');
			return false;

		}

	$.ajax({
		type: "POST",
		url: '/restaurant',
		beforeSend: Util.StartWaiting,
		data: "action=add_rest_comment&user_id=" + user_id + "&note_id=" + note_id + "&comment="+ Base64.encodeAndEscape(note.val()) + "&urlLink=" + window.location.pathname,
		success: function (r)
		{
			//alert(r);

			r = eval(r);

			Util.StopWaiting();

			if( r.code == 0 )
			{
				$(a).parent().parent().parent().parent().append( r.res );
				note.val('');

				$(a).parent().parent().parent().hide();
			}
		}
	});
}

function rate_restaurant(rest_id, score)
{

	var span = $('#rating > img');

	span.each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star0_1/, 'star1_1') : this.src.replace(/star0_2/, 'star1_2') ) });
	span.slice(0, score).each( function(i) { this.src = ( i%2 == 0 ? this.src.replace(/star1_1/, 'star0_1') : this.src.replace(/star1_2/, 'star0_2') ) });
	//alert(window.location.pathname);
	
	$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "rest_id="+ rest_id + "&score="+ (score/2),
		success: function (r)
		{
			r = eval(r);
			
			if( r && r.code == 0)
			{
				
				display_popup(r.msg);
				$('#score > p:first').html(r.msg);
				$('#score').show().animate({"opacity": 1}, 3000, function() { $(this).hide() });
				document.location.reload();
			}
			else
			{
				display_popup(r.msg);
				return;
			}
		}
	 });
}

function send_rest_note_to_friend(a,note_id)
{

	var url = window.location.pathname;
	//alert(url);
	var note = $(a).parent().parent().parent().parent().find('div.note > div:first').html();
	//alert(url.indexOf('dailysip'));
	if (url.indexOf('dailysip') != -1) {
		
		$('#noteDaily').get(0).value = note;
        var textareaNote = '#noteDaily';
	} else {
		$('#note').get(0).value = note;
        var textareaNote = '#note';
	}

    if(url=='/note/list/recent-notes'){
		
        var winename = $('#winename');
        var noteurl = $('#noteurl');
        var link = $(a).parent().parent().parent().parent().find('div.note > p:first > a:last');

        winename.val(link.text());
        noteurl.val(link.attr('href'));
    }
    
 	document.getElementById('noteid').value = note_id;    
   //$('#send-popup-form').show();
    if(! $.browser.msie){
	
    $(textareaNote).tinymce().execCommand('mceInsertContent',false,note);
    }
        
 	$('#send-popup-form').show();
}

	function trim_for_signup_popup(strToTrim)
	{
		return strToTrim.replace(/^\s+|\s+$/g,"");
	}
	
	function check_fields_for_signup_popup($popup)
	{
		var data = "";
	
		data += "&popup_ds="+ $popup;
		
		if( $('#email_ds').val() == '' )
		{
			$('#email_ds').parent().addClass('error');
			$('#email_ds').focus();
			alert('Please, enter your email');
			return false;
		}
		else
		{
			$validemail = check_email(trim_for_signup_popup($('#email_ds').val()));
			if($validemail==false){
				$('#email_ds').parent().addClass('error');	
				$('#email_ds').focus();
				alert('Please, enter a valid email');
				return false;
			}
			else{
			    $('#email_ds').parent().removeClass('error');
			    data += "&email="+ $('#email_ds').val();
			}
            	
        }
        
        $.ajax({
			type: "POST",
			url:"/daily-sip-signup-thanks",
			data: "action=signup"+ data,
			success: function (r)
			{
				r=eval(r);
				if(r.code==0)
				{
					window.location.href = "/daily-sip-signup-thanks";
				}
				else
				{
					display_popup(r.msg);
 				}
			}
		});
	}	
	
	function update_registry_items()
	{
		var data="&count="+reg_quantity.length;
		for(i=0;i<reg_quantity.length;i++)
		{
		data+="&item_id"+i+"="+reg_quantity[i][0]+"&qnt"+i+"="+reg_quantity[i][1];
		}
		$.ajax({
		type: "POST",
		url: window.location.pathname,
		data: "action=update_all_qnt_in_registry"+data,
		success: function (r)
		{
			r = eval(r);
			display_popup(r.msg);
        	$(a).parent().parent().parent().next().children('p:first').html(r.needed+"");
		}
	 });
	}

var reg_quantity =new Array();
	function update_registry_quantity(registry_item_id,a)
	{
	var qnt = $(a).parent().children('input:first').val();
	reg_quantity[reg_quantity.length] =new Array(registry_item_id,qnt);
	}
	
function add_event_to_cart(event_id,vip_event_id)
{	
	var vip_qnt = 0;
	var gen_qnt = 0;
	var vip_qnt = $('#vip_qnt').val();
	var gen_qnt = $('#gen_qnt').val();
	if( vip_qnt == 0 && gen_qnt == 0)
	{
		alert('Please select quantity');
		return false;
	}
	if(vip_qnt=="undefined")
	{
		alert('Please select quantity');
		return false;
	}
	$("#shade").css('height', $(document).height());
	$("#shade").show();
	setTimeout('',5000);

	$.ajax({
		type: "POST",
		url: "/event/around-australia-in-80-sips-dash-los-angeles",
		data: "action=add_to_cart&item_id="+ event_id + "&vip_qnt="+ vip_qnt + "&gen_qnt=" +gen_qnt + "&vip_event_id=" + vip_event_id,
		success: function (r)
		{
			r = eval(r);

			if ( r.code == 0 )
			{
				//display_popup(r.msg);
				window.location.href = '/shopping-cart';				
			}
			display_popup(r.msg);
			 
			
		}
	 });
}

function share_event_to_friend(a, id)
{
	$.ajax({
		type: "POST",
		url: "/mybottlenotes",
		data: "action=get_event_description&id="+id,
		success: function (r)
		{
			r = eval(r);

			if( r.code == 0 )
			{
				
				if(Base64.decode(r.description)!="")
				{
				$('#send-popup-form1 #story').val(Base64.decode(r.description));
				}
				$('#send-popup-form1 #event').val(r.event);
				$('#send-popup-form1 #url').val(r.url);
			  	$('#send-popup-form1').show();
				$("#shade").css('height', $(document).height());
	            $("#shade").show();
	            $('#send-popup-form1 #to').focus();
			}
		}
	});
}

function wine_encylopedia_form(id,title)
{       
        var val = $('#sign'+id).html();
	    if($('#'+id).is(':visible')){
		$('#anchor'+id).html(' + '+title);
		}
		else
		{
		$('#anchor'+id).html(' - '+title);
		}
		$('#'+id).toggle(100);
		

}

function dsdeallist(id)
{       
	
	$.ajax({
		type: "POST",
		url:  window.location.pathname,
		data: "action=deallist&id="+id,
		success: function (data)
		{
			data=eval(data);
			if(data.code==0){
			$("#resultslist").html(data.html);
			}
		}
	});
}

