<!--2006-04-04.16h:30 BELEN PADILLA.  funcion validarMayor !-->		
<!--2006-06-29.16h:30 PATRICIA VIRACOCHA.  funcion validar_doc_CR() !-->		
<!--2006-06-30.16h:30 DIEGO BURBANO.  quitarslash() !-->		
<!--2007-03-15.14h:18 PATRICIA VIRACOCHA. ValidarCadena(c) Quita los saltos de línea y los tabuladores de una cadena!-->	
<!-- ============== 	C A M B I O S   N I C A R A G U A -->
<!-- 2007-08-14 14h:27 Validación de los tipos de documentos -->
<!--  			36 	Incluir validación de documentos -->
<!--  			206 Creación de la function validar_doc_NI() -->
<!--  			501 Creación de la function validarCI_HN(cedula) -->
<!--  			511 Creación de la function validarRTN_HN(cedula) -->
<!-- ============== 	C A M B I O S   P A N A M A -->
<!-- 2007-08-21 10h:25 Validación de los tipos de documentos -->
<!--  			47 	Incluir validación de documentos -->
<!--  			249 Creación de la function validar_doc_PA() -->
<!--  			603 Creación de la function validarCI_PA(cedula) -->
<!--  			616 Creación de la function validarRUC_PA(cedula) -->
<!--  			625 Creación de la function validarPAS_PA(cedula) -->
<!-- ============== 	C A M B I O S   G U A T E M A L A -->
<!--  			601 Validación Correcta del NIT -->
<!-- ============== 	C A M B I O S   en TODAS LAS FUNCIONES DE VALIDAR DOCUMENTO DE IDENTIFICACION-->
<!-- 2007-10-18.16h:30 BELEN PADILLA.  funcion validar_ci_ruc y  sus dependientes reciben parámetros select_tipo_id,texto_id-->
<!-- ============== 	C A M B I O S   PRODUCTO MAS CERCA-->
<!--2007-11-05.17h:00  BELEN PADILLA. -> Cambio en function validarIBS() validar el select de Puntos de Venta más cerca  -->	
<!-- ============== 	C A M B I O S   E L  S A L V A D O R -->
<!--2008-10-28.09h:16  MARTHA QUINZO C. //====Implementacion Inicial El Salvador  -->	
<!-- 2008-NOV-12  BELEN PADILLA. ECUADOR //------Nuevo IMP EC 2008-->
<!-- 2008-11-19   BELEN PADILLA  GUATEMALA //====Aumento campo Recibo-->
<!-- 2008-12-29   MARTHA QUINZO C.  EL SALVADOR //Campo Registro Fiscal Obligatorio para los comprobantes de crédito Fiscal-->
<!-- 2009-02-10   BELEN PADILLA. ECUADOR //------Nuevo IMP EC 2008: 2 funciones nuevas para enfocar los campos con color: onfocus_color(), onblur_color() -->
<!--2009-ABR-16.12h:26 MARTHA QUINZO C.  //===Mejora Formato Números -->
<!--2009-JUN-29.11h:16 MARTHA QUINZO C.  //===Integración Embajada US en CRA   Función validarIbs_eUS -->
<!--2009-AGO-26.12h:04 MARTHA QUINZO C.  //=====Implementacion Venezuela -->


