/*
	function checkUncheckAll
	Copyright 2006
	http://www.shawnolson.net
*/
function checkUncheckAll(theElement)
{
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{
			theForm[z].checked = theElement.checked;
		}
	}
}
 
/*
	function checkUncheckSome
	Copyright 2006
	http://www.shawnolson.net
*/
function checkUncheckSome(controller,theElements) {
	//theElements is an array of objects designated as a comma separated list of their IDs
	//If an element in theElements is not a checkbox, then it is assumed
	//that the function is recursive for that object and will check/uncheck
	//all checkboxes contained in that element
	// examples: http://www.shawnolson.net/a/1302/select-some-checkboxes-javascript-function.html
	
var formElements = theElements.split(',');
var theController = document.getElementById(controller);
for(var z=0; z<formElements.length;z++){
theItem = document.getElementById(formElements[z]);
if(theItem){
if(theItem.type){
     if(theItem.type == 'checkbox' && theItem.id != theController.id){
   theItem.checked = theController.checked;
  }
} else {

  var nextArray = '';
   for(var x=0;x <theItem.childNodes.length;x++){
    if(theItem.childNodes[x]){
      if (theItem.childNodes[x].id){
        nextArray += theItem.childNodes[x].id+',';
   }
    }
   }
   checkUncheckSome(controller,nextArray);
 
 }

}
  }
 }

