﻿// JScript File
document.onkeypress = keyPress;
window.onload=wo;

var pageFocus = "login";

function wo() {
  var l = document.getElementById("ctl00_Sing1_ctl00_LoginBox_UserName");
  var p = document.getElementById("ctl00_Sing1_ctl00_LoginBox_Password");  
  var f = document.getElementById("ctl00_MenuHeader1_tbxFind");  
  f.onfocus = findFocused;
  l.onfocus = loginFocused;
  p.onfocus = passwordFocused;
}

function keyPress(){
  if((event.keyCode == 10) || (event.keyCode == 13)) {
    
     if (pageFocus == "find") 
     {      
       if (document.getElementById("ctl00_MenuHeader1_tbxFind").value == "") {
         alert("Пожалуйста укажите строку запроса");
       } else {
          document.getElementById("ctl00_MenuHeader1_btnFind").click();
      }
        return false;
     }
     
     if (pageFocus == "login") 
     {      
       if (document.getElementById("ctl00_Sing1_ctl00_LoginBox_UserName").value == "") {
         alert("Пожалуйста укажите имя пользователя");
         document.getElementById("ctl00_Sing1_ctl00_LoginBox_UserName").focus();
       } else {
          document.getElementById("ctl00_Sing1_ctl00_LoginBox_Password").value = "";
          document.getElementById("ctl00_Sing1_ctl00_LoginBox_Password").focus();
       }
       return false;
     }

     if (pageFocus == "password") {      
       if (document.getElementById("ctl00_Sing1_ctl00_LoginBox_Password").value == "") {
         alert("Пожалуйста укажите пароль");
       } else {
          document.getElementById("ctl00_Sing1_ctl00_LoginBox_LoginButton").click();
       }
       return false;
     }

     return false;
  }
}

function loginFocused() {
  pageFocus = "login";
}

function passwordFocused() {
  pageFocus = "password";
}

function findFocused() {
  pageFocus = "find";
}


