/* ------ Página de todos los programas ------ */
jQuery(function(){
  jQuery("#all_data").click(function(){
    accordeon(0);
    jQuery("ul.subcat li a","#listacat").removeClass("active");
    jQuery(".aux_canal").removeClass("choosed");
    jQuery(".aux_canal").parents("li").removeClass("active");
    var url = jQuery("#url_1582").val() + "&param7=";
    eBDSection.reload(1582, url);
    return false;
  });

  jQuery(".aux_canal").click(function(){
    var idcat = jQuery(this).attr("id").split("_")[1];
    accordeon(idcat);
    jQuery("ul.subcat li a","#listacat").removeClass("active");
    jQuery(".aux_canal").parents("li").removeClass("active");
    jQuery(".aux_canal").removeClass("choosed");
    jQuery(this).parents("li").addClass("active");
    jQuery(this).addClass("choosed");
    var filtro = "AND (T1.IDCANAL = " + idcat + " OR T2.IDSUBCANAL = -1)";
    var url = jQuery("#url_1582").val() + "&param7=" + filtro;
    eBDSection.reload(1582, url);
    return false;
  });

  jQuery(".aux_sub").click(function(){
    jQuery(".aux_sub a").removeClass("active");
    jQuery(this).children("a").addClass("active");
    var idcat = jQuery(this).parents("ul").attr("id").split("_")[1];
    jQuery("li", "#listacat").removeClass("active");
    jQuery("a", "#listacat").removeClass("choosed");
    jQuery("#catclick_" + idcat,"#listacat").addClass("choosed").parents("li").addClass("active");
    var idsub = jQuery(this).attr("id").split('_')[1];
    var filtro = "AND (T1.IDCANAL = -1 OR T2.IDSUBCANAL = " + idsub + ")";
    var url = jQuery("#url_1582").val() + "&param7=" + filtro;
    eBDSection.reload(1582, url);
    return false;
  });

/*
  jQuery("a[id^=cat_]","ul#listacat").click(function(){
    var idcat = jQuery(this).attr("id").split("_")[1];
    accordeon(idcat);
    return false;
  });
*/
});


function accordeon(idcat){
	if(jQuery("#subcat_" + idcat + ":visible","#listacat").length == 0){
		jQuery("ul.subcat","#listacat").slideUp("fast");
		jQuery("li a","#listacat").find('img').attr('src','/imgfiles/Front_xal/img/more_bt.gif');
		jQuery("#subcat_" + idcat,"#listacat").slideDown("fast");
		jQuery("a#cat_" + idcat + " img","#listacat").attr('src','/imgfiles/Front_xal/img/less_bt.gif');
	}
}

function update(html){
//  jQuery("#prog_especifico").html(html);
  jQuery("#content_section_1579").html(html);
}

/* --- Desplegables de la barra de menu --- */
jQuery(function(){
	jQuery("li.first","#tematics").mouseenter(function(){
		var idelt = jQuery(this).attr("id");
		if(idelt == 'ver_municipis') var urltolook = "/front_xal/canales.listamunicipis";
		if(idelt == 'ver_locales') var urltolook = "/front_xal/canales.listalocales";
		if(idelt == 'ver_tematics') var urltolook = "/front_xal/canales.listatematics";
		if(jQuery("#lista_" + idelt).length == 0){
			jQuery.get(urltolook, function(json){
				jQuery("#tematics").after("<div id='lista_" + idelt + "' class='onelistaelems'><ul></ul></div>");
				var json = eval("(" + json + ")");
				var puthtml = '';
				jQuery.each(json, function(i,valor){
 					puthtml = puthtml + "<li><a href='" + valor["url"] + "' title='" + valor["descripcion"] + "'>" + valor["nombre"] + "</a></li>";
				})
				jQuery("#lista_" + idelt + " ul").html(puthtml);
				jQuery("#" + idelt).removeClass("sel").addClass("sel");
				jQuery("#lista_" + idelt).fadeIn("fast");
				eventdesple(idelt);
			},"json")
		}

	})

})

