/**
 * shoutit
 *
 * @version      1.1
 * @author       Gabriel Freinbichler
 * @link         http://www.cmods-dev.de
 * @copyright    Copyright (C) 2007 by Gabriel Freinbichler
 * @license      http://www.gnu.org/copyleft/gpl.html GNU General Public License
 */


/*
 * ---------------------------------------------------------------------------------------------------------
 * javascript stuff
 * ---------------------------------------------------------------------------------------------------------
 */

preurl = "";

function initShoutItEventHandler()
{
	if (post_perm == 1){
		$('shoutitsend').observe('click', saveData, false);
		$('shoutitsend').observe('keypress', saveData, false);
	}
	
	if (is_dot8 >= 1)
	{
		preurl = document.location.pnbaseURL;
	}
}

function initShoutItEventHandlerAdmin()
{
	$('shoutitclear').observe('click', clearData, false);
	$('shoutitclear').observe('keypress', clearData, false);
}

var loadData = new Ajax.PeriodicalUpdater(
		             'shoutit_content', 
  	                 preurl + 'index.php?module=shoutit&type=ajax&func=getmessages',
	                 {
	                  method: 'get',
	                  frequency: 5
			 		 }
	                 );
	                 
function saveData()
{
	loadData.stop();				  
	new Ajax.Request(preurl + "index.php?module=shoutit&type=ajax&func=reply", {
	  parameters: {
	    message: $F('shoutitmessage')
	  }
	}
	); 
	loadData.start();
 
	$('shoutitmessage').value = '';
	$('shoutitmessage').focus();
}

function clearData()
{
	loadData.stop();	
	new Ajax.Request(preurl + "index.php?module=shoutit&type=ajax&func=clear", 
 				  {method:"post"
				  }
				  );
	loadData.start();
}