


/* função que direciona para adição de video na playlist
 * consulta se video ja foi adicionado 
 * retorna alert ao usuario caso retorno seja 'true' */
function adicionar(video,url,idioma)
{
	var id = video;
	var end = url;	
	var texto = '';
	var t = '';
	var alerta = '';

	
	if(idioma == 'en'){
		texto = 'Video can not be added because it already belongs to your playlist';
		t = 'Video added';
		alerta = 'To add videos, login!';
	}else if(idioma == 'pt-br'){
		texto = 'Video nao pode ser adicionado, pois ja pertence a sua playlist!';
		t = 'Vídeo adicionado!';
		alerta = 'Para adicionar vídeos, faça seu login!';
	}else if(idioma == 'es'){
		texto = 'Video no se puede añadir porque ya pertenece a tu lista de reproducción!';
		t = 'Video añadido';
		alerta = 'Para agregar videos, inicio de sesión!';
	}else if(idioma == 'it'){
		texto = 'Video non può essere aggiunto perché appartiene già alla tua playlist!';
		t = 'Video ha aggiunto';
		alerta = 'Per aggiungere i video, il login!';
	}else if(idioma == 'fr'){
		texto = 'Vidéo ne peut être ajouté, car il appartient déjà à votre playlist!';
		t = 'Vidéo ajoutée!';
		alerta = 'Pour ajouter des vidéos, connectez-vous!';
	}			

	

	jQuery.ajax({
		url: end +'playlist/add/',
		type: 'post',
		dataType: 'Json',
		data: {
		       video: id,
		       endereco: end
			
		},
		success: function (data) {
			var resposta = data;
			
			// Caso tenha tido erro na validacao do login  
			if (resposta == 'true'){ 
				alert(t);
			}
			else if (resposta == 'false') {	
				alert(texto);
			}
			else {	
				alert(alerta);
			}		
		}
	});


// 	jQuery.ajax({
// 		cache:false,
//         	async:false,
// 		url:'/webtv_teste/playlist/add/',
// 		type: 'post',
// 		dataType: 'Json',
// 		data: {
// 			video: id
// 		},
// 		success: function (data) {
// 			var resposta = data;
// 			
// 		
// 			if (resposta == 'false'){ 
//  				alert(texto);
//  			}else if (resposta == 'true'){
//  				alert(t);
//  			}
// 						
// 		}
// 	});

}




//função para abrir topDez
function abrir(titulo,end)
{

	var titulo = titulo;
	var end = end;	
	
	jQuery.ajax({
		url: end+'topdez',
		type: 'post',
		data: {
			titulo: titulo
		},
		success: function (data)
			{
				jQuery('#videos-top10').html(data);
			}
	});

}

//abrir formulario de comentarios
function abrirForm(end,acao,video)
{
	
	jQuery.ajax({
		url: end+'comentarios/'+acao,
		type: 'post',
		data: {
			video: video
		},
		success: function(data){
			jQuery('#exibecomentario').html(data);
		}
	});
	
	

}


// *****************************
//funções para a votação das estrelas
// *****************************

try { 
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (e) { 
    try { 
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } catch (E) { 
        xmlhttp = false; 
    } 
} 

if  (!xmlhttp && typeof  XMLHttpRequest != 'undefined' ) { 
    try  { 
        xmlhttp = new  XMLHttpRequest(); 
    } catch  (e) { 
        xmlhttp = false ; 
    } 
} 

/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $(v,o) { 
	return((typeof(o)=='object'?o:document).getElementById(v)); 
}
function $S(o) { 
	return((typeof(o)=='object'?o:$(o)).style); 
}
function agent(v) { 
	return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); 
}
function abPos(o) { 
	var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; 
	while(o!=null) { 
		z.X+=o.offsetLeft; 
		z.Y+=o.offsetTop; 
		o=o.offsetParent; 
	}; 
	return(z); 
}
function XY(e,v) { 
	var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; 
	return(v?o[v]:o); 
}

