/*
 * 
 * Function Code:#121
 *
 *	Funcion que setear el width a todos los elemmentos hijos de una clase 
 *	apartir de la cantidad de elementos
 *
 *	@param classID string El nombre de la clase
 *	@return void.
 */
function setWidth(classId){

	//width total del container
	var width_container = $('.' + classId).width();
	
	//cuento la cantidad de secciones/tabs
	var cant = $('.' + classId +' li').size();
	
	//calculo el width optimo para los tabs
	var width = Math.round((width_container/cant) -1);
	
	//me fijo los paddings de los tabs
	var pleft = parseInt($('.' + classId + ' li').css('padding-left'));
	var pright = parseInt($('.' + classId + ' li').css('padding-right'));

	//le resto paddings
	width = (width - (pleft + pright));
	
	//seteo el width de las secciones/tabs
	$('.' + classId + ' li').css('width',width);
	
}

function addFavoritos() {

	if (window.sidebar && window.sidebar.addPanel)
		window.sidebar.addPanel("bingo.es - Tu revista de bingo online", "http://www.bingo.es", "");
	else
		window.external.AddFavorite("http://www.bingo.es", "bingo.es - Tu revista de bingo online");

}

function addFavorites() {

	if (window.sidebar && window.sidebar.addPanel)
		window.sidebar.addPanel("bingo.es - Source for online bingo games", "http://www.bingo.es", "");
	else
		window.external.AddFavorite("http://www.bingo.es", "bingo.es - Source for online bingo games");

}

function apuntarseBoletin() {

	var email = document.getElementById('email').value;
	var boletin = document.getElementById('boletin').value;
	
	if ((! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		alert('El email indicado no es válido. Debes escribir un email válido.');
		return false;
	}

	//loadingPanel.show();
	//xajax_obtenerCodigo(imei);

	boletin.submit();
		
	return true;	
}

function apuntarseBoletin_en() {

	var email = document.getElementById('email').value;
	var boletin = document.getElementById('boletin').value;
	
	if ((! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		alert('Please fill in a valid e-mail address.');
		return false;
	}

	//loadingPanel.show();
	//xajax_obtenerCodigo(imei);

	boletin.submit();
		
	return true;	
}

function enviarConsulta() {

	var email = document.getElementById('emailContacto').value;
	var nombre = document.getElementById('nombre').value;
	var mensaje = document.getElementById('mensaje').value;
	var enviarConsulta = document.getElementById('contacto').value;
	var error = '';
		
	if (nombre == '') {
		error = "- No has escrito ningún nombre.\n";
	}
	if ((! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		error = error+"- El email indicado no es válido. Debes escribir un email válido.\n";
	}
	if (mensaje == '') {
		error = error+"- No has escrito ningún mensaje.\n";
	}

	if (error.length > 0) {
		alert("Por favor, comprueba los siguientes errores y corrige el formulario:\n\n" + error);
		return false;
	}
	
	enviarConsulta.submit();
		
	return true;
	
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var link = anchor.getAttribute("href"); 
		var linkRelativo = link.replace(/http:\/\/www\.bingo\.es/, "");
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "nofollow" && ((/^\/jugar\/[^\/]+\/$/i.test(linkRelativo)))) {
			anchor.target = "_blank";
		}
		
	}
}
