<?php

include 'tse-comments.php';
$smileys = tseCTI_get_smileys('all');
$smileypx = $_GET['smileysize'];
/* Start tsepop.htm */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Tango Smileys Extended: Insert Smiley</title>

<script type="text/javascript" src="<?php 
echo $_GET['tsepop'];
?>
"></script>
<script type="text/javascript">
var TSEDialog = {
	init : function(ed) {
		tinyMCEPopup.resizeToInnerSize();
	},

	insert : function insertTSE(code) {
    	tinyMCEPopup.execCommand('mceInsertContent', false, code);
		tinyMCEPopup.close();
	}
};
tinyMCEPopup.onInit.add(TSEDialog.init, TSEDialog);
</script>

<style type="text/css">
function tse_options_smiley_showcase($option)
{
    $smileys = tseCTI_get_smileys($option);
    $output = '';
    for ($i = 0; $i < sizeof($smileys); $i++) {
        $smiley = plugins_url("/tango/{$smileys[$i][1]}", __FILE__);
        $output .= "<img src='{$smiley}' alt='{$smileys[$i][2]}' title='{$smileys[$i][2]} ( {$smileys[$i][0]} )' />";
    }
    echo '<div class="showcase">' . $output . '</div>';
}
function tse_cti_anywhere($target = 'comment', $view = true, $showcase = 'none')
{
    $jsout = <<<JAVASCRIPT
\t<script language="javascript" type="text/javascript">
\t//<![CDATA[
\tfunction tseCTI{$target}(tseClicked) {
\t\tvar target;
\t\tif (document.getElementById('{$target}') && document.getElementById('{$target}').type == 'textarea') {
\t\t\ttarget = document.getElementById('{$target}');
\t\t\tscroll = target.scrollTop;
\t\t}
\t\telse {
\t\t\treturn false;
\t\t}
\t\tif (document.selection) {
\t\t\ttarget.focus();
\t\t\tsel = document.selection.createRange();
\t\t\tsel.text = tseClicked;
\t\t\ttarget.focus();
\t\t}
\t\telse if (target.selectionStart || target.selectionStart == '0') {
\t\t\tvar startPos = target.selectionStart;
\t\t\tvar endPos = target.selectionEnd;
\t\t\tvar cursorPos = endPos;
\t\t\ttarget.value = target.value.substring(0, startPos) + tseClicked + target.value.substring(endPos, target.value.length);
\t\t\tcursorPos += tseClicked.length;
\t\t\ttarget.focus();
\t\t\ttarget.selectionStart = cursorPos;
\t\t\ttarget.selectionEnd = cursorPos;
\t\t}
\t\telse {
\t\t\ttarget.value += tseClicked;
\t\t\ttarget.focus();
\t\t}
\t\ttarget.scrollTop = scroll;
\t}
\t//]]>
\t</script>
JAVASCRIPT;
    $smileys = tseCTI_get_smileys($showcase);
    $tse = get_option('tango_smileys_extended');
    $folder = $tse['smileysize'] >= 18 ? 'tango24' : 'tango';
    $output = '';
    for ($i = 0; $i < sizeof($smileys); $i++) {
        $smiley = plugins_url("/{$folder}/{$smileys[$i][1]}", __FILE__);
        $output .= "<img src='{$smiley}' alt='{$smileys[$i][2]}' title='{$smileys[$i][2]} ( {$smileys[$i][0]} )' onclick='javascript:tseCTI{$target}(\"{$smileys[$i][0]}\");' />";
    }
    $output = "{$jsout}<div id='tseCTIsmileys-{$target}'>{$output}</div>";
    if ($view) {
        echo $output;
    } else {
        return $output;
    }
}