  // со страницы index.html
  var countimage=1;
  var countfile=1;
  var countvideo=1;
  
  var IsIE=IsIEBrowser();
/* параметры для поля input загрузки фотографии*/  
function ItemImage(){
  var maxfile=30;
  var filespan='imagespan'; //id для блока добалвения input загрузки
  var id_Br ='idAttachBr';
  var id_input=''; //для id
  if (maxfile<=countimage){
    alert(max_count_file + maxfile);
    return true;
  }
  countimage++;
  var strIndex = countimage;
  addItem(maxfile, filespan, id_input, id_Br, strIndex);
} 
/* параметры для поля input загрузки видео*/  
function ItemVideo(){
  var maxfile=5;
  var filespan='videospan'; //id для блока добалвения input загрузки
  var id_Br ='video_idAttachBr';
  var id_input='video_'; //для id

  if (maxfile<=countvideo){
    alert(max_count_file + maxfile);
    return true;
  }
  countvideo++;
  var strIndex = countvideo;
  addItem(maxfile, filespan, id_input, id_Br, strIndex);
}
/* параметры для поля input загрузки файлов*/  
function ItemFile(){
  var maxfile=3; //максимальное количетсво загружаемых файлов
  var filespan='filespan'; //id для блока добалвения input загрузки
  var id_Br ='file_idAttachBr';
  var id_input='file_'; //для id

  if (maxfile<=countfile){
    alert(max_count_file + maxfile);
    return true;
  }
  countfile++;
  var strIndex = countfile;
  
  addItem(maxfile, filespan, id_input, id_Br, '_'+strIndex);
}  
/* Проверка правильности введения капчи при загрузке*/
function check_safecode(hash, id){
  var text="<strong style='color:red'>" + code_check_wait + "</strong>";
  var check=1;
  document.getElementById(id + "_code_text").innerHTML = text;
  document.getElementById(id + "_code_check").value = 1;
  safecode = document.getElementById(id + '_safecode').value;
  JsHttpRequest.query(
      '/external/ajax.php', // путь к backend-скрипту
      { 'hash': hash, 'safecode': safecode, 'action': 'safecode' }, // передаем текстовые данные
      function(result, errors) {
        // Вывести отладочные сообщения (если нужно).
        document.getElementById("debug").innerHTML = errors; 
        // Вывести результат работы.
        if( result["str"] == 'yes'){
          text='<strong style="color:blue">' + code_ok + '</strong>';
          document.getElementById(id + "_code_check").value = 2;   
          document.getElementById(id + "_code_text").innerHTML = text; 
        }
        else {
          text='<strong style="color:red">' + code_wrong + '</strong>';
          document.getElementById(id + "_code_check").value = 0;   
          document.getElementById(id + "_code_text").innerHTML = text; 
        }
      }
  );   
  return check;  
}
/* Сохранение настроек открытия/закрытия окон*/
function trigger(id, data, code){
  JsHttpRequest.query(
      '/external/ajax.php',
      { 'id': id, 'data' : data, 'code': code, 'action': 'trigger' },
      function(result, errors) {
        document.getElementById("debug").innerHTML = errors;
      }
  );   
  return check;  
}
/*открываение закладки на главной странице*/
function tab(tab){
  div = document.getElementById('tab_image');
    div.style.display = 'none';
  div = document.getElementById('tab_file');
    div.style.display = 'none';
  div = document.getElementById('tab_video');
    div.style.display = 'none';
  div = document.getElementById('tab_'+tab);
    div.style.display = 'inline';
}
function IsIEBrowser(){
  if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1) {
    return true;
  }else{
    return false;
  }
} 
function addbr(spanId,brId){
  var span = document.getElementById(spanId);
  if(span !=null){
    var brObj = document.createElement("br");
    if( brObj !=null ){
      brObj.name = brId;
      brObj.id = brId;
      span.appendChild(brObj);
    }
  }
  return;
}
function addItem(maxfile, filespan, id_input, id_Br, strIndex){
  // id для добавления файлов
  var attachId = id_input+"attachId"+ strIndex;
  // id для <br>
  var brId = id_Br + strIndex;
  // id для кнопки удаления
  var delId = "idAttachOper"+ strIndex;
  
  addbr(filespan,brId);
  var jsCode={'event':'onclick','handler':''};
  addInputField(filespan,attachId,'file','',jsCode);
  if(IsIE)
    var jsCode={'event':'onclick','handler':''};
  else
    var jsCode={'event':'onclick','handler':''};
  //addInputField('idfilespan',delId,'button','del',jsCode);
  var span = document.getElementById(filespan);
  return false;
}  
function addInputField(pareId,fieldId,fieldType,fieldValue,fieldJs){
  var pare = document.getElementById(pareId);
  if ( pare !=null ){
    if ( !IsIE ){
      var fieldObj = document.createElement("input");
      if ( fieldObj != null ) {
        fieldObj.type= fieldType;
        if(fieldType=='file')
          fieldObj.name = 'uploads_'+fieldId+'';
        else
          fieldObj.name = 'uploads['+fieldId+']';
        if(fieldType!='file')
          fieldObj.value = fieldValue;
        fieldObj.id = fieldId;
        fieldObj.size="30";
        if(fieldJs['event'])
          fieldObj.setAttribute(fieldJs['event'],fieldJs['handler'],0);
        pare.appendChild(fieldObj);
      }//if fieldObj
    }// !IsIE
    if( IsIE ){
      var jsEvent = fieldJs['event'] + '=' + fieldJs['handler'];
      if(jsEvent=='=') 
        jsEvent='';
      if(fieldType=='file')
          var fieldTag ="<input type='"+fieldType+"' id ='"+fieldId+"' name=uploads_"+ fieldId + " value='" + fieldValue + "' size='30' " + jsEvent + ">";
      else
        var fieldTag = "<input type='"+fieldType+"' id ='" + fieldId + "' name=uploads[" + fieldId + "] value='" + fieldValue + "' size='30' " + jsEvent + ">";
      var fieldObj = document.createElement(fieldTag);
      pare.appendChild(fieldObj);
    }
  }
} 
 // *** index.html
