/*Modificacion       : M001.
  Fecha Modificacion : 01/02/2011
  Autor              : Alex Magñin
  Empresa            : ANTCIPA S.A.
  Objetivo           : Se convierte el rut ingresado por el usuario a mayuscula.
*/
<!----

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}

function isInteger (s)
{
	var i;

	if (isEmpty(s)) 
		if (isInteger.arguments.length == 1)
			return false;
	else
		return (isInteger.arguments[1] == true);


	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

function solonum()
{
	if ((event.keyCode<48)||(event.keyCode>57))
	{
		event.returnValue=false;
	}
}

function solonum_fono(ref)
{
	if (((event.keyCode == 45) && (ref.value.length == 2) && (ref.value != "2-")) || ((event.keyCode == 45) && (ref.value == "2")))
	{
		event.returnValue=true;
		return;
	}
	if ((event.keyCode<48)||(event.keyCode>57))
	{
		event.returnValue=false;
	}
}


function trim(variable)
{
	largo=variable.length;
	m=0;
	while (m<largo){
		caracter=variable.substring(m,m+1);
		if (caracter != " ")	
		{
			break;
		}
		m++;
	}
	if (m==largo)
	{
		return "";
	}
	n=0;
	while (n<largo)
	{
		caracter=variable.substring(largo-n-1,largo-n);
		if (caracter != " ")	
		{
			break;
		}
		n++;
	}
	variable=variable.substring(m,largo-n);
	return variable;
}

function borrar()
{
	document.formulario.reset();
}

function solorut()
{
	if (((event.keyCode>47)&&(event.keyCode<58))||(event.keyCode==75)||(event.keyCode==107))
	{
		event.returnValue=true;
	}
	else
	{
		event.returnValue=false;	
	}
}

function rut(variable,digit)
{
	Sum = 0;
	digito = 0;
	factor = 2;
	largo = variable.length;
	while (largo !== 0)
	{
		Sum = Sum + (variable.substring(largo, largo-1) * factor);
		if (factor == 7)
			{
				factor = 2;
			}
		else
		{
			factor = factor + 1;
		}
		largo = largo - 1;
	}
	d = 11 - Sum % 11;
	if (d == "10")
	{
		digito = "K";
        }
	else 
	{
		if (d == "11")
		{
			digito = 0;
		}
		else
		{
			digito = d;
		}
	}
	if (digito == digit)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function mail(texto)
{
	var supported = 0;
	booleano2=false;
	
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
	{
		booleano2=(texto.indexOf(".") > 2) && (texto.indexOf("@") > 0);
		return booleano2;
	}
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	booleano2=(!r1.test(texto) && r2.test(texto));
	return booleano2;
}

function buscarchar(cadena1,cadena2)
{
	var s = cadena1.indexOf(cadena2);
	return (s) ;
}


function formatear(forma)
{
	forma.prsn_id_temp.value=forma.prsn_id_temp.value.toUpperCase();
	if (forma.prsn_id_temp.value != "")
	{
		valor=forma.prsn_id_temp.value;
		forma.prsn_id.value=valor;
		if (valor.length > 1)
		{
			forma.prsn_id_temp.value=insertapuntos(valor.substring(0,valor.length - 1)) + '-' + valor.substring(valor.length - 1,valor.length);
		}
	}
}

function formatear3(forma)
{
	forma.rut1.value=forma.rut1.value.toUpperCase();//M001
	if (forma.rut1.value != "")
	{ 
		
		valor=forma.rut1.value;
		forma.rut2.value=valor;
		if (valor.length > 1)
		{
			forma.rut1.value=insertapuntos(valor.substring(0,valor.length - 1)) + '-' + valor.substring(valor.length - 1,valor.length);
		}
	}
}

function formatear4(forma)
{
	forma.rut1.value=forma.rut2.value;
}

function Right(strvar,intcant)
{
	strtemp = "";
	intlargo = strvar.length -1;
	for(i = 1;i <= intcant; i++)
	{
		strtemp = strtemp + strvar.charAt(intlargo);
		intlargo--;	
	}
			
	strtmp2=""
	for(intlargo = strtemp.length -1; intlargo >=0; intlargo--)
	{
		strtmp2 = strtmp2 + strtemp.charAt(intlargo);
	}
	return(strtmp2);
}

function insertapuntos(strval)
{
	var A = new Array();
	var strtemp = strval;
			
	strtemp = new Number(strtemp);
	strtemp = new String(strtemp);
	if (strtemp.length > 3)
	{
		for(var i = 0; strtemp.length > 3; i++)
		{
			A[i] = Right(strtemp,3);
			strtemp /= 1000;
			strtemp=new String(strtemp);
			if (strtemp.indexOf('.') != -1)
			{
      				strtemp = strtemp.substr(0,strtemp.indexOf('.'));
      			}
		}
		for(i-- ;i >= 0 ;i--)
		{
			strtemp = strtemp + "." + A[i];
		}
	}
	return(strtemp);			
}

	function ValidaCaracter(Tipo, Adicional, Enter){
		var strNumeros ="0123456789";
		var Minusculas = "abcdefghijklmnñopqrstuvwxyzáéíóú ";

		var Mayusculas = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ´´´";
		var strTexto = Minusculas + Mayusculas + " ";
		var strAlfanumerico = strTexto + strNumeros + "/-_,;.";
		
		var strMail = Minusculas + Mayusculas + strNumeros + "@_-.";
		
		var TextoTotal = new String();
		TextoTotal = Adicional;
		
		switch(Tipo){
			case "Numerico":{
				TextoTotal += strNumeros;
			break;	
			}
			case "Texto":{
				TextoTotal += strTexto;
			break;	
			}
			case "Alfanumerico":{
				TextoTotal += strAlfanumerico;
			break;	
			}
			case "Email":{
				TextoTotal += strMail;
			break;	
			}
		}
		
		
				
		strCaracter = new String();
		strCaracter = String.fromCharCode(window.event.keyCode);

         	if (Enter) {     
              		if(window.event.keyCode==13) {
                   		revisar(document.formulario);
                   		return true;
              		}
         	}		
		var Pos = TextoTotal.indexOf (strCaracter);
		if(Pos > -1){
			return true;
		}else{
			window.event.keyCode = 0;
			return false;			
		}
			
		
	}


	function ValidaCaracter2(Tipo, Adicional, Caracter){
		var strNumeros ="0123456789";
		var Minusculas = "abcdefghijklmnñopqrstuvwxyz";
		var Mayusculas = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
		var strTexto = Minusculas + Mayusculas + " ";
		var strAlfanumerico = strTexto + strNumeros + "/-_,;";
		
		var strMail = Minusculas + Mayusculas + strNumeros + "@_-.";
		
		var TextoTotal = new String();
		TextoTotal = Adicional;
		
		//alert(Caracter);
		
		switch(Tipo){
			case "Numerico":{
				TextoTotal += strNumeros;
			break;	
			}
			case "Texto":{
				TextoTotal += strTexto;
			break;	
			}
			case "Alfanumerico":{
				TextoTotal += strAlfanumerico;
			break;	
			}
			case "Email":{
				TextoTotal += strMail;
			break;
			}
		}
		strCaracter = new String();
		strCaracter = String.fromCharCode(Caracter);
		
		if (Caracter == 13){ 
		    revisar(document.formulario);
		
		}
		
		var Pos = TextoTotal.indexOf (strCaracter);
		if(Pos > -1){
			return true;
		}else{
			//window.event.keyCode = 0;
			return false;			
		}
	}
	


function valiTexto(e) {
	key = "";
	key = e.which;
	tipo = e.id;
	if (	ValidaCaracter2('Texto','',key) || key == 8) {
		return true;
	}else{
		return false;
	}
}

function valiNumero(e) {
	key = "";
	key = e.which;
	tipo = e.id;
	if (	ValidaCaracter2('Numerico','',key) || key == 8) {
		return true;
	}else{
		return false;
	}
}

function valiAlfanumerico(e) {
	key = "";
	key = e.which;
	tipo = e.id;
	if (	ValidaCaracter2('Alfanumerico','',key) || key == 8) {
		return true;
	}else{
		return false;
	}
}
 
function valiEmail(e) {
	key = "";
	key = e.which;
	tipo = e.id;
	if (	ValidaCaracter2('Email','',key) || key == 8) {
		return true;
	}else{
		return false;
	}
}

function Captura(Tipo){
	if (navigator.appName == 'Netscape') {
		if (Tipo == "T"){
			window.captureEvents(Event.KEYPRESS);
			window.onKeyPress = valiTexto;
		}
		if (Tipo == "N"){
			window.captureEvents(Event.KEYPRESS);
			window.onKeyPress = valiNumero;
		}
		if (Tipo == "A"){
			window.captureEvents(Event.KEYPRESS);
			window.onKeyPress = valiAlfanumerico;
		}
		if (Tipo == "E"){
			window.captureEvents(Event.KEYPRESS);
			window.onKeyPress = valiEmail;
		}
	}
}

function formatear(forma)
{
	forma.prsn_id_temp.value=forma.prsn_id_temp.value.toUpperCase();
	if (forma.prsn_id_temp.value != "")
	{
		valor=forma.prsn_id_temp.value;
		forma.prsn_id.value=valor;
		if (valor.length > 1)
		{
			forma.prsn_id_temp.value=insertapuntos(valor.substring(0,valor.length - 1)) + '-' + valor.substring(valor.length - 1,valor.length);
		}
	}
}

function formatear2(forma)
{
	forma.prsn_id_temp.value=forma.prsn_id.value;
}

function formatearRut(psRut)
{
	var largoRut 	= psRut.length;
	var RutSalida 	= '';	
	
	if (largoRut < 10)
	{
		for(i=10;i>largoRut;i--)
		{
			RutSalida += '0';
		}
		RutSalida += psRut;
	}
	else
	{
		RutSalida = psRut;
	}
	return RutSalida;
}



/************************************************************/


function teclaEvento(evento){ if (evento.keyCode)
return evento.keyCode;
else
return evento.which;
} 

function continuarEvento(evento,continuar){ if (evento.preventDefault && !continuar){
evento.preventDefault();
evento.stopPropagation();
} 
return continuar;
}

function ValidarDecimal(event,txtCampo)
{
var ac;
//no utilizo el name ya tengo la referencia del text
var texto = txtCampo.value;


ac = teclaEvento(event); 
if ((ac >= 48) && (ac <= 57) || (ac == 44) || (ac == 46) || (ac == 13) || (ac == 8) || (ac == 9)) {

}
else { 
if (ac == 46) {
//en fire fox no puedes cambiar el codigo de la tecla
//o no lo he visto lo que puedes hacer es cancelar el evento
//window.event.keyCode = ac - 2;
continuarEvento(event,false)
}
else { 
if (ac == 13) {
window.lnkIntro.click(); 
}
else {
//window.event.keyCode = " ";
//esta funcion te garantiza que canceles el evento tanto en ie como en ff
return continuarEvento(event,false)
}
} 
//document.forms.item(0).item(txtCampo).value = texto; 
texto = "";
}
} 





/************************************************************/

/*GGG*/

function validarVacNum(e)
{
 var key;
 if(window.event) // IE
 {
  key = e.keyCode;
 }
  else if(e.which) // Netscape/Firefox/Opera
 {
  key = e.which;
 }
 if (key < 48 || key > 57) 
    {
      return false;
    }
 return true;
}


function validarVacTxt(e)
{
 var key;
 if(window.event) // IE
 {
  key = e.keyCode;
 }
  else if(e.which) // Netscape/Firefox/Opera
 {
  key = e.which;
 }
 alert (key);
 /*//////*/
 
 if ((key >=65 && key <= 90) || (key >=97 && key <= 122) || key == 8 || key == 9  || key == 177 || key == 32 || key == 209 || key == 241 || key == 225 || key == 233 || key == 237 || key == 243 || key == 250 || key == 193 || key == 201 || key == 205 || key == 211 || key == 218)
    {
      return true;
    }
 return false;
 /**********/
}





//------>

