var INDEX_PERSON_TYPE=2;function loginOnLoad(){const urlParams=new URLSearchParams(window.location.search);var req="";if(urlParams.has('req')){req=urlParams.get('req')}
var wc="LOGIN";if(urlParams.has('wc')){wc=urlParams.get('wc')}
ST_SRH_MAIN_WHO_CALL=wc;sessionStorage.setItem(ST_SRH_MAIN_SESSION_CNAME,"");if(req!=""){showParts("divIndLogPlanInfo")}
includeHtmlInHtml();var btGetIn=document.getElementById("btIndLoginGetIn");btGetIn.onclick=function(){indexLogin(ST_SRH_MAIN_WHO_CALL)};var btCreateAccount=document.getElementById("btIndLoginCreateAccount");btCreateAccount.onclick=function(){var urlPlans="https://silicaweb.ao/sfront/CompanySelfRegister.php";window.open(urlPlans)};var ssettRoot="ssetting";if(getDesktopStatus()){ssettRoot+="_desk"}
document.getElementById("btIndLoginForfotPasswprd").href="../../"+ssettRoot+"/forgotmypassword";setTriggerButtonByText('txtIndUserName',btGetIn.id);setTriggerButtonByText('txtIndPassword',btGetIn.id);scrollToElement("txtIndUserName");document.getElementById("txtIndUserName").focus()}
function indexLogin(whoCall="LOGIN"){var lbMsg=document.getElementById('lbIndMsgError');lbMsg.innerHTML="";if(!desktopSecurityCheck(1)){return!1}
var FILTER=setFilterStatus();FILTER.st="SRH";FILTER.wc=whoCall;FILTER.username=getElementValue('txtIndUserName').toString().trim();FILTER.pass=getElementValue('txtIndPassword').toString().trim();if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor",0);return!1}
ST_SRH_WAITING_SERVER=1;showNotification();var http=new XMLHttpRequest();var params="action=getSystemLogin"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_INDEX_LOGIN_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(this.readyState==4&&this.status==200){try{ST_SRH_WAITING_SERVER=0;hideNotification();var response=JSON.parse(http.responseText)}catch(e){showHttpResponseText(http)}
if(response.status==1){loginSessionNotification(response);if(getDesktopStatus()){loginAddUsernameAutocomplete(FILTER.username)}
sessionStorage.setItem(ST_SRH_MAIN_SESSION_CNAME,response.sessionid);sessionStorage.setItem("sms_lockwindows",0);var lastPageVisited=getCookie(ST_SRH_MAIN_LAST_PAGE_CNAME);if(lastPageVisited!=""){window.location.assign("app/"+lastPageVisited+"?&frc=1")}else{window.location.assign("app/home/home?rp="+response.defaultPass+"?&frc=1")}}else{lbMsg.innerHTML="Utilizador ou palavra passe errada."}}};http.onerror=function(){console.log('Request encountered an error');hideNotification();ST_SRH_WAITING_SERVER=0};http.ontimeout=function(){console.log('Request connection timeout');hideNotification();ST_SRH_WAITING_SERVER=0};http.send(params)}
function loginSessionNotification(response){if(!desktopSecurityCheck(1)){return!1}
var FILTER=setFilterStatus();Object.keys(response).forEach(key=>{FILTER[key]=response[key]});var http=new XMLHttpRequest();var params="action=sendMailSessionNotification"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_INDEX_LOGIN_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.send(params)}
function indexGoBack(a){hideParts('divIndLogin');showParts('divIndPersonType')}
function indexRegisterMyCompany(a){window.location.href='PreCadastroCadastro.php?personType='+INDEX_PERSON_TYPE+'&userId=-1&request=20&registerId=0&companyId=5000&businessGroupId=-1&businessId=-1'}
function indexRequestNewPass(a){var mandatoryField=!1;var msg="";if(!desktopSecurityCheck(1)){return!1}
var FILTER=setFilterStatus();FILTER.username=reviewString(document.getElementById('txtIndUserName'));FILTER.email=reviewEmail(document.getElementById('txtIndEmail').value);if(FILTER.username==""){mandatoryField=!0;msg="Deve indicar o utilizador. <br>"}
if(!validateEmail(FILTER.email)){mandatoryField=!0;msg+="Deve indicar um e-mail válido"}
if(mandatoryField){alert(msg);return!1}
var http=new XMLHttpRequest();var params="action=validateUsernameEmail"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_INDEX_LOGIN_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(this.readyState==4&&this.status==200){var response=JSON.parse(http.responseText);if(response.status==1){alert(response.msg);setTimeout(function(){window.location.assign("./")},5000)}else{alert(response.msg)}}};http.send(params)}
function loginResetPasswordOnLoad(){document.title="Definir nova palavra passe";includeHtmlInHtml();if(!desktopSecurityCheck(1)){return!1}
var FILTER=setFilterStatus();const urlParams=new URLSearchParams(window.location.search);FILTER.rid="";if(urlParams.has('rid')){FILTER.rid=urlParams.get('rid')}
FILTER.wc="";if(urlParams.has('wc')){FILTER.wc=urlParams.get('wc')}
var http=new XMLHttpRequest();var params="action=validatePasswordRequest"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_INDEX_LOGIN_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(this.readyState==4&&this.status==200){try{var response=JSON.parse(http.responseText)}catch(e){showHttpResponseText(http)}
if(response.status==1){setElementValue("txtUserResPasUserId",response.id);setElementValue("txtUserResPasUserFullName",response.userfullname)}else{alert(response.msg);setTimeout(function(){window.location.href="./"},6000)}}};http.send(params);document.getElementById("txtUserResPasNewPass").focus();scrollToElement("txtUserResPasNewPass")}
function loginSaveNewPassword(){if(!desktopSecurityCheck(1)){return!1}
var FILTER=setFilterStatus();const urlParams=new URLSearchParams(window.location.search);FILTER.rid="";if(urlParams.has('rid')){FILTER.rid=urlParams.get('rid')}
FILTER.userId=document.getElementById('txtUserResPasUserId').value;FILTER.newPass=document.getElementById('txtUserResPasNewPass').value;FILTER.newPassRepit=document.getElementById('txtUserResPasNewPassRepit').value;var mandatoryField=!1;var msg="";if(FILTER.userId.length<=0){mandatoryField=!0;msg+="Deve não foi encontrado um utilizador válido. <br>"}
if(FILTER.newPass.length<6){mandatoryField=!0;msg+="A nova palavra-passe deve ter no mínimo 6 caracteres. <br>"}
if(FILTER.newPassRepit==""){mandatoryField=!0;msg+="Deve repetir a nova palavra-passe. <br>"}
if(FILTER.newPass!=FILTER.newPassRepit){mandatoryField=!0;msg+="Nova palavra-passe não combina. <br>"}
if(ST_SRH_WAITING_SERVER==1){mandatoryField=!0;msg+="Aguardando resposta do servidor. <br>"}
if(mandatoryField){alert(msg);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=saveLoginNewPassword"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_INDEX_LOGIN_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;try{var response=JSON.parse(http.responseText)}catch(e){showHttpResponseText(http)}
if(response.status==1){alert(response.msg,1);setTimeout(function(){window.location.href="./"},5000)}else{showNotification(response.msg,0)}}};http.send(params)}