function fillSelectSystemType(selectId,startFrom=1){const selSystemType=document.getElementById(selectId);if(!validateUserControl(selSystemType)){return!1}
selSystemType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selSystemType.appendChild(optionStart)}
setSystemType('');for(var i=1;i<=SYSTEM_TYPES.length;i++){var optTypes=document.createElement("option");optTypes.value=i;optTypes.innerHTML=SYSTEM_TYPES[i];selSystemType.appendChild(optTypes)}
selSystemType.dispatchEvent(new Event('input'))}
function fillSelectPaymentMechanism(selectId,startFrom=1){const selPaymentMechanism=document.getElementById(selectId);if(!validateUserControl(selPaymentMechanism)){return!1}
selPaymentMechanism.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selPaymentMechanism.appendChild(optionStart)}
setPaymentMechanism('');PAYMENT_MECHANISM.forEach(element=>createSel(element));function createSel(element){var optionPayMechanism=document.createElement("option");if(Number(element.id)<100){optionPayMechanism.value=element.id;optionPayMechanism.innerHTML=element.mechanism;selPaymentMechanism.appendChild(optionPayMechanism)}}
selPaymentMechanism.dispatchEvent(new Event('input'))}
function fillSelectAccountBank(selectId,startFrom=-1){const selAccountBK=document.getElementById(selectId);if(!validateUserControl(selAccountBK)){return!1}
selAccountBK.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selAccountBK.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.accountId=-1;var http=new XMLHttpRequest();var params="action=getBankAccountList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SW_BANK_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 accountBanks=JSON.parse(this.responseText);accountBanks.forEach(element=>createTbl(element));var n=0;function createTbl(element){n+=1;let accountBk=JSON.parse(element);var optAccountBk=document.createElement("option");optAccountBk.value=accountBk.accountid;optAccountBk.innerHTML=accountBk.initials+" - "+accountBk.accountnumber;selAccountBK.appendChild(optAccountBk)}
selAccountBK.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectNationalBank(selectId,startFrom=1,initialValue=-1){const selBank=document.getElementById(selectId);if(!validateUserControl(selBank)){return!1}
selBank.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selBank.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var http=new XMLHttpRequest();var params="action=getNationalBank"+"&filterInfo="+JSON.stringify(setFilterStatus());var url=URL_SRH_CRUD_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 banks=JSON.parse(this.responseText);banks.forEach(element=>createTbl(element));function createTbl(element){let bank=JSON.parse(element);var optBank=document.createElement("option");optBank.value=bank.id;optBank.innerHTML=bank.initials+" - "+bank.bankname;selBank.appendChild(optBank)}
if(initialValue!=-1){selBank.value=initialValue}
selBank.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectCountry(selectId,startFrom=1){const selCountry=document.getElementById(selectId);if(!validateUserControl(selCountry)){return!1}
selCountry.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selCountry.appendChild(optionStart)}
try{var countries=JSON.parse(sessionStorage.getItem("fill-country-list"));realCountries(countries)}catch(e){if(!desktopSecurityCheck()){return!1}
var http=new XMLHttpRequest();var params="action=getCountry"+"&filterInfo="+JSON.stringify(setFilterStatus());var url=URL_SRH_CRUD_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 countries=JSON.parse(this.responseText);sessionStorage.setItem("fill-country-list",http.responseText);realCountries(countries)}catch(e){showHttpResponseText(http)}}};http.send(params)}
function realCountries(countries){countries.forEach(element=>createTbl(element));function createTbl(element){let country=JSON.parse(element);var optionCountry=document.createElement("option");optionCountry.value=country['id'];optionCountry.innerHTML=country['country'];selCountry.appendChild(optionCountry)}
selCountry.dispatchEvent(new Event('input'))}}
function fillSelectProvince(selectId,startFrom=1,initialValue=-1,withWP=0){const selProvince=document.getElementById(selectId);selProvince.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selProvince.appendChild(optionStart)}
try{var provinces=JSON.parse(sessionStorage.getItem("fill-province-list"));realFillProvince(provinces)}catch(e){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();var http=new XMLHttpRequest();var params="action=getProvince"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_CRUD_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 provinces=validateSession(http);sessionStorage.setItem("fill-province-list",http.responseText);realFillProvince(provinces)}catch(e){showHttpResponseText(http)}}};http.send(params)}
function realFillProvince(provinces){provinces.forEach(element=>createTbl(element));function createTbl(element){let province=JSON.parse(element);var optProvince=document.createElement("option");optProvince.value=province.id;var strProv=province.province;if(withWP==1){strProv+=" ("+province.NumberOfWP+")"}
optProvince.innerHTML=strProv;selProvince.appendChild(optProvince)}
if(initialValue!=-1){selProvince.value=initialValue}
selProvince.dispatchEvent(new Event('input'))}}
function fillSelectMunicipality(selectId,provinceId,startFrom=1,initValue=-1,withWP=0){const selMunicipality=document.getElementById(selectId);if(!validateUserControl(selMunicipality)){return!1}
selMunicipality.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selMunicipality.appendChild(optionStart)}
if((isNaN(provinceId))||(Number(provinceId)<=0)){return!1}
try{var municipalities=JSON.parse(sessionStorage.getItem("fill-municipality-list"));realFillMunicipality(municipalities)}catch(e){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.provinceId=-1;var http=new XMLHttpRequest();var params="action=getMunicipality"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_CRUD_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{sessionStorage.setItem("fill-municipality-list",http.responseText);var municipalities=JSON.parse(this.responseText);realFillMunicipality(municipalities)}catch(e){alert(e.message);showHttpResponseText(http)}}};http.send(params)}
function realFillMunicipality(municipalities){municipalities.forEach(element=>createTbl(element));function createTbl(element){let municipality=JSON.parse(element);if(municipality.provinceid==provinceId){var optMunicipality=document.createElement("option");optMunicipality.value=municipality.id;var strMun=municipality.municipality;if(withWP==1){strMun+=" ("+municipality.NumberOfWP+")"}
optMunicipality.innerHTML=strMun;selMunicipality.appendChild(optMunicipality)}}
if(initValue!=-1){selMunicipality.value=initValue}
selMunicipality.dispatchEvent(new Event('input'))}}
function fillSelectCustomerType(selectId,startFrom=1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
for(var i=1;i<CUSTOMER_TYPE.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=CUSTOMER_TYPE[i];selType.appendChild(optType)}
selType.dispatchEvent(new Event('input'))}
function fillSelectSystemUserBillingUser(selectId,userProfile,startFrom=1,initialValue=-1){const selProfile=document.getElementById(selectId);if(selProfile!==null){selProfile.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selProfile.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.userProfile=userProfile;FILTER.userId=-1;var http=new XMLHttpRequest();var params="action=getSystemUserBillingProfile"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_SYSTEM_USER_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){var users=validateSession(http);users.forEach(element=>createTbl(element));function createTbl(element){let user=JSON.parse(element);var optUser=document.createElement("option");optUser.value=user.userid;optUser.innerHTML=user.userfullname;selProfile.appendChild(optUser)}
if(initialValue!=-1){selProfile.value=initialValue}
selProfile.dispatchEvent(new Event('input'))}};http.send(params)}}
function fillSelectPatrimonyType(selectId,startFrom=1){const selType=document.getElementById(selectId);selType.innerHTML="";if(startFrom==-1){var optStart=document.createElement("option");optStart.value="-1";optStart.setAttribute('class','selectPlaceHolder');optStart.innerHTML="Seleccionar tipo de activo";selType.appendChild(optStart)}
var TYPES=["Imóvel","Móvel"];TYPES.forEach(element=>{var optType=document.createElement("option");optType.value=element.toString().toUpperCase();optType.innerHTML=element;selType.appendChild(optType)});selType.dispatchEvent(new Event('input'))}
function fillSelectPatrimonySubType(selectId,startFrom=1){const selSubType=document.getElementById(selectId);selSubType.innerHTML="";if(startFrom==-1){var optStart=document.createElement("option");optStart.value="-1";optStart.setAttribute('class','selectPlaceHolder');optStart.innerHTML="Seleccionar subtipo de activo";selSubType.appendChild(optStart)}
var SUBTYPES=['Outro',"Terreno","Vivenda",'Apartamento','Prédio','Automóvel ligeiro','Automóvel pesado','Motocíclo','Mobiliário','Equipamento'];SUBTYPES.forEach(element=>{var optSType=document.createElement("option");optSType.value=element.toString().toUpperCase();optSType.innerHTML=element;selSubType.appendChild(optSType)});selSubType.dispatchEvent(new Event('input'))}
function fillSelectPatrimonyTaxSubject(selectId,startFrom=1){const selTax=document.getElementById(selectId);selTax.innerHTML="";if(startFrom==-1){var optStart=document.createElement("option");optStart.value="";optStart.setAttribute('class','selectPlaceHolder');optStart.innerHTML="Seleccionar tipo de imposto";selTax.appendChild(optStart)}
var SUBTYPES=[['IP','Imposto Predial'],['IVM','Imposto sobre Veículos Motorizados']];SUBTYPES.forEach(element=>{var optTax=document.createElement("option");optTax.value=element[0];optTax.innerHTML=element[1];selTax.appendChild(optTax)});selTax.dispatchEvent(new Event('input'))}
function fillSelectPatrimonyAquisitionStatus(selectId,startFrom=1){const selStatus=document.getElementById(selectId);selStatus.innerHTML="";if(startFrom==-1){var optStart=document.createElement("option");optStart.value="-1";optStart.setAttribute('class','selectPlaceHolder');optStart.innerHTML="Seleccionar estado do activo";selStatus.appendChild(optStart)}
var STATUS=['Novo',"Usado funcional","Usado com defeito",'Não funcional'];STATUS.forEach(element=>{var optStatus=document.createElement("option");optStatus.value=element.toString().toUpperCase();optStatus.innerHTML=element;selStatus.appendChild(optStatus)});selStatus.dispatchEvent(new Event('input'))}
function fillSelectDependencyFull(selectId,startFrom=1,onlyMyDepependency=0){const selDependency=document.getElementById(selectId);selDependency.innerHTML="";if(startFrom==-1){var optStart=document.createElement("option");optStart.value="-1";optStart.setAttribute('class','selectPlaceHolder');optStart.innerHTML="Seleccionar";selDependency.appendChild(optStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;if(onlyMyDepependency==1){if(Number(SYSTEM_USER_STATUS.billingprofile)<Number(BILLING_PROFILE_DEPARTMENT_BOSS_INDEX)){FILTER.dependencyId=Number(SYSTEM_USER_STATUS.workplaceId)}}
var http=new XMLHttpRequest();var params="action=getCompanyDependencyList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_COMPANY_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){var dependences=validateSession(http);dependences.forEach(element=>createTbl(element));function createTbl(element){let dependence=JSON.parse(element);var optDep=document.createElement("option");optDep.value=dependence.id;optDep.innerHTML=dependence.province+" - "+dependence.municipality+" - "+dependence.designation;selDependency.appendChild(optDep)}
if(onlyMyDepependency!=0){if(FILTER.dependencyId>0){selDependency.value=FILTER.dependencyId;selDependency.dispatchEvent(new Event('change'))}}
selDependency.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectProductInstallmentIndicator(selectId,startFrom=1){const selInd=document.getElementById(selectId);if(!validateUserControl(selInd)){return!1}
selInd.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selInd.appendChild(optionStart)}
for(var i=1;i<PRODUCT_INSTALLMENT_INDICATORS.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=PRODUCT_INSTALLMENT_INDICATORS[i];selInd.appendChild(optType)}
selInd.dispatchEvent(new Event('input'))}
function fillSelectDays(selectId,startFrom=1){const selDays=document.getElementById(selectId);if(!validateUserControl(selDays)){return!1}
selDays.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selDays.appendChild(optionStart)}
for(var i=1;i<=31;i++){let optDay=document.createElement("option");optDay.value=i;optDay.innerHTML=i;selDays.appendChild(optDay)}
selDays.dispatchEvent(new Event('input'))}
function fillSelectMonth(selectId,startFrom=1,initialValue=-1){const selMonth=document.getElementById(selectId);if(!validateUserControl(selMonth)){return!1}
selMonth.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selMonth.appendChild(optionStart)}
for(var i=0;i<=11;i++){let optMonth=document.createElement("option");optMonth.value=i+1;optMonth.innerHTML=monthName(i);selMonth.appendChild(optMonth)}
if(initialValue!=-1){selMonth.value=initialValue}
selMonth.dispatchEvent(new Event('input'))}
function fillSelectIdentificationDoc(selectId,startFrom=1,initialValue=""){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var DOC_LIST=identificationDocumentList();for(var i=0;i<DOC_LIST.length;i++){let optType=document.createElement("option");optType.value=DOC_LIST[i];optType.innerHTML=DOC_LIST[i];selType.appendChild(optType)}
if(DOC_LIST.includes(initialValue)){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectAcademicDegree(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var DOC_LIST=academicDegreeList();for(var i=0;i<DOC_LIST.length;i++){let optType=document.createElement("option");optType.value=DOC_LIST[i].level;optType.innerHTML=DOC_LIST[i].description;selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectPrintOptionSignature(selectId,startFrom=1){const selSign=document.getElementById(selectId);if(!validateUserControl(selSign)){return!1}
selSign.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar um assinante";selSign.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();var http=new XMLHttpRequest();var params="action=getPrintOptionSignature"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_CRUD_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 signatures=JSON.parse(this.responseText);signatures.forEach(element=>createTbl(element));function createTbl(element){let signature=JSON.parse(element);var optValue=document.createElement("option");optValue.value=signature.person+"-/-"+signature.quality;optValue.innerHTML=signature.person+" ["+signature.quality+"]";selSign.appendChild(optValue)}
selSign.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectSex(selectId,startFrom=1,initialValue=""){const selSex=document.getElementById(selectId);if(!validateUserControl(selSex)){return!1}
selSex.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selSex.appendChild(optionStart)}
let optM=document.createElement("option");optM.value="M";optM.innerHTML="Masculino";selSex.appendChild(optM);let optF=document.createElement("option");optF.value="F";optF.innerHTML="Feminino";selSex.appendChild(optF);if(initialValue!=""){initialValue=initialValue.slice(0,1).toUpperCase();if((initialValue=="F")||(initialValue=="M")){selSex.value=initialValue}}
selSex.dispatchEvent(new Event('input'))}
function fillSelectCivilStatus(selectId,startFrom=1,initialValue=""){const selStatus=document.getElementById(selectId);if(!validateUserControl(selStatus)){return!1}
selStatus.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selStatus.appendChild(optionStart)}
let optS=document.createElement("option");optS.value="S";optS.innerHTML="Solteiro(a)";selStatus.appendChild(optS);let optU=document.createElement("option");optU.value="U";optU.innerHTML="União de facto";selStatus.appendChild(optU);let optC=document.createElement("option");optC.value="C";optC.innerHTML="Casado(a)";selStatus.appendChild(optC);let optD=document.createElement("option");optD.value="D";optD.innerHTML="Divorciado(a)";selStatus.appendChild(optD);let optF=document.createElement("option");optF.value="V";optF.innerHTML="Viúvo(a)";selStatus.appendChild(optF);if(initialValue!=""){initialValue=initialValue.slice(0,1).toUpperCase();selStatus.value=initialValue}
selStatus.dispatchEvent(new Event('input'))}
function fillSelectDepartment(selectId,startFrom=1,initialValue=-1){const selDepart=document.getElementById(selectId);if(!validateUserControl(selDepart)){return!1}
selDepart.innerHTML="";addEventInput2Select(selDepart);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selDepart.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.departmentid=-1;var http=new XMLHttpRequest();var params="action=getCompanyDepartmentList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_DEPARTMENT_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){var departments=validateSession(http);for(var i=0;i<departments.length;i++){let department=JSON.parse(departments[i]);let optDepart=document.createElement("option");optDepart.value=department.departmentid;optDepart.innerHTML=department.department+" ("+department.initials+")";selDepart.appendChild(optDepart)}
if(initialValue!=-1){selDepart.value=initialValue}
selDepart.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectEmployeeCategory(selectId,startFrom=1,initialValue=-1){const selCat=document.getElementById(selectId);if(!validateUserControl(selCat)){return!1}
selCat.innerHTML="";addEventInput2Select(selCat);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selCat.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.categoryId=-1;FILTER.startIdx=0;FILTER.pageItems=1000;var http=new XMLHttpRequest();var params="action=getEmployeeCategoryList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_EMPLOYEE_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){var categories=validateSession(http);for(var i=0;i<categories.length;i++){let category=JSON.parse(categories[i]);let optCat=document.createElement("option");optCat.value=category.categoryid;optCat.innerHTML=category.category;selCat.appendChild(optCat);if(initialValue!=-1){selCat.value=initialValue}
selCat.dispatchEvent(new Event('input'))}}};http.send(params)}
function fillSelectWorkschedule(selectId,startFrom=1,initialValue=-1){const selWorksch=document.getElementById(selectId);if(!validateUserControl(selWorksch)){return!1}
selWorksch.innerHTML="";addEventInput2Select(selWorksch);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selWorksch.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.workscheduleId=-1;FILTER.startIdx=0;FILTER.pageItems=2000;var http=new XMLHttpRequest();var params="action=getWorkscheduleList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_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){var response=validateSession(http);for(var i=0;i<response.length;i++){let works=JSON.parse(response[i]);let optWorksch=document.createElement("option");optWorksch.value=works.workscheduleid;optWorksch.innerHTML=works.workschedule;selWorksch.appendChild(optWorksch)}
if(initialValue!=-1){selWorksch.value=initialValue}
selWorksch.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectBiometricDevice(selectId,startFrom=1,initialValue=-1){const selToFill=document.getElementById(selectId);if(!validateUserControl(selToFill)){return!1}
selToFill.innerHTML="";addEventInput2Select(selToFill);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selToFill.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.biometricId=-1;var http=new XMLHttpRequest();var params="action=getBiometricDeviceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_POINT_CONTROL_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){var response=validateSession(http);for(var i=0;i<response.length;i++){let works=JSON.parse(response[i]);let optToFill=document.createElement("option");optToFill.value=works.biometricid;optToFill.innerHTML=works.brand;if(works.localip!=''){optToFill.innerHTML+=" ("+works.localip+")"}
selToFill.appendChild(optToFill)}
if(initialValue!=-1){selToFill.value=initialValue}
selToFill.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectAllowanceType(selectId,startFrom=1,initialValue=""){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var LIST=payrollSetAllowanceType();var allTypes=['A','D'];Array.from(allTypes).forEach(type=>{let optType=document.createElement("option");optType.value=type;optType.innerHTML=LIST[type];selType.appendChild(optType)});if(allTypes.includes(initialValue)){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectAllowanceProcessWay(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var LIST=payrollSetAllowanceProcessWay();for(var i=1;i<LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=LIST[i];selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectAllowanceIRTStatus(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var LIST=payrollSetAllowanceIRTStatus();for(var i=0;i<LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=LIST[i];selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectIRTGroup(selectId,startFrom=1,initialValue=""){const selStatus=document.getElementById(selectId);if(!validateUserControl(selStatus)){return!1}
selStatus.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selStatus.appendChild(optionStart)}
let optA=document.createElement("option");optA.value="A";optA.innerHTML="Grupo A - Trabalhador por conta de outrem (Tabela geral do IRT)";selStatus.appendChild(optA);let optB=document.createElement("option");optB.value="B";optB.innerHTML="Grupo B - Trabalhor por conta própria (10,5% de toda remuneração";selStatus.appendChild(optB);let optC=document.createElement("option");optC.value="C";optC.innerHTML="Grupo C - Em sede do Imposto Industrial (6,5 % de toda remuneração)";selStatus.appendChild(optC);if(initialValue!=""){initialValue=initialValue.slice(0,1).toUpperCase();selStatus.value=initialValue}
selStatus.dispatchEvent(new Event('input'))}
function fillSelectPayroll(selectId,startFrom=1,initialValue=-1){const selDepart=document.getElementById(selectId);if(!validateUserControl(selDepart)){return!1}
selDepart.innerHTML="";addEventInput2Select(selDepart);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selDepart.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollId=-1;FILTER.year=-1;var http=new XMLHttpRequest();var params="action=getPayrollList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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){var response=validateSession(http);for(var i=0;i<response.length;i++){let option=JSON.parse(response[i]);let optDepart=document.createElement("option");optDepart.value=option.payrollid;optDepart.innerHTML=option.referenceyear+"/"+monthName(Number(option.referencemonth)-1)+" ("+payrollSetPayrollStatus(option.payrollstatus)+")";selDepart.appendChild(optDepart)}
if(initialValue!=-1){selDepart.value=initialValue}
selDepart.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectAdvanceStatus(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var LIST=payrollSetAdvanceStatus();for(var i=1;i<LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=LIST[i];selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectPayrollExtractType(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var LIST=[];LIST[1]="Banco";LIST[2]="Segurança Social";LIST[3]="IRT";for(var i=1;i<LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=LIST[i];selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectSalaryBaseSource(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var DOC_LIST=[];DOC_LIST[1]="A apartir da escala salarial";DOC_LIST[2]="Horas / Mês";DOC_LIST[3]="Indicado";DOC_LIST[4]="Horas trabalhadas";DOC_LIST[5]="Tempos (de 45 min) / Mês";for(var i=1;i<DOC_LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=DOC_LIST[i];selType.appendChild(optType)}
if(DOC_LIST.includes(initialValue)){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectFontSize(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
for(var i=3;i<=50;i++){let optType=document.createElement("option");let op=i+"pt";optType.value=op;optType.innerHTML=op;selType.appendChild(optType)}
if(initialValue!=-1){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectAllowance(selectId,startFrom=1,initialValue=-1){const selDepart=document.getElementById(selectId);if(!validateUserControl(selDepart)){return!1}
selDepart.innerHTML="";addEventInput2Select(selDepart);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selDepart.appendChild(optionStart)}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.allowanceId=-1;FILTER.processway=2;var http=new XMLHttpRequest();var params="action=getPayrollAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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){var response=validateSession(http);for(var i=0;i<response.length;i++){let option=JSON.parse(response[i]);let optDepart=document.createElement("option");optDepart.value=option.allowanceid;optDepart.innerHTML=option.allowance;selDepart.appendChild(optDepart)}
if(initialValue!=-1){selDepart.value=initialValue}
selDepart.dispatchEvent(new Event('input'))}};http.send(params)}
function fillSelectWorkscheduleAplicationType(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var DOC_LIST=setWorkscheduleAplicationType();for(var i=0;i<DOC_LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=DOC_LIST[i];selType.appendChild(optType)}
if(DOC_LIST.includes(initialValue)){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}
function fillSelectEmployeeStatus(selectId,startFrom=1,initialValue=-1){const selType=document.getElementById(selectId);if(!validateUserControl(selType)){return!1}
selType.innerHTML="";addEventInput2Select(selType);if(startFrom==-1){var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selType.appendChild(optionStart)}
var DOC_LIST=setEmployeeStatus();for(var i=0;i<DOC_LIST.length;i++){let optType=document.createElement("option");optType.value=i;optType.innerHTML=DOC_LIST[i];selType.appendChild(optType)}
if(DOC_LIST.includes(initialValue)){selType.value=initialValue}
selType.dispatchEvent(new Event('input'))}