function posicio_fons()
{    
    // Calculem l'altura que ha de tenir el fons amb logo perque talli justament amb el peu de pagina

    if (!document.getElementById("fons_si_logo")) {return};         // Si no existeix el div, no fem res
    if (!document.getElementById("menu")) {return};                 // En principi no pot pasar

    alt_menu_min = 552;                                             // Altura mínima del menú 
    alt_logo_ini = 376;                                             // Altura inicial del fons amb el logo

    alt_menu     = document.getElementById("menu").offsetHeight;    // Altura real del menu
    dif          = alt_menu - alt_menu_min;                         // Cantitat de píxels de més que te el menú
    alt_logo_fin = alt_logo_ini + dif;                              // Sumem aquests píxels a l'altura del div

    document.getElementById("fons_si_logo").style.height = alt_logo_fin + "px";
    
}

function chgmenu(opc,div,ima,imadest)
{    
    if (opc=='si') 
    { 
    	document.getElementById(div).style.display='';
    } 
    if (opc=='no') 
    { 
    	document.getElementById(div).style.display='none';
    } 
    
    document.getElementById(ima).src=imadest;
}

function idioma(opcion,id)
{    
    if (opcion=='si') document.getElementById(id).style.background='url(\'Imatges/Optim/idi_deur.gif\')'; 
    if (opcion=='no') document.getElementById(id).style.background='url(\'Imatges/Optim/idi_blau.gif\')';     
}

function mostra_pais(numtot, num)
{
	if (document.getElementById('sub_'+num).style.display=='') 
        document.getElementById('sub_'+num).style.display='none';
	else
	{
		for(i=1; i<numtot+1; i++)
		{
			if (i!=num) { document.getElementById('sub_'+i).style.display='none' }
			else { document.getElementById('sub_'+i).style.display='' }
		}
    }

    posicio_fons();
}

function mostra_any(numtot, num)
{
	
	if (document.getElementById('sub_'+num).style.display=='') 
        document.getElementById('sub_'+num).style.display='none';
	else
	{
		for(i=1; i<numtot+1; i++)
		{
			if (i!=num) { document.getElementById('sub_'+i).style.display='none' }
			else { document.getElementById('sub_'+i).style.display='' }
		}
    }

    posicio_fons();
}

function cambiar_color(tip,num,color)
{    
    document.getElementById(tip+1+'_'+num).style.backgroundColor=color;
    document.getElementById(tip+2+'_'+num).style.backgroundColor=color;
    document.getElementById(tip+3+'_'+num).style.backgroundColor=color;
    document.getElementById(tip+4+'_'+num).style.backgroundColor=color;
    document.getElementById(tip+5+'_'+num).style.backgroundColor=color;
    document.getElementById(tip+6+'_'+num).style.backgroundColor=color;

}

function color_partit(var1,var2,color)
{    
    document.getElementById(var1+'1_'+var2).style.backgroundColor=color;
    document.getElementById(var1+'2_'+var2).style.backgroundColor=color;
    document.getElementById(var1+'3_'+var2).style.backgroundColor=color;
    document.getElementById(var1+'4_'+var2).style.backgroundColor=color;
    document.getElementById(var1+'5_'+var2).style.backgroundColor=color;

}

function negreta(celda,neg)
{    
    celda.style.fontWeight=neg;
}

function subr(celda,opcion)
{    
    if (opcion=='si') celda.style.textDecoration='underline';
    if (opcion=='no') celda.style.textDecoration='none';
}

function subratllat(opcion)
{    
    if (opcion=='si') document.getElementById('txt4').style.textDecoration='underline';
    if (opcion=='no') document.getElementById('txt4').style.textDecoration='none';
}

function pop_idi(opcion)
{    
    if (opcion=='si') document.getElementById('pop_idioma').style.display='';
    if (opcion=='no') document.getElementById('pop_idioma').style.display='none';
}


function pop_sis(opcion)
{    
    if (opcion=='si') document.getElementById('pop_sistema').style.display='';
    if (opcion=='no') document.getElementById('pop_sistema').style.display='none';
}

function pop_gmt(opcion)
{    
    if (opcion=='si') document.getElementById('pop_gmt').style.display='';
    if (opcion=='no') document.getElementById('pop_gmt').style.display='none';
}


function sel(opcion,num)
{    
    if (opcion=='si'){
        document.getElementById('sub_m'+num).style.display='';
        document.getElementById('boto'+num).style.background='url(\'Imatges/Optim/boto_superior_sel.gif\')'; 
    }

    if (opcion=='no'){
       document.getElementById('boto'+num).style.background='url(\'Imatges/Optim/boto_superior.gif\')';
       document.getElementById('sub_m'+num).style.display='none';       
    }
    
}

function des_sel(num)
{    
    setTimeout('des_sel('+num+')',0400);
}



