var txt_Movil = 'N\xBA PCS';
var txt_Rut = 'RUT Usuario';
var txt_PIN = '';
var expressInstall = "archivos_home/swf/expressInstall.swf";

/* FUNCIONES INICIALES ****************/
window.addEvent('domready', function() {								 
	//mensaje de error
	if($('alerta_error')) {
		$('alerta_error').fade(0,0);
	}

	if($('Movil')) $('Movil').addEvent('keypress', enterForm);
	if($('PIN')) $('PIN').addEvent('keypress', enterForm);
	if($('submit')) $('submit').addEvent('keypress', enterForm);
});

function enterForm(event) {
	if(event.code == 13 && validaFormulario() && $('PIN').value.length==4) enviarFormulario()
}


/*************************************/
function movilFocus() {
	if($('Movil').value == txt_Movil) {
		$('Movil').value = '';
	}
}

function movilBlur() {
	if($('Movil').value != '') {
		//validaFormulario(); 
		validaLoginMovil();
	} else {		
		$('Movil').value = txt_Movil;
		$('PIN').value = "";
		$('labelClave').style.display ="block";
		limpiarCasillas(['Movil'],'text_login_large');
		
		//if($('Rut').value == txt_Rut && $('PIN').value == txt_PIN) {
		//	$('alerta_error').fade(0);
		//}
	}
}

function rutFocus() {
	if($('Rut').value.substr(0,3) == txt_Rut.substr(0,3)) {
		$('Rut').value='';
	}
}

function rutBlur() {
	if($('Rut').value != '') {
		//validaFormulario(); 
		validaLoginRUT();
	} else {	
		$('Rut').value = txt_Rut;
		limpiarCasillas(['Rut'],'text_login_large');
		
		if($('Movil').value == txt_Movil && $('PIN').value == txt_PIN) {
			$('alerta_error').fade(0);
		}
	}
}

function labelClaveClick() {
	$('labelClave').style.display = 'none';
	$('PIN').focus();	
}
function pinFocus() {
	if($('PIN').value == txt_PIN) {
		$('PIN').value='';
		$('labelClave').style.display = 'none';
	}
}

function pinBlur() {
	if($('PIN').value != '') {
		//validaFormulario(); 
		validaLoginPIN();
	} else {			
		$('PIN').value = txt_PIN;
		$('labelClave').style.display = 'block';
		
		limpiarCasillas(['PIN'],'text_login_large');
	}
}

function pinKeyUp() {
	if($('PIN').value.length==4) { 
		//validaFormulario(); 
		validaLoginPIN();
	}	
}

function soloRUT(evt) {
	var key = evt.keyCode ? evt.keyCode : evt.which ;
	return (key <= 31 || (key >= 48 && key <= 57) || key == 75 || key == 107); 
}

function soloNumeros(evt){
	var key = evt.keyCode ? evt.keyCode : evt.which ;
	return (key <= 31 || (key >= 48 && key <= 57)); 
}

//************************
//   GET: ajaxGet(url, div)
//************************
function ajaxGet(url, div) {
	ajax = ajaxobj();
	ajax.open("GET", url, true);

	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1: 
				document.getElementById(div).innerHTML = '<img src="archivos_home/img/home/ajax.gif" border="0" />Cargando...';
				break;
				
			case 4: 
				document.getElementById(div).innerHTML = ajax.responseText;
				break;
		}
	}
	ajax.send(null);
}

//************************
//    AJAX: OBJETO
//************************
function ajaxobj() {
	try	{
		_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E)	{
			_ajaxobj = false;
		}
	}
	if(!_ajaxobj && typeof XMLHttpRequest!='undefined') {
		_ajaxobj = new XMLHttpRequest();
	}
	
	return _ajaxobj;
}



window.onload = function() {
	document.getElementById('PIN').value = "";
}
function OcultaLabel(){
	var clave = document.getElementById('PIN').value;
	if(clave.length > 0){
		document.getElementById('labelClave').style.display = "none";	
	}
}
