// JScript File
  var CharSeparadorDecimal;
  var CharNumerico;
  var CharOperacion;
  var CharLetras;
  var CharPuntuacion;
  var CharAcentuacion;
  var CharEspeciales;
  var CharParentesis;
  
  var CharAlfaNumericos;
  var CharFono;
  var CharEmail;
  var CharFecha;
  var CharHora;
  
  var GBLVALSelect = false;				//Es true cuando se selecciona el texto en un input o area

    CharSeparadorDecimal = ",";
    CharNumerico = "0123456789.,-";
    CharOperacion = "+-*/";
    CharLetras = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuioplkjhgfdsazxcvbnmáéíóúÁÉÍÓÚ ";
    CharPuntuacion = ".,:";
    CharAcentuacion = "´`^¨";
    CharEspeciales = "_-ºª!¡·#$%@¬=¿?\ç\Ç";
    CharParentesis = "()[]{}";
    
    CharTodos  = CharNumerico + CharOperacion + CharLetras + CharPuntuacion + CharAcentuacion + CharEspeciales + CharParentesis;
    CharFono   = CharNumerico + CharParentesis;
    CharEmail  = CharNumerico + CharLetras + ".@";
    CharFecha  = "0123456789/";
    CharHora   = "0123456789:"
    CharRut    = "0123456789Kk";
    CharRutDig = "0123456789Kk";


function ObjIniciarVal(Obj)
{
    if(Obj)
    {
	    var cadenaF,posF;
    
        //Declara la Funcion al presionar Teclas
		Obj.onkeypress = new Function("ObjKeyPress(this);");
    
        //Declara la Funcion al perder el focus y concerva la funcion existente
		cadenaF = Obj.onblur + "";
		posF = cadenaF.indexOf("{");
		
		if(posF != -1)
		{
			cadenaF = cadenaF.substring(posF + 1,cadenaF.length - 1);
	    }
	    else
	    {
			cadenaF = "";
		}
		
		Obj.onblur = new Function("ObjValidar(this);" + cadenaF);
	    
	    //Declara la Funcion para no mostrar el menu Secundario sobre el objeto
	    Obj.oncontextmenu = new Function("return false;");
	    
	    //Declara la Función de Seleccion del Texto
        Obj.onselectstart = new Function("GBLVALSelect = true;");
    
        if(Obj.Formato.substring(Obj.Formato.length - 1,Obj.Formato.length) == "R")
		    SacaGuion(Obj);
        else if( Obj.Formato == "+12.0N")
            val_DesFormateaNumeroMA(Obj);

        
	
        if(Obj.Mascara)
        {
            if(Obj.value == Obj.Mascara)
                Obj.select();
        }
    }
}