function popup(url, height, width, resizable, scrollbars) 
{
	window.open(url,'',"height="+height+",width="+width+",toolbar=0,location=0,directories=0,menubar=0,status=0,resizable="+resizable+",scrollbars="+scrollbars+",left="+((screen.width - width) / 2)+",top="+((screen.height - height) / 2))
}

function alerta(txt)
{    
    alert(txt);
}

function welcome(celda,opcion)
{    
    if (opcion=='si') celda.style.color='#C6B80F';
    if (opcion=='no') celda.style.color='#5D7C90';
    if (opcion=='si') blinkar('si');

    if (opcion=='no') blinkar('no');
}

function imatgeg(id,ima)
{    
    document.getElementById(id).src=ima; 
}

function shlayer(idlayer,visStr) { //v2.5

     if (document.getElementById)
        { // Netscape 6 & IE 6
         if (visStr == '#C6B80F') visStr = '#C6B80F'; //convert vals
         if (visStr == '#E6EBF0') visStr = '#E6EBF0';
         if (visStr == '#5D7C90') visStr = '#5D7C90';
      document.getElementById(idlayer).style.color=visStr;      
        } else {
         if (navigator.appName == 'Netscape' && document.layers != null) // Netscape 4
        {
        document.layers[idlayer].style.color=visStr;
        } else if (document.all != null) { //IE 4+
         if (visStr == '#C6B80F') visStr = '#C6B80F'; //convert vals
         if (visStr == '#E6EBF0') visStr = '#E6EBF0';
         if (visStr == '#5D7C90') visStr = '#5D7C90';
        document.all[idlayer].style.color=visStr;}
        }
}

function blink()
{
   for (n=0;n<textos.length;n++) { shlayer(textos[n],aestado[estado]); }
   id=window.setTimeout("blink();",tiempo);
   estado = (estado) ? 0 : 1;
}

function blink_ini()
{
    textos=new Array('welc_txt');
    aestado= new Array('#5D7C90','#5D7C90');
    estado=0;
    tiempo=300;
    id=window.setTimeout("blink();",tiempo);
}

function blinkar(opcion)
{    
   clearTimeout(id);

   textos=new Array('welc_txt');

   if (opcion=='si') aestado= new Array('#C6B80F','#E6EBF0');
   if (opcion=='no') aestado= new Array('#5D7C90','#5D7C90');

   estado=0;
   tiempo=300;
   id=window.setTimeout("blink();",tiempo);
}

function mailsortida(correo)
{
    correo_sor='mailto: ' + correo.replace ('#','@');
    document.getElementById('ocmail').href = correo_sor;
}

function condicions(txt)
{
    document.getElementById("condi").innerHTML = txt;
}

function Enviar_histo(form)
{
   form.submit();
}

function Enviar_comp(url)
{
	document.entrada.action=url+document.getElementById("sport").value+'.html';
}

function Form_gest(id)
{
	document.getElementById(id).value = document.getElementById("literal").value;
	if(document.getElementById('utf8').checked) document.getElementById(id).value = utf8_decode(document.getElementById("literal").value);
}

function Form_doubt()
{
	document.getElementById('dubte').value = document.getElementById("literal").value;
	document.getElementById('espdubte').value = document.getElementById("sport").value;
	
	if (confirm('¿Seguro de generar la duda?')) document.getElementById('doubt').submit();
}

function Form_doubt2()
{
	document.getElementById('lit4').value = document.getElementById("literal").value;
	if(document.getElementById('utf8').checked) document.getElementById('lit4').value = utf8_decode(document.getElementById("literal").value);	
	
	if (confirm('¿Seguro de generar la duda?')) document.getElementById('doubt').submit();
}

function Form_del(id,idlit,alrt)
{	
	document.getElementById(idlit).value = document.getElementById("literal").value;
	
	if (confirm('¿Esta seguro de borrar '+alrt+'?')) document.getElementById(id).submit();
}

function competitor_ok()
{	

	if (document.getElementById('sport').value == 0)  { alert('Falta informar el deporte'); return (false);  }
	if (document.getElementById('des15').value == "") { alert('Falta informar la descripcion');  return (false);  }
	if (document.getElementById('des20').value == "") { alert('Falta informar la descripcion');  return (false);  }
	
	return (true);
}

function utf8_decode (str_data) {
    // Converts a UTF-8 encoded string to ISO-8859-1  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/utf8_decode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var tmp_arr = [],
        i = 0,
        ac = 0,
        c1 = 0,
        c2 = 0,
        c3 = 0;
 
    str_data += '';
 
    while (i < str_data.length) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if (c1 > 191 && c1 < 224) {
            c2 = str_data.charCodeAt(i + 1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i + 1);
            c3 = str_data.charCodeAt(i + 2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}

function clearText(input)
{    
	if (input.defaultValue==input.value)
		input.value = ""
}	
