﻿function countChars(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 = pr + num + po;
    }
    else
    {
        num = t - n;
        document.getElementById('cont').innerHTML =  pr + num + po;
    }
    if(e)
    { 
        e = e;
        characterCode = e.which ;
    }
    else
    {
        e = event;
        characterCode = e.keyCode;
    }
} 

function commentVideo(ObjectId, empty, men)
{
    var element = document.getElementById('line').value;
    
    if(element != '' && element != men)
    {
        AddComment(ObjectId, element);
        document.getElementById('commentMessage').innerHTML = element;
        document.getElementById('showSendComment').style.display = 'block';
        document.getElementById('sendComment').style.display = 'none';
    }
    else
    {
        alert(empty);
    }
}

function deleteVideo(Id, mens)
{
    if (confirm(mens))
        Delete(Id);
    else
        return;
}

function deleteComment(commentId, ObjectId, mens)
{
    if (confirm(mens))
    {
        document.getElementById('comment_' + commentId).style.display = 'none';
        var url = '/Global/Services/Comments.asmx/DelInVideo';
        new Ajax.Request(url, { method: 'post', parameters: { ObjectId: ObjectId, Id: commentId },
            onSuccess: function (transport)
            {
                var rsp = transport.responseText.evalJSON().rsp;
                if (rsp.stat != 'fail')
                    alert(rsp.err.msg);
            } 
        });
        document.getElementById('Line_' + commentId).style.display = 'none';
    }
    else
    {
        return;
    }
}

 
function reportarVideo(param, paramId, Owner)
{
    var elem = document.createElement('a');
    var attr = document.createAttribute('rel');
    attr.value = 'shadowbox;width=370;height=340';	            
    elem.setAttributeNode(attr);

    var attr3 = document.createAttribute('href');
    attr3.value = '/Global/Layers/Report.aspx?strObject=' + param + '&strObjectId=' + paramId + '&OwnerId=' + Owner;
    elem.setAttributeNode(attr3);

    Shadowbox.open(elem);
}	     
 
function FavoriteAdd(Name,ObjectTypeId,ObjectId,OwnerId,Status, pre, post)
{
    VideoFavoriteIns(Name,ObjectId, OwnerId);
    alert(pre + Name + post);
}
 
