 // Загрузка файлов на Аякс
function doLoad(value,file_name,id_change,action) {                      
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
            //alert(req.readyState);
        if (req.readyState == 4) {  
            // Write debug information too (output become responseText).
            if (!action) document.getElementById(id_change).innerHTML = req.responseText;
            else 
           document.getElementById(id_change).innerHTML = document.getElementById(id_change).innerHTML+req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax/'+file_name, true);
    // Send data to backend.
    req.send( { q: value } );
}        
 
var str_cat_id = 0; // Текущий выбранный элемент в категориях

function check_cat(id)
        {        
        if (str_cat_id!=0)
                {
                document.getElementById("str_cat"+str_cat_id).checked = false;   // невидимые radio
                document.getElementById("tr_str_cat"+str_cat_id).className = ""; //класс tr
                document.getElementById("edit_cat"+str_cat_id).disabled = true; // кнопка редактировать
                }
        str_cat_id = id;        
        document.getElementById("str_cat"+id).checked = true;        
        document.getElementById("tr_str_cat"+id).className = "tr_white";
        document.getElementById("edit_cat"+id).disabled = false;
        }
        
function show_news_list()
        {
        var ar = "";        
        for (var i=0; i<document.f.length; i++)
                {
                if (document.f.elements[i].checked==true) 
                        {
                        ar=ar+document.f.elements[i].id+"_";
                        }        
                }
        doLoad(document.getElementById('f'),'news_list.admin.php?ar='+ar,'news_list');
        }
        
        
//Номер формы для тега
function add_delete_tag(action,tag_list_start,tag_list_finish)
        {
        var tag_list_finish = document.getElementById(tag_list_finish);        
        switch (action)
                {        
                // Добавляем option        
                case "add":        
                if (document.getElementById(tag_list_start))
                        {        
                        var tag_list_start = document.getElementById(tag_list_start);                        
                        var repeat = 0;
                        
                        // Проверяем, нет ли уже такого значения
                        for (var i=0; i < tag_list_finish.options.length; i++)
                                {
                                if (tag_list_finish.options[i].value==tag_list_start.options[tag_list_start.selectedIndex].value) repeat = 1;
                                }
                                
                        if (!repeat) 
                                {
                                // Добавляем новый option        
                                tag_list_finish.options[tag_list_finish.options.length] = new Option(tag_list_start.options[tag_list_start.selectedIndex].text, tag_list_start.options[tag_list_start.selectedIndex].value); 
                                
                                //Выделяем новый option
                                tag_list_finish.options[tag_list_finish.options.length-1].selected=true;
                                }
                                else
                                {
                                alert("Данный элемент списка уже выбран");
                                }
                        }
                        else
                        {
                        alert("Необходим список тегов");        
                        }
                break;
                        
                //Удаляем option        
                case "delete":
                if (getSelectedIndexes(tag_list_finish).length!=0) tag_list_finish.options[tag_list_finish.selectedIndex] = null;
                else alert("Необходимо выбрать элемент списка для удаления");                
                break;        
                }        
        }
        
//Массив выделенных элементов        
function getSelectedIndexes (oListbox)
{
  var arrIndexes = new Array;
  for (var i=0; i < oListbox.options.length; i++)
  {
      if (oListbox.options[i].selected) arrIndexes.push(i);
  }
  return arrIndexes;
}

var count_upload = 0;
//Загрузчик файлов
function upload_foto()
        {        
        //alert(count_upload);
        $("<div><input type=\"file\" name=\"file_foto"+count_upload+"\"><br><TextArea style=\"width:300px;height:100px;\" name=\"description_foto[]\"></TextArea></div>").appendTo("#gallery_form");
        count_upload++;
        }

var count_upload_video = 0;        
function upload_video()
        {        
        //alert(count_upload);
        $("<div><input type=\"text\" name=\"title_video[]\" style=\"width:400px;\"><br><TextArea style=\"width:300px;height:100px;\" name=\"value_video[]\"></TextArea></div>").appendTo("#video_form");
        count_upload_video++;
        }        

        
// Загрузить фотки и удалить форму
function delete_foto_form(id_match)
        {
        count_upload = 0;        
        doLoad(document.getElementById("gallery_form"),"foto.admin.php?id_match="+id_match,"gallery_result"); 
        doLoad(document.getElementById("gallery_form"),"foto.form.php?id_match="+id_match,"gallery_form_block");
        //$('#gallery_form').empty();
        }
        
// Загрузить видео и удалить форму
function delete_video_form(id_match)
        {
        count_upload = 0;        
        doLoad(document.getElementById("video_form"),"video.admin.php?id_match="+id_match,"video_result"); 
        doLoad(document.getElementById("video_form"),"video.form.php?id_match="+id_match,"video_form_block");
        //$('#gallery_form').empty();
        }        
        
//Сортировка туров
function redirect_tour(id_season,id_tournir)
        {
        //alert(111);        
        location.href = "tours.php?id_season="+id_season+"&id_tournir="+id_tournir;
        }
        
function redirect_match(id_season,id_tournir)
        {        
        location.href = "match_list.php?id_season="+id_season+"&id_tournir="+id_tournir;
        }        
        
function show_hide_block(id)
        {
        var obj = document.getElementById(id);
        switch(GetCssStyle(obj).display)
                {
                case "none":
                obj.style.display = "block";
                break;        
                        
                case "block":
                obj.style.display = "none";
                break;
                }
        }
        
function GetCssStyle(e){
    if (e.currentStyle) return e.currentStyle;
    else if (window.getComputedStyle) return window.getComputedStyle(e,null)
}        

var vote_id = 1;
// Голосования
function add_vote_punct()
{
vote_id = vote_id+1;
var vote = document.getElementById("vote_block");
$("<div style=\"padding-left:117px;margin:2px;\" id=\"vote_"+vote_id+"\"><input type=\"text\" name=\"vote_answer"+vote_id+"\" style=\"width:400px;\"><input type=\"button\" value=\"-\" onClick=\"minus_golos("+vote_id+")\"></div>").appendTo("#form_vote");
}

// Уюрать пункт голосования
function minus_golos(id)
{
//$("#vote_"+id).hide();
//alert(document.getElementById("vote_"+id));
document.getElementById("vote_"+id).innerHTML = "";
$("#vote_"+id).hide();
}
