﻿        function cambio(e)
        {
            var element = document.getElementById('line').value
            n = element.length;
            t = 164;
            if (n > t)
            {
                document.getElementById('line').value = document.getElementById('line').value.substring(0, t);
                document.getElementById('cont').innerHTML = 'Te quedan ' + num + ' caracteres';
            }
            else
            {
                num = t - n;
                document.getElementById('cont').innerHTML = 'Te quedan ' + num + ' caracteres';
            }
            if(e)
            { 
    	        e = e;
	            characterCode = e.which ;
	        }
            else
            {
	            e = event;
    	        characterCode = e.keyCode;
	        }
	        
            if (n >= 39 || characterCode == 13)
            {
                document.getElementById('line').style.height = '120px';
            }
            else
            {
                document.getElementById('line').style.height = '23px';
            } 

        } 
	     
	     function FavoriteAdd(Name,ObjectTypeId,ObjectId,OwnerId,Status, elementId)
	     {
	        VideoFavoriteIns(Name,ObjectId, OwnerId);
            alert('Se agregó el video \"' + Name + '\" a tus Favoritos.');
            //window.location.reload();
            
            document.getElementById(elementId).onclick = null;
            document.getElementById(elementId).innerHTML = 'Ya es Favorito';
            
	     }        
        
        function refresh()
        {
         if (document.getElementById('line').value == 'Hace click para comentar')
            document.getElementById('line').value = '';
        }
        
        function checkEmpty()
        {
            var element = document.getElementById('line').value;
            if(element == '')
            {
                document.getElementById('line').value = 'Hace click para comentar';
            }
        }          
        
        
        function commentVideo(ObjectId)
        {
            var element = document.getElementById('line').value;
            
            if(element != '' && element != 'Hace click para comentar' )
            {
                AddComment(ObjectId, element);
                document.getElementById('commentMessage').innerHTML = element;
                document.getElementById('showSendComment').style.display = 'block';
                document.getElementById('sendComment').style.display = 'none';
            }
            else
            {
                alert('No puede dejar un comentario vacio');
            }
        }
        
        function deleteVideo(Id)
        {
    
            if(confirm('¿está seguro que desea eliminar el video?'))
            {
               Delete(Id,2001);
               window.location = './';
            }
            else
            {
                return;
            }
        }
        
        function deleteComment(commentId, ObjectId)
        {
            if(confirm('¿está seguro que desea eliminar el comentario?'))
            {
               document.getElementById('comment_' + commentId).style.display = 'none';
               DeleteComment(ObjectId,2001,commentId);
            }
            else
            {
                return;
            }        
            
        }

        function compartirVideo(param,type)
        {
          var elem = document.createElement('a');
	        var attr = document.createAttribute('rel');
	        if (document.getElementById('UserLogInn').value =='')
	        {
	        
	            attr.value = 'shadowbox;width=390;height=432';//376
	        }
	        if (document.getElementById('UserLogInn').value !='')
	        {
	        
	            attr.value = 'shadowbox;width=390;height=432';
	        }
	        elem.setAttributeNode(attr);

	        var attr3 = document.createAttribute('href');
	        attr3.value = '/LayerShareVideo.aspx?idVideo='+param+'&type='+type;
	        elem.setAttributeNode(attr3);

	        Shadowbox.open(elem);
	     }
	     
	     function reportarVideo(param, paramId)
	     {
	     var elem = document.createElement('a');
	        var attr = document.createAttribute('rel');
	        attr.value = 'shadowbox;width=368;height=340';                                           	        	        
	        elem.setAttributeNode(attr);

	        var attr3 = document.createAttribute('href');
	        attr3.value = '/LayerReport.aspx?strObject='+param+'&strObjectId='+paramId;
	        elem.setAttributeNode(attr3);

	        Shadowbox.open(elem);
	     }	     
	     

	     

