<?php

use Core\Database;
use Core\Db;

if (!defined('GAME_VERSION')) {
    require_once '_incl_data/autoload.php';
}

//10:05 Внимание! Вы успешно пополнили свой игровой счїт на <b>0.13 ЕКР</b>. Приятной Вам игры!

Database::init();

$u = User::start();
if (!isset($u->info['id'])) {
    header('location: /');
    die();
}

$ball = Db::getValue('select sum(ekr) from pay_operation where uid = ? and good > 0', [$u->info['id']]);

$day1def = 50; //сколько екр. в день можно менять на кр.
$day2def = 1000 * ($u->info['level'] - 7); //сколько кр. в день можно менять на екр.

$day1 = $day1def;
$day2 = $day2def;

if ($day2 < 0) {
    $day2 = 0;
}

$timetoday = strtotime(date('d.m.Y'));
$dc1 = Db::getValue('select sum(money2) from user_operation where time >= unix_timestamp() and uid = ? and type = ?', [$u->info['id'], 'Обмен ЕКР на КР']);
$dc2 = Db::getValue('select sum(money) from user_operation where time >= unix_timestamp() and uid = ? and type = ?', [$u->info['id'], 'Обмен КР на ЕКР']);

$day1 = round($day1 + $dc1, 2);
$day2 = round($day2 + $dc2, 2);

if ($day1 < 0) {
    $day1 = 0;
}
if ($day2 < 0) {
    $day2 = 0;
}


$b1 = 0; //бонус накопительный

$bt = Db::getRow('select cur, USD from bank_table order by time desc limit 1');


$bns = [
    [0, 0, 0],
    [10, 1, 0],
    [50, 2, 0],
    [100, 3, 0],
    [200, 4, 0],
    [300, 5, 0],
    [400, 6, 0],
    [500, 7, 0],
    [600, 8, 0],
    [700, 9, 0],
    [800, 10, 0],
    [900, 11, 0],
    [1000, 13, 1],
    [1100, 15, 2],
    [1200, 17, 3],
    [1300, 19, 4],
    [1500, 21, 5],
    [1700, 23, 6],
    [2000, 25, 7],
    [2500, 27, 8],
    [3000, 30, 9],
];

$bns2 = [
    [0, 0],
    [10, 10],
    [20, 10],
    [30, 10],
    [40, 10],
    [50, 10],
    [60, 10],
    [70, 10],
    [80, 10],
    [90, 10],
    [100, 20],
];

$i = 0;
while ($i < count($bns)) {
    if (isset($bns[$i][0]) && $ball > $bns[$i][0]) {
        $b1 = $i;
    }
    $i++;
}


