function concurso() {
	var width = 530;
	var height = 700;
	var xPos = (screen.width - width) / 2; 
	var yPos = (screen.height - height) / 2; 
	var url = "/concurso/maravillas.php";

	var newWin = window.open(url, "info", "left=" + xPos + ",top=" + yPos + ",width=" + width + ",height=" + height);
	newWin.focus();
}


function check_maravilla(form) {
	var otro = trim(form.otro_sitio.value);
	if (form.maravilla.value == 0 && otro == "")  {
		alert("Por favor, seleccione una maravilla o escriba otra propuesta");
		form.maravilla.focus();
		return false;
	}
	
	if (isBlank(form.nombre, "Introduzca su nombre")) { return false; }
	if (isBlank(form.email, "Introduzca su email")) { return false; }
	if (!isValidAddress(form.email.value)) {
		alert("Su email no parece válido");
		form.email.focus();
		form.email.select();
		return false;
	}
	
	return true;
}

// Removes leading whitespaces
function LTrim(value) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim(value) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value) {
	return LTrim(RTrim(value));
}

function isBlank(obj, message) {
	if (obj.value == "") {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isBlankNoFocus(obj, message) {
	if (obj.value == "") {
		alert(message);
		return true;
	}
	
	return false;
}

function isValue(obj, value, message) {
	if (obj.value == value) {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isValidAddress(addr) {
	index1 = addr.indexOf("@");
	if (index1 <= 0) {
		return false;
	}
	index2 = addr.indexOf(".", index1);
	if (index2 < index1) {
		return false;
	}
	
	//must be at least a period and 2 characters at the end
	if (index2 == addr.length-1 || index2 == addr.length-2) {
		return false;
	}
	return true;
}
