
/** PM  **/


// feedback LB 
function openGedichtEditLb(id)
{	
	Lightbox.showBoxByAJAX('php_bin/admincenter/edit_gedicht_lb.php?id='+id,630,550);	
}

function pwEdit(form_id)
{		
	$$(".error").each(Element.hide);
	$("success_pw_edit").hide();
	
	var url = 'php_bin/admincenter/pw_edit.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onPwEditSuccess
						  }
					);
}

function onPwEditSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("success_pw_edit").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}


function emailEdit(form_id)
{		
	$$(".error").each(Element.hide);
	$("success_email_edit").hide();
	
	var url = 'php_bin/admincenter/email_edit.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onEmailEditSuccess
						  }
					);
}

function onEmailEditSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("success_email_edit").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}
/* [END OF MODULE] Admincenter *****************************************/



/** kontakt.js **/
// handle Errors
function emptyInput(id)
{
	$(id).value = "";	
}

// register LB 
function openRegisterLb()
{	
	Lightbox.showBoxByAJAX('php_bin/register_lb.php',630,600);	
}


function registerSend(form_id)
{		
	
	$$('.error').each(Element.hide);	
	$("register_success").hide();
	
	var url = 'php_bin/security/register.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onRegisterSendSuccess
						  }
					);
}

function onRegisterSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$$('.error').each(Element.hide);		
		$("register_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

// pw vergessen LB 
function openPmVergessenLb()
{	
	username = $('username').value;
	Lightbox.showBoxByAJAX('php_bin/pw_vergessen_lb.php?username='+username,630,600);	
}

function pwVergessenSend(form_id)
{		
	
	$$('.error').each(Element.hide);	
	$("pw_vergessen_success").hide();
	
	var url = 'php_bin/security/pw_vergessen.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onPwVergessenSendSuccess
						  }
					);
}

function onPwVergessenSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$$('.error').each(Element.hide);		
		$("pw_vergessen_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}


function loginSend(form_id)
{		
	
	$$('.error').each(Element.hide);	
		
	var url = 'php_bin/security/login.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onLoginSendSuccess
						  }
					);
}

function onLoginSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$$('.error').each(Element.hide);
		document.location.href = result_obj.action;		
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** LOGOUT **/
function logout()
{			
	var url = 'php_bin/security/logout.php';
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onLogoutSendSuccess
						  }
					);
}

function onLogoutSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		document.location.href = result_obj.action;				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}
/* [END OF MODULE] Login ***********************************************/



/** kontakt.js **/

function changeKat(kat_id)
{
	var url = 'php_bin/index/change_kat.php?kat='+kat_id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onChangeKatSuccess
						  }
					);
	
}

function onChangeKatSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		
		answer = result_obj.answer;
		$('subkat_container').innerHTML = answer;
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}


function insertSend(form_id)
{		
	
	$("nachricht_erfolg").hide();
	$("no_text").hide();
	$("no_kat").hide();
	$("no_autor").hide();
	$("no_titel").hide();
	$("kat_nicht_passend").hide();
	$("choose_subkat").hide();
	
	
	
	var url = 'php_bin/index/send_insert.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onInsertSendSuccess
						  }
					);
}

function onInsertSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		$("no_text").hide();
		$("no_kat").hide();
		$("no_autor").hide();
		$("no_titel").hide();
		$("kat_nicht_passend").hide();	
		$("choose_subkat").hide();
		$("nachricht_erfolg").show();
		
		$("titel").value = "";	
		$("tags").value = "";	
		$("text").value = "";	
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}


function updateTags(form_id)
{			
	$("nachricht_erfolg").hide();	
	$("gedicht_error").hide();
	
	var url = 'php_bin/index/update_tags.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onUpdateTagsSuccess
						  }
					);
}

function onUpdateTagsSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		$("nachricht_erfolg").show();
		$("gedicht_error").hide();
		
		$("id").value = "";	
		$("tags").value = "";	
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/* [END OF MODULE] Insert **********************************************/



//** INDEX JS **//

function fadeContent(id)
{	
	if(id != GLOBAL['acct_fade_tab']){		
	
		new Effect.Opacity(id, { from: 0.0, to: 1.0, duration: 0.5 });		
		new Effect.Opacity(GLOBAL['acct_fade_tab'], { from: 1.0, to: 0.0, duration: 0.5 });
		
		$(id).style.zIndex = 9999;
		$(GLOBAL['acct_fade_tab']).style.zIndex = 0;
				
		GLOBAL['acct_fade_tab'] = id;
	}
	
}

