<!--

function troba_nom(str)
{
	re=/%20/gi;
	theleft = str.indexOf("n=") + 2;
	theright = str.indexOf("&");
	newstr=str.substring(theleft, theright);
	return(newstr.replace(re," "));
}

function troba_email(str)
{
	theleft = str.indexOf("e=") + 2;
	theright = str.indexOf("&m=");
	
	return(str.substring(theleft, theright));
}

function troba_maxlec(str)
{
	theleft = str.indexOf("m=") + 2;
	theright = str.lastIndexOf("&");
	return(str.substring(theleft, theright));
}

function nomes_variables(str)
{
	theleft = str.indexOf("?") + 3;
	newstr=str.substring(theleft);
	return(newstr);
}

function desencripta(Str_Message)
{
	Len_Str_Message=Str_Message.length;
	Str_Encrypted_Message="";
	for (Position = 0 ; Position<Len_Str_Message ; Position+=3)
	{
		cadena_num = Str_Message.substring(Position, Position+3);
		Ascii_Num_Byte = 999-cadena_num;
	        caracter=String.fromCharCode(Ascii_Num_Byte);
		Str_Encrypted_Message=Str_Encrypted_Message+caracter;
	} 
	return(Str_Encrypted_Message);
}

function encripta(Str_Message)
{
	Len_Str_Message=Str_Message.length;
	Str_Encrypted_Message="";
	for (Position = 0 ; Position<Len_Str_Message ; Position++)
	{
		Byte_To_Be_Encrypted = Str_Message.substring(Position, Position+1); 
		Ascii_Num_Byte = 999-Str_Message.charCodeAt(Position);
		Str_Encrypted_Message=Str_Encrypted_Message+Ascii_Num_Byte;

	} 
	return(Str_Encrypted_Message);
}