function ActiveEditTitulo(id)
    {
    
        document.getElementById('control_edit_tit_'+id).style.display='none'; 
        document.getElementById('div_control_edit_tit_'+id).style.display='none'; 
        document.getElementById('edit_tit_'+id).style.display='block';   //muestro edicion
        
        
        document.getElementById('control_edit_des_'+id).style.display='block'; 
       
        document.getElementById('edit_des_'+id).style.display='none'; 
        
        //document.getElementById('lahora').style.display='none';  
     
    }
    
    function GuardarTit(id)
    {

        document.getElementById('control_edit_tit_'+id).innerText =  document.getElementById('txtTitle_'+id).value ;  //seteo
        document.getElementById('txtTitle_'+id).value = document.getElementById('control_edit_tit_'+id).innerText;
        
        
        document.getElementById('edit_tit_'+id).style.display='none';  //oculto la edicion
        //document.getElementById('lahora').style.display='block';  
        
        document.getElementById('div_control_edit_tit_'+id).style.display='block'; 
        
        if(document.getElementById('txtTitle_'+id).value  =='' || document.getElementById('txtTitle_'+id).value  =='Agregar titulo')
        {
             document.getElementById('edit_tit_'+id).style.display='block';  //obligo a que no sea null
             document.getElementById('control_edit_tit_'+id).style.display='none';
             
        }
        else
        {
             document.getElementById('edit_tit_'+id).style.display='none';  
             document.getElementById('control_edit_tit_'+id).style.display='block';  // muestro el nuevo
             document.getElementById('div_control_edit_tit_'+id).style.display='block';  
        }
        
        //Community_TitleUpd
        if(document.getElementById('txtTitle_'+id).value !='')
            {
                var title = document.getElementById('txtTitle_'+id).value ;
                 var url = '/Video/Video.ashx?Community_TitleUpd&Format=json';												
		            new Ajax.Request(url, {method: 'post', parameters: {VideoId: id,Title: title}, onSuccess: function(transport) 
		                {
                                var rsp = transport.responseText.evalJSON().rsp;
					                if(rsp.stat == 'fail')
						                alert(rsp.err.msg);
                                }
                            }
                        );
             }
        }
        function CancelarTit(id,title)
        {
        
            document.getElementById('control_edit_tit_'+id).style.display='block'; 
            document.getElementById('div_control_edit_tit_'+id).style.display='block'; 
            document.getElementById('edit_tit_'+id).style.display='none';     
            document.getElementById('control_edit_tit_'+id).innerText =document.getElementById('control_edit_tit_'+id).innerText;
            //document.getElementById('lahora').style.display='block';  
            
            
             if(document.getElementById('txtTitle_'+id).value =='' || document.getElementById('txtTitle_'+id).value =='Agregar titulo' )
             {
                document.getElementById('control_edit_tit_'+id).innerHTML = 'Agregar titulo';
             }
        }



    function ActiveEditDescription(id)
    {
    
        document.getElementById('control_edit_des_'+id).style.display='none'; 
        
        document.getElementById('divDelLabel').style.display='none';
        
        document.getElementById('edit_des_'+id).style.display='block';   //muestro edicion
        
        
         document.getElementById('control_edit_tit_'+id).style.display='block'; 
         document.getElementById('div_control_edit_tit_'+id).style.display='block'; 
       
        document.getElementById('edit_tit_'+id).style.display='none';
        
        
        document.getElementById('txtDescription_'+id).value =  document.getElementById('control_edit_des_'+id).innerHTML;
    }
    
    function GuardarDes(id)
    {
   
        document.getElementById('control_edit_des_'+id).innerText = document.getElementById('txtDescription_'+id).value ;  //seteo
        document.getElementById('txtDescription_'+id).value = document.getElementById('control_edit_des_'+id).innerText ; //para evitar que al Cancelar recargue el anterior
        document.getElementById('edit_des_'+id).style.display='none';  //oculto la edicion
        
        
        if(document.getElementById('txtDescription_'+id).value  =='')
        {
             document.getElementById('edit_des_'+id).style.display='block';  //obligo a que no sea null
             document.getElementById('control_edit_des_'+id).style.display='none';  
        }
        else
        {
             document.getElementById('edit_des_'+id).style.display='none';  
             document.getElementById('control_edit_des_'+id).style.display='block';  // muestro el nuevo
             
             document.getElementById('divDelLabel').style.display='block';
         
        }
        
        //Community_DescriptionUpd
        if(document.getElementById('txtDescription_'+id).value !='')
            {
                var title = document.getElementById('txtDescription_'+id).value ;
                 var url = '/Video/Video.ashx?Community_DescriptionUpd&Format=json';												
		            new Ajax.Request(url, {method: 'post', parameters: {VideoId: id,Description: title}, onSuccess: function(transport) 
		                {
                                var rsp = transport.responseText.evalJSON().rsp;
					                if(rsp.stat == 'fail')
						                alert(rsp.err.msg);
                                }
                            }
                        );
             }
        }
        function CancelarDes(id,title)
        {
        
            document.getElementById('control_edit_des_'+id).style.display='block'; 
            document.getElementById('edit_des_'+id).style.display='none';     
             document.getElementById('control_edit_des_'+id).innerText =document.getElementById('control_edit_des_'+id).innerText;
                         
             if(document.getElementById('txtDescription_'+id).value =='' || document.getElementById('txtDescription_'+id).value == 'Agregar descripcion ' )
             {
                document.getElementById('control_edit_des_'+id).innerHTML = 'Agregar descripcion';
             } 
             document.getElementById('divDelLabel').style.display='block';
            
        }








	     function publicAllComment(objectId)
	     {
	        var countOfComment = document.getElementById('totalPendComment').getElementsByTagName('input');
	        
	        var commentIdCollection = '';
	        
           
	        for(x=0; x < countOfComment.length; x++)
	        {
	            //alert('gg');

	            if(countOfComment.item(x).checked == true && countOfComment.item(x).style.display != 'none')
	            {
	                var collectionId = countOfComment.item(x).value;
                    
	                commentIdCollection = commentIdCollection + collectionId + ', ';
	                
	                publicMassiveComment(collectionId);
	                
	            }
	        }	        
	        
	        commentIdCollection = commentIdCollection.substring(0,commentIdCollection.length-2);
	        
	        VideoApproval(commentIdCollection, objectId);
	     }
	     
	     
	     function rechazarAllComment(objectId)
	     {
	        var countOfComment = document.getElementById('totalPendComment').getElementsByTagName('input');
	        
	        var commentIdCollection = '';
	        
           
	        for(x=0; x < countOfComment.length; x++)
	        {
	            //alert('gg');

	            if(countOfComment.item(x).checked == true && countOfComment.item(x).style.display != 'none')
	            {
	                var collectionId = countOfComment.item(x).value;
                    
	                commentIdCollection = commentIdCollection + collectionId + ', ';
	                
	                rechazarMassiveComment(collectionId);
	                
	            }
	        }	        
	        
	        commentIdCollection = commentIdCollection.substring(0,commentIdCollection.length-2);
	        
	        VideoDesapproval(commentIdCollection, objectId);
	     }	     
     
	     
	     function selectAllComment()
	     {
	        var countOfComment = document.getElementById('totalPendComment').getElementsByTagName('input');
	        
	        for(x=0; x < countOfComment.length; x++)
	        {
	            countOfComment.item(x).checked = true;
	        }
	     }
	     
	     function unchekedAllComment()
	     {
	        var countOfComment = document.getElementById('totalPendComment').getElementsByTagName('input');
	        
	        for(x=0; x < countOfComment.length; x++)
	        {
	            countOfComment.item(x).checked = false;
	        }
	     }	     
	     
	     
	     
	     function publicOneComment(commentToHidden, commentId, objectId)
	     {
	        VideoApproval(commentId, objectId);
	        var commentStatusInput = document.getElementById('commentStatus_' + commentId).getElementsByTagName('input').item(0);
	        
	        var countOfCommentToAprobal = parseInt(document.getElementById('countOfAprobalComment').value);
	        var nuevaCantidad = document.getElementById('countOfAprobalComment').value = countOfCommentToAprobal - 1;
	        
	        
	        document.getElementById('cantidadDeCommenPend').innerHTML = '(' + nuevaCantidad + ')';
            
            var commentStatus = document.getElementById('commentStatus_' + commentId);
            commentStatus.removeChild(commentStatusInput);
            
            document.getElementById('acctionPendComment_' + commentId).innerHTML = '<a class=\"btnPublicado\">Publicado</a>';
	        
	     }
	     
	     function publicMassiveComment(commentId)
	     {
	     
	        var commentStatusInput = document.getElementById('commentStatus_' + commentId).getElementsByTagName('input').item(0);
	        
	        var countOfCommentToAprobal = parseInt(document.getElementById('countOfAprobalComment').value);
	        var nuevaCantidad = document.getElementById('countOfAprobalComment').value = countOfCommentToAprobal - 1;
	        
	     
	        document.getElementById('cantidadDeCommenPend').innerHTML = '(' + nuevaCantidad + ')';
            
            var commentStatus = document.getElementById('commentStatus_' + commentId);
         
            commentStatusInput.style.display = 'none';
            
            document.getElementById('acctionPendComment_' + commentId).innerHTML = '<a class=\"btnPublicado\">Publicado</a>';
	        
	     }
	     
	     
	     function rechazarMassiveComment(commentId)
	     {
	     
	        var commentStatusInput = document.getElementById('commentStatus_' + commentId).getElementsByTagName('input').item(0);
	        
	        var countOfCommentToAprobal = parseInt(document.getElementById('countOfAprobalComment').value);
	        var nuevaCantidad = document.getElementById('countOfAprobalComment').value = countOfCommentToAprobal - 1;
	        
	     
	        document.getElementById('cantidadDeCommenPend').innerHTML = '(' + nuevaCantidad + ')';
            
            var commentStatus = document.getElementById('commentStatus_' + commentId);
         
            commentStatusInput.style.display = 'none';
            
            document.getElementById('acctionPendComment_' + commentId).innerHTML = '<a class=\"btnRechazado\">Rechazado</a>';
	        
	     }	     	     
	     
	     
	     
	     function rechazarOneComment(commentToHidden, commentId, objectId)
	     {
	        VideoDesapproval(commentId, objectId);
	        var commentStatusInput = document.getElementById('commentStatus_' + commentId).getElementsByTagName('input').item(0);
	        
	        var countOfCommentToAprobal = parseInt(document.getElementById('countOfAprobalComment').value);
	        var nuevaCantidad = document.getElementById('countOfAprobalComment').value = countOfCommentToAprobal - 1;
	        
	        
	        document.getElementById('cantidadDeCommenPend').innerHTML = '(' + nuevaCantidad + ')';
            
            var commentStatus = document.getElementById('commentStatus_' + commentId);
            commentStatus.removeChild(commentStatusInput);
            
            document.getElementById('acctionPendComment_' + commentId).innerHTML = '<a class=\"btnRechazado\">Rechazado</a>';

	     }	     
	     
	     
	     function blockOneUser(commentToHidden, commentId, objectId)
	     {
	        VideoBloqUser(commentId, objectId);
	        var commentStatusInput = document.getElementById('commentStatus_' + commentId).getElementsByTagName('input').item(0);
	        
	        var countOfCommentToAprobal = parseInt(document.getElementById('countOfAprobalComment').value);
	        var nuevaCantidad = document.getElementById('countOfAprobalComment').value = countOfCommentToAprobal - 1;
	        
	        
	        document.getElementById('cantidadDeCommenPend').innerHTML = '(' + nuevaCantidad + ')';
            
            var commentStatus = document.getElementById('commentStatus_' + commentId);
            commentStatus.removeChild(commentStatusInput);
            
            document.getElementById('acctionPendComment_' + commentId).innerHTML = '<a class=\"btnBloqueado\">Bloqueado</a>';
	        
	     }	 