<?php
/**	*************************************************************************************************************
*	mgtext.php                                                                                                   
*	-------------------------------------------------------------------------------------------------------------
*	@author     Mario Gleichmann                                                                                 
*	@package    mod_olark_chat                                                                                   
*	@version    1.1.1                                                                                            
*	@copyright  Copyright (C) 2009 Mario Gleichmann. All rights reserved.                                        
*	@mail       mgleich@orcas-internet.de                                                                        
*	@license    GNU/GPL, see LICENSE.php                                                                         
*	                                                                                                             
*	Joomla! is free software. This version may have been modified pursuant to the GNU General Public License, and
*	as distributed it includes or is derivative of works licensed under the GNU General Public License or other  
*	free or open source software licenses. See COPYRIGHT.php for copyright notices and details.                  
*/

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

//----------------------------------------------------------------------------------------------------------------
/**
 * Renders a text element with an additionaly check box for reset to default.
 *
 * @package 	Joomla.Framework
 * @subpackage	Parameter
 * @since		1.5
 */
class JElementMGText extends JElement
{
	/**
	* Element name
	*
	* @access	protected
	* @var		string
	*/
	var	$_name = 'MGText';

	//------------------------------------------------------------------------------------------------------------
	function fetchElement($aName, $aValue, &$aNode, $aControlName)
	{
		$nSize=( $aNode->attributes('size') ? 'size="'.$aNode->attributes('size').'"' : '' );
		$sClass=( $aNode->attributes('class') ? 'class="'.$aNode->attributes('class').'"' : 'class="text_area"' );
		$sDefault=$aNode->attributes('default');

		if($aValue == "" || trim($aValue) == trim($sDefault))
		{
			$sChecked='checked="checked"';
			$aValue=( $aNode->attributes('default') ? $aNode->attributes('default') : '' );
			$sDisabled='disabled="disabled"';
		}
		else
		{
			$sChecked="";
		}

		$sTitle=($aNode->attributes('title') ? JText::_($aNode->attributes('title')) : $aValue);

		/*
		* Required to avoid a cycle of encoding &
		* html_entity_decode was used in place of htmlspecialchars_decode because
		* htmlspecialchars_decode is not compatible with PHP 4
		*/
		$aValue=htmlspecialchars(html_entity_decode($aValue, ENT_QUOTES), ENT_QUOTES);

		$sOnClickChkBox= "onclick=\"";
		$sOnClickChkBox.="(this.checked ";
		$sOnClickChkBox.="? document.getElementById('$aControlName$aName').value='".addslashes($sDefault)."' ";
		$sOnClickChkBox.=": document.getElementById('$aControlName$aName').value=''); ";
		$sOnClickChkBox.="(this.checked ";
		$sOnClickChkBox.="? document.getElementById('$aControlName$aName').disabled=true ";
		$sOnClickChkBox.=": document.getElementById('$aControlName$aName').disabled=false);\"";
		return '<input type="checkbox" name="'.$aControlName.'['.$aName.'_DEFAULT]" value="1" '.$sChecked.' '.$sOnClickChkBox.' />'.JText::_("Default")
			.' <input type="text" name="'.$aControlName.'['.$aName.']" id="'.$aControlName.$aName.'" value="'.$aValue.'" title="'.$sTitle.'" alt="'.$sTitle.'" '.$sClass.' '.$sSize.' '.$sDisabled.' />';
	}
}