function precarga()
{

	for (i=0; i<=max_lec; i++)
	{
		linea="Lesson "+i;
		window.document.MyForm.lessons.options[i] = new Option(linea,i);
	}


	linia_url=window.location.href;

	theright=linia_url.indexOf(".htm");
	if (linia_url.indexOf("leccionUS")!=(-1))
	{
		theleft=linia_url.indexOf("leccionUS");
		leccion=parseInt(linia_url.substring(theleft+9,theright));
		window.document.MyForm.keyblayout.options[0].selected = 1;
	}
	else
	{
		if (linia_url.indexOf("leccionUK")!=(-1))
		{
			theleft=linia_url.indexOf("leccionUK");
			leccion=parseInt(linia_url.substring(theleft+9,theright));
			window.document.MyForm.keyblayout.options[1].selected = 1;
		}
		else
		{
			if (linia_url.indexOf("leccionBEL")!=(-1))
			{
				theleft=linia_url.indexOf("leccionBEL");
				leccion=parseInt(linia_url.substring(theleft+10,theright));
				window.document.MyForm.keyblayout.options[2].selected = 1;
			}
			else
			{
				if (linia_url.indexOf("leccionBRA")!=(-1))
				{
					theleft=linia_url.indexOf("leccionBRA");
					leccion=parseInt(linia_url.substring(theleft+10,theright));
					window.document.MyForm.keyblayout.options[3].selected = 1;
				}
				else
				{
					if (linia_url.indexOf("leccionCANI")!=(-1))
					{
						theleft=linia_url.indexOf("leccionCANI");
						leccion=parseInt(linia_url.substring(theleft+11,theright));
						window.document.MyForm.keyblayout.options[4].selected = 1;
					}
					else
					{
						if (linia_url.indexOf("leccionCANF")!=(-1))
						{
							theleft=linia_url.indexOf("leccionCANF");
							leccion=parseInt(linia_url.substring(theleft+11,theright));
							window.document.MyForm.keyblayout.options[5].selected = 1;
						}
						else
						{
							if (linia_url.indexOf("leccionDAN")!=(-1))
							{
								theleft=linia_url.indexOf("leccionDAN");
								leccion=parseInt(linia_url.substring(theleft+10,theright));
								window.document.MyForm.keyblayout.options[6].selected = 1;
							}
							else
							{
								if (linia_url.indexOf("leccionFIN")!=(-1))
								{
									theleft=linia_url.indexOf("leccionFIN");
									leccion=parseInt(linia_url.substring(theleft+10,theright));
									window.document.MyForm.keyblayout.options[7].selected = 1;
								}
								else
								{
									if (linia_url.indexOf("leccionFRA")!=(-1))
									{
										theleft=linia_url.indexOf("leccionFRA");
										leccion=parseInt(linia_url.substring(theleft+10,theright));
										window.document.MyForm.keyblayout.options[8].selected = 1;
									}
									else
									{
										if (linia_url.indexOf("leccionGER")!=(-1))
										{
											theleft=linia_url.indexOf("leccionGER");
											leccion=parseInt(linia_url.substring(theleft+10,theright));
											window.document.MyForm.keyblayout.options[9].selected = 1;
										}
										else
										{
											if (linia_url.indexOf("leccionICE")!=(-1))
											{
												theleft=linia_url.indexOf("leccionICE");
												leccion=parseInt(linia_url.substring(theleft+10,theright));
												window.document.MyForm.keyblayout.options[10].selected = 1;
											}
											else
											{
												if (linia_url.indexOf("leccionITA")!=(-1))
												{
													theleft=linia_url.indexOf("leccionITA");
													leccion=parseInt(linia_url.substring(theleft+10,theright));
													window.document.MyForm.keyblayout.options[11].selected = 1;
												}
												else
												{
													if (linia_url.indexOf("leccionJAP")!=(-1))
													{
														theleft=linia_url.indexOf("leccionJAP");
														leccion=parseInt(linia_url.substring(theleft+10,theright));
														window.document.MyForm.keyblayout.options[12].selected = 1;
													}
													else
													{

														if (linia_url.indexOf("leccionLAT")!=(-1))
														{
															theleft=linia_url.indexOf("leccionLAT");
															leccion=parseInt(linia_url.substring(theleft+10,theright));
															window.document.MyForm.keyblayout.options[13].selected = 1;
														}
														else
														{
															if (linia_url.indexOf("leccionDUT")!=(-1))
															{
																theleft=linia_url.indexOf("leccionDUT");
																leccion=parseInt(linia_url.substring(theleft+10,theright));
																window.document.MyForm.keyblayout.options[14].selected = 1;
															}
															else
															{
																if (linia_url.indexOf("leccionNOR")!=(-1))
																{
																	theleft=linia_url.indexOf("leccionNOR");
																	leccion=parseInt(linia_url.substring(theleft+10,theright));
																	window.document.MyForm.keyblayout.options[15].selected = 1;
																}
																else
																{
																	if (linia_url.indexOf("leccionPOR")!=(-1))
																	{
																		theleft=linia_url.indexOf("leccionPOR");
																		leccion=parseInt(linia_url.substring(theleft+10,theright));
																		window.document.MyForm.keyblayout.options[16].selected = 1;
																	}
																	else
																	{
																		if (linia_url.indexOf("leccionES")!=(-1))
																		{
																			theleft=linia_url.indexOf("leccionES");
																			leccion=parseInt(linia_url.substring(theleft+9,theright));
																			window.document.MyForm.keyblayout.options[17].selected = 1;
																		}
																		else
																		{
																			if (linia_url.indexOf("leccionSWIG")!=(-1))
																			{
																				theleft=linia_url.indexOf("leccionSWIG");
																				leccion=parseInt(linia_url.substring(theleft+11,theright));
																				window.document.MyForm.keyblayout.options[18].selected = 1;
																			}
																			else
																			{
																				if (linia_url.indexOf("leccionSWIF")!=(-1))
																				{
																					theleft=linia_url.indexOf("leccionSWIF");
																					leccion=parseInt(linia_url.substring(theleft+11,theright));
																					window.document.MyForm.keyblayout.options[19].selected = 1;
																				}
																				else //US
																				{
																					theleft=linia_url.indexOf("leccionUS");
																					leccion=parseInt(linia_url.substring(theleft+9,theright));
																					window.document.MyForm.keyblayout.options[0].selected = 1;
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}


	window.document.MyForm.lessons.options[leccion].selected = 1;


	if (troba_email(variables_no_encriptades)=="Invitado")
	{
		window.document.MyForm.EditarDatos.disabled=true;
	}


}

function cambioLeccion(leccion, elmail)
{
	variables_a_encriptar='e='+elmail+'&l='+leccion+'&t='+teclado+'&';
	variables_encriptades=encripta(variables_a_encriptar);
	window.location="cambiar_leccion.php?v="+variables_encriptades;	
}

function cambioTeclado(teclado, elmail, leccion)
{
	if ((teclado)==0)
	{
		//US
		variables_a_encriptar='e='+elmail+'&t=1&'+'l='+leccion+'&';
	}
	else
	{
		if ((teclado)==1)
		{
			//UK
			variables_a_encriptar='e='+elmail+'&t=2&'+'l='+leccion+'&';
		}
		else
		{
			if ((teclado)==2)
			{
				//BEL
				variables_a_encriptar='e='+elmail+'&t=18&'+'l='+leccion+'&';
			}
			else
			{
				if ((teclado)==3)
				{
					//BRA
					variables_a_encriptar='e='+elmail+'&t=15&'+'l='+leccion+'&';
				}
				else
				{
					if ((teclado)==4)
					{
						//CANI
						variables_a_encriptar='e='+elmail+'&t=11&'+'l='+leccion+'&';
					}
					else
					{
						if ((teclado)==5)
						{
							//CANF
							variables_a_encriptar='e='+elmail+'&t=12&'+'l='+leccion+'&';
						}
						else
						{
							if ((teclado)==6)
							{
								//DAN
								variables_a_encriptar='e='+elmail+'&t=4&'+'l='+leccion+'&';
							}
							else
							{
								if ((teclado)==7)
								{
									//FIN
									variables_a_encriptar='e='+elmail+'&t=3&'+'l='+leccion+'&';
								}
								else
								{
									if ((teclado)==8)
									{
										//FRA
										variables_a_encriptar='e='+elmail+'&t=17&'+'l='+leccion+'&';
									}
									else
									{
										if ((teclado)==9)
										{
											//GER
											variables_a_encriptar='e='+elmail+'&t=8&'+'l='+leccion+'&';
										}
										else
										{
											if ((teclado)==10)
											{
												//ICE
												variables_a_encriptar='e='+elmail+'&t=7&'+'l='+leccion+'&';
											}
											else
											{
												if ((teclado)==11)
												{
													//ITA
													variables_a_encriptar='e='+elmail+'&t=13&'+'l='+leccion+'&';
												}	
												else
												{
													if ((teclado)==12)
													{
														//JAP
														variables_a_encriptar='e='+elmail+'&t=16&'+'l='+leccion+'&';
													}
													else
													{
														if ((teclado)==13)
														{
															//LAT
															variables_a_encriptar='e='+elmail+'&t=20&'+'l='+leccion+'&';
														}
														else
														{
															if ((teclado)==14)
															{
																//DUT
																variables_a_encriptar='e='+elmail+'&t=6&'+'l='+leccion+'&';
															}
															else
															{
																if ((teclado)==15)
																{
																	//NOR
																	variables_a_encriptar='e='+elmail+'&t=5&'+'l='+leccion+'&';
																}
																else
																{
																	if ((teclado)==16)
																	{
																		//POR
																		variables_a_encriptar='e='+elmail+'&t=14&'+'l='+leccion+'&';
																	}
																	else
																	{
																		if ((teclado)==17)
																		{
																			//ESP
																			variables_a_encriptar='e='+elmail+'&t=19&'+'l='+leccion+'&';
																		}
																		else
																		{
																			if ((teclado)==18)
																			{
																				//SWIG
																				variables_a_encriptar='e='+elmail+'&t=9&'+'l='+leccion+'&';
																			}
																			else
																			{
																				if ((teclado)==19)
																				{
																					//SWIF
																					variables_a_encriptar='e='+elmail+'&t=10&'+'l='+leccion+'&';
																				}
																				else
																				{
																					// US
																					variables_a_encriptar='e='+elmail+'&t=1&'+'l='+leccion+'&';
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

	}

	variables_encriptades=encripta(variables_a_encriptar);
	window.location="cambiar_teclado.php?v="+variables_encriptades;	

}


var locate = window.location;
var text;
var nom_usuario;
var emailusuario;
var teclado;

document.joe.burns.value = locate;
text=document.joe.burns.value;

variables_encriptades=nomes_variables(text);
variables_no_encriptades=desencripta(variables_encriptades);

nom_usuario=troba_nom(variables_no_encriptades);
emailusuario=troba_email(variables_no_encriptades);
max_lec=troba_maxlec(variables_no_encriptades);

if ((text.indexOf('leccionUS'))!=(-1)) teclado="1";
if ((text.indexOf('leccionUK'))!=(-1)) teclado="2";
if ((text.indexOf('leccionBEL'))!=(-1)) teclado="18";
if ((text.indexOf('leccionBRA'))!=(-1)) teclado="15";
if ((text.indexOf('leccionCANI'))!=(-1)) teclado="11";
if ((text.indexOf('leccionCANF'))!=(-1)) teclado="12";
if ((text.indexOf('leccionDAN'))!=(-1)) teclado="4";
if ((text.indexOf('leccionFIN'))!=(-1)) teclado="3";
if ((text.indexOf('leccionFRA'))!=(-1)) teclado="17";
if ((text.indexOf('leccionGER'))!=(-1)) teclado="8";
if ((text.indexOf('leccionICE'))!=(-1)) teclado="7";
if ((text.indexOf('leccionITA'))!=(-1)) teclado="13";
if ((text.indexOf('leccionJAP'))!=(-1)) teclado="16";
if ((text.indexOf('leccionDUT'))!=(-1)) teclado="6";
if ((text.indexOf('leccionNOR'))!=(-1)) teclado="5";
if ((text.indexOf('leccionPOR'))!=(-1)) teclado="14";
if ((text.indexOf('leccionSWIG'))!=(-1)) teclado="9";
if ((text.indexOf('leccionSWIF'))!=(-1)) teclado="10";
if ((text.indexOf('leccionES'))!=(-1)) teclado="19";
if ((text.indexOf('leccionLAT'))!=(-1)) teclado="20";

-->
