// JavaScript Document
/*
//Indice de Funciones

	ValidarDatosIdent
	respIdentificacion
	CerrarVentanaIdent
	IntroPwd
	IntroNIF
	InicioFormularioIdentificacion
	
*/
///// FUNCIONES //////////////////////////////////////////////////////////////////////////
	
	function ValidarDatosIdent(){
		usuario = document.getElementById('nif').value;
		clave = document.getElementById('pwd').value;
		document.getElementById('divErrorIdentificacion').innerHTML ="&nbsp;"
		if (usuario == ""){
			document.getElementById('divErrorIdentificacion').innerHTML="Introduzca el usuario";
			document.getElementById('nif').focus('nif');
			return 0;
		}
		if (clave == ""){
			document.getElementById('divErrorIdentificacion').innerHTML="Introduzca clave";
			 document.getElementById('pwd').focus('pwd')	;		
			return 0;
		}
		var dir;
		dir=url_inicio+"tecnologiaweb/includes/identificacioncomprobar.asp?nif="+usuario+"&pwd="+clave;
		document.getElementById('botonEntrar').disabled=true;
		$.get(dir, '', respIdentificacion);
		return true;
		/*doAjax(dir,'','respIdentificacion','post','1');*/
	}  
	
	function respIdentificacion(texto){		
	    var IdentificacionValue = texto.getElementsByTagName('identificacion')[0];		
	    var registradoValue = IdentificacionValue.getElementsByTagName('registrado')[0].firstChild.data;
		if (registradoValue=="ok"){
			//identificacion correcta
			nombre=IdentificacionValue.getElementsByTagName('nombre')[0].firstChild.data;
			ncolegiado=IdentificacionValue.getElementsByTagName('ncolegiado')[0].firstChild.data;
			if (LlamadaIdentDesde=='identificacion'){
				document.location.href=url_inicio+"tecnologiaweb/inicio.asp";
			}else{
				CerrarVentanaIdent();
			}
		}else{
			var mensaje = IdentificacionValue.getElementsByTagName('mensaje')[0].firstChild.data;
			document.getElementById('divErrorIdentificacion').innerHTML = mensaje;
			if (Trim(mensaje)=="Cuenta bloqueada."){
					alert("Acceso temporalmente bloqueado. Por favor, póngase en contacto con el Dpto. de Contabilidad del colegio. Telf: 952 22 42 06. Disculpe las molestias.");
				
			}
			document.getElementById('pwd').value="";
			document.getElementById('pwd').focus();
		}
		document.getElementById('botonEntrar').disabled = false;
	}
	
	function CerrarVentanaIdent(){
		// poner el nombre del div definitivo
		OcultarFondoAlert();
		$('#divSesionPerdida').hide();						
	}
	
	function IntroPwd(e){
		if (window.event) {
			var tecla=window.event.keyCode;
		} else if (e)  {
			var tecla=e.which;
		}
		if (tecla==13){
//			$('#botonEntrar').trigger('click');
			ValidarDatosIdent();
	
		}

	}
	function IntroNIF(e){
		if (window.event) {
			var tecla=window.event.keyCode;
		} else if (e)  {
			var tecla=e.which;
		}
		if (tecla==13){
			Form.Element.focus('pwd');
		}
		return false;
	}	
	
	function InicioFormularioIdentificacion(desde){
		document.getElementById('nif').focus();

		addEvent(document.getElementById('botonEntrar'), 'click', ValidarDatosIdent);
		addEvent(document.getElementById('botonCerrar'), 'click', CerrarVentanaIdent);
		addEvent(document.getElementById('pwd'),'keypress',IntroPwd,false);
		/*addEvent(document.getElementById('nif'),'keypress',IntroNIF,false);*/
		
		$('#pwd').keypress(IntroPwd);

		LlamadaIdentDesde=desde;
		if (LlamadaIdentDesde=='identificacion'){
			$('#botonCerrar').hide();
		}
	}
	
	var LlamadaIdentDesde='';


