
if( !window.opener ){ window.location = './../'; }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Muestra la ficha del SELECT
function fWindowFicha( fichaID ){
	if( Number( fichaID ) ){
		window.location.href = './ficha.php?fichaID=' + fichaID;
	}
}

var arrImagenes = new Array();

var imagenActiva = 0;

// Funcion para mostrar la imagen
function fMostrarImagen(){
	if( imagenActiva < 0 ){
		imagenActiva = arrImagenes.length - 1;
	}
	else
	if( imagenActiva > arrImagenes.length - 1 ){
		imagenActiva = 0;
	}
	document.getElementById( 'imagenFicha' ).src = arrImagenes[ imagenActiva ].src;
//	document.getElementById( 'imagenFicha' ).width = arrImagenes[ imagenActiva ].width;
//	document.getElementById( 'imagenFicha' ).height = arrImagenes[ imagenActiva ].height;
	document.getElementById( 'statusImagenes' ).innerHTML = "FOTO <b>" + ( imagenActiva + 1 ) + "</b> DE <b>" + arrImagenes.length + "</b>";
}

function fImagenAnterior(){
	imagenActiva--;
	fMostrarImagen();
}
function fImagenSiguiente(){
	imagenActiva++;
	fMostrarImagen();
}


// Función FOCUS y BLUR de los campos del formulario
function fInputFocus( inputID )
{
	document.getElementById( inputID ).style.backgroundColor = "#AAAAAA";
	document.getElementById( inputID ).style.color = "#000000";
}
function fInputBlur( inputID )
{
	document.getElementById( inputID ).style.backgroundColor = "#333333";
	document.getElementById( inputID ).style.color = "#AAAAAA";
}


// Validación de formularios ( Email 'e' y Recomendacion 'r' )
function validarFormulario( tipo ){
	var errores = false;
	var txtError = "Se enontraron los siguientes errores:";
	
	var frmNombre, frmAmigo, frmEmail;
	
	switch( tipo ){
		case 'r' : // Si se está recomendando a alguna ficha
			frmNombre = document.getElementById( 'frmNombreRecomienda' ).value.replace( /\s/g, '' );
			frmAmigo = document.getElementById( 'frmAmigoRecomienda' ).value.replace( /\s/g, '' );
			frmEmail = document.getElementById( 'frmEmailRecomienda' ).value.replace( /\s/g, '' );
			break
		case 'e' : // si se está enviando un email a una ficha
			frmNombre = document.getElementById( 'frmNombreEmail' ).value.replace( /\s/g, '' );
			frmEmail = document.getElementById( 'frmEmailEmail' ).value.replace( /\s/g, '' );
			break;
	}
	
	if( !frmNombre ){
		errores = true;
		txtError += "\n- Debes proporcionar tu nombre";
	}
	if( !frmAmigo && tipo == 'r' ){
		errores = true;
		txtError += "\n- Debes proporcionar el nombre de tu amigo";
	}
	if( !frmEmail ){
		errores = true;
		if( tipo == 'r' ){
			txtError += "\n- Debes proporcionar el email de tu amigo";
		} else {
			txtError += "\n- Debes proporcionar tu email";
		}
	} else {
		if( frmEmail.indexOf('@') < 1 || 
			frmEmail.indexOf('.') < 1 || 
			frmEmail.indexOf('@') > frmEmail.length - 6 || 
			frmEmail.indexOf('@') != frmEmail.lastIndexOf('@') || 
			frmEmail.lastIndexOf('.') == frmEmail.length - 1 ||
			frmEmail.lastIndexOf('.') < frmEmail.indexOf('@') ){
				errores = true;
				txtError += "\n- Debes ingresar una cuenta de email válida";
		}
	}
	
	if( errores ){ alert( txtError ); }
	else {
		switch( tipo ){
			case 'r' : document.formularioRecomienda.submit(); break;
			case 'e' : document.formularioEmail.submit(); break;
		}
	}
}

// Función al CANCELAR formulario o CERRAR video

var hayVideo = false;

function ocultarFlotante(){
	document.getElementById( 'fondoNegro' ).style.display = 'none';
	document.getElementById( 'formularioRecomienda' ).style.display = 'none';
	document.getElementById( 'formularioEmail' ).style.display = 'none';
	if( hayVideo ){
		document.getElementById( 'fichaVideo' ).style.display = 'none';
	}
	if( document.getElementById( 'tablaCalificacion' ) ){
		document.getElementById( 'tablaCalificacion' ).style.display = 'none';
	}
}

// Función para mostrar formulario, video o calificacion
function mostrarFlotante( tipo ){
	ocultarFlotante();
	document.getElementById( 'fondoNegro' ).style.display = 'block';
	switch( tipo ){
		case 'e' : document.getElementById( 'formularioEmail' ).style.display = 'block'; break; // EMail
		case 'r' : document.getElementById( 'formularioRecomienda' ).style.display = 'block'; break; // Recomienda
		case 'v' : document.getElementById( 'fichaVideo' ).style.display = 'block'; break; // Video
		case 'cal' : document.getElementById( 'tablaCalificacion' ).style.display = 'block'; break; // Calificacion
	}
}

// No mostramos el ContextMenu
document.oncontextmenu = new Function( "return false" );

window.focus();

function fOcultarListadoNombres(){}
function fFiltrarListadoNombres(){}

