function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   if (sText.length<=0 ) { return false; }
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function PasaAEntero(formulario, nombre, valor) {
	if (IsNumeric(valor)) { var intval = parseFloat(valor); } else { return ""; }
	document.getElementById(nombre).value =intval;
}

function isDate(f) {
	/* la forma de verificar el formato es la que ya comentamos */
	re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
	if(f.length==0 || !re.exec(f)) { return false; }
	/* comprobamos que la fecha es vï¿½lida */
	var d = new Date()
	/* la funciï¿½n tiene como entrada: aï¿½o, mes, dï¿½a */
	d.setFullYear(f.substring(6,10), f.substring(3,5)-1, f.substring(0,2))
	 
	/* ï¿½el mes del objeto Date es el mes introducido por el usuario?
	   OJO: getMonth() devuelve el nï¿½mero de mes del 0 al 11
	 
	   ï¿½el dï¿½a del objeto Date es el dï¿½a introducido por el usuario?
	   OJO: getDate() devuelve el dï¿½a del mes */
	if(d.getMonth() != f.substring(3,5)-1 || d.getDate() != f.substring(0,2)) { return false; }
	return true;	
}
function ValidarEmail(email) 
{
	var invalidChars
	var badChar
	var atPos
	var PeriodPos
	
	invalidChars=" /:,;";
	if (email == "") { return false }
	for (i=0; i<invalidChars.length; i++) {
		badChar=invalidChars.charAt(i)
		if (email.indexOf(badChar,0)>-1) { return false }
	}
	atPos= email.indexOf("@",1)
	if (atPos == -1) { return false }
	if (email.indexOf("@",atPos+1) > -1) { return false }
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) { return false }
	if (periodPos+3 > email.length) { return false }
	return true

}
function letraDni (numero,destino) { 
	var letra="";
	var idestino=document.getElementById(destino);
	idestino.value=letra;
	if (numero.length==0) {  return; }
	if (numero.length!=8) {  return; }
	if (!IsNumeric(numero)) {  return; }
	cadena="TRWAGMYFPDXBNJZSQVHLCKET" 
	posicion = numero % 23 
	letra = cadena.substring(posicion,posicion+1) 
	idestino.value=letra;
	return;
} 


function printPage() {
  if (confirm("¿Desea imprimir la pagina?")) {  window.print();  }
}

function openNewWindow(URLtoOpen,windowName, windowFeatures) {
 newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}

function aleatorio(inferior,superior){ 
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.round(aleat) 
    return parseInt(inferior) + aleat 
} 


function CodigoAleatorio (longitud) { 
	var codigo="";
	var cadena="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789" 
	var posicion;
	var letra="";
	if (!IsNumeric(longitud)) { return; }
	for (i=1;i<=longitud;i++) {	
		posicion = aleatorio(1,62)
		letra = cadena.substring(posicion,posicion+1) 
		codigo=codigo+letra;	
	}
	return codigo;
} 

function EstadoHorarioLaboral(strEstado, formulario) { 
	if (document.getElementById(formulario.cofinanciado.id).value=="0") {
		document.getElementById(formulario.hinimannana.id).value="";
		document.getElementById(formulario.minimannana.id).value="";
		document.getElementById(formulario.hfinmannana.id).value="";
		document.getElementById(formulario.mfinmannana.id).value="";
		document.getElementById(formulario.hinitarde.id).value="";
		document.getElementById(formulario.minitarde.id).value="";
		document.getElementById(formulario.hfintarde.id).value="";
		document.getElementById(formulario.mfintarde.id).value="";
	}
}

function EstadoValoresTutoria(formulario) { 

	var vTutorizado=document.getElementById(formulario.tutorizar.id).value;
	if (!IsNumeric(vTutorizado) || vTutorizado<0) { return; }
	//Si es Tutorizado => habilitamos los campos de Fecha, Horas del Curso y Cofinanciaciï¿½n...
	var cbolEstado =false;
	if (vTutorizado==0) { cbolEstado=true; } 
		
	
	//formulario.FINICIO.disabled=cbolEstado;
	//formulario.FFIN.disabled=cbolEstado;
	formulario.cofinanciado.disabled=cbolEstado;
	//formulario.horas.disabled=cbolEstado;
	formulario.hinimannana.disabled=cbolEstado;
	formulario.minimannana.disabled=cbolEstado;
	formulario.hfinmannana.disabled=cbolEstado;
	formulario.mfinmannana.disabled=cbolEstado;
	formulario.hinitarde.disabled=cbolEstado;
	formulario.minitarde.disabled=cbolEstado;
	formulario.hfintarde.disabled=cbolEstado;
	formulario.mfintarde.disabled=cbolEstado;
		
	//document.getElementById(formulario.FINICIO.id).value="";
	//document.getElementById(formulario.FFIN.id).value="";
	document.getElementById(formulario.cofinanciado.id).selectedIndex=1;
	//document.getElementById(formulario.horas.id).value="";
	document.getElementById(formulario.hinimannana.id).value="";
	document.getElementById(formulario.minimannana.id).value="";
	document.getElementById(formulario.hfinmannana.id).value="";
	document.getElementById(formulario.mfinmannana.id).value="";
	document.getElementById(formulario.hinitarde.id).value="";
	document.getElementById(formulario.minitarde.id).value="";
	document.getElementById(formulario.hfintarde.id).value="";
	document.getElementById(formulario.mfintarde.id).value="";
	
}

function comprobarCIF(valor)
{
	
	var url="/js/ajax/comprobar_cif.php?valor="+valor;
	var ajax=nuevoAjax();
	ajax.open("POST",url, false);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(null);
	var strdevuelto=ajax.responseText;
	var indCar=strdevuelto.indexOf(";");
	var intError=strdevuelto.slice(0,indCar);
	if (intError==1) { alert (strdevuelto.slice(indCar+1,strdevuelto.length));return} 
	else 
	{	
		vresultado=strdevuelto.slice(indCar+1,strdevuelto.length);
		return(vresultado);

	}	
}
function submitintro(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}




