
function printSchedule()
{
	var printWindow = window.open(WSD_WEBROOT+"users/user.inc-print-schedule.php");
}

/*
	Show the Comment Toolbar | user-comments.php
*/

function uc_ShowToolbar(i, hType)
{
	var ucTB = E('uctb_'+i);

	ucTB.style.display = (hType == 'in') ? 'block' : 'none';
}

function uc_ShowComment(i)
{
	var ucComm = E('uccomm_'+i);

	ucComm.style.display = (ucComm.style.display != 'block') ? 'block' : 'none';
}


/*
	Add Comment | comment-overview.php

	tableId: main id of target-table, located in the table `mod_tables`
	pTarget: main id of a record, located in the target-table
*/

function comment_Add(tableId, pTarget)
{
	var postContent = $('#commPreviewForm').serialize();

	var newSeq = 0;
	while(E('postItem_'+newSeq)){newSeq++;}
	
	var postParam = postContent+"&action=comment_add&tableId="+tableId+"&pTarget="+pTarget+"&comment_seq="+newSeq;

	$.post(WSD_WEBROOT+"users/comment-add.process.php", postParam, function(data)
	{
		comment_RequestAction(data, 'add');
	});

	return false;
}


/*
	Preview Comment | comment-overview.php

	activated from the preview textarea
*/

function comment_Preview()
{
	var postContent = $('#commPreviewForm').serialize();

	var postParam = postContent+"&action=comment_preview";

	$.post(WSD_WEBROOT+"users/comment-preview.php", postParam, function(data)
	{
		comment_RequestAction(data, 'preview');
	});

	return false;
}


/*
	Edit Comment (toggle) | comment-display.php

	i: unique number to identify and modify the div containing the comment
	pId: the main id of the comment, located in `comm_comments`, passed through ajax when submitting changes
*/

function comment_Edit(i, pId)
{
	// Edit Mode
	if($('#post_'+i).is(":visible"))
	{
		$('#post_'+i).hide();
		$('#postEdit_'+i).show();
		
		// preview text:
		$('#postPrev_'+i).hide();
	}

	// Preview Mode
	else
	{
		var postContent = $('#postContent_'+i).serialize();

		var postParam = postContent+"&action=comment_parse";

		$.post(WSD_WEBROOT+"users/comment-item.inc-parse.php", postParam, function(data)
		{
			comment_RequestAction(data, 'preview_edit', i);
		});
	}

	return false;
}


/*
	Submit and Save Changes (from edit-toggle) | comment-display.php

	i: unique number to identify and modify the div containing the comment
	pId: the main id of the comment, located in `comm_comments`, passed through ajax when submitting changes
*/

function comment_Submit(i, pId)
{
	if($('#postEdit_'+i).length < 1) {return false;}

	var postContent = $('#postContent_'+i).serialize();

	var postParam = postContent+"&action=comment_edit&pId="+pId;

	$.post(WSD_WEBROOT+"users/comment-item.inc-edit.php", postParam, function(data)
	{
		comment_RequestAction(data, 'edit_finish', i, pId);
	});
}


/*
	Delete Comment | comment-display.php
*/

function comment_Delete(i, pId)
{
	var postParam = "action=comment_delete&pId="+pId;

	$.post(WSD_WEBROOT+"users/comment-item.inc-delete.php", postParam, function(data)
	{
		comment_RequestAction(data, 'delete', i, pId);
	});

	return false;
}


/*
	Create Preview-comment from 'Edit Comment'

	called when AJAX request is successfull
*/

function comment_EditPreview(i, newContent)
{
	comment_UpdateContent(i, newContent);
	
	// preview text:
	$('#postPrev_'+i).show();
}


/*
	Create Real-comment from 'Edit Comment'

	called when AJAX request is successfull
*/

function comment_SubmitFinish(i, newContent)
{
	comment_UpdateContent(i, newContent);

	// preview text:
	$('#postPrev_'+i).hide();
}


/*
	Update HTML Content for either preview or real
*/

function comment_UpdateContent(i, newContent)
{
	$('#post_'+i).html(newContent);

	// switch real/edit:
	$('#post_'+i).show();
	$('#postEdit_'+i).hide()
}


