var cursos=new Array();

cursos["EMBA"]="EXECUTIVE MBA LA SALLE";
cursos["MBAFT"]="INTERNACIONAL LA SALLE PART TIME";
cursos["MBAPT"]="INTERNACIONAL LA SALLE FULL TIME";
cursos["MBAOL"]="INTERNACIONAL ONLINE";
cursos["MEB"]="MASTER IN E-BUSSINESS";
cursos["MIB"]="MASTER IN INTERNACIONAL E-BUSSINESS";
cursos["MGTI"]="MÁSTER EN GESTIÓN DE LAS TECNOLOGÍAS DE LA INFORMACIÓN";
cursos["EMSG"]="MÁSTER EN SOFTWARE DE GESTIÓN DE EMPRESA SAP R/3";
cursos["MGET"]="MÁSTER EN GESTIÓN DE EMPRESAS DE TELECOMUNICACIÓN";
cursos["MGM"]="MÁSTER IN GLOBAL MARKETING";
cursos["CSDM"]="CURSO SUPERIOR DE DIRECCIÓN DE MARKETING Y GESTIÓN COMERCIAL";
cursos["MSCMT"]="MASTER IN SUPPLY CHAIN MANAGEMENT AND TECHNOLOGY";
cursos["MFM"]="MÁSTER IN FACILITIES MANAGEMENT";
cursos["MEC@"]="MÁSTER EN ENTORNO Y CALIDAD AMBIENTAL";
cursos["MPM"]="MASTER IN PROJECT MANAGEMENT";
cursos["MDTIC"]="MÁSTER EN DERECHO Y TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN";
cursos["MXST"]="MÁSTER EN REDES Y SERVICIOS DE LA TELECOMUNICACIÓN";
cursos["MSTI"]="MÁSTER EN SEGURIDAD DE LAS TECNOLOGÍAS DE LA INFORMACIÓN";
cursos["MTVD"]="MÁSTER EN TELEVISIÓN DIGITAL";
cursos["MIT"]="POSTGRADO EN INFRAESTRUCTURAS DE TELECOMUNICACIONES";
cursos["MDPM"]="MÁSTER EN DISEÑO Y PRODUCCIÓN DE CONTENIDOS MULTIMEDIA";
cursos["MLG"]="MÁSTER EN e-LEARNING";
cursos["MGA3D"]="MÁSTER EN GUIÓN Y ANIMACIÓN 3D";
cursos["MCPAD"]="MÁSTER EN COMUNICACIÓN Y PRODUCCIÓN AUDIOVISUAL DIGITAL";
cursos["MAPSAD"]="MÁSTER EN PRODUCCIÓN SONORA Y AUDIO DIGITAL";
cursos["MCAD"]="MÁSTER EN NUEVAS TECNOLOGÍAS CAD APLICADAS A LA ARQUITECTURA Y A LA CONSTRUCCIÓN";
cursos["MAAM"]="MÁSTER EN ACÚSTICA ARQUITECTÓNICA Y MEDIO AMBIENTAL";
cursos["MCEAS"]="MÁSTER EN CONTROL DE EDIFICIOS Y ARQUITECTURA SOSTENIBLE";
cursos["MMC"]="MÁSTER EN MANAGEMENT DE LA CONSRUCCIÓN";