//со страницы photo.html
var saveWidth = 0;

function scaleImg(what){
  what = document.getElementById(what);
  if (navigator.appName=="Netscape")
    winW = window.innerWidth;
  if (navigator.appName.indexOf("Microsoft")!=-1)
    winW = document.body.offsetWidth;
  if (what.width>(700) || saveWidth>(700)) {
    if (what.width==(700))
      what.width=saveWidth;
    else
    {
      saveWidth = what.width;
      what.style.cursor = "pointer";
      what.width=(700);
    }
  }
}
function addBookmark(url, title){
  if (!url) url = location.href;
  if (!title) title = document.title;
 
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  return true;
}
// *** photo.html
//функция отвечает за всплывающее меню в photoalbum.php функция edit_photo()
function showSubMenu(num) {
	if (num) {
		var ID = 'submenu'+num.toString();
		var menu = document.getElementById(ID);
    menu.style.visibility = 'visible';
  }
}
function HideSubMenu(num) {
	if (num) {
		var ID = 'submenu'+num.toString();
		var menu = document.getElementById(ID);
    menu.style.visibility = 'hidden';
  }
}
//функции отвечает за всплывающее меню ввода пароля на фотоальбом в photoalbum.php 
function show_pass_form(el) {
  div = document.getElementById('pass_form');
  if (el.checked) {             
    div.style.display = 'block';
  }
  else {
    div.style.display = 'none';
  }
}
function hide_pass_form(el) {
  div = document.getElementById('pass_form');
  if (el.checked) {             
    div.style.display = 'none'; 
  }
  else {
    div.style.display = 'block'; 
  }
}
function check_values(aForm){
        if (aForm.password1.value != "" && (aForm.password1.value != aForm.password2.value)) {
        alert(password_error);
        aForm.password1.focus();
        return false;          
        }
       if (aForm.category.options[aForm.category.selectedIndex].value==0){
              aForm.description.focus();
         return false;    }
}
// для меню категорий
function openTreeList (what) {
  var x=what.id;
  var status;
 if (document.getElementById("list"+x).style.display != "block") {
  document.getElementById("list"+x).style.display = "block";
 }
 else {
  document.getElementById("list"+x).style.display = "none";
 }
 status=document.getElementById("list"+x).style.display=='none'?0:1;
 document.cookie = 'left_'+x+'='+status+'; domain=hostingfailov.com';
 /* alert (x);*/
}
//для меню выбора категорий при редактировании фотоальбома
function showselected(menu, submenu){
var i;

  if(submenu!=61){
    div = document.getElementById('menu_5_submenu_61');
    div.style.display = 'none'; 
  }
  if(submenu!=89 ){  
    div = document.getElementById('menu_6_submenu_89');
    div.style.display = 'none'; 
  }
  if(submenu!=90 ){  
    div = document.getElementById('menu_6_submenu_90');
    div.style.display = 'none'; 
  }
  if(submenu!=91 ){  
    div = document.getElementById('menu_6_submenu_91');
    div.style.display = 'none'; 
  }
  if(submenu!=92 ){  
    div = document.getElementById('menu_6_submenu_92');
    div.style.display = 'none'; 
  }
  if(submenu!=93 ){  
    div = document.getElementById('menu_6_submenu_93');
    div.style.display = 'none'; 
  }
  if(submenu!=94 ){  
    div = document.getElementById('menu_6_submenu_94');
    div.style.display = 'none'; 
  }
  
  switch(submenu){
    case 5:
      if(menu.value==61){ 
        div = document.getElementById('menu_'+ submenu +'_submenu_'+ menu.value);
        div.style.display = 'block';      
      }
    break;
    case 6:
      if(menu.value==89 || menu.value==90 || menu.value==91 || menu.value==92 || menu.value==93 || menu.value==94){
        div = document.getElementById('menu_'+ submenu +'_submenu_'+ menu.value);
        div.style.display = 'block';         
      }
    break;
    default:
      for(i = 1; i < menu.options.length; i++){ 
        if(menu.options[i].selected){  
          div = document.getElementById('menu_'+ submenu +'_submenu_'+ i);
          div.style.display = 'block';
          if(i==5){
            div = document.getElementById('menu_5_submenu_61');
            div.style.display = 'block';
          }
        }
        else{            
          div = document.getElementById('menu_'+ submenu +'_submenu_'+ i);
          div.style.display = 'none'; 
        }       
      }    
  }
}
//добавляет смаилы при добавлении коментариев к фото
function addSmile(name){
  var comment = window.document.comment_form.comment_text;
  comment.value+= name;
  comment.focus();
}
  // функция для обработки ajax запросов.
  function load_photo(num) {
    JsHttpRequest.query(
      '/external/ajax.php', // путь к backend-скрипту
        // передаем текстовые данные   
      { 'photo': num,  'action': 'load_photo' },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // Вывести отладочные сообщения (если нужно).
        document.getElementById("debug").innerHTML = errors; 
        // Вывести результат работы.
        if( result["str"] == 'yes'){
        document.getElementById("link").innerHTML ='<a href="http://' + result["domen"] + '.hostingfailov.com/photo-' + result["filekey"]+ '">' + result["comment"] + '</a>';
        document.getElementById("prev").innerHTML = result["prev"];
        document.getElementById("next").innerHTML = result["next"]; 
        document.getElementById("comment_photo").innerHTML ='<h2 style="margin:0px">' + result["comment"] + '</h2>';
        document.getElementById("code").innerHTML ='<a href="' + result["base_url"]+ 'code-' + result["filekey"]+ '" target="_blank">' + code_this_photo + '</a> | <a onClick="javascript: void(addBookmark(\'' + result["base_url"]+ 'photo/' + result["filekey"]+ '\',\'hostingfailov.com - ' + result["comment"] + '\') || alert(\'' + browser_bad + '\'))">' + save_photo + '</a>';        
        document.getElementById("image").innerHTML = '<img src="http://dl.hostingfailov.com/full/' + result["filekey"] + '.' + result["type"] + '" border="0" id="thepic" onClick="scaleImg(\'thepic\')" onLoad="scaleImg(\'thepic\')" alt="' + result["comment"] + '" vspace="5">';
        document.getElementById("adress_photo").innerHTML = adr_photo + ' <a href="/photo-' + result["filekey"] + '">' + result["domen"] + '.hostingfailov.com/photo-' + result["filekey"] + '</a>';
        document.getElementById("size").innerHTML ='<span class="smallred">' + result["comment"] + '</span><br>' + result["image_size"] + 'kb.<br> ' + mark_photo + result["image_rate"] +'<br>';
        document.getElementById("user_menu").innerHTML =result["menu_photo"];
        document.getElementById("comment").innerHTML =result["comment_text"]+'<br>';        
        document.getElementById("photo_golos").value =result["filekey"]; 
        document.getElementById("filekey_comment_form").value =result["filekey"]; 
        document.getElementById("id_comment_form").value =result["photo_id"]; 
        //счетчики и реклама
        document.getElementById("count_liveinternet").innerHTML ='<a href="http://www.liveinternet.ru/click;download" target=_blank><img src="http://counter.yadro.ru/logo;download?11.5" title="LiveInternet: показано число просмотров за 24 часа, посетителей за 24 часа и за сегодня" alt="" border=0 width=88 height=31></a>'; 
        document.getElementById("count_mail").innerHTML ='<a target=_top href="http://top.mail.ru/jump?from=1152134"><img src="http://d4.c9.b1.a1.top.list.ru/counter?js=na;id=1152134;t=49" border=0 height=31 width=88 alt="Рейтинг@Mail.ru"/></a>';
        }
      }
    );
  }