/* --- Control de coordenadas de los desplegables de la barra de menu --- */
function eventdesple(idelt){
	jQuery("#idelt").unbind();
	var points = new Array();
	var elem1 = jQuery("#" + idelt).offset();
	var elem2 = jQuery("#lista_" + idelt).offset();
	points["x1"]=elem1.left;
	points["y1"]=elem1.top;
	points["x2"]=elem1.left + jQuery("#" + idelt).outerWidth();
	points["y2"]=elem2.top;
	points["x3"] = elem2.left + jQuery("#lista_" + idelt).outerWidth();
	points["y3"]=points["y2"] + jQuery("#lista_" + idelt).outerHeight();	
	jQuery("#" + idelt).hover(function(e){
		jQuery("#lista_" + idelt).fadeIn("fast");
		jQuery("#" + idelt).removeClass("sel").addClass("sel");
	  }, function(e){
		if(e.pageX <= points["x1"] || e.pageY <= points["y1"] || (e.pageX > points["x2"] && e.pageY < points["y2"])){
			jQuery("#lista_" + idelt).fadeOut("fast"); 
			jQuery("#" + idelt).removeClass("sel");
	  }
	})
	jQuery("#lista_" + idelt).hover(function(e){
		jQuery("#lista_" + idelt).fadeIn("fast");
		jQuery("#" + idelt).removeClass("sel").addClass("sel");
	  }, function(e){
		if(e.pageX <= points["x1"] || e.pageX >= points["x3"] || e.pageY>= points["y3"] || (e.pageX >= points["x2"] && e.pageY<= points["y2"])){
			jQuery("#lista_" + idelt).fadeOut("fast");
			jQuery("#" + idelt).removeClass("sel");
		}
	  }
	)
}

function cerrarPopup(){
        jQuery("#capa").fadeOut("fast");
        jQuery("#popup").fadeOut("fast");
	jQuery(".imgLoader").parent("a").removeAttr("style"); 
	jQuery(".imgLoader").hide();
	jQuery("*").removeClass("loader");
}
var section = {
	clearContent: function(funcion){
		 jQuery('#tabs-content').empty();
		},
	show: function(url, callbackFunction){
		if (url != 0){
			var content = jQuery.get('/_ajax/Section.show' + url,callbackFunction);
			
			/*var i = eBDSection.calls.length;
			eBDSection.calls[i] = callbackFunction;*/
		}else{
			this.clearContent(callbackFunction);
		}
	}	
}

/* --- Si los programas aparecen arriba, puede ser que aparezca un scroll --- */
jQuery(function(){
	if(jQuery("#topsidebar #programas").length > 0 ){
		jQuery("div#needscroll","#programas").addClass("modscroll");
		if(jQuery("div#needscroll > ul").outerHeight() > jQuery("div#needscroll").height()){
			var flechup = "<a href='#up' class='up' id='scrup_needscroll'>up</a>";
			var flechdown = "<a href='#down' class='down' id='scrdown_needscroll'>down</a>";
			jQuery("div#needscroll","#programas").before(flechup).after(flechdown);
			imscrolling("#scrdown_needscroll", "#scrup_needscroll", "div#needscroll");
		}
	}

})
/* --- Aplicar el scroll usa la libreria scrollTo --- */
function imscrolling(iddown, idup, ideltscroll){
		
		jQuery(iddown).hover(function(){
			var cont_h = jQuery(ideltscroll + " > ul").height()
			var time = (cont_h-jQuery(ideltscroll).scrollTop()) * 10;
			jQuery(ideltscroll).animate({scrollTop:cont_h}, time);

		 },
			function(){jQuery(ideltscroll).stop();
		 });

		 jQuery(idup).hover(function(){
			var cont_h = jQuery(ideltscroll + " > ul").height()
			var time = jQuery(ideltscroll).scrollTop() * 10;
			jQuery(ideltscroll).animate({scrollTop:0}, time);

		 },
			function(){jQuery(ideltscroll).stop();
		 });

}

/* --- esconder la lista de canales despues de un rato --- */
function hidelistatematics() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(hidelistatematicsNow, 1500);
};