/*
*	Descripcion : Indicar el nombre del formulario, nombre del combobox, el valor a ser asignado (1-marcados; 0-desmardados) (fg = Funcion Glogal)
*	Autor		: Jacob Gutierrez
*	Fecha		: 4 de Julio de 2009
*/
fg_SetAllCheckBoxes = function(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

/*
*	Descripcion : Crea url con los objetos del formulario para pasar como parametro.
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 7 de Julio de 2008
*/
creaParametrosURL = function(frm)
{
	var formParametros = $(frm).serialize();
	formParametros = formParametros.replace(/=&/g, "/0/");
	formParametros = formParametros.replace(/&/g, "/");
	formParametros = formParametros.replace(/=/g, "/");
	formParametros = formParametros.replace(/ /g, ",");

	return formParametros;	
}

/*
*	Descripcion : Reemplaza acentos.
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 20 de Septiembre de 2008
*/
reemplazaAcentos = function(palabra)
{

	stringF = palabra;
	
	for(i=0;i<(stringF.length-1);i++)
	{

		stringF = stringF.replace("\u00C1","A")
		stringF = stringF.replace("\u00E1","a")
		stringF = stringF.replace("\u00C9","E")
		stringF = stringF.replace("\u00E9","e")
		stringF = stringF.replace("\u00CD","I")
		stringF = stringF.replace("\u00ED","i")
		stringF = stringF.replace("\u00D3","O")
		stringF = stringF.replace("\u00F3","o")
		stringF = stringF.replace("\u00DA","U")
		stringF = stringF.replace("\u00FA","u")
		stringF = stringF.replace("\u00D1","N")
		stringF = stringF.replace("\u00F1","n")
		stringF = stringF.replace("\u00DC","U")
		stringF = stringF.replace("\u00FC","u")
		stringF = stringF.replace("\*","")
		
	}
	
	return stringF;	
}


/*
*	Descripcion : Valida NIF (universia).
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 30 de Septiembre de 2008
*/
validaNIF = function(dni) 
{
	numero = dni.substr(0,dni.length-1);
	let = dni.substr(dni.length-1,1);
	numero = numero % 23;
	letra='TRWAGMYFPDXBNJZSQVHLCKET';
	letra=letra.substring(numero,numero+1);
	if (letra!=let) 
		resultado = false;
	else
		resultado = true;
  
	return resultado;	  
}


/*
*	Descripcion : Valida CIF (universia).
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 30 de Septiembre de 2008
*/
validaCIF = function(texto)
{
	var pares = 0;
	var impares = 0;
	var suma;
	var ultima;
	var unumero;
	var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	var xxx;
	
	texto = texto.toUpperCase();
	
	var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
	 if (!regular.exec(texto)) return false;
		 
	 ultima = texto.substr(8,1);

	 for (var cont = 1 ; cont < 7 ; cont ++){
		 xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
		 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
		 pares += parseInt(texto.substr(cont,1));
	 }
	 xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
	 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	 
	 suma = (pares + impares).toString();
	 unumero = parseInt(suma.substr(suma.length - 1, 1));
	 unumero = (10 - unumero).toString();
	 if(unumero == 10) unumero = 0;
	 
	 if ((ultima == unumero) || (ultima == uletra[unumero]))
		 return true;
	 else
		 return false;

}



/*
*	Descripcion : Valida Identificadores Universia.
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 30 de Septiembre de 2008
*/
validaIdentificador = function(vcTipoIdentificador, vcIdentificador)
{
	if(vcTipoIdentificador == 1)
	{
		return validaCIF(vcIdentificador);		
	}
	else if(vcTipoIdentificador == 2)
	{
		return validaNIF(vcIdentificador);		
	}
	else
	{
		return true;
	}
}

/*
*	Descripcion : Mueve la opciï¿½n (<option>) de un combobox a otro.
*	Parametros  : 	'valora', value de la opciï¿½n a ser movida. 
					'origen', objeto combobox donde esta la opciï¿½n a ser movida.
					'destino', objeto combobox que recibe la opciï¿½n seleccionada (indicada en el primer parametro).
*	Autor		: Jacob Gutierrez Romero
*	Fecha		: 4 de Octubre de 2008
*/
function selecciona(valora,origen,destino) {
	var ok=false; 
	if (valora !='Cualquiera') {
		i=destino.length;
		if (i==1 && destino.options[0].text=='Cualquiera') {
				destino.options[0].text=destino.options[destino.length-1].text;
				destino.options[0].value=destino.options[destino.length-1].value;
				destino.options[0].title=destino.options[destino.length-1].value;
				destino.length--;
				i--;
		}
		
		valor=origen.selectedIndex ;
		if (valor>=0) {
			texto=origen.options[valor].text;
		
			for (var e=0; e< i; e++) {
				if (texto==destino.options[e].text) {
					ok=true;
					break;
				}
				else
					ok=false;
			}
			if (!ok) {
				var el = new Option(texto,valora);
				destino.options[i] = el;
				destino.options[i].title = texto;
			}
				
			for (var i=0;i<origen.length;i++) {
				if (origen.options[i].value==valora) {
					for (j=i;j<origen.length-1;j++){
						origen.options[j].text=origen.options[j+1].text;
						origen.options[j].value=origen.options[j+1].value;
						origen.options[j].title=origen.options[j+1].value;
					}
					origen.length--;
//					if (origen.length ==0) {
//						var el = new Option('Cualquiera',0);
//						origen.options[0] = el;
//					}
					break;
				}
			}
		} // FIN: if (valor>=0)
		else
			alert("Seleccione una opciï¿½n primero");
	} //FIN: if (valora !='Cualquiera')
}


/*
*	Descripcion : Cambia de color y estilo el elemento (una fila <tr> generalmente) cuando el Mouse esta encima (Mouse Over). Normalmente se llama asï¿½: 
*	Parametros  : 	'src', objeto 
					'clrOver', Color que se asigna
*	Autor		: Jacob Gutierrez Romero
*	Fecha		: 4 de Octubre de 2008
*/
function mOvr(src,clrOver) {
	src.style.cursor = 'hand';
	src.bgColor = clrOver;
}
					  
function mOut(src,clrIn) {
	src.style.cursor = 'default';
	src.bgColor = clrIn;
}

/*
*	Descripcion : Abrir una nueva ventana/popup con las dimensiones indicadas y ciertas caracteristicas de la ventana predefinidas:
					- toolbar: Sin barra de herramientas
					- location: No se despliega la direccion de la pagina
					- directories:
					- status: sin la barra inferior que indica el estatus
					- menubar: Sin la barra de menu
					-.... etc :)
*	Parametros  : 	'archivo', pagina que se llama/invoca
					'nombre', Nombre que se da a la ventana/pop-up. Recordar que si se trata de crear una ventana con el mismo nombre de otra (ya abierta), se reutiliza esa ventana y no habre otra.
					'ancho', ancho de la nueva ventana en pixeles.
					'alto', alto de la nueva ventana en pixeles.
*	Autor		: Jacob Gutierrez Romero
*	Fecha		: 10 de Octubre de 2008
*/
function ventanaFija(archivo,nombre,ancho,alto) {
	LeftPosition=(screen.width)?(screen.width-ancho)/2:100;
	TopPosition=(screen.height)?(screen.height-alto)/2:100;
	anexosayuda = window.open(archivo,nombre,"left="+LeftPosition+",top="+TopPosition+",height="+alto+",width="+ancho+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,maximized");
}


/*
*	Descripcion : Las siguientes funciones permiten el intercambio de valores entre Select`s.
*                 Permite la selecciï¿½n y traspaso de multiples registros.
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 17 de Octubre de 2008
*/
function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
	theSel.options[theIndex] = null;
  }
}

