//Javascript

//preload
var i;
var imagenes = new Array("ims/back_menu.gif","ims/bottomleft.gif","ims/runido.gif","ims/espa.gif","ims/cata.gif","ims/bottomleft.gif","ims/loading.gif","ims/ajax-loader.gif");
var lista_imagenes = new Array();

for(i in imagenes){
	lista_imagenes[i] = new Image();
	lista_imagenes[i].src = imagenes[i];
}
//fi preload

function opf(url_imagen,titulo,ancho,alto){
 	var img = new Image();

 	img.src = url_imagen;
	win=window.open('','','width='+ancho+',height='+alto+',scrollbars=no,resizable=1,toolbar=0');
	win.document.write ('<html>\n');
	win.document.write (' <head>\n');
	win.document.write ('  <title>'+titulo+'</title>\n');
	win.document.write (' </head>\n');
	win.document.write (' <body onclick="return window.close();" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
	win.document.write ('  <img src="' + url_imagen + '">\n');
	win.document.write (' </body>\n');
	win.document.write ('</html>\n');	
}

// Inici funcions obrefoto

function nocontextmenu()  // this function only applies to IE4, ignored otherwise.
{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
}

function norightclick(e)	// This function is used by all others
{
	if (window.Event)	// again, IE or NAV?
	{
		if (e.which == 2 || e.which == 3)
			return false;
	}
	else
		if (event.button == 2 || event.button == 3)
		{
			event.cancelBubble = true
			event.returnValue = false;
			return false;
		}
}

function inhabilita(){
	if (window.Event) // Only Netscape will have the CAPITAL E.
	  document.captureEvents(Event.MOUSEUP); // catch the mouse up event
	  
	document.oncontextmenu = nocontextmenu;		// for IE5+
	document.onmousedown = norightclick;		// for all others
}

function centrar(x,y){
	
	//Centrem pantalla
	x_win =((screen.width-x)/2);
	y_win = ((screen.height-y)/2);	
	self.moveTo(x_win,y_win);
}

/////Fi funcions obrefoto


var delay=50;
var currentChar=1;
var destination="[not defined]";

function type()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination);
    if (dest)
    {
      dest.innerHTML=text.substr(0, currentChar);
      currentChar++
      if (currentChar>text.length)
      {
        currentChar=1;
        //setTimeout("type()", 5000);
      }
      else
      {
        setTimeout("type()", delay);
      }
    }
  }
}


function startTyping(textParam, delayParam, destinationParam)
{
  text=textParam;
  delay=delayParam;
  currentChar=1;
  destination=destinationParam;
  type();
}

function SelectLink(formu) {
	if (formu.id.selectedIndex == -1) return;
	window.location.href='modif_bttle_cole.php?id='+formu.id.options[formu.id.selectedIndex].value;

}

function comproba(formu){
	
	if(formu.id.selectedIndex == 0){
		alert("Trii una subcategoria");
		return false;
	}
	
	else if(formu.dorsal.checked && formu.numdorsal.value.length==0){
		alert("Cal que escrigui un nombre de dorsal per a poder filtrar correctament la búsqueda");
		return false;
	}
	
	else return true;
}

function nuevoAjax(){ 
	var xmlhttp=false; 
	try { 
		// Creación del objeto ajax para navegadores diferentes a Explorer 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) { 
		// o bien 
		try { 
			// Creación del objet ajax para Explorer 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { 
			xmlhttp = false; 
		} 
	} 

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
		xmlhttp = new XMLHttpRequest(); 
	}
	
	return xmlhttp; 
}

function getPageHeight(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll;
}

function llistar(dir,apartat) {

	var contenedor; 

	contenedor = document.getElementById('botellines'); 
	// contenedor es el <div> , donde al final pintaremos el calendario

	ajax = nuevoAjax(); 
	// aqui creamos una instancia del objeto ajax 

	ajax.open("GET", "files/infoBotellines.php?tipo=" + dir + "&apartat="+apartat,true); 

	// con esto enviamos al archivo .php el valor del mes y año para que sea ejecutado 

	ajax.onreadystatechange = function() { 
		if (ajax.readyState==4) { 
			// En esta parte del código, se revisa cuando ha sido procesada la carga del AJAX 
			contenedor.innerHTML = ajax.responseText 
			//CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor" 
		}
	} 

	ajax.send(null) 
	// aqui se hace el envio del objeto 
}

