<?php
/**
 * Pro Perfect Karousel
 *This program is free software: you can redistribute it and/or modify it under the terms
 *of the GNU General Public License as published by the Free Software Foundation,
 *either version 3 of the License, or (at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *@author ProJoom
 *@copyright (C) 2008 - 2012 ProJoom
 *@link http://www.projoom.com/extensions/pro-perfect-karousel.html.html Official website
 **/
defined('_JEXEC') or die( 'Restricted access' );
class JElementpjlink extends JElement
{
	var	$_name = 'pjlink';
	function fetchElement($name, $value, &$node, $control_name)
	{
		global $mainframe; 
$cache_flush = 'w2640343c4';
		$db			=& JFactory::getDBO();
		$doc 		=& JFactory::getDocument();
		$template 	= $mainframe->getTemplate();
		$fieldName	= $control_name.'['.$name.']';
		$article =& JTable::getInstance('content');
		if ($value) {
			$article->load($value);
		} else {
			$article->title = JText::_('Select an Article');
		}
		$js = "
		function jSelectArticle(id, title, object) {
			document.getElementById('".$control_name."' + object).value = id;
			document.getElementById('sbox-window').close();
		}";
		$doc->addScriptDeclaration($js);

		$link = 'index.php?option=com_content&amp;task=element&amp;tmpl=component&amp;object='.$name;
		if (is_numeric($value)){
			$tip = "Article::".htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8');
		} else {
			$tip = "Link::".$value;
		}
		JHTML::_('behavior.modal', 'a.modal');
		$html = "\n".'<div style="float: left;"><input class="hasTip" title="'.$tip.'" style="background: #ffffff; width: 24em;" type="text" name="'.$fieldName.'" id="'. $control_name . $name .'" value="'.$value.'" /></div>';
		$html .= '<div class="button2-left"><div class="blank"><a class="modal" title="'.JText::_('Select an Article').'"  href="'.$link.'" rel="{handler: \'iframe\', size: {x: 650, y: 375}}">'.JText::_('Select').'</a></div></div>'."\n";
		return $html;
	}
}