// feedback LB 
function openMuttertagLb()
{	
	Lightbox.showBoxByAJAX('php_bin/index/muttertag_lb.php',630,550);	
}
/* [END OF MODULE] Index ***********************************************/



// general.js
var globals = new Array();
globals["name"] = "ccf";

// check browser
var browser, agent, ns=0, ie=0, op=0;
browser = navigator.appName.toLowerCase();
agent = navigator.userAgent.toLowerCase();

globals["browser"] = "ot"; // other
if(browser.indexOf("explorer") >-1) globals["browser"] = "ie";
if(browser.indexOf("netscape") >-1) globals["browser"] = "ns";
if(agent.indexOf("opera") >-1) globals["browser"] = "op";
if(agent.indexOf("mozilla") >-1 && globals["browser"] != "ie") globals["browser"] = "mo"; // mozilla

// -- update avatar -------------------------------------------------------
function updateUserAvatar(form_id, action, target)
{
	globals['useravatar_form_id'] = form_id;
	
	$$('.error').each(Element.hide);	
	$('loading').show();
	$('send_button').hide();
	
	// - show hide -
	$('avatar_flash_iframe').hide();
	
	// break conditions
	if( $('avatar_input').value.split(' ').join().length == 0 )
	{
		$('avatar_no_file_selected').show();
		
		// show hide
		onReceiveForm(form_id)
		
		return;		
	}
	// - sbumit form -
	var old_action = $(form_id).action;
	var old_target = $(form_id).target;
	
	$(form_id).action = action;
	$(form_id).target = target;
	$(form_id).submit();
	
	// reset action an target
	$(form_id).action = old_action;
	$(form_id).target = old_target;	
}

// request got valid answer
function onUserAvatarSuccess()
{
	
	$('loading').hide();
	$('send_button').show();
	var form_id = globals['useravatar_form_id'];

	// show avatar_upload_finished
	$('avatar_upload_finished').show();
	
	// show flash resize iframe
	$('avatar_flash_iframe').show();
}

// request got valid answer
function onUserAvatarSaved()
{
	var form_id = globals['useravatar_form_id'];
	
	// show hide
	//onReceiveForm(form_id);
	
	// show avatar_change_finished
	$('avatar_change_finished').show();
	
	reloadUserboxAvatarImage();
}

function reloadUserboxAvatarImage()
{
	var img = $($$('.switch_logged #logged_in .user_img')[0]);
	var bg_img = img.getStyle('background-image').split(')'); 
	var img_pre = bg_img[0].split('?'); // remove previous ?=2342 if necessary
	var new_img = img_pre[0] + '?' + Math.random()*9999 + ')' + bg_img[1];
	img.setStyle({'backgroundImage': new_img});
}

/** USER DATA STORE **/
function saveProfileData(form_id)
{		
	
	$$('.error').each(Element.hide);	
	$("user_data_success").hide();
	
	var url = 'php_bin/user/profile_save.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onSaveProfileDataSuccess
						  }
					);
}

function onSaveProfileDataSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$$('.error').each(Element.hide);		
		$("user_data_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** AUTOR WERDEN **/
function autorWerden(form_id)
{	
	$$('.error').each(Element.hide);	
	$("autor_werden_success").hide();
	
	var url = 'php_bin/user/autor_werden.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onAutorWerdenSuccess
						  }
					);
}

function onAutorWerdenSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$$('.error').each(Element.hide);		
		$("autor_werden_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** AUTOR FREISCHALTEN **/
function acceptAutor(id)
{	
	//$("autor_werden_success").hide();
	globals['id'] = id;
	var url = 'php_bin/user/autor_freischalten.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onAcceptAutorSuccess
						  }
					);
}

function onAcceptAutorSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	id = globals['id'];
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("autor_freischalten_success"+id).show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** AUTOR ABLEHNEN **/
function denyAutor(id)
{	
	//$("autor_werden_success").hide();
	globals['id'] = id;
	var url = 'php_bin/user/autor_deny.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDenyAutorSuccess
						  }
					);
}

function onDenyAutorSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	id = globals['id'];
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("autor_deny_success"+id).show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function openAutorDenyLb(name,id)
{	
	Lightbox.showBoxByAJAX('php_bin/pm/view_pm_lb.php?name='+name,630,550);	
	denyAutor(id);
}


