	function cambiarValores()
	{
		var option1 = document.getElementById('option1');
		var option2 = document.getElementById('option2');
		//var url_id= top.document.referrer;
		var url_id = parent.ReferringUrl;
		//alert("pre: " + url_id);   //está ok
		//alert("url_id = " + url_id);
		if(url_id=='')
		{
			option1.style.display ='block';
			option2.style.display ='none';
		}
		else
		{
			option2.style.display ='block';
			option1.style.display ='none';

			if (url_id=='grupospr')	// www.grupospr.net
			{
//						form1.selectconocer.selectedIndex = 0;
				form1.selectconocer.value = "grupospr";
			}
			else if (url_id=='mkmpi')	// www.mkm-pi.com
			{
//						form1.selectconocer.selectedIndex = 1;
				form1.selectconocer.value = "mkmpi";
			}
			else if (url_id=='ruralgest')	// www.ruralgest.net
			{
//						form1.selectconocer.selectedIndex = 2;
				form1.selectconocer.value = "ruralgest";
			}
			else if (url_id=='sage')	// www.sageformacion.es
			{
//						form1.selectconocer.selectedIndex = 3;
				form1.selectconocer.value = "sage";
			}
			else if (url_id=='elcorteingles')
			{
//						form1.selectconocer.selectedIndex = 4;
				form1.selectconocer.value = "elcorteingles";
			}
			else if (url_id=='educaterra')
			{
//						form1.selectconocer.selectedIndex = 6;
				form1.selectconocer.value = "educaterra";
			}
			else if (url_id=='csica')
			{
//						form1.selectconocer.selectedIndex = 7;
				form1.selectconocer.value = "csica";
			}
			else if (url_id=='cedeco')
			{
//						form1.selectconocer.selectedIndex = 8;
				form1.selectconocer.value = "cedeco";
			}
			else if (url_id=='trescantos')
			{
//						form1.selectconocer.selectedIndex = 9;
				form1.selectconocer.value = "trescantos";
			}
			else if (url_id=='camporeal')
			{
//						form1.selectconocer.selectedIndex = 10;
				form1.selectconocer.value = "camporeal";
			}
			else if (url_id=='tecniberia')
			{
//						form1.selectconocer.selectedIndex = 11;
				form1.selectconocer.value = "TECNIBERIA";
			}
			else if (url_id=='asimelec')
			{
//						form1.selectconocer.selectedIndex = 12;
				form1.selectconocer.value = "ASIMELEC";
			}
			else
			{
//						form1.selectconocer.selectedIndex = 5;
				form1.selectconocer.value = "GARBEN";
			}
		}
	}
	function pedirDatos()
	{
		if (document.form1.check_lopd != null && document.form1.check_lopd.checked == false)
		{
			alert("Debe consentir el tratamiento de datos conforme al aviso legal LOPD.");
			return false;
		}
		if (test(document.form1))
		{
			document.form1.submit();
		}
	}
	function CompruebaCif(elCIF)
	{
		var resul = false;
		// pasar a mayúsculas
		var temp = elCIF.toUpperCase();
		if (!/^[A-Za-z0-9]{9}$/.test(temp)) // Son 9 dígitos?
			return false;
		else if (!/^[ABCDEFGHKLMNPQS]/.test(temp))
			return false;
		else
			resul = true;
		return resul;
	}
  // La función recibe el CIF completo: A58818501
	function ValidaCIF(elCIF)
	{
		var pares = 0;
		var impares = 0;
		var suma;
		var ultima;
		var unumero;
		var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
		var xxx;
		var texto = "";
		texto = elCIF;
		texto = texto.toUpperCase();
		var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g;
		if (!regular.exec(texto))
			return false;
		ultima = texto.substr(8,1);
		for (var cont = 1 ; cont < 7 ; cont ++)
		{
			xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
			impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
			pares += parseInt(texto.substr(cont,1));
		}
		xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
		impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
		suma = (pares + impares).toString();
		unumero = parseInt(suma.substr(suma.length - 1, 1));
		unumero = (10 - unumero).toString();
		if(unumero == 10)
			unumero = 0;
		if ((ultima == unumero) || (ultima == uletra[unumero]))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	function fncActivarCampos(strEstado)
	{
		var activar, color;
		if(strEstado == "desactivar")
		{
			activar = false;
			color = "#FFFFFF";
		}
		else
		{
			activar = true;
			color = "#e0e0e0";
		}
		document.form1.txtNombreEmpresa.disabled = activar;
		document.form1.txtCif.disabled = activar;
		document.form1.selectTamanio.disabled = activar;
		document.form1.txtPersonaContacto.disabled = activar;
		document.form1.txtDireccionEmp.disabled = activar;
		document.form1.txtPoblacionEmp.disabled = activar;
		document.form1.txtProvinciaEmp.disabled = activar;
		document.form1.txtCodPostalEmp.disabled = activar;
		document.form1.txtTelefonoFijoEmp.disabled = activar;
		document.form1.txtTelefonoMovilEmp.disabled = activar;
		document.form1.txtFaxEmp.disabled = activar;
		document.form1.txtEmailEmp.disabled = activar;
		document.getElementById('txtNombreEmpresa').style.background  = color;
		document.getElementById('txtCif').style.background  = color;
		document.getElementById('selectTamanio').style.background  = color;
		document.getElementById('txtPersonaContacto').style.background  = color;
		document.getElementById('txtDireccionEmp').style.background  = color;
		document.getElementById('txtPoblacionEmp').style.background  = color;
		document.getElementById('txtProvinciaEmp').style.background = color;
		document.getElementById('txtCodPostalEmp').style.background = color;
		document.getElementById('txtTelefonoFijoEmp').style.background = color;
		document.getElementById('txtTelefonoMovilEmp').style.background = color;
		document.getElementById('txtFaxEmp').style.background = color;
		document.getElementById('txtEmailEmp').style.background = color;
	}
	function validaEmpleado(form)
	{
		var expr5 = /[0-9]{5}/;
		var expr9 = /[0-9]{9}/;
		var error = "";
		if (form.txtNombreEmpresa.value == "")
		{
			error += "\tNombre de empresa vacío.\n";
		}
		if (form.txtCif.value == "")
		{
			error += "\tC.I.F. vacío.\n";
		}
		else
		{
			if(!ValidaCIF(form.txtCif.value) || !CompruebaCif(form.txtCif.value))
			{
				error +="\tC.I.F. no válido.\n";
			}
		}
		if (form.selectTamanio.selectedIndex == 0)
		{
			error += "\tTamaño de empresa vacío.\n";
		}
		if (form.txtPersonaContacto.value == "")
		{
			error += "\tPersona de contacto vacío.\n";
		}
		if (form.txtDireccionEmp.value == "")
		{
			error += "\tDirección vacía.\n";
		}
		if (form.txtPoblacionEmp.value == "")
		{
			error += "\tPoblación vacía.\n";
		}
		if (form.txtProvinciaEmp.value == "")
		{
			error += "\tProvincia vacía.\n";
		}
		if (form.txtCodPostalEmp.value == "")
		{
			error += "\tCódigo postal vacío.\n";
		}
		else if (!expr5.test(form.txtCodPostalEmp.value))
		{
			error += "\tCódigo postal no válido.\n"
		}
		if (form.txtTelefonoFijoEmp.value == "")
		{
			error += "\tTeléfono fijo vacío.\n";
		}
		else if (!expr9.test(form.txtTelefonoFijoEmp.value))
		{
			error += "\tTeléfono fijo no válido.\n"
		}
		if (form.txtTelefonoMovilEmp.value != "" && !expr9.test(form.txtTelefonoMovilEmp.value))
		{
			error += "\tTeléfono móvil no válido.\n"
		}
		if (form.txtFaxEmp.value != "" && !expr9.test(form.txtFaxEmp.value))
		{
			error += "\tFax no válido.\n"
		}
		if (form.txtEmailEmp.value != "" && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.txtEmailEmp.value)))
		{
			error += "\tE-mail incorrecto.\n";
		}
		if (error != "")
		{
			error = "\nDatos Profesionales:\n" + error;
		}
		return error;
	}
	function test(form)
	{
		var Error = "";
		var aux = "";
		var expr5 = /[0-9]{5}/;
		var expr9 = /[0-9]{9}/;
		var autonomo = document.getElementById("tipoProfesionalA").checked;
		var letras = "TRWAGMYFPDXBNJZSQVHLCKE";
		var letraDni, letraAux, numero;
		var nif = form.nif.value;

		//DATOS PROFESIONALES
		aux = "";
		if (autonomo == false)
		{
			aux = validaEmpleado(form);
			if (aux != "")
				Error +=  aux;
		}
		//DATOS PERSONALES
		aux = "";
		if (form.apellido1.value =="")
		{
			aux += "\tPrimer apellido vacío.\n";
		}
		if (form.apellido2.value =="")
		{
			aux += "\tSegundo apellido vacío.\n";
		}
		if (form.nombre.value =="")
		{
			aux += "\tNombre vacío.\n";
		}
		if(nif != "")
		{
			if((nif.substring(0,1) != "x") && (nif.substring(0,1) != "X") && (nif.substring(0,1) != " "))
			{
				if(nif.length != 9)
				{
					aux += "\tEl NIF debe estar formado por 9 caracteres.\n";
				}
				else
				{
					letranif = nif.substring(8);
					nif = nif.substring(0,8);
					if(isNaN(letranif))
					{
						numero = nif % 23;
						letraAux = letras.substring(numero,numero+1);
						if(letraAux == letranif.toUpperCase())
						{
						}
						else
						{
							aux += "\tEl NIF especificado no es válido.\n";
						}
					}
					else
					{
						aux += "\tEl último caracter del NIF debe ser una letra.\n";
					}
				}
			}
			else
			{
			}
		}
		else
		{
			aux += "\tEl NIF no puede estar vacío.\n";
		}
		if (form.email.value == "")
		{
			aux += "\tE-mail vacío.\n";
		}
		else if (! (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value)))
		{
			aux += "\tE-mail incorrecto.\n";
		}
		if (form.selectSexo.value == "")
		{
			aux += "\tDebe seleccionar un sexo.\n";
		}
		if (form.selectEdad.value == "")
		{
			aux += "\tDebe seleccionar una edad.\n";
		}
		if (aux != "")
			Error += "\nDatos personales:\n" + aux;
		//DOMICILIO PARTICULAR
		aux = "";
		if (form.domicilio.value == "")
		{
			aux += "\tDirección vacío.\n";
		}
		if (form.poblacion.value == "")
		{
			aux += "\tPoblación vacío.\n";
		}
		if (form.codigo_postal.value == "")
		{
			aux += "\tCódigo Postal vacío.\n";
		}
		if (form.provincia.value == "")
		{
			aux += "\tProvincia vacía.\n";
		}
		else if( !expr5.test(form.codigo_postal.value))
		{
			aux += "\tCódigo Postal no válido.\n";
		}
		if (form.telefono_fijo.value == "")
		{
			aux += "\tTelefono fijo vacío.\n";
		}
		else if( !expr9.test(form.telefono_fijo.value))
		{
			aux += "\tTelefono fijo no válido.\n";
		}
		if(form.telefono_movil.value != "" && !expr9.test(form.telefono_movil.value))
		{
			aux += "\tTelefono movil no válido.\n";
		}
		if (aux != "")
			Error += "\nDomicilio particular:\n" + aux;
		//FORMACION Y SITUACION PROFESIONAL
		aux = "";
		if (form.selectFormacion.value=="")
		{
			aux += "\tFormación no seleccionada.\n";
		}
		if (form.selectTipoContrato.value=="")
		{
			aux += "\tTipo de contrato no seleccionado.\n";
		}
		if (form.selectCategoriaProfesional.value=="")
		{
			aux += "\tCategoría profesional no seleccionada.\n";
		}
		if (aux != "")
			Error += "\nFormación y situación profesional:\n" + aux;
		//CURSOS
		aux = "";
		if (form.selectCurso1.value=="" && form.selectCurso2.value=="" && form.selectCurso3.value=="" && form.selectCurso4.value=="")
		{
			aux += "\tDebe de elegir al menos un curso.\n";
		}
		if (form.selectconocer != null && form.selectconocer.value=="")
		{
			aux += "\tDebe indicar cómo conoció los cursos.\n";
		}
		if (aux != "")
			Error += "Cursos:\n" + aux;
		
		if (document.getElementById("check_lopd") != null && !document.getElementById("check_lopd").checked)
		{
			Error += "\nDebe aceptar las condiciones legales.\n";
		}
		var result = false;
		if (!Error)
		{
			result = true;
		}
		else
		{
			alert(Error);
		}
		return result;
	}
	function es_numero(cadena)
	{
		for (i = 0; i < cadena.length; i++)
		{
			ch = cadena.substring(i, i+1);
			if (ch < "0"|| ch > "9")
				return 0;
		}
		return 1;
	}