function hidelistatematicsNow(){
	jQuery("#listatematics, #listamunicipis").fadeOut("fast");
	jQuery("#tematics li.first").removeClass().addClass("first");
}


/* --- tabs mas vistos, votados y novedades --- */
jQuery(function(){
	jQuery("ul.tabs-nav li a").click(function(){
		var url = jQuery(this).attr("href");
		jQuery("ul.tabs-nav li").removeClass();
		jQuery(this).parents("li").addClass("active");
		eBDSection.show(url, callbackpest)
		return false;
	});
	pillalo();
})

function callbackpest(html){
	var contentSection = jQuery("#tabs-content div[id^=content_section]:eq(0)").attr("id");
        // var contentSection = jQuery("#tabs-content").attr("id"); no se porque se ha puesto esta linea en lugar de la de arriba, pero esta linea - 
	//  - hace que no se puede cambiar de pagina despues haber cambiado de pestana. Loic.
	jQuery("#" + contentSection).html(html);
	pillalo();
}

function pillalo(){
    /* --- Recupera los eventos de los enlaces de paginacion de las secciones tablas para que sigue funcionando la paginacion despues del cambio de pestana --- */
    jQuery("a.LISTPAG_pagnum, td.LISTPAG_rightpag a, td.LISTPAG_leftpag a").each(function(){
	//jQuery(this).unbind();
        var url = "http://" + document.domain + "/_ajax/Section.show";
        var actionclick = String(jQuery(this).attr("onclick")).split('"')[1];

	/* --- el atributo onclick no tiene el mismo valor en ie (como siempre) --- */
	if(actionclick == undefined) {var actionclick = String(jQuery(this).attr("onclick")).split("'")[1];};
	jQuery(this).attr("href","#html");

        jQuery(this).click(function(){
        	var papa = jQuery(this).parents("div[id^=content_section_]").attr("id");
		jQuery.get(url + actionclick, function(data){
	                var res = data.getElementsByTagName("body")[0].firstChild.nodeValue;
        	        jQuery("#" + papa).html(res);
                	pillalo();
            	})
		return false;
        })
	jQuery(this).removeAttr("onclick");       
    })

}

