// JavaScript Document

// DETECTEM SI LA PLANA TÉ LA LIB DE JQUERY
var jQueryIsInstalled = false;
if(typeof jQuery != 'function'){ 
// jquery not installed
jQueryIsInstalled = false;
}else{
// jquery is installed
jQueryIsInstalled = true;
}




function swapTabs_old(sel,tot) {

var id1, id2;
for(var i=1;i<=tot;i++){
	var id1 = 'tab'+i;
	var id2 = 'tab_cont_'+i;
	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';
		}
}
//ajaxSite_DoHit();

}

// FUNCIÓ SWAP STYLE
// Utilities
/*function changeStyle(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}*/

//function swapTabs(sel,tot,uniqueId) {
function swapTabs(sel,tot,uniqueId, categoria, accio, label) {

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';
		}
}
	// HIT OJD
	if(categoria != null && categoria != undefined){
		if(label != null && label != undefined){	ajaxSite_DoHit(categoria,accio,label);}
		else{ajaxSite_DoHit(categoria,accio,'');}
	}
	else{ajaxSite_DoHit();}
}



function swapId(count,idPre,id,className) {
for(var i=1;i<=count;i++){
	var idNow = idPre+i;
	document.getElementById(idNow).className = 'nodisp';		
		if(i == id){
		document.getElementById(idNow).className = className;
		}
}

}



function swapCss(id,className) {
document.getElementById(id).className = className;
}


var tempSize = 100;
var minFontSize = 80;
var maxFontSize = 160;

function swapFontSize(id,symbol) {
if(symbol == "++" && tempSize < maxFontSize){
	tempSize += 20;
	document.getElementById(id).style.fontSize = tempSize+"%";
}else if(symbol == "--" && tempSize > minFontSize){
	tempSize -= 20;
	document.getElementById(id).style.fontSize = tempSize+"%";
	}
	//alert(tempSize);
}


function swapIdCss(count,idPre,id,className) {
for(var i=1;i<=count;i++){
	var idNow = idPre+i;
	document.getElementById(idNow).className = 'className';		
}

}


function mostraDirecteMesInfo(toggle) {
	if(toggle){
		document.getElementById("directedesc").className = "fullinfo";
		if (document.getElementById("nextdesc")) {
			document.getElementById("nextdesc").style.display = "none";
		}
		document.getElementById("directedesc_minisinopsi").style.display = "none";		
	}else{
		document.getElementById("directedesc").className = "";
		if (document.getElementById("nextdesc")) {
			document.getElementById("nextdesc").style.display = "block";
		}
		document.getElementById("directedesc_minisinopsi").style.display = "block";
		}
}



function selectVideoDesc(count,idPre,id) {
for(var i=1;i<=count;i++){
	var idNow = idPre+i;
	document.getElementById(idNow).className = '';
		if(i == id){
			document.getElementById(idNow).className = 'selected_video';
		}
}

// HIT OJD
ajaxSite_DoHit();

}



function showVideoDesc(id) {	
document.getElementById(id).className = 'show_video';

}

function hideVideoDesc(id) {
if(document.getElementById(id).className != 'selected_video'){
	document.getElementById(id).className = '';
}

}


function swapMenu(count,className,id) {
for(var i=1;i<=count;i++){
	var idNow = className+i;
	var liIdNow = className+'_li_'+i;
	document.getElementById(idNow).className = 'submenu_off';
	document.getElementById(liIdNow).className = '';
		if(i == id){
		document.getElementById(idNow).className = className;
		document.getElementById(liIdNow).className = 'actiu';
		}
}

//	ajaxSite_DoHit();

}

function mostraLogin(){
document.getElementById('login').className = 'login';
document.getElementById('loginlink').className = 'actiu';
document.getElementById('preloginlink').className = 'noborder';

}

function amagaLogin(){
document.getElementById('login').className = 'hide';
document.getElementById('loginlink').className = '';
document.getElementById('preloginlink').className = '';

}


function submitform(formname) {
var formName=formname;
document.formname.submit();

}

