// JavaScript Document

var fitxaseleccionada = 'general';

function mostrarPanell ( obj, mostrar ) {

	if ( mostrar ) {
		obj.className = 'fitxavisible';
	} else {
		obj.className = 'fitxanovisible';
	}
	
}

function mostrarFitxa ( nom ) {
	
	var aux = fitxaseleccionada;
	fitxaseleccionada = nom;
	activarPestanya ( aux, false );
	activarPestanya ( nom, true );
	
	switch ( nom ) {
		case 'general':
			mostrarPanell ( MM_findObj ( 'fitxageneral' ), true );
			mostrarPanell ( MM_findObj ( 'fitxafotos' ), false );
			mostrarPanell ( MM_findObj ( 'fitxamapa' ), false );
			mostrarPanell ( MM_findObj ( 'fitxavaloracio' ), false );
			break;
		case 'fotos':
			mostrarPanell ( MM_findObj ( 'fitxageneral' ), false );
			mostrarPanell ( MM_findObj ( 'fitxafotos' ), true );
			mostrarPanell ( MM_findObj ( 'fitxamapa' ), false );
			mostrarPanell ( MM_findObj ( 'fitxavaloracio' ), false );
			break;
		case 'mapa':
			mostrarPanell ( MM_findObj ( 'fitxageneral' ), false );
			mostrarPanell ( MM_findObj ( 'fitxafotos' ), false );
			mostrarPanell ( MM_findObj ( 'fitxamapa' ), true );
			mostrarPanell ( MM_findObj ( 'fitxavaloracio' ), false );
			GLoad();
			break;
		case 'valoracio':
			mostrarPanell ( MM_findObj ( 'fitxageneral' ), false );
			mostrarPanell ( MM_findObj ( 'fitxafotos' ), false );
			mostrarPanell ( MM_findObj ( 'fitxamapa' ), false );
			mostrarPanell ( MM_findObj ( 'fitxavaloracio' ), true );
			animacioValoracio();
			break;
	}
	
}	

function mostrarRecepta ( nom ) {
	
	switch ( nom ) {
		case 'recepta1':
			mostrarPanell ( MM_findObj ( 'recepta1' ), true );
			mostrarPanell ( MM_findObj ( 'recepta2' ), false );
			mostrarPanell ( MM_findObj ( 'recepta3' ), false );
			break;
		case 'recepta2':
			mostrarPanell ( MM_findObj ( 'recepta1' ), false );
			mostrarPanell ( MM_findObj ( 'recepta2' ), true );
			mostrarPanell ( MM_findObj ( 'recepta3' ), false );
			break;
		case 'recepta3':
			mostrarPanell ( MM_findObj ( 'recepta1' ), false );
			mostrarPanell ( MM_findObj ( 'recepta2' ), false );
			mostrarPanell ( MM_findObj ( 'recepta3' ), true );
			break;
	}
	
}	

function animacioValoracio ( ) {
	activarGif ( 'valoraciomenjar' );
	activarGif ( 'valoracioatencio' );
	activarGif ( 'valoraciolocal' );
	activarGif ( 'valoraciozona' );
	pause ( 500 );
	activarGif ( 'valoraciototal' );
}

function activarGif ( id ) {
	if (document.getElementById ( id ))
		document.getElementById ( id ).src = document.getElementById ( id ).src;
}

function activarPestanya ( nom, activar ) {
	var estilo;
	if ( fitxaseleccionada == nom ) {
		estilo = 'pestanyaactiva';
	} else {
		if ( activar ) {
			estilo = 'pestanyacandidata';
		} else {
			estilo = 'pestanya';
		}
	}
	MM_findObj ( 'pestanya' + nom + 'fondo' ).className = estilo;
	MM_findObj ( 'pestanya' + nom + 'texto' ).className = estilo;
	MM_findObj ( 'pestanya' + nom + 'inicio' ).className = estilo;
	MM_findObj ( 'pestanya' + nom + 'fin' ).className = estilo;
}

function MM_findObj ( name ) {

	return document.getElementById ( name );
	
}	

function veureImatge ( nom ) {
	var foto = MM_findObj ( 'fotogaleria' );
	foto.src = nom;
}

function veureImatgePopup ( nom, ample ) {
	if ( ample == null ) ample = 800;
	var alt = ample * 3 / 4;
	var foto = nom.substring ( 0, nom.lastIndexOf ( '-' ) ) ;
	foto += '-' + ample + '.jpg';
	popup ( foto, ample, alt );
}

function publiOff () {
	var t = window.setTimeout('publiOff()', 500);
	//alert ( t );
	for ( var i=t-10; i<t; i++ ) {
		window.clearTimeout(i);
	}
	//document.getElementsByTagName("iframe")[0].style.display = 'none';
	//document.getElementsByTagName("div")[0].style.display = 'none';
}
//publiOff();

function popup ( pagina, ample, alt ) {
	var win = window.open ( pagina, "popup","width=" + ample + ", height=" + alt + ", scrollbars=no, menubar=no, location=no, resizable=no")
	win.focus ();
} 

function popupscroll ( pagina, ample, alt ) {
	var win = window.open ( pagina, "popup","width=" + ample + ", height=" + alt + ", scrollbars=yes, menubar=no, location=no, resizable=no")
	win.focus ();
} 

function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}

// A function to create the marker and set up the event window
function createMarker(point, name, html, icon) {
	var marker = new GxMarker(point, icon, "<p>" + name + "</p>");
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
}

/* Verificar email */
function verificarEmail ( campo, mensaje, formatoOK, formatoNOK ) {

  var ok = false;
  
  if ( campo != null ) {
      if ( ( campo.value.lastIndexOf(".") > 3) && (campo.value.indexOf("@") > 1 ) ) {
        campo.className = formatoOK;
        ok = true;
      } else {
        campo.focus();
        campo.className = formatoNOK;
        ok = false;
      }
      
      if ( !ok && mensaje != '' ) {
        alert ( mensaje );
      }
      
      return ok;
      
  } else {
      // El campo no existe
      return false;
  }

}

/* Seleccionar un valor de las opciones de un select */
function seleccionarValorSelect ( select, valor ) {

  var i;
  
  for ( i=0; i<select.options.length; i++ ) {
    
    if ( select.options[i].value == valor )
      select.selectedIndex = i;
      
  }
  
}

function confirmarEsborrar() {
	return confirm('Segur que vol esborrar?');
}