/** GÄSTEBUCH **/
function sendGbEntry(form_id)
{	
	$('kommentar_success').hide();
	$$('.notice_vote').each(Element.hide);	

	var url = 'php_bin/gb/send_gb.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onSendGbEntrySuccess
						  }
					);
}

function onSendGbEntrySuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		
		$('text').innerHTML = "";
		$('kommentar_success').show();
		
		// DOM insert new gb entry
		str = $('new_comment_container').innerHTML;
		var template = new Template(str);
		new Insertion.After('komment_entry_insert_after', template.evaluate(result_obj)) ;
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function deleteGb(id)
{	
	$('gb_'+id).hide();	

	var url = 'php_bin/gb/delete_gb.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeleteGbSuccess
						  }
					);
}

function onDeleteGbSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function addFriendlist(name)
{	
	$('allready_friend').hide();
	$('is_self').hide();	
	$('success_friendlist').hide();	
	

	var url = 'php_bin/user/add_friendlist.php?friend='+name;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onAddFriendlistSuccess
						  }
					);
}

function onAddFriendlistSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		$('success_friendlist').show();	
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function deleteFromFriendlist(id)
{	
	$('friend_tr_'+id).hide();	

	var url = 'php_bin/user/delete_from_friendlist.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeleteFromFriendlistSuccess
						  }
					);
}

function onDeleteFromFriendlistSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function gotoFriend(name){
	if(name != "") document.location.href = "user/"+name+"/";	
}

function toggleUserpageContent()
{
	$('show_gedichte').toggle();
	$('show_userpage').toggle();
	$('userpage_content').toggle();
	$('usergedichte_content').toggle();
}
/* [END OF MODULE] User ************************************************/



/** kontakt.js **/
// handle Errors
function handleErrors(errors)
{
	$A(errors).each(showMsg);
}

function showMsg(v)
{
	var msg = $(v);
	if(msg != null) msg.show();	
}

function kontaktSend(form_id)
{		
	
	$("nachricht_erfolg").hide();
	$("no_name").hide();
	$("no_email").hide();
	$("no_text").hide();
	$("invalid_email").hide();
	
	
	var url = 'php_bin/index/send_kontakt.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onKontaktSendSuccess
						  }
					);
}

function onKontaktSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("nachricht_erfolg").show();
		$("no_name").hide();
		$("no_email").hide();
		$("no_text").hide();
		$("invalid_email").hide();	
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

// feedback LB 
function openFeedbackLb()
{	
	Lightbox.showBoxByAJAX('php_bin/index/feedback_lb.php',630,550);	
}

function feedbackSend(form_id)
{		
	
	$("feedback_success").hide();
	
	var url = 'php_bin/index/send_feedback.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onFeedbackSendSuccess
						  }
					);
}

function onFeedbackSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("feedback_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

// empfehlen LB 
function openEmpfehlenLb(titel,id)
{	
	Lightbox.showBoxByAJAX('php_bin/index/empfehlen_lb.php?titel='+titel+'&id='+id,630,600);	
}

function empfehlenSend(form_id)
{		
	
	$("error_name").hide();
	$("error_email_leer").hide();
	$("error_email_valid").hide();
	$("error_to").hide();
	
	$("empfehlen_success").hide();
	
	var url = 'php_bin/index/send_empfehlen.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onEmpfehlenSendSuccess
						  }
					);
}

function onEmpfehlenSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("error_name").hide();
		$("error_email_leer").hide();
		$("error_email_valid").hide();
		$("error_to").hide();
		
		$("empfehlen_success").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/* [END OF MODULE] Kontakt *********************************************/



// -- update avatar -------------------------------------------------------

function toggleId(id){
	$(id).toggle();
}

function changeStar(value)
{
	for(i = 1; i<=value; i++){
		$('bewerten_'+i).className = "star_yellow";
	}	
}

function removeStar()
{
	for(i = 1; i<=5; i++){
		$('bewerten_'+i).className = "star_grey";
	}	
}

function vote(id,value)
{		
	var url = 'php_bin/gedicht/vote.php?id='+id+"&value="+value;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onVoteSendSuccess
						  }
					);
}

function onVoteSendSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{				
		window.location.reload( false );	
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function sendKommentar(form_id)
{	
	$('kommentar_success').hide();
	$$('.notice_vote').each(Element.hide);	

	var url = 'php_bin/gedicht/send_kommentar.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onSendKommentarSuccess
						  }
					);
}

function onSendKommentarSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		$('kommentar').innerHTML = "";
		$('kommentar_success').show();
		
		// DOM insert new gb entry
		str = $('new_comment_container').innerHTML;
		var template = new Template(str);
		new Insertion.After('komment_entry_insert_after', template.evaluate(result_obj)) ;
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function deleteKommentar(id)
{	
	$('comment_'+id).hide();	

	var url = 'php_bin/gedicht/delete_kommentar.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeleteKommentarSuccess
						  }
					);
}

function onDeleteKommentarSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** GEDICHT FREISCHALTEN **/
function acceptGedicht(id)
{	
	//$("autor_werden_success").hide();
	globals['id'] = id;
	var url = 'php_bin/user/gedicht_freischalten.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onAcceptGedichtSuccess
						  }
					);
}

function onAcceptGedichtSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	id = globals['id'];
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("gedicht_freischalten_success"+id).show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** GEDICHT ABLEHNEN **/
function denyGedicht(id)
{	
	//$("autor_werden_success").hide();
	globals['id'] = id;
	var url = 'php_bin/user/gedicht_deny.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDenyGedichtSuccess
						  }
					);
}

function onDenyGedichtSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	id = globals['id'];
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("gedicht_deny_success"+id).show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function openDenyGedichtLb(name,id)
{	
	Lightbox.showBoxByAJAX('php_bin/pm/view_pm_lb.php?name='+name,630,550);	
	denyGedicht(id);
}

/** UPDATE GEDICHT **/

function updateGedicht(form_id)
{		
	
	$("nachricht_erfolg").hide();
	$("no_text").hide();
	$("no_kat").hide();
	$("no_autor").hide();
	$("no_titel").hide();
	$("kat_nicht_passend").hide();
	
	
	
	var url = 'php_bin/admincenter/edit_gedicht.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onUpdateGedichtSuccess
						  }
					);
}

function onUpdateGedichtSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		$("no_text").hide();
		$("no_kat").hide();
		$("no_autor").hide();
		$("no_titel").hide();
		$("kat_nicht_passend").hide();	
		$("nachricht_erfolg").show();		
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

/** DELETE GEDICHT **/

function deleteGedicht(id)
{		
	
	var url = 'php_bin/admincenter/delete_gedicht.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeleteGedichtSuccess
						  }
					);
}

function onDeleteGedichtSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{	
		id = result_obj.id;
		$('gedicht_'+id).hide();
		$('gedicht_tr_'+id).hide();
			
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}



/* [END OF MODULE] Gedicht *********************************************/



/** PM  **/
if(GLOBAL == undefined) var GLOBAL = new Array();
GLOBAL['acct_fade_tab'] = 'content3';


// feedback LB 
function openPmLb(name,antwort)
{	
	if(name == undefined) name = "";
	if(antwort == undefined) antwort = "";
	Lightbox.showBoxByAJAX('php_bin/pm/view_pm_lb.php?name='+name+'&antwort='+antwort,630,550);	
}

function sendPm(form_id)
{		
	$$(".error").each(Element.hide);
	$("success_pm_send").hide();
	
	var url = 'php_bin/pm/send_pm.php';
	new Ajax.Request(url, {
							method: 'post',
							parameters: $(form_id).serialize(true),
							onSuccess: onSendPmSuccess
						  }
					);
}

function onSendPmSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
		$("success_pm_send").show();
				
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function deletePm(id)
{		
	$("pmrow_"+id).hide();
	$("pm"+id).hide();
	
	var url = 'php_bin/pm/delete_pm.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeletePmSuccess
						  }
					);
	
}

function onDeletePmSuccess(result)
{
	var result_obj = result.responseText.evalJSON();
	
	// if no errors occurrend
	if(result_obj.errors.length == 0)
	{		
						
	}
	else
	{	
		handleErrors(result_obj.errors);
	}
}

function updateIsRead(id)
{		

	var url = 'php_bin/pm/update_read_pm.php?id='+id;
	new Ajax.Request(url, {
							method: 'post',
							onSuccess: onDeletePmSuccess
						  }
					);	
}

function togglePmId(id,update){
	$("pm"+id).toggle();
	if(update) updateIsRead(id);
}

/* [END OF MODULE] Pm **************************************************/


