﻿function commentsAnswer(id){
    jQuery("#commentForm").find("input:hidden").val(id);
    location.href=  '#commentForm';
}

function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    else return;
    return txt;
}



 //additional properties for jQuery object
jQuery(document).ready(function(){
   //align element in the middle of the screen
   jQuery.fn.alignCenter = function() {
      //get margin left
      var marginLeft =  - jQuery(this).width()/2 + 'px';
      //get margin top
      var marginTop =  - jQuery(this).height()/2 + 'px';
      //return updated element
      return jQuery(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

   jQuery.fn.togglePopup = function(){
     //detect whether popup is visible or not
     //if(jQuery('#popup').hasClass("hidden"))
     if(jQuery('#popup').hasClass("hidden"))
     {
       //hidden - then display
       //when IE - fade immediately
       if(jQuery.browser.msie)
       {
         jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden')
                    .click(function(){jQuery(this).togglePopup();});
       }
       else
       //in all the rest browsers - fade slowly
       {
         jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden').fadeTo('slow', 0.6)
                    .click(function(){jQuery(this).togglePopup();});
       }

       jQuery('#popup')
         .html($(this).html())
         .alignCenter()
         .toggleClass('hidden');
         jQuery('#frame').attr("height", 1);
     }
     else
     {
          jQuery('#frame').attr("height", 600);
       //visible - then hide
       jQuery('#opaco').toggleClass('hidden').removeAttr('style').unbind('click');
       jQuery('#popup').toggleClass('hidden');
     }
   };
});

// document.onkeypress = function(){
//        var e = arguments[0] || window.event;
//        var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode);
//        if(e.ctrlKey && code==13){
//                var text = getSelText();
//                jQuery('#popup').togglePopup();
//
//        }
// }

function showPopupNotice(){
     var  text = new String(getSelText());

     if(text.length > 400){
         alert ("Р’С‹РґРµР»РµРЅРѕ СЃР»РёС€РєРѕРј РјРЅРѕРіРѕ С‚РµРєСЃС‚Р°");
         return false;
     }
     jQuery('#popup').togglePopup();
     jQuery('#textValue').val(text);
     jQuery('#linkValue').val(location.href);
     jQuery('#error-text').text(jQuery('#textValue').val());
}
var sendMessage = function(successText){
          jQuery.ajax({
              type: 'POST',
              url: jQuery("#bug").attr('action'),
              dataType: 'html',
              global: false,
              data: jQuery("#bug").serializeArray(),
              success : function(data) {
                  alert(successText);
              }
            });
    jQuery('#popup').togglePopup();
}

var DownloadStatistic = function(url){
          jQuery.ajax({
              type: 'POST',
              url: url,
              dataType: 'html',
              global: false,
              data: ({action : 'downloadstat'}),
              success : function(data) {
                  
              }
            });
    
}
var subscribeNotification = function (url, elem){
    jQuery.ajax({
              type: 'POST',
              url: url,
              dataType: 'html',
              global: false,
              data: ({action : 'subscribe',subscribe : jQuery(elem).attr("checked")}),
              success : function(data) {
                alert(data);
              }
            });
}

var errorDownloadLink = function (url,text){
     jQuery.ajax({
              type: 'POST',
              url: url,
              dataType: 'html',
              global: false,
              data: ({action : 'errorLink', link : url}),
              success : function(data) {
                alert(text);
              }
            });
}


var getSize = function(nameInputLink, nameSizeLink){

          jQuery.ajax({
              type: 'POST',
              url: location.href,
              dataType: 'html',
              global: false,
              data: ({action : 'getsize', url: jQuery('input:[name="'+nameInputLink+'"]').val()}),
              success : function(data) {
              if(data != ''){
                  jQuery('input:[name="'+nameSizeLink+'"]').val(data +' MB');
              }else{
                  alert('Невозможно получить размер. Проверьте ссылку');
              }

              }
            });
}
