//Javascript

//preload
var i;
var imagenes = new Array("topleft.gif.gif","top1.gif","top.gif","bl.gif","topright.gif","bottomleft.gif","bottomright.gif","bottom1.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 preload_galeria(dir){

	var array;

	ajax = nuevoAjax(); 
	// aqui creamos una instancia del objeto ajax 

	ajax.open("GET", "files/llistar.php?dir=" + dir,true); 

	ajax.onreadystatechange = function() { 
		if (ajax.readyState==4) {

			// En esta parte del código, se revisa cuando ha sido procesada la carga del AJAX 
			arrayet = ajax.responseText;

			var j;
			var imagenes = new Array(arrayet);
			var lista_imagenes = new Array();

			for(j in imagenes){
				lista_imagenes[j] = new Image();
				lista_imagenes[j].src = imagenes[j];
			}
						
		}
	} 

	ajax.send(null)
}

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 end_preload(){

	document.getElementById('loader').style.visibility = "hidden";

}

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){
	
	//no comprovo el telf, es opcional...
	//sol a 1 es error
	var sol = new Array(2);
	var alerta="";
	filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	
	if(formu.nom.value.length==0)
		alerta += "- El campo NOMBRE está vacío.\n" ;
	
	if(formu.mail.value.length==0 || !filter.test(formu.mail.value))
		alerta += "- El campo E-MAIL está vacío o contiene errores." ;	

	if(alerta!=""){
		alert(''+alerta);
		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;
}

