
//-----------------------------------
// Entrada en los cursos
// Selecciona entre clave simple o unica

function Entrar(form, target)
  {


	var acceso = form.acceso.value;

	if ( acceso.search(/<.*>/gi) !=-1)
		ret = Entrar_CLVUNICA(form, target);
	else
		ret = Entrar_CLVSIMPLE(form, target);


	return ret;
 }



//-----------------------------------
// Entrada en los cursos con clave unica

function Entrar_CLVUNICA(form, target)
{
 
	login = form.acceso.value.replace(/<|>/g,'');
	clave = form.clave.value;

	window.open("/MLTgestor/selectTree.html?config=/gestor/claveunica&login=" + login + "&password=" + clave ,'GCU','toolbar=no,status=no,width=400,height=600,location=no,scrollbars=yes');

	return 'OK';
}




//-----------------------------------
// Entrada en los cursos con clave simple

function Entrar_CLVSIMPLE(form, target)
  {

	SetCookie('TIPO','alumno','','/');
	SetCookie('LOGIN',form.acceso.value,'','/');
	SetCookie('PASS',form.clave.value,'','/');


 	var ret=GoIn();


 	target = ( typeof target=='undefined') ? '_fullscreen' : target;

 	if ( isOK(ret) ) dsptch( target );

 	return ret;
 }




//-----------------------------------
// Redirecciona la entrada al curso sencillo
//-----------------------------------


function dsptch ( target ) {

	var lnk="";
	var ret=SelAlumnos('');


	if ( !isOK(ret) ) return ( getMsg(ret) );

	// salta al path que marca idcur
	if (typeof (alum.idcur)!='undefined' && alum.idcur!='null') lnk="/formacion2/cursos/" + alum.idcur;
		else lnk="/formacion2";

	// guarda el mail del tutor en una cookie para que lo pueda leer GetTutorMail()
	SetCookie('TUTEMAIL',unescape(alum.tutemail),'','/');
	SetCookie('AFSID',unescape(alum.AFSID),'','/');

	// abre el curso
	switch ( target )
	{
		case '_this':

			window.top.location=lnk;

		break;

		case '_new':
			window.open ( lnk );
		break;

		case '_opener':
			window.opener.top.location = lnk;
		break;

		case '_fullscreen':
			Cwin = window.open ( lnk,'WCURSO','toolbar=no,menubar=no,location=no,resizable=yes');
			Cwin.moveTo(0,0);
			Cwin.resizeTo(screen.availWidth,screen.availHeight);
			// MODIFICADO POR MAITE PARA QUE CIERRE LA VENTANA DE DONDE VIENE.
			window.close();

		break;

		case '_fullscreen_noclose':
			Cwin = window.open ( lnk,'WCURSO','toolbar=no,menubar=no,location=no,resizable=yes');
			Cwin.moveTo(0,0);
			Cwin.resizeTo(screen.availWidth,screen.availHeight);

		break;



	}


	return '';
}


function testPopups_curlinks()
{
	
		var 	popupWindow = window.open('/foroanaya/testnavegador/popups.html','WTEST2','height=200,width=200');
	
	
		return popupWindow;
}


//-----------------------------------
// Realiza el proceso de entrada a un curso hijo
// desde un curso padre
//-----------------------------------
function Entrar_Parent ( parentcur, childcur ) {


	var tipo=GetCookie('TIPO');
	var login=GetCookie('LOGIN');
	var pass=GetCookie('PASS');

	if (tipo==null)  return('KO=Falta identificacion');


	// Modifica el identificador  para entrar en el curso hijo
	// Se ha elegido ~ como separador para que no se confunda con otros separadores
	// del tipo : que se dan en otros sitios como el log

	if ( login.indexOf('~')==-1 ) {
		login += '~'+ parentcur + '~' + childcur;
		document.cookie="LOGIN="+ login +"; path=/ ";
	}


 	var ret=GoIn();

 	if ( isOK(ret) ) dsptch( );

	return '';

}




//-----------------------------------
// Realiza el proceso de salida desde curso hijo
// desde un curso padre
//-----------------------------------
function Salir ( ) {



	var tipo=GetCookie('TIPO');
	var login=GetCookie('LOGIN');
	var pass=GetCookie('PASS');

	if (tipo==null)  return('KO=Falta identificacion');

	// registra la salida en el log
 	var ret=GoOut();

 	if ( !isOK(ret) ) return (ret);


	// Si existe identificación de un curso hijo hace un dispath
	// y  si no, sale

   	if ( login.indexOf('~')!=-1 )
		dsptch_parent( );
	else
		dsptch_single ();

	WaitMessage_close();

	return '';

}