function insertSimpleFlash(url,w,h) {
var str='';
str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ w +'" height="'+ h +'">';
str+='<param name="movie" value="'+url+'" />';
str+='<param name="quality" value="high" />';
str+='<param name="wmode" value="opaque" />';
str+='<param name="menu" value="false" />';
str+='<param value="exactfit" name="scale" />';
str+='<embed src="'+url+'" quality="high" wmode="opaque" scale="exactfit" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" width="'+ w +'" height="'+ h +'"></embed>';
str+='</object>';
document.write(str);
}

function insertSimpleFlashById(url,w,h,id) {
var str='';
str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ w +'" height="'+ h +'"  name="'+id+'"  id="'+id+'">';
str+='<param name="movie" value="'+url+'" />';
str+='<param name="quality" value="high" />';
str+='<param name="wmode" value="opaque" />';
str+='<param name="menu" value="false" />';
str+='<param value="exactfit" name="scale" />';
str+='<embed src="'+url+'" quality="high" wmode="opaque" scale="exactfit" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" swLiveConnect="true" width="'+ w +'" height="'+ h +'" name="'+id+'"></embed>';
str+='</object>';
document.write(str);
}

//  FUNCIONS GESTIO AUDIO GALERIA
function insertAudio(url,w,h) {
var str='';
str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ w +'" height="'+ h +'"  id="audioPlayer">';
str+='<param name="movie" value="'+url+'" />';
str+='<param name="quality" value="high" />';
str+='<param name="wmode" value="opaque" />';
str+='<param name="menu" value="false" />';
str+='<param value="exactfit" name="scale" />';
str+='<embed src="'+url+'" quality="high" wmode="opaque" scale="exactfit" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" width="'+ w +'" height="'+ h +'" name="audioPlayer"></embed>';
str+='</object>';
document.write(str);
}

var playInterval;
var galInterval;
var isPlaying = false;