function intercambiarSelect(selectDesde, selectHasta)
{
  
  var selLength = selectDesde.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  for(i=selLength-1; i>=0; i--)
  {
	if(selectDesde.options[i].selected)
	{
	  selectedText[selectedCount] = selectDesde.options[i].text;
	  selectedValues[selectedCount] = selectDesde.options[i].value;
	  deleteOption(selectDesde, i);
	  selectedCount++;
	}
  }
  
  for(i=selectedCount-1; i>=0; i--)
  {
	addOption(selectHasta, selectedText[i], selectedValues[i]);
  }
}

	//function que limpia caja de textos en base al cambio de pais
	limpiaTextos = function (){	
		
	document.cpfcheck.cpf_2_check.value = "";
		
	
	}
	
	//Autor: Marco Lobos
	//Fecha: 02/06/2009
	//Objetivo: Limpiar caja de texto x, de un formulario x
	limpiaTextBoxIngresoCandidatoBR = function (){
		document.formRegistroInicial.txtRut.value = "";
	}
	
	
	//Autor: Samuel Carriel
	//Fecha: 20/07/2007
	//Objetivo: Verificar el formato de campos (RG / RNE) y CPF (Los equivalentes a RUT).
	// Uso: <input type="rut" onBlur="formato(this,2)">  <input type="rut2" onBlur="formato(this,1)">
	// VER = 1, se valida que un solo caracter exista despues del '-' (puede ser numero o letra). Ahora permite que la 'letra'
	// aparezca en cualquiera parte (corregir a futuro!. Ejemplo formato: 12.345.678-X
	// VER = 2 , se valida que hasta 2 caracteres existan despues del '-'. Solo numeros!
	// Ejemplo de formato: 123.456.789-00

	function formato(obj,ver)
	{
	 
	 
	 
	 if (ver == 1){//chile
		
		largoTotal = 12;
	 }
	 else{//brasil
		
		largoTotal = 14;
		 
	 }
	 cadena=obj.value;
	 cuenta=0;
	 var tmpstr = "";
	  for ( i=0; i < largoTotal ; i++ )
		if ( cadena.charAt(i) != ' ' && cadena.charAt(i) != '.' && cadena.charAt(i) != '-' )
	 	{
		  	tmpstr = tmpstr + cadena.charAt(i);
	   		character=cadena.charAt(i);
	   		codi=character.charCodeAt(0);
	   	if (codi>=48 && codi<=57)
			cuenta++;
	   	}
	   		largo=tmpstr.length;
	   	if (largo>ver)
	   	{	 
	   		if ((ver==2 && cuenta!=largo) || (ver==1 && cuenta+1<largo))
	   		{
	  			alert('Formato erroneo');
	  			obj.focus();
	   		}
	   		else
	   		{	
				sw=largo-ver; 
				cambiado="";
	   			for (i=0;i<sw;i++){
					cambiado=cambiado + tmpstr.charAt(i);
					if (i+1!=sw && ((sw-i)%3==1))
						cambiado=cambiado + '.';
	   			}
	   		if (ver==1)
			
				cambiado=cambiado+'-'+tmpstr.charAt(largo-1);
				
			
	   		else
				cambiado=cambiado+'-'+tmpstr.charAt(largo-2)+tmpstr.charAt(largo-1);
	   			obj.value=cambiado; 
	   		}
	  	}
	 }

	function isDigit (c){
	return ((c >= "0") && (c <= "9"))
	} 

	//function que verifica el CPF del candidato Brasilero
	function TestaCPF(strCPF) {
		
	var Soma;
    var Resto;
	var strCPFtemp = '';
    Soma = 0;
	//Primero quitamos los caracteres que no sean numericos (como '.' y '-')
    for (i = 1; i <= strCPF.length; i++) {
		if ( isDigit( strCPF.substring(i - 1, i) ) ) { 
        	strCPFtemp = strCPFtemp + strCPF.substring(i - 1, i);
	   }
    }
	strCPF = strCPFtemp;
    if (strCPF == "00000000000") {
        return false;
    }
    for (i = 1; i <= 9; i++) {
        Soma = Soma + parseInt(strCPF.substring(i - 1, i)) * (11 - i);
    }
    Resto = Soma * 10 % 11;
    if (Resto == 10 || Resto == 11) {
        Resto = 0;
    }
    if (Resto != parseInt(strCPF.substring(9, 10))) {
        return false;
    }
    Soma = 0;
    for (i = 1; i <= 10; i++) {
        Soma = Soma + parseInt(strCPF.substring(i - 1, i)) * (12 - i);
    }
    Resto = Soma * 10 % 11;
    if (Resto == 10 || Resto == 11) {
        Resto = 0;
    }
    if (Resto != parseInt(strCPF.substring(10, 11))) {
        return false;
    }
    return true;
}
	
	function validaCEP(strCEP)
	{
		var strCEPtemp = '';
		for (i = 1; i <= strCEP.length; i++) {
			if ( isDigit( strCEP.substring(i - 1, i) ) ) { 
				strCEPtemp = strCEPtemp + strCEP.substring(i - 1, i);
		   }
		}
		return (strCEPtemp.replace(" ","").length == 8);
	}

	//Autor: Jorge Leiva
	//Fecha: 08/07/2010
	//Objetivo: validar el identificador Peruano, la unica validación es que sea de 8 digitos y que solo sean digitos. 
	function validaDni(Identificador,obj)
	{
	var	largo = obj.length;
	var	valida =false;
	if(largo==8){
		if ( IsNumeric(obj))  {
			valida =true;
		}
	}
	return valida;
	}


	function TestaCEP2(strCEP) {
		

	var strCEPtemp = '';
	var strCEPfinal = '';
	//Primero quitamos los caracteres que no sean numericos (como '.' y '-')
    for (i = 1; i <= strCEP.length; i++) {
		if ( isDigit( strCEP.substring(i - 1, i) ) ) { 
        	strCEPtemp = strCEPtemp + strCEP.substring(i - 1, i);
	   }
    }
	if(eval(strCEPtemp) == 0)
		return false;
	if(strCEPtemp.length > 4)
	{
       strCEPfinal = strCEPtemp.substring(0, 5);
	   strCEPfinal = strCEPfinal + '-' + strCEPtemp.substring(5, strCEP.length);
	}
	else
		return strCEP;
	return strCEPfinal;
}

	function dv(T)
			{
			var M=0,S=1;
				for(;T;T=Math.floor(T/10))
						S=(S+T%10*(9-M++%6))%11;
				return S?S-1:'k';
			}
	
	//verifica si el rut ingresado es correcto
	function esrut(T)
		{
			miRut = T.value;
			nn=miRut.length;
			if (nn <4) 
				return false;
			mm=nn-2;
			gg=String(miRut.charAt(mm));
			if (gg != "-")
			{
				return false;
			}	
			digito=String(miRut.charAt(nn-1));
			n=1;
			num=0;
			j=1;
			for(i=mm-1;i>=0;i--){
				if (String(miRut.charAt(i))=='.'){
					if (j%4 !=0)
					{
						return false;
					}	
				}
				else
				{		
					num=num + n*parseInt(miRut.charAt(i));
					n=n*10;
				}
				j=j+1;	
			}
			digito2=dv(num);
			if ((digito!=digito2 && digito!='K') || (digito=='K' && digito2!='k'))
				return false;
			return true;				
		} 		
	
	
	
	function Procesa() {
		var cmbPaisDocumento = document.cpfcheck.pais_documento.options[document.cpfcheck.pais_documento.selectedIndex].value;
		
		<!--- CPF --->
		if (cmbPaisDocumento == 31) { //caso brasil CPF
			formato(document.cpfcheck.cpf_2_check,2);
							
				 if (TestaCPF(document.cpfcheck.cpf_2_check.value)  == false) {
		 			alert ('ï¿½ necessï¿½rio preencher corretamente o nï¿½mero do CPF!');
					return false;
		 		 }	
		 }
		 
		 else if (cmbPaisDocumento == 44){ // caso de chile rut
		  	formato(document.cpfcheck.cpf_2_check,1);
			if (esrut(document.cpfcheck.cpf_2_check)==false){
			alert('El rut Ingresado es incorrecto');
			document.cpfcheck.cpf_2_check.focus();
			return false;
			}
		}	
		 	
	
	
	document.cpfcheck.submit();
	}


	