if (isset($_POST['do']) && $_POST['do'] == 'newShadow') {
    $o = mysql_fetch_array(
        mysql_query(
            'SELECT * FROM `_obraz` WHERE `uid` = "' . $u->info['id'] . '" AND `good` = 0 AND `cancel` = 0 AND `img` = "' . mysql_real_escape_string(
                $_POST['ffinput']
            ) . '" LIMIT 1'
        )
    );
    if (!isset($o['id'])) {
        $u->error = 'Данный образ не найден! Возможно он уже был подтвержден!';
    } elseif ($o['price'] > $u->info['money2']) {
        $u->error = 'На счету недостаточно ЕКР';
    } else {
        //
        $u->info['money2'] -= $o['price'];
        mysql_query(
            'UPDATE `users` SET `money2` = "' . $u->info['money2'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
        );
        //
        mysql_query('UPDATE `_obraz` SET `good` = "' . time() . '" WHERE `id` = "' . $o['id'] . '" LIMIT 1');
        if ($o['type'] == 1 || $o['type'] == 2) {
            //Личный или Клановый
            copy(
                'clan_prw/' . $o['img'], './'.\Core\Config::get('img').'/i/obraz/' . $o['sex'] . '/buy' . $o['id'] . '.gif'
            );
        } elseif ($o['type'] == 3) {
            //Питомец
            copy('clan_prw/' . $o['img'], './'.\Core\Config::get('img').'/pet/buy' . $o['id'] . '.gif');
        } elseif ($o['type'] == 5) {
            //Питомец
            copy('clan_prw/' . $o['img'], './'.\Core\Config::get('img').'/i/smile/s' . $o['id'] . '.gif');
        }
        //
        if ($_POST['ffsex'] == 1) {
            $o['sex'] = 1;
        } elseif ($_POST['ffsex'] == 0) {
            $o['sex'] = 0;
        }
        //
        if ($o['clan'] > 0) {
            $o['uid1'] = 0;
        } else {
            $o['uid1'] = $o['uid'];
        }
        //
        if ($o['type'] == 1 || $o['type'] == 2) {
            //Личный и клановый
            mysql_query(
                'INSERT INTO `obraz` (
					`sex`,`uid`,`img`,`usr_add`,`clan`
				) VALUES (
					"' . $o['sex'] . '","' . $o['uid1'] . '","buy' . $o['id'] . '.gif","' . $o['uid'] . '","' . $o['clan'] . '"
				)'
            );
        } elseif ($o['type'] == 3) {
            //Питомца
            mysql_query(
                'INSERT INTO `obraz_pet` (
					`uid`,`time`,`img`
				) VALUES (
					"' . $u->info['id'] . '","' . time() . '","' . mysql_real_escape_string('buy' . $o['id'] . '.gif') . '"
				)'
            );
        } elseif ($o['type'] == 5) {
            //Смайлик
            $u->info['add_smiles'] .= ',s' . $o['id'] . '';
            $u->info['add_smiles'] = ltrim($u->info['add_smiles'], ',');
            mysql_query(
                'UPDATE `users` SET `add_smiles` = "' . $u->info['add_smiles'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
            );
        }
        //
        if ($o['type'] == 1) {
            $u->error = 'Личный образ успешно установлен! Можете выбрать его в инвентаре, в разделе Образ.';
        } elseif ($o['type'] == 2) {
            $u->error = 'Клановый образ успешно установлен! Можете выбрать его в инвентаре, в разделе Образ.';
        } elseif ($o['type'] == 3) {
            $u->error = 'Личный образ питомца успешно установлен! Можете выбрать его в инвентаре, в разделе Звери.';
        } elseif ($o['type'] == 5) {
            $u->error = 'Личный смайлик успешно установлен! Можете выбрать его в разделе Личные смайлики. Код смайлика <b>:s' . $o['id'] . ':</b>';
        }
    }
} elseif (isset($_FILES['img'])) {
    //Личный образ
    $ekr = 100;
    if ($u->info['money2'] < $ekr) {
        echo '{"err":"На счету недостаточно ЕКР"}';
    } else {
        $obraz = 'f_shadow1_' . $u->info['id'] . '-' . md5((time() - rand(0, 1000)) . '#shadow1') . '.gif';
        $upload = new Uploader('img', $obraz);
        $upload->setSavePath('clan_prw/');
        $upload->setExtentions('gif');
        $upload->setMaxFileSize(.5);
        $upload->setDimensions(120, 220);
        //
        if ($file = $upload->saveimg()) {
            mysql_query(
                'INSERT INTO `_obraz` ( `uid`,`time`,`price`,`good`,`cancel`,`img`,`sex`,`type`,`clan` ) VALUES (
					"' . $u->info['id'] . '",
					"' . time() . '",
					"' . mysql_real_escape_string($ekr) . '",
					"0",
					"0",
					"' . mysql_real_escape_string($obraz) . '",
					"' . $u->info['sex'] . '",
					"1",
					"0"
				) '
            );
            echo '{"img":"' . $obraz . '"}';
        } else {
            echo '{"err":"' . Uploader::$error . '"}';
        }
    }
    die();
} elseif (isset($_FILES['img5'])) {
    //Личный смайлик
    $ekr = 10;
    $ekr_smile = 10;
    if ($u->info['money2'] < $ekr) {
        echo '{"err":"На счету недостаточно ЕКР"}';
    } else {
        $obraz = 'f_smile_' . $u->info['id'] . '-' . md5((time() - rand(0, 1000)) . '#smile') . '.gif';
        $upload = new Uploader('img5', $obraz);
        $upload->setSavePath('clan_prw/');
        $upload->setExtentions('gif');
        $upload->setMaxFileSize(.05);
        $upload->setWidth(100, 15);
        $upload->setHeight(50, 15);
        //
        if ($file = $upload->saveimg()) {
            mysql_query(
                'INSERT INTO `_obraz` ( `uid`,`time`,`price`,`good`,`cancel`,`img`,`sex`,`type`,`clan` ) VALUES (
					"' . $u->info['id'] . '",
					"' . time() . '",
					"' . mysql_real_escape_string($ekr) . '",
					"0",
					"0",
					"' . mysql_real_escape_string($obraz) . '",
					"0",
					"5",
					"0"
				) '
            );
            echo '{"img":"' . $obraz . '"}';
        } else {
            echo '{"err":"' . Uploader::$error . '"}';
        }
    }
    die();
} elseif (isset($_FILES['img2'])) {
    //Клановый образ
    $ekr = 49.99;
    if ($u->info['clan'] == 0) {
        echo '{"err":"Вы должны состоять в клане"}';
    } elseif ($u->info['money2'] < $ekr) {
        echo '{"err":"На счету недостаточно ЕКР"}';
    } else {
        $obraz = 'f_shadow2_' . $u->info['id'] . '-' . md5((time() - rand(0, 1000)) . '#shadow2') . '.gif';
        $upload = new Uploader('img2', $obraz);
        $upload->setSavePath('clan_prw/');
        $upload->setExtentions('gif');
        $upload->setMaxFileSize(.3);
        $upload->setDimensions(120, 220);
        //
        if ($file = $upload->saveimg()) {
            mysql_query(
                'INSERT INTO `_obraz` ( `uid`,`time`,`price`,`good`,`cancel`,`img`,`sex`,`type`,`clan` ) VALUES (
					"' . $u->info['id'] . '",
					"' . time() . '",
					"' . mysql_real_escape_string($ekr) . '",
					"0",
					"0",
					"' . mysql_real_escape_string($obraz) . '",
					"' . $u->info['sex'] . '",
					"2",
					"' . $u->info['clan'] . '"
				) '
            );
            echo '{"img":"' . $obraz . '"}';
        } else {
            echo '{"err":"' . Uploader::$error . '"}';
        }
    }
    die();
} elseif (isset($_FILES['img4'])) {
    //Питомец образ
    $ekr = 4.99;
    if ($u->info['money2'] < $ekr) {
        echo '{"err":"На счету недостаточно ЕКР"}';
    } else {
        $obraz = 'f_shadow3_' . $u->info['id'] . '-' . md5((time() - rand(0, 1000)) . '#shadow3') . '.gif';
        $upload = new Uploader('img4', $obraz);
        $upload->setSavePath('clan_prw/');
        $upload->setExtentions('gif');
        $upload->setMaxFileSize(.3);
        $upload->setDimensions(120, 40);
        //
        if ($file = $upload->saveimg()) {
            mysql_query(
                'INSERT INTO `_obraz` ( `uid`,`time`,`price`,`good`,`cancel`,`img`,`sex`,`type`,`clan` ) VALUES (
					"' . $u->info['id'] . '",
					"' . time() . '",
					"' . mysql_real_escape_string($ekr) . '",
					"0",
					"0",
					"' . mysql_real_escape_string($obraz) . '",
					"' . $u->info['sex'] . '",
					"3",
					"' . $u->info['clan'] . '"
				) '
            );
            echo '{"img":"' . $obraz . '"}';
        } else {
            echo '{"err":"' . Uploader::$error . '"}';
        }
    }
    die();
} elseif (isset($_POST['kr001'])) {
    //Обмен екр на кр.
    $kr = round($_POST['kr001'], 2);
    if ($c['crtoecr'] < 0.01) {
        $u->error = 'Сегодня обменник закрыт.';
    } elseif ($day2 < 0.01) {
        $u->error = 'Сегодня для вас обмен закрыт, приходите завтра.';
    } elseif ($kr < round($c['crtoecr'] / 100, 2)) {
        $u->error = 'Минимальная сумма обмена ' . round($c['crtoecr'] / 100, 2) . ' КР.';
    } elseif ($kr > $day2) {
        $u->error = 'Вы можете обменять еще ' . $day2 . ' КР сегодня.';
    } elseif ($kr > $u->info['money']) {
        $u->error = 'Недостаточно денег для обмена.';
    } else {
        $ekr = round($kr / $c['crtoecr'], 2);
        $u->error = 'Вы успешно обменяли ' . $kr . ' КР на ' . $ekr . ' ЕКР.';
        //
        $u->info['money'] -= $kr;
        $u->info['money2'] += $ekr;
        //
        mysql_query(
            'UPDATE `users` SET `money` = "' . $u->info['money'] . '",`money2` = "' . $u->info['money2'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
        );
        mysql_query(
            'INSERT INTO `user_operation` ( `uid`,`time`,`money`,`money2`,`type`,`b1`,`b2` ) VALUES (
				"' . $u->info['id'] . '","' . time() . '","' . round(-$kr, 2) . '","' . round(
                $ekr, 2
            ) . '","Обмен КР на ЕКР","' . $u->info['money'] . '","' . $u->info['money2'] . '"
			)'
        );
    }
    $dc1 = mysql_fetch_array(
        mysql_query(
            'SELECT SUM(`money2`) FROM `user_operation` WHERE `time` >= "' . $timetoday . '" AND `uid` = "' . $u->info['id'] . '" AND `type` = "Обмен ЕКР на КР" LIMIT 1'
        )
    );
    $dc2 = mysql_fetch_array(
        mysql_query(
            'SELECT SUM(`money`) FROM `user_operation` WHERE `time` >= "' . $timetoday . '" AND `uid` = "' . $u->info['id'] . '" AND `type` = "Обмен КР на ЕКР" LIMIT 1'
        )
    );
    $dc1 = $dc1[0];
    $dc2 = $dc2[0];
    $day1 = round($day1def + $dc1, 2);
    $day2 = round($day2def + $dc2, 2);
} elseif (isset($_POST['ekr2'])) {
    //Обмен екр на кр.
    $ekr = round($_POST['ekr2'], 2);
    if ($c['ecrtocr'] * 2.5 < 0.01) {
        $u->error = 'Сегодня обменник закрыт.';
    } elseif ($day1 < 0.01) {
        $u->error = 'Сегодня для вас обмен закрыт, приходите завтра.';
    } elseif ($ekr < 0.01) {
        $u->error = 'Минимальная сумма обмена 0.01 ЕКР.';
    } elseif ($ekr > $day1) {
        $u->error = 'Вы можете обменять еще ' . $day1 . ' ЕКР сегодня.';
    } elseif ($ekr > $u->info['money2']) {
        $u->error = 'Недостаточно денег для обмена.';
    } else {
        $kr = round($ekr * $c['ecrtocr'] * 2.5, 2);
        $u->error = 'Вы успешно обменяли ' . $ekr . ' ЕКР на ' . $kr . ' КР.';
        //
        $u->info['money'] += $kr;
        $u->info['money2'] -= $ekr;
        //
        mysql_query(
            'UPDATE `users` SET `money` = "' . $u->info['money'] . '",`money2` = "' . $u->info['money2'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
        );
        mysql_query(
            'INSERT INTO `user_operation` ( `uid`,`time`,`money`,`money2`,`type`,`b1`,`b2` ) VALUES (
				"' . $u->info['id'] . '","' . time() . '","' . round($kr, 2) . '","' . round(
                -$ekr, 2
            ) . '","Обмен ЕКР на КР","' . $u->info['money'] . '","' . $u->info['money2'] . '"
			)'
        );
    }
    $dc1 = mysql_fetch_array(
        mysql_query(
            'SELECT SUM(`money2`) FROM `user_operation` WHERE `time` >= "' . $timetoday . '" AND `uid` = "' . $u->info['id'] . '" AND `type` = "Обмен ЕКР на КР" LIMIT 1'
        )
    );
    $dc2 = mysql_fetch_array(
        mysql_query(
            'SELECT SUM(`money`) FROM `user_operation` WHERE `time` >= "' . $timetoday . '" AND `uid` = "' . $u->info['id'] . '" AND `type` = "Обмен КР на ЕКР" LIMIT 1'
        )
    );
    $dc1 = $dc1[0];
    $dc2 = $dc2[0];
    $day1 = round($day1def + $dc1, 2);
    $day2 = round($day2def + $dc2, 2);
} elseif (isset($_POST['login'])) {
    //
    function en_ru($txt)
    {
        $g = false;
        $en = preg_match("/^(([0-9a-zA-Z _-])+)$/i", $txt);
        $ru = preg_match("/^(([0-9а-яА-Я _-])+)$/i", $txt);
        if (($ru && $en) || (!$ru && !$en)) {
            $g = true;
        }
        return $g;
    }

    //
    function testBad($txt)
    {
        $white = '-_ 0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMїЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮїйцукенгшщзхъфывапролджэячсмитьбю';
        $r = false;
        $i = 0;
        while ($i != -1) {
            if (isset($txt[$i])) {
                $g = false;
                $j = 0;
                while ($j != -1) {
                    if (isset($white[$j])) {
                        if ($white[$j] == $txt[$i]) {
                            $g = true;
                        }
                    } else {
                        $j = -2;
                    }
                    $j++;
                }
                if (!$g) {
                    $r = true;
                }
            } else {
                $i = -2;
            }
            $i++;
        }
        return $r;
    }

    function is_login($login)
    {
        $r = true;
        //
        $login = htmlspecialchars($login, null);
        //
        $bad = [
            'Мусорщик' => 1,
            'Мироздатель' => 1,
        ];
        //
        $login_db = mysql_fetch_array(
            mysql_query(
                'SELECT `id` FROM `users` WHERE `login` = "' . mysql_real_escape_string($login) . '" LIMIT 1'
            )
        );
        if (isset($login_db['id']) || isset($bad[$login])) {
            $r = false;
        } else {
            $true = true;
            //
            /*
            Логин может содержать от 4 до 16 символов, и состоять только из букв русского ИЛИ английского алфавита, цифр, символов '_', '-' и пробела.
            Логин не может начинаться или заканчиваться символами '_', '-' или пробелом.
            */
            //
            $login = str_replace('	', ' ', $login);
            $login = str_replace('%', ' ', $login);
            $login = str_replace('&nbsp;', ' ', $login);
            //
            if (strlen($login) > 16) {
                $true = false;
            } elseif (strlen($login) < 4) {
                $true = false;
            } elseif (strripos($login, '  ') == true) {
                $true = false;
            } elseif (substr($login, 1) == ' ' || substr($login, -1) == ' ') {
                $true = false;
            } elseif (substr($login, 1) == '-' || substr($login, -1) == '-') {
                $true = false;
            } elseif (substr($login, 1) == '_' || substr($login, -1) == '_') {
                $true = false;
            } elseif (testBad($login) == true) {
                $true = false;
            } elseif (en_ru(str_replace('ї', 'е', str_replace('ї', 'Е', $login))) == true) {
                $true = false;
            }
            //
            if ($true == false) {
                $r = false;
            } else {
                $r = true;
            }
        }
        return $r;
    }

    if ($u->info['login'] == $_POST['login']) {
        $u->error = 'Выберите другой логин...';
    } elseif ($u->info['money2'] < 25) {
        $u->error = 'Недостаточно средств.';
    } else {
        $login = htmlspecialchars($_POST['login'], null);
        if (is_login($login) == true) {
            mysql_query(
                'INSERT INTO `lastnames` ( `uid`,`login`,`newlogin`,`time` ) VALUES (
					"' . $u->info['id'] . '","' . $u->info['login'] . '","' . mysql_real_escape_string(
                    $login
                ) . '","' . time() . '"
				)'
            );
            $u->info['login_last'] = $u->info['login'];
            $u->info['login'] = $login;
            $u->info['money2'] -= 25;
            //
            mysql_query(
                "UPDATE `items_users` SET `data` = replace( `data` , 'sudba=" . $u->info['login_last'] . "', 'sudba=" . mysql_real_escape_string(
                    $u->info['login']
                ) . "') WHERE `data` LIKE '%sudba=" . mysql_real_escape_string(
                    $u->info['login_last']
                ) . "%' AND `uid` = '" . $u->info['id'] . "'"
            );
            //
            mysql_query(
                'UPDATE `users` SET `login` = "' . mysql_real_escape_string(
                    $u->info['login']
                ) . '", `money2` = "' . $u->info['money2'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
            );
            $u->error = 'Вы успешно сменили логин на &quot;' . $u->info['login'] . '&quot; перезайдите в игру с главной страницы.';
        } else {
            $u->error = 'Выберите другой логин...';
        }
    }
} elseif (isset($_GET['buy_ekr'])) {
    //
    $mrh_login = "15922";//"65643";
    $mrh_pass1 = "6?ljVLf]RSiBM2F";
    //
    $inv_id = 0;
    //
    $out_ekr = round($_POST['ekr'], 2);
    if ($out_ekr < 0) {
        //
        $out_ekr = 0;
    }
    $out_summ = round($out_ekr * $bt['cur'], 2);
    $inv_desc = 'Приобрести ' . $out_ekr . ' екр., персонаж №' . $u->info['id'] . ', дилер №' . round(
            (int)$_POST['ref']
        ) . '';
    //
    $shp_item = 0;
    //
    //Бонус опытовый, первичный и накопительный
    $out_ekr0 = $out_ekr;
    //
    $out_ekr += round($out_ekr0 / 100 * $bns[$b1][1], 2);
    $i = 0;
    while ($i < count($bns2)) {
        if (isset($bns2[$i][0]) && $out_ekr >= $bns2[$i][0]) {
            $b2_2 = $i;
        }
        $i++;
    }
    $out_ekr += round($out_ekr0 / 100 * $bns2[$b2_2][1], 2);
    if ($ball == 0) {
        $out_ekr += round($out_ekr0 / 100 * 20, 2);
    }
    //
    //Добавляем в базу
    mysql_query(
        'INSERT INTO `pay_operation` (
			`uid`,`bank`,`code`,`ekr`,`time`,`good`,`cur`,`var`,`val`,`ref`,`ref2`,`ip`,`date`
		) VALUES (
			"' . $u->info['id'] . '","' . $u->bank['id'] . '","' . mysql_real_escape_string(
            (int)$_GET['code']
        ) . '","' . mysql_real_escape_string($out_ekr) . '",
			"' . time() . '","0","' . mysql_real_escape_string(
            $cur['cur']
        ) . '","buy_ekr","0","' . mysql_real_escape_string($u->info['host_reg']) . '",
			"' . mysql_real_escape_string((int)$_GET['ref']) . '","' . mysql_real_escape_string(IP) . '","' . date(
            'Y-m-d H:i:s'
        ) . '"
		)'
    );

    $shp_item = mysql_insert_id();

    if ($shp_item <= 0) {
        die('Ошибка в обработке платежа, обратитесь к Администрации');
    }
    if ($out_ekr < 1) {
        die('Минимальная сумма покупки 1 екр.');
    }
    //
    // предлагаемая валюта платежа
    // default payment e-currency
    $in_curr = "";

    // язык
    // language
    $culture = "ru";
    $currency = "RUB";

    // формирование подписи
    // generate signature

    //md5( merchant_id : order_amount : secret_word : currency : order_id)
    $crc = md5($mrh_login . ':' . $out_summ . ':' . $mrh_pass1 . ':' . $currency . ':' . $shp_item);

    // форма оплаты товара
    // payment form
    $url = 'https://pay.freekassa.ru/?';
    $url .= 'm=' . $mrh_login . '&';
    $url .= 'oa=' . $out_summ . '&';
    $url .= 'currency=' . $currency . '&';
    $url .= 'o=' . $shp_item . '&';
    $url .= 's=' . $crc;

    header('location: ' . $url);
    die();
    print "<html>" .
        "<script type=\"text/javascript\" src=\"js/jquery.js\"></script><form id=\'F1\' action='https://www.free-kassa.ru/merchant/cash.php' method=POST>" .
        "Сумма платежа: " . $out_ekr . " Екр. " .
        "<input type=hidden name=m value=$mrh_login>" .
        "<input type=hidden name=oa value=$out_summ>" .
        "<input type=hidden name=InvId value=$inv_id>" .
        "<input type=hidden name=Desc value='$inv_desc'>" .
        "<input type=hidden name=s value=$crc>" .
        "<input type=hidden name=ovalue='$shp_item'>" .
        "<input type=hidden name=i value=$in_curr>" .
        "<input type=hidden name=lang value=$culture>" .
        "<input type=submit value='Оплатить'><Br>" .
        "(Все средства идут на развитие и улучшение игры)" .
        "</form><script>$('#F1').sumbit();</script></html>";
    die();
}

