﻿function enviar(){
if (document.main_form.firstname.value == ""){
        alert ("Debes introducir tu nombre.")
        document.main_form.firstname.focus()
        return (false)
    }

    // el nombre debe ser entre 1 y 3 palabras de minimo 2 letras
    var name_reg_exp = /^([a-zA-Zˆ‡ËçŽéƒ’ê˜—ñîœòŸ†•ìáéíóúàèìòù–„'-]{2,20}\s?){1,3}$/
    if(!document.main_form.firstname.value.match(name_reg_exp)) {
        alert ("Nombre incorrecto. Por favor, introdúcelo de nuevo.")
        document.main_form.firstname.focus()
        return (false)
    }

    if (document.main_form.lastname.value == ""){
        alert ("Debes introducir tus apellidos.")
        document.main_form.lastname.focus()
        return (false)
    }

    // los apellidos deben ser entre 1 y 4 palabras de entre 2 y 20 letras
    var apellido_reg_exp = /^([a-zA-Zˆ‡ËçŽéƒ’ê˜—ñîœòŸ†•ìáéíóúàèìòù–„'-]{2,20}\s?){1,4}$/
    if(!document.main_form.lastname.value.match(apellido_reg_exp)) {
        alert ("Apellidos incorrectos. Por favor, introdúcelo de nuevo.")
        document.main_form.lastname.focus()
        return (false)
    }

    if (document.main_form.email.value==""){
        alert ("Debes introducir tu correo electrónico.")
        document.main_form.email.focus()
        return (false)
    }

    var mail_reg_exp = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
    if(!document.main_form.email.value.match(mail_reg_exp)) {
        alert ("Dirección de correo electrónico incorrecta. Por favor, introdúcela de nuevo.")
        document.main_form.email.focus()
        return (false)
    }

    if (document.getElementById("segments_select[]").value==""){
        alert ("Debes seleccionar al menos una ciudad.")
        return (false)
    }

    if (document.main_form.password.value == ""){
        alert ("Debes introducir un password.")
        document.main_form.password.focus()
        return (false)
    }

    var pwd_reg_exp = /^[a-zA-Z0-9]{6,20}$/
    if(!document.main_form.password.value.match(pwd_reg_exp)) {
        alert ("Password incorrecto, debe estar formado por entre 6 y 20 caracteres que sean letras o números. Por favor, introdúcelo de nuevo.")
        document.main_form.password.focus()
        return (false)
    }

    if (document.main_form.confirmation.value == ""){
        alert ("Debes confirmar tu password.")
        document.main_form.confirmation.focus()
        return (false)
    }

    if (document.main_form.confirmation.value != document.main_form.password.value){
        alert ("El password de confirmación no es el mismo que tu password. Por favor, introdúcelo de nuevo.")
        document.main_form.confirmation.focus()
        return (false)
    }

    if( !document.main_form.accept_conditions.checked ) {
        alert( "Debes leer y aceptar las condiciones de uso." )
        return( false )
    }
    
    document.main_form.submit();
    return (true);
}

function popup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
