var inscripcionTextos=["","Sólo Curso","Sólo Reunión","Curso y Reunión","Sólo Curso (Socios)","Sólo Reunión (Socios)","Curso y Reunión (Socios)","Sólo Curso (En formación)","Sólo Reunión (En formación)","Curso y Reunión (En formación)"];
var inscripcionPrecios;
var formaPagoTextos=["","Talón bancario","Transferencia bancaria","Tarjeta de Crédito"];
//var precioAcompanante=100;
var fechaPrecios2=new Date();
fechaPrecios2.setFullYear(2009,8,13);			// 13 de Septiembre de 2009
var fechaHoy=new Date();

	// Comprobar precios para antes o despues del 16 de Agosto
if (fechaHoy<fechaPrecios2)
{
	inscripcionPrecios=[0,200,320,420,120,230,270,100,180,210];
}
else
{
	inscripcionPrecios=[0,225,400,480,135,300,330,115,220,250];
}


function checkmail(email) {
           var reg = /^\w+([\.-]?\w*)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
           return (reg.exec(email)!=null);
}

function enviarformulario(){
	nombre=document.formRegistro.frmNombre.value;
	apellidos=document.formRegistro.frmApellidos.value;
	dni=document.formRegistro.frmDNI.value;
	telefono=document.formRegistro.frmTelefono.value;
	direccion=document.formRegistro.frmDireccion.value;
	poblacion=document.formRegistro.frmPoblacion.value;
	provincia=document.formRegistro.frmProvincia.value;
	codigopostal=document.formRegistro.frmCP.value;
	email=document.formRegistro.frmEMail.value;
	tipoInscripcion=getCheckedValue(document.formRegistro.frmTipoInscripcion);
	formaPago=getCheckedValue(document.formRegistro.frmFormaPago);
//	acompanante=document.formRegistro.frmAcompanante.checked;
	
	if(nombre=="" || apellidos=="" || telefono=="" || direccion=="" || poblacion=="" || provincia=="" || codigopostal==""){
		alert("Por favor rellene todos los campos\nmarcados con un asterisco.");
		return false;
	}
	if(tipoInscripcion==""){
		alert("Debe rellenar el tipo de inscripción.");
		return false;
	}
	if(formaPago==""){
		alert("Debe rellenar la forma de pago.");
		return false;
	}
	if(email.length>50){
		alert("El campo E-Mail no puede tener más de 50 caracteres.");
		return false;
	}
	if(email!=""){
		if(!checkmail(email)){
			alert("La dirección de email no es una dirección válida");
			return false;
		}
	}
	
//	if(acompanante){
//		if(tipoInscripcion==3 || tipoInscripcion==6){
//			alert("La inscripción para Estudiantes no puede incluir acompañante");
//			return false;
//		}
//	}

	total=CalcularTotal();
	var text="";
	text=text+"Estos son sus datos de inscripción:\n\n";
	text=text+"Tipo de inscripción: "+inscripcionTextos[tipoInscripcion]+" ("+inscripcionPrecios[tipoInscripcion]+" euros)\n";
//	if(acompanante)
//		text=text+"Cena con acompañante: "+" ("+precioAcompanante+" euros)\n";
	text=text+"\nTotal a Pagar: "+total+" euros\n";
	text=text+"(El pago se realizará por "+formaPagoTextos[formaPago]+")\n";
	text=text+"\nSi son correctos pulse Aceptar para confirmar la inscripción.\n";
	text=text+"Pulse Cancelar para corregirlos.\n\n";
	
	if(confirm(text))
	{
		document.formRegistro.frmFormaPagoTxt.value=formaPagoTextos[formaPago];
		document.formRegistro.frmTipoInscripcionTxt.value=inscripcionTextos[tipoInscripcion];
		document.formRegistro.submit();
	}
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

// http://www.somacon.com/p143.php

function CalcularTotal()
{
	formulario=document.formRegistro;
	tipoInscripcion=getCheckedValue(document.formRegistro.frmTipoInscripcion);
//	acompanante=document.formRegistro.frmAcompanante.checked;
	
	if(tipoInscripcion=="")
		return "Rellene Inscripción";

	total=inscripcionPrecios[tipoInscripcion];
	
//	if(acompanante)
//		total=total+precioAcompanante;
	
	document.formRegistro.frmTotalPagar.value=total;
	return total;		
			
}


