var contenidoTextarea = ""
function ValidaLongitudTextArea(name,numCaracteresPermitidos){	
	var objTextArea = document.getElementById(name);
	var objText	= document.getElementById("C_" + name);		
	
	numCaracteres = objTextArea.value.length
	
	if (numCaracteres <= numCaracteresPermitidos){
		contenidoTextarea = objTextArea.value	
	}else{
		objTextArea.value = contenidoTextarea
	}
	
	if (numCaracteres >= numCaracteresPermitidos){
		objText.style.color="#ff0000";
	}else{
		objText.style.color="#5F6C76";
	}
	
	CuentaLongitud(objTextArea, objText)
}
	
function CuentaLongitud(objTextArea, objText){
	objText.value=objTextArea.value.length
}

function LlenarIndexUbigeo(obj1,obj2)
{  
  if (obj1[obj1.selectedIndex].value != '')
    obj2.value = obj1.selectedIndex;
  else
    obj2.value = '';   
}

function mostrarObjeto(objeto) {
  mostrarTitulo = document.getElementById(objeto.name + "Titulo");
  mostrarCampo = document.getElementById(objeto.name + "Campo");
  
  if (objeto[objeto.selectedIndex].value == '-1'){
	mostrarTitulo.style.display = 'block';
	mostrarCampo.style.display = 'block';
	ValidatorField(objeto.name + "Otra", true, "", "", "");
  }
  else{
	mostrarTitulo.style.display = 'none'; 
	mostrarCampo.style.display = 'none';
	ValidatorField(objeto.name + "Otra", false, "", "", "");
  }
}

function ValidarDocumento(obj){
	if (obj.value == "DNI"){		
		a_fields['numeroDocumento']['f'] = 'unsigned';
		a_fields['numeroDocumento']['mn'] = 8;
		a_fields['numeroDocumento']['mx'] = 8;
	}else{
		a_fields['numeroDocumento']['f'] = 'alphanum2';
		a_fields['numeroDocumento']['mn'] = 4;
		a_fields['numeroDocumento']['mx'] = 20;	
	}
}

function ValidatorField(nombre, obligatorio, formato, minimo, maximo){
	if (obligatorio != "")
		a_fields[nombre]['r'] = obligatorio;
	if (formato != "")
		a_fields[nombre]['f'] = formato;
	if (minimo != "")
		a_fields[nombre]['mn'] = minimo;
	if (maximo != "")
		a_fields[nombre]['mx'] = maximo;	
}

// solo texto y número
function valida_ingreso2()
{
  var key=window.event.keyCode;//codigo de tecla. 
  if (key < 48 || key > 57) //si no es numero en rango ascii
  {  
    //window.event.keyCode=0;//anula la entrada de texto. 
    event.returnValue = false;//anula la entrada de otros signos. 
  }
}

function valida_solo_texto_y_numero()
{
	//verify for netscape/mozilla
	var key1=window.event.keyCode;
	var key2=event.which;
	
	var isNS4 = (navigator.appName=="Netscape")?1:0;	
	
	if(!isNS4){
		if ((key1 > 32 && key1 < 48) || (key1 > 57 && key1 < 65) || (key1 > 90 && key1 < 97) || (key1 > 122 && key1 < 129) || (key1 > 165 && key1 < 192))
			event.returnValue = false;
	}
	else{
		if ((key2 > 32 && key2 < 48) || (key2 > 57 && key2 < 65) || (key2 > 90 && key2 < 97) || (key2 > 122 && key2 < 129) || (key2 > 165 && key2 < 192)) 
			return false;
	}
}


function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++){
	    j=i;
		if(s.substring(i,i+1) != ' ')		
			break;
	}	
	return s.substring(j, s.length);
}

function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}
function Trim(s){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(s));
}

function ActualizarFechaNacimiento()
{
  var fechaNacimiento = document.getElementById("fechaNacimiento");
  var dia = document.getElementById("dia");
  var mes = document.getElementById("mes");
  var anio = document.getElementById("anio");
   
  fechaNacimiento.value = dia.value + "/" + mes.value + "/" + anio.value;
}

function LlenarCampoHdd(obj1,obj2)
{  
  if (obj1[obj1.selectedIndex].value != '')
    obj2.value = obj1[obj1.selectedIndex].text;
  else
    obj2.value = '';
}