function ObjKeyPress(Obj)
{
  var Cod = event.keyCode;
  var Tec = String.fromCharCode(event.keyCode);
  var Tipo,Largo,TipoDato;
  
  TipoDato = Obj.Formato;  
  
  if(TipoDato == "D"){   //Tipo de Dato Fecha
    TipoDato = "10D";
  }
  if(TipoDato == "H"){   //Tipo de Dato Hora
    TipoDato = "8H";
  }
  
  Tipo = TipoDato.substring(TipoDato.length - 1,TipoDato.length);
  Largo = TipoDato.substring(0,TipoDato.length - 1);
  
  if("AXNDRVH".indexOf(Tipo) == -1 || isNaN(Largo) == true){
    event.returnValue = "";
    return false;
  }  
  
  switch(Tipo.toUpperCase()){
    case "A":
        //Tipo Alfabético
        Largo = parseFloat(Largo);
        CharValidos = CharLetras;
        if(CharValidos.indexOf(Tec) == -1 && "|13|32|225|233|237|243|250|193|201|205|211|218|241|209|".indexOf("|"+Cod+"|") == -1){
          event.returnValue = "";
          return false;
        }
        if(--Largo < Obj.value.length && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
        break;
    case "N":
        //Tipo de Dato Numérico
        if(TipoDato.substring(0,1) == "+")
        {
            Largo = Largo.substring(1);
            CharValidos = CharNumerico.substring(0,CharNumerico.length - 1); //Menos el -
        }
        else
        {
            CharValidos = CharNumerico;   //Con el signo -
        }        
        //Signo Númerico
        Sig = 0;
        if(TipoDato.substring(0,1) == "-")
        {
            Largo = Largo.substring(1);
            Sig = 1;
        }
        
        if(TipoDato.substring(0,1) != "+"){
            Sig = 1;
        }
        
        //Tecla No Valida
        if(CharValidos.indexOf(Tec) == -1)
        {
            event.returnValue = "";
            return false;
        }
        
        //Largo del Número
        Aux = parseInt(Largo) + "";
        Largo += "";
        
        if(Largo.indexOf(".") != -1)
        { //.
            Aux = parseInt(Aux) + parseInt(Largo.substring(Largo.indexOf(".") + 1)); //.
        }
        else
        {
          //alert(parseInt(Aux) + parseInt(Sig));
        }
        
        if(Obj.value.length == parseInt(Aux) + parseInt(Sig) && GBLVALSelect == false)
        {
          event.returnValue = "";
          return false;
        }
        
        break;

    case "D":
        //Tipo Fecha = dd/mm/aaaa
        CharValidos = CharFecha;
        if(CharValidos.indexOf(Tec) == -1){
          event.returnValue = "";
          return false;
        }        
        if(Largo <= Obj.value.length && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
        break;
    case "R":
		//Hora con formato = hh:mm:ss
		CharValidos = CharRut;
        if(CharValidos.indexOf(Tec) == -1){
          event.returnValue = "";
          return false;
        }
        if(--Largo < Obj.value.length && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
		break;
    case "V":
		//Digito Verificador del Rut
		CharValidos = CharRutDig;
        if(CharValidos.indexOf(Tec) == -1){
          event.returnValue = "";
          return false;
        }
        if(Obj.value.length >= 1 && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
		break;
	case "H":
		//Tipo Hora = hh:mm:ss
        CharValidos = CharHora;
        if(CharValidos.indexOf(Tec) == -1){
          event.returnValue = "";
          return false;
        }        
        if(Largo <= Obj.value.length && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
		break;
    default:
        //Tipo AlfaNumérico
        CharValidos = CharTodos;
        
        if(CharValidos.indexOf(Tec) == -1 && "|13|32|225|233|237|243|250|193|201|205|211|218|241|209|".indexOf("|"+Cod+"|") == -1){
          event.returnValue = "";
          return false;
        }        
        if(--Largo < Obj.value.length && GBLVALSelect == false){
          event.returnValue = "";
          return false;
        }
  }
  GBLVALSelect = false;
}

function ObjValidar(Obj)
{
    var Tipo,Largo;
    var newText = "";
  
    GBLVALSelect = false;
  
    TipoDato = Obj.Formato;
    if(TipoDato == "D")
    {	 //Tipo de Dato Fecha
        TipoDato = "10D";
    }
    if(TipoDato == "H")
    {   //Tipo de Dato Hora
        TipoDato = "8H";
    }
    
    Tipo = TipoDato.substring(TipoDato.length - 1,TipoDato.length);
    Largo = TipoDato.substring(0,TipoDato.length - 1);
  
    switch(Tipo.toUpperCase())
    {
        case "A":
            //Tipo Alfabético
            for(i=0;(i < Obj.value.length);i++)
            {
		        if(CharLetras.indexOf(Obj.value.substring(i,i+1)) != -1 || "|13|32|225|233|237|243|250|193|201|205|211|                     218|241|209|".indexOf("|"+ Obj.value.substring(i,i+1).charCodeAt(0) +"|") != -1)
		        {
		            newText += Obj.value.substring(i,i+1);
		        }
            }
        
            Obj.value = newText.substring(0,parseInt(Largo));
        break;
        
        case "N":
            //Tipo Numérico
            Decimal = 0;
            
            // formato de ejemplo +12.0N
            // Tipo = TipoDato.substring(TipoDato.length - 1,TipoDato.length);
            //==== Encuentra el Largo del Numero
            if(TipoDato.substring(0,1) == "-" || TipoDato.substring(0,1) == "+")
            {
                Largo = parseFloat(Largo.substring(1));
            }
            
            Largo += "";
            Entero = parseInt(Largo);
            
            
            if(Largo.indexOf(".") != -1)
            { //.
                Decimal = Largo.substring(Largo.indexOf(".") + 1); //.
            }
            
            AuxNum = FormatoNumero2(Obj.value,Entero,Decimal);
            
            if(TipoDato.substring(0,1) == "-")
            {
                if(AuxNum > 0)
                {
                    AuxNum = AuxNum * -1;
                }
            }
            else
            {
                if(TipoDato.substring(0,1) == "+" && AuxNum < 0)
                {
		            AuxNum = AuxNum * -1;
                }
            }
            
            //Obj.value = val_FormateaNumero(AuxNum);
             if (Obj.isFormat =="true")
                AuxNum = val_addCommas2(AuxNum);
            
            //Completa decimales
            if(Decimal == 2 && AuxNum != "")
            {
                //alert(AuxNum + "=" + AuxNum.lastIndexOf(","))
                switch(AuxNum.lastIndexOf(","))
                {
                    case -1:
                        AuxNum += ",00";
                        break;
                    case AuxNum.length - 2:
                        AuxNum += "0";
                }
            }
            
            Obj.value = AuxNum;
            
            break;
        
        case "D":
            //Tipo Fecha = dd/mm/aaaa
            var Array;
            
            //==== Quita Caracteres no Válidos
            for(i=0;(i < Obj.value.length);i++){
		      if(CharFecha.indexOf(Obj.value.substring(i,i+1)) != -1){
		        newText += Obj.value.substring(i,i+1);
		      }
            }
            
            Obj.value = Array = newText;
            if(Array == ""){
              break;
            }
            
            Array = Array.split("/")
            
            if(Array.length != 3){
              alert("Fecha no válida");
              Obj.value = "";
              return false;
            }
            
            if(Array[0] < 1 || Array[0] > 31){
              alert("El día no es válido");
              Obj.value = "";
	          return false;
            }
            if(Array[1] < 1 || Array[1] > 12){
              alert("El mes no es válido");
              Obj.value = "";
	          return false;
            }
            if(Array[2] < 1000 || Array[2] > 3000){
              alert("El año no es válido");
              Obj.value = "";
	          return false;
            }
            
            if ((Array[1]==4 || Array[1]==6 || Array[1]==9 || Array[1]==11 || Array[1]==2) && Array[0]==31) {
              //Mes de dias inferiores
	          alert("El mes " +  strMes(Array[1])  + " no tiene 31 días");
	          Obj.value = "";
	          return false;
            }

            if (Array[1] == 2) { 
	          var isleap = (Array[2] % 4 == 0 && (Array[2] % 100 != 0 || Array[2] % 400 == 0));
	          if (Array[0]>29 || (Array[0]==29 && !isleap)) {
	            //Febrero de dias inferior (Año visiesto)
	            if (!isleap){
		          alert("Febrero no tiene 29 días");
		          Obj.value = "";
	              return false;
	            }else{
	              alert("Febrero no tiene 30 días");
		          Obj.value = "";
	              return false;
	            }
	          }
            }       
            break;
        case "R":
		    //Rut Continuado (Ingresado en un solo Text: 99999999k)
            for(i=0;(i < Obj.value.length);i++){
		      if(CharRut.indexOf(Obj.value.substring(i,i+1)) != -1){
		        newText += Obj.value.substring(i,i+1);
		      }
            }
            
            if(newText == ""){
              Obj.value = newText;
              break;
            }
            
            //==== Valida el Rut
            var rut="";var dig="";
		    largo = newText.length;
    		
		    newText = newText.substring(0, newText.length - 1) + "-" + newText.substring(newText.length - 1);
    		
		    rut = newText.substring(0,newText.indexOf("-")) + "";
		    dig = newText.substring(newText.indexOf("-")+1) + "";
    		
		    //====Valida qie sean Numero
		    rut = parseInt(rut);
		      if(isNaN(rut)){
			    alert("El Rut ingresado no es Válido");
			    Obj.value = "";
			    Obj.focus();
		        break;
		      }else
		        rut = rut + "";
		    if(dig.toLowerCase() != "k" && dig != ""){
		      dig = parseInt(dig);
		      if(isNaN(dig)){
				    alert("El Dígito Verificador no es Válido");
				    Obj.value = "";
			        Obj.focus();
				    break;
		      }else
		        dig = dig + "";
		    }
    		
		    suma = 0;
		    mul  = 2;
		    dvr = "";

		    for (i=rut.length -1;(i >= 0);i--){
		      suma = suma + rut.charAt(i) * mul;
		      if (mul == 7)
		        mul = 2;
		      else
		        mul++;
		    }
    		
		    res = suma % 11;
		    if (res==1)
		      dvr = 'K';
		    else 
		      if (res==0)
		       dvr = '0';
	          else{
		        dvr = eval(11-res) + "";
		      }
    		
		    if(dig == ""){
		      dig = dvr;
		    }
    		
		    //====Compara el Digito Verificador ingresado por el User con el calculado
		    if (dig != dvr){
		      alert("EL Rut ingresado no es correcto.");
		      Obj.value = rut + "" + dig;
		      Obj.select();
		      Obj.focus();
            }else{
			    Obj.value = rut + "-" + dig;
		    }
		    break;
        case "V":
		    //Digito Verificador del Rut
            for(i=0;(i < Obj.value.length);i++){
		      if(CharRutDig.indexOf(Obj.value.substring(i,i+1)) != -1){
		        newText += Obj.value.substring(i,i+1);
		      }
            }
            
            Obj.value = newText.substring(0,1);
		    break;
		
    default:
        //Tipo AlfaNumérico
        for(i=0;(i < Obj.value.length);i++){
		  if(CharTodos.indexOf(Obj.value.substring(i,i+1)) != -1 || "|13|32|225|233|237|243|250|193|201|205|211|218|241|209|".indexOf("|"+ Obj.value.substring(i,i+1).charCodeAt(0) +"|") != -1){
		    newText += Obj.value.substring(i,i+1);
		  }
        }
        
        Obj.value = newText.substring(0,parseInt(Largo));
  }
  
  var cadenaF,posF;
  
  cadenaF = Obj.onblur + "";
  posF = cadenaF.indexOf(";");
  cadenaF = cadenaF.substring(posF + 1,cadenaF.length - 1);
  
  Obj.onblur = new Function(cadenaF);
  Obj.onkeypress = "";
  
  if(Obj.Mascara){
    if(Obj.value == "")
      Obj.value = Obj.Mascara;
  }
  
}

function FormatoNumero2(Numero,CantEntero,CantDecimal)
{
    var Enteros,Decimales,Sig=0;
    var sCompletaDecimales;
    Num = Numero + "";
    Enteros = Decimales = "";

    if(Num.length == 0)
    {
        return "";
    }
    
    if(Numero.indexOf("-") == 0)
    {
        Sig = 1;
    }

    //Saca los puntos separadores de miles y soloca separador decimal ,
    Num = val_DesFormateaNumero(Numero)

    //Recorre los Digitos Enteros
    for(i=0;(i < CantEntero + Sig && i != Num.length);i++)
    {
        if(Num.substring(i,i+1) == ".") //"."
            break;
    
        Enteros = Enteros + Num.substring(i,i+1);
    }

    //Recorre los Numeros decimales
    if(Num.indexOf(".") != -1)
    { //"."
        Num = Num.substring(Num.indexOf(".")+1); //"."
        
        for(i=0;(i < CantDecimal && i != Num.length);i++)
        {
            if(Num.substring(i,i+1) != ".") //"."
                Decimales = Decimales + Num.substring(i,i+1);
        }
        
        Decimales = "." + Decimales; //"."
    }

    Total = parseFloat(Enteros + Decimales);
    
    if(isNaN(Total))
    {
        Total = "";
    }   

    return Total;
 } 
 
 function strMes(numMes){
	switch(parseFloat(numMes)){
		case 1:
				return "Enero";
				break;
		case 2:
				return "Febrero";
				break;
		case 3:
				return "Marzo";
				break;
		case 4:
				return "Abril";
				break;
		case 5:
				return "Mayo";
				break;
		case 6:
				return "Junio";
				break;
		case 7:
				return "Julio";
				break;
		case 8:
				return "Agosto";
				break;
		case 9:
				return "Septiembre";
				break;
		case 10:
				return "Octubre";
				break;
		case 11:
				return "Noviembre";
				break;
		case 12:
				return "Diciembre";
				break;
	}
 
 }
 //=====================================================================================
 //	Combierte en un numero la fecha dd/mm/yyyy => yyyymmdd
function FechaNumero(objFecha)
{
	var vector,pos,Fnumero = "";
	vector = objFecha.split("/");
	
	for(pos=vector.length - 1;(pos >= 0);pos--)
	{
		vector[pos] += "";
		if(vector[pos].length == 1)
            Fnumero += "0" + vector[pos];
		else
		    Fnumero += vector[pos];
		
	}
	return parseInt(Fnumero);
}

function FormatoFecha(strFecha)
{
	var vecFecha = strFecha.split("/");
	        
	if(vecFecha.length != 3){
		return "Fecha no válida";
	}
	        
	if(vecFecha[0] < 1 || vecFecha[0] > 31){
		return "El día no es válido";
	}
	
	if(vecFecha[1] < 1 || vecFecha[1] > 12){
		return "El mes no es válido";
	}
	
	if(vecFecha[2] < 1000 || vecFecha[2] > 3000){
		return "El año no es válido";
	}
	        
	if((vecFecha[1]==4 || vecFecha[1]==6 || vecFecha[1]==9 || vecFecha[1]==11 || vecFecha[1]==2) && vecFecha[0]==31){
		return "El mes no tiene 31 días";
	}

	if(vecFecha[1] == 2){ 
		var isleap = (vecFecha[2] % 4 == 0 && (vecFecha[2] % 100 != 0 || vecFecha[2] % 400 == 0));
		if (vecFecha[0] > 29 || (vecFecha[0] == 29 && !isleap))
			if (!isleap) return "Febrero no tiene 29 días";
			else return "Febrero no tiene 30 días";
	}
	return "";
}

function SacaGuion(objText)
{
	var Rut;
	
	if(objText.value.indexOf("-") > -1){
		Rut = objText.value.substring(0,objText.value.indexOf("-")) + "";
		Rut+= objText.value.substring(objText.value.indexOf("-")+1) + "";
		objText.value = Rut;
		objText.select();
	}
}

function val_DesFormateaNumero(strNumero)
{
    var numero;
    numero = val_StringReplace(strNumero,".","");
    numero = val_StringReplace(numero,",",".");
    
    return numero;
 }

function val_DesFormateaNumeroMA(objNumero)
{
    var numero;
    numero =  objNumero.value
    if(numero.indexOf(".") > -1)
    {
        numero = val_StringReplace(numero,".","");
        numero = val_StringReplace(numero,",","");
    }        
    objNumero.value = numero;
	objNumero.select();
 }

function val_StringReplace(originalString, findText, replaceText) {  
    originalString = originalString + "";
    var pos = 0;
    var len = findText.length;
    var limit = originalString.length;
    var i= 0;
    pos = originalString.indexOf(findText);
    
    while (pos != -1 && i < limit){
        preString = originalString.substring(0, pos);
        postString = originalString.substring(pos+len, originalString.length);
        originalString = preString + replaceText + postString;
        pos = originalString.indexOf(findText); 
        i++;
    }
    return originalString; 
}

function val_FormateaNumero(Numero)
{
    return val_addCommas2(Numero);
}
   
function val_addCommas(nStr){
    nStr += ''; 
    x = nStr.split(','); 
    x1 = x[0]; 
    x2 = x.length > 1 ? ',' + x[1] : ''; 
    var rgx = /(\d+)(\d{3})/; 
    while (rgx.test(x1)) { 
        x1 = x1.replace(rgx, '$1' + '.' + '$2'); 
    } 
    return x1 + x2; 
}

function val_addCommas2(nStr){ 
    nStr += ''; 
    x = nStr.split('.'); 
    x1 = x[0]; 
    x2 = x.length > 1 ? ',' + x[1] : ''; 
    var rgx = /(\d+)(\d{3})/; 
    while (rgx.test(x1)) { 
        x1 = x1.replace(rgx, '$1' + '.' + '$2'); 
    }
    return x1 + x2; 
}

////////////////////////////////////////////////////////////////////////////
/////FUNCION PARA QUE LOS TEXTBOX SOLO PERMITAN INGRESAR NUMEROS////////////
function validar_numero(e) 
{
    tecla = (document.all)?e.keyCode:e.which;

    if (tecla==8) return true;
    
    patron = /\d/;
    
    return patron.test(String.fromCharCode(tecla));
}
////////////////////////////////////////////////////////////////////////////

////////////////////FECHAS se llama primero a Formato(control)/////////////
/**
* script para validar fechas en una caja de texto.
*/

/**
* definimos las varables globales que van a contener la fecha completa, cada una de sus partes
* y los dias correspondientes al mes de febrero segun sea el año bisiesto o no
*/
var a, mes, dia, anyo, febrero;

/**
* funcion para comprobar si una año es bisiesto
* argumento anyo > año extraido de la fecha introducida por el usuario
*/
function anyoBisiesto(anyo)
{
/**
* si el año introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
*/
if (anyo < 100)
var fin = anyo + 1900;
else
var fin = anyo ;

/*
* primera condicion: si el resto de dividir el año entre 4 no es cero > el año no es bisiesto
* es decir, obtenemos año modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
*/
if (fin % 4 != 0)
return false;
else
{
if (fin % 100 == 0)
{
/**
* si el año es divisible por 4 y por 100 y divisible por 400 > es bisiesto
*/
if (fin % 400 == 0)
{
return true;
}
/**
* si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
*/
else
{
return false;
}
}
/**
* si es divisible por 4 y no es divisible por 100 > el año es bisiesto
*/
else
{
return true;
}
}
}

/**
* funcion principal de validacion de la fecha
* argumento fecha > cadena de texto de la fecha introducida por el usuario
*/
function validar(oTxt)
{
/**
* obtenemos la fecha introducida y la separamos en dia, mes y año
*/
    a=oTxt.value;
    dia=a.split("-")[0];
    mes=a.split("-")[1];
    anyo=a.split("-")[2];
    if( (isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) )
    {
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
    
    if(anyoBisiesto(anyo))
        febrero=29;
    else
        febrero=28;
/**
* si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecucion
*/
    if ((mes<1) || (mes>12))
    {
        //alert("El mes introducido no es valido. Por favor, introduzca un mes correcto");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes introducido es febrero y el dia es mayor que el correspondiente
* al año introducido > alertamos y detenemos ejecucion
*/
    if ((mes==2) && ((dia<1) || (dia>febrero)))
    {
        //alert("El día introducido no es valido. Por favor, introduzca un día correcto");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes introducido es de 31 dias y el dia introducido es mayor de 31 > alertamos y detenemos ejecucion
*/
    if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31)))
    {
        //alert("El día introducido no es valido. Por favor, introduzca un día correcto");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes introducido es de 30 dias y el dia introducido es mayor de 301 > alertamos y detenemos ejecucion
*/
    if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30)))
    {
        //alert("El día introducido no es valido. Por favor, introduzca un día correcto");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes año introducido es menor que 1900 o mayor que 2010 > alertamos y detenemos ejecucion
* NOTA: estos valores son a eleccion vuestra, y no constituyen por si solos fecha erronea
*/
    if ((anyo<1900) || (anyo>2099))
    {
        //alert("El año introducido no es valido. Por favor, introduzca un año entre 1900 y 2010");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
}

//Formatea la fecha entregada.	
function Formato(oText)
{
    var texto, texto2, dia, mes, anho, i, a;
    texto =oText.value;
    if(texto != '')
    {
        while(texto.indexOf('/') != -1)
        { 
            texto = texto.replace("/","");  
        }
        
        while(texto.indexOf('-') != -1)
        { 
            texto = texto.replace("-","");  
        }
        
        dia   =texto.substring(0,2);
        mes   =texto.substring(2,4);
        anho  =texto.substring(4,8);
        oText.value=dia + "-" + mes + "-" + anho;
        validar(oText);
    }
}


/**
* funcion principal de validacion de la fecha mm-yyyy
* argumento fecha > cadena de texto de la fecha introducida por el usuario
*/
function validar_fecha_mes_anho(oTxt)
{
/**
* obtenemos la fecha introducida y la separamos en dia, mes y año
*/
    a=oTxt.value;
    mes=a.split("-")[0];
    anyo=a.split("-")[1];
    if((isNaN(mes)==true) || (isNaN(anyo)==true) )
    {
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecucion
*/
    if ((mes<1) || (mes>12))
    {
        //alert("El mes introducido no es valido. Por favor, introduzca un mes correcto");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
/**
* si el mes año introducido es menor que 1900 o mayor que 2010 > alertamos y detenemos ejecucion
* NOTA: estos valores son a eleccion vuestra, y no constituyen por si solos fecha erronea
*/
    if ((anyo<1900) || (anyo>2099))
    {
        //alert("El año introducido no es valido. Por favor, introduzca un año entre 1900 y 2010");
        alert("La fecha introducida debe estar formada sólo por números y debe ser válida.");
        oTxt.value=""
        oTxt.focus();
        return;
    }
}

//Formatea la fecha entregada como (mm-yyyy).
function Formato_Mes_Anho(oText)
{
    var texto, mes, anho, i, a;
    texto =oText.value;
    if(texto != '')
    {
        while(texto.indexOf('/') != -1)
        { 
            texto = texto.replace("/","");  
        }
        
        while(texto.indexOf('-') != -1)
        { 
            texto = texto.replace("-","");  
        }
        
        mes = texto.substring(0,2);
        anho = texto.substring(2,6);
        oText.value = mes + "-" + anho;
        validar_fecha_mes_anho(oText);
    }
}

//////////////////////////////////////////////////////////

//Reemplaza los caracteres de al cadena enviada.
function ReemplazarCaracter(oText)
{
    var Texto, TextoRetorno;
    Texto = oText.value;
    
    if(oText!='')
    {
      oText.value = Texto.replace(".",",");  
    }
    return
}

////////////////////////////////////////////////////////////
//Comprueba el largo del textbox, y si es mayor a lo esperado no deja escribir mas, es mas usado en los textox 
//Multiline.
function Comprobar_Lon(obj, maximo)
{
    var lon; 
    lon=obj.value;

    if (lon.length > maximo)
    {
      window.event.keyCode=27
    } 
}

//function calcularEdad(obj)
//{
//    var edad ;
//    var facnac = Date.parse(obj.value);
//    alert(obj.value);
//    
//    //edad = DateTime.Today.Year - fechanac.Year;
//     //   if (new DateTime(DateTime.Today.Year, fechanac.Month, fechanac.Day) > DateTime.Today)
//       //     edad--;
//     
//    //return edad.ToString();
//}

