arr_ppal = new Array ("Centrales Nucleares y empresas electricas","Centros de Investigación","Empresas públicas","Hospitales","Ingenierías","Organismos e Instituciones","Proveedores de bienes","Proveedores de servicios","Sociedades y Asociaciones","Universidades");
arr_pbienes = new Array("Fuentes y productos radiactivos", "Equipos radiactivos", "Detectores", "Blindajes y equipamiento laboratorio", "Otros");
arr_pservicios = new Array("UTPR","Centros de dosimetría","Formación en instalaciones radiactivas","Formación en instalaciones de rayos X","Transporte","Otros (descontaminación, desmantelamiento, vigilancia ambiental)");
arr_organismos = new Array("Administración general","Administración autonómica");
arr_ingenierias = new Array("Diseño", "Consultoría", "Construcción de equipos", "Descontaminación");

function addRow(in_tbl_name){
    var tbody = document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
    var rowppal = document.createElement("TR");
    
	
	

    var row = document.createElement("TR");
	row.id="tr"+count;

	var td1 = document.createElement("TD")
   
    //var strHtml = "<INPUT TYPE=\"Button\" CLASS=\"boton\" onClick=\"delRow("+count+")\" VALUE=\"Eliminar\">";
	var strHtml1 ="<a href=\"#\" class=\"boton\" onclick='javascript:delRow("+count+")'>Eliminar&nbsp;Sector</a>";
    td1.innerHTML = strHtml1.replace(/!count!/g,count);

    var tdmedio = document.createElement("TD")
    tdmedio.innerHTML="&nbsp;"

    var td2 = document.createElement("TD")
	//td2.align="left";
	//td2.width="10px";
	//td2.height="40";
    var strHtml2 = "<SELECT class='campo' ID='CAT" + count + "' NAME='CAT" + count +"' onchange='addCell("+count+")' >";
    strHtml2 = strHtml2 + "<OPTION></OPTION>";
	for(f=0;f <arr_ppal.length;f++){
	   var title = arr_ppal[f].replace(/ /g,"_");
     
		strHtml2 = strHtml2 + "<OPTION value=" + title +">" + arr_ppal[f] +"</OPTION>";
	}
	strHtml2 = strHtml2 + "</SELECT>";
	td2.innerHTML = strHtml2

    var td3 = document.createElement("TD")
	td3.id="col2-"+count;
    td3.innerHTML = "";

   

	var td4 = document.createElement("TD")
	td4.id="imagsect"+count;
    td4.innerHTML = "<img src='../imgs/px.gif' name='imgsect"+count+"' id='imgsect"+count+"'>";

	row.appendChild(td1);
	//row.appendChild(tdmedio);
    row.appendChild(td2);
	//row.appendChild(tdmedio);
    row.appendChild(td3);
	//row.appendChild(tdmedio);
	row.appendChild(td4);
	

    tbody.appendChild(row);
    count = parseInt(count) + 1;
    
 }

  function delRow(num){
	var idtr = "tr"+num;
	var d = document.getElementById('tblsectores').getElementsByTagName("TBODY")[0]; 
	d.removeChild(document.getElementById(idtr)); 
  }

function addCell(num){
idcell = "col2-"+num;
idselect ="CAT"+num;
var x=document.getElementById(idcell)
var y  = document.getElementById(idselect)
var content="";
switch (y.value){
				case "Proveedores_de_bienes":
							   content = "<SELECT class='campo' ID='SUBCAT" + num + "' NAME='SUBCAT" + num +"'>";
							   content = content + "<OPTION></OPTION>";
								for(f=0;f <arr_pbienes.length;f++){
									var opcion = arr_pbienes[f].replace(/ /g,"_");
     
									content = content + "<OPTION value=" + opcion +">" + arr_pbienes[f] +"</OPTION>";
								}
								content = content + "</SELECT>";
								break;
				case "Proveedores_de_servicios":
							   content = "<SELECT class='campo' ID='SUBCAT" + num + "' NAME='SUBCAT" + num +"'>";
							   content = content + "<OPTION></OPTION>";
								for(f=0;f <arr_pservicios.length;f++){
									var opcion = arr_pservicios[f].replace(/ /g,"_");
     
									content = content + "<OPTION value=" + opcion +">" + arr_pservicios[f] +"</OPTION>";
								}
								content = content + "</SELECT>";
								break;

								
				case "Organismos_e_Instituciones":
							   content = "<SELECT class='campo' ID='SUBCAT" + num + "' NAME='SUBCAT" + num +"'>";
							   content = content + "<OPTION></OPTION>";
								for(f=0;f <arr_organismos.length;f++){
									var opcion = arr_organismos[f].replace(/ /g,"_");
     
									content = content + "<OPTION value=" + opcion +">" + arr_organismos[f] +"</OPTION>";
								}
								content = content + "</SELECT>";
								break;
				case "Ingenierías":
							   content = "<SELECT class='campo' ID='SUBCAT" + num + "' NAME='SUBCAT" + num +"'>";
							   content = content + "<OPTION></OPTION>";
								for(f=0;f <arr_ingenierias.length;f++){
									var opcion = arr_ingenierias[f].replace(/ /g,"_");
     
									content = content + "<OPTION value=" + opcion +">" + arr_ingenierias[f] +"</OPTION>";
								}
								content = content + "</SELECT>";
								break;

}
x.innerHTML=content;
}