/*
*	Descripcion : Esta funcion permite la validacion del cpf del candidato , el numero 5 corresponde al tipo de documento cpf de la tabla tipodocumento
*	Autor		: alvaro gutierrez
*	Fecha		: 04/06/09
*/
	
	validaCPF = function(obj,cpf){
	
			if(obj == 5)//CPF
			{
				if (TestaCPF(cpf)  == false) {
		 			resultado = false;
				}
				else {
					
					resultado = true;
				}
				
			}
	
	return resultado;
		
		
	}
	
	
/*
*	Descripcion : Funcion que permite desplegar u ocultar un div determinado, dependiendo de los valores entregados
*	Autor		: Rodrigo Marin Saxton
*	Fecha		: 10/06/2009
*/

	despliegaDiv = function(valor, idDiv)
	{
		
		if(valor == 1)
		{
			Effect.Appear($(idDiv))	
		}
		else
		{
			Effect.Fade($(idDiv))	
		}
	
		
	}
		

		
	function IsNumeric(valor) 
	{ 
		var log=valor.length; var sw="S"; 
		for (x=0; x<log; x++) 
		{ v1=valor.substr(x,1); 
		v2 = parseInt(v1); 
		//Compruebo si es un valor numï¿½rico 
		if (isNaN(v2)) { sw= "N";} 
		} 
		if (sw=="S") {return true;} else {return false; } 
	}


