function openBrWindow(theURL,winName,features) { //v2.0
  var win = window.open(theURL,winName,features);
   	win.focus();
}
function chg() {
    document.Entidad.frm_CHG.value = "C"
	document.Entidad.submit();
 }	 
function checklogin(a) { 
	// verifica que han pulsado Usuario y Clave
	if(a == undefined) {Nivel = "";} else { Nivel = a;}
	var o = document.Identifica;
	
	 
	 if (o.frm_usuario.value.length == 0) { alert('Debe rellenar el dato Usuario'); o.frm_usuario.focus(); return; }
	
	  
	 if (o.frm_clave.value.length == 0)	  { alert('Debe rellenar el dato Contraseña'); o.frm_clave.focus(); return; }
	 
	document.Identifica.action=Nivel + "usuarios/validauser.asp";
  	document.Identifica.submit();
  }
function pidelogin(a) { 
	if(a == undefined) {Nivel = "";} else { Nivel = a;}
	var o = document.Identifica;
	document.Identifica.action= Nivel + "usuarios/PideLogin.asp";
  	document.Identifica.submit();
  }  
function ValidoContacto() { 
	// verifica que en contactos al menos han pulsado el nombre, email, empresa y telefono
	var txtError ="Debe rellenar los siguientes Datos :";
	txtError = txtError + "\n\n";
	
	var bError = false
	
	var o = document.Contacto;
	
	o.frm_nombre.value = trim(o.frm_nombre.value);	
	if (o.frm_nombre.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Persona de Contacto \n";
	  }

 	if (!emailCheck(o.frm_email.value)) { 
		bError = true;
		txtError = txtError + "--> Email no valido \n";
	}

	o.frm_empresa.value = trim(o.frm_empresa.value);	
	if (o.frm_empresa.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Empresa \n";
	  }

	o.frm_telefono.value = trim(o.frm_telefono.value);	
	if (o.frm_telefono.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Teléfono \n";
	  }

	if (bError == true)
	{
		txtError = txtError + "\n" + "<-------------->" + "\n";
		alert(txtError);
		return false;
	}
	else
	{
	 o.action = "contactosql.asp";
	 return true;
	 }
	
  }
  function ValidoContacto_ecopilas() { 
	// verifica que en contactos al menos han pulsado el nombre, email, empresa y telefono
	var txtError ="Debe rellenar los siguientes Datos :";
	txtError = txtError + "\n\n";
	
	var bError = false
	
	var o = document.Contacto;
	
	o.frm_nombre.value = trim(o.frm_nombre.value);	
	if (o.frm_nombre.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Persona de Contacto \n";
	  }


	o.frm_empresa.value = trim(o.frm_empresa.value);	
	if (o.frm_empresa.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Entidad \n";
	  }

	if (o.frm_actividad.value == "-")    {
		bError = true;
		txtError = txtError + "--> Actividad \n";
	  }
	  
	o.frm_telefono.value = trim(o.frm_telefono.value);	
	if (o.frm_telefono.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Teléfono \n";
	  }

 	if (!emailCheck(o.frm_email.value)) { 
		bError = true;
		txtError = txtError + "--> Email no valido \n";
	}
	if (bError == true)
	{
		txtError = txtError + "\n" + "<-------------->" + "\n";
		alert(txtError);
		return false;
	}
	else
	{
	 o.action = "contactosql_ecopilas.asp";
	 return true;
	 }
	
  }
  