/*
	Create Preview Comment (from ajax request)
*/

function comment_CreatePreview(cContent)
{
	if(E('postItem_preview'))
	{
		E('commHolder').removeChild(E('postItem_preview'));
		E('commHolder').removeChild(E('postSep_preview'));
	}

	var postHolder = E('commHolder');

	postHolder.innerHTML = cContent + postHolder.innerHTML;
}


/*
	Add Real Comment (from ajax request)
*/

function comment_CreateReal(cContent)
{
	if(E('postItem_preview'))
	{
		E('commHolder').removeChild(E('postItem_preview'));
		E('commHolder').removeChild(E('postSep_preview'));
	}

	var postHolder = E('commHolder');

	postHolder.innerHTML = cContent + postHolder.innerHTML;
}


/*
	Comment Actions: Finish the Ajax Request
*/

function comment_RequestAction(data, pAction, i, pId)
{
	var responseStatus = data;

	if(!responseStatus.match(/^good(\:.*)?/gi))
	{
		alert("Error: "+responseStatus);
	}
	else
	{
		if(pAction == "preview")
		{
			cContent = responseStatus.replace(/^good(\:(.*))?/gi, '$2');

			comment_CreatePreview(cContent)
		}
		else if(pAction == "add")
		{
			cContent = responseStatus.replace(/^good(\:(.*))?/gi, '$2');

			comment_CreateReal(cContent)
		}
		else if (pAction == "preview_edit")
		{
			cContent = responseStatus.replace(/^good(\:(.*))?/gi, '$2');

			comment_EditPreview(i, cContent);
		}
		else if(pAction == "edit")
		{
			comment_Edit(i, pId);

			// hide preview message to overwrite the above function:
			E('postPrev_'+i).style.display = 'none';
		}
		else if (pAction == "edit_finish")
		{
			cContent = responseStatus.replace(/^good(\:(.*))?/gi, '$2');

			comment_SubmitFinish(i, cContent);
		}
		else if (pAction == "delete")
		{
			E('postItem_'+i).style.display = 'none';
			E('postSep_'+i).style.display = 'none';
		}
	}
}

function comment_UpdateCharacters()
{
	var cBox = E('postContent_preview');
	var charLeft = E('postCharLeft');
	var charTotal = E('postMaxLeft');

	var maxChar = charTotal.innerHTML;
	var currentChar = cBox.value.replace(/[\n]/gi, '\r\n').length;

	charLeft.innerHTML = parseInt(maxChar) - currentChar;
}

function bb_TogglePane(caller)
{
	var bbcodePane = document.getElementById("bbcodePane");

	if(bbcodePane.style.display != "block")
	{
		bbcodePane.style.display = "block";
	}
	else
	{
		bbcodePane.style.display = "none";
	}
}

function bb_AddCode ( str )
{
	var inputfield = document.getElementById('postContent_preview');
	inputfield.value += str;

	comment_UpdateCharacters();
}

/*
	end: Comments
*/



// This function is called when you click the 'Add to my schedule' button on a dj-detail page
function addArtistToMySchedule ( artistID )
{
	$.get(WSD_WEBROOT+"users/rpc.add-artist-to-my-schedule.php?artistID="+artistID, function(data){alert(data);});
}

// This function is called when you click the 'Add to my schedule' button on a dj-detail page
function removeArtistToMySchedule ( artistID )
{
	$.get(WSD_WEBROOT+"users/rpc.remove-artist-to-my-schedule.php?artistID="+artistID, function(data){alert(data);});
}

// This function is called when you click the 'Add to my buddies' button on a user profile page
function addUserToMyBuddies ( userID )
{
	$.get(WSD_WEBROOT+"users/rpc.add-user-to-my-buddies.php?userID="+userID, function(data){alert(data);});
}

// This function is called when you remove a friend from your friendslist @ profile->your friends
function removeUserFromMyBuddies ( userID )
{
	$.get(WSD_WEBROOT+"users/rpc.remove-user-from-my-buddies.php?userID="+userID, function(data){alert(data);});
}
