function MostrarCuerpo(){
	document.getElementById("cuerpo").style.display="";
	FocusFirstItem();
}

function FocusFirstItem(){
	document.Form.refoferta.focus();
}

function valEmail(valor){  // función para validar formato email correcto
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

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 "";
}


function validaForm(){

d = document.Form;

//*********************************






//*********************************


var er_codpostal = /^([0-9])*$/
var er_cont_tel = /^([0-9])*$/
var er_fecha = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

//***** APARTADO 1 ******

if (d.rsocial.value == "") {
	alert("Debe indicar la/s razon/es sociales");
	d.rsocial.focus();
	return false;
}

if (d.dsocial.value == "") {
	alert("Debe indicar el domicilio social");
	d.dsocial.focus();
	return false;
}

if (d.localidad.value == "") {
	alert("Debe indicar la localidad");
	d.localidad.focus();
	return false;
}

if (d.codpostal.value == "") {
	alert("Debe indicar el código postal");
	d.codpostal.focus();
	return false;
}

if(!er_codpostal.test(d.codpostal.value)){
	alert("Código Postal incorrecto");
	d.codpostal.focus();
	return false;
}

//***** APARTADO 2 ******

if (d.cont_nombre.value == "") {
	alert("Debe indicar el nombre y los apellidos de la persona de contacto");
	d.cont_nombre.focus();
	return false;
}

if (d.cont_tel.value == "") {
	alert("Debe indicar el teléfono de la persona de contacto");
	d.cont_tel.focus();
	return false;
}

if(!er_cont_tel.test(d.cont_tel.value)){
	alert("Teléfono incorrecto. Especifique solo números");
	d.cont_tel.focus();
	return false;
}

if(!valEmail(d.cont_email.value)){
	alert("E-mail incorrecto");
	d.cont_email.focus();
	return false;
}

//***** APARTADO 3 ******

if ( (getCheckedValue(d.QSERVSOL) == "") ) {
	alert("Debe indicar el servicio solicitado");
	d.QSERVSOL[0].focus();
	return false;
}

if ( (getCheckedValue(d.iso9001) == "")&& (getCheckedValue(d.iso14001) == "")&& (getCheckedValue(d.ohsas18001) == "")&& (getCheckedValue(d.alegalPRL) == "")&& (getCheckedValue(d.en9100) == "")&& (getCheckedValue(d.une66926) == "")&& (getCheckedValue(d.emas) == "")&& (getCheckedValue(d.otrasnormas) == "") ) {
	alert("Debe indicar la/s norma/s para el servicio solicitado");
	d.iso9001.focus();
	return false;
}

if ( (getCheckedValue(d.otrasnormas) == "1")&&(d.txt_otrasnormas.value == "") ) {
	alert("Debe indicar la/s norma/s para el servicio solicitado");
	d.txt_otrasnormas.focus();
	return false;
}

if ( (getCheckedValue(d.QSG) == "") ) {
	alert("Debe indicar si tiene algún otro Sistema de Gestión");
	d.QSG[0].focus();
	return false;
} 

if ( (getCheckedValue(d.QSG) == "1") ) {

	if (getCheckedValue(d.QCERTIF) == ""){
		alert("Debe indicar si se ha certificado e indicar en qué norma/s");
		d.QCERTIF[0].focus();
		return false;
	}

	if (getCheckedValue(d.QCERTIF) == "1"){

		if (d.normas.value==""){
			alert("Debe indicar la/s norma/s en la/s que se ha certificado");
			d.normas.focus();
			return false;
		}

		if ((d.fvenccertif.value=="")||(d.fvenccertif.value=="DD/MM/AAAA")){
			alert("Debe indicar la fecha de vencimiento del/los certificado/s");
			d.fvenccertif.focus();
			return false;
		}

	
		if(!er_fecha.test(d.fvenccertif.value)){
			alert("Fecha incorrecta. Especifique DD/MM/AAAA");
			d.fvenccertif.focus();
			return false;
		}

		if (d.entcertif.value==""){
			alert("Debe indicar la Entidad de Certificación");
			d.entcertif.focus();
			return false;
		}
	}
}

if (getCheckedValue(d.QSERVCONS) == ""){
	alert("Debe indicar si se ha recibido servicios de consultoría para la obtención o mantenimiento de la certificación solicitada");
	d.QSERVCONS[0].focus();
	return false;
}

if (getCheckedValue(d.QSERVCONS) == "1"){

	if (d.consultora.value == "") {
		alert("Debe indicar el nombre de la consultora");
		d.consultora.focus();
		return false;
	}

	if ((d.fconsultoria.value == "")||(d.fconsultoria.value == "DD/MM/AAAA")) {
		alert("Debe indicar la fecha de finalización de la consultoría");
		d.fconsultoria.focus();
		return false;
	}

	if(!er_fecha.test(d.fconsultoria.value)){
		alert("Fecha incorrecta. Especifique DD/MM/AAAA");
		d.fconsultoria.focus();
		return false;
	}

}


if (getCheckedValue(d.QRECFORM) == "") {
	alert("Debe indicar si ha recibido formación 'in-company' por parte de Bureau Veritas");
	d.QRECFORM[0].focus();
	return false;
}

//***** APARTADO 4 ******

if (d.alcance_certif.value == "") {
	alert("Debe indicar el alcance de la certificación");
	d.alcance_certif.focus();
	return false;
}


if ( (getCheckedValue(d.act_diseno) == "")&& (getCheckedValue(d.act_fabric) == "")&& (getCheckedValue(d.act_comerc) == "")&& (getCheckedValue(d.act_distrib) == "")&& (getCheckedValue(d.act_prest) == "") ) {
	alert("Debe indicar al menos una actividad realizada en el entorno de la Certificación");
	d.act_diseno.focus();
	return false;
}

//***** APARTADO 5 ******

if (d.nemplazamientos.value == "") {
	alert("Debe indicar el nº total de emplazamientos involucrados");
	d.nemplazamientos.focus();
	return false;
}

if (d.nempleados.value == "") {
	alert("Debe indicar el nº de empleados involucrados");
	d.nempleados.focus();
	return false;
}

if ( (getCheckedValue(d.en9100) == "1") && (d.paeronautico.value == "")) {
	alert("Debe indicar el porcentaje de empleados para el sector aeronáutico");
	d.paeronautico.focus();
	return false;

}

//***** APARTADO 6 ******

if (d.nemplazamientos.value > 1 ) {

	if ((getCheckedValue(d.QISG1) == "")||(getCheckedValue(d.QISG2) == "")||(getCheckedValue(d.QISG3) == "")||(getCheckedValue(d.QISG4) == "")||(getCheckedValue(d.QISG5) == "")||(getCheckedValue(d.QISG6) == "")||(getCheckedValue(d.QISG7) == "")||(getCheckedValue(d.QISG8) == "")||(getCheckedValue(d.QISG9) == "")  ) {
		alert("Al tener múltiples emplazamientos, debe completar el apartado 6");
		d.QISG1[0].focus();
		return false;
	}

	if ((getCheckedValue(d.QISG6) == "0")||(getCheckedValue(d.QISG7) == "0")||(getCheckedValue(d.QISG8) == "0")||(getCheckedValue(d.QISG9) == "0") ) {
		if (d.cisg.value == "") {
			alert("Debe indicar comentarios en el apartado 6, perteneciente a la 'Información sobre el Sistema de Gestión'");
			d.cisg.focus();
			return false;
		}
	}
}


//***** APARTADO 7 ******



cont=0;
if (getCheckedValue(d.iso9001) == "1")cont = cont+1
if (getCheckedValue(d.iso14001) == "1")cont = cont+1
if (getCheckedValue(d.ohsas18001) == "1")cont = cont+1
if (getCheckedValue(d.emas) == "1")cont = cont+1


if (cont > 1) {
	if (getCheckedValue(d.QISG) == ""){
		alert("Debe indicar si están integrados sus Sistemas de Gestión");
		d.QISG[0].focus();
		return false;
	}
}


if ((getCheckedValue(d.QISG) != "")&& (getCheckedValue(d.QISG) != "0")) {
	
	if (getCheckedValue(d.GISG) == "") {
		alert("Debe indicar el grado de integración de sus Sistemas de Gestión");
		d.GISG[0].focus();
		return false;
	}

	if ((getCheckedValue(d.QGISG1) == "")||(getCheckedValue(d.QGISG2) == "")||(getCheckedValue(d.QGISG3) == "")||(getCheckedValue(d.QGISG4) == "")) {
		alert("Debe completar el apartado 7");
		d.QGISG1[0].focus();
		return false;
	}


}





// **** ANEXOS ***************+

if ((getCheckedValue(d.iso14001) == "1")||(getCheckedValue(d.emas) == "1")) {

	if ((getCheckedValue(d.loc_inst) != "1") && (getCheckedValue(d.loc_inst) != "2") && (getCheckedValue(d.loc_inst) != "3")){
		alert("Debe indicar la localización de las instalaciones de la Organización");
		d.loc_otrastext.focus();
		return false;
	}
	if ((getCheckedValue(d.loc_inst) == "3") && (d.loc_otrastext.value == "")){
		alert("Debe indicar la localización de las instalaciones de la Organización");
		d.loc_otrastext.focus();
		return false;
	}

	if (d.aa_residuos.value == ""){
		alert("Debe indicar los principales residuos, emisiones y otros aspectos que genere o consuma");
		d.aa_residuos.focus();
		return false;

	}
	if (d.aa_permisos.value == ""){
		alert("Debe indicar los principales permisos, autorizaciones o licencias de que dispone");
		d.aa_permisos.focus();
		return false;

	}	
	if ( (getCheckedValue(d.QAAlicencia) != "0") && ((getCheckedValue(d.QAAlicencia) != "1"))){
		alert("Debe indicar si dispone de Licencia de Actividad/apertura/funcionamiento en el apartado de 'INFORMACIÓN ADICIONAL PARA LA CERTIFICACIÓN ISO 14001 / EMAS'");
		d.QAAlicencia[0].focus();
		return false;
	}
	if ( (getCheckedValue(d.QAAlicencia) == "0") && (   (getCheckedValue(d.QAAlicsol) != "0")  && (getCheckedValue(d.QAAlicsol) != "1"))  ) {
		alert("Debe indicar si ha solicitado la Licencia de Actividad/apertura/funcionamiento en el apartado de 'INFORMACIÓN ADICIONAL PARA LA CERTIFICACIÓN ISO 14001 / EMAS'");
		d.QAAlicsol[0].focus();
		return false;
	}

}

if ((getCheckedValue(d.ohsas18001) == "1")||(getCheckedValue(d.alegalPRL) == "1")) {

	if ((getCheckedValue(d.modalidad) != "Ajeno") && (getCheckedValue(d.modalidad) != "Propio") && (getCheckedValue(d.modalidad) != "Mixto")){
		alert("Debe indicar la modalidad del Servicio de Prevención de la Organización en el apartado de 'INFORMACIÓN ADICIONAL PARA LA CERTIFICACIÓN OHSAS 18001 Y AUDITORÍA LEGAL PRL'");
		return false;	
	}

	if (getCheckedValue(d.Qanexo1) == "") {
		alert("Debe indicar si alguna actividad está englobada en el Anexo I (RD 39/97)");
		d.Qanexo1[0].focus();
		return false;
	}

	if ( (getCheckedValue(d.Qanexo1) == "1") && (d.actanexo1.value == "")){
		alert("Debe indicar las actividades englobadas en el Anexo I (RD 39/97)");
		d.actanexo1.focus();
		return false;
	}

	if (d.modalidad.value != "Ajeno"){
		if (getCheckedValue(d.especpreven) == "") {
			alert("Debe indicar las especialidades preventivas asumidas internamente");
			d.especpreven[0].focus();
			return false;
		}
	} 

	if (d.riesgos.value == ""){
		alert("Debe indicar los principales riesgos o peligros identificados en su organización");
		d.riesgos.focus();
		return false;
	} 
	if ( (getCheckedValue(d.QDispLic) != "0") && ((getCheckedValue(d.QDispLic) != "1"))){
		alert("Debe indicar si dispone de Licencia de Actividad/apertura/funcionamiento");
		d.QDispLic[0].focus();
		return false;
	}

	if ( (getCheckedValue(d.QDispLic) == "0") && ((getCheckedValue(d.QSolLic) != "0") && (getCheckedValue(d.QSolLic) != "1"))){
		alert("Debe indicar si ha solicitado la Licencia de Actividad/apertura/funcionamiento");
		d.QSolLic[0].focus();
		return false;
	}
	


}

return true;

}

function mano(a) {
	if (navigator.appName=="Netscape") {
		a.style.cursor='pointer';
	} else {
		a.style.cursor='hand';
	}
}