function ValidoAdhesion() { 
	// verifica que en contactos al menos han rellenado los datos de IDENTIFICACION
	var txtError ="Debe rellenar / corregir los siguientes Datos :";
	txtError = txtError + "\n\n";
	
	var bError = false
	
	var o = document.Contacto;
	
	o.frm_empresa.value = trim(o.frm_empresa.value);	
	if (o.frm_empresa.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Empresa \n";
	  }
	// quitamos el control a petición de Patricia y Cristina 26/01/2006  
	o.frm_CIF.value = trim(o.frm_CIF.value);	
	// var	msg	= CompruebaCIF(o.frm_CIF.value);  
	// var	msg	= CompruebaCIF(o.frm_CIF.value);
	// if ( msg != "")  { 
	// 	bError = true;
	//	txtError = txtError + "--> " + msg + "  \n";
  	// }
	
	if (o.frm_CIF.value.length == 0)    {	// no se comprueba la valided por los extranjeros
		bError = true;
		txtError = txtError + "--> Falta CIF \n";
	  }
	
	o.frm_direccion.value = trim(o.frm_direccion.value);	
	if (o.frm_direccion.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Dirección \n";
	  }
	
	o.frm_CP.value = trim(o.frm_CP.value);	
	if (o.frm_CP.value.length < 5)    {
		bError = true;
		txtError = txtError + "--> Código Postal \n";
	  }
	if (o.frm_CP.value < 01000 || o.frm_CP.value > 52999)    {
		bError = true;
		txtError = txtError + "--> Código Postal \n";
	  }
	
	if (o.frm_CodMunicipios.value == "-")    {
		bError = true;
		txtError = txtError + "--> Población \n";
	  }
	  
	  o.frm_telefono.value = trim(o.frm_telefono.value);	
	if (o.frm_telefono.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Teléfono \n";
	  }
	o.frm_fax.value = trim(o.frm_fax.value);	
	if (o.frm_fax.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Fax \n";
	  }
	o.frm_email.value = trim(o.frm_email.value);	
	if (o.frm_email.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Email de 1 IDENTIFICACION \n";
	  }
	 
	 if (o.frm_email.value.length != 0) { 
	 	if (!emailCheck(o.frm_email.value)) { 
			bError = true;
			txtError = txtError + "--> La dirección Email de 1 IDENTIFICACION no es valida \n";
	} }
	
	o.frm_numempleados.value = trim(o.frm_numempleados.value);
	if (o.frm_numempleados.value < 1)    {
		bError = true;
		txtError = txtError + "--> Número de Empleados debe ser mayor que cero \n";
	}
	
	//var dia = o.frm_FechaComunicacionAutonomiaDD.value;
	//var mes = o.frm_FechaComunicacionAutonomiaMM.value;
	//var año = o.frm_FechaComunicacionAutonomiaAA.value;
	//var	msg	= checkFecha(dia, mes, año);
	//if ( msg != "")  { 
	//	bError = true;
	//	txtError = txtError + "--> " + msg + " EN FECHA COMUNICACIÓN A LA COMUNIDAD AUTONOMA \n";
	//} 
	 
	o.frm_c1nom.value = trim(o.frm_c1nom.value);	
	if (o.frm_c1nom.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Nombre 6.1 REPRESENTANTE LEGAL \n";
	}
	o.frm_c1ape.value = trim(o.frm_c1ape.value);	
	if (o.frm_c1ape.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Apellidos 6.1 REPRESENTANTE LEGAL \n";
	}
	
	// quitamos el control a petición de Patricia y Cristina 26/01/2006  
	o.frm_c1NIF.value = trim(o.frm_c1NIF.value);	
	// if (o.frm_c1NIF.value.length < 9)    {
	//	bError = true;
	//	txtError = txtError + "--> NIF 6.1 REPRESENTANTE LEGAL debe de tener 9 digitos \n";
	//  }
	// 	NIF = o.frm_c1NIF.value
	//	NIF8 = NIF.substr(0,8)
	//	cadena="TRWAGMYFPDXBNJZSQVHLCKET"
	//	posicion = NIF8 % 23
	//	letra = cadena.substring(posicion,posicion+1)
			
	// if (NIF.substr(8,1) != letra)    {
	//	bError = true;
	//	txtError = txtError + "--> el NIF 6.1 REPRESENTANTE LEGAL es erroneo \n";
	//  }
	  
	  if (!emailCheck(o.frm_c1email.value)) { 
		bError = true;
		txtError = txtError + "--> La dirección Email de 6.1 REPRESENTANTE LEGAL no es valida \n";
	} 
	o.frm_c2nom.value = trim(o.frm_c2nom.value);	
	if (o.frm_c2nom.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Nombre 6.2 RESPONSABLE DATOS \n";
	}
	o.frm_c2ape.value = trim(o.frm_c2ape.value);	
	if (o.frm_c2ape.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Apellidos 6.2 RESPONSABLE DATOS \n";
	}
	// quitamos el control a petición de Patricia y Cristina 26/01/2006  
	o.frm_c2NIF.value = trim(o.frm_c2NIF.value);	
	// if (o.frm_c2NIF.value.length < 9)    {
	//	bError = true;
	//	txtError = txtError + "--> NIF 6.2 RESPONSABLE DATOS debe de tener 9 digitos \n";
	//  }
	// 	NIF = o.frm_c2NIF.value
	//	NIF8 = NIF.substr(0,8)
	//	cadena="TRWAGMYFPDXBNJZSQVHLCKET"
	//	posicion = NIF8 % 23
	//	letra = cadena.substring(posicion,posicion+1)
			
	//if (NIF.substr(8,1) != letra)    {
	//	bError = true;
	//	txtError = txtError + "--> el NIF 6.2 RESPONSABLE DATOS es erroneo \n";
	//  }	
	if (!emailCheck(o.frm_c2email.value)) { 
		bError = true;
		txtError = txtError + "--> La dirección Email de 6.2 RESPONSABLE DATOS no es valida \n";
	} 
	
	if (o.frm_c3nom.value.length != 0 || o.frm_c3ape.value.length != 0 || o.frm_c3NIF.value.length != 0 || o.frm_c3email.value.length != 0) { 
		o.frm_c3nom.value = trim(o.frm_c3nom.value);	
		if (o.frm_c3nom.value.length == 0)    {
			bError = true;
			txtError = txtError + "--> Nombre 6.3 PERSONA DE CONTACTO \n";
		}
		
		o.frm_c3ape.value = trim(o.frm_c3ape.value);	
		if (o.frm_c3ape.value.length == 0)    {
			bError = true;
			txtError = txtError + "--> Apellidos 6.3 PERSONA DE CONTACTO \n";
		}
		// quitamos el control a petición de Patricia y Cristina 26/01/2006  
		o.frm_c3NIF.value = trim(o.frm_c3NIF.value);	
		//if (o.frm_c3NIF.value.length < 9)    {
		//	bError = true;
		//	txtError = txtError + "--> NIF 6.3 PERSONA DE CONTACTO debe de tener 9 digitos \n";
		//  }
		//	NIF = o.frm_c3NIF.value
		//	NIF8 = NIF.substr(0,8)
		//	cadena="TRWAGMYFPDXBNJZSQVHLCKET"
		//	posicion = NIF8 % 23
		//	letra = cadena.substring(posicion,posicion+1)
				
		// if (NIF.substr(8,1) != letra)    {
		//	bError = true;
		//	txtError = txtError + "--> el NIF 6.3 PERSONA DE CONTACTO es erroneo \n";
		//  }
		
	 	if (!emailCheck(o.frm_c3email.value)) { 
			bError = true;
			txtError = txtError + "--> La dirección Email de 6.3 PERSONA DE CONTACTO no es valida \n";
	} } 
	  
	if (bError == true)
	{
		txtError = txtError + "\n" + "<-------------->" + "\n";
		alert(txtError);
		return false;
	}
	else
	{
	 o.action = "adhesionforsql.asp";
	 return true;
	 }
	
  }
