//### INI DETECT VIDEO ###
// DETECCIÒ (MOLT AMPLA, CAL RETALLAR? )
var ver=navigator.appVersion;  
var agt=navigator.userAgent;
var dom= (document.getElementById);
var mac= (agt.indexOf("Mac")>-1);
var win= ((agt.indexOf("Win")!=-1) || (agt.indexOf("32bit")!=-1));
var linux = (agt.indexOf("Linux")!=-1);
var unix = (agt.indexOf("x11")!=-1);
var OS = (mac)?"MAC":(win)?"WIN":(linux)?"LNX":(unix)?"UNX":"UNKNOWN";
var opera5= (agt.indexOf("Opera")>-1);
var ie5= (ver.indexOf("MSIE 5")>-1 && dom && !opera5); 
var ie6= (ver.indexOf("MSIE 6")>-1 && dom && !opera5);
var ie7= (ver.indexOf("MSIE 7")>-1 && dom && !opera5);
var ie6_xp_sp2= (ie6 && agt.indexOf("SV1") != -1); // IE 6 EN WIN XP SERVICE PACK 2
var ie= (win && (ie5 || ie6  || ie7));
var Safari= (mac && (agt.toLowerCase().indexOf('safari') != -1) && (agt.toLowerCase().indexOf('khtml') != -1));
var Firefox= (agt.indexOf("Firefox")!=-1);
var Mozilla= (agt.indexOf("Mozilla/5.0")>-1);
var ns1sup= (Mozilla && (agt.indexOf("Netscape/7.2")>-1 || agt.indexOf("Netscape/7.1")>-1 ));
var VideoModuleCompactVersion = (Firefox || mac); 

// CALL WRITE FUNCTION DEPENDING ON DETECTION
// WRITE VIDEO FUNCTION
function insertVideoDiferits(url,ptipus){
//var css = "video_player_directe";
var w = 250;
var h;
if (ptipus =="audio"){
	h= 45;
}
else{
	h= 225;
}
// VIDEO ACTIVE-X ELEM.
var videoStrDiferit;
if(mac){
videoStrDiferit = '<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+w+'" height="'+h+'" >'+
'<param name="src" value="img/video.wmv" >'+
'<embed  src="img/video.wmv" width="'+w+'" height="'+h+'" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"  />  '+
'</object><br />'+
'<div style="background-color:#FFFFFF;"><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=915D874D-D747-4180-A400-5F06B1B5E559&displaylang=en" title="Descarrega\'t el plugin de windows media per mac">Si no pot visualitzar el video, descarrega\'t el plugin de windows media per Mac</a></div>';
}else{
videoStrDiferit = '<object type="video/x-ms-wmv" data="'+url+'" width="'+w+'" height="'+h+'">'+
'  <param name="src" value="'+url+'" />'+
'  <param name="autostart" value="true" />'+
'  <param name="controller" value="true" />'+
'  <param name="AutoSize" value="0">'+
'</object>';
}
// WRITE MODULE
document.getElementById("videoBlock_diferits").innerHTML = videoStrDiferit;
}

//### FIN DETECT VIDEO ###