function correctos(){
		var errores=false;
		var msgerror="";


		/*if(document.agi.nombre.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique nombre de la empresa\n";
			document.imgnombre.src="../imgs/error.gif";
		}else{
			document.imgnombre.src="../imgs/px.gif";
		}*/

	
		/*if(document.agi.direccion.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique dirección de la empresa\n";
		document.imgdireccion.src="../imgs/error.gif";
		}else{
			document.imgdireccion.src="../imgs/px.gif";
		}*/
		/*if(document.agi.cp.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique código postal de la empresa\n";
		document.imgcp.src="../imgs/error.gif";
		}else{
			document.imgcp.src="../imgs/px.gif";
		}*/
		/*if(document.agi.poblacion.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique población de la empresa\n";
		document.imgpoblacion.src="../imgs/error.gif";
		}else{
			document.imgpoblacion.src="../imgs/px.gif";
		}*/
		/*if(document.agi.provincia.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique provincia de la empresa\n";
		    document.imgprovincia.src="../imgs/error.gif";
		}else{
			document.imgprovincia.src="../imgs/px.gif";
		}*/
		/*if(document.agi.email.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique e-mail de la empresa\n";
		    document.imgemail.src="../imgs/error.gif";
		}else{
			if (chmail()==false){
				errores=true;
				msgerror=msgerror + "  - Proporcion e-mail válido\n";
			 document.imgemail.src="../imgs/error.gif";
			}else{
				document.imgemail.src="../imgs/px.gif";
			}
		}*/
		/*if(document.agi.contacto.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique persona de contacto\n";
		    document.imgcontacto.src="../imgs/error.gif";
		}else{
			document.imgcontacto.src="../imgs/px.gif";
		}*/
		/*if(document.agi.pwd1.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique contraseña de acceso\n";
			document.imgpwd1.src="../imgs/error.gif";
			document.imgpwd2.src="../imgs/px.gif";
		}else{
			document.imgpwd1.src="../imgs/px.gif";
			if(document.agi.pwd2.value==""){
				errores=true;
				msgerror=msgerror + "  - Confirme contraseña de acceso\n";
                document.imgpwd2.src="../imgs/error.gif";
			}else{
				if(document.agi.pwd1.value != document.agi.pwd2.value){
							errores=true;

							msgerror=msgerror + "  - Confirme correctamente la contraseña de acceso\n";
							document.imgpwd2.src="../imgs/error.gif";
						}else{
							document.imgpwd2.src="../imgs/px.gif";
						}
			}
		}*/


		var rows = document.getElementById('tblsectores').getElementsByTagName("TBODY")[0].rows.length;
		if (rows <=1){
			errores=true;
			msgerror=msgerror + "  - Seleccione algún sector de actividad\n";
			document.imgsector.src="../imgs/error.gif";
		}else{
			document.imgsector.src="../imgs/px.gif";
			var el = document.getElementById('tblsectores').getElementsByTagName("TBODY")[0];

			for(var i=0; i<rows; i++){
				

				if (el.rows[i].id != ""){
					var trid=el.rows[i].id;
						var numid = trid.replace("tr","")
						var nomsel = eval("document.agi.CAT"+numid)
							var nomimage=eval("document.imgsect"+numid);
						if (nomsel.value == ""){
                           errores=true;
							msgerror=msgerror + "  - Seleccione sector de actividad en linea " +i +"\n";
							nomimage.src="../imgs/error.gif";
						}else{
                          if ((nomsel.value =="Ingenierías") || (nomsel.value=="Organismos_e_Instituciones") || (nomsel.value == "Proveedores_de_bienes") || (nomsel.value=="Proveedores_de_servicios")){
                             var nomsubcat = eval("document.agi.SUBCAT"+numid);
							 if (nomsubcat.value == ""){
								errores=true;
								msgerror=msgerror + "  - Seleccione subcategoría para el sector " +nomsel.value.replace(/_/g," ") +"\n";
								nomimage.src="../imgs/error.gif";
							 }else{
								nomimage.src="../imgs/px.gif";
							 }
						  }else{
							nomimage.src="../imgs/px.gif";
						  }
						}
				}

				
			}
		}

		if(errores == true){
			alert (msgerror);
			return false;
		}else{
			return true;
		}
	}




