// JavaScript Document

//post: Comprobar si se han introducido datos
function validar_curso(){
	tipoIND = document.getElementById("crear-curso").tipo.selectedIndex;
	tipo = document.getElementById("crear-curso").tipo.options[tipoIND].value;
	nombre=document.getElementById("crear-curso").nombre.value;
	duracion=document.getElementById("crear-curso").duracion.value;
	precio=document.getElementById("crear-curso").precio.value;
	hayMens=false;
	msg="";
	if((duracion!="" && isNaN(duracion)) || (precio!="" && isNaN(precio))){
		msg="El valor de los siguientes campos no es adecuado:\n\n";
		hayMens=true;
		if (isNaN(duracion))	msg = msg + " - Duracion debe ser numerico.\n";
  		if (isNaN(precio))		msg = msg + " - Precio debe ser numerico.\n";				
	}
  	if(tipo=="" || nombre=="" || duracion=="" || precio==""){
		if(hayMens)	msg = msg + "\n\n"; 
		hayMens=true;
		msg = msg + "Los siguientes campos han de ser introducidos:\n\n";
		if(tipo == "")		msg = msg + " - Individual o completo.\n";
		if(nombre =="") 	msg = msg + " - Nombre.\n";		
		if(duracion =="") 	msg = msg + " - Duracion.\n";
		if(precio == "")	msg = msg + " - Precio.\n";
	}
	if(hayMens==true){
		alert(msg);
		return false;
	}
	return true;
}

//post: mirar si ha seleccionado algun calendario
function validar_cal_completo(f){
	var todos=false;
	var controles=document.getElementsByTagName('input');
	var nam;
	for(i=0; i<controles.length; i++){
		nam=controles[i].name;
		if(nam.substr(0,3)=="cal"){
			act=document.getElementById(nam).checked;
			todos=todos || act;
		}
	}
	return todos;
}

//validar formulario de contacto
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
   return (true)
  } else {
    return (false);
  }
}

//funcion para validar el formulario de casting
function validar_contacto(frm){
	nombre=document.getElementById(frm.name).nombre.value;
	mensaje=document.getElementById(frm.name).mensaje.value;
	email=document.getElementById(frm.name).email.value;
	if ((nombre=="" || nombre==null) || (mensaje=="" || mensaje==null) || (email=="" || email==null)) {
		 msg="Los siguientes campos han de ser introducidos:\n";		
	}
	if (nombre=="" || nombre==null){
		msg=msg + "   - Nombre del remitente.\n";		
	}
	if(email=="" || email==null){
		msg=msg + "   - Email.\n"; 
	}
	if (!validarEmail(email)){
		alert("El email introducido no es valido.");
		return false;
	}
	if (mensaje=="" || mensaje==null){
		msg=msg + "   - Mensaje.\n";		
	}
	if ((nombre=="" || nombre==null) || (mensaje=="" || mensaje==null) || (email=="" || email==null)) {
		alert(msg);
		return false;
	}
	return true;
}

function validar_calendario(frm){
	comentario=document.getElementById(frm.name).comentario.value;
	if(isNaN(comentario)){
		msg = " - Comentario debe ser numerico.\n";
		alert(msg);
		return false;		
	}
	return true;
}