function formato_cnpj(cnpj)
{
	var	largo = cnpj.length;
	var cnpj; 
	
	// Se evalua 12.xxx.xxx/xxxx-xx
	if(largo<=2){
		if ( IsNumeric(cnpj) ) {
			if(largo==2) {
				return cnpj +'.';
			}
			else {
				return cnpj ;
			}
		} else 
			return cnpj.substr(0, cnpj.length-1);
	}
	// Se evalua xx.456.xxx/xxxx-xx
	if ((largo>=4) && (largo<=6) ){
		tempCep = cnpj.substr(4, cnpj.length-3);
		if ( IsNumeric(tempCep) ) {
			if(largo==6){
				return cnpj +'.';
			} else 
				return cnpj ;
		} else 
			return cnpj.substr(0, cnpj.length-1);
	}
	// Se evalua xx.xxx.89(10)/xxxx-xx
	if ((largo>=8) && (largo<=10) ){
		tempCep = cnpj.substr(8, cnpj.length-7);
		if ( IsNumeric(tempCep) ) {
			if(largo==10) {
				return cnpj +'/';
			} else 
				return cnpj ;
		} else 
			return cnpj.substr(0, cnpj.length-1);
	}
	// Se evalua xx.xxx.xxx/(12)(13)(14)(15)-xx
	if ((largo>=12) && (largo<=15) ){
		tempCep = cnpj.substr(12, cnpj.length-11);
		if ( IsNumeric(tempCep) ) {
			if(largo==15) {
				return cnpj +'-';
			} else 
				return cnpj ;
		} else 
			return cnpj.substr(0, cnpj.length-1);
	}
	// Se evalua xx.xxx.xxx/xxxx-(17)(18)
	if ((largo>=17) && (largo<=18) ){
		tempCep = cnpj.substr(17, cnpj.length-16);
		if ( IsNumeric(tempCep) ) {
			return cnpj ;
		} else 
			return cnpj.substr(0, cnpj.length-1);
	}
return cnpj ;
}

