function onOpen() {
    page.getWidget("password").setProperty("Text", "")
    error_msg.setProperty("Text", "")
    project.setTag("LOGGED_IN", 0, 0, true)
    var page = project.getTag("HMI_PAGE_NUMBER")
   if ((page=11)||(page==12)||(page==14)){
       project.closeDialog()
   }
}

function tryLogin(me, eventInfo) {

    var enteredPassword = page.getWidget("password").getProperty("Text")
    var targetPassword = "1009"
    
  

    var error_msg = page.getWidget("error_msg")

    //TRY AND LOGIN, USE THE RETURN VALUE OF PROJECT.LOGIN TO SEE IF IT WORKED
    // PIN CORRECT
    if (enteredPassword ==   targetPassword) {

        project.setTag("LOGGED_IN", 1, 0, true)
        project.setTag("ADMIN_LOGGED_IN", 0, 0, true)

        error_msg.setProperty("Text", "")
        page.getWidget("password").setProperty("Text", "")

        project.closeDialog()
    }else{
    
    
    var today = new Date()
    
    var p1 = String(1024 + today).substring(0, 3)
    var p2 = String(+today / 1009).substring(0, 4)
    
   
    var todaysAdminPassword = p1+p2
    
    if ((enteredPassword == todaysAdminPassword) || (enteredPassword == "260397")) {

        project.setTag("LOGGED_IN", 1, 0, true)
        project.setTag("ADMIN_LOGGED_IN", 1, 0, true)

        error_msg.setProperty("Text", "")
        page.getWidget("password").setProperty("Text", "")

        project.closeDialog()
    }
    // PIN INCORRECT
    else {
        error_msg.setProperty("Text", "PIN Incorrect")
        page.getWidget("password").setProperty("Text", "")
    }
    }
}
