//Variable de GREYBOX donde están las imágenes
var GB_ROOT_DIR = './js/greybox/';

window.onload = function() 
{ 
	settings_redondeado = { 
			tl: { radius: 10 }, 
			tr: { radius: 10 }, 
			bl: { radius: 10 }, 
			br: { radius: 10 }, 
			antiAlias: true, 
			autoPad: false 
		};
	
	settings_no_redondeado = { 
			tl: { radius: 0 }, 
			tr: { radius: 0 }, 
			bl: { radius: 0 }, 
			br: { radius: 0 }, 
			antiAlias: true, 
			autoPad: false 
		};
	
	curvyCorners(settings_redondeado, document.getElementById("datos_personales"));
	curvyCorners(settings_redondeado, document.getElementById("buzon_personal"));
	curvyCorners(settings_redondeado, document.getElementById("nueva_edicion"));	
	curvyCorners(settings_redondeado, document.getElementById("fotos_partidos"));
	curvyCorners(settings_redondeado, document.getElementById("zona_administrador"));
};

function validarTelefono(ph) {  
	if (ph == null) {  
		return false;
	}
	var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");  
	return ((/\d{9,}/i).test(stripped));
}

// Longitud de caracteres máximo en un objecto
// onkeypress="return imposeMaxLength(this, 15);
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

// Repetidos de en 2 cadenas y se queda con los que también estén en la segunda de ellas
function devolverRepetidos(valores1,valores2) {
	var arr_1 = valores1.split(";");
	var arr_2 = valores2.split(";");
	var no_repetidos = [];
	var repetidos = [];
	var nr = 0;
	var r = 0;
	for(var i = 0; i < arr_1.length; i++){
		if(!($.inArray(arr_1[i],arr_2)!=-1)) {
			no_repetidos[nr++] = arr_1[i]; 
		} else{ 
			repetidos[r++] = arr_1[i];
		}
	}
	var devolver = '';
	for(var i = 0; i < repetidos.length; i++){
		devolver += repetidos[i];
		if (i < (repetidos.length-1)) devolver += ';';
	}
	return devolver;
}

// Elimina duplicados de un array
function uniqueArray( myArr ) {
	  var r = [];
	  o : for( var i = 0, n = myArr.length; i < n; i++ ){
	    for( var x = 0, y = r.length; x < y; x++ ){
	      if( r[ x ] == myArr[ i ] ){
	        continue o;
	      }
	    }
	    if( !!myArr[ i ] ) r[ r.length ] = myArr[ i ];
	  }
	  return r;
	}


	
// Recoge el texto interno de un componente label, span ...
function textoInterno(ide){
	el = document.getElementById(ide);
	hi = el.childNodes;
	l = hi.length;
	texto = '';
	for(m=0; m<l; m++){
		if(hi[m].nodeType == 3){
			texto += hi[m].nodeValue;
		}
		else{
			texto += hi[m].firstChild.nodeValue;
		}
	}
	
	return texto;
}

// Redirige a una página
function redirigir(url) { 
	location.href=url; 
} 

// Muestra una caja de texto
function mostrarAlert(titulo,texto) {
	titulo = "";	
	// Diferentes estilos
// Sexy.alert('<h1>SexyAlertBox</h1><em>versión 1.2</em><br/><p>No te olvides de
// visitar <a href=\'http://www.coders.me/\'>www.coders.me</a> está lleno de
// artículos de programación.</p>');
// Sexy.info('<h1>SexyAlertBox</h1><em>versión 1.2</em><br/><p>&copy;2008-2009
// Todos los derechos reservados.</p><p>Sexy Alert Box está basado en
// PBBAcpBox.</p><p>Visita <a href=\'http://www.coders.me/\'>www.coders.me</a>
// para obtener la última versión de este script.</p>');
// Sexy.error('<h1>Error al intentar entrar al sistema</h1><p>Inténtalo de
// nuevo.</p>')
// Sexy.confirm('<h1>Error al intentar entrar al sistema</h1><p>Inténtalo de
// nuevo.</p>')
// Sexy.prompt('<h1>Error al intentar entrar al sistema</h1><p>Inténtalo de
// nuevo.</p>')
	Sexy.info('<h1 style="text-align:center;font-size:14pt;">'+titulo+'</h1><br/><br/><p>'+texto+'</p>');
}

function popUp(URL, ancho, alto) {
	if (ancho == null) ancho = 900;
	if (alto == null) alto = 750;
	var der = (screen.width - ancho) / 2;
	var sup = (screen.height - alto) / 2;
	var propiedades = "menubars=no,toolbars=no,scrollbars=1,width="+ancho+",height="+alto+",top=" + sup + ",left=" + der;
	window.open(URL, "win", propiedades);
}

function validar_correo(valor) {
	if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/
			.test(valor)) {
		return (true);
	} else {
		return (false);
	}
}

function rotarImagenTiendaIndex() {
	$('#banner_tienda_index').cycle({ 
		fx: 'scrollLeft',
// fx: 'scrollUp',
// fx: 'fade',
	    speed:   800, 
	    timeout: 5000, 
	    next:   'banner_tienda_index', 
	    pause:   1 
	});
}

function rotarImagenTiendaContacto() {
	$('#banner_tienda_contacto').cycle({ 
		fx:     'fade', 
	    speed:   1000, 
	    timeout: 5000, 
	    next:   'banner_tienda_contacto', 
	    pause:   1 
	});
}

function rotarImagenTiendaResultados() {
	$('#banner_tienda_resultados').cycle({ 
		fx:     'fade', 
	    speed:   1000, 
	    timeout: 5000, 
	    next:   'banner_tienda_resultados', 
	    pause:   1 
	});
}

/*
 * Valida una fecha del tipo dd/mm/yyyy hh:mm
 */
function validarFecha(strFecha) {
	try {
		if (strFecha.length != 16) {
			return false;
		}
		// Obtención de los componentes
		var compFechaHora = strFecha.split(" ");
		var compFecha = compFechaHora[0].split("/");
		var compHora = compFechaHora[1].split(":");
		var dia = parseInt( compFecha[0], 10);
		var mes = parseInt( compFecha[1], 10)-1;
		var anio = parseInt( compFecha[2], 10);
		var hora = parseInt( compHora[0], 10);
		var minuto = parseInt( compHora[1], 10);
		var segundo = parseInt('00');
		var objFecha = new Date( anio, mes, dia, hora, minuto, segundo );
		// Ahora que tengo todos los componentes y el objFecha, paso a la comprobación
		var fechaCorrecta = ( dia == objFecha.getDate() );
		fechaCorrecta = fechaCorrecta && ( mes == objFecha.getMonth() );
		fechaCorrecta = fechaCorrecta && ( anio == objFecha.getFullYear() );
		fechaCorrecta = fechaCorrecta && ( hora == objFecha.getHours() );
		fechaCorrecta = fechaCorrecta && ( minuto == objFecha.getMinutes() );
		fechaCorrecta = fechaCorrecta && ( segundo == objFecha.getSeconds() );
	} catch (e) {
		return false;
	}

	return true;    
}