function isEmailAddress(theElement)
	{
		var retorno = true
		var s = theElement.value;
		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)){
		      retorno = true;
		   }  
		   else{
		     retorno = false;
		   }
	return retorno;	 
	} 	


function formatofono(fono)
{

		var	largo=fono.length;
		var fono;
	
		// Primer caracter
		if (largo<=1){ 
			if (IsNumeric(fono) ) {
				if(largo==1)
					return '(' + fono ;
				else 
					return fono ;
			} 
		}
		
		// Ingresa segundo caracter, aÃƒÂ±adimos el cierre de parentesis
		if (largo==3) { 
			return fono + ')' ;
		} 

		
		// Validar los caracteres del 5 al 8 que sean numeros
		if (largo==8){ 
			 return fono + '.' ;
		} 
		else {
				return fono;
			}
		
		
		return fono;
}


 function CompararFechas(fecha, fecha2)  
   {  
     var xMonth=fecha.substring(3, 5);  
     var xDay=fecha.substring(0, 2);  
     var xYear=fecha.substring(6,10);  
     var yMonth=fecha2.substring(3, 5);  
     var yDay=fecha2.substring(0, 2);  
     var yYear=fecha2.substring(6,10);  
     if (xYear> yYear)  
     {  
         return true  ;
     }  
     else  
     {  
       if (xYear == yYear)  
       {   
         if (xMonth> yMonth)  
         {  
             return true;  
         }  
         else  
         {   
           if (xMonth == yMonth)  
           {  
             if (xDay> yDay)  
               return true;  
             else  
               return false;  
           }  
           else  
             return false;  
         }  
       }  
       else  
         return false;  
     }  
 }  

function formatoRemuneracionBrasil(obj)
{
 var ver=2;
 cadena=obj.value;
 var tmpstr = "";
  for ( i=0; i < cadena.length ; i++ )
    if ( cadena.charAt(i) != ' ' && cadena.charAt(i) != '.' && cadena.charAt(i) != ',' )
      tmpstr = tmpstr + cadena.charAt(i);
   largo=tmpstr.length;
   if (largo>ver)
   {
    sw=largo-ver; 
    cambiado="";
   for (i=0;i<sw;i++){
    cambiado=cambiado + tmpstr.charAt(i);
    if (i+1!=sw && ((sw-i)%3==1))
    cambiado=cambiado + '.';
   }
   cambiado=cambiado+','+tmpstr.charAt(largo-2)+tmpstr.charAt(largo-1);
   obj.value=cambiado; 
  }
 } 
 
//funcion para manejar el contador de caracteres en contacto para que el SQL no se caiga por que escede el limite
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Written by Steve - http://jsmadeeasy.com/ -->

<!--
function getObject(obj) {
 var theObj;
 if(document.all) {
   if(typeof obj=="string") {
     return document.all(obj);
   } else {
     return obj.style;
   }
 }
 if(document.getElementById) {
   if(typeof obj=="string") {
     return document.getElementById(obj);
   } else {
     return obj.style;
   }
 }
 return null;
}

