var bugReportForm = '<div id="bug_report_form">' +
        '    <a class="bug_reporting_link" href="javascript:void(0);" id="dont_report_bug" onclick="hideBugReportBlock();">не сообщать об ошибке ↑</a>' +
        '    <form id="bug_reporting" style="width: 400px;" onsubmit="return submitBug();">' +
        '        <div class="report_subject">' +
        '            <span>Неточность в:</span>' +
        '            <ul>' +
        '            <li><label><input name="type" value="location" type="checkbox" class="xb">расположении на карте</label></li>' +
        '            <li><label><input name="type" value="address" type="checkbox" class="xb">адресе</label></li>' +
        '            <li><label><input name="type" value="timetable" type="checkbox" class="xb">времени работы</label></li>' +
        '            <li><label><input name="type" value="currency" type="checkbox" class="xb">наименовании валют</label></li>' +
        '            </ul>' +
        '        </div>' +
        '        <div class="report_comment">' +
        '            <span>Комментарий</span>' +
//        '            <textarea rows="4" cols="5" name="comment" id="bug_comment"></textarea>' +
        '             <input type="text" name="comment" id="bug_comment">'+
        '        </div>' +
        '        <div class="form_submit">' +
        '            <img src="/images/loader.gif" class="ajax_loader" style="display: none;">' +
        '            <input value="Отправить" class="send_report" type="button" onclick="submitBug();">' +
        '        </div>' +
        '    </form>' +
        '    <span id="report_message" class="message" style="display: none;">Спасибо за информацию.</span>' +
        '</div>';

var reportBugLink = '<br><a class="bug_reporting_link" href="javascript:void(0);" onclick="showBugReportBlock();" id="report_bug_link">сообщить об ошибке ↓</a>'
                    + '<div id="bug_report_cont" style="display:none"></div>';

function showBugReportBlock() {
    var container = $('#bug_report_cont');
    container.html(bugReportForm);
    container.show();
    $('#report_bug_link').hide();
    updateBallon();
}
function hideBugReportBlock() {
    $('#bug_report_cont').hide();
    $('#report_bug_link').show();
    updateBallon();
}
function updateBallon() {
    var balloon = map.getBalloon();
    if (balloon != null) {
        balloon.update();
    }
}

function submitBug() {
    var checked = $('.xb').get(); // input[type=checkbox][checked]
    var l = checked.length;
    var bug = $('.YMaps-b-balloon-content').html();
  //  alert(bug);
    bug = bug.substring(0,bug.indexOf('<div><div id="balloon_content">'));
    var bugurl = bug.substring(bug.indexOf('<a href=')+10,bug.indexOf('">'));
    bugurl = 'http://prodengi.kz/'+bugurl;
  //  alert(bugurl);
//    alert (bug);
	bug +="\nЛинк: " + bugurl + "\n";
    bug += $('#balloon_content').html();
    bug += "\nНеточность в:\n";
    for (var i = 0; i < l; i++) {
        if(checked[i].checked)
        bug += "\n" + checked[i].value;
    }
    bug += "\nКомментарий:\n" + $('#bug_comment').val();
    jQuery.get('/cat/map_bug/', {'bug': bug},
    function(data) {
        $('#report_message').show();
        updateBallon();
    });
}

