﻿function openMenu(id) {
    for (var i = 1; i < 15; i++) {
        if (id == 'sub_menu_' + i) {

            if (document.getElementById('sub_menu_' + i).style.display == 'none') 
            {
                document.getElementById('sub_menu_' + i).style.display = 'block';
                document.getElementById('div_' + i).className += " UpLev_Sel";
            }
            else {
                document.getElementById('sub_menu_' + i).style.display = 'none';
                document.getElementById('div_' + i).className -= " UpLev_Sel";
                document.getElementById('div_' + i).className += " UpLevel";
            }
        }
    }
}
function setCookie(name, value) {
    var valueEscaped = escape(value);
    var expiresDate = new Date();
    expiresDate.setTime(expiresDate.getTime() + 365 * 24 * 60 * 60 * 1000);
    var expires = expiresDate.toDateString();
    var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
    if (valueEscaped.length <= 4000)
        document.cookie = newCookie + ";";
}
function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}

function checkright() {
    var isright = document.getElementById("isRight");
    var btn = document.getElementById("btn");
    if (!isright.checked)
        btn.className = "hide";
    else
        btn.className = "";

}
function geturl() {
    var host = document.location.host;
    var s = document.location.pathname;
    //alert(host);
    if (host.indexOf("srf") != -1)
    {
        //alert(s.substr(0,s.indexOf("/",1)));
        return "/" + s.substr(1,s.indexOf("/",1));
    }
    else
        return "/";
}
function GetMonthInParentCase(m) {
    var s = "";
    switch (m)
    {
         case 1:
         s = "января";
          break;
      case 2:
          s = "февраля";
          break;
      case 3:
          s = "марта";
          break;
      case 4:
          s = "апреля";
          break;
      case 5:
          s = "мая";
          break;
      case 6:
          s = "июня";
          break;
      case 7:
          s = "июля";
          break;
      case 8:
          s = "августа";
          break;
      case 9:
          s = "сентября";
          break;
      case 10:
          s = "октября";
          break;
      case 11:
          s = "ноября";
          break;
      case 12:
          s = "декабря";
          break;
     }
     return s;
 }
 function HighlithFrase(phrase, seminar) {
     var arr = phrase.split(' ');
     for (var i = 0; i < arr.length; i++) {
         if (arr[i] != ' ' && arr[i].length > 2) {
             seminar = seminar.replace(new RegExp(arr[i], 'ig'), "<span class='cur-yellow'>" + arr[i] + "</span>");
         }
     }
     return seminar;
 }
 
 
 function GetNameCountSeminar(q,k) {

     if (q != "нет") {
         var s = (q - k).toString();
         var ch = "";
         if (s != "") {
             if ((q-k) == 0)
                 return "нет семинаров";
             else {
                 var len = s.length;
                 ch = s.substr(len - 1, 1);
                 switch (ch) {
                     case "0":
                         s = (q - k) + " семинаров";
                         break;
                     case "1":
                         s = (q - k) + " семинар";
                         break;
                     case "2":
                         s = (q - k) + " семинара";
                         break;
                     case "3":
                         s = (q - k) + " семинара";
                         break;
                     case "4":
                         s = (q - k) + " семинара";
                         break;
                     default:
                         s = (q - k) + " семинаров";
                         break;
                 }
                 if (Number(q - k) < 0)
                     return "нет семинаров";
                 return s;
             }
         }
         else
             return "нет семинаров";
     }
     else
         return "нет семинаров";
 }
 function GetNameCountSubscribe(s) {
     var ch = s.substr(s.length - 1, 1);
     if (s[0] != "1") {
         switch (ch) {
             case "0":
                 s = " рассылок";
                 break;
             case "1":
                 s = " рассылку";
                 break;
             case "2":
                 s = " рассылки";
                 break;
             case "3":
                 s = " рассылки";
                 break;
             case "4":
                 s = " рассылки";
                 break;
             default:
                 s = " рассылок";
         }
     }
     else {
         if (s != "1")
             s = " рассылок";
         else
             s = " рассылку";
     }
     return s;
 }

 function ManagerFoto(id,g) {
     
     var str = { sid: g, id: id };
     var url = geturl();
     if ($("#Foto" + id).attr("value") == "del") {
         if (navigator.userAgent.indexOf("MSIE") != -1) {
             $("#img" + id).attr("style", "filter:alpha(opacity=80, style=3);");
             $("#Foto" + id).attr("class", "id211");
             $("#Foto" + id).html("Восстановить");
         }
         else {
             $("#img" + id).attr("style", "opacity: 0.5;");
             $("#Foto" + id).attr("class", "id211");
             $("#Foto" + id).html("Восстановить");
         }
         $.post("" + url + "Home/DeleteFoto", str, function(result) {
             $("#Foto" + id).attr("value", "rec");
         });

     }
     else {
         if (navigator.userAgent.indexOf("MSIE") != -1) {
             $("#img" + id).attr("style", "filter:alpha(opacity=100);");
             $("#Foto" + id).attr("class", "id207");
             $("#Foto" + id).html("Удалить");
         }
         else {
             $("#img" + id).attr("style", "opacity: 1;");
             $("#Foto" + id).attr("class", "id207");
             $("#Foto" + id).html("Удалить");
         }
         $.post("" + url + "Home/RecoveryFoto", str, function(result) {
             $("#Foto" + id).attr("value", "del");
         });
     }
 }
 
 function ManagerGallery(id,g) {
     
     var str = { sid: g, id: id };
     var url = geturl();
     if ($("#Gallery" + id).attr("value") == "del") {
         if (navigator.userAgent.indexOf("MSIE") != -1) {
             $("#img" + id).attr("style", "filter:alpha(opacity=80, style=3);");
             $("#Gallery" + id).attr("class", "id214");
             $("#Gallery" + id).html("<span>Восстановить</span>");
         }
         else {
             $("#img" + id).attr("style", "opacity: 0.5;");
             $("#Gallery" + id).attr("class", "id214");
             $("#Gallery" + id).html("<span>Восстановить</span>");
         }
         $.post("" + url + "Home/DeleteGalery", str, function(result) {
            $("#Gallery" + id).attr("value", "rec");
            
        });
         
     }
     else {
         if (navigator.userAgent.indexOf("MSIE") != -1) {
             $("#img" + id).attr("style", "filter:alpha(opacity=100);");
             $("#Gallery" + id).attr("class", "id213");
             $("#Gallery" + id).html("<span>Удалить</span>");
         }
         else {
             $("#img" + id).attr("style", "opacity: 1;");
             $("#Gallery" + id).attr("class", "id213");
             $("#Gallery" + id).html("<span>Удалить</span>");
         }
         $.post("" + url + "Home/RecoveryGalery", str, function(result) {
             $("#Gallery" + id).attr("value", "del");
         });
     }
 }
 
