﻿     var starsPhoto = new Array();
     var ObjectIdPhoto ;
     
        function ObjectVoteSelPhoto(ObjectId)
        {
            document.getElementById('starsLoadingPhoto').style.display = 'block';

	        ObjectIdPhoto = ObjectId;
            var url = '/Votes/Votes.ashx?photoVoteSel&Format=json';
            new Ajax.Request(url, {   parameters: { ObjectId: ObjectId},onSuccess: function(transport) {     
	                                       var rsp = transport.responseText.evalJSON().rsp;
        			                       
	                                        if(rsp.stat == 'fail')
				                {
				                   alert('Ha ocurrido un error, por favor vuelva a intentar en unos minutos');
				                }
				                else
				                {
                                    StarCountPhoto = parseInt(rsp.data.StarCount);
                                    VotesCountPhoto = parseInt(rsp.data.VotesCount);

                                    IsVotedPhoto = rsp.data.IsVoted;
                                    IsLoginPhoto = rsp.data.IsLogin;
                                    document.getElementById('RateItBoxPhoto').style.display = 'block';
                                    document.getElementById('starsLoadingPhoto').style.display = 'none';
                                    document.getElementById('belowStarsPhoto').innerHTML = VotesCountPhoto + ' votos';
                                    
                                    if(IsLoginPhoto==1)
                                    {
                                        if(IsVotedPhoto == 1)
                                        {
 
			                                document.getElementById('aboveStarsPhoto').innerHTML = 'Puntaje:';
 
		                                    for(var i = 1; i <= StarCountPhoto; i++)
		                                    {
			                                    starsPhoto[i] = document.getElementById('starPhoto' + i);
			                                    starsPhoto[i].className = 'starHover';
			                                    starsPhoto[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsPhoto[i] = document.getElementById('starPhoto' + i);
			                                    starsPhoto[i].onclick = function(){photoVoted()};
			                                    
		                                    }		                                    
                                        }
                                        else
	                                    {
		                                    document.getElementById('aboveStarsPhoto').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxPhoto').onmouseout = resetStarsPhoto;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsPhoto[i] = document.getElementById('starPhoto' + i);
			                                    starsPhoto[i].onmouseover = mouseOverStarPhoto;
			                                    starsPhoto[i].className = 'star';
			                                    starsPhoto[i].starNum = i;
			                                   
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountPhoto; i++)
		                                    {
			                                    starsPhoto[i].className = 'starHover';
			                                   
		                                    }		                                    
		                                    
	                                    }
                                        
                                    }
                                    else
                                    {       //mostrar el panelsito para que largue el login
		                                    document.getElementById('aboveStarsPhoto').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxPhoto').onmouseout = resetStarsPhoto;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsPhoto[i] = document.getElementById('starPhoto' + i);
			                                    starsPhoto[i].className = 'star';
			                                    starsPhoto[i].onmouseover = mouseOverStarPhoto;
			                                    starsPhoto[i].onclick = function(){starClicklogoff()};
			                                    starsPhoto[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountPhoto; i++)
		                                    {
			                                    starsPhoto[i].className = 'starHover';
			                                   
		                                    }		                                    

                                    }                     
				                }
                                        } }); 
        		
        }

        function mouseOverStarPhoto()
        {
        
	        for(var i = 1; i <= this.starNum; i++)
	        {
		        starsPhoto[i].className = 'starHover';
	        }
	        for(var i = this.starNum + 1; i <= 5; i++)
	        {
		        starsPhoto[i].className = 'star';
	        }
        }
        
        
        
        function photoVoted()
        {
            document.getElementById('belowStarsPhoto').innerHTML = ' Foto ya votada!'; 
        }
        
        
        function resetStarsPhoto()
        {
            if(StarCountPhoto == 0)
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsPhoto[i].className = 'star';
	            }            
            }
            else
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsPhoto[i].className = 'star';
	            }             
	            for(var i = 1; i <= StarCountPhoto; i++)
	            {
			        starsPhoto[i].className = 'starHover';
	            }            
            }

        }
        function starClicklogoff()
        {
	        //document.getElementById('VoteNotLogin').style.display = 'block';  // definir si lanzo shadown
	        //alert('Necesita estar logueado para poder votar');
	        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 starClickPhoto(vote,ObjectId)
        {
            var StarCountPhoto = vote;
	        
	               
            var url = '/Votes/Votes.ashx?photoVoteIns&Format=json';												
					new Ajax.Request(url, {method: 'post', parameters: {ObjectId: ObjectId, StarCount: StarCountPhoto },												
									 onSuccess: function(transport) {     
                					 var rsp = transport.responseText.evalJSON().rsp;
															 if(rsp.stat != 'fail')
															    {
															        var nuevaCantidadPhoto = VotesCountPhoto + 1;
															        document.getElementById('belowStarsPhoto').innerHTML = nuevaCantidadPhoto + ' votos';
															        document.getElementById('RateItBoxPhoto').onmouseout = null;
															        
															        for(var i = 1; i <= 5; i++)
				                                                    {
				                                                        starsPhoto[i] = document.getElementById('starPhoto' + i);
					                                                    starsPhoto[i].onmouseover = null;
					                                                    starsPhoto[i].onclick = null;
				                                                    }
				                                                    
															        for(var i = 1; i <= vote; i++)
				                                                    {
				                                                        starsPhoto[i] = document.getElementById('starPhoto' + i);
					                                                    starsPhoto[i].className = 'starVoted';
				                                                    }				                                                    
															    }
															        

																			
                        } });

        }
        
        

// ############################################################## END PHOTO VOTE ##############################################################################################        


     var starsVideo = new Array();
     var ObjectIdVideo ;
     
        function ObjectVoteSelVideo(ObjectId)
        {
            document.getElementById('starsLoadingVideo').style.display = 'block';

	        ObjectIdVideo = ObjectId;
            var url = '/Votes/Votes.ashx?videoVoteSel&Format=json';
            new Ajax.Request(url, {   parameters: { ObjectId: ObjectId},onSuccess: function(transport) {     
	                                       var rsp = transport.responseText.evalJSON().rsp;
        			                       
	                                        if(rsp.stat == 'fail')
				                {
				                   alert('Ha ocurrido un error, por favor vuelva a intentar en unos minutos');
				                }
				                else
				                {
                                    StarCountVideo = parseInt(rsp.data.StarCount);
                                    VotesCountVideo = parseInt(rsp.data.VotesCount);

                                    IsVotedVideo = rsp.data.IsVoted;
                                    IsLoginVideo = rsp.data.IsLogin;
                                    document.getElementById('RateItBoxVideo').style.display = 'block';
                                    document.getElementById('starsLoadingVideo').style.display = 'none';
                                    document.getElementById('belowStarsVideo').innerHTML = VotesCountVideo + ' votos';
                                    
                                    if(IsLoginVideo==1)
                                    {
                                        if(IsVotedVideo == 1)
                                        {
 
			                                document.getElementById('aboveStarsVideo').innerHTML = 'Puntaje:';
 
		                                    for(var i = 1; i <= StarCountVideo; i++)
		                                    {
			                                    starsVideo[i] = document.getElementById('starVideo' + i);
			                                    starsVideo[i].className = 'starHover';
			                                    starsVideo[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsVideo[i] = document.getElementById('starVideo' + i);
			                                    starsVideo[i].onclick = function(){videoVoted()};
			                                    
		                                    }		                                    
                                        }
                                        else
	                                    {
		                                    document.getElementById('aboveStarsVideo').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxVideo').onmouseout = resetStarsVideo;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsVideo[i] = document.getElementById('starVideo' + i);
			                                    starsVideo[i].onmouseover = mouseOverStarVideo;
			                                    starsVideo[i].className = 'star';
			                                    starsVideo[i].starNum = i;
			                                   
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountVideo; i++)
		                                    {
			                                    starsVideo[i].className = 'starHover';
			                                   
		                                    }		                                    
		                                    
	                                    }
                                        
                                    }
                                    else
                                    {       //mostrar el panelsito para que largue el login
		                                    document.getElementById('aboveStarsVideo').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxVideo').onmouseout = resetStarsVideo;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsVideo[i] = document.getElementById('starVideo' + i);
			                                    starsVideo[i].className = 'star';
			                                    starsVideo[i].onmouseover = mouseOverStarVideo;
			                                    starsVideo[i].onclick = function(){starClicklogoff()};
			                                    starsVideo[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountVideo; i++)
		                                    {
			                                    starsVideo[i].className = 'starHover';
			                                   
		                                    }		                                    

                                    }                     
				                }
                                        } }); 
        		
        }

        function mouseOverStarVideo()
        {
	        for(var i = 1; i <= this.starNum; i++)
	        {
		        starsVideo[i].className = 'starHover';
	        }
	        for(var i = this.starNum + 1; i <= 5; i++)
	        {
		        starsVideo[i].className = 'star';
	        }
        }
        
        function videoVoted()
        {
            document.getElementById('belowStarsVideo').innerHTML = ' Video ya votado!'; 
        }
        
        
        function resetStarsVideo()
        {
            if(StarCountVideo == 0)
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsVideo[i].className = 'star';
	            }            
            }
            else
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsVideo[i].className = 'star';
	            }             
	            for(var i = 1; i <= StarCountVideo; i++)
	            {
			        starsVideo[i].className = 'starHover';
	            }            
            }

        }
        function starClicklogoff()
        {
	        //document.getElementById('VoteNotLogin').style.display = 'block';  // definir si lanzo shadown
	        //alert('Necesita estar logueado para poder votar');
	        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 starClickVideo(vote,ObjectId)
        {
            var StarCountVideo = vote;
	        
	               
            var url = '/Votes/Votes.ashx?videoVoteIns&Format=json';												
					new Ajax.Request(url, {method: 'post', parameters: {ObjectId: ObjectId, StarCount: StarCountVideo },												
									 onSuccess: function(transport) {     
                					 var rsp = transport.responseText.evalJSON().rsp;
															 if(rsp.stat != 'fail')
															    {
															        var nuevaCantidadVideo = VotesCountVideo + 1;
															        document.getElementById('belowStarsVideo').innerHTML = nuevaCantidadVideo + ' votos';
															        document.getElementById('RateItBoxVideo').onmouseout = null;
															        
															        for(var i = 1; i <= 5; i++)
				                                                    {
				                                                        starsVideo[i] = document.getElementById('starVideo' + i);
					                                                    starsVideo[i].onmouseover = null;
					                                                    starsVideo[i].onclick = null;
				                                                    }
				                                                    
															        for(var i = 1; i <= vote; i++)
				                                                    {
				                                                        starsVideo[i] = document.getElementById('starVideo' + i);
					                                                    starsVideo[i].className = 'starVoted';
				                                                    }				                                                    
															    }
															        

																			
                        } });

        }
        
        
        
// ############################################################## END VIDEO VOTE ##############################################################################################                

     var starsNote = new Array();
     var ObjectIdNote ;
     
        function ObjectVoteSelNote(ObjectId)
        {
            document.getElementById('starsLoadingNote').style.display = 'block';

	        ObjectIdNote = ObjectId;
            var url = '/Votes/Votes.ashx?noteVoteSel&Format=json';
            new Ajax.Request(url, {   parameters: { ObjectId: ObjectId},onSuccess: function(transport) {     
	                                       var rsp = transport.responseText.evalJSON().rsp;
        			                       
	                                        if(rsp.stat == 'fail')
				                {
				                   alert('Ha ocurrido un error, por favor vuelva a intentar en unos minutos');
				                }
				                else
				                {
                                    StarCountNote = parseInt(rsp.data.StarCount);
                                    VotesCountNote = parseInt(rsp.data.VotesCount);

                                    IsVotedNote = rsp.data.IsVoted;
                                    IsLoginNote = rsp.data.IsLogin;
                                    document.getElementById('RateItBoxNote').style.display = 'block';
                                    document.getElementById('starsLoadingNote').style.display = 'none';
                                    document.getElementById('belowStarsNote').innerHTML = VotesCountNote + ' votos';
                                    
                                    if(IsLoginNote==1)
                                    {
                                        if(IsVotedNote == 1)
                                        {
 
			                                document.getElementById('aboveStarsNote').innerHTML = 'Puntaje:';
 
		                                    for(var i = 1; i <= StarCountNote; i++)
		                                    {
			                                    starsNote[i] = document.getElementById('starNote' + i);
			                                    starsNote[i].className = 'starHover';
			                                    starsNote[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsNote[i] = document.getElementById('starNote' + i);
			                                    starsNote[i].onclick = function(){noteVoted()};
			                                    
		                                    }		                                    
                                        }
                                        else
	                                    {
		                                    document.getElementById('aboveStarsNote').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxNote').onmouseout = resetStarsNote;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsNote[i] = document.getElementById('starNote' + i);
			                                    starsNote[i].onmouseover = mouseOverStarNote;
			                                    starsNote[i].className = 'star';
			                                    starsNote[i].starNum = i;
			                                   
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountNote; i++)
		                                    {
			                                    starsNote[i].className = 'starHover';
			                                   
		                                    }		                                    
		                                    
	                                    }
                                        
                                    }
                                    else
                                    {       //mostrar el panelsito para que largue el login
		                                    document.getElementById('aboveStarsNote').innerHTML = 'Puntaje:';
		                                    document.getElementById('RateItBoxNote').onmouseout = resetStarsNote;
		                                    for(var i = 1; i <= 5; i++)
		                                    {
			                                    starsNote[i] = document.getElementById('starNote' + i);
			                                    starsNote[i].className = 'star';
			                                    starsNote[i].onmouseover = mouseOverStarNote;
			                                    starsNote[i].onclick = function(){starClicklogoff()};
			                                    starsNote[i].starNum = i;
		                                    }
		                                    
		                                    for(var i = 1; i <= StarCountNote; i++)
		                                    {
			                                    starsNote[i].className = 'starHover';
			                                   
		                                    }		                                    

                                    }                     
				                }
                                        } }); 
        		
        }

        function mouseOverStarNote()
        {
	        for(var i = 1; i <= this.starNum; i++)
	        {
		        starsNote[i].className = 'starHover';
	        }
	        for(var i = this.starNum + 1; i <= 5; i++)
	        {
		        starsNote[i].className = 'star';
	        }
        }
        
        function noteVoted()
        {
            document.getElementById('belowStarsNote').innerHTML = ' Nota ya votada!'; 
        }
        
        
        function resetStarsNote()
        {
            if(StarCountNote == 0)
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsNote[i].className = 'star';
	            }            
            }
            else
            {
	            for(var i = 1; i <= 5; i++)
	            {
			        starsNote[i].className = 'star';
	            }             
	            for(var i = 1; i <= StarCountNote; i++)
	            {
			        starsNote[i].className = 'starHover';
	            }            
            }

        }
        function starClicklogoff()
        {
	        //document.getElementById('VoteNotLogin').style.display = 'block';  // definir si lanzo shadown
	        //alert('Necesita estar logueado para poder votar');
	        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 starClickNote(vote,ObjectId)
        {
            var StarCountNote = vote;
	        
	               
            var url = '/Votes/Votes.ashx?noteVoteIns&Format=json';												
					new Ajax.Request(url, {method: 'post', parameters: {ObjectId: ObjectId, StarCount: StarCountNote },												
									 onSuccess: function(transport) {     
                					 var rsp = transport.responseText.evalJSON().rsp;
															 if(rsp.stat != 'fail')
															    {
															        var nuevaCantidadNote = VotesCountNote + 1;
															        document.getElementById('belowStarsNote').innerHTML = nuevaCantidadNote + ' votos';
															        document.getElementById('RateItBoxNote').onmouseout = null;
															        
															        for(var i = 1; i <= 5; i++)
				                                                    {
				                                                        starsNote[i] = document.getElementById('starNote' + i);
					                                                    starsNote[i].onmouseover = null;
					                                                    starsNote[i].onclick = null;
				                                                    }
				                                                    
															        for(var i = 1; i <= vote; i++)
				                                                    {
				                                                        starsNote[i] = document.getElementById('starNote' + i);
					                                                    starsNote[i].className = 'starVoted';
				                                                    }				                                                    
															    }
															        

																			
                        } });

        }