//-----------------------------------------
// Redirecciona la salida del curso
// segun si viene de Formacion o de Mascerca
//-----------------------------------------


function dsptch_single () {

	var lnk="";
	var param="";
	var ret=SelAlumnos('');


	if ( !isOK(ret) ) return ( getMsg(ret) );

	// mira el grupo al que pertenece el curso

	switch  ( alum.curtipo)
	{
		case '20':
		case '21':
		case '24':
		case '31':
			urlout = 'http://www.anayaformacion.com/foroanaya/';		
			//urlout = 'http://www.anayamascerca.com/menu.html?nav=0:0';
			//urlout = 'http://desarrollo.anaya.es:1771/foroanaya/';
		break;

		case '22':
			urlout = 'http://www.cepmalaga.com/';
		break;

		case '23':
			urlout = 'http://www.safa.edu/';
		break;
		
		case '30':
			urlout = 'http://www.algaida.es';
		break;

		case '40':
			urlout = 'http://www.socotec.com/sp/';
			//urlout = 'http://www.educarioja.org/educarioja/home.jsp';

		break;

		default:
			urlout = 'http://www.anayaformacion.com/formacion2/index.html';		
			//urlout = 'http://www.anayaformacion.com/formacion2/index.html';
			//urlout = 'http://desarrollo.anaya.es:1771/formacion3/';

	}


	top.location.href = urlout;
}



//Presenta el mensaje de espera
function Salir_wait() { WaitMessage(1); }


//-----------------------------------------
// Redirecciona la entrada al curso padre
// para ello añade los datos de las evaluaciones
// del alumno
//-----------------------------------------


function dsptch_parent () {

	var lnk="";
	var param="";
	var ret=SelAlumnos('');


	if ( !isOK(ret) ) return ( getMsg(ret) );

	// Retoma los datos de las evaluaciones o ejercicios del alumnos
	// para pasarlos al curso padre
	switch (alum.codcur) {

		// Curso TIE
		// En este curso los datos significativos no son evaluaciones
		// si no los porcentajes de ejercicios realizados y estos van
		// a partir del dato 506 de estejer
		// Pero como este se considera aprobado se devuelve un 10
		case 4:
			/*
			ret=GetEjer('')
			if ( !isOK(ret) ) return ( getMsg(ret) );
			param = alum.codcur + ':'+ dato.estejer.substr(506,15);
			*/
			param = alum.codcur + ':'+ '10';
			break;

		// para cualquier otro curso
		default:
			var s,i,j=0;
			ret=GetEval('')
			if ( !isOK(ret) ) return ( getMsg(ret) );
			s = dato.esteval.split(':');
			param = alum.codcur + ':';
			for ( i=0; i<alum.ntemas; i++) {
				param += s[3*i+1] + ':';
				}
			break;




	}

	// haya el link de retorno para el curso padre
	var login=GetCookie('LOGIN');
	var lg = login.split('~');
	SetCookie('LOGIN',lg[0],'','/');

	var ret=SelAlumnos('');
	if ( !isOK(ret) ) return ( getMsg(ret) );

	// localiza el  path que marca idcur
	if (typeof (alum.idcur)!='undefined' && alum.idcur!='null') lnk="/formacion2/cursos/" + alum.idcur + "/index.html#" + param ;
		else lnk = "/formacion2";

	// salta al curso
	top.location.href="http://www.anayaformacion.com" + lnk ;

	return '';
}


//------------------------------------------
// Mensajes de espera
//------------------------------------------




function WaitMessage(type) {

	var left= parseInt(self.screenX + self.outerWidth/2);
	var top = parseInt(self.screenY + self.outerHeight/2);

	// abre el mensaje de espera
		winmess=window.open("/formacion2/conectando.html","alert", "left=" + parseInt(left-160) + ",top=" + parseInt(top-65) + ",width=320,height=130");
		//winmess.document.open();

		//winmess.document.write('<HTML>\n<HEAD>\n<TITLE>Enviando...</TITLE>\n\n</HEAD>\n\n<BODY>\n<TABLE WIDTH=300 border=2 BGCOLOR="#FFC000"><tr><td ALIGN=center> <font size=3><br> <b>Enviando Datos a la Base de Datos</font>\n<br><img src="/formacion/banners/Spin2.gif" ><br>Un momento por favor...\n</td></TR></TABLE>\n\n</BODY>\n\n\n\n</HTML>\n\n');

		//winmess.document.close();

	winmess.focus();


}

// funcion para cerrar la ventana de mensajes
function WaitMessage_close() { winmess.close(); }