//функции показа и скрытия меню изменение логина и пароля
function showMenu(name) {
    div = document.getElementById('form_edit_'  + name);
     div.style.display = 'block';
    div = document.getElementById('link_edit_'  + name);
     div.style.display = 'none';
}
function HideMenu(name) {
  div = document.getElementById('form_edit_'  + name);
   div.style.display = 'none';
  div = document.getElementById('link_edit_'  + name);
   div.style.display = 'block';

}
function close_block(id) {
  document.getElementById(id + '_open').style.display='block';
  document.getElementById(id).style.display='none'; 
  document.getElementById(id + '_close').style.display='none';
}
function open_block(id) {
  document.getElementById(id + '_open').style.display='none';
  document.getElementById(id).style.display='block'; 
  document.getElementById(id + '_close').style.display='inline';
  document.getElementById(id + '_close').style.width='100%';
}
function t_close_block(id, non_id) {
  document.getElementById(id + '_open').style.display='block';
  document.getElementById(id).style.display='none'; 
  document.getElementById(non_id).style.display='block';
  document.getElementById(id + '_close').style.display='none';
}
function t_open_block(id, non_id) {
    document.getElementById(id + '_open').style.display='none';
    document.getElementById(id).style.display='block'; 
    document.getElementById(non_id).style.display='none';
    document.getElementById(id + '_close').style.display='inline';
    document.getElementById(id + '_close').style.width='100%';
    if(id == 'from_url')
      document.getElementById("source").value = '1';
    else
      document.getElementById("source").value = '0';
}
/* вопросы в FAQ*/
function faq(name) {
 if (document.getElementById(name).style.display != "block") {
  document.getElementById(name).style.display = "block";
 }
 else {
  document.getElementById(name).style.display = "none";
 }
}