<?php
/**
 * @package    Contact_Enhanced
 * @author     Douglas Machado {@link http://ideal.fok.com.br}
 * @author     Created on 28-Aug-10
 * @license		GNU/GPL, see license.txt
 * Contact Enhanced  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.
 */

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

/**
 * Renders a SQL element
 *
 * @package 	Contact_Enhanced
 * @since		1.5.7.1
 */

class JElementCampaignmonitorlist extends JElement
{
	/**
	* Element name
	*
	* @access	protected
	* @var		string
	*/
	var	$_name = 'Campaignmonitorlist';

	function fetchElement($name, $value, &$node, $control_name)
	{
		global $mainframe;
		$db			=& JFactory::getDBO();
		$doc 		=& JFactory::getDocument();
		$template 	= $mainframe->getTemplate();
		$fieldName	= $control_name.'['.$name.']';
		
		if (!$value){
			$title = JText::_('Select a list');
		}else {
			$title	= $value;
		}

		$js = "
		function jSelectItem(id, title, object) {
			document.getElementById(object + '_id').value = id;
			document.getElementById(object + '_name').value = title;
			document.getElementById('sbox-window').close();
		}";
		$doc->addScriptDeclaration($js);

		$link = 'index.php?option=com_contact_enhanced&task=element&tmpl=component&object='.$name.'&elemType=campaignmonitor';

		JHTML::_('behavior.modal', 'a.modal');
		$html = "\n".'<div style="float: left;">
		<input style="background: #ffffff;" type="text" id="'.$name.'_name" value="'.htmlspecialchars($title, ENT_QUOTES, 'UTF-8').'" disabled="disabled" /></div>';
//		$html .= "\n &nbsp; <input class=\"inputbox modal-button\" type=\"button\" value=\"".JText::_('Select')."\" />";
		$html .= '<div class="button2-left"><div class="blank">
				<a 
					class="modal" 
					onclick="this.href=this.href+\'&elemVar1=\'+$(\'paramscampaignmonitor_api_key\').value+\'&elemVar2=\'+$(\'paramscampaignmonitor_api_client\').value" 
					title="'.JText::_('Select a list').'"  
					href="'.$link.'" 
					rel="{handler: \'iframe\', size: {x: 650, y: 375}}">'.JText::_('Select')
				.'</a></div></div>'."\n";
		$html .= '<div class="button2-left"><div class="blank">
				<a href="javascript:void(0);" onclick="$(\''.$name.'_name\').value=\'\';$(\''.$name.'_id\').value=\'\';" >
				'.JText::_('Clear').'</a></div></div>'."\n";
		$html .= "\n".'<input type="hidden" id="'.$name.'_id" name="'.$fieldName.'" value="'.$value.'" />';

		return $html;
	}
}