star= {};

star.mouse=function(e,o) { 
	if(star.stop || isNaN(star.stop)) { 
		star.stop=0;

	document.onmousemove=function(e) { 
		var n=star.num;
	
		var p=abPos($('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

		if(oX<1 || oX>84 || oY<0 || oY>19) { 
			star.stop=1; 
			star.revert(); 
		}
		else {

			$S('starCur'+n).width=oX+'px';
			$S('starUser'+n).color='#111';
			$('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
		}
	}
} 

}

star.revert=function() { 
	var n=star.num, v=parseInt($('starCur'+n).title);
	$S('starCur'+n).width=Math.round(v*84/100)+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';
	
	document.onmousemove='';

}

star.num=0;

//função para avisar ao internauta que necessita estar logado ao tentar votar
function avisologin(idioma)
{

	var frase = '';
	
	if(idioma == 'en'){
		frase = "To assess, <a href='/login' class='thickbox login link_alerta'>login</a>";
		
	}else if(idioma == 'pt-br'){
		frase = "Para avaliar, faça seu <a href='/login' class='thickbox login link_alerta'>login</a>";
		
	}else if(idioma == 'es'){
		frase = "Para evaluar, <a href='/login' class='thickbox login link_alerta'>inicio de sesión</a>";
		
	}else if(idioma == 'it'){
		frase = "Per valutare, rendere il vostro <a href='/login' class='thickbox login link_alerta'>accesso</a>";
		
	}else if(idioma == 'fr'){
		frase = "D'évaluer, de faire de votre <a href='/login' class='thickbox link_alerta'>login </a>";
		
	}	
	var str = frase;
	document.getElementById('mensagem').innerHTML = str;
}

//funcao para votar
star.votar = function(e,o,video,end,idioma)
{
	var n=star.num, v=parseInt($('starUser'+n).innerHTML);

	n=o.id.substr(4);
	$('starCur'+n).title=v;
	var valor = (v/100);
	var texto = '';
	var t = '';

	if(idioma == 'en'){
		texto = 'Your vote has been successfully!';
		t = 'Can not be computed! Have you voted before!';
	}else if(idioma == 'pt-br'){
		texto = 'Seu voto foi efetuado com sucesso!';
		t = 'Não pode ser computado! Voce já votou antes!';
	}else if(idioma == 'es'){
		texto = 'Su voto ha sido correctamente!';
		t = 'No se puede calcular! ¿Ha votado antes!';
	}else if(idioma == 'it'){
		texto = 'Il tuo voto è stato correttamente!';
		t = 'Non può essere calcolata! Hai mai votato prima!';
	}else if(idioma == 'fr'){
		texto = 'Votre vote a été achevée avec succès!';
		t = 'Ne peuvent être calculés! Avez-vous voté avant!';
	}	
	
	jQuery.ajax({
		url: end + 'votacao/votar/',
		type: 'post',
		dataType: 'Json',
		data: {nota: valor,
		       video: video},
		success: function (data) {
			var resposta = data;
			
			// Caso tenha tido erro na validacao do login  
			if (resposta == 'true'){ 
				alert(texto);
			}
			else {	
				alert(t);
			}		
		}
	});


		
}

function teste(id,end)
{

	jQuery.ajax({
		url: '/webtv_teste/playlist/add/',
		type: 'post',
		dataType: 'Json',
		data: {
		       video: id,
		       endereco: end
			
		},
		success: function (data) {
			var resposta = data;
			
			// Caso tenha tido erro na validacao do login  
			if (resposta == 'true'){ 
				alert('video add');
			}
			else {	
				alert('video nao pode ser add');
			}		
		}
	});


	
}


 function sobe()
	{
		jQuery('#primeiros').show();
		jQuery('#ultimos').hide();
	}
function desce()
	{
		jQuery('#ultimos').show();
		jQuery('#primeiros').hide();
	}