function validosolclaves() { 
	
	var o = document.solclaves;
	if (o.frm_email.value.length == 0) { alert('Debe rellenar el dato email'); o.frm_email.focus(); return false; }
	if (o.frm_email.value.length != 0) { if (!emailCheck(o.frm_email.value)) { alert('La dirección de correo electronico (Email) no es valida'); frm_email.focus (); return false; } }
	
	document.solclaves.action="mcta_solclavessql.asp";
  	document.solclaves.submit();
  }    
function validocontra() { 
	var txtError ="Debe rellenar / corregir los siguientes Datos :";
	txtError = txtError + "\n\n";
	
	var bError = false
	
	var o = document.cambiocontra;
	
	if (o.frm_Actual.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Contraseña Actual \n";
	  }
	if (o.frm_Nueva.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Nueva Contraseña \n";
	  }
	if (o.frm_Nueva.value.length < 6)    {
		bError = true;
		txtError = txtError + "--> Nueva Contraseña inferior a 6 caracteres\n";
	  }
	if (o.frm_NuevaRep.value.length == 0)    {
		bError = true;
		txtError = txtError + "--> Repita la Nueva Contraseña \n";
	  }
	if (o.frm_NuevaRep.value != o.frm_Nueva.value)    {
		bError = true;
		txtError = txtError + "--> Repita la Nueva Contraseña distinta a Nueva Contraseña \n";
	  }

	if (bError == true)
	{
		txtError = txtError + "\n" + "<-------------->" + "\n";
		alert(txtError);
		return false;
	}
	else
	{
	 o.action = "mcta_CambioContrasql.asp";
	 return true;
	 }
  }    
  
function viewAparatos(cat,idi) {
    var win = window.open("/aeesrespuestaapa.asp?cat=" + (cat) + "&" + (idi),"DetalleAparatos","width=610,height=500,left=0,top=0,scrollbars=yes");
	 	win.focus();
}

function viewTipos_Ecopilas(tip,idi) {
    var win = window.open("/Declaracion/PD_DetalleTipos_Ecopilas.asp?tip=" + (tip) + "&" + (idi),"DetalleTipos_Ecopilas","width=610,height=500,left=0,top=0,scrollbars=yes");
	 	win.focus();
} 

function viewCantidades(codigoAP,URL,periodoID) {
    var win = window.open("/declaracioncanti.asp?codigoAP=" + (codigoAP) + "&URL=" + (URL) + "&periodoID=" + (periodoID),"DeclaracionCantidades","resizable =yes,width=450,height=350,left=250,top=250,scrollbars=no");
		win.focus();
}
 
function CheckNumEnt(obj)
{

	var cadena = "";
     var importe = 0;

  	for (var i=0; i<obj.value.length; i++) {
		var ch = obj.value.substring (i, i+1);
		if ((ch < "0" || ch > "9")) {
 			alert ("Sólo se admiten números.");
			obj.value = "";
			obj.focus ();
			return false;
		}
	}
return true;
}