function chmail() {
		str=document.agi.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function correctos_admin(){
		var errores=false;
		var msgerror="";


		/*if(document.agi.nombre.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique nombre de la empresa\n";
			document.imgnombre.src="../imgs/error.gif";
		}else{
			document.imgnombre.src="../imgs/px.gif";
		}*/

		/*if(document.agi.direccion.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique dirección de la empresa\n";
		document.imgdireccion.src="../imgs/error.gif";
		}else{
			document.imgdireccion.src="../imgs/px.gif";
		}*/
		/*if(document.agi.cp.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique código postal de la empresa\n";
		document.imgcp.src="../imgs/error.gif";
		}else{
			document.imgcp.src="../imgs/px.gif";
		}*/
		/*if(document.agi.poblacion.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique población de la empresa\n";
		document.imgpoblacion.src="../imgs/error.gif";
		}else{
			document.imgpoblacion.src="../imgs/px.gif";
		}*/
		/*if(document.agi.provincia.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique provincia de la empresa\n";
		    document.imgprovincia.src="../imgs/error.gif";
		}else{
			document.imgprovincia.src="../imgs/px.gif";
		}*/
		/*if(document.agi.email.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique e-mail de la empresa\n";
		    document.imgemail.src="../imgs/error.gif";
		}else{
			if (chmail()==false){
				errores=true;
				msgerror=msgerror + "  - Proporcion e-mail válido\n";
			 document.imgemail.src="../imgs/error.gif";
			}else{
				document.imgemail.src="../imgs/px.gif";
			}
		}*/
		/*if(document.agi.contacto.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique persona de contacto\n";
		    document.imgcontacto.src="../imgs/error.gif";
		}else{
			document.imgcontacto.src="../imgs/px.gif";
		}*/
		/*if(document.agi.pwd.value==""){
			errores=true;
			msgerror=msgerror + "  - Indique contraseña de acceso\n";
		    document.imgpwd1.src="../imgs/error.gif";
		}else{
			document.imgpwd1.src="../imgs/px.gif";
		}*/
		


		var rows = document.getElementById('tblsectores').getElementsByTagName("TBODY")[0].rows.length;
		if (rows <=1){
			errores=true;
			msgerror=msgerror + "  - Seleccione algún sector de actividad\n";
			document.imgsector.src="../imgs/error.gif";
		}else{
			document.imgsector.src="../imgs/px.gif";
			var el = document.getElementById('tblsectores').getElementsByTagName("TBODY")[0];

			for(var i=0; i<rows; i++){
				

				if (el.rows[i].id != ""){
					var trid=el.rows[i].id;
						var numid = trid.replace("tr","")
						var nomsel = eval("document.agi.CAT"+numid)
							var nomimage=eval("document.imgsect"+numid);
						if (nomsel.value == ""){
                           errores=true;
							msgerror=msgerror + "  - Seleccione sector de actividad en linea " +i +"\n";
							nomimage.src="../imgs/error.gif";
						}else{
                          if ((nomsel.value =="Ingenierías") || (nomsel.value=="Organismos_e_Instituciones") || (nomsel.value == "Proveedores_de_bienes") || (nomsel.value=="Proveedores_de_servicios")){
                             var nomsubcat = eval("document.agi.SUBCAT"+numid);
							 if (nomsubcat.value == ""){
								errores=true;
								msgerror=msgerror + "  - Seleccione subcategoría para el sector " +nomsel.value.replace(/_/g," ") +"\n";
								nomimage.src="../imgs/error.gif";
							 }else{
								nomimage.src="../imgs/px.gif";
							 }
						  }else{
							nomimage.src="../imgs/px.gif";
						  }
						}
				}

				
			}
		}

		if(errores == true){
			alert (msgerror);
			return false;
		}else{
			return true;
		}
	}