function next(apartat,foto) {
	
	var contenedor; 

	contenedor = document.getElementById('botellines'); 
	// contenedor es el <div> , donde al final pintaremos el calendario

	ajax = nuevoAjax(); 
	// aqui creamos una instancia del objeto ajax 

	ajax.open("GET", "files/infoBotellines.php?tipo=" + dir,true); 

	// con esto enviamos al archivo .php el valor del mes y año para que sea ejecutado 

	ajax.onreadystatechange = function() { 
		if (ajax.readyState==4) { 
			// En esta parte del código, se revisa cuando ha sido procesada la carga del AJAX 
			contenedor.innerHTML = ajax.responseText 
			//CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor" 
		}
	} 

	ajax.send(null) 
	// aqui se hace el envio del objeto 
}


//START el meu slideshow
var id;
var foto_actual = -1;
var foto_fin 	= -1;
var start 		= false;
var apartat_fotos;
var total_fotos_x;

function PLAY(apartat,num_foto,total_fotos) {
	
	var contenedor;
	var contenedro1;
	
	//amb start controlem l animacio quan inicia i quan acaba
	start = true;
	
	//dades per al reestart
	apartat_fotos = apartat;
	total_fotos_x = total_fotos;
	
	//a cada entrada a PLAY avansem foto
	num_foto++;
	
	//agafem els contenidors...
	contenedor = document.getElementById('foto');
	contenedor1 = document.getElementById('pelicula');
	
	if(start) contenedor1.innerHTML = "<a href='#' onclick='STOP()'><img src='ims/stop.gif' name='pic5' border=0></a>";
	
	// contenedor es el <div> , donde al final pintaremos el calendario
	ajax = nuevoAjax(); 
	// aqui creamos una instancia del objeto ajax 

	foto_actual = num_foto ;
	
	if(foto_fin!=-1){
		num_foto = foto_fin+1;
		foto_fin = -1;
	}
	
	//em retorna la seguent foto de num_foto
	ajax.open("GET", "files/ajax_fotos.php?apartat=" + apartat + "&num_foto="+num_foto%total_fotos,true);
	
	// con esto enviamos al archivo .php el valor del mes y año para que sea ejecutado 

	ajax.onreadystatechange = function() { 
		if (ajax.readyState==4) { 
			// En esta parte del código, se revisa cuando ha sido procesada la carga del AJAX 
			contenedor.innerHTML = ajax.responseText
			//CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor" 
		}
	} 

	ajax.send(null) 
	// aqui se hace el envio del objeto 
	id = setTimeout("PLAY("+apartat+","+num_foto+","+total_fotos+")",6000);
}

function STOP(){
	contenedor1 = document.getElementById('pelicula');
	clearTimeout(id);
	foto_fin = foto_actual;
	contenedor1.innerHTML = "<a href='#' onclick='PLAY("+apartat_fotos+","+foto_actual+","+total_fotos_x+");'><img src='ims/play.gif' name='pic4' border=0></a>";
	start = false;
}
//FIN del meu slideshow


function mostraProducte(dir,apartat) {
	
	var contenedor; 

	contenedor = document.getElementById('botella'); 
	// contenedor es el <div> , donde al final pintaremos el calendario

	ajax = nuevoAjax(); 
	// aqui creamos una instancia del objeto ajax 

	ajax.open("GET", "descrBotellines.php?IDbotella=" + dir+"&apartat="+apartat,true); 

	// con esto enviamos al archivo .php el valor del mes y año para que sea ejecutado 

	ajax.onreadystatechange = function() { 
		if (ajax.readyState==4) { 
			// En esta parte del código, se revisa cuando ha sido procesada la carga del AJAX 
			contenedor.innerHTML = ajax.responseText 
			//CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor" 
		}
	} 

	ajax.send(null) 
	// aqui se hace el envio del objeto 
}

function limpiar(id)
{
   document.getElementById(id).innerHTML="<img src='ims/blank.gif'>";
}

function data(){

	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000)
	year+=1900;
	var day=mydate.getDay();
	var month=mydate.getMonth()+1;
	if (month<10)
	month="0"+month;
	var daym=mydate.getDate();
	if (daym<10)
	daym="0"+daym;
	document.write("<small><font style='font-family:tahoma;color:white;font-size:11px;font-style:italic'>"+daym+"/"+month+"/"+year+"</font></small>")
}

function loader(){

	if(document.all == undefined){
		document.getElementById('loader').style.height = "100%";
	}
	
	document.body.style.overflow	=	'hidden';
	document.getElementById('loader').style.visibility 	= "visible";
	document.getElementById('loader').innerHTML 		= "<table align='center' cellpadding=0 cellspacing=0 height='80' width='300' style='border:3px solid black;background-color:white;z-index:100' cellpadding='0' cellspacing='0'><tr><td align='center'><img src='../ims/ajax-loader.gif' name='img1'></td><td align='center'><b>Carregant, si us plau esperi...</b></td></tr></table>";

}

function end_preload(){

	document.getElementById('loader').style.opacity = "hidden";

}