function compartirVideo(paramId, videoType)
{
    var elem = document.createElement('a');
    var attr = document.createAttribute('rel');
    
    if (document.getElementById('UserLogInn').value =='')
    {
        attr.value = 'shadowbox;width=366;height=445';//376
    }
    
    if (document.getElementById('UserLogInn').value !='')
    {
        attr.value = 'shadowbox;width=366;height=445';
    }
    
    elem.setAttributeNode(attr);

    var attr3 = document.createAttribute('href');
    attr3.value = '/Videos/Layers/ShareIt.aspx?idVideo='+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'; 
}
    
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('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';
    }

    if(document.getElementById('txtTitle_'+id).value !='')
    {
        var control_edit_tit = document.getElementById('control_edit_tit_'+id); //label titulo
        var txtTitle = document.getElementById('txtTitle_'+id).value; // guardo el valor del input
        
        control_edit_tit.innerHTML = document.getElementById('txtTitle_'+id).value;  // seteo valor del input
        var url = '/Services/Videos.asmx/TitleUpd';
        
        new Ajax.Request(url, {method: 'post', parameters: {Id: id, Title: txtTitle}, 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;
    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('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';

    }

    if (document.getElementById('txtDescription_' + id).value != '')
    {
        var control_edit_des = document.getElementById('control_edit_des_' + id); //label titulo
        var txtDesc = document.getElementById('txtDescription_' + id).value; // guardo el valor del input

        control_edit_des.innerHTML = document.getElementById('txtDescription_' + id).value  // seteo valor del input

        var url = '/Services/Videos.asmx/DescriptionUpd';
        new Ajax.Request
        (
            url,
            { method: 'post',
                parameters: {
                    Id: id,
                    Description: txtDesc
                },
                onSuccess: function (transport)
                {
                    var rsp = transport.responseText.evalJSON().rsp;
                    if (rsp.stat == 'fail')
                        alert(rsp.err.msg);
                }
            }
        );
    }
}
        
function CancelarDes(id,title, mens)
{
    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 == mens )
    {
        document.getElementById('control_edit_des_'+id).innerHTML = mens;
    }
    
    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++)
    {
        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, pub)
{
    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\">'+pub+'</a>';
}

function publicMassiveComment(commentId, pub)
{
    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\">'+pub+'</a>';    
}
 
function rechazarMassiveComment(commentId, rec)
{
    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\">'+rec+'</a>';
}	     	     
 
function rechazarOneComment(commentToHidden, commentId, objectId, rec)
{
    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\">'+rec+'</a>';
}     
 
function blockOneUser(commentToHidden, commentId, objectId)
{
    VideoBloqUser(commentId, objectId, blo);
    
    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\">'+blo+'</a>';
}
	     
var stars = new Array();
var ObjectId ;

function ObjectVoteSel(ObjectId, error,vot, score)
{
    document.getElementById('starsLoading').style.display = 'block';

    ObjectId = ObjectId;
    
    var url = '/Services/Votes.asmx/videoVoteSel';
    
    new Ajax.Request(url, {   parameters: { ObjectId: ObjectId},onSuccess: function(transport) {     
                                   var rsp = transport.responseText.evalJSON().rsp;
			                       
                                    if(rsp.stat == 'fail')
		                {
		                   alert(error);
		                }
		                else
		                {
                            StarCount = parseInt(rsp.data.StarCount);
                            VotesCount = parseInt(rsp.data.VotesCount);

                            IsVoted = rsp.data.IsVoted;
                            IsLogin = rsp.data.IsLogin;
                            document.getElementById('RateItBox').style.display = 'block';
                            document.getElementById('starsLoading').style.display = 'none';
                            document.getElementById('belowStars').innerHTML = VotesCount + vot;
                            
                            if(IsLogin==1)
                            {
                                if(IsVoted == 1)
                                {

	                                document.getElementById('aboveStars').innerHTML = score;

                                    for(var i = 1; i <= StarCount; i++)
                                    {
	                                    stars[i] = document.getElementById('star' + i);
	                                    stars[i].className = 'starHover';
	                                    stars[i].starNum = i;
                                    }
                                    
                                    for(var i = 1; i <= 5; i++)
                                    {
	                                    stars[i] = document.getElementById('star' + i);
	                                    stars[i].onclick = function(){isVoted()};
	                                    
                                    }		                                    
                                }
                                else
                                {
                                    document.getElementById('aboveStars').innerHTML = score;
                                    document.getElementById('RateItBox').onmouseout = resetStars;
                                    for(var i = 1; i <= 5; i++)
                                    {
	                                    stars[i] = document.getElementById('star' + i);
	                                    stars[i].onmouseover = mouseOverStar;
	                                    stars[i].className = 'star';
	                                    stars[i].starNum = i;
	                                   
                                    }
                                    
                                    for(var i = 1; i <= StarCount; i++)
                                    {
	                                    stars[i].className = 'starHover';
	                                   
                                    }		                                    
                                    
                                }
                                
                            }
                            else
                                    document.getElementById('aboveStars').innerHTML = score;
                                    document.getElementById('RateItBox').onmouseout = resetStars;
                                    for(var i = 1; i <= 5; i++)
                                    {
	                                    stars[i] = document.getElementById('star' + i);
	                                    stars[i].className = 'star';
	                                    stars[i].onmouseover = mouseOverStar;
	                                    stars[i].onclick = function(){starClicklogoff()};
	                                    stars[i].starNum = i;
                                    }
                                    
                                    for(var i = 1; i <= StarCount; i++)
                                    {
	                                    stars[i].className = 'starHover';
	                                   
                                    }		                                    

                            }                     
		                }
                                } ); 
		
}

function mouseOverStar()
{
    for(var i = 1; i <= this.starNum; i++)
    {
        stars[i].className = 'starHover';
    }
    
    for(var i = this.starNum + 1; i <= 5; i++)
    {
        stars[i].className = 'star';
    }
}

function isVoted(me)
{
    document.getElementById('belowStars').innerHTML = me; 
}


function resetStars()
{
    if(StarCount == 0)
    {
        for(var i = 1; i <= 5; i++)
        {
	        stars[i].className = 'star';
        }            
    }
    else
    {
        for(var i = 1; i <= 5; i++)
        {
	        stars[i].className = 'star';
        }             
        for(var i = 1; i <= StarCount; i++)
        {
	        stars[i].className = 'starHover';
        }            
    }
}

function starClicklogoff()
{
    var urlparam = window.location.href;
    var elem = document.createElement('a');
    var attr = document.createAttribute('rel');

    attr.value = 'shadowbox;width=330;height=340';
    elem.setAttributeNode(attr);

    var attr3 = document.createAttribute('href');
    
    attr3.value = '/layerLogin.aspx';
    elem.setAttributeNode(attr3);
    Shadowbox.open(elem);
}

function starClick(vote,ObjectId)
{
    var StarCount = vote;
    var url = '/Services/Votes.asmx/videoVoteIns';	
    											
	new Ajax.Request(url, {
	    method: 'post', 
	    parameters: {
	        ObjectId: ObjectId, 
	        StarCount: StarCount
	    },												
		onSuccess: 
		    function(transport) {     
			    var rsp = transport.responseText.evalJSON().rsp;
			    
				if(rsp.stat != 'fail')
				{
		            var nuevaCantidad = VotesCount + 1;
		            document.getElementById('belowStars').innerHTML = nuevaCantidad + ' votos';
		            document.getElementById('RateItBox').onmouseout = null;
    		        
		            for(var i = 1; i <= 5; i++)
                    {
                        stars[i] = document.getElementById('star' + i);
                        stars[i].onmouseover = null;
                        stars[i].onclick = null;
                    }
                    
		            for(var i = 1; i <= vote; i++)
                    {
                        stars[i] = document.getElementById('star' + i);
                        stars[i].className = 'starVoted';
                    }
				}
			}
        });
    }

    

function tellA()
{
    var elem = document.createElement('a');
    var attr = document.createAttribute('rel');

    attr.value = 'shadowbox;width=610;height=510';

    elem.setAttributeNode(attr);

    var attr3 = document.createAttribute('href');
    attr3.value = 'http://www.freetellafriend.com/tell/?title='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(document.location.href), 'freetellafriend', 'scrollbars=1,menubar=0,width=617,height=530,resizable=1,toolbar=0,location=0,status=0,screenX=210,screenY=100,left=210,top=100';
    elem.setAttributeNode(attr3);

    Shadowbox.open(elem);
}
     
      function ShowLogin()
      {
      var elem = document.createElement('a');
      var attr = document.createAttribute('rel');

      attr.value = 'shadowbox;width=370;height=355';

      elem.setAttributeNode(attr);

      var attr3 = document.createAttribute('href');
      attr3.value = '/Global/Layers/LoginRedirect.aspx', 'hrefLogin', 'scrollbars=1,menubar=0,width=400,height=350,resizable=1,toolbar=0,location=0,status=0,screenX=210,screenY=100,left=210,top=100';
      elem.setAttributeNode(attr3);

      Shadowbox.open(elem);
      }