//FUNCION PARA VALIDAR LA CEDULA O RUC
function validar_ci_ruc(select_tipo_id,texto_id)
{ 
	/*alert("Nombre select::"+select_tipo_id);
	alert("Nombre texto::"+texto_id);*/
	//if(document.fIbs.texto_id.value == '' )return false;
    if (document.getElementById(texto_id).value=='') return false;
	if (PA_IDPAIS=='EC')	//ECUADOR
	return validar_doc_EC(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='CL')	//CHILE
	return validar_doc_CL(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='CR')	//COSTA RICA
	return validar_doc_CR(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='CO')	//COLOMBIA
	return validar_doc_CO(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='PE')	//PERU
	return validar_doc_PE(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='HN')	//HONDURAS
	return validar_doc_HN(select_tipo_id, texto_id);
	
	if (PA_IDPAIS=='GT')	//GUATEMALA
	return validar_doc_GT(select_tipo_id, texto_id);

	if (PA_IDPAIS=='NI')	//NICARAGUA
	return validar_doc_NI(select_tipo_id, texto_id);

	if (PA_IDPAIS=='PA')	//PANAMA
	return validar_doc_PA(select_tipo_id, texto_id);

	if (PA_IDPAIS=='SV')	//SALVADOR //====Implementacion Inicial El Salvador 
	return validar_doc_SV(select_tipo_id, texto_id);
	//=====Implementacion Venezuela
	if (PA_IDPAIS=='VE')	//VENEZUELA
	return validar_doc_VE(select_tipo_id, texto_id);
	
	//los demas paises
	return true;
	
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE ECUADOR
function validar_doc_EC(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C'  )
  	{  
   		if(validarCedula(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de cédula incorrecto");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarRucSPE(document.getElementById(texto_id).value)!=1) && (validarRucPN(document.getElementById(texto_id).value)!=1) && (validarRucSP(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de RUC incorrecto");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			
			return false;
  	 	} 
  	}
	
	return true;
}

//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE CHILE
function validar_doc_CL(select_tipo_id,texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if(!RutVerificador(document.getElementById(texto_id).value))
   		{	
			alert("Número de RUT incorrecto");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
	return true;
}

//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE CHILE
function validar_doc_CO(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C')
  	{  
   		if(!validar_NIT(document.getElementById(texto_id).value))
   		{	
			alert("Número de NIT incorrecto");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	if((document.getElementById(select_tipo_id).value)=='O')
  	{  
		if(validarNumeros(document.fIbs.gui_cedularuc,0)==false)
   		{	
			//alert("Número de OTROS incorrecto");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
	return true;
}

//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE COSTA RICA
function validar_doc_CR(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C')
  	{  
   		if(!validarCedula_CR(document.getElementById(texto_id).value))
   		{	
			alert("Número de C.I. incorrecto, debe tener el formato: #-####-####");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE PERÚ
function validar_doc_PE(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='D'  )
  	{  
   		if(validarDNI_PE(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de DNI incorrecto, debe tener el formato: ########");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarRUC_PE(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de RUC incorrecto, debe tener el formato: ###########");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			
			return false;
  	 	} 
  	}
	
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE HONDURAS
function validar_doc_HN(select_tipo_id,texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C'  )
  	{  
   		if(validarCI_HN(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de CI es incorrecto, debe tener el formato: #############");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarRTN_HN(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de RTN incorrecto, debe tener el formato: ##############");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			
			return false;
  	 	} 
  	}
	
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE GUATEMALA
function validar_doc_GT(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='N'  )
  	{  
   		if(validarNIT_GT(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de NIT es incorrecto, debe tener el formato: #######-X, ######-X, #####-X, ####-X ");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  		
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE NICARAGUA
function validar_doc_NI(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C'  )
  	{  
   		if(validarCI_NI(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de CI es incorrecto, debe tener el formato: ####-######-####X");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 

			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarRUC_NI(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de RUC incorrecto, debe tener el formato: ######-####");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
  	if((document.getElementById(select_tipo_id).value)=='I')
  	{  
   		if((validarIDN_NI(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de IDN incorrecto, debe tener el formato: ######");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DE PANAMA
function validar_doc_PA(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='C'  )
  	{  
   		if(validarCI_PA(document.getElementById(texto_id).value)!=1)
		{
			alert("Número de CI es incorrecto, debe tener los siguienetes formatos: #-####-####, XX-#-####, N-##-####, E-#-#####");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarRUC_PA(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de RUC incorrecto, debe tener el formato: XXXXXX-XXXXX-XXXXX");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
  	if((document.getElementById(select_tipo_id).value)=='P')
  	{  
   		if((validarPAS_PA(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de Pasaporte incorrecto, debe tener el formato: XXXXXXXXXX");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
	return true;
}
//FUNCION QUE LLAMA A LAS FUNCIONES DE VALIDACION DE DOCUMENTOS DEL SALVADOR
function validar_doc_SV(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='D'  )
  	{  
   		if(validarDNI_SV(document.getElementById(texto_id).value)!=1)	{
			alert("Número de DUI es incorrecto, debe tener el formato:#########-# (de 8 a 10 dígitos)");
				  //###-####-#, ########");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
  	if((document.getElementById(select_tipo_id).value)=='N')
  	{  
   		if((validarNIT_SV(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de NIT incorrecto, debe tener el formato: ####-######-###-#");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
  	if((document.getElementById(select_tipo_id).value)=='R')
  	{  
   		if((validarNRC_SV(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de NRC es incorrecto, debe tener el formato: #########-#(de 4 a 10 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
	
  	if((document.getElementById(select_tipo_id).value)=='C')//CARNET DE EXENCION
  	{  
   		if((validarCARNETEXENCION_SV(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de CARNET DE EXENCION es incorrecto, debe tener el formato: ##########");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}	
	
	return true;
}
//=====Implementacion Venezuela
function validar_doc_VE(select_tipo_id, texto_id)
{
	if((document.getElementById(select_tipo_id).value)=='V'  )
  	{  
   		if(validarCV_VE(document.getElementById(texto_id).value)!=1)	{
			alert("Número de Cédula incorrecto, debe tener el formato:V-###### (Letra V, guión (-) seguido de 6 a 9 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}
	if((document.getElementById(select_tipo_id).value)=='E'  )
  	{  
   		if(validarCE_VE(document.getElementById(texto_id).value)!=1)	{
			alert("Número de Cédula incorrecto, debe tener el formato:E-######## (Letra E guión (-) seguido de 6 a 9 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
   		}
  	}	
  	if((document.getElementById(select_tipo_id).value)=='P')
  	{  
   		if((validarPAS_VE(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de PASAPORTE incorrecto, debe tener el formato: P-#########(Letra P guión (-) seguido de 4 a 9 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
  	if((document.getElementById(select_tipo_id).value)=='J')
  	{  
   		if((validarRIFJ_VE(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de R.I.F. JURIFICO incorrecto, debe tener el formato: J-#########(Letra J guión (-) seguido de hasta 9 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}
  	if((document.getElementById(select_tipo_id).value)=='G')
  	{  
   		if((validarRIFG_VE(document.getElementById(texto_id).value)!=1))
   		{	
			alert("Número de R.I.F GUBERNAMENTAL incorrecto, debe tener el formato: G-#########(Letra G guión (-) seguido de 9 dígitos)");
			document.getElementById(texto_id).focus(); 
			document.getElementById(texto_id).select(); 
			return false;
  	 	} 
  	}	
	
	return true;
}

//FUNCION QUE PERMITE VALIDAR EL NUMERO DE CEDULA
function validarCedula(cedula)
{ 
 cadena=/^[0-9]{10}$/;
 sumaprod=0;
 coef='212121212';
 	if(cadena.test(cedula)){  
  	i=0;
  	while(i<9){    
   	if(i==0){
    	numruc=cedula.substr(0,1);  
     	numcoef=coef.substr(0,1);      
   		}
   	else{
     	numruc=cedula.substr(i,1);  
     	numcoef=coef.substr(i,1);   
   		}  
   	product=numruc*numcoef;  
  	 if (product>=10){   
  		product1=String(product);      
     	num1=product1.substr(0,1);   
     	num2=product1.substr(1,1);   
     	product=Number(num1)+Number(num2);  
   		}
    sumaprod=sumaprod+product;        
    	i=i+1;  
  		}  
  	resid=sumaprod%10;
  	if(resid==0)
   	digverf=0;
  	else
   	digverf=10-resid;
  	digverfced=cedula.substr(9,1);           
  	if(digverfced==digverf)
   	return 1;  
  	else
   	return 0;          
 	}
 	else
  	return 0;  
}

/// validacion del ruc para personas naturales
function validarRucPN(rucpn)
{ 
 cadena=/^[0-9]{13}$/;
 sumaprod=0;
 coef='212121212';  
 if(cadena.test(rucpn)&&(rucpn.substr(10,3))==001&&(rucpn.substr(2,1))<6&&(rucpn.substr(0,2))>=1&&(rucpn.substr(0,2))<=22){  
  i=0;
  while(i<9)
  {    
   if(i==0)
   {
     numruc=rucpn.substr(0,1);  
     numcoef=coef.substr(0,1);      
   }
   else
   {
     numruc=rucpn.substr(i,1);  
     numcoef=coef.substr(i,1);   
   }  
   product=numruc*numcoef;  
   if (product>=10)
   {   
     product1=String(product);      
     num1=product1.substr(0,1);   
     num2=product1.substr(1,1);   
     product=Number(num1)+Number(num2);  
   }
    sumaprod=sumaprod+product;        
    i=i+1;  
  }   
  resid=sumaprod%10;
  if(resid==0)
   digverf=0;
  else
   digverf=10-resid;
  digverfced=rucpn.substr(9,1);           
  if(digverfced==digverf)
   return 1;  
  else
   return 0;           
 }
 else
  return 0;  
}
 
/////   validacion del RUC para sociedades publicas
function validarRucSP(rucsp)
{
 cadena=/^[0-9]{13}$/;
 sumaprod=0;
 coef='32765432';
 if(cadena.test(rucsp)&&(rucsp.substr(9,4))==0001&&(rucsp.substr(2,1))==6&&(rucsp.substr(0,2))>=1&&(rucsp.substr(0,2))<=22){  
  i=0;
  while(i<8)
  {    
   if(i==0)
   {
     numruc=rucsp.substr(0,1);  
     numcoef=coef.substr(0,1);      
   }
   else
   {
     numruc=rucsp.substr(i,1);  
     numcoef=coef.substr(i,1);   
   }  
   product=numruc*numcoef;     
            sumaprod=sumaprod+product;        
      i=i+1;  
  }  
  resid=sumaprod%11;
  if (resid==0)
   digverf=0;
  else
   digverf=11-resid;  
  digverfruc=rucsp.substr(8,1);  
  if(digverfruc==digverf)
   return 1;  
  else
   return 0; 
 }
 else
  return 0;  
}

/// validacion del ruc para sociedades privadas y extranjeros sin cedula 
function validarRucSPE(rucspe)
{ 
 cadena=/^[0-9]{13}$/;
 sumaprod=0; 
 coef='432765432'; 
 if(cadena.test(rucspe)&&(rucspe.substr(10,3))==001&&(rucspe.substr(2,1))==9&&(rucspe.substr(0,2))>=1&&(rucspe.substr(0,2))<=22)
 {   
  i=0;
  while(i<9)
  {    
   if(i==0)
   {
     numruc=rucspe.substr(0,1);  
     numcoef=coef.substr(0,1);      
   }
   else
   {
     numruc=rucspe.substr(i,1);  
     numcoef=coef.substr(i,1);   
   }  
   product=numruc*numcoef;     
            sumaprod=sumaprod+product;        
      i=i+1;  
  }
  resid=sumaprod%11;
  if (resid==0)
   digverf=0;
  else
   digverf=11-resid;  
  digverfruc=rucspe.substr(9,1);  
  if(digverfruc==digverf)
   return 1;  
  else
   return 0; 
 }
 else
  return 0;  
}



//FUNCION QUE PERMITE VALIDAR EL NUMERO DE CEDULA DE COSTA RICA
function validarCedula_CR(cedula)
{ 
 cadena=/^[0-9]{1}-[0-9]{4}-[0-9]{4}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//COSTA RICA:FUNCION QUE PERMITE VALIDAR LA FECHA Y HORA DE LLEGADA DE UN ENVIO DPI 

function validarFecha_CR(objeto)
{ 
 cadena=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}$/;
 	if(cadena.test(objeto.value)){  
		return 1; 
 	}else{
  		 alert ('El campo Fecha y Hora de llegada no tiene el siguiente formato(yyyy/mm/dd hh:mm:ss)');
		objeto.focus();
		return false;  
	}
}

//FUNCION QUE PERMITE VALIDAR EL NIT DE COLOMBIA
function validar_NIT(cedula)
{ 
 cadena=/^[0-9]{10}$/;
 sumaprod=0;
 //pentera
 coef= new Array(41,37,29,23,19,17,13,7,3);
	
			
			//alert('longitud'+cedula.length);
			switch(cedula.length) { 
				case 7: 
					cedula='000'+cedula;
				break; 
				case 8: 
					cedula='00'+cedula;
				break; 
				case 9: 
					cedula='0'+cedula;
				break; 
								
			} 
	if(cadena.test(cedula)){  
			i=0;
			while(i<(cedula.length-1)){ 
					product=coef[i]*Number(cedula.substr(i,1));
					//alert('i:'+i+'producto'+product);
					sumaprod=sumaprod+product;
					i=i+1;
			}
			valorreal=sumaprod/11;
			valorentero=parseInt(sumaprod/11);
			valordif=valorreal-valorentero;
			digverf=valordif*11;
			digverf=digverf.toFixed(0);
			if(digverf==0 || digverf==1)
				digverf_f=digverf
			else
				digverf_f=11-digverf;
			digverfced=cedula.substr((cedula.length-1),1);  
			
			if(digverfced==digverf_f)	
				return 1;
			else	
				return 0;	
	}else
		return 0;
  
}
//FUNCION QUE PERMITE VALIDAR EL NUMERO DE CEDULA ó DNI PARA PERÚ
function validarDNI_PE(cedula)
{ 
 cadena=/^[0-9]{8}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL NUMERO DE CEDULA ó DNI PARA PERÚ
function validarRUC_PE(cedula)
{ 
 cadena=/^[0-9]{11}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}

//FUNCION QUE PERMITE VALIDAR EL NUMERO DE CEDULA PARA HONDURAS
function validarCI_HN(cedula)
{ 
 cadena=/^[0-9]{13}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL NUMERO EL RTN PARA HONDURAS
function validarRTN_HN(cedula)
{ 
 cadena=/^[0-9]{14}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL NUMERO DE NIT GUATEMALA
function validarNIT_GT(cedula)
{ 
 cadena=/^[0-9]{7}-[a-zA-Z0-9]{1}$/;
 cadena1=/^[0-9]{6}-[a-zA-Z0-9]{1}$/;
 cadena2=/^[0-9]{5}-[a-zA-Z0-9]{1}$/; 
 cadena3=/^[0-9]{4}-[a-zA-Z0-9]{1}$/;  
 	if(cadena.test(cedula) || cadena1.test(cedula) || cadena2.test(cedula) || cadena3.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR LA CI DE NICARAGUA
function validarCI_NI(cedula)
{ 
	cadena=/^[0-9]{3}-[0-9]{6}-[0-9]{4}[a-zA-Z]{1}$/;

 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL RUC DE NICARAGUA
function validarRUC_NI(cedula)
{ 
 cadena=/^[0-9]{6}-[0-9]{4}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL IDN DE NICARAGUA
function validarIDN_NI(cedula)
{ 
 cadena=/^[0-9]{6}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}

//FUNCION QUE PERMITE VALIDAR LA CI DE PANAMA
function validarCI_PA(cedula)
{ 
	cadena=/^[0-9]{1}-[0-9]{4}-[0-9]{4}$/;
	cadena1=/^[A-Z]{2}-[0-9]{1}-[0-9]{4}$/;
	cadena2=/^[N]{1}-[0-9]{2}-[0-9]{4}$/;	
	cadena3=/^[E]{1}-[0-9]{1}-[0-9]{5}$/;		

 	if(cadena.test(cedula) || cadena1.test(cedula) || cadena2.test(cedula) || cadena3.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL RUC DE PANAMA
function validarRUC_PA(cedula)
{ 
 cadena=/^[a-zA-Z0-9]{6}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL PASAPORTE DE PANAMA
function validarPAS_PA(cedula)
{ 
 cadena=/^[a-zA-Z0-9]{10}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL DNI PARA EL SALVADOR
function validarDNI_SV(cedula)
{ 
 //cadena=/^[0-9]{3}-[0-9]{4}-[0-9]{1}$/;
 //de 8 a 10 dígitos en total xxxxxxxx (7-9 dígitos) - x(1 dígito)
 cadena=/^[0-9]{7,9}-[0-9]{1}$/;
 //alert("valida DUI");
	if(cadena.test(cedula)){
		return 1; 
 	}else
  		return 0;  
}
//FUNCION QUE PERMITE VALIDAR EL NIT PARA EL SALVADOR
function validarNIT_SV(cedula)
{ 
 cadena=/^[0-9]{4}-[0-9]{6}-[0-9]{3}-[0-9]{1}$/;
  	if(cadena.test(cedula)){  
		
		return 1; 
 	}else{
		
  		return 0;  
	}
}
//FUNCION QUE PERMITE VALIDAR EL NRC PARA EL SALVADOR
function validarNRC_SV(cedula)
{ 
 //cadena=/^[0-9]{4,10}$/;
 //de 4 a 10 dígitos en total xxx(3-9) - x (1 dígito)
 cadena=/^[0-9]{3,9}-[0-9]{1}$/;
  	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}

//FUNCION QUE PERMITE VALIDAR EL NRC PARA EL SALVADOR
function validarCARNETEXENCION_SV(cedula)
{ 
 cadena=/^[0-9]{1,10}$/;
  	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//=====Implementacion Venezuela
//Función que permite validar la Cédula Venezolano
function validarCV_VE(cedula)
{ 
	cadena=/^[V]{1}[-]{1}[0-9]{6,9}$/;
 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//Función que permite validar la Cédula Extrangero
function validarCE_VE(cedula)
{ 
	cadena=/^[E]{1}[-]{1}[0-9]{6,9}$/;

 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//Función que permite validar el Pasaporte
function validarPAS_VE(cedula)
{ 
	cadena=/^[P]{1}[-]{1}[0-9]{4,9}$/;

 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//Función que permite validar el RIF para personas Jurídicas
function validarRIFJ_VE(cedula)
{ 
	cadena=/^[J]{1}[-]{1}[0-9]{6,9}$/;

 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//Función que permite validar el RIF para entes gubernamentales
function validarRIFG_VE(cedula)
{ 
	cadena=/^[G]{1}[-]{1}[0-9]{9}$/;

 	if(cadena.test(cedula)){  
		return 1; 
 	}else
  		return 0;  
}
//=====FIN Implementacion Venezuela
function validarCampo(objeto,mensaje)
{
	var texto=objeto.value;
	//alert(mensaje);
	//objeto.disabled=false;
	//prueba=trim(objeto.value);
	//alert('linea 6: '+prueba);
	//|| trim(objeto.value)!=''
	if (objeto.value == null || objeto.value == '')
	{		
		alert ('El campo ' + mensaje + ', no debe estar vacío');
		if (!objeto.disabled)
		objeto.focus();
		return false;
	}	
	return true;
}
function validarCampoTrim(objeto,mensaje)
{
	var texto=objeto.value;
	//alert(mensaje);
	//objeto.disabled=false;
	//prueba=trim(objeto.value);
	//alert('linea 6: '+prueba);
	//|| trim(objeto.value)!=''
	if (objeto.value == null || objeto.value == '' || trim(objeto.value)!='')
	{		
		alert ('El campo ' + mensaje + ', no debe estar vacío');
		if (!objeto.disabled)
		objeto.focus();
		return false;
	}	
	return true;
}

function validarSelect(objeto,mensaje)
{

	if (objeto.selectedIndex == 0)
	{		
		alert ('El campo ' + mensaje + ', no debe estar vacío');
		objeto.focus();
		return false;
	}	
	return true;
}

function validarIbs(forma)
{
 	
	if (!validarCampo(forma.gui_cedularuc,"Id")) return false;
	if (!validarCampo(forma.cli_cuenta,"Num. Cuenta")) return false;
	if (!validarCampo(forma.gui_idorigen,"Origen")) return false;
	if (!validarCampo(forma.gui_iddestino,"Destino")) return false;
	if (!validarSelect(forma.pro_nombre,"Producto")) return false;	
	if (!validarCampo(forma.gui_descripcion,"Contenido")|| !validarTamanoCampo(forma.gui_descripcion,2,"Contenido")) return false;
	if (!validarCampo(forma.gui_valordeclarado,"Valor Declarado")) return false;
	if (!validarCampo(forma.gui_peso,"Peso")) return false;
	if (!validarCampo(forma.gui_numpiezas,"Num. Piezas")) return false;


	if(document.getElementById("datos_arancel").style.display!='none')//PARA TRAEME VALIDAR ARANCEL
		if (!validarSelect(forma.gui_arancel,"Arancel")) return false;	
	if(document.getElementById("etiqueta_transporte").style.display!='none')//PARA T. collect
		if (!validarCampo(forma.gui_etiqueta_transporte,"Etiqueta de Transporte")) return false;	
	
	//	ENVIO MAS CERCA ECUADOR
	if(document.getElementById("div_pvta_mascerca").style.display!='none')
	if (!validarSelect(document.getElementById('select_pvta_mascerca'),"Punto de Venta")) return;

	return true;
}

function validarIbs_dpi(forma)
{
	if (!validarCampo(forma.gui_cedularuc,"Id")) return false;
	if (!validarCampo(forma.cli_cuenta,"Num. Cuenta")) return false;
	if (!validarCampo(forma.gui_idorigen,"Origen")) return false;
	if (!validarCampo(forma.gui_iddestino,"Destino")) return false;
	if (!validarSelect(forma.pro_nombre,"Producto")) return false;	
	if (!validarCampo(forma.gui_descripcion,"Contenido")|| !validarTamanoCampo(forma.gui_descripcion,2,"Contenido")) return false;
	if (!validarCampo(forma.gui_valordeclarado,"Valor Declarado")) return false;
	if (!validarCampo(forma.gui_peso,"Peso")) return false;
	if (!validarCampo(forma.gui_numpiezas,"Num. Piezas")) return false;


	if(document.getElementById("datos_arancel").style.display!='none')//PARA TRAEME VALIDAR ARANCEL
		if (!validarSelect(forma.gui_arancel,"Arancel")) return false;	
	if(document.getElementById("etiqueta_transporte").style.display!='none')//PARA T. collect
		if (!validarCampo(forma.gui_etiqueta_transporte,"Etiqueta de Transporte")) return false;	
	
	//	ENVIO MAS CERCA ECUADOR
	if(document.getElementById("div_pvta_mascerca").style.display!='none')
	if (!validarSelect(document.getElementById('select_pvta_mascerca'),"Punto de Venta")) return;

	//------Nuevo IMP EC 2008--
	if(document.getElementById("datos_subcaso_categ").style.display!='none')//SI HAY SUBCATEGORIA DE ARANCEL VERIFICAR QUE ESTE SELECCIONADA
	if (!validarSelect(document.getElementById('gui_subcaso_categ'),"Tipo de Categoría")) return false;
	
	if(document.getElementById("datos_subpartida").style.display!='none')//SI HAY SUBPARTIDA VERIFICAR QUE NO ESTE VACIA
	{
		if (!validarCampo(document.getElementById("gui_subpartida"),"Subpartida"))  return false;
		if (!validar_subpartida_F(document.getElementById("gui_subpartida"))) return false;
		//alert('valor despues de calcular tarifa'+document.getElementById('hgui_subpartida').value);
	}
	
	if(document.getElementById("datos_categorias_abiertas").style.display!='none')//SI HAY PARTIDAS DE CONSUMO VALIDAR CAMPOS
	{
		//alert('Validando categorias d consumo');
		if(!validar_partidas_consumo())return false;
	}
	//------fin Nuevo IMP EC 2008-

	return true;
}
//===Integración Embajada US en CRA
function validarIbs_eUS(forma)
{
	if (!validarCampo(forma.gui_cedularuc,"Id")) return false;
	if (!validarCampo(forma.cli_cuenta,"Num. Cuenta")) return false;
	if (!validarCampo(forma.gui_idorigen,"Origen")) return false;
	if (!validarCampo(forma.gui_iddestino,"Destino")) return false;
	if (!validarSelect(forma.pro_nombre,"Producto")) return false;	
	if (!validarCampo(forma.gui_descripcion,"Contenido")|| !validarTamanoCampo(forma.gui_descripcion,2,"Contenido")) return false;
	if (!validarCampo(forma.gui_valordeclarado,"Valor Declarado")) return false;
	if (!validarCampo(forma.gui_peso,"Peso")) return false;
	if (!validarCampo(forma.gui_numpiezas,"Num. Piezas")) return false;


	if(document.getElementById("datos_arancel").style.display!='none')//PARA TRAEME VALIDAR ARANCEL
		if (!validarSelect(forma.gui_arancel,"Arancel")) return false;	
	if(document.getElementById("etiqueta_transporte").style.display!='none')//PARA T. collect
		if (!validarCampo(forma.gui_etiqueta_transporte,"Etiqueta de Transporte")) return false;	
	return true;		
}

function validarPago(forma)
{
	//REMITENTE
	if (!validarCampo(forma.cli_nombre,"Nombre del Remitente")|| !validarTamanoCampo(forma.cli_nombre,2,"Nombre del Remitente")) return false;
	if (!validarCampo(forma.cli_empresa,"Compañía del Remitente")|| !validarTamanoCampo(forma.cli_empresa,2,"Compañía del Remitente")) return false;
	if (!validarCampo(forma.cli_direccion,"Dirección del Remitente") || !validarTamanoCampo(forma.cli_direccion,2,"Dirección del Remitente")) return false;
	if (!validarCampo(forma.cli_telefono,"Teléfono del Remitente")  || !validarTamanoCampo(forma.cli_telefono,6,"Teléfono del Remitente")) return false;
	if (!validarCampo(forma.cli_zipcode,"Código Postal del Remitente")) return false;
	//=====Implementacion Venezuela
	if(PA_IDPAIS=='VE') if (!validarCampo(forma.cli_email,"e-mail del Remitente")  || !validarTamanoCampo(forma.cli_email,7,"e-mail del Remitente")) return false;		
	
	//DESTINATARIO
	if (!validarCampo(forma.gui_nombredes,"Nombre de Destinatario")|| !validarTamanoCampo(forma.gui_nombredes,2,"Nombre de Destinatario")) return false;
	if (!validarCampo(forma.gui_contactodes,"Compañía de Destinatario")|| !validarTamanoCampo(forma.gui_contactodes,2,"Persona a contactar")) return false;
	if (!validarCampo(forma.gui_direcciondes,"Dirección del Destinatario")|| !validarTamanoCampo(forma.gui_direcciondes,2,"Dirección del Destinatario")) return false;
	if (!validarCampo(forma.gui_zip,"Código Postal del Destinatario")) return false;
	//=====Implementacion Venezuela
	if(PA_IDPAIS=='VE') if (!validarCampo(forma.gui_emaildes,"e-mail del Destinatario")  || !validarTamanoCampo(forma.gui_emaildes,7,"e-mail del Destinatario")) return false;			
	//===Integración Embajada US en CRA
   if (envio_id=='US'){
		if (!validarCampo(forma.gui_pasanomb,"Nombre Pasaporte")) return false;
		if (!validarCampo(forma.gui_pasaqmat,"Num. QMAT")) return false;
	}
	
	//ZIP CODE
	/*if (envio_id!='TR' && !validarCampo(forma.gui_zip,"Código Postal del Destinatario")) return false;
	if (envio_id=='TR' && !validarCampo(forma.cli_zipcode,"Código Postal del Remitente")) return false;*/
	
	
	if (!validarCampo(forma.gui_telefonodes,"Teléfono del Destinatario")|| !validarTamanoCampo(forma.gui_telefonodes,7,"Teléfono del Destinatario")) return false;

	
	if(document.getElementById("datos_factura").style.display!='none')//PARA VALIDAR Facturas
	{
		
		var selectfact=document.getElementById('tipofact').value;
		var tipofact='';
		for (var i=0; i<a_tipofact.length ;i++)
		{ 
			if(a_tipofact[i].tipofact_id==selectfact)
			{
				tipofact=a_tipofact[i].tipofact_descrip;
				break;
			}
		}
		if (!validarCampo(forma.factnum,tipofact)) return false;
		
		/*if(document.getElementById('cli_idcliente').value=='R'){ //Para RUC
			if (!validarCampo(forma.factnum,"No. Factura")) return false;
		}
		else{
			if (!validarCampo(forma.factnum,"Nota de Venta")) return false;
		}*/
		

	}
	
	//====Implementacion Inicial El Salvador
	if (PA_IDPAIS=='SV')
	{
		if (!validar_NEP(forma)) return false;// Validar que exista email de cliente para el extracargo NEP de SV
		//Campo Registro Fiscal Obligatorio para los comprobantes de crédito Fiscal
		if(forma.tipofactura.value=='C'){
			if (!validarCampo(forma.cli_regfiscal,"No. Registro Fiscal")|| !validarTamanoCampo(forma.cli_nombre,2,"No. Registro Fiscal")) return false;
		}
		
		
	}
	
	//alert("VALIDA PAGO");
	return true;
}
//función para verificar valores numéricos
function validarNumeros(objeto,maxNumDecimales)
{
	//alert("name:"+objeto.id+" value:"+ objeto.value);
	if(objeto.value == '' )
	{		
		objeto.value=0;
		return false;
	}
	var str=objeto.value;
	var unDecimal=false;
	var unCaracter=0;
	var numDecimales=0;
	//asegurar que el valor nos sea de tipo numérico
	str=str.toString();
	for (var i=0; i < str.length ;i++)
	{
		unCaracter=str.charAt(i).charCodeAt(0);		
		if (unDecimal==true)
		numDecimales++;		
		if (numDecimales > maxNumDecimales)
		{
			alert("Sólo se permiten "+maxNumDecimales +" números decimales");
			objeto.focus();
			objeto.select();
			return false;
		}
		if (unCaracter==46)//un punto decimal
		{
			if(maxNumDecimales==0 ) {
			alert("Sólo se permiten valores enteros");
			objeto.focus();
			objeto.select();
			return false;
			} 
		
			if(!unDecimal){
				unDecimal=true; 
				posicionDecimal=i;
				continue;
			}
			else {
			alert("Sólo se permite un punto decimal");
			objeto.focus();
			objeto.select();
			return false;
			} 
		}
		
		if (unCaracter < 48 || unCaracter > 57){
			alert("Sólo se permiten valores numéricos");
			objeto.focus();
			objeto.select();
			return false;

		}
	}
	return true;
}

//funcion para validar que un numero sea mayor a otro
function validarMayor(campoMayor, campoMenor)
{
	valormin=parseFloat(campoMenor.value);
	valormax=parseFloat(campoMayor.value);
	
	if(valormin>valormax)
	{
		alert("Verifique los valores mínimos y máximos");
		campoMenor.focus();
		campoMenor.select();
		return false;
	}
	else
	return true;
  
}


//función para cambiar a mayúsuculas un campo de texto
function cambiarMayusculas(objeto)
{
	objeto.value=objeto.value.toUpperCase();
}
//función para cambiar a minúsculas un campo de texto
function cambiarMinusculas(objeto)
{
	objeto.value=objeto.value.toLowerCase();
}


function validarTamanoCampo(objeto,num,texto)
{
	//alert("validar campo tama");
	var cadena=objeto.value;
	if(cadena.length < num)
	{
		alert("El campo "+texto+" debe contener al menos "+num+" caracteres");
			objeto.focus();
			objeto.select();
			return false;
	}
	return true;
		
}

function escapeVal(textarea,replaceWith){
textarea.value=escape(textarea.value)
for(i=0; i<textarea.value.length; i++){
 	if(textarea.value.indexOf("%0D%0A") > -1){
	textarea.value=textarea.value.replace("%0D%0A",replaceWith)
	}
	else if(textarea.value.indexOf("%0A") > -1){
	textarea.value=textarea.value.replace("%0A",replaceWith)
	}
	else if(textarea.value.indexOf("%0D") > -1){
	textarea.value=textarea.value.replace("%0D",replaceWith)
	}
}
textarea.value=unescape(textarea.value)
}

function blockEnter(evt)
{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode: ((evt.which) ? evt.which : evt.keyCode);
	if (charCode==13 || charCode==3)
	{
		return false;
	}
	else
	{
		return true;
	}
}
//Esta función Quita los saltos de línea y los tabuladores de una cadena de texto
function ValidarCadena(c) { 
	//var entra=new Array('enter' ,'enter','tab '%09'','pipe |'); 
	var entra=new Array('%0D','%0A','%7C'); 
	//var sale =new Array('-','*','#','_'); 
	var sale =new Array('','',''); 
	var oc=new String(c.value),nt=new String(""),nc; 
	for(var q=0;q<oc.length;q++){ 
		nc=oc.charAt(q); 
		for(var w=0;w<entra.length;w++){ 
			if(escape(oc.charAt(q))==entra[w]){ 
					nc=sale[w];
					break; 
			}  
			
		} 
	 	//document.write(q+'['+escape(nc)+']');
		nt+=nc; 
	} 
	//document.write(escape(nt));
	c.value=nt; 
	delete oc,nt; 
	return true;
} 

function diferencia_fechas(campo_final,campo_inicial,texto)
{
		var elementos_final = campo_final.value.split("/");
		var dia_final = parseInt(elementos_final[0],10);
		var mes_final = parseInt(elementos_final[1],10);
		var ano_final = parseInt(elementos_final[2],10);
		var elementos_inicial = campo_inicial.value.split("/");
		var dia_inicial = parseInt(elementos_inicial[0],10);
		var mes_inicial = parseInt(elementos_inicial[1],10);
		var ano_inicial = parseInt(elementos_inicial[2],10);
		var fecha_final = new Date(ano_final,mes_final,dia_final);    
		var fecha_inicial = new Date(ano_inicial,mes_inicial,dia_inicial); 
	    var diferencia = fecha_final.getTime()-fecha_inicial.getTime();
		if (diferencia<0)
		{
			alert (texto);
			return false;
		}
		else
			return true;
}

function validar_diferencia_fechas(campo_final,campo_inicial,texto)
	{
		var elementos_final = campo_final.value.split("/");
		var dia_final = parseInt(elementos_final[0],10);
		var mes_final = parseInt(elementos_final[1],10);
		var ano_final = parseInt(elementos_final[2],10);
		var elementos_inicial = campo_inicial.value.split("/");
		var dia_inicial = parseInt(elementos_inicial[0],10);
		var mes_inicial = parseInt(elementos_inicial[1],10);
		var ano_inicial = parseInt(elementos_inicial[2],10);
		var fecha_final = new Date(ano_final,mes_final,dia_final);    
		var fecha_inicial = new Date(ano_inicial,mes_inicial,dia_inicial); 
	    var diferencia = fecha_final.getTime()-fecha_inicial.getTime();
		if (diferencia<0)
		{
			alert (texto);
			return false;
		}
		else
			return true;
	}
	
	
function validar_guia(objeto,mensaje)
{
var nume_guia=objeto.value;

constante = parseInt(nume_guia/10)
valor1 = constante - parseInt (constante / 7)  *7

constante1 = (nume_guia/10)-constante
valor2= Math.round(constante1 * Math.pow(10, 1));

	if (valor1 == valor2) { 
		return true;
	}else{ 
		alert ('El campo ' + mensaje + ', no es valido');
		if (!objeto.disabled)
		objeto.focus();
		
		return false;

	};
}


function fecha()
{
  var cadena;
  var today = new Date();
  var day=today.getDate();
  var month = today.getMonth() + 1;
  var year = today.getFullYear().toString();

   var horas=today.getHours();
  var minutos=today.getMinutes();
  var segundos=today.getSeconds();


  //var box=document.getElementById(obj);//this is where we want to print the date
  if ( ( month /10 ) < 1 )
  {
    month=("0" + month).toString(); //add the leading 0 -- looks more professional
  }
  if ( (day/10)<1)
  {
    day=("0" + today.getDate()).toString();//add the leading 0 -- looks better
  }

	if (segundos<10)
	 segundos="0"+segundos;

	if (minutos<10)
	 minutos="0"+minutos;

  //box.value=day + "/" + month + "/" + year+" "+horas+":"+minutos+":"+segundos;
  cadena= year+"/"+month+"/"+day+" "+horas+":"+minutos+":"+segundos;
  
  return cadena;

}


//Chile
//Descripción:  Valida un RUT        //
//Parámetros Entrada: cc_rut         //
//Parametros Salida: True o False        //
function RutVerificador(cc_rut) 
{
 var factor = 2;
 var suma = 0;
 
 var pos = cc_rut.indexOf("-");
 if( pos == -1 )
 {  
  return false;
 }
 
 var valRut = cc_rut.substring(0,pos);
 var digito = cc_rut.substring(pos+1,cc_rut.length);
  
 // Valida Si después del "-" colocó más caracteres....
 if ( digito.length > 1  ) 
 {  
  return false;
 }
 
 for( var i = valRut.length-1; i >= 0; i -= 1)
 {
  var ch = valRut.substring(i, i + 1);
  if (ch < "0" || ch > "9")
  {   
   return false;
  }
  suma = parseInt(ch) * factor + suma;
  factor = factor + 1;
  if( factor == 8)
  {
   factor = 2;
  }
 }
 suma = suma % 11;
 suma = 11 - suma;
 if( suma == 11 )
 {
  suma = 0;
 }
 if( suma == 10 && ( digito == "k" || digito == "K" ))
 {
  return true;
 }
 else if( suma == parseInt(digito) )
 {
  return true;
 }
 return false;
}

	function validar_fecha(campo,nombre)
	{
		r=true;
		//if (!validar_texto(campo,nombre)) r=false;
		if (r)
		{
			var elementos = campo.value.split("/");
			r = (elementos.length==3);
			if (r)
			{
				var dia = parseInt(elementos[0],10);
				var mes = parseInt(elementos[1],10);
				var ano = parseInt(elementos[2],10);
				if (!isNaN(dia))
				{
					if ((dia<1)||(dia>31)) r=false;
					if (elementos[0].length!=2) r=false;
				}
				else r=false;
				if (!isNaN(mes))
				{
					if ((mes<1)||(mes>12)) r=false;
					if (elementos[1].length!=2) r=false;
				}
				else r=false;
				if (!isNaN(ano))
				{
					if (ano<1900) r=false;
					if (elementos[2].length!=4) r=false;
				}
				else r=false;
			}
			if (!r)
			{
				alert(' '+nombre+' debe ingresar con el formato dd/mm/yyyy');
				campo.focus();
			}
		}
		return r;
	}
	
	
//FUNCION QUE DESPLIEGA Y DESPLIEGA LOS DATOS DE UN DIV DETERMINADO
//SI ESTABA DESPLEGADO LO OCULTA, SI ESTABA OCULTO LO DESPLIEGA
function desplegar_div(div_id)
{
	if(div_id.style.display=='block')	
	div_id.style.display='none';
	else 
	{
		if(div_id.style.display=='none')
		div_id.style.display='block';	
	}	
}

//====Aumento campo Recibo--
function desplegar_div_valor(div_id,valor)
{
	if(valor==false)	
	div_id.style.display='none';
	else 
	{
		if(div_id.style.display=='none')
		div_id.style.display='block';	
		
	}	
	
}

//Devuelve true si el elemento está en el arreglo.
function valor_en_arreglo(valor,arreglo)
{
  for (var i=0; i<arreglo.length ;i++)
  { 
	if(arreglo[i]==valor) return true;
  }
	 return false;
}
//Devuelve true si el valor(pa_idpais) está en el arreglo de países CENAM.
function pais_CENAM(pais)
{
	var a_CENAM=new Array();
	a_CENAM[a_CENAM.length] ="CR";
	a_CENAM[a_CENAM.length] ="PA";
	a_CENAM[a_CENAM.length] ="HN";
	a_CENAM[a_CENAM.length] ="NI";
	a_CENAM[a_CENAM.length] ="SV";
	a_CENAM[a_CENAM.length] ="GT";
	
	return valor_en_arreglo (pais,a_CENAM);
	
}

//====fin Aumento campo Recibo--


//====Implementacion Inicial El Salvador
//Para extracargo NEP (notificacion de envio de paquete) para SV el email del cliente es obligatorio
function validar_NEP(forma)
{
	//document.getElementById('NEP');
	obj_NEP=document.getElementById('N');
	if (obj_NEP.checked==true)
	{ 
	
		if (envio_id!='TR' && envio_id!='IC')
		{
		   	if (forma.cli_email.value=='N/A')forma.cli_email.value='';
	   		if (!validarCampo(forma.cli_email,"E-mail de Cliente")) return false;
		}
		else
		{
			
			if (forma.gui_emaildes.value=='N/A')forma.gui_emaildes.value='';
	   		if (!validarCampo(forma.gui_emaildes,"E-mail de Cliente")) return false;
		}
	}
	return true;
}
//====fin Implementacion Inicial El Salvador
//Elimina espacios en blanco a la derecha y al izquierda de una cadena
function trim(cadena)
{
	return cadena.replace(/^\s+|\s+$/g, ""); //};	
}

//------Nuevo IMP EC 2008
//resalta el campo 
function onfocus_color(objeto)
{
	objeto.style.background=color_dentro;
}
//quita el resaltado del campo
function onblur_color(objeto)
{
	objeto.style.background=color_fuera;
}
//devuelve true si la cadena2 esta contenida en la cadena1
function contiene_cadena(cadena1, cadena2)
{
	
	//alert(cadena1.match(cadena2));
	if(cadena1.match(cadena2)==null) 
	{
		//alert('1.no encuentra::'+cadena2+'::en::'+cadena1);
		return false;
	}
	else 
	{
		//alert('2.encuentra::'+cadena2+'::en::'+cadena1);
		return true;
	}
}
//------fin Nuevo IMP EC 2008
//===Mejora Formato Números
function FormatoNumero(numero,smiles,sdecimales){ 
//Propiedades 
	this.valor = numero || 0 
	this.dec = -1; 
	
	//Métodos 
	this.formato = numFormat; 
	this.ponValor = ponValor; 
	
	//Definición de los métodos 
	function ponValor(cad) 
	{ 
		if (cad =='-' || cad=='+') return 
		if (cad.length ==0) return 
		if (cad.indexOf('.') >=0) 
		this.valor = parseFloat(cad); 
		else 
		this.valor = parseInt(cad); 
	} 
	
	function numFormat(dec, miles) 
	{ 
		var num = this.valor, signo=3, expr; 
		var cad = ""+this.valor; 
		var ceros = "", pos, pdec, i; 
		for (i=0; i < dec; i++) 
		ceros += '0'; 
		pos = cad.indexOf('.') 
		if (pos < 0) 
		cad = cad+"."+ceros; 
		else 
		{ 
		pdec = cad.length - pos -1; 
		if (pdec <= dec) 
		{ 
		for (i=0; i< (dec-pdec); i++) 
		cad += '0'; 
		} 
		else 
		{ 
		num = num*Math.pow(10, dec); 
		num = Math.round(num); 
		num = num/Math.pow(10, dec); 
		cad = new String(num); 
		} 
		} 
		pos = cad.indexOf('.') 
		if (pos < 0) pos = cad.lentgh 
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
		signo = 4; 
		if (miles && pos > signo) 
		do{ 
		expr = /([+-]?\d)(\d{3}[\.\,]\d*)/ 
		cad.match(expr) 
		cad=cad.replace(expr, RegExp.$1+','+RegExp.$2) 
		} 
		while (cad.indexOf(',') > signo) 
		if (dec<0) cad = cad.replace(/\./,'') 
		cad=cad.replace( /\./g,"*");
		cad=cad.replace( /\,/g,smiles);
		cad=cad.replace( /\*/g,sdecimales);
		return cad; 
		
	} 
	
	
} 
//==Mejoras Inicio
//función que quita slash and backslash
function quitar(objeto)
{
	var y=objeto.value
	y=y.replace("\\", " ");
	objeto.value=y;
}

function validarPeso (peso_minimo,peso_maximo,peso,incremento,objeto)
{
	var pmin=parseFloat(peso_minimo);
	var pmax=parseFloat(peso_maximo);
	var pinc=parseFloat(incremento);
	var p=parseFloat(peso);
	var pcor = parseFloat(peso_minimo);
	if (p > pmax)
	{
		
			alert ('El peso NO puede ser mayor al peso: ' + peso_maximo);
			if(PA_IDPAIS=='VE'){
				document.getElementById('gui_peso_ing_real').value=''; 
				objeto.value=''; 				
				document.getElementById('gui_peso_ing_real').focus(); 
				
			}
			else{
				objeto.focus();
				objeto.select();
			}
			return false;
		
	}
	else if (p <= pmin)
	{
		objeto.value=pcor.toFixed(2);
	}
	else
	{
		while (pcor < p)
		{
			pcor = (pcor + pinc);			
			if (pcor >= p)
			{
				if(pcor.toFixed(2)>pmax) pcor=pmax;
				objeto.value=pcor.toFixed(2);
				break;				
			}
		}
	}
	return true;
}

function validar_diferencia_fechas(objanio,objmes,texto)
{
	var dia_final = 1;
	var mes_final = objmes.value;
	var ano_final = objanio.value;
	var fecha_final = new Date(ano_final,mes_final,dia_final);    

	var fecha = new Date();
	var fecha_inicial = new Date(fecha.getYear(),fecha.getMonth(),fecha.getDate()); 
	var diferencia = fecha_final.getTime()-fecha_inicial.getTime();
	if (diferencia<0){//2592000000
		alert (texto);//TEXTO DE ALERTA
		var mes = fecha.getMonth();
		var anio = fecha.getYear();
		for (var i=0; i<=objanio.options.length ;i++)
		{ 

			if (objanio[i].value==anio)
			{
				objanio.options[i].selected=true;
				break;
			}

		}
		objmes.options[mes].selected=true;
		objmes.focus();
		return false;
	}
	else
		return true;
}

//==Fin Mejoras Inicio

//=====Implementacion Venezuela
function aleatorio(inferior,superior){ 
	numPosibilidades = superior - inferior 
	aleat = Math.random() * numPosibilidades 
	aleat = Math.round(aleat) 
	return parseInt(inferior) + aleat 
} 
//=====FIN Implementacion Venezuela

//** function max length for textArea by Jp
function validarTextArea(obj,name,len)
	{
	var value = obj.value;
	value = value.length;
	num_caracteres = value;
	num_caracteres_permitidos=len;
	if (num_caracteres > num_caracteres_permitidos)
		{
		obj.value = contenido_textarea.substr(0,len);
		}
	else
		{
		contenido_textarea = obj.value;
		}
	}

function alfanumerico(evt)
	{
	//asignamos el valor de la tecla a keynum
	if(window.event)
		{// IE
		tecla = evt.keyCode;
		}
	else
		{
		tecla = evt.which;
		}
	//comprobamos si se encuentra en el rango
	if(65<=tecla && tecla<=90 || 97<=tecla && tecla<=122 || 48<=tecla && tecla<=57 ||  tecla==32)
		{
		return true;
		}
	else
		{
		return false;
		}
	}
/*
function alfanumerico(obj)
	{
	var tecla = window.event.keyCode;
	if(65<=tecla && tecla<=90 || 97<=tecla && tecla<=122 || 48<=tecla && tecla<=57 ||  tecla==32)
		{
		}
	else
		{
		window.event.keyCode=0;
	 	}
	}
*/
