function showEvents()
{
	var currentVal = document.getElementById('events').style.display;
	var newVal;
	if(currentVal == 'none')
		newVal = 'block';
	else
		newVal = 'none';
	document.getElementById('events').style.display=newVal;
}

function processPriceRate(element, memo)
{
	var rating = memo.rated;
	var wine_id = element.id.replace("ratingPrice_", "");
	var midstr = "/journal/rank_wine.php?type=price&wine_id=" + wine_id + "&rating=" + rating;
	new Ajax.Request(midstr);

}
function processTasteRate(element, memo)
{
	var rating = memo.rated;
	var wine_id = element.id.replace("ratingTaste_", "");
	var midstr = "/journal/rank_wine.php?type=taste&wine_id=" + wine_id + "&rating=" + rating;
	new Ajax.Request(midstr);
}
function showComment(wine_id, user_id, comm_id ) {
	//alert('wine_id=' + wine_id + ' user_id=' + user_id + ' comm_id=' + comm_id );
	//var midstr = 'show_comment.php?wine_id=<?=$wine->getID()?>&user_id=<?=$myUser->getID()?>&comm_id=<?=$journalUser->getID()?>';
	var midstr = '/journal/show_comment.php?wine_id=' + wine_id + '&user_id=' + user_id + '&comm_id=' + comm_id;
	new Ajax.Updater('showComment', midstr);
}
function showEmail( id, wine_id, from_id, to_id, journal_id ) {
	//var midstr = '/journal/show_email.php?id=' + id + '&wine_id=<?=$wine->getID()?>&user_id=<?=$myUser->getID()?>&comm_id=<?=$journalUser->getID()?>';
	var midstr = '/journal/show_email.php?id=' + id + '&wine_id=' + wine_id + '&from_id=' + from_id + '&to_id=' + to_id + '&journal_id=' + journal_id;
	new Ajax.Updater('showEmail_' + id, midstr);
}
function showTastingNoteEmail( wine_id, user_id, from_id )
{
	var midstr = '/journal/show_tasting_note_email.php?wine_id=' + wine_id + '&user_id=' + user_id + '&from_id=' + from_id;
	new Ajax.Updater('showTastingNoteEmail', midstr );
}
function sendTastingNoteEmail( wine_id, user_id, from_id )
{
	// get the emails to send to
	var email_addresses = document.getElementById('email_addresses').value;
	var midstr = '/journal/send_tasting_note_email.php?wine_id=' + wine_id + '&user_id=' + user_id + '&from_id=' + from_id + "&email_addresses=" + email_addresses;
	new Ajax.Updater('showTastingNoteEmail', midstr );
}
function sendEmail( id, wine_id, from_id, to_id, journal_id ) {
	var email_subject = document.getElementById('email_subject').value;
	var email_body = document.getElementById('email_body').value;
	//var midstr = '/journal/send_email.php?wine_id=<?=$wine->getID()?>&user_id=<?=$myUser->getID()?>&comm_id=<?=$journalUser->getID()?>&journal_id=<?=$journalUser->getID()?>&email_subject=' + email_subject + '&email_body=' + email_body;
	var midstr = '/journal/send_email.php?wine_id=' + wine_id + '&from_id=' + from_id + '&to_id=' + to_id + '&journal_id=' + journal_id + '&email_subject=' + email_subject + '&email_body=' + email_body;
	new Ajax.Updater('showEmail_' + id, midstr );
}