function Comprobar_formulario() {
//******* COMPROBACION DE LOS MASTERS SELECCIONADOS ******
	master1 = document.form_master.select_master1.value;
	master2 = document.form_master.select_master2.value;
	tots_masters = document.form_master.checkbox_tots_masters.checked;
	if ((master1=='null') && (master2=='null') && (tots_masters==false))
	{
		alert("Ha de seleccionar uno o dos másters, en caso de querer más información seleccione 'Todos los másters'.");
		document.form_master.select_master1.focus();
		return false;
	}
//********* COMPROBACIÓN DEL CAMPUS **************
	campus = document.form_master.select_campus.value;
	if (campus == '0')
	{
		alert("Ha de seleccionar un Campus.");
		document.form_master.select_campus.focus();
		return false;
	}

//******* COMPROBACION DE LOS DATOS PERSONALES ******
	cognom1 = document.form_master.textfield_cognom1.value;
	if (cognom1.length == 0) {
		alert("Sus apellidos son un dato obligado. Si pone más de uno sepárelos con un espacio.");
		document.form_master.textfield_cognom1.focus();
		return false;
	}
	nombre = document.form_master.textfield_nom.value;
	if (nombre.length == 0) {
		alert("Su nombre es un dato obligado. En el caso de ser un nombre compuesto separe los nombres con un espacio.");
		document.form_master.textfield_nom.focus();
		return false;
	}
	edad = document.form_master.textfield_edat.value;
	regExp_edad = /^\d[0-9]?$/;
	if (!(regExp_edad.test(edad))) {
		alert("La edad es un dato obligado.");
		document.form_master.textfield_edat.focus();
		return false;
	}
	if (edad <= 0){
		alert ("La edad ha de ser mayor que 0");
		document.form_master.textfield_edat.focus();
		return false;
	}

	titulacion = document.form_master.textfield_titulacio.value;
	if (titulacion.length == 0) {
		alert("La titulación es un dato obligado.");
		document.form_master.textfield_titulacio.focus();
		return false;
	}
	h_m = document.form_master.textfield_h_d.value;
	if (h_m != 'H' && h_m != 'M' && h_m != 'h' && h_m != 'm') {
		alert("El valor del campo H/M(Hombre/Mujer) ha de contener uno de los siguientes carácteres 'H,h,M,m'.");
		document.form_master.textfield_h_d.focus();
		return false;
	}
	telf = document.form_master.textfield_telf.value;
	regExp_telf = /^\d+$/;

	if ((telf.length != 0) && (!(regExp_telf.test(telf)))) {
		alert("Introduzca su teléfono correctamente. Introduzca sólo números.");
		document.form_master.textfield_telf.focus();
		return false;
	}

	telf2 = document.form_master.textfield_telf2.value;
	regExp_telf2 = /^\d+$/;
	if ((telf2.length != 0) && (!(regExp_telf2.test(telf2)))) {
		alert("Introduzca su teléfono correctamente. Introduzca sólo números.");
		document.form_master.textfield_telf2.focus();
		return false;
	}

	if (document.form_master.textfield_domicili_particular.value.length == 0){
		alert("Introduzca su domicilio.");
		document.form_master.textfield_domicili_particular.focus();
		return false;
	}

	if (document.form_master.textfield_ciutat_particular.value.length == 0){
		alert("Introduzca la ciudad particular.");
		document.form_master.textfield_ciutat_particular.focus();
		return false;
	}

	cod_postal = document.form_master.textfield_codigo_postal.value;
	regExp_cod_post = /^\d+$/;
	if ((cod_postal.length != 0) && (!(regExp_cod_post.test(cod_postal)))) {
		alert("Introduzca su Código Postal correctamente. Introduzca sólo números.");
		document.form_master.textfield_codigo_postal.focus();
		return false;
	}

	if (document.form_master.select_pais_particular.value.length == 0){
		alert("Introduzca el pais.");
		document.form_master.select_pais_particular.focus();
		return false;
	}

	if (!(validacion_e_mail(document.form_master.textfield_e_mail_particular))) {
		document.form_master.textfield_e_mail_particular.focus();
		return false;
	}

	if (document.form_master.select_trabajo.value == "si"){
		if (document.form_master.textfield_ciutat_empresa.value.length == 0){
			alert("Introduzca la ciudad de la empresa.");
			document.form_master.textfield_ciutat_empresa.focus();
			return false;
		}
	}

//********** DEVUELVE TRUE EN EL CASO QUE LOS DATOS SEAN CORRECTOS ***********

	return true;
}


function validacion_e_mail(elemento) {
    if(elemento.value.length == 0) {
      elemento.focus();
      alert("Por favor introduzca su dirección de correo.");
      return false;
      }
    if(-1 == elemento.value.indexOf("@")) {
       elemento.focus();
       alert("Su dirección de correo debe contener '@'.");
       return false;
       }
    if(-1 != elemento.value.indexOf(",")) {
       elemento.focus();
       alert("Su dirección de correo no debe contener ','.");
       return false;
       }
    if(-1 != elemento.value.indexOf("#")) {
       elemento.focus();
       alert("Su dirección de correo no debe contener '#'." );
       return false;
       }
    if(-1 != elemento.value.indexOf("!")) {
       elemento.focus();
       alert("Su dirección de correo no debe contener '!'." );
       return false;
       }
    if(-1 != elemento.value.indexOf(" ")) {
       elemento.focus();
       alert("Su dirección de correo no debe contener espacios." );
       return false;
       }
    if(elemento.value.length == (elemento.value.indexOf("@")+1) ) {
      elemento.focus();
      alert("Su dirección de correo no debe contener un dominio detras de '@'.");
      return false;
      }
    return true;
}

