//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}

function isNull(val){
	return(val==null);
}
function isBlanco(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
}
function isCadena(val){
	var er_nombre = /^([a-z]|[A-Z]|á|é|í|ó|ú|ñ|ü|\s|\.|-)+$/			//letras, '.' y '-' o vacio
	if(!er_nombre.test(val)) { 
		return false;
	}   
	else{
		return true;
		}
}	
function isInteger(val){
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

function isDecimal(fieldValue) {
	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue) || fieldValue == "") {
		return false;
	}
	else {
		if (fieldValue.indexOf('.') == -1) 
			fieldValue += ".";
		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed){
			return false;
	    }
		else {
			return true;
	    }
	}
}

function isPorcentaje(fieldValue) {
	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue) || fieldValue == "") {
		return false;
	}
	else {
		if (fieldValue.indexOf('.') == -1) 
			fieldValue += ".";
		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed){
			return false;
	    }
		else if (fieldValue > 100){
			return false;
	    }
		else {
			return true;
	    }
	}
}

function isBisiesto(anyo)
    {
        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;
            }
        }
    }

    function isDate(value )
    {
       a=value;
       anyo=a.split("-")[0]; 
       mes=a.split("-")[1]; 
       dia=a.split("-")[2]; 
	   if( (isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) )  {
     		return false;
       }
       if(isBisiesto(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))
       {
           return false;
       }
       /**
       * 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)))
       {
           return false;
       }
       /**
       * 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)))
       {
           return false;
       }
       /**
       * 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)))
       {
           return false;
       }
       if ((anyo<1900) || (anyo>2010))
       {
           return false;
       } 
       return true;

	}    
//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

function isEmailAddress(cadena)
	{
	var s = cadena;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]*$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	else
		return false;
	}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}
//-------------------------------------------------------------------
// setFieldsToLowerCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToLowerCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toLowerCase();
		}
	}

var obj = null;
function fobj(pobj){
	obj = pobj;
}

//-------------------------------------------------------------------
// foto(path file)
//   Valida que la foto escogida de un directorio se valida
//-------------------------------------------------------------------
function isFoto(file) {
	extArray = new Array(".jpg",".gif");
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (allowSubmit) return true;
	else
		return false;
	document.forms[0].reset();
	document.forms[0].uploadfile.focus();
}	
//
// Para sumar o restar dias a fechas
//
  var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 

  function finMes(nMes, nAno){ 
   return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
  } 

   function padNmb(nStr, nLen, sChr){ 
    var sRes = String(nStr); 
    for (var i = 0; i < nLen - String(nStr).length; i++) 
     sRes = sChr + sRes; 
    return sRes; 
   } 

   function FormatoFecha(nDay, nMonth, nYear){ 
    var sRes; 
    sRes = padNmb(nYear, 4, "0") +"-" + padNmb(nMonth, 2, "0") + "-" +padNmb(nDay, 2, "0") ; 
    return sRes; 
   } 
    
  function incrementaFecha(sFec0){ 
   var nDia = parseInt(sFec0.substr(8, 2), 10); 
   var nMes = parseInt(sFec0.substr(5, 2), 10); 
   var nAno = parseInt(sFec0.substr(0, 4), 10); 
   nDia += 1; 
   if (nDia > finMes(nMes, nAno)){ 
    nDia = 1; 
    nMes += 1; 
    if (nMes == 13){ 
     nMes = 1; 
     nAno += 1; 
    } 
   } 
   return FormatoFecha(nDia, nMes, nAno); 
  } 

  function decrementaFecha(sFec0){ 
   var nDia = Number(sFec0.substr(8, 2)); 
   var nMes = Number(sFec0.substr(5, 2)); 
   var nAno = Number(sFec0.substr(0, 4)); 
   nDia -= 1; 
   if (nDia == 0){ 
    nMes -= 1; 
    if (nMes == 0){ 
     nMes = 12; 
     nAno -= 1; 
    } 
    nDia = finMes(nMes, nAno); 
   } 
   return FormatoFecha(nDia, nMes, nAno); 
  } 

  function sumaDiaFecha(sFec0, sInc){  
   var nInc = Math.abs(parseInt(sInc)); 
   var sRes = sFec0; 
   if (parseInt(sInc) >= 0) 
    for (var i = 0; i < nInc; i++) sRes = incrementaFecha(sRes); 
   else 
    for (var i = 0; i < nInc; i++) sRes = deccrementaFecha(sRes); 
   return sRes; 
  } 

function isCedula(num) {
	if (num.length!=10){return false;}
	return true;
	}


function validar (){
//matriz = new Array ();  
//matriz[0] = new Array ('e00', 'e01', 'e02');  
//matriz[1] = new Array ('e10', 'e11', 'e12');  
//matriz[2] = new array ('e20', 'e21', 'e22'); 
//Y sabiendo que matriz[0] es new Array ('e00', 'e01', 'e02'), tenemos que si queremos acceder a e01, haremos //matriz[0][1].

	/*obj = new Array ();  
	obj[0] = new Array ('USUARIO', 1, 'D');  
	obj[1] = new Array ('PASSWORD', 1, 'C');  */

	var mensaje = "Informacion Inconsistente: \n";
	var retorno = true;

	for (i = 0;i < document.FormPrincipal.length; i++) {
			var nombrecampo = null;
			var requerido = null;
			var tipodato = null;
			var descripcioncampo = null;
   	    	var tempObj = document.FormPrincipal.elements[i];
			var tname = tempObj.name.toUpperCase();

			var tvalue = tempObj.value;
			for(var j=0;j<obj.length;j++) { 
					 nombrecampo = obj[j][0];
					 requerido = obj[j][1];
					 tipodato = obj[j][2];
					 descripcioncampo = obj[j][3];
 					 if (tname == nombrecampo.toUpperCase() ){
						if (requerido == '1'){//REQUERIDO
							if (isBlanco(tvalue)){	
								mensaje = mensaje + "El campo " + descripcioncampo + " esta vac\xEDo.\n" ;
								retorno = false;
							}
	
						}
						if ((tipodato == 'C') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isCadena(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener letras.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'I') && (!isBlanco(tvalue))){//CAMPO ENTERO
							if (!isInteger(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener n\xFAmeros.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'PH') && (!isBlanco(tvalue))){//CAMPO TELEFONO
							if (!isInteger(tvalue)||(tvalue.length!=9)){
								mensaje = mensaje + "El campo " + descripcioncampo + " debe contener 9 n\xFAmeros.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'D') && (!isBlanco(tvalue))){//CAMPO FECHA
							if (!isDate(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene una fecha v\xE1lida.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'F') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isDecimal(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor Decimal v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'P') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isPorcentaje(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor de Porcentaje v\xE1lido.\n" ;
								retorno = false;
							}
						}	
						if ((tipodato == 'E') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isEmailAddress(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no es una direcci\xF3n email v\xE1lida.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'FT') && (!isBlanco(tvalue))){//CAMPO FOTO
							if (!isFoto(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un archivo con formato de foto v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'CED') && (!isBlanco(tvalue))){//CAMPO FOTO
							if (!isCedula(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no es una cedula correcta.\n" ;
								retorno = false;
							}
						}
						
						
					}
					
			}	
			
	}
	if (retorno == false ){
		alert (mensaje);
		return false;
	}
	else {
		return retorno;
	}
}


function validarForm2 (){
//matriz = new Array ();  
//matriz[0] = new Array ('e00', 'e01', 'e02');  
//matriz[1] = new Array ('e10', 'e11', 'e12');  
//matriz[2] = new array ('e20', 'e21', 'e22'); 
//Y sabiendo que matriz[0] es new Array ('e00', 'e01', 'e02'), tenemos que si queremos acceder a e01, haremos //matriz[0][1].

	/*obj = new Array ();  
	obj[0] = new Array ('USUARIO', 1, 'D');  
	obj[1] = new Array ('PASSWORD', 1, 'C');  */

	var mensaje = "Informacion Inconsistente: \n";
	var retorno = true;

	for (i = 0;i < document.FormPrincipal.length; i++) {
			var nombrecampo = null;
			var requerido = null;
			var tipodato = null;
			var descripcioncampo = null;
   	    	var tempObj = document.FormPrincipal.elements[i];
			var tname = tempObj.name.toUpperCase();

			var tvalue = tempObj.value;
			for(var j=0;j<obj.length;j++) { 
					 nombrecampo = obj[j][0];
					 requerido = obj[j][1];
					 tipodato = obj[j][2];
					 descripcioncampo = obj[j][3];
 					 if (tname == nombrecampo.toUpperCase() ){
						if (requerido == '1'){//REQUERIDO
							if (isBlanco(tvalue)){	
								mensaje = mensaje + "El campo " + descripcioncampo + " esta vac\xEDo.\n" ;
								retorno = false;
							}
	
						}
						if ((tipodato == 'C') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isCadena(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener letras.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'I') && (!isBlanco(tvalue))){//CAMPO ENTERO
							if (!isInteger(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener n\xFAmeros.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'D') && (!isBlanco(tvalue))){//CAMPO FECHA
							if (!isDate(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene una fecha v\xE1lida.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'F') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isDecimal(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor Decimal v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'P') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isPorcentaje(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor de Porcentaje v\xE1lido.\n" ;
								retorno = false;
							}
						}	
						if ((tipodato == 'E') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isEmailAddress(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no es una direcci\xF3n email v\xE1lida.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'FT') && (!isBlanco(tvalue))){//CAMPO FOTO
							if (!isFoto(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un archivo con formato de foto v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'CED') && (!isBlanco(tvalue))){//CAMPO FOTO

							if (document.getElementById('valorRadioParent').value=='C'){
      
                  if(!isInteger(document.getElementById('parent_document_number').value)){
                     mensaje = mensaje + "El campo " + descripcioncampo + " no puede tener caracteres.\n" ;
                      retorno = false;
                  }
                  else{
                    if (document.getElementById('parent_document_number').value.length!=10){
                        mensaje = mensaje + "El campo " + descripcioncampo + " debe tener 10 digitos.\n" ;
                        retorno = false;
                    }
                  }

              }
						}
						if ((tipodato == 'CEDSON') && (!isBlanco(tvalue))){//CAMPO FOTO

							if (document.getElementById('valorRadioSon').value=='C'){
      
                  if(!isInteger(document.getElementById('son_document_number').value)){
                     mensaje = mensaje + "El campo " + descripcioncampo + " no puede tener caracteres.\n" ;
                      retorno = false;
                  }
                  else{
                    if (document.getElementById('son_document_number').value.length!=10){
                        mensaje = mensaje + "El campo " + descripcioncampo + " debe tener 10 digitos.\n" ;
                        retorno = false;
                    }
                  }

              }
						}
						
						
						
						
					}
					
			}	
			
	}
	if (retorno == false ){
		alert (mensaje);
		return false;
	}
	else {
		return retorno;
	}
}



function validarForm3 (){
//matriz = new Array ();  
//matriz[0] = new Array ('e00', 'e01', 'e02');  
//matriz[1] = new Array ('e10', 'e11', 'e12');  
//matriz[2] = new array ('e20', 'e21', 'e22'); 
//Y sabiendo que matriz[0] es new Array ('e00', 'e01', 'e02'), tenemos que si queremos acceder a e01, haremos //matriz[0][1].

	/*obj = new Array ();  
	obj[0] = new Array ('USUARIO', 1, 'D');  
	obj[1] = new Array ('PASSWORD', 1, 'C');  */

	var mensaje = "Informacion Inconsistente: \n";
	var retorno = true;

	for (i = 0;i < document.FormPrincipal.length; i++) {
			var nombrecampo = null;
			var requerido = null;
			var tipodato = null;
			var descripcioncampo = null;
   	    	var tempObj = document.FormPrincipal.elements[i];
			var tname = tempObj.name.toUpperCase();

			var tvalue = tempObj.value;
			for(var j=0;j<obj.length;j++) { 
					 nombrecampo = obj[j][0];
					 requerido = obj[j][1];
					 tipodato = obj[j][2];
					 descripcioncampo = obj[j][3];
 					 if (tname == nombrecampo.toUpperCase() ){
						if (requerido == '1'){//REQUERIDO
							if (isBlanco(tvalue)){	
								mensaje = mensaje + "El campo " + descripcioncampo + " esta vac\xEDo.\n" ;
								retorno = false;
							}
	
						}
						if ((tipodato == 'C') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isCadena(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener letras.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'I') && (!isBlanco(tvalue))){//CAMPO ENTERO
							if (!isInteger(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " solo debe contener n\xFAmeros.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'D') && (!isBlanco(tvalue))){//CAMPO FECHA
							if (!isDate(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene una fecha v\xE1lida.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'F') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isDecimal(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor Decimal v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'P') && (!isBlanco(tvalue))){//CAMPO FLOAT, DECIMAL
							if (!isPorcentaje(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un valor de Porcentaje v\xE1lido.\n" ;
								retorno = false;
							}
						}	
						if ((tipodato == 'E') && (!isBlanco(tvalue))){//CAMPO DE CARACTERES
							if (!isEmailAddress(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no es una direcci\xF3n email v\xE1lida.\n" ;
								retorno = false;
							}
							
						}
						if ((tipodato == 'FT') && (!isBlanco(tvalue))){//CAMPO FOTO
							if (!isFoto(tvalue)){
								mensaje = mensaje + "El campo " + descripcioncampo + " no tiene un archivo con formato de foto v\xE1lido.\n" ;
								retorno = false;
							}
						}
						if ((tipodato == 'CED') && (!isBlanco(tvalue))){//CAMPO FOTO

							if (document.getElementById('valorRadioParent').value=='C'){
      
                  if(!isInteger(document.getElementById('parent_document_number').value)){
                     mensaje = mensaje + "El campo " + descripcioncampo + " no puede tener caracteres.\n" ;
                      retorno = false;
                  }
                  else{
                    if (document.getElementById('parent_document_number').value.length!=10){
                        mensaje = mensaje + "El campo " + descripcioncampo + " debe tener 10 digitos.\n" ;
                        retorno = false;
                    }
                  }

              }
						}
						if ((tipodato == 'CEDSON') && (!isBlanco(tvalue))){//CAMPO FOTO

							if (document.getElementById('valorRadioSon').value=='C'){
      
                  if(!isInteger(document.getElementById('son_document_number').value)){
                     mensaje = mensaje + "El campo " + descripcioncampo + " no puede tener caracteres.\n" ;
                      retorno = false;
                  }
                  else{
                    if (document.getElementById('son_document_number').value.length!=10){
                        mensaje = mensaje + "El campo " + descripcioncampo + " debe tener 10 digitos.\n" ;
                        retorno = false;
                    }
                  }

              }
						}
						
						
						
						
					}
					
			}	
			
	}
	if (retorno == false ){
		alert (mensaje);
		return false;
	}
	else {
		return retorno;
	}
}
//-------------------------------------------------------------------
// mascara(d,separador,tipo,numeros). Forma una máscara para el ingreso de datos
// d: objeto en el que se aplicará la mascara.
// separador: caracter separador, Ej: - , / , etc.
// formato: un arreglo que indica patrón de la máscara con sus separadores Ej:
// numeros: indica si acepta o no números
//-------------------------------------------------------------------
function mascara(d,separador,tipo,numeros){
var formato
if (tipo=='D') formato = new Array(4,2,2)
if (tipo=='T') formato = new Array(2,4,3)
valor=d.value
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(separador)
	val2 = ''
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(numeros){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	val = ''
	val3 = new Array()
	for(s=0; s<formato.length; s++){
		val3[s] = val2.substring(0,formato[s])
		val2 = val2.substr(formato[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += separador + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}