function getFlashMovieObject(movieName){
  if (window.document[movieName])   {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)  {
    if (document.embeds && document.embeds[movieName]){
      alert("MOZILLA");
	  return document.embeds[movieName]; 
	}
  }  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
 
// FUNCION STOP AUDIO
function flStopAudio() {
getFlashMovieObject("audioPlayer").flStopAudio();
}

// FUNCION PLAY AUDIO
function flReproduirAudio() {
getFlashMovieObject("audioPlayer").flReproduirAudio();
clearInterval(playInterval);
}




function autoplayGaleria(forceAudioPlay){	
	galInterval = setInterval(iefixAutoplay,3500);
	//flReproduirAudio();
	if(forceAudioPlay){
		playInterval = setInterval(flReproduirAudio,500);
	}
}

function iefixAutoplay(){
	updateGaleria(">>",true);
}

function stopAutoplayGaleria(){
	clearInterval(galInterval);
}


function galeriaInicia(gal){
//show audio, hide play, show pause
isPlaying = true;
pre=gal+'_';
audio=pre+'audio';
para=pre+'para';
inicia=pre+'inicia';
document.getElementById(audio).className='audio';
document.getElementById(inicia).className='nodisp';
document.getElementById(para).className='';
document.getElementById('songName').className = 'audio_info';
autoplayGaleria(true);
//and probably some more start swf, start slideshow...
}

function galeriaPara(gal){
//hide audio, show play, hide pause
isPlaying = false;
pre=gal+'_';
audio=pre+'audio';
para=pre+'para';
inicia=pre+'inicia';
flStopAudio();
document.getElementById(audio).className='nodisp';
document.getElementById(inicia).className='';
document.getElementById(para).className='nodisp';
document.getElementById('songName').className = 'nodisp';
stopAutoplayGaleria();
}

function updateGaleria(symbol,auto){
auto = (auto == undefined)?false:auto;
if(isPlaying && !auto){stopAutoplayGaleria(); autoplayGaleria();}
if (symbol == ">>") {
	ind++;
	if(ind >= tot){
		ind = 0;
	}
} else {
	ind--;
	if(ind < 0){
		ind = (tot-1);
	}
}
//
document.getElementById("counter").innerHTML = (ind+1)+"/"+tot;
document.getElementById("autor").innerHTML = dataArray.autor[ind];
document.getElementById("titol").innerHTML = dataArray.titol[ind];
document.getElementById("texto").innerHTML = dataArray.texto[ind];
document.getElementById("foto").src = dataArray.foto[ind];
document.getElementById("foto").alt = dataArray.titol[ind];

// HIT OJD
ajaxSite_DoHit();
}

// FUNCTION MODULO MULTI CONTENT

function updateMulti(symbol){	
if (symbol == ">>") {
	ind++;
	if(ind >= tot){
		ind = 0;
	}
} else {
	ind--;
	if(ind < 0){
		ind = (tot-1);
	}
}
// PINTAMOS LOS NUEVOS DATOS
document.getElementById("counter").innerHTML = (ind+1)+"/"+tot;
document.getElementById("atitol").innerHTML = dataArray.atitol[ind];
document.getElementById("titol").innerHTML = dataArray.titol[ind];
document.getElementById("foto").src = dataArray.foto[ind];
document.getElementById("fecha").innerHTML = dataArray.fecha[ind];
document.getElementById("url").src = dataArray.url[ind];
// HIT OJD
ajaxSite_DoHit();
}


// FUNCTION MODUL MULTI CONTENT
function updateMultiExclusives(symbolExclusives,avoidHit){ 
if (symbolExclusives == "seg") {
 indExclusives++;
 if(indExclusives >= totExclusives){
  indExclusives = 0;
 }
} else {
 indExclusives--;
 if(indExclusives < 0){
  indExclusives = (totExclusives-1);
 }
}
// DADES
document.getElementById("counterExclusives").innerHTML = (indExclusives+1)+"/"+totExclusives;
document.getElementById("titolExclusives").innerHTML = dataArrayExclusives.atitolExclusives[indExclusives];
document.getElementById("titolExclusives").href = dataArrayExclusives.urlExclusives[indExclusives];
document.getElementById("llocExclusives").innerHTML = dataArrayExclusives.llocExclusives[indExclusives];
document.getElementById("fotoExclusives").src = dataArrayExclusives.fotoExclusives[indExclusives];
document.getElementById("fotoLinkExclusives").href = dataArrayExclusives.urlExclusives[indExclusives];
document.getElementById("fotoLinkExclusives").title = dataArrayExclusives.titolExclusives[indExclusives];
document.getElementById("titolExclusives").title = dataArrayExclusives.atitolExclusives[indExclusives];
document.getElementById("fotoExclusives").alt = dataArrayExclusives.atitolExclusives[indExclusives];
// HIT OJD
	if(avoidHit){
		//
	}else{
		ajaxSite_DoHit();
		}
}
// FI FUNCIÓ MÒDUL EXCLUSIVES //


// FUNCIONS PER GESTIONAR MILLOR EL OBJECTE SVP. HEM DE PODER-HO PARAMETRITZAR ON-THE-FLY
//  NOTE: el index comença amb el numero 1.
function insertHomeSVPObject(placeHolderId,dataObj,index){
			
			index = index-1;
			
			var ConfigData = new Object()
				ConfigData.VIDEO_ID =		dataObj.videoID[index];                                
				ConfigData.POSTER_URL =	dataObj.posterURL[index];				
				ConfigData.WIDTH =	320;
				ConfigData.HEIGHT =		240;
				ConfigData.USE_LINK_TOCONTEXT = "true";

				
			
			var FlashParams = new Object()
				
				FlashParams.bgcolor = 					"#1B597A";
				FlashParams.width  =					320;
				FlashParams.height =					277;
				FlashParams.quality =					"high";
				FlashParams.swLiveConnect =				"true";
				FlashParams.menu =						"true";
				FlashParams.scale =						"noscale";
				FlashParams.salign =					"tl";
				FlashParams.align =						"l";
				FlashParams.allowFullScreen =			"true";

								
			insertaSVP( placeHolderId, ConfigData , FlashParams );
			
			// ACTUALITZEM LES DADES DEL ITEM CORRESPONDENT
			
			document.getElementById("currentAtitol").innerHTML = dataObj.atitol[index];
			//document.getElementById("currentTitol").innerHTML = "<a href=\"/videos/"+dataObj.videoID[index]+"\">"+dataObj.titol[index]+"</a>";
			document.getElementById("currentTitol").innerHTML = "<a href=\"/videos/"+dataObj.videoID[index]+"/"+dataObj.titolURL[index]+"\">"+dataObj.titol[index]+"</a>";
			//document.getElementById("currentTitol").innerHTML = dataObj.titol[index];
			document.getElementById("currentDesc").innerHTML = dataObj.desc[index];		

		}

function manageFormContent(form,focused,val){	
	if(focused){
		if(form.value == val){
			form.value = "";
		}
	}else{
		if(form.value == ""){
			form.value = val;
		}
	}
}

function popup(url,wname,width,height){
openIt=window.open(url,wname,'scrollbars=yes,resizable=yes,width='+width+',height='+height);
}


function buidaEnviaForm(){
	document.getElementById("correu_amic_nom").value = "";
	document.getElementById("correu_amic").value = "";	
	document.getElementById("correu_de_nom").value = "";	
	document.getElementById("correu_de").value = "";
	document.getElementById("missatge").value = "";	
}

// FUNCIONS GESTIO VISIBILITAT DEL SUBMENU FITXES DE PROGRAMA

function showMenu(id,cl){
document.getElementById(id).className = cl;
}

function hideMenu(id,cl){
document.getElementById(id).className = cl;
}

// CONSTRUCTOR SUBMENUS FITXES DE PROGRAMA
function insertSubMenu(data,selected){
var style1, style2;
var maxSubMenuLengthPerColumn = 7;
var maxSubMenuLength = maxSubMenuLengthPerColumn*2;
var str = '<div class="din_menu">';
if(selected == 0){
str += '<h3 class="titol">'+data[0][0]+'</h3><ul>';
}else{
str += '<h3 class="titol"><a href="'+data[0][1]+'">'+data[0][0]+'</a></h3><ul>';
}
for(var i=1;i<data.length;i++){
	if(i == data.length-1  && i != selected){
		style1 = " last";
		style2 = style1;
	}else if(i == data.length-1 && i == selected){
		style1 = " last selected";
		style2 = " last selectedHasMenu";
	}else if(i != data.length-1 && i == selected){
		style1 = " selected";
		style2 = " selectedHasMenu";
	}else{
		style1 = "";
		style2 = style1;
	}
	// CREATE SUBMENU IF EXIST	
	if(data[i][1] == "x" && data[i][2].length <= maxSubMenuLengthPerColumn){
		var idSubMenu = 'sub'+Math.ceil(Math.random()*9999);
		str += '<li class="din_hasMenu'+style2+'" onmouseover="showMenu(\''+idSubMenu+'\',\'din_subShow\');" onmouseout="hideMenu(\''+idSubMenu+'\',\'din_subHidden\');"><a href="#">'+data[i][0]+'</a>';
		str += '<div class="din_subHidden" id="'+idSubMenu+'"><ul class="din_submenu">';
		for(var j=0;j<data[i][2].length;j++){
			str += '<li><a href="'+data[i][2][j][1]+'">'+data[i][2][j][0]+'</a></li>';
		}
		str += '</ul></div>';
	}else if(data[i][1] == "x" && data[i][2].length > maxSubMenuLengthPerColumn){
		var idSubMenu = 'sub'+Math.ceil(Math.random()*9999);
		str += '<li class="din_hasMenu'+style2+'" onmouseover="showMenu(\''+idSubMenu+'\',\'din_subShow large\');" onmouseout="hideMenu(\''+idSubMenu+'\',\'din_subHidden\');"><a href="#">'+data[i][0]+'</a>';
		str += '<div class="din_subHidden large" id="'+idSubMenu+'"><ul class="din_submenu left borderRight">';
		
		for(var j=0;j<data[i][2].length;j++){
			if(j < maxSubMenuLengthPerColumn){
				str += '<li><a href="'+data[i][2][j][1]+'">'+data[i][2][j][0]+'</a></li>';
			}else if(j == maxSubMenuLengthPerColumn){
				str += '</ul><ul class="din_submenu left"><li><a href="'+data[i][2][j][1]+'">'+data[i][2][j][0]+'</a></li>';
			}else if(j >= maxSubMenuLength){
				// DO NOTHING
				str += '</ul></div>';
			}else{
				str += '<li><a href="'+data[i][2][j][1]+'">'+data[i][2][j][0]+'</a></li>';
			}
		}
	}else{
		str += '<li class="'+style1+'"><a href="'+data[i][1]+'">'+data[i][0]+'</a>';		
	}
	str += '</li>';
}
str += '</ul></div>';
document.write(str);
}


//***************************************************************
//### INI VOTEBAR ### //TODO: extend to tv3.cat?
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+='<span>Vota\'m</span>';
	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("/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("/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 ###



/*
 * jQuery ToolTip
 * @name     ToolTipDemo
 * @example  $("a,input").ToolTipDemo('cssRule');
 *
 */

if(jQueryIsInstalled){
	
	$.fn.ToolTip = function(cssClass)
	{
		this.mouseover(
			function(e)
			{
				if((!this.title && !this.alt) && !this.tooltipset) return;
				// get mouse coordinates
				// based on code from http://www.quirksmode.org/js/events_properties.html
				var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
				var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
				mouseX += 18;
				mouseY -= 25;
				cssClass = (cssClass == undefined)?"qtip":cssClass;
				// if there is no div containing the tooltip
				if(!this.tooltipdiv)
				{
					// create a div and style it
					var div = document.createElement("div");
					this.tooltipdiv = div;
					$(div).addClass(cssClass)		
					// add the title/alt attribute to it
					.html((this.title || this.alt));
					this.title = "";
					this.alt = "";
					$("body").append(div);
					this.tooltipset = true;
				}
				$(this.tooltipdiv).show().css({left: mouseX + "px", top: mouseY + "px"});
				
				//$(this.tooltipdiv).fadeIn("fast").css({left: mouseX + "px", top: mouseY + "px"});			
	
				
			}
		).mouseout(
			function()
			{
				if(this.tooltipdiv)
				{
					$(this.tooltipdiv).hide();
					//$(this.tooltipdiv).fadeOut("fast")
				}
			}
		);
		return this;
	}


}



/* SWAP TABS PLANA PODCAST AZ */

function seleccionaPodcastTab(n){
	var i=1;
	do{
		if(i==n){
			document.getElementById("podTabContent_"+i).className = "visible";
			document.getElementById("podTab_"+i).className = "selected";
		}else{
			document.getElementById("podTabContent_"+i).className = "hidden";
			document.getElementById("podTab_"+i).className = "";
		}
		i++;
	}while(document.getElementById("podTabContent_"+i) != null);
}

function enviaEnquesta(id, varResult, idServei){
 	if (varResult == null) alert ("Sisplau, tria una de les opcions.");
	else{
		var toLoad = 'loadXMLDoc("http://www.tv3.cat/su/Register?hiAction=64&hiPortal=tvc&hiRegServiceId=TVC_REG&hiServiceId='+idServei+'&hiTarget=*.swf&resposta='+varResult+'&hiRetrievalXsl=aggregatedata.xsl&hiRetrieval=S",false,\''+id+'\')';
	  setTimeout(toLoad,10);
	  ajaxSite_DoHit();
  }
}
function veureEnquesta(id, idServei){
		var toLoad = 'loadXMLDoc("http://www.tv3.cat/su/Register?hiAction=69&hiPortal=tvc&hiRegServiceId=TVC_REG&hiServiceId='+idServei+'&hiTarget=*.swf&hiRetrievalXsl=aggregatedata.xsl&hiRetrieval=S",false,\''+id+'RES\')';
	  setTimeout(toLoad,10);
}

function recullResultatEnquesta(id, num_option){
  eval('result'+id+'='+num_option);
}

function enquestaAmbResultats(id, result, res){
		var rootElement = result.documentElement;
			var items = rootElement.getElementsByTagName("items")[0].getElementsByTagName("item");
			var txtResultat = "";
			var txtBoto = "";
			var guanyador = 0;
			var max_percentatge = 0;
			for(i=0; i<items.length; i++){
				var item = items[i];
				var percentatge = item.getElementsByTagName("pencentage")[0].firstChild.data;
				if(parseFloat(percentatge) > parseFloat(max_percentatge)){
					guanyador = i;
					max_percentatge = percentatge;
				}
			}

			for(i=0; i<items.length; i++){
				var item = items[i];
				var percentatge = item.getElementsByTagName("pencentage")[0].firstChild.data;
				var iniguanyador = "";
				var finguanyador = "";
				if(i==guanyador){
					iniguanyador='class="guanyador"';				
				}
				else {
				  iniguanyador='';
				} 
				
				txtResultat+='<li>'
				
				if(res=='RES'){
						txtResultat+=item.getElementsByTagName("description")[0].firstChild.data.replace(/\./g,',').replace(/\,$/g,'.');
				}
				else{
					  txtResultat+='<input name="OPT" type="radio" id="opcio'+item.getElementsByTagName("order")[0].firstChild.data+'" value="1" onclick="recullResultatEnquesta(\''+id.replace("RES", "")+'\', '+item.getElementsByTagName("order")[0].firstChild.data+')"/>';
						txtResultat+='<label opcio="opcio'+item.getElementsByTagName("order")[0].firstChild.data+'">';
						txtResultat+=item.getElementsByTagName("description")[0].firstChild.data.replace(/\./g,',').replace(/\,$/g,'.');
						txtResultat+='</label>';					
				}				

				txtResultat+='<div class="enq_percent"><img src="/img/enq_res.gif" ' + iniguanyador + 'width="'+percentatge+'" height="6" vspace="4" alt="" />'+percentatge+'%</div>';
				txtResultat+='</li>';
				
			}
			
			document.getElementById("resultat" + id + res).innerHTML = txtResultat;
			
			if(res=='RES'){
				document.getElementById("modenq"+id.replace("RES", "")).className = 'mod_enquesta_res enquesta_item_res';
			}
}

function pintaVots(id, result, res){			
	var rootElement = result.documentElement;
	var items = rootElement.getElementsByTagName("items")[0].getElementsByTagName("item");
	var enquestaVotsTotals = 0;
	for(i=0; i<items.length; i++){
			var item = items[i];
			enquestaVotsTotals = enquestaVotsTotals + parseInt(item.getElementsByTagName("counter")[0].firstChild.data);
	}
	if(enquestaVotsTotals == 1){
 		enquestaVotsTotals = enquestaVotsTotals+" vot";	
	}else{
		enquestaVotsTotals = enquestaVotsTotals+" vots";
	}			
	var identificador = "votsTotals"+id;
  document.getElementById(identificador).innerHTML = enquestaVotsTotals;
}

function swapTabsComSys(sel) {
	if(sel == "form"){
		document.getElementById("cs_form").className = 'com_contenidor';
		document.getElementById("cs_ajuda").className = 'com_contenidor hidden';
		document.getElementById("cs_tab_form").className = 'selected';
		document.getElementById("cs_tab_ajuda").className = '';
	}else if(sel == "ajuda"){
		document.getElementById("cs_form").className = 'com_contenidor hidden';
		document.getElementById("cs_ajuda").className = 'com_contenidor';		
		document.getElementById("cs_tab_form").className = '';
		document.getElementById("cs_tab_ajuda").className = 'selected';
	}
	// HIT OJD
	//ajaxSite_DoHit();
}



function cs_mostraCom(isReg){	
	
	if(isReg == "reg"){
		document.getElementById("cs_noreg_form").className = 'hidden';
		document.getElementById("cs_reg_form").className = '';
	}else{		
		document.getElementById("cs_noreg_form").className = '';
		document.getElementById("cs_reg_form").className = 'hidden';
		}
}


function cs_mostralog(){
	var comentari_value = document.getElementById("comentari").value;
	
	if(comentari_value != "" && comentari_value != undefined){
		document.getElementById("cs_missatge").className = 'hidden';
		document.getElementById("cs_log").className = '';
		document.getElementById("cs_emptycom").className = 'hidden';
	}else{		
		document.getElementById("cs_emptycom").className = 'buto_enviar msg_benvinguda';
		}
}

function cs_amagalog(){	
	document.getElementById("cs_log").className = 'hidden';
	document.getElementById("cs_missatge").className = '';
	}


function mostraPemissioMesInfo(id) {	
	if(document.getElementById("mes_info_"+id).className == "hidden"){
		document.getElementById("mes_info_"+id).className = "";
		document.getElementById("mes_info_btn_"+id).className = "tancainfo";
		document.getElementById("mes_info_punts_"+id).className = "hidden";
		document.getElementById("mes_info_btn_"+id).innerHTML = "tanca";
	}else{
		document.getElementById("mes_info_"+id).className = "hidden";
		document.getElementById("mes_info_btn_"+id).className = "";
		document.getElementById("mes_info_punts_"+id).className = "";
		document.getElementById("mes_info_btn_"+id).innerHTML = "info";
		}
}