function Trabajo() {
	if (document.form_master.select_trabajo.value == "no") {
		document.form_master.textfield_domicili_empresa.value = "-disabled-";
		document.form_master.textfield_domicili_empresa.disabled = true;
		document.form_master.select_pais_empresa.value = "-disabled-";
		document.form_master.select_pais_empresa.disabled = true;
		document.form_master.textfield_ciutat_empresa.value = "-disabled-";
		document.form_master.textfield_ciutat_empresa.disabled = true;
		document.form_master.textfield_web_empresa.value = "disbaled";
		document.form_master.textfield_web_empresa.disabled = true;
		document.form_master.textfield_empresa.value = "-disabled-";
		document.form_master.textfield_empresa.disabled = true;
		document.form_master.textfield_cargo_empresa.value = "-disabled-";
		document.form_master.textfield_cargo_empresa.disabled = true;
		document.form_master.textfield_dep_empresa.value = "-disabled-";
		document.form_master.textfield_dep_empresa.disabled = true;
		document.form_master.textfield_codigo_postal_empresa.value = "-disabled-";
		document.form_master.textfield_codigo_postal_empresa.disabled = true;
	}else{
		document.form_master.textfield_domicili_empresa.value = "";
		document.form_master.textfield_domicili_empresa.disabled = false;
		document.form_master.select_pais_empresa.value = "";
		document.form_master.select_pais_empresa.disabled = false;
		document.form_master.textfield_ciutat_empresa.value = "";
		document.form_master.textfield_ciutat_empresa.disabled = false;
		document.form_master.textfield_web_empresa.value = "";
		document.form_master.textfield_web_empresa.disabled = false;
		document.form_master.textfield_empresa.value = "";
		document.form_master.textfield_empresa.disabled = false;
		document.form_master.textfield_cargo_empresa.value = "";
		document.form_master.textfield_cargo_empresa.disabled = false;
		document.form_master.textfield_dep_empresa.value = "";
		document.form_master.textfield_dep_empresa.disabled = false;
		document.form_master.textfield_codigo_postal_empresa.value = "";
		document.form_master.textfield_codigo_postal_empresa.disabled = false;
	}
}

function NombreCompletoMasters1(queSelect) { //v3.0
	switch (queSelect.selectedIndex) {
		case 0:
		if (document.form_master.checkbox_tots_masters.value == "checked") {
			document.form_master.textfield_NombreCompleto.value = 'Todos los Masters';
		}else{
			if ((document.form_master.select_campus.value == 4)||(document.form_master.select_campus.value == 5)){
				document.form_master.select_master2.selectedIndex = 1;
				document.form_master.textfield_NombreCompleto.value = "e-MBA. Executive MBA";
			}else{
				document.form_master.textfield_NombreCompleto.value = 'Ningún master seleccionado';
			}
		}
		break;
		default:
			if (queSelect.name=="select_master1")
			{
				document.form_master.textfield_NombreCompleto.value = cursos[queSelect[queSelect.selectedIndex].value];
			}else{
				document.form_master.textfield_NombreCompleto2.value = cursos[queSelect[queSelect.selectedIndex].value];
			}
		break;
	}
}

function EvaluaCampus (){
	if ((document.form_master.select_campus.value == 4)||(document.form_master.select_campus.value == 5)){
		document.form_master.checkbox_tots_masters.disabled = true;
		document.form_master.textfield_NombreCompleto.value = "e-MBA. Executive MBA";
		document.form_master.textfield_NombreCompleto2.value = "e-MBA. Executive MBA";
		document.form_master.select_master1.value = "e-MBA";
		document.form_master.select_master2.value = "e-MBA";
		document.form_master.select_master2.selectedIndex = 1;
		document.form_master.select_master1.selectedIndex = 1;
	}else{
		document.form_master.checkbox_tots_masters.disabled = false;
	}
}

var activeMaster=1;

function setMaster(nombreMaster)
{
	queSelect=document.form_master.select_master1;
   	if(activeMaster==1)
   	{
   	 	queSelect=document.form_master.select_master1;
   	 	donde=document.form_master.textfield_NombreCompleto;
   	 	activeMaster=2;
   	}else{
   		queSelect=document.form_master.select_master2;
   		donde=document.form_master.textfield_NombreCompleto2;
      	activeMaster=1;
   	}
   
   	donde.value = cursos[nombreMaster];
   	for (i=0;i < queSelect.length;i++)
   	{
   		if (queSelect[i].value==nombreMaster)
   		{
   		 	queSelect.selectedIndex=i;
      		break;
   		}
   	}
    
   
   
   
   
   
}

function todosMasters()
{
	if (document.form_master.checkbox_tots_masters.value == "checked") {
		document.form_master.checkbox_tots_masters.value = "unchecked";
			NombreCompletoMasters1(document.form_master.select_master1);
			NombreCompletoMasters1(document.form_master.select_master2);
	}else{
		document.form_master.checkbox_tots_masters.value = "checked";
		document.form_master.textfield_NombreCompleto.value = 'Todos los Masters';
		document.form_master.textfield_NombreCompleto2.value = 'Todos los Masters';
	}
}