?>
<HTML>
<HEAD>
    <title>Покупка ЕвроКредитов - Бойцовский Клуб</title>
    <script type="text/javascript" src="/res/js/jquery-1.7.1.min.js"></script>

    <link href="/res/css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <META Http-Equiv=Cache-Control Content=no-cache>
    <meta http-equiv=PRAGMA content=NO-CACHE>
    <META Http-Equiv=Expires Content=0>

    <style>

        .t, .t tr, .t tr td {
            font-family: Times New Roman;
            font-size: 16px;
            border: 1px solid black;
            border-collapse: collapse;
            text-align: center;
            vertical-align: top;
        }

        .t {
            border: 3px solid black;
            border-collapse: collapse;
        }

        .t .al {
            text-align: left;
        }

        .t .vam {
            vertical-align: middle;
        }

        .t .ac {
            text-align: center;
        }

        .t .b {
            font-weight: bold;
        }

        .t .p {
            padding: 0px 5px 0px 5px;
        }

        .t .btop {
            border-top: 3px solid black;
            border-collapse: collapse;
        }

        .t .bright {
            border-right: 3px solid black;
            border-collapse: collapse;
        }

        .t .bleft {
            border-left: 3px solid black;
            border-collapse: collapse;
        }

        .t .bbottom {
            border-bottom: 3px solid black;
            border-collapse: collapse;
        }

        .t .light {
            background: #D6F5D3;
            color: green;
            font-weight: bold;
        }

    </style>
