/*  **********************************************************************************************************************************************************************  */
/*  ************************************************   FUNCIONES DE CONTROL DE FORMULARIOS EN JAVASCRIPT   ***************************************************************  */
/*  **********************************************************************************************************************************************************************  */
//Funcion que solo permite introducir cantidades numericas (incluidos decimales) en un campo   -------------------------------------------------------------------------------
function MascaraNumeros(control){
	if (window.event.keyCode!=13)
		if (window.event.keyCode>47 && window.event.keyCode<58)
			window.event.returnValue=true;
		else
			if (window.event.keyCode==44)
				window.event.returnValue=true;
			else
				window.event.returnValue=false;
}
/*  **********************************************************************************************************************************************************************  */
//Funcion que solo permite introducir numeros en un campo   ------------------------------------------------------------------------------------------------------------------
function MascaraSoloNumeros(control){
	if (window.event.keyCode!=13)
		if (window.event.keyCode>47 && window.event.keyCode<58)
			window.event.returnValue=true;
		else
			window.event.returnValue=false;	
}
/*  **********************************************************************************************************************************************************************  */
//FUNCION QUE ELIMINA LOS ESPACIOS EN BLANCO DE UNA CADENA  -----------------------------------------------------------------------------------------------------------------
function fEliminaEspacios(cad){
	var baux, vres="";
	//Controlamos si la cadena es vacia
	if (cad.length != 0 || cad.value != null){
		//Recorremos la cadena
		for (var i=0; i < cad.length; i++){	
			(cad.charAt(i) == " ") ? baux = true : baux = false;
			if (i == 0){
				if (!baux){vres = cad.charAt(i);}
			}else{
				if (baux){
					if (cad.charAt(i-1) != " ")
						vres = vres + cad.charAt(i);
				}
				else
					vres = vres + cad.charAt(i);
			}
		}
	}
	return(vres);
}
/*  **********************************************************************************************************************************************************************  */
//Funcion que formatea a Fecha (dd//mm/yyyy) segun se teclee dentro de un campo    -------------------------------------------------------------------------------------------
function MascaraFecha(control){
	if (window.event.keyCode >= 45 && window.event.keyCode < 58){
		if (window.event.keyCode != 46){
			if (window.event.keyCode > 47 && window.event.keyCode < 58){	
					if (control.value.length == 2 || control.value.length == 5)
						control.value = control.value + "/";
			}
			if (window.event.keyCode == 47){								
					if (control.value.length != 2 && control.value.length != 5)
						window.event.returnValue = false;
			}
			if (window.event.keyCode == 45){							
				if (control.value.length == 2 || control.value.length == 5)
					control.value = control.value + "/";
				window.event.returnValue = false;
			}
		}
		else
			window.event.returnValue = false;
	}
	else
		window.event.returnValue = false;
}
/*  **********************************************************************************************************************************************************************  */
//Funcion que controla que una fecha sea correcta  ---------------------------------------------------------------------------------------------------------------------------
function EsFecha(cadena){
	var vfecha = new Array();
	var dias_meses = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	vfecha = cadena.split("/");
	if (vfecha.length == 3)
	{
		if ((vfecha[2] < 1900 || vfecha[2]>2100)  || (isNaN(vfecha[2])==true))
			return 0;
		if ((vfecha[1] < 1 || vfecha[1] > 12)  || (isNaN(vfecha[1])==true))
			return 0;
		if ((vfecha[0] < 1 || vfecha[0] > dias_meses[parseInt(vfecha[1]-1)])  || (isNaN(vfecha[0])==true))
			return 0;
		return 1;
	}
	else
		return 0;
}
/*  **********************************************************************************************************************************************************************  */