//Contador de caracteres..
function Contar(entrada,salida,texto,caracteres) {
 var entradaObj=getObject(entrada);
 var salidaObj=getObject(salida);
 var longitud=caracteres - entradaObj.value.length;
 if(longitud <= 0) {
   longitud=0;
   texto='<div class="disable">'+texto+'</div>';
   entradaObj.value=entradaObj.value.substr(0,caracteres);
 }
 salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

//-->


//esta funcion verifica que solo se ingresen numeros en un campo  - MLH 15-09-2009
//Modificado por: GermÃ¡n Leal Migueles.
// se cambiÃ³ la forma de obtener el evento de tecla puesto que habÃ­a conflictos
// con lightwindows.
var nav4 = window.Event ? true : false;
function soloNum(evt){
// OBS: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
//var key = (nav4) ? evt.which : evt.keyCode;
if(evt.which)
	key = evt.which;
else
	key = evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57));
}
//funcion que calcula la fecha de nacimiento para corp292
function calcular_edad(fecha){

    //calculo la fecha de hoy
    hoy=new Date()
    //alert(hoy)

    //calculo la fecha que recibo
    //La descompongo en un array
    var array_fecha = fecha.split("/")
    //si el array no tiene tres partes, la fecha es incorrecta
    if (array_fecha.length!=3)
       return false

    //compruebo que los ano, mes, dia son correctos
    var ano
    ano = parseInt(array_fecha[2]);
    if (isNaN(ano))
       return false

    var mes
    mes = parseInt(array_fecha[1]);
    if (isNaN(mes))
       return false

    var dia
    dia = parseInt(array_fecha[0]);
    if (isNaN(dia))
       return false

    //si el aÃ±o de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4
    if (ano<=99)
       ano +=1900

    //resto los aÃ±os de las dos fechas
    
	edad=hoy.getFullYear()- ano - 1; //-1 porque no se si ha cumplido aÃ±os ya este aÃ±o
	
	//si resto los meses y me da menor que 0 entonces no ha cumplido aÃ±os. Si da mayor si ha cumplido
    if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0
       return edad
    if (hoy.getMonth() + 1 - mes > 0)
       return edad+1

    //entonces es que eran iguales. miro los dias
    //si resto los dias y me da menor que 0 entonces no ha cumplido aÃ±os. Si da mayor o igual si ha cumplido
    if (hoy.getUTCDate() - dia >= 0)
       return edad + 1

    return edad
}
 // dice si cadena es texto no vacio o no                                      
 function es_vacio(cadena)  
   {                                    // DECLARACION DE CONSTANTES  
     var blanco = " \n\t" + String.fromCharCode(13); // blancos  
                                        // DECLARACION DE VARIABLES  
     var i;                             // indice en cadena  
     var esta_vacio;                      // cadena es vacio o no  
     for(i = 0, es_vacio = true; (i < cadena.length) && es_vacio; i++) // INICIO  
       esta_vacio = blanco.indexOf(cadena.charAt(i)) != - 1;  
     return(esta_vacio);  
   }  
//Autor: GermÃ¡n Leal Migueles
//Descripcion:
// implementacion de funciones Trim (quitar espacios laterales), RTrim (quitar espacios a la derecha) y 
//LTrim (quitar espacios a la izquierda)

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

//Autor: GermÃ¡n Leal Migueles
//Descripcion: Algunas implementaciones para el manejo de fechas

Date.prototype.dateDiff = function(d)
{ return Math.round((d.valueOf() - this.valueOf()) / 86400000); }
Date.prototype.add = function(n)
{
 var d = new Date(this);
 d.setDate(d.getDate() + n);
 return d;
}
Date.prototype.addMonth = function(n)
{
 var d = new Date(this);
 d.setMonth(d.getMonth() + n);
 return d;
}

Date.prototype.addYear = function(n)
{
 var d = new Date(this);
 d.setFullYear(d.getFullYear() + n);
 return d;
}
Date.prototype.getFirstDate =
  function() { var d = new Date(this); 
               d.setDate(1); return d; }
Date.prototype.getLastDate =
  function() { var d = this.addMonth(1); 
               d.setDate(1); return d.add(-1); }
Date.prototype.between =
function(d1, d2) { return 0 <= d1.dateDiff(this) && 
                   d2.dateDiff(this) <= 0; } 


//function formatNumber(num,prefix){
function formateoSalarioBR(obj)
{
 var ver=2;
 cadena=obj.value;
 var tmpstr = "";
  for ( i=0; i < cadena.length ; i++ )
    if ( cadena.charAt(i) != ' ' && cadena.charAt(i) != '.' && cadena.charAt(i) != ',' )
      tmpstr = tmpstr + cadena.charAt(i);
   largo=tmpstr.length;
   if (largo>ver)
   {
    sw=largo-ver; 
    cambiado="";
   for (i=0;i<sw;i++){
    cambiado=cambiado + tmpstr.charAt(i);
    if (i+1!=sw && ((sw-i)%3==1))
    cambiado=cambiado + '.';
   }
   cambiado=cambiado+','+tmpstr.charAt(largo-2)+tmpstr.charAt(largo-1);
   obj.value=cambiado; 
  }
 } 
