/*======================================================================*\
|| #################################################################### ||
|| # Benutzernotizen 1.1.1
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2007 Stoebi & Surviver
|| # This file may not be redistributed in whole or significant part. # ||
|| # http://vbulletin.pytalhost.org/hacks/index.php?productid=usernotes&show=supporturl
|| #################################################################### ||
\*======================================================================*/

var usernotes_errors_shown = false;
var usernotes_notices_shown = false;

/**
* This Function sends the udernotes to the ajax.php and check ajax compatiblity
*
* @param	string	Content of the note
*/

function send_usernotes(event, note)
{
	notehandler = new vB_AJAX_Handler(true);
	if (!notehandler.is_compatible())
	{
		return true;
	}
	
	if (is_ie)
	{
		event.cancelBubble = true;
	}
	else
	{
		event.stopPropagation();
	}
	
	usernotes_hide_notice();
	usernotes_hide_errors();
	notehandler.onreadystatechange(handle_usernotes);
	notehandler.send('ajax.php?' + SESSIONURL + 'do=updateusernotes', 'notes=' + PHP.urlencode(note));
	return false;
}

/**
* This Function handels teh usernotes respons. If tehere are any errors, they will be displayed, else a suc note will be displayed.
*/
function handle_usernotes()
{
	if (notehandler.handler.readyState == 4 && notehandler.handler.status == 200)
	{
		if (notehandler.handler.responseXML)
		{
			if(fetch_tags(notehandler.handler.responseXML, 'error').length)
			{
				usernotes_show_errors(notehandler.fetch_data(fetch_tags(notehandler.handler.responseXML, 'error')[0]));
				return false;
			}
			
			if(fetch_tags(notehandler.handler.responseXML, 'response').length)
			{
				usernotes_hide_errors();
				usernotes_show_notice(notehandler.fetch_data(fetch_tags(notehandler.handler.responseXML, 'response')[0]));
				return false;
			}
		}
	}
	return false;
}

/**
* Shows Errors occoured while trying to save the notes
*
* @param	string	Content of the Error-Message
*/
function usernotes_show_errors(errortext)
{
	usernotes_hide_notice();
	usernotes_errors_shown = true;
	fetch_object('usernotes_error_td').innerHTML = errortext + ' <a  style="color: #FF9900;" onclick="return usernotes_hide_errors();">[x]</a>';
	fetch_object('usernotes_error_tbody').style.display = '';
}

/**
* Shows the Notice (eg Usernotes successfully saved)
*
* @param	string	Content of the Notice
*/
function usernotes_show_notice(noticetext)
{
	usernotes_notices_shown = true;
	fetch_object('usernotes_notice_td').innerHTML = noticetext + ' <a style="color: #FF9900;" onclick="return hide_usernotes();">[x]</a>';
	fetch_object('usernotes_notice_tbody').style.display = '';
}

/**
* Hides the Error
*/
function usernotes_hide_errors()
{
	if(usernotes_errors_shown)
	{
		fetch_object('usernotes_error_tbody').style.display = 'none';
	}
}

/**
* Hides the Notice
*/
function usernotes_hide_notice()
{
	if(usernotes_notices_shown)
	{
		fetch_object('usernotes_notice_tbody').style.display = 'none';
	}
}

function hide_usernotes()
{
	vBmenu.hide(fetch_object('usernotes'));
	usernotes_hide_notice();
	usernotes_hide_errors();
	return false;
}

function count_down(textareaobj, countboxid, startcount)
{	
	boxobj = fetch_object(countboxid);	
	curr_count = startcount - textareaobj.value.length;	
	
	if(curr_count < 0)
	{
		textareaobj.value = textareaobj.value.substring(0, startcount);
		curr_count = 0;
	}
	
	boxobj.innerHTML = curr_count;
}

//File vbulletin_usernotes.js Created: 06/15/2007 23:15