//### INI GALERIA PARTE COMUN ###
function ModGaleria(uid){ //Constructor galeria
this.id = uid;
}
ModGaleria.prototype.update = function(symbol){
if (symbol == "+") {
this.vo.actual++;
if(this.vo.actual >= this.vo.size){
this.vo.actual = 0;
}
} else {
this.vo.actual--;
if(this.vo.actual < 0){
this.vo.actual = (this.vo.size-1);
}
}
document.getElementById("navpag"+this.id).innerHTML = (this.vo.actual+1)+"/"+this.vo.titols.length;
document.getElementById("titol"+this.id).innerHTML = this.vo.titols[this.vo.actual];
document.getElementById("fotoGal"+this.id).src = this.vo.foto[this.vo.actual];
ajaxSite_DoHit();
}
//### FIN GALERIA PARTE COMUN ###
//### INI MULTI PARTE COMUN ###
function ModMulti(uid){ //Constructor módulo multi
this.id = uid;
}
ModMulti.prototype.update = function(symbol){
if (symbol == "+") {
this.vo.actual++;
if(this.vo.actual >= this.vo.size){
this.vo.actual = 0;
}
} else {
this.vo.actual--;
if(this.vo.actual < 0){
this.vo.actual = (this.vo.size-1);
}
}	
var titolLink = '<a href="/p3xl/3xlItem.jsp?seccio='+this.vo.seccio+'&idint='+this.vo.ids[this.vo.actual]+'&item='+this.vo.item+'">'+this.vo.titols[this.vo.actual]+'</a>';		
document.getElementById("titol"+this.id).innerHTML = titolLink;
document.getElementById("fotoMulti"+this.id).src = this.vo.foto[this.vo.actual];
ajaxSite_DoHit();
}
//### FIN GALERIA PARTE COMUN ###
//### INI VO ###
function VO(){ //Constructor VO
}
//### FIN VO ###
//### INI VOTEBAR ###
var tStars = 5;
function updateVistaVotos(value,time,uniqueId,tipoId,contentId){
var result;
var roundResult;
var openLink = '';
var closeLink = '';
var fullStar;
var halfStar;
var emptyStar;
var puntsSeleccionats = value;
punts = eval("punts"+uniqueId);
tVots = eval("tVots"+uniqueId);
if(value == undefined || value == 0){
value = 0;
}
if(time==2){
tVots += 1;
}
var i,j;
var counter = 1;
punts += value;
if(tVots == 0){
result = 0;
roundResult = 0;
}else{
var maxPunt = tVots*tStars;
result = (punts*tStars)/maxPunt;
roundResult = Math.floor((punts*tStars)/maxPunt);
}
var dif = Math.abs(result-roundResult);
var empty = tStars-roundResult;
if(dif > 0.5){
roundResult++;
empty--;
dif = 0;
}else if(dif <= 0.5 && dif != 0){
dif = 0.5;
}
var openLink = '<a href="javascript:updateVotos(';
var closeLink = ',2,\''+uniqueId+'\',\''+tipoId+'\',\''+contentId+'\');">';
if(time==1){
fullStar = '<img src="/img/ico_estel.gif" alt="" width="10" height="9" border="0" onmouseover="this.src=\'/img/ico_estel_on.gif\'" onmouseout="this.src=\'/img/ico_estel.gif\'" />';
halfStar = '<img src="/img/ico_estel_half.gif" alt="" width="10" height="9" border="0" onmouseover="this.src=\'/img/ico_estel_on.gif\'" onmouseout="this.src=\'/img/ico_estel_half.gif\'" />';
emptyStar = '<img src="/img/ico_estel_off.gif" alt="" width="10" height="9" border="0" onmouseover="this.src=\'/img/ico_estel_on.gif\'" onmouseout="this.src=\'/img/ico_estel_off.gif\'" />';
}
else{
fullStar = '<img src="/img/ico_estel.gif" alt="" width="10" height="9" border="0" />';
halfStar = '<img src="/img/ico_estel_half.gif" alt="" width="10" height="9" border="0" />';
emptyStar = '<img src="/img/ico_estel_off.gif" alt="" width="10" height="9" border="0" />';
}
var str = '<div class="ranking">';
if(time==1) str+='Vota\'m  ';
var endStr = '&nbsp;&nbsp;'+tVots+' vots</div>';//+punts+' punts,  '+result+'</div>';
// PINTO LAS ESTRELLAS FULL
for(i=0;i<roundResult;i++){
if(time==1) str+=(openLink+counter+closeLink);
str+=fullStar;
if(time==1) str+='</a>'
counter++;
}
// PINTO LAS ESTRELLAS HALF SI EXISTEN
if((dif >0 && roundResult<tStars) || (result > 0 && roundResult == 0)){
if(time==1) str+=(openLink+counter+closeLink);
str+=halfStar;
if(time==1) str+='</a>'			
counter++;
empty--;
}
// ACABO RELLENANDO LAS QUE FALTAN CON ESTRELLAS VACIAS
for(j=0;j<empty;j++){
if(time==1) str+=(openLink+counter+closeLink);
str+=emptyStar;
if(time==1) str+='</a>'			
counter++;
}
// CIERRO EL DIV
str+=endStr;
// PINTO
document.getElementById("stars"+uniqueId).innerHTML = str;
}
function startLoader(uniqueId){
var loader = '<div class="ranking_loader"><img src="/img/enviant.gif" alt="" width="21" height="9" />Enviant</div>';
document.getElementById("stars"+uniqueId).innerHTML = loader;
}
function updateVotos(value,time,uniqueId,tipoId,contentId){	
if(time==1){
updateVistaVotos(value,time,uniqueId,tipoId,contentId);
}	
if(time==2){ //Lanzamos la peticion a SU
puntsSeleccionats = value;
startLoader(uniqueId);
ajaxSite_DoHit();
if(tipoId=="DTY_PARTICIPACIO"){ //Votacions sobre participacions (TODO saber que llega en este param)
	var toLoad = 'loadXMLDoc("http://www.3xl.cat/su/Register?numPunt='+value+'&participationId='+contentId+'&tipoId=DTY_PARTICIPACIO&hiTarget=*.swf&hiAction=206&hiRegServiceId=CCRTVI_CONT&hiServiceId=3XL_REG&hiPortal=3xl&numVot=1&localeParticipation=ca",false,\''+uniqueId+'\');';
}else{ //Votacions sobre tipologies
	var toLoad = 'loadXMLDoc("http://www.3xl.cat/su/Register?num_punt='+value+'&contentId='+contentId+'&tipoId='+tipoId+'&hiTarget=*.swf&hiAction=220&hiRegServiceId=3XL_REG&hiServiceId=3XL_VOTE'+tipoId+contentId+'&hiPortal=3xl&num_vot=1&domainId=TXL&language=ca&hiGroupServiceId=3XL_VOTE",false,\''+uniqueId+'\');';
}
setTimeout(toLoad,1000);
}
}
//### FIN VOTEBAR ###
// FUNCIÓ SWAP STYLE
// Utilities
/*function changeStyle(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}*/
function swapTabs(sel,tot,uniqueId,hit) {
var id1, id2;
	for(var i=1;i<=tot;i++){
		var id1 = 'tab'+i+'_'+uniqueId;
		var id2 = 'tab_cont_'+i+'_'+uniqueId;
		document.getElementById(id1).className = '';
		document.getElementById(id2).className = 'tab_contingut_hidden';
			if(i == sel){
			document.getElementById(id1).className = 'selected';
			document.getElementById(id2).className = 'tab_contingut';
			}
	}
	if (hit != '0') {
		ajaxSite_DoHit();
	}
}

//Tool Tips correu 
function showTips(nm){
  var style=document.getElementById?
              document.getElementById(nm).style:(
                document.all?document.all(nm).style:(
                  document.layers?document.layers[nm]:null
                  )
              );
  if(style) style.visibility='inherit';
}
function hideTips(nm){
  var style=document.getElementById?
              document.getElementById(nm).style:(
                document.all?document.all(nm).style:(
                  document.layers?document.layers[nm]:null
                  )
              );
  if(style) style.visibility='hidden';
}