function editComment(id, user_id, comm_id )
{
	var midstr = '/journal/edit_comment.php?user_id=' + user_id + '&comm_id=' + comm_id + '&comment_id=' + id;
	new Ajax.Updater('showComment', midstr);
	document.getElementById('comm_' + id).style.display="none";
}
function updateComment(id)
{
	var saveComm = document.getElementById("addComment").value;
	var saveTitle = document.getElementById("comm_title").value;
	var newBody = saveComm.replace(/(\r\n|[\r\n])/g, '<br/>');
	var midstr = '/journal/update_comment.php?comment_id=' + id + '&comm_title=' + saveTitle + '&comm_text=' + newBody;
	new Ajax.Updater('showComment', midstr);
	document.getElementById('title_' + id).innerHTML=saveTitle;

	document.getElementById('text_' + id).innerHTML=newBody;
	document.getElementById('comm_' + id).style.display="block";
}
function saveComment(wine_id, user_id, comm_id) {
	//alert('wine_id=' + wine_id + ' user_id=' + user_id + ' comm_id=' + comm_id );
	var saveComm = document.getElementById("addComment").value;
	var saveTitle = document.getElementById("comm_title").value;
	var newBody = saveComm.replace(/(\r\n|[\r\n])/g, '<br/>');
	//var midstr = '/journal/save_comment.php?wine_id=<?=$wine->getID()?>&user_id=<?=$myUser->getID()?>&comm_id=<?=$journalUser->getID()?>&comm_title=' + encode64(saveTitle) + '&comm_text=' + encode64(saveComm);
	var midstr = '/journal/save_comment.php?wine_id=' + wine_id + '&user_id=' + user_id + '&comm_id=' + comm_id + '&comm_title=' + saveTitle + '&comm_text=' + newBody;
	new Ajax.Updater('showComment', midstr);
}
function removeComment(author, id, owner) {
	var midstr = '/journal/remove_comment.php?comm_id=' + id + '&owner=' + owner + '&jour_id=' + author ;
	new Ajax.Updater('showComment', midstr);
	document.getElementById('comm_' + id).style.display="none";
}
function OremoveComment(author, id, owner) {
	var midstr = '/journal/remove_comment.php?comm_id=' + id + '&owner=' + owner;
	new Ajax.Updater('showComment', midstr);
	document.getElementById('comm_' + id).style.display="none";
}
function doInfoEdit( wine_id, add_user ) {
	var midstr = '/journal/edit_wine_info.php?wine_id=' + wine_id + '&add_user=' + add_user;
	new Ajax.Updater('editBio', midstr);
}
function saveInfoEdit( wine_id ) {
	var saveText = document.getElementById("infotext").value;
	var breakedSave = saveText.replace(/(\r\n|[\r\n])/g, '<br/>');
	var midstr = '/journal/save_wine_info.php?wine_id=' + wine_id + '&infotext=' + breakedSave;
	new Ajax.Updater('editBio', midstr);
	
	document.getElementById("userInfo").innerHTML = breakedSave;
}
function addToJournal(wine_id,member_id, alternate_id) {
	var midstr = '/wines/add_to_journal.php?wine_id=' + wine_id + '&member=' + member_id + '&alternate_id=' + alternate_id;
	new Ajax.Updater('wineadd', midstr);
}
function addWineToEvent(wine_id, event_id, alternate_id, user_id ) {
	var midstr = "/local_events/add_wine_to_event.php?event=" + event_id + "&wine_id=" + wine_id + "&alternate_id=" + alternate_id + "&user=" + user_id;
	new Ajax.Updater('add_to_event_msg', midstr);
}

function removeFromJournal(wine_id)
{
	var cfrm = confirm("Are you sure you want to remove this wine from your journal?");
	if(cfrm)
	{
		var midstr = "/journal/index.php?action=remove_wine&wine_id=" + wine_id;
		window.location=midstr;
	}
}
function blockUser( block_user, block_comment )
{
	var midstr = '/journal/block_user.php?block_id=' + block_user;
	new Ajax.Updater( 'comm_' + block_comment, midstr );
}

//functions to move values from one select box to another
function singleMoveRight()
{
	for(var i= document.getElementById('favorite_members').length-1; i >= 0; i-- )
	{
		if(document.getElementById('favorite_members')[i].selected)
		{
			// create the new element at the end of the list
			document.getElementById('selected_members')[document.getElementById('selected_members').length] = new Option(document.getElementById('favorite_members')[i].text,
				document.getElementById('favorite_members')[i].value);
			document.getElementById('favorite_members')[i] = null;
		}
	}
}

function singleMoveLeft()
{
	for(var i= document.getElementById('selected_members').length-1; i >= 0; i-- )
	{
		if(document.getElementById('selected_members')[i].selected)
		{
			// create the new element at the end of the list
			document.getElementById('favorite_members')[document.getElementById('favorite_members').length] = new Option(document.getElementById('selected_members')[i].text,
				document.getElementById('selected_members')[i].value);
			document.getElementById('selected_members')[i] = null;

		}
	}
}

function allMoveLeft()
{
	for(var i= document.getElementById('selected_members').length-1; i >= 0; i-- )
	{
			// create the new element at the end of the list
			document.getElementById('favorite_members')[document.getElementById('favorite_members').length] = new Option(document.getElementById('selected_members')[i].text,
				document.getElementById('selected_members')[i].value);
		document.getElementById('selected_members')[i] = null;
	}
}

// functions to move values from one select box to another
function allMoveRight()
{
	for(var i= document.getElementById('favorite_members').length-1; i >= 0; i-- )
	{
		// create the new element at the end of the list
		document.getElementById('selected_members')[document.getElementById('selected_members').length] = new Option(document.getElementById('favorite_members')[i].text,
				document.getElementById('favorite_members')[i].value);
		document.getElementById('favorite_members')[i] = null;
	}
}