</HEAD>
<body>
<div id="main">
    <img alt="freekassa" src="image/free.png" width="300" height="110">
    <?php if (!empty($u->info['id'])): ?>
        <div style="padding:10px; border-bottom:1px solid white; text-align: center;">
            Персонаж: <?= $u->microLogin($u->info['id'], 1) ?>
        </div>
    <?php endif; ?>
    <?php if (!empty($u->error)): ?>
        <div style="padding:10px; color: red; font-weight: bold;">
            <?= $u->error ?>
        </div>
    <?php endif; ?>
    <?php if ($ball == 0): ?>
        <div style='font-weight:bold; color:red; padding: 10px 0 10px 0; font-size: 1.2em; text-align: center;'>
            Акция! При первом пополнении баланса,<br>
            Вы получаете дополнительно 20% ЕКР к сумме покупки БЕСПЛАТНО.
        </div>
    <?php endif; ?>
    <table style="width:98%; margin: auto;">
        <tr>
            <td style="width: 500px; padding: 10px; vertical-align: top;">
                <fieldset style="border: 1px solid white; padding: 10px;margin-top:15px; font-weight: bold;">
                    <span style='color:#8F0000;'>Ваш накопительный бонус:</span>
                    <span style="color: green; "><?= $bns[$b1][1] ?>% (<?= $ball ?> ЕКР)</span>
                </fieldset>

                <fieldset
                    style="width:480px; border: 1px solid white; margin-top:15px; padding: 10px;">
                    <legend style='font-weight:bold; color:#8F0000;'>Покупка ЕКР</legend>

                    <form method="post" id="ekrform" action="ekr.php?buy_ekr=1"
                          onsubmit="if(document.getElementById('ch_1').checked==false) {alert('Вы не согласились с пользовательским соглашением.');return false;} else {if(document.getElementById('ch_2').checked==false) {alert('Вы не согласились с условиями оплаты.');return false;};}; if(document.getElementById('ekr').value<1) {alert('Нельзя купить менее 1 ЕКР!');return false;};">
                        <b>Сумма ЕКР:</b> <input type="text" name="ekr" id="ekr" value="" size="8"
                                                 onchange="calc();"
                                                 onkeyup="if(event.keyCode<35||event.keyCode>40) calc();"> &nbsp;
                        <input type="submit" class="btn btn-success" value="Пополнить баланс"><br/>

                        <div id="calc" style="font-weight: bold; width: 400px; margin: 10px auto;">
                            &nbsp;<br>&nbsp;<br>&nbsp;
                        </div>

                        <script>
                            function bonus_n(a) {
                                var pr = <?=($bns[$b1][1])?>;
                                return (Math.floor((a * pr / 100) * 100) / 100);
                            }

                            function bonus_s(a) {
                                if (a >= 100) {
                                    pr = 20;
                                } else if (a >= 10) {
                                    pr = 10;
                                } else {
                                    pr = 0;
                                }
                                return (Math.floor((a * pr / 100) * 100) / 100);
                            }

                            function calc() {
                                document.getElementById('ekr').value = document.getElementById('ekr').value.replace(/[^\d\.]+/g, '');
                                var ekr = document.getElementById('ekr').value;
                                if (ekr.match(/^[-\+]?[\d]+\.?[\d]*$/) == null) {
                                    ekr = 0;
                                }

                                ekr4 = ekr = Math.round(ekr * 100) / 100;
                                var ekr4 = ekr.toFixed(2);

                                if (document.getElementById('ekr').value != ekr) {
                                    document.getElementById('ekr').value = ekr;
                                }
                                //alert(ekr);
                                var ekr2 = bonus_n(ekr);    //alert(ekr2);
                                var ekr3 = bonus_s(ekr);    //alert(ekr3);
                                var ekr7 = 0;
                                ekr2 = Math.floor(ekr2 * 100) / 100;
                                ekr3 = Math.floor(ekr3 * 100) / 100;
                                <?php if ($ball == 0): ?>
                                ekr7 = Math.floor((ekr / 5) * 100) / 100;
                                <?php endif; ?>
                                var ekrr = ekr + ekr2 + ekr3 + ekr7;
                                ekrr = Math.round(ekrr * 100) / 100;

                                document.getElementById('calc').innerHTML = 'Накопительный бонус: <font color=green>' + ekr2 + ' ЕКР</font><br />Оптовый бонус: <font color=green>' + ekr3 + ' ЕКР</font><?php if($ball == 0) { ?><br />Акция на 1-ое пополнение: <font color=red>' + ekr7 + ' ЕКР</font><?php } ?><br />Итого: <font color=green>' + ekrr + ' ЕКР</font>';
                            }

                            calc();
                        </script>

                        <table style="border: 1px solid white; margin: auto; width: 400px;">
                            <tr style="border-bottom: 1px solid white;">
                                <td style="border-right: 1px solid white;padding:2px;">1 ЕКР</td>
                                <td style="padding:2px;"><?= round($bt['cur'], 2) ?> Рублей</td>
                            </tr>
                            <tr style="border-bottom: 1px solid white;">
                                <td style="border-right: 1px solid white;padding:2px;">1 ЕКР</td>
                                <td style="padding:2px;"><?= round($bt['cur'] / $bt['USD'], 2) ?> Доллара *</td>
                            </tr>
                        </table>
                        <small>
                            * - зависит от текущих курсов валют<br/>
                            <b>Доставка игровой валюты производится в автоматическом режиме, сразу же после
                                оплаты!</b>
                            <br/><br/>
                            При оплате могут возникать задержки на пополнение, обычно не более 1 часа. Если по
                            истечению нескольких часов деньги так и не поступили на ваш баланс, то необходимо
                            обратиться в <a href="https://www.free-kassa.ru/support.php" target="_blank">службу
                                поддержки FREE-KASSA</a>.
                        </small>
                        <br/><br/>
                    </form>

                    <small>
                        <label><input type="checkbox" name="ch1" id="ch_1"/> Внимание! При пополнении баланса вы
                            соглашаетесь с <a href="/encicl/law2.html" target="_blank">соглашением
                                о предоставлении сервиса игры &laquo; Бойцовский Клуб &raquo;</a>.</label><br>
                        <label><input type="checkbox" name="ch1" id="ch_1"/> Внимание! При пополнении баланса вы
                            соглашаетесь с <a href="/encicl/law3.html" target="_blank">Политикой
                                Конфиеденцальности проекта &laquo; Бойцовский Клуб &raquo;</a>.</label><br>
                        <label><input type="checkbox" name="ch1" id="ch_1"/> Внимание! При пополнении баланса вы
                            соглашаетесь с <a href="/encicl/law4.html" target="_blank">Договором
                                публичной оферты &laquo; Бойцовский Клуб &raquo;</a>.</label>
                        <br/>
                        Если Вы очень хотели бы положить деньги на игровой счїт, но нет подходящей платїжной
                        системы, обратитесь за помощью к <b> Администратору </b> проекта.
                        <br/><br/>
                    </small>
                </fieldset>

            </td>


            <td style="padding: 10px; vertical-align: top;">
                <div style="border: 1px solid white; padding: 10px;margin-top:15px;">
                        <span style='color:#8F0000; font-weight: bold;'>
                            Ваш баланс счёта:
                            <b style="color: green"><?= $u->info['money2'] ?> ЕКР</b> и
                            <b style="color: black"><?= $u->info['money'] ?> КР</b>.
                        </span>
                </div>

                <fieldset style="border: 1px solid white; padding: 10px;margin-top:15px;">
                    <legend style='font-weight:bold; color:#8F0000;'>Обмен</legend>
                    <form method="post" action="ekr.php"
                          onsubmit="if(document.getElementById('ekr2').value><?= $day1 ?>) {alert('Сегодня вы можете еще обменять не более <?= $day1 ?> ЕКР');return false;} else if(document.getElementById('ekr2').value<0.01||document.getElementById('ekr2').value><?= $day1 ?>) {alert('За 1 раз Вы можете обменять сумму от 0.01 до <?= $day1 ?> ЕКР.');return false;} else {return confirm('Вы действительно хотите обменять '+document.getElementById('ekr2').value+' ЕКР на '+(document.getElementById('ekr2').value*<?= $c['ecrtocr'] * 2.5 ?>)+' КР ? В обратном направлении обмен с КР на ЕКР будет невозможен.');};">
                        Обменять ЕКР на КР по курсу <b>1ЕКР=<?= $c['ecrtocr'] * 2.5 ?>КР</b>: &nbsp; <input
                            type="text" name="ekr2" id="ekr2" value="" size="5" placeholder="<?= $day1 ?> max"
                            onchange="calc22();" onkeyup="if(event.keyCode<35||event.keyCode>40) calc22();">
                        &nbsp; <input type="submit" class="btn btn-success" name="submit" id="calc2"
                                      value="Обменять"><br/>
                    </form>
                    <form method="post" action="ekr.php"
                          onsubmit="if(document.getElementById('kr001').value<<?= round(
                              $c['crtoecr'] / 100, 2
                          ) ?>) {alert('Минимальная сумма обмена <?= round(
                              $c['crtoecr'] / 100, 2
                          ) ?> КР');return false;}else if(document.getElementById('kr001').value><?= $day2 ?>) {alert('Сегодня вы можете еще обменять не более <?= $day2 ?> КР');return false;} else {return confirm('Вы действительно хотите обменять '+document.getElementById('kr001').value+' КР на '+(Math.round(document.getElementById('kr001').value/10)/50)+' ЕКР? Отменить операцию обмена будет невозможно.');};">
                        Обменять КР на ЕКР по курсу <b><?= $c['crtoecr'] ?>КР=1ЕКР</b>:
                        <input type="text" style="margin-left:1px;" name="kr001"
                               id="kr001" value="" placeholder="<?= $day2 ?> max" size="5" onchange="calc24();"
                               onkeyup="if(event.keyCode<35||event.keyCode>40) calc23();">
                        &nbsp;<input type="submit" class="btn btn-success" name="submit" id="calc3"
                                     value="Обменять">
                        <br>
                    </form>
                    <script>
                        function calc23() {
                            document.getElementById('kr001').value = document.getElementById('kr001').value.replace(/[^\d]+/g, '');
                            var kr001 = document.getElementById('kr001').value;
                            kr001 = Math.floor(kr001 / 10) * 10;
                            var kr001ekr = kr001 / <?=$c['crtoecr']?>;

                            document.getElementById('calc3').value = 'Обменять ' + kr001 + ' КР на ' + kr001ekr + ' ЕКР';
                            return kr001;
                        }

                        function calc24() {
                            document.getElementById('kr001').value = calc23();
                            if (document.getElementById('kr001').value == 0) document.getElementById('kr001').value = '';
                        }

                        calc24();

                        function calc22() {
                            document.getElementById('ekr2').value = document.getElementById('ekr2').value.replace(/[^\d\.]+/g, '');
                            var ekre = document.getElementById('ekr2').value;
                            if (ekre.match(/^[-\+]?[\d]+\.?[\d]*$/) == null) {
                                ekre = 0;
                            }

                            ekre = Math.floor(ekre * 100) / 100;
                            var ekr4 = ekre.toFixed(2);

                            if (document.getElementById('ekr2').value != ekre) {
                                document.getElementById('ekr2').value = ekr4;
                            }
                            var kre = parseFloat(ekre) * <?=$c['ecrtocr'] * 2.5?>;

                            document.getElementById('calc2').value = 'Обменять ' + ekre + ' ЕКР на ' + kre.toFixed(0) + ' КР';
                        }

                        calc22();
                    </script>
                </fieldset>

                <fieldset style="border: 1px solid white; padding: 20px 11px 21px 11px;margin-top:15px;">
                    <legend style='font-weight:bold; color:#8F0000;'>Накопительные бонусы</legend>
                    <table class="t" style="width: 500px; margin: auto;">
                        <tr class="b">
                            <td>ЕКР</td>
                            <td class="bright ">Бонус</td>
                            <td>ЕКР</td>
                            <td>Бонус</td>
                        </tr>
                        <tr>
                            <td class="">800 ЕКР</td>
                            <td class="bright ">10%</td>
                            <td class="">3 000 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">30%</td>
                        </tr>
                        <tr>
                            <td class="">700 ЕКР</td>
                            <td class="bright ">9%</td>
                            <td class="">2 500 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">27%</td>
                        </tr>
                        <tr>
                            <td class="">600 ЕКР</td>
                            <td class="bright ">8%</td>
                            <td class="">2 000 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">25%</td>
                        </tr>
                        <tr>
                            <td class="">500 ЕКР</td>
                            <td class="bright ">7%</td>
                            <td class="">1 700 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">23%</td>
                        </tr>
                        <tr>
                            <td class="">400 ЕКР</td>
                            <td class="bright ">6%</td>
                            <td class="">1 500 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">21%</td>
                        </tr>
                        <tr>
                            <td class="">300 ЕКР</td>
                            <td class="bright ">5%</td>
                            <td class="">1 300 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">19%</td>
                        </tr>
                        <tr>
                            <td class="">200 ЕКР</td>
                            <td class="bright ">4%</td>
                            <td class="">1 200 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">17%</td>
                        </tr>
                        <tr>
                            <td class="">100 ЕКР</td>
                            <td class="bright ">3%</td>
                            <td class="">1 100 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">15%</td>
                        </tr>
                        <tr>
                            <td class="">50 ЕКР</td>
                            <td class="bright ">2%</td>
                            <td class="">1 000 ЕКР <img src="/res/img/medals/vip.gif" title="VIP"
                                                        style="margin-top:2px; width: 20px;" alt="VIP"></td>
                            <td class="">13%</td>
                        </tr>
                        <tr>
                            <td class="">10 ЕКР</td>
                            <td class="bright ">1%</td>
                            <td class="">900 ЕКР</td>
                            <td class="">11%</td>
                        </tr>
                    </table>
                </fieldset>

                <fieldset style="border: 1px solid white; padding: 18px 12px 18px 12px;margin-top:15px;">
                    <legend style='font-weight:bold; color:#8F0000;'>Оптовые бонусы</legend>

                    <table class="t" style="width: 500px; margin: auto;">
                        <tr class="b light">
                            <td>Бонус</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>10%</td>
                        </tr>
                        <tr style="border-bottom: 2px solid black;">
                            <td class="b">Сумма</td>
                            <td>10 ЕКР</td>
                            <td>20 ЕКР</td>
                            <td>30 ЕКР</td>
                            <td>40 ЕКР</td>
                            <td>50 ЕКР</td>
                        </tr>
                        <tr class="b light">
                            <td class="b">Бонус</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>10%</td>
                            <td>20%</td>
                        </tr>
                        <tr>
                            <td class="b">Сумма</td>
                            <td>60 ЕКР</td>
                            <td>70 ЕКР</td>
                            <td>80 ЕКР</td>
                            <td>90 ЕКР</td>
                            <td>100 ЕКР</td>
                        </tr>
                    </table>
                </fieldset>

            </td>
        </tr>

        <tr>
            <td colspan="2" style='font-weight:bold; color:#8F0000; padding: 10px 0 10px 0; font-size: 1.5em;'>
                <center>Коммерческие услуги</center>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="padding: 10px; vertical-align: top;">

                <!-- komplekt form -->
                <div class="komplekt-form" id="theLayer"
                     style="position: absolute; left: -300px; top: 160px; visibility:hidden; width: 150px; height:320px;">
                    <div class="form-title" id="titleBar">
                        <label id="ftitle">Просмотр</label>
                        <button type="button" class="close"
                                onclick="document.getElementById('theLayer').style.visibility = 'hidden';return false"
                                data-dismiss="modal" aria-hidden="true">x
                        </button>
                    </div>
                    <div class="form">
                        <form method="post" id="fform" action="ekr.php">
                            <input type="hidden" name="do" value="newShadow"/>
                            <input type="hidden" id="ffinput" name="ffinput" value=""/>
                            <center>
                                <img src="" id="ffimg" width="120" height="220" style="margin-bottom: 5px;"/><br>
                                <div style="padding:5px;">
                                    <select name="ffsex" id="ffsex">
                                        <option value="0" <?php if ($u->info['sex'] == 0) {
                                            echo 'selected="selected"';
                                        } ?> >Мужской образ
                                        </option>
                                        <option value="1" <?php if ($u->info['sex'] == 1) {
                                            echo 'selected="selected"';
                                        } ?> >Женский образ
                                        </option>
                                    </select>
                                </div>
                                <div
                                    style="width:240px; margin-left:-6px;background:#cbc4aa;padding:5px 0px 5px 0px;border:1px solid #cbc4aa;background-color:#eee;border:1px solid #999;border:1px solid rgba(0,0,0,0.3);*border:1px solid #999;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;outline:none;-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);box-shadow:0 3px 7px rgba(0,0,0,0.3);-webkit-background-clip:padding-box;-moz-background-clip:padding-box;background-clip:padding-box;">
                                    <input type="button" class="btn btn-success" value="Подтвердить"
                                           style="height: 28px; line-height: 20px; width: 100px;font-size:13px;"
                                           onclick="if(confirm('Действительно хотите купить это изображение?')) $('#fform').submit();"/>
                                    <input type="button" class="btn btn-danger" value="Отменить"
                                           onclick="document.getElementById('theLayer').style.visibility = 'hidden';return false"
                                           style="height: 28px; line-height: 20px; width: 100px;font-size:13px;"/>
                                </div>
                            </center>
                        </form>
                    </div>
                </div>
                <table style="width: 100%">
                    <tr>
                        <td style="vertical-align: baseline;">
                            <fieldset style="width:480px; border: 1px solid white; padding: 10px;margin:15px;">
                                <legend style='font-weight:bold; color:#8F0000;'>Покупка личного образа</legend>
                                <small>
                                    <b>Стоимость услуги: 100 ЕКР</b><br>
                                    Требования к персональному образу:<br/>
                                    GIF-картинка размером 120x220 (ШхВ) и весом до 300 Кб.<br/>
                                    <br>
                                    Выберите картинку: <input type="file" id="imgFile"/>
                                    <script>

                                        function showImgPreview(img) {
                                            document.getElementById('theLayer').style.visibility = "visible";
                                            document.getElementById('theLayer').style.left = 300;
                                            document.getElementById('theLayer').style.top = 300;
                                            $('img#ffimg').attr('src', '/clan_prw/' + img);
                                            document.getElementById('ffinput').value = img;
                                            $('img#ffimg').attr('height', '220');
                                            document.getElementById('theLayer').style.height = 290;
                                        }

                                        function showImgPreviewPet(img) {
                                            document.getElementById('theLayer').style.visibility = "visible";
                                            document.getElementById('theLayer').style.left = 300;
                                            document.getElementById('theLayer').style.top = 300;
                                            $('img#ffimg').attr('src', '/clan_prw/' + img);
                                            $('img#ffimg').attr('height', '40');
                                            //$('#theLayer').attr('height','120');
                                            document.getElementById('ffinput').value = img;
                                            document.getElementById('ffsex').style.display = 'none';
                                            document.getElementById('theLayer').style.height = 105;
                                            $('html, body').animate({scrollTop: 0}, 'slow');
                                        }

                                        function showImgPreviewSmile(img) {
                                            document.getElementById('theLayer').style.visibility = "visible";
                                            document.getElementById('theLayer').style.left = 300;
                                            document.getElementById('theLayer').style.top = 300;
                                            $('img#ffimg').attr('src', '/clan_prw/' + img);
                                            $('img#ffimg').attr('width', null);
                                            $('img#ffimg').attr('height', null);
                                            document.getElementById('ffinput').value = img;
                                            document.getElementById('ffsex').style.display = 'none';
                                            document.getElementById('theLayer').style.height = 105;
                                            $('html, body').animate({scrollTop: 0}, 'slow');
                                        }

                                        $('#imgFile').change(function () {
                                            var fd = new FormData();
                                            fd.append('type', 'person');
                                            fd.append('img', $('#imgFile')[0].files[0]);
                                            $.ajax({
                                                type: 'POST',
                                                url: 'ekr.php',
                                                data: fd,
                                                processData: false,
                                                contentType: false,
                                                dataType: "json", // поменять на json
                                                success: function (data) {
                                                    if (data['img'] != undefined) {
                                                        document.getElementById('ffsex').style.display = 'none';
                                                        showImgPreview(data['img'])
                                                    } else {
                                                        alert(data['err']);
                                                    }
                                                },
                                                error: function (data) {
                                                    alert('Ошибка AJAX.')
                                                }
                                            });
                                        })
                                    </script>
                                </small>
                            </fieldset>
                        </td>
                        <td style="vertical-align: baseline;">
                            <fieldset style="border: 1px solid white; padding: 10px;margin:15px;">
                                <legend style='font-weight:bold; color:#8F0000;'>Покупка личного смайлика</legend>
                                <small>
                                    <b>Стоимость услуги: <?php $ekr_smile = 10;
                                        echo $ekr_smile; ?> ЕКР</b><br>
                                    Требования к смайлику:<br/>
                                    GIF-картинка размером от 15x15 до 95x21 (ШхВ) и весом до 30 Кб.<br/>
                                    <br>
                                    Выберите картинку: <input type="file" id="imgFile5"/>
                                    <script>

                                        $('#imgFile5').change(function () {
                                            var fd = new FormData();
                                            fd.append('type', 'person');
                                            fd.append('img5', $('#imgFile5')[0].files[0]);
                                            $.ajax({
                                                type: 'POST',
                                                url: 'ekr.php',
                                                data: fd,
                                                processData: false,
                                                contentType: false,
                                                dataType: "json", // поменять на json
                                                success: function (data) {
                                                    if (data['img'] != undefined) {
                                                        showImgPreviewSmile(data['img'])
                                                    } else {
                                                        alert(data['err']);
                                                    }
                                                },
                                                error: function (data) {
                                                    alert('Ошибка AJAX.');
                                                }
                                            });
                                        })
                                    </script>
                                </small>
                            </fieldset>
                        </td>
                        <td style="vertical-align: baseline;">
                            <fieldset style="border: 1px solid white; padding: 10px;margin:15px;">
                                <legend style='font-weight:bold; color:#8F0000;'>Смена имени персонажа</legend>
                                <small>
                                    <b>Стоимость услуги: 25 ЕКР</b><br>
                                    Текущее имя: <?= $u->info['login'] ?><br>
                                    <form method="post" action="ekr.php" id="lform">
                                        <input type="hidden" name="do" value="changeLogin"/>
                                        <input type="text" name="login" id="llogin" onkeyup="check_login();" size=35
                                               placeholder="Введите новое имя.." style="margin: 5px 0 5px 0;"/>
                                        <span
                                            id="ajaxLogin"></span><br>
                                        <input type="button" class="btn btn-success" value="Сменить имя"
                                               onclick="if(confirm('Действительно хотите сменить имя?')) $('#lform').submit();"/>
                                    </form>
                                    <script>
                                        function check_login() {
                                            $("#ajaxLogin").html('<b>Проверка доступности...</b>');
                                            $.ajax({
                                                url: "ajax_checklogin.php?login=" + $('#llogin').val(),
                                                cache: false
                                            }).done(function (html) {
                                                $("#ajaxLogin").html(html);
                                            });
                                        }
                                    </script>
                                </small>
                            </fieldset>
                        </td>
                    </tr>
                </table>
                <!-- end komplekt form -->
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
    </table>
</div>
</BODY>
</HTML>