/* --- mi lista --- */
jQuery(function(){
   jQuery("a[class^=addmylis_],a[class^=addmyfav_]").live("click",function(){

	var tipo = jQuery(this).attr("class").split("_")[0];
	var id   = jQuery(this).attr("class").split("_")[1];
	//var idp   = jQuery(this).attr("class").split("_")[2]; 
	//var estila   = jQuery(this).attr("class").split("_")[3];
	//var estilb   = jQuery(this).attr("class").split("_")[4];

        //alert(tipo+','+id+','+idp+','+estila+'_'+estilb);

	//alert(tipo);

	var text_literal_0 = jQuery('#lit_iniciar_sessio').val(); 

	if(log_val=='0' || typeof log_val=='undefined'){
		muestra_popup(id);
		pideConfirmacion("Informatiu","Confirmació",
					 text_literal_0,
					 "login();cerrarPopup");
	}else{
		var ws = "play";

		if(tipo=='addmyfav'){ws = 'fav'}

		jQuery("#capa").css("display","block");
		//jQuery(this).html('<img src="/imgfiles/Front_xal/img/loader.gif" class="imgLoader"/>');
		//jQuery(this).css("background","none");

		jQuery(this).addClass("loader");

		var wsDir 	= "/publicat_comentari.add"+ws;
		var newClass 	= "menos";
		var oldClass	= "plusgris";

		if(tipo=='addmyfav'){newClass = "heart_orange"; oldClass = "heart_gray";}

		//alert(jQuery(this).hasClass("menos"));
		//alert(jQuery(this).hasClass("plusgris"));

		if(jQuery(this).hasClass("menos") || jQuery(this).hasClass("heart_orange")){
			wsDir 	 = "/publicat_comentari.remove"+ws;
			newClass = "plusgris";
			oldClass = "menos";
			if(tipo=='addmyfav'){newClass = "heart_gray"; oldClass = "heart_orange";}
		}

		id   = id.split(" ")[0];
		
		//alert(wsDir);

		//var text_literal_1 = jQuery('#lit_segur_vol_eliminar_video_llista').val();
		var text_literal_1 = jQuery('#lit_segur_vol_eliminar_subscripcio_programa').val();

		if(oldClass=='menos' && !jQuery(this).hasClass("S")){
			pideConfirmacion("Informatiu","Confirmació",
					 text_literal_1,
					 "confirmaQuitar("+ id +");cerrarPopup");
		}
		else if(jQuery(this).hasClass("heart_orange")){
			//alert('doyouwant esborrar?');
			doyourealywanttodothat(wsDir, id, newClass, oldClass);
		}
		else{
			jQuery.getJSON(wsDir,{idvideo:id},function(json){
				//alert('afegir a llista?');
				var continuar = true;

				var selectores = ".addmylis_"+ id + ", .addmylis_"+ id + "_side";
				if(tipo=='addmyfav'){selectores = ".addmyfav_"+ id + ", .addmyfav_"+ id + "_side";OkForFav();continuar=false;}

				//var selectores = ".addmylis_"+ id + ", .addmylis_"+ id + "_"+ idp + "_side";
				//if(tipo=='addmyfav'){selectores = ".addmyfav_"+ id + ", .addmyfav_"+ id + "_"+ idp + "_side";OkForFav();continuar=false;}

				//alert(selectores);

				if(json.val=='S'){

					//alert(json.idproyecto);

					//if(json.idproyecto!=0){
						jQuery("a[class^=addmylis_],a[class^=addmyfav_]").removeClass("loader");
						jQuery(selectores).removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);
					//}

					//alert('un');

					//if(tipo=='addmylis'){
						//var oldClass="menos";
						//var newClass="plusgris";
						//jQuery(".addmylis_"+ id).removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);
						//jQuery(".addmylis_"+ id + "_side").removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);

					//}

					//if(wsDir=='/publicat_comentari.addplay'){
						//alert('2');
						//OkForList();
					//}

					if(tipo=='addmyfav' && jQuery("#favoritos").parent("li").hasClass("active")){
						jQuery("#favoritos").click();
					}
				}
				else{
					if(json.popUp=='S'){
						continuar=false;
						var i;
						popCanales(json.canales, json.idprograma, json.warning, json.idproyecto);
					}
					else{

						var text_literal_0 = jQuery('#lit_accio_no_completada').val();

						jQuery(selectores).removeAttr("style");
						//popUp("Error","No s\'ha pogut completar l\'acció, intenti-ho més tard");
						popUp("Error",text_literal_0);
					}

					//KoForList();
					//continuar=false;
				}

				if(continuar){
					jQuery("#capa").css("display","none");
					jQuery(".imgLoader").remove();

					if(wsDir=='/publicat_comentari.addplay'){
						OkForList();						

					}
					else{
						if(wsDir=='/publicat_comentari.removeplay'){
							Ko2ForList();	
						}
					}
				}
			});
		}
	}
	return false;
   });


/* --- Quitar videos de milista --- */


	jQuery("a[id^=quitvid_]","#tabs-content").live("click", function(){

		var text_literal_0 = jQuery('#lit_segur_vol_eliminar_seleccionats').val();

		var idvidtoquit = jQuery(this).attr("id").split("_")[1]; 

		pideConfirmacion("Informatiu","Confirmació",
			 text_literal_0,
			 "delfrommylist_listado(\""+idvidtoquit+"\");cerrarPopup");
		return false;
	})


	jQuery("a[class^=sendmsg_]","#boxinfo").live("click",function(){
		var idvid = jQuery(this).attr("class").split("_")[1];
		var url = jQuery("#pestcomment a").attr("href");
		eBDSection.show(url, callbackpest);
		jQuery("ul.tabs-nav li").removeClass();
		jQuery("#pestcomment").addClass("active");
		jQuery.scrollTo("#footer",1000);
		return false;	
	})
});

/* --- Action de borrar de mi lista en los listados --- */
function delfrommylist_listado(idvidtoquit){
	jQuery.post("/publicat_comentari.removedefrommylist",{listids:idvidtoquit},function(data){
		if(data.result == 'ok'){
			jQuery("#mylistvid_" + idvidtoquit,"#tabs-content").fadeOut("slow", function(){jQuery("#mylistvid_" + idvidtoquit,"#tabs-content").remove();})
		}
	},"json")
}


/* --- Mostrar pop up de error --- */
function popUp(titulo,contenido){
        jQuery("#capa").css("display","block");
        jQuery("#popup").css("display","block");
        jQuery("#pop_titulo").html(titulo);
        jQuery("#pop_interior").html(contenido);
        jQuery("#pop_buttons").html("<input type='button' onclick='cerrarPopup()' class='boton_verde' id='button_ok' value='Acceptar'>");
	jQuery("#popup").css('top','315px;');
	return false;
}

//para activar las funciones del popUp de canales
jQuery(".cancel_canal").live("click",function(){
	var html_pop = jQuery("#htmlPop").val();
	jQuery(".imgLoader").parents("a").removeAttr("style");
	jQuery(".imgLoader").remove();
	cerrarPopup();
	jQuery("#popup").removeAttr("style");
	jQuery("#popup").html(html_pop);
	jQuery("a[class^=addmylis_],a[class^=addmyfav_]").removeClass("loader");

});
jQuery("#button_canal").live("click",function(){
	var canal = $("#seleccion_canales :radio:checked");
	var id = jQuery("#idPrograma").val();
	var idvideo = jQuery("#idVideo").val();
	jQuery("a[class^=addmylis_],a[class^=addmyfav_]").removeClass("loader");
	if(canal.length>0 && idvideo!=''){
		var idcanal = canal.val();
		jQuery.getJSON("/publicat_comentari.addplay",{idvideo:idvideo,idcanal:idcanal},function(json){
			// se agrega el id de canal para saber cual relación eliminar
			jQuery(".addmylis_"+ idvideo).removeAttr("style");
			jQuery(".addmylis_"+ idvideo + "_side").removeAttr("style");
			if(json.cambia=='S'){
				jQuery(".addmylis_"+ idvideo).removeClass("plusgris").addClass("menos");
				jQuery(".addmylis_"+ idvideo + "_side").removeClass("plusgris").addClass("menos");
			}
			jQuery(".cancel_canal").click();			
			OkForList();
		});
	}
});

function popCanales(json,idprograma,warning,idproyecto){
	//para regresar su contenido original
	var htmlPop = jQuery("#popup").html();
	/*jQuery("#pop_titulo", "#popup").text("Canals");
	jQuery("#popup").css("width","500px");
	jQuery("#pop_border").css("width","498px");
	jQuery("#pop_contenido").css("height","auto");
	var offset = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	offset += 200;
	var left=(jQuery("body").width() - 500)/2;
	jQuery("#popup").css({left: left, top: offset+"px"})
	*/
	jQuery("#pop_cerrar").hide();

	var canales = '<div id="seleccion_canales"><h4>'+ warning +'</h4>';
	var counter = 0;
	for(i in json){
		var value = i.split("-");
		var counter = counter + 1;
		if (value[0]==idproyecto) 	{	canales += '<input type="radio" id="selCanal_' + value[0] + '" name="selCanal" value="' + value[0] + '" checked="checked"/><label for="selCanal_' + value[0] + '">' + json[i] + '</label> <br/>';	}
		else				{	canales += '<input type="radio" id="selCanal_' + value[0] + '" name="selCanal" value="' + value[0] + '" /><label for="selCanal_' + value[0] + '">' + json[i] + '</label> <br/>';	}
		
	}
	canales += '</div>'
		+  "<textarea style='display:none' id='htmlPop'>" + htmlPop + "></textarea>"
		//+  "<input type='hidden' id='idPrograma' value='"+ idprograma +"'>"
		//+  "<input type='hidden' id='idVideo' value='"+ idvideo +"'>" 
		+  "<input type='hidden' id='idVideo' value='"+ idprograma +"'>" 
		+  '<div id="pop_buttons"><input type="button" class="boton_verde" id="button_canal" value="Acceptar">  '
		+  '<input type="button" class="boton_naranja cancel_canal" value="Cancel·lar" name="aceptar" id="delete_ko"/></div>';
	jQuery("#pop_contenido").html(canales);
	// si solo hay un canal, no hay que proponer eleccion(se valida el form por js), con mas de un programa, sale el formulario.
	if(counter == 1){
		jQuery("input[type=radio]:eq(0)","#popup #seleccion_canales").attr("checked","checked");
		jQuery("#button_canal","#popup #pop_buttons").click();
		OkForList();
	}
	else{
		muestra_popup();
	}
}

/* --- Lista de categorias -- Plegar, desplegar --- */
jQuery(function(){

	/* --- Abrir ventana para ver el live --- */
	jQuery("#verlive").click(function(){
		var popw = 640;
		var poph = 360;
		var vamos = "http://" + document.domain + "/" + jQuery(this).attr("href");
		var ww = jQuery(window).width();
		var wh = jQuery(window).height();
		var posx = Math.round((ww - popw)/2);
		var posy = Math.round((wh - poph)/2);
		livewindow = window.open(vamos,"","width=" + popw + ",height=" + poph + ", left=" + posx + ",top=" + posy + ",channelmode=no,directories=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");
		return false;
	})

});

/* --- Borrado multiple de favoritos y playlist --- */
jQuery(function(){
	jQuery("#del_selected").click(function(){
		var selectedElems  = "";
		jQuery(".check_elem:checkbox:checked").each(function() {
		    selectedElems += $(this).val()+",";
		});
		var len = selectedElems.length;
		if(len>0){
			selectedElems = selectedElems.substr(0,len-1);
		}

		var text_literal_0 = jQuery('#lit_segur_vol_eliminar_seleccionats').val();

		var tipo = jQuery("#cont_lista").attr("class");

		//alert("selectedElems: "+selectedElems); aqui se llama al ws
		//borraRelacionesVideos(tipo,selectedElems);
		pideConfirmacion("Informatiu","Confirmació",
			 text_literal_0,
			 "borraRelacionesVideos(\""+tipo+"\",\""+selectedElems+"\");cerrarPopup");
	});
});

function borraRelacionesVideos(tipo,id){
	// esta funcion elimina videos de favoritos y de playlist
	jQuery("#capa").css("display","block");
	jQuery("#del_selected").after('<img src="/imgfiles/Front_xal/img/loader.gif" class="imgLoader"/>');

	jQuery.getJSON("/publicat_comentari.remove"+tipo,{idvideo:id},function(json){
			jQuery("#capa").css("display","none");
			jQuery(".imgLoader").remove();

			if(json.val=='S'){
				jQuery(".check_elem:checkbox:checked").parent("td").parent("tr").fadeOut("slow");
			}else{

				var text_literal_0 = jQuery('#lit_accio_no_completada').val();
				jQuery(selectores).removeAttr("style");
				//popUp("Error","No s\'ha pogut completar l\'acció, intenti-ho més tard");
				popUp("Error",text_literal_0);
			}
		});

}

login = function(){
	window.location='http://'+location.host+'/login/';
}

//funciones copiadas de capas_jquery, porque el js completo interfiere con el player

function ColocaTextos(tipo,titulo,texto)
{
	jQuery("#pop_titulo").html(titulo);
	jQuery("#pop_interior").html(texto);
	switch (tipo){
	case "Alerta":
		jQuery("#pop_imagen").html("<img src='/imgfiles/back/dynamic/imgs/question.gif' style='margin-left:20px;'>");
		break;
	case "Informativo":
		jQuery("#pop_imagen").html("<img src='/imgfiles/back/dynamic/imgs/warning.gif'>");
		break;
	}
}
/*
function muestra_popup(){
	jQuery("#capa").height(jQuery(document).height() + 500);
	jQuery("#capa").width(jQuery("body").width());
	var offset = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	offset += 200;
	var left=(jQuery("body").width() - 550)/2;
	jQuery("#popup").css({left: left, top: offset+"px"})
	jQuery("#pop_buttons").show();
	jQuery("#capa").fadeIn("slow");
	jQuery("#popup").fadeIn("slow");	
}
*/

function muestra_popup(){
	var dw = jQuery(document).width();
	var dh = jQuery(document).height();
	var wh = jQuery(window).height();
	var popw = jQuery("#popup").outerWidth();
	var poph = jQuery("#popup").outerHeight();
	var scrolltop = jQuery(document).scrollTop();
	var pospopx = (dw - popw) / 2;
	var pospopy = (wh - poph) / 2;
	jQuery("#popup").css("position","fixed");
	/* caso explorer < 7 */
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7){
		var pospopy = (wh - poph) / 2 + scrolltop;
		jQuery("#popup").css("position","absolute");
	}
	jQuery("#capa").css({"width":dw, "height":dh,"opacity":"0.6"});
        //jQuery("#capa").css("display","block");
        jQuery("#popup").css({"left":pospopx, "top":pospopy});
	jQuery("#pop_buttons").show();
	jQuery("#capa").fadeIn("slow");
	jQuery("#popup").fadeIn("slow");	

}

function pideConfirmacion(tipo,titulo,texto,callback) {
	ColocaTextos(tipo,titulo,texto);
	jQuery("#button_ok").hide();
	jQuery("#button_ko").hide();
	jQuery("#delete_ok").remove();
	jQuery("#delete_ko").remove();
	jQuery("#dok").remove();
	jQuery("#dcan").remove();
	jQuery("#dcl").remove();
	jQuery("#pop_buttons #button_delfav, #pop_buttons #button_closepop","#popup").remove();
	//var texto_aceptar = jQuery("#button_ok").val();
	//alert (texto_aceptar);
	var texto_aceptar = 'Acceptar'
	var texto_cancelar = jQuery("#button_ko").val();
	//alert(texto_cancelar);
	jQuery("#pop_buttons").prepend("<input type='button' style='' id='delete_ok' name='aceptar' onclick='"+callback+"();' value='"+texto_aceptar+"' class='boton_verde'/>&nbsp;&nbsp;&nbsp;");
	jQuery("#pop_buttons").append("<input type='button' id='delete_ko' name='aceptar' onclick='cerrarPopup();' value='"+texto_cancelar+"' class='boton_naranja'/></div><div style='clear:both;' id='dcl'>");
	muestra_popup();
}

function confirmaQuitar(id){
	jQuery(".addmylis_"+id).addClass("S");
	jQuery(".addmylis_"+id+":first").click();
}

function confirmaQuitarVideo(id){
	//alert(id);
	deleteVideoFromPlaylist(id);
	//jQuery(".addmylis_"+id).addClass("S");
	//jQuery(".addmylis_"+id+":first").click();
}

function doyourealywanttodothat(wsDir, id, newClass, oldClass){

	var text_literal_0 = jQuery('#lit_eliminar_favorit').val(); 
	var text_literal_1 = jQuery('#lit_segur_vol_eliminar_video_favorits').val();

	jQuery("#pop_buttons input","#popup").hide();
	jQuery("#pop_buttons #button_delfav, #pop_buttons #button_closepop","#popup").remove();

	muestra_popup();

	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);

	var boutons = '<input type="button" value="Acceptar" id="button_delfav" class="boton_verde"/>';
	var boutons = boutons + '&nbsp;&nbsp;&nbsp;<input type="button" value="Cancel·lar" id="button_closepop" class="boton_naranja"/>';

	jQuery("#pop_buttons","#popup").prepend(boutons);
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
	jQuery("#button_delfav","#popup").unbind().click(function(){
		jQuery.getJSON(wsDir,{idvideo:id},function(json){
		var urlfav = jQuery("a#favoritos").attr("href");
		eBDSection.show(urlfav, callbackpest);
		jQuery("ul.tabs-nav li").removeClass();
		jQuery("a#favoritos").parents("li").addClass("active");
		cerrarPopup();
		jQuery("a[class^=addmyfav_" + id + "_]","#boxinfo").removeClass("heart_orange").addClass("heart_gray");
		})
	});
	return false;
}
function OkForFav(){

	var text_literal_0 = jQuery('#lit_favorits').val();
	var text_literal_1 = jQuery('#lit_video_afegit_favorits').val();

	muestra_popup();jQuery("#capa").show();
	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);
	jQuery("#pop_buttons","#popup").empty();
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
}

function OkForList(){

	//var text_literal_0 = jQuery('#lit_meva_llista').val();
	var text_literal_0 = jQuery('#lit_subscripcio').val();
	//var text_literal_1 = jQuery('#lit_video_afegit_llista').val();
	var text_literal_1 = jQuery('#lit_programa_afegit_subscripcio').val();

	muestra_popup();jQuery("#capa").show();
	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);
	jQuery("#pop_buttons","#popup").empty();
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
	//alert('ee');
	//var oldClass="plusgris";
	//var newClass="menos";
	//jQuery('.#addmylis_'+id).removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);
}

function KoForList(){

	//var text_literal_0 = jQuery('#lit_meva_llista').val();
	var text_literal_0 = jQuery('#lit_subscripcio').val();
	var text_literal_1 = jQuery('#lit_video_ja_en_llista').val();

	muestra_popup();jQuery("#capa").show();
	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);
	jQuery("#pop_buttons","#popup").empty();
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
}



function Ko2ForList(){

	//var text_literal_0 = jQuery('#lit_meva_llista').val();
	var text_literal_0 = jQuery('#lit_subscripcio').val();
	//var text_literal_1 = jQuery('#lit_video_eliminat_llista').val();
	var text_literal_1 = jQuery('#lit_programa_eliminat_subscripcio').val();

	muestra_popup();jQuery("#capa").show();
	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);
	jQuery("#pop_buttons","#popup").empty();
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
}

function OkDeletedList(id){

	//var text_literal_0 = jQuery('#lit_meva_llista').val();
	var text_literal_0 = jQuery('#lit_subscripcio').val();
	//var text_literal_1 = jQuery('#lit_video_eliminat_llista').val();
	var text_literal_1 = jQuery('#lit_programa_eliminat_subscripcio').val();

	muestra_popup();jQuery("#capa").show();
	jQuery("#pop_titulo","#popup").empty().text(text_literal_0);
	jQuery("#pop_interior","#popup").empty().text(text_literal_1);
	jQuery("#pop_buttons","#popup").empty();
	jQuery("#button_closepop","#popup").unbind().click(function(){
		cerrarPopup();
	});
	//alert('deleted video from playlist');
	var oldClass="menos";
	var newClass="plusgris";

	//jQuery(".addmylis_"+ id).removeAttr("style");
	//jQuery(".addmylis_"+ id + "_side").removeAttr("style");

	//jQuery(".addmylis_"+ id).removeClass(olClass).addClass(newClass);
	jQuery(".addmylis_"+ id).removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);
	jQuery(".addmylis_"+ id + "_side").removeClass(oldClass).removeClass("S").removeAttr("style").addClass(newClass);
}


function deleteVideoFromPlaylist(id){

	// esta funcion elimina videos de playlist (mi lista)
	//jQuery("#capa").css("display","block");
	//jQuery("#del_selected").after('<img src="/imgfiles/Front_xal/img/loader.gif" class="imgLoader"/>');

	var text_literal_0 = jQuery('#lit_accio_no_completada').val();

	jQuery.getJSON("/publicat_comentari.removeVideoFromPlaylist",{idvideo:id},function(json){
		jQuery("#capa").css("display","none");
		jQuery(".imgLoader").remove();

		if(json.val=='S'){			
			//jQuery(".check_elem:checkbox:checked").parent("td").parent("tr").fadeOut("slow");
			//canviar estil + ! ! ! ! !	
			//mostrar capa informant ke sha eliminat 			
			OkDeletedList(id);
		}else{
			jQuery(selectores).removeAttr("style");
			//popUp("Error","No s\'ha pogut completar l\'acció, intenti-ho més tard");
			popUp("Error",text_literal_0);
		}
	});
}
