
function changeImage(aurl, url,text){
    if (url != null)
    {
          var currentaImage = document.getElementById("aprincipal");
          if (currentaImage != null)
          {
              currentaImage.href = aurl;
              currentaImage.title = text;
          }
          var currentImage = document.getElementById("principal");
          if (currentImage != null)
          {
                currentImage.src = url;
                currentImage.alt = text;
                currentImage.title = text;
          }
          var currentImageFoot = document.getElementById("principalFoot");
          if (currentImageFoot != null)
          {
                currentImageFoot.innerHTML = unescape(text);
          }
    }
}
function changeItemHomeVideo(aurl, url,text,embed){
    
	var Item = document.getElementById("item");
    if(Item!=null){
    	Item.innerHTML ='<embed id=\"videoprincipal\" height=\"270\" width=\"310\" flashvars=\"width=310&height=270&file='+embed+'&image='+url+'\" allowfullscreen=\"true\" quality=\"high\" name=\"mediaplayer\" id=\"mediaplayer\" src=\"/export/system/modules/info.cerdanyola.presentation/resources/swf/mediaplayer.swf\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"/><h3><a id=\"principalFoot\" href=\"'+aurl+'\" title=\"'+text+'\">'+text+'</a></h3>';
    }
}
function changeItemHomeImage(aurl, url,text){
    
	var Item = document.getElementById("item");
    if(Item!=null){
    	Item.innerHTML ='<a id=\"aprincipal\" href=\"'+aurl+'\" title=\"'+text+'\"><img id=\"principal\" alt=\"'+text+'\" title=\"'+text+'\" src=\"'+url+'\" /></a><h3><a id=\"principalFoot\" href=\"'+aurl+'\" title=\"'+text+'\">'+text+'</a></h3>';
    }
}/*
function changeSport(j,q){
	for(i = 1 ; i<=q;i++){
		 if(document.getElementById('lideporte'+i)!=null){
		 	document.getElementById('lideporte'+i).className ='noselected';
		 }
		 if(document.getElementById('ulpestanyacategoria'+i)!=null){
		 	document.getElementById('ulpestanyacategoria'+i).className ='none';
		 }
	}
	var sport = document.getElementById('lideporte'+j);
	if(sport!=null)	sport.className  = 'selected';

	var categorias = document.getElementById('ulpestanyacategoria'+j);
	if(categorias!=null) categorias.className  = 'block';

	changeCategoria(j,1);	
}
*/
function changeSport(j,q,l,a){
	for(i = 1 ; i<=q;i++){
		 if(document.getElementById('lideporte'+i)!=null){
		 	document.getElementById('lideporte'+i).className ='noselected';
		 }
		 if(document.getElementById('ulpestanyacategoria'+i)!=null){
		 	document.getElementById('ulpestanyacategoria'+i).className ='none';
		 }
	}
	var sport = document.getElementById('lideporte'+j);
	if(sport!=null)	sport.className  = 'selected';

	document.getElementById('frame_res').src = l;	
	document.getElementById('frame_res').height = a;	

}
function changeCategoria(j,k){
	var end = false;
	for(i = 1 ; !end ;i++){
		 if(document.getElementById('lipestanyacategoria'+j+i)!=null){
		 	document.getElementById('lipestanyacategoria'+j+i).className ='noselected';
		 }else{
			 end=true;
		 }
	}

	var categoria = document.getElementById('lipestanyacategoria'+j+k);
	if(categoria!=null) categoria.className  = 'selected';	

	end = false;
	 
	for(s = 1, n = 1 ; !end ;n++){
		 if(document.getElementById('pestanyaresultats'+s+n)!=null){
		 	document.getElementById('pestanyaresultats'+s+n).className ='none';
			if(document.getElementById('pestanyaclassificacions'+s+n)!=null){
				 document.getElementById('pestanyaclassificacions'+s+n).className ='none';
		     }
		 }else if(document.getElementById('pestanyaresultats'+(s+1)+'1')!=null){
			 s++;
			 n=0;
		 }else{
			end = true;
	     }
	}
	var resultats = document.getElementById('pestanyaresultats'+j+k);
	if(resultats!=null) resultats.className  = 'block';	
	var classificacio = document.getElementById('pestanyaclassificacions'+j+k);
	if(classificacio!=null) classificacio.className  = 'block';	
}
function enviar_formulario()
{
	formulario = document.getElementById("form_enquesta");
	resposta=formulario.resposta;
	res = false; 
	for(i=0;!res&&i<resposta.length;i++)
	{
		if(resposta[i].checked)
			res=resposta[i].value;
	}
	if(!res) 
		alert('Has de seleccionar alguna resposta');
	else
	{	
		//parsear datos por si hay comas
		
		formulario.submit();
	}		
}
function mostrar_resultados()
{
    window.location = '?veure_grafica=true';
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e) 
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function recargarMasVotados(){
	var URL_AJAX = "/web/system/modules/info.cerdanyola.presentation/elements/mas_vistos_votados_ajax.jsp";
	ajaxCallVotacion(URL_AJAX);
	var xmlHttp;
	function ajaxCallVotacion(url)
	{
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
	  return;
	  } 
	else
	  {
		try{
			xmlHttp.onreadystatechange = printDosPuntCero;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}catch(e){
			alert(e);
		}
	  }
	} 
	function printDosPuntCero()  
	{		
			if (xmlHttp.readyState==4)
			{
				var div = document.getElementById('contents');
				if(div!=null) div.innerHTML =xmlHttp.responseText;		
			}
	}
} 
function recargarMasVotadosCategory(category){
	var URL_AJAX = "/web/system/modules/info.cerdanyola.presentation/elements/mas_vistos_votados_ajax.jsp?category="+category;
	ajaxCallVotacion(URL_AJAX);
	var xmlHttp;
	function ajaxCallVotacion(url)
	{
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
	  return;
	  } 
	else
	  {
		try{
			xmlHttp.onreadystatechange = printDosPuntCero;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}catch(e){
			alert(e);
		}
	  }
	} 
	function printDosPuntCero()  
	{		
			if (xmlHttp.readyState==4)
			{
				var div = document.getElementById('contents');
				if(div!=null) div.innerHTML =xmlHttp.responseText;		
			}
	}
} 
function valorar(url){
	var URL_AJAX = '/web/system/modules/info.cerdanyola.presentation/elements/valorar.jsp' + '?resource=' + url;
	ajaxCallValorar(URL_AJAX);
	var xmlHttp;
	function ajaxCallValorar(url)
	{
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
	  return;
	  } 
	else
	  {
		try{
			xmlHttp.onreadystatechange = printValorar;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}catch(e){
			alert(e);
		}
	  }
	} 
	function printValorar()  
	{		
			if (xmlHttp.readyState==4)
			{
				var div = document.getElementById('valoraciones');
				if(div!=null) div.innerHTML =xmlHttp.responseText;	
				var divPos = document.getElementById('pos');
				if(divPos!=null){
					divPos.innerHTML ='';
					divPos.style.display = 'none';
				}
				
			}
	}	
}
function changePestanyaDosCero(i,k){
	
	var contents1 = document.getElementById('contents'+i);
	if(contents1!=null) contents1.className = 'block';
	
	var contents2 = document.getElementById('contents'+k);
	if(contents2!=null) contents2.className = 'none';
	
	var pestanya1 = document.getElementById('pestanya'+i);
	if(pestanya1!=null) pestanya1.className = 'select';
	var pestanya2 = document.getElementById('pestanya'+k);
	if(pestanya2!=null) pestanya2.className = '';
	
}