function CheckNumDec(obj)
{
	var cadena = "";
     var importe = 0;

      if (obj.value.charAt(0) == ","){
	  alert ("Importe erróneo.");
	  obj.value = "";
	  obj.focus ();
	  return false;
      }
  	for (var i=0; i<obj.value.length; i++) {
		var ch = obj.value.substring (i, i+1);
		if ((ch < "0" || ch > "9") && (ch != ",")) {
 			alert ("Sólo se admiten números y coma.");
			obj.value = "";
			obj.focus ();
			return false;
		}
	}
	for (var i=0; i<obj.value.length; i++)
	{
	  if (obj.value.charAt(i) == ',')
	    if ((obj.value.length-(i+1) > 2) || (obj.value.length-(i+1) == 0))
	    {
		alert ("Sólo se admiten uno o dos decimales.");
		obj.value = "";
		obj.focus ();
	      return false;
	    }
      }

	return true;
}
function CheckNum3Dec(obj)
{
	var cadena = "";
     var importe = 0;

      if (obj.value.charAt(0) == ","){
	  alert ("Importe erróneo.");
	  obj.value = "";
	  obj.focus ();
	  return false;
      }
  	for (var i=0; i<obj.value.length; i++) {
		var ch = obj.value.substring (i, i+1);
		if ((ch < "0" || ch > "9") && (ch != ",")) {
 			alert ("Sólo se admiten números y coma.");
			obj.value = "";
			obj.focus ();
			return false;
		}
	}
	for (var i=0; i<obj.value.length; i++)
	{
	  if (obj.value.charAt(i) == ',')
	    if ((obj.value.length-(i+1) > 3) || (obj.value.length-(i+1) == 0))
	    {
		alert ("Sólo se admiten tres decimales.");
		obj.value = "";
		obj.focus ();
	      return false;
	    }
      }

	return true;
}
function ValidoEmail(email) { 
	 if ( email.value.length != 0) { if (!emailCheck(email.value)) { alert('La dirección de correo electronico (Email) no es valida'); email.focus (); return false; } }
} 
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
  } // Ends the "trim" function

 function emailCheck (emailStr) {
		var emailPat=/^(.+)@(.+)$/ 
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 
		var validChars="\[^\\s" + specialChars + "\]" 
		var quotedUser="(\"[^\"]*\")" 
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) { return false; }
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) { return false; }
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IAPArray[i]>255) { return false; }
			}
			return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) { return false; }
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (len<2) { return false; }
		return true;
	}
function CompruebaCIF(elCIF) 
{
 var resul = false;
  var temp = elCIF.toUpperCase(); // pasar a mayúsculas

  if (!/^[A-Za-z0-9]{9}$/.test(temp))  // Son 9 dígitos? 

     return ("CIF debe tener 9 digitos");

  else if (!/^[ABCDEFGHKLMNPQSW]/.test(temp)) // Es una letra de las admitidas ?

     return ("CIF debe comenzar por: A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S,W ");

  else 



  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;

  
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(elCIF.substr(i-1,1)) ];
      temp = temp + parseInt(elCIF.substr(i,1));
    };

  temp = temp + v1[ parseInt(elCIF.substr(7,1)) ];

  temp = (10 - ( temp % 10));
	
	
  if( temp == 10 ) {
	if ((elCIF.substr(8,1) == "J" ) || (elCIF.substr(8,1) == "0" ) ) { return (""); }
	}	
  if (elCIF.substr(8,1) == temp ) { return (""); }
	
  return "digitos CIF erroneo";
}

function checkFecha	(dia, mes, año)
{
 
   if ( (mes < 1) || (mes) > 12 )
	return ("Mes erroneo ");
  else if (parseFloat (dia)	< 1)
	return ("Día erroneo ");
  else if (parseFloat (mes)	== 2)
  {
		if (Bisiesto (parseFloat (año)))
		{
			if (parseFloat (dia) > 29)
				return ("Día erroneo ");
		}
		else if (parseFloat (dia) > 28)
			return ("Día erroneo ");
	}
  else if (	((mes == 4)	|| (mes	== 6) || (mes == 9)	|| (mes	== 11))	&& (dia	>= 31) )
	return ("Día erroneo ");
  else if (dia > 31)
	return ("Día erroneo ");
	
	if ((parseFloat(año) < 2004) || (parseFloat(año) > 2100)) return (" Año fuera de limites");
	
	

return "";

}
function Bisiesto (año)
{
  if ( ( (año%4 ==	0) && (año%100	!= 0) )	|| (año%400 ==	0) ) return	true;
  else return false;
}	 