<?

session_start();

header( 'Content-type: text/html; charset=windows-1251' );

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest' ) exit();

if ( !isset( $_SESSION['iduser'] ) ) exit();

define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );

include_once ROOT_DIR . '/engine/config.php';
include_once ROOT_DIR . '/engine/function.php';

switch ( $_POST['type'] ) {
    case md5( $message_md5 . 'serfing' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM dynlink WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'serfing';
        break;
    case md5( $message_md5 . 'klink' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM klink WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'klink';
        break;
    case md5( $message_md5 . 'banners' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM banners WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'banners';
        break;
    case md5( $message_md5 . 'tests' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM tests WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'tests';
        break;
    case md5( $message_md5 . 'tasks' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM tasks WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'tasks';
        break;
	case md5( $message_md5 . 'chain' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM chain WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'chain';
        break;
	case md5( $message_md5 . 'statlink' ):
        $pr_transfer = mysql_query( "SELECT id, balance FROM statlink WHERE id = '" . ( int ) $_POST['id'] . "' and iduser = '" . $_SESSION['iduser'] . "'" );
        $pref = 'statlink';
        break;
    default:
        echo '<div class="error" style="width: 90%; text-align: center">Рекламная площадка не существует или не принадлежит Вам.</div>';
    break;
}

if ( mysql_num_rows( $pr_transfer ) == 0 ) {
    echo '<div class="error" style="width: 90%;text-align: center">Рекламная площадка не существует или не принадлежит Вам.</div>';
    $t_panel = '';
    exit();
} else {
    $pr_transfer_row = mysql_fetch_array( $pr_transfer );
    $t_panel = '<a href="#" id="transferSend" class="btn_box" onclick="transfer.Send(' . ( int ) $_POST['id'] . ', \'' . md5( $message_md5 . $pref ) . '\'); return false;">Перевести</a>';
}

?>

<script type="text/javascript">
$(document).ready(function() {
    $('#rek_area').styler({width:'270'});
    $('#rek_id').styler({width:'270'});
});

function send_rek() {
    $.post('ajax.php?func=preload_area', {
        id_area: $('#rek_area').val()
    }, function(data) {
        if (data.ok == 1) {
            $('#rek_id').html('');
            for(var i = 0; i <= data.transfer.length - 1; i++) {
                $('#rek_id').append('<option value="'+data.transfer[i].id+'">'+data.transfer[i].text+'</option>');
            }
            $('#rek_id').trigger('refresh');
        } else
        if (data.ok == 2) {
            $('#rek_id').html('');
            $('#rek_id').trigger('refresh');
        }
    }, 'json');
    return false;
}
</script>
<div style="height: 210px;">
    <div style="position: absolute; width: 500px; padding: 10px;">
        <div style="text-align: center; padding: 10px 0; ">На счету рекламной площадки <?=$pr_transfer_row['balance']?> <?=$config['valutaname']?></div>
    <table style="width: 100%; border: 0;" cellpadding="0" cellspacing="2" align="left">
        <tr>
            <td style="width: 170px; text-align: left; ">Выберите вид рекламы:</td>
            <td style="text-align: left;">
				<select id="rek_area" onchange="send_rek();">
					<option value="1">Реклама в серфинге</option>
					<option value="2">Контекстная реклама</option>
					<option value="8">Статическая реклама</option>
					<option value="3">Баннерная реклама</option>
					<option value="4">Оплачиваемые тесты</option>
					<option value="5">Оплачиваемые задания</option>
					<option value="">Реклама (vk.com)</option>
				</select><br>
			</td>
		</tr>
        <tr>
            <td style="width: 200px; text-align: left;">Рекламная площадка:</td>
            <td style="text-align: left; "><select id="rek_id"></select><br></td>
        </tr>
        <tr>
             <td style="text-align: left;">Введите желаемую сумму:</td>
            <td style="text-align: left;"><input type="text" id="sum" class="val" style="width: 70px; text-align: center;" /></td>
        </tr>
    </table>
    </div>
</div>
<div class="task_a_button"><?=$t_panel?></div>











