WS_waitscreen = true;

window.onload = function(){
    
    // Call Entry
    getCountries()
    // Later
    document.getElementById('later-button').addEventListener("click", function(){
        document.getElementsByClassName('completeLater')[0].style.display = 'table'
    });
    
    document.getElementById('completeLaterAccept').addEventListener("click", function(){
        gotoPage('dashboard','home', { 'sessionid' : getParameterByName('sessionid') })
    });
    
    document.getElementById('completeLaterCancel').addEventListener("click", function(){
        document.getElementsByClassName('completeLater')[0].style.display = 'none'
    });
    
    // Go to Register Profesional Information 
    document.getElementById('previous-button').addEventListener("click", function(){
        gotoPage('register','regCompany',{ 'sessionid' : getParameterByName('sessionid') })
    });
    
    // Go to Register Transactional Data
    document.getElementById('next-button').addEventListener("click", function(){
        verify()
    });
    
    // Remove red errors 
    document.getElementsByTagName('body')[0].addEventListener("change", function(){
        for(i = 0; i < document.getElementsByClassName('partnerdiv').length; i++){
            var partnerdiv = document.getElementsByClassName('partnerdiv')[i];
            var partnerdiv2 = document.getElementsByClassName('partnerdiv2')[i];
            if (partnerdiv.children[0].children[0].children[2].value !=''){
                partnerdiv.children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdiv.children[0].children[0].children[3].innerHTML = ""
                partnerdiv.children[0].children[0].children[3].style.display = "none"
            }
            if (partnerdiv.children[1].children[0].children[2].value !=''){
                partnerdiv.children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdiv.children[1].children[0].children[3].innerHTML = ""
                partnerdiv.children[1].children[0].children[3].style.display = "none"
            }
            if (partnerdiv2.children[0].children[0].children[2].value !=''){
                partnerdiv2.children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdiv2.children[0].children[0].children[3].innerHTML = ""
                partnerdiv2.children[0].children[0].children[3].style.display = "none"
            }
            if (partnerdiv2.children[1].children[0].children[2].value !=''){
                partnerdiv2.children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdiv2.children[1].children[0].children[3].innerHTML = ""
                partnerdiv2.children[1].children[0].children[3].style.display = "none"
            }
            var partnerdivP = document.getElementById('0');
            var partnerdiv2P = document.getElementById('1');
            if(partnerdivP.children[0].children[0].children[2].value !=''){
                partnerdivP.children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdivP.children[0].children[0].children[3].innerHTML = ""
                partnerdivP.children[0].children[0].children[3].style.display = "none"
            }
            if(partnerdivP.children[1].children[0].children[2].value !=''){
                partnerdivP.children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdivP.children[1].children[0].children[3].innerHTML = ""
                partnerdivP.children[1].children[0].children[3].style.display = "none"
            }
            if(partnerdiv2P.children[0].children[0].children[2].value !=''){
                partnerdivP.children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdivP.children[0].children[0].children[3].innerHTML = ""
                partnerdivP.children[0].children[0].children[3].style.display = "none"
            }
            if(partnerdiv2P.children[1].children[0].children[2].value !=''){
                partnerdivP.children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                partnerdivP.children[1].children[0].children[3].innerHTML = ""
                partnerdivP.children[1].children[0].children[3].style.display = "none"
            
            
            if (partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[3].innerHTML = ''
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[3].style.display = "none"
                }
            }
            
            
            if (partnerdiv2.children[1].children[0].children[2].value ==1 && i !=0){
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[3].style.display = "none"
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[2].value != ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[2].style.border ="1px solid #D5DCE5";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[3].innerHTML = ""
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[3].style.display = "none"
                }

        }
        }
        
        
        
    }); 
    
    /*document.getElementsByTagName('body')[0].addEventListener("keyup", function(){
        for(i = 0; i < document.getElementsByName('id01').length; i++){
            var number = document.getElementsByName('id01')[i]
            numberFormat(number,number.value.charAt(number.value.length-1));
        }
    })*/
    
     // Session Update
    document.getElementById('expSessionButton').addEventListener("click",function(){
        var req = {
            'sessionid': getParameterByName('sessionid')
        }
        sessionUpdate(req)
    })
    
    document.getElementsByTagName('body')[0].addEventListener("change", function(){
        for(i = 0; i < document.getElementsByClassName('politician').length; i++){
            if (document.getElementsByClassName('politician')[i].value == 1){
                addPolitician(i)
            }
            else{
                deletePolitician(i)
            }
        }
    }); 
    
    //Mostrar HTML cargado
    esconderHTML(false);
}

function numberFormat(donde,caracter){
    pat = /[\*,\+,\(,\),\?,\\,\$,\[,\],\^]/
    valor = donde.value
    largo = valor.length
    crtr = true
    if(isNaN(caracter) || pat.test(caracter) == true)
    	{
    	if (pat.test(caracter)==true) 
    		{caracter = "\\" + caracter}
    	carcter = new RegExp(caracter,"g")
    	valor = valor.replace(carcter,"")
    	donde.value = valor
    	crtr = false
    	}
    else
    	{
    	var nums = new Array()
    	cont = 0
    	for(m=0;m<largo;m++)
    		{
    		if(valor.charAt(m) == "." || valor.charAt(m) == " ")
    			{continue;}
    		else{
    			nums[cont] = valor.charAt(m)
    			cont++
    			}
    		}
    	}
    var cad1="",cad2="",tres=0
    if(largo > 3 && crtr == true)
    	{
    	for (k=nums.length-1;k>=0;k--)
    		{
    		cad1 = nums[k]
    		cad2 = cad1 + cad2
    		tres++
    		if((tres%3) == 0)
    			{
    			if(k!=0){
    				cad2 = "." + cad2
    				}
    			}
    		}
    	 donde.value = cad2
    	}
}	


function listDraw(rsp){
    console.log(rsp)
    var tbl = document.getElementById("regForm");
    console.log(tbl)
    var node = tbl.firstElementChild.cloneNode(true);
    var node2 = tbl.children[1].cloneNode(true);
    var tmp = null; tmp = node.cloneNode(true);
    var tmp2 = null; tmp2 = node2.cloneNode(true)
    tbl.innerHTML = ""; // <div class="regForm" id="regForm"></div>
    if(!(rsp.length>0)){
        var ele = null;
        ele = tmp.cloneNode(true);
        ele.style.display = "none";
        tbl.appendChild(ele);
    }else{
        for(var i=1; i<rsp.length; i++){
            //console.log(i) // 0, 1, 2, 3
            var ele = null;
            var ele2 = null;
            ele = tmp.cloneNode(true);
            ele.style.display = "table";
            ele2 = tmp2.cloneNode(true);
            //Bg del reglon
            ele.classList.add("tableForm");
            ele2.classList.add("tableForm");
            
            if(rsp[i].dsc !== ""){
                ele.children[0].children[0].children[0].children[1].textContent="Nombre Socio "+(i)
                ele.children[0].children[1].children[0].children[1].textContent="Identificación Socio "+(i)
                //ele.children[0].children[2].children[0].children[0].textContent="Teléfono Socio "+(i+1)
                ele.children[1].children[0].children[0].children[1].textContent="Teléfono Socio "+(i)
                ele.children[1].children[1].children[0].children[1].textContent="Persona Políticamente Expuesta Socio "+(i)
                ele.children[0].id = (i+2) // Asigno el id 
                ele.children[1].id = (i+3) // Asigno el id 
            }
            setSpecialStatus(ele,rsp[i],rsp[i].politicalexp)
            console.log(ele)
            console.log('rsp[i].id ',rsp[i].id)
            ele.setAttribute('id',rsp[i].id)
            tbl.appendChild(ele);
            tbl.appendChild(ele2);
            
        }
    }
}

var entrydata;
function getEntry(sessionid){
    callWS("GET", "users/entry", { 'sessionid' : sessionid}, response);
        
    function response(status, rsp){
        switch(status){
            case 200:
                console.log(JSON.parse(rsp))
                entrydata = JSON.parse(rsp).entry
                levels = JSON.parse(rsp).entry.levels
                console.log('Este es el entry')
                console.log( JSON.parse(rsp).entry)
                var aNames  = new Array(JSON.parse(rsp).entry.company.partnersnumber.value);
                var aId = new Array(JSON.parse(rsp).entry.company.partnersnumber.value);
                var aPhone   = new Array(JSON.parse(rsp).entry.company.partnersnumber.value);
                var aPol   = new Array(JSON.parse(rsp).entry.company.partnersnumber.value);

                var aLegal = new Array(document.getElementsByClassName('partnerdiv2').length);
                var aaffiliationbody   = new Array(document.getElementsByClassName('partnerdiv2').length);
                var apositionheld   = new Array(document.getElementsByClassName('partnerdiv2').length);
                var apepcountryid = new Array(document.getElementsByClassName('partnerdiv2').length);
                var apeprelatedid = new Array(document.getElementsByClassName('partnerdiv').length);
                
                var id = new Array(document.getElementsByClassName('partnerdiv').length);
                
                var data = []
                var obj = {}
                    
                    
                if(JSON.parse(rsp).entry.company.partners!=null){
                            console.log(JSON.parse(rsp).entry.company.partners[0])
                            // Se inicializa un JSON de datos de los socios
                        if(JSON.parse(rsp).entry.company.partners[0]){
                            if(JSON.parse(rsp).entry.company.partners[0].politicalexposed.value == 1){
                                data.push({ 
                                    "name"    : JSON.parse(rsp).entry.company.partners[0].name.value,
                                    "id" : JSON.parse(rsp).entry.company.partners[0].id,
                                    "document"  : JSON.parse(rsp).entry.company.partners[0].document.value,
                                    "phone"    : JSON.parse(rsp).entry.company.partners[0].phone.value,
                                    "politicalexp"    : JSON.parse(rsp).entry.company.partners[0].politicalexposed.value,
                                    "legalrep": JSON.parse(rsp).entry.company.partners[0].legalrep.value,
                                    "affiliationbody": JSON.parse(rsp).entry.company.partners[0].affiliationbody.value,
                                    "positionheld": JSON.parse(rsp).entry.company.partners[0].positionheld.value,
                                    "pepcountryid": JSON.parse(rsp).entry.company.partners[0].pepcountryid.value,
                                    "peprelatedid": JSON.parse(rsp).entry.company.partners[0].peprelatedid.value
                                }); 
                                setStatus('nameIcon',JSON.parse(rsp).entry.company.partners[0].name,'nameRL')
                                setStatus('numberIcon',JSON.parse(rsp).entry.company.partners[0].document,'numberRL')
                                setStatus('phoneIcon',JSON.parse(rsp).entry.company.partners[0].phone,'phoneRL')
                                setStatus('politicianIcon',JSON.parse(rsp).entry.company.partners[0].politicalexposed,'politician')
                                
                                setStatus('polNameIcon',JSON.parse(rsp).entry.company.partners[0].affiliationbody,'polName')
                                setStatus('polPositionIcon',JSON.parse(rsp).entry.company.partners[0].positionheld,'polPosition')
                                setStatus('polCountryIcon',JSON.parse(rsp).entry.company.partners[0].pepcountryid,'polCountry')
                                setStatus('polDocumentIcon',JSON.parse(rsp).entry.company.partners[0].peprelatedid,'polDocument')
                            }else{
                                
                                data.push({ 
                                    "name"    : JSON.parse(rsp).entry.company.partners[0].name.value,
                                    "id" : JSON.parse(rsp).entry.company.partners[0].id,
                                    "document"  : JSON.parse(rsp).entry.company.partners[0].document.value,
                                    "phone"    : JSON.parse(rsp).entry.company.partners[0].phone.value,
                                    "politicalexp"    : JSON.parse(rsp).entry.company.partners[0].politicalexposed.value,
                                    "legalrep" : JSON.parse(rsp).entry.company.partners[0].legalrep.value
                                });   
                                setStatus('nameIcon',JSON.parse(rsp).entry.company.partners[0].name,'nameRL')
                                setStatus('numberIcon',JSON.parse(rsp).entry.company.partners[0].document,'numberRL')
                                setStatus('phoneIcon',JSON.parse(rsp).entry.company.partners[0].phone,'phoneRL')
                                setStatus('politicianIcon',JSON.parse(rsp).entry.company.partners[0].politicalexposed,'politician')
                            }
                        }else{
                            data.push({ 
                                "name"    : '',
                                "id": '0',
                                "document"  : '',
                                "phone"    : '',
                                "politicalexp" : '',
                                "legalrep": ''
                            }); 
                        }
                }
                    
                console.log(JSON.parse(rsp).entry.company.partners)
                console.log(JSON.parse(rsp).entry.company.partnersnumber.value)
                for (i=1;i<JSON.parse(rsp).entry.company.partnersnumber.value+1; i++){
                        if( JSON.parse(rsp).entry.company.partners!=null){
                            console.log(JSON.parse(rsp).entry.company.partners[i])
                            // Se inicializa un JSON de datos de los socios
                        if(JSON.parse(rsp).entry.company.partners[i]){
                            console.log('asdasdasdasdasdasdsad')
                            if(JSON.parse(rsp).entry.company.partners[i].politicalexposed.value == 1){
                                console.log('asdasdasdasdasdasdsad')
                                data.push({ 
                                    "name"    : JSON.parse(rsp).entry.company.partners[i].name.value,
                                    "id" : JSON.parse(rsp).entry.company.partners[i].id,
                                    "document"  : JSON.parse(rsp).entry.company.partners[i].document.value,
                                    "phone"    : JSON.parse(rsp).entry.company.partners[i].phone.value,
                                    "politicalexp"    : JSON.parse(rsp).entry.company.partners[i].politicalexposed.value,
                                    "legalrep": JSON.parse(rsp).entry.company.partners[i].legalrep.value,
                                    "affiliationbody": JSON.parse(rsp).entry.company.partners[i].affiliationbody.value,
                                    "positionheld": JSON.parse(rsp).entry.company.partners[i].positionheld.value,
                                    "pepcountryid": JSON.parse(rsp).entry.company.partners[i].pepcountryid.value,
                                    "peprelatedid": JSON.parse(rsp).entry.company.partners[i].peprelatedid.value,
                                    
                                    "nameValid" : JSON.parse(rsp).entry.company.partners[i].name.valid,
                                    "documentValid" : JSON.parse(rsp).entry.company.partners[i].document.valid,
                                    "phoneValid" : JSON.parse(rsp).entry.company.partners[i].phone.valid,
                                    "politicalexpValid" : JSON.parse(rsp).entry.company.partners[i].politicalexposed.valid,
                                    
                                    "affiliationbodyValid" : JSON.parse(rsp).entry.company.partners[i].affiliationbody.valid,
                                    "positionheldValid" : JSON.parse(rsp).entry.company.partners[i].positionheld.valid,
                                    "pepcountryidValid" : JSON.parse(rsp).entry.company.partners[i].pepcountryid.valid,
                                    "peprelatedidValid" : JSON.parse(rsp).entry.company.partners[i].peprelatedid.valid,
                                    
                                    
                                    "nameUpdate" : JSON.parse(rsp).entry.company.partners[i].name.update,
                                    "documentUpdate" : JSON.parse(rsp).entry.company.partners[i].document.update,
                                    "phoneUpdate" : JSON.parse(rsp).entry.company.partners[i].phone.update,
                                    "politicalexpUpdate" : JSON.parse(rsp).entry.company.partners[i].politicalexposed.update,
                                    
                                    "affiliationbodyUpdate" : JSON.parse(rsp).entry.company.partners[i].affiliationbody.update,
                                    "positionheldUpdate" : JSON.parse(rsp).entry.company.partners[i].positionheld.update,
                                    "pepcountryidUpdate" : JSON.parse(rsp).entry.company.partners[i].pepcountryid.update,
                                    "peprelatedidUpdate" : JSON.parse(rsp).entry.company.partners[i].peprelatedid.update,
                                    
                                }); 
                            }else{
                                
                                data.push({ 
                                    "name"    : JSON.parse(rsp).entry.company.partners[i].name.value,
                                    "id" : JSON.parse(rsp).entry.company.partners[i].id,
                                    "document"  : JSON.parse(rsp).entry.company.partners[i].document.value,
                                    "phone"    : JSON.parse(rsp).entry.company.partners[i].phone.value,
                                    "politicalexp"    : JSON.parse(rsp).entry.company.partners[i].politicalexposed.value,
                                    "legalrep" : JSON.parse(rsp).entry.company.partners[i].legalrep.value,
                                    
                                    "nameValid" : JSON.parse(rsp).entry.company.partners[i].name.valid,
                                    "documentValid" : JSON.parse(rsp).entry.company.partners[i].document.valid,
                                    "phoneValid" : JSON.parse(rsp).entry.company.partners[i].phone.valid,
                                    "politicalexpValid" : JSON.parse(rsp).entry.company.partners[i].politicalexposed.valid,
                                    
                                    "nameUpdate" : JSON.parse(rsp).entry.company.partners[i].name.update,
                                    "documentUpdate" : JSON.parse(rsp).entry.company.partners[i].document.update,
                                    "phoneUpdate" : JSON.parse(rsp).entry.company.partners[i].phone.update,
                                    "politicalexpUpdate" : JSON.parse(rsp).entry.company.partners[i].politicalexposed.update,
                                });   
                            }
                        }else{
                            data.push({ 
                                "name"    : '',
                                "id" : '0',
                                "document"  : '',
                                "phone"    : '',
                                "politicalexp" : '',
                                "legalrep": ''
                            }); 
                        }
                    }
                }
                
                obj.data = data; 
                console.log(obj.data)
                //console.log(obj.data) // ESte es el que tal
                if(JSON.parse(rsp).entry.company.partners!=null){
                    listDraw(obj.data)   
                }else{
                    for (i=0;i<JSON.parse(rsp).entry.company.partnersnumber.value +1; i++){
                            // Se inicializa un JSON de datos de los socios
                            data.push({ 
                                "name"    : '',
                                "id" : '0',
                                "document"  : '',
                                "phone"    : '',
                                "politicalexp" : ''
                            });
                    }
                    listDraw(obj.data)   
                }
                //console.log(JSON.stringify(obj));
                console.log(obj.data)
                    if(JSON.parse(rsp).entry.company.partners!=null){
                        for (i=0;i<JSON.parse(rsp).entry.company.partnersnumber.value+1; i++){
                            var partnerdiv = document.getElementsByClassName('partnerdiv')[i];
                            var partnerdiv2 = document.getElementsByClassName('partnerdiv2')[i];
                            partnerdiv.children[0].children[0].children[2].value = obj.data[i].name;
                            partnerdiv.children[1].children[0].children[2].value = obj.data[i].document;
                            partnerdiv2.children[0].children[0].children[2].value = obj.data[i].phone;
                            partnerdiv2.children[1].children[0].children[2].value = obj.data[i].politicalexp;
                            if (obj.data[i].politicalexp == 1){
                                console.log(obj.data[i])
                                console.log(partnerdiv2.parentNode.nextElementSibling)
                                console.log(obj.data[i].affiliationbody)
                                console.log(obj.data[i].positionheld)
                                console.log(obj.data[i].pepcountryid)
                                console.log(obj.data[i].peprelatedid)
                                partnerdiv2.parentNode.nextElementSibling.children[0].children[0].children[0].children[2].value = obj.data[i].affiliationbody;
                                partnerdiv2.parentNode.nextElementSibling.children[0].children[1].children[0].children[2].value= obj.data[i].positionheld;
                                partnerdiv2.parentNode.nextElementSibling.children[1].children[0].children[0].children[2].value= obj.data[i].pepcountryid;
                                partnerdiv2.parentNode.nextElementSibling.children[1].children[1].children[0].children[2].value= obj.data[i].peprelatedid;
                                partnerdiv2.parentNode.nextElementSibling.style.display='block'
                                
                                setColorIcon(obj.data[i].affiliationbodyValid,partnerdiv2.parentNode.nextElementSibling.children[0].children[0].children[0].children[0].children[0])
                                setColorIcon(obj.data[i].positionheldValid,partnerdiv2.parentNode.nextElementSibling.children[0].children[1].children[0].children[0].children[0])
                                setColorIcon(obj.data[i].pepcountryidValid,partnerdiv2.parentNode.nextElementSibling.children[1].children[0].children[0].children[0].children[0])
                                setColorIcon(obj.data[i].peprelatedidValid,partnerdiv2.parentNode.nextElementSibling.children[1].children[1].children[0].children[0].children[0])
                                
                                if(obj.data[i].affiliationbodyValid == 1){
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[0].children[0].children[2].disabled = true;
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[0].children[0].children[2].style.cursor = 'default'
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[0].children[0].children[2].style.backgroundColor = 'white';
                                }
                                if(obj.data[i].positionheldValid == 1){
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[1].children[0].children[2].disabled = true;
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[1].children[0].children[2].style.cursor = 'default'
                                    partnerdiv2.parentNode.nextElementSibling.children[0].children[1].children[0].children[2].style.backgroundColor = 'white';
                                }
                                if(obj.data[i].pepcountryidValid == 1){
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[0].children[0].children[2].disabled = true;
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[0].children[0].children[2].style.cursor = 'default'
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[0].children[0].children[2].style.backgroundColor = 'white';
                                }
                                if(obj.data[i].peprelatedidValid == 1){
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[1].children[0].children[2].disabled = true;
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[1].children[0].children[2].style.cursor = 'default'
                                    partnerdiv2.parentNode.nextElementSibling.children[1].children[1].children[0].children[2].style.backgroundColor = 'white';
                                }
    
                            }
                            partnerdiv.parentElement.setAttribute("id",obj.data[i].id);
                    }   
                }
                setLevels(levels)
                document.getElementsByClassName('pageCnt')[0].style.visibility="visible"
                // Window Load
                var waitScreen = document.getElementById("waitScreen");
                document.body.removeChild(waitScreen);
                WS_waitscreen = false;
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
        //console.log(status)
        //console.log(rsp)
    }    
}

var data1 = [];
function verify(){
    var complete = true;
    for (i=0; i< document.getElementsByClassName('partnerdiv').length;i++){
        console.log('entrooooo')
        var partnerdiv = document.getElementsByClassName('partnerdiv')[i];
        var partnerdiv2 = document.getElementsByClassName('partnerdiv2')[i];
        if (partnerdiv.children[0].children[0].children[2].value =='' || partnerdiv.children[1].children[0].children[2].value =='' || 
            partnerdiv2.children[0].children[0].children[2].value =='' || partnerdiv2.children[1].children[0].children[2].value ==''){
                console.log(i)
            complete = false;
            if ( partnerdiv.children[0].children[0].children[2].value =='' ){
                partnerdiv.children[0].children[0].children[2].style.border ="2px solid #D0021B";
                partnerdiv.children[0].children[0].children[3].innerHTML = "Introduzca un nombre."
                partnerdiv.children[0].children[0].children[3].style.display = "block"
            }
            if ( partnerdiv.children[1].children[0].children[2].value =='' ){
                partnerdiv.children[1].children[0].children[2].style.border ="2px solid #D0021B";
                partnerdiv.children[1].children[0].children[3].innerHTML = "Introduzca una identificación."
                partnerdiv.children[1].children[0].children[3].style.display = "block"
            }
            if ( partnerdiv2.children[0].children[0].children[2].value =='' ){
                partnerdiv2.children[0].children[0].children[2].style.border ="2px solid #D0021B";
                partnerdiv2.children[0].children[0].children[3].innerHTML = "Introduzca un teléfono."
                partnerdiv2.children[0].children[0].children[3].style.display = "block"
            }
            if ( partnerdiv2.children[1].children[0].children[2].value =='' ){
                partnerdiv2.children[1].children[0].children[2].style.border ="2px solid #D0021B";
                partnerdiv2.children[1].children[0].children[3].innerHTML = "Seleccione una opción."
                partnerdiv2.children[1].children[0].children[3].style.display = "block"
            }
        }
        if (partnerdiv2.children[0].children[0].children[2].validity.valid == false){
            complete = false;
            partnerdiv2.children[0].children[0].children[2].style.border ="2px solid #D0021B";
            partnerdiv2.children[0].children[0].children[3].innerHTML = "El teléfono no es válido."
            partnerdiv2.children[0].children[0].children[3].style.display = "block"
        }
        if (partnerdiv2.children[1].children[0].children[2].value ==1 && i !=0){
            console.log('aaaaaa',i)
            console.log(partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[2])
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[3].innerHTML = "Introduzca un nombre."
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[0].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[3].innerHTML = "Introduzca un cargo."
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[0].children[1].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[3].innerHTML = "Seleccione un país."
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[0].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[3].innerHTML = "Introduzca una identificación."
                    partnerdiv2.parentNode.parentNode.children[i*2 - 1].children[1].children[1].children[0].children[3].style.display = "block"
                    complete = false
                }

        }
        if (partnerdiv2.children[1].children[0].children[2].value ==1 && i ==0){
            console.log(partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[1])
                if (partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[3].innerHTML = "Introduzca un nombre."
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[0].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[3].innerHTML = "Introduzca un cargo."
                    partnerdiv2.parentNode.parentNode.children[1].children[0].children[1].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[3].innerHTML = "Seleccione un país."
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[0].children[0].children[3].style.display = "block"
                    complete = false
                }
                if (partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[2].value == ''){
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[2].style.border ="2px solid #D0021B";
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[3].innerHTML = "Introduzca una identificación."
                    partnerdiv2.parentNode.parentNode.children[1].children[1].children[1].children[0].children[3].style.display = "block"
                    complete = false
                }

        }
    }
    console.log(complete)
    
    if(!complete){
        return;
    }else{
        console.log('holaaa')
        var aNames  = new Array(document.getElementsByClassName('partnerdiv').length);
        var aId = new Array(document.getElementsByClassName('partnerdiv').length);
        var aPhone   = new Array(document.getElementsByClassName('partnerdiv2').length);
        var aPol   = new Array(document.getElementsByClassName('partnerdiv2').length);
        var aLegal = new Array(document.getElementsByClassName('partnerdiv2').length);
        
        var aaffiliationbody   = new Array(document.getElementsByClassName('partnerdiv2').length);
        var apositionheld   = new Array(document.getElementsByClassName('partnerdiv2').length);
        var apepcountryid = new Array(document.getElementsByClassName('partnerdiv2').length);
        var apeprelatedid = new Array(document.getElementsByClassName('partnerdiv').length);
        var sessionid = new Array(document.getElementsByClassName('partnerdiv').length);
        
        var id = new Array(document.getElementsByClassName('partnerdiv').length);
        
        var data = []
        var obj = {}
        var j = document.getElementsByClassName('partnerdiv').length -1
        //for (i=0; i< document.getElementsByClassName('partnerdiv').length;i++){
        
        
        
        //for (i=document.getElementsByClassName('partnerdiv').length-1; i>=0;i--){
        //for (i=document.getElementsByClassName('partnerdiv').length-1; i>=0;i--){
        for (i=0; i<document.getElementsByClassName('partnerdiv').length;i++){
            
            aNames[i] = capitalize(document.getElementsByClassName('partnerdiv')[j-i].children[0].children[0].children[2].value);
            console.log(document.getElementsByClassName('partnerdiv')[j-i].children[1])
            aId[i] = document.getElementsByClassName('partnerdiv')[j-i].children[1].children[0].children[2].value;
            if(aId[i]=="")aId[i]=0;
            aPhone[i] = document.getElementsByClassName('partnerdiv2')[j-i].children[0].children[0].children[2].value;
            aPol[i] = document.getElementsByClassName('partnerdiv2')[j-i].children[1].children[0].children[2].value;
            console.log(aNames[i])
            aaffiliationbody[i] = capitalize(document.getElementsByClassName('partnerdiv')[j-i].parentElement.nextElementSibling.children[0].children[0].children[0].children[2].value);
            apositionheld[i] = document.getElementsByClassName('partnerdiv')[j-i].parentElement.nextElementSibling.children[0].children[1].children[0].children[2].value;
            /*
            aaffiliationbody[i] = capitalize(document.getElementsByClassName('partnerdiv')[j-i].parentNode.parentNode.children[1].children[0].children[0].children[0].children[2].value);
            apositionheld[i] = document.getElementsByClassName('partnerdiv')[j-i].parentNode.parentNode.children[1].children[0].children[1].children[0].children[2].value;*/
            apepcountryid[i] = document.getElementsByClassName('partnerdiv2')[j-i].parentElement.nextElementSibling.children[1].children[0].children[0].children[2].value;
            apeprelatedid[i] = document.getElementsByClassName('partnerdiv2')[j-i].parentElement.nextElementSibling.children[1].children[1].children[0].children[2].value;
            //apepcountryid[i] = document.getElementsByClassName('partnerdiv2')[j-i].parentNode.parentNode.children[1].children[1].children[0].children[0].children[2].value;
            //apeprelatedid[i] = document.getElementsByClassName('partnerdiv2')[j-i].parentNode.parentNode.children[1].children[1].children[1].children[0].children[2].value;
            sessionid[i] = getParameterByName('sessionid');
            
            console.log(document.getElementsByClassName('partnerdiv')[j-i].parentNode);
            console.log(document.getElementsByClassName('partnerdiv')[j-i].parentNode.id);
            
            //debugger;
            id[i] = document.getElementsByClassName('partnerdiv')[j-i].parentNode.id;
            if(id[i]=="")id[i] = 0;
            
            if (i==document.getElementsByClassName('partnerdiv').length-1){
                aLegal[i] = 1
            }else{
                aLegal[i] = 0
            }
            console.log(id)
            if (aPol[i] == 1){
                data.push({ 
                    "name": aNames[i],
                    "doc": aId[i],
                    "phone": aPhone[i],
                    "politicalexp" : aPol[i],
                    "legalrep": aLegal[i],
                    "affiliationbody": aaffiliationbody[i],
                    "positionheld": apositionheld[i],
                    "pepcountryid": apepcountryid[i],
                    "peprelatedid": apeprelatedid[i],
                    "id": id[i],
                    'sessionid' : sessionid[i],
                    "number" : i
                });   
            }else{
                data.push({ 
                    "name": aNames[i],
                    "doc": aId[i],
                    "phone": aPhone[i],
                    "politicalexp" : aPol[i],
                    "legalrep": aLegal[i],
                    "id": id[i],
                    'sessionid' : sessionid[i],
                    "number" : i
                }); 
            }
            console.log(data)
        }
        obj.data = data;
        console.log(obj.data) // ESte es el que tal
        //console.log
        var isOk = true;
        var req = {
            "sessionid" : getParameterByName('sessionid'),
            "id": 0,
            "name" : '',
            'doc' : '',
            "phone" : '',
            "affiliationbody": '',
            "positionheld": '',
            "pepcountryid": '',
            "peprelatedid": '',
            'politicalexp': '',
            
            "step" : 2
        }
        var isOk = true;
        data1 = data.reverse()
        size = data1.length;
        validLoaded();
        // for(i=0;i<obj.data.length;i++){
            
        //     (function(i){
        //         console.log('iiiiiiii',i)
        //         // Retrasar ciclo for 
        //         console.log(obj.data)
        //       window.setTimeout(function(){
        //         req.name = obj.data[i].name
        //         req.doc = obj.data[i].doc
        //         req.phone = obj.data[i].phone
        //         console.log(req.politicalexp)
        //          console.log(obj.data[i].politicalexp)
        //         req.politicalexp = obj.data[i].politicalexp
        //         console.log(req.politicalexp)
        //         console.log('AAAAAAAAAA2',req.politicalexp)
        //         if (req.politicalexp == 1){
        //             console.log('entro')
        //             req.affiliationbody = obj.data[i].affiliationbody
        //             req.positionheld = obj.data[i].positionheld
        //             req.pepcountryid = obj.data[i].pepcountryid
        //             req.peprelatedid = obj.data[i].peprelatedid
        //         }
        //         console.log('AAAAAAAAAA',req)
        //         req.number = i
        //         console.log(req)
        //         //callWS("GET", "partners/update", req, response);
        //         function response(status, rsp){
        //             console.log(status)
        //             console.log(req)
        //             switch(status){
        //                 case 200:
        //                     console.log(status)
        //                     console.log(req)
        //                     // Ok
        //                     console.log('fel')
        //                     //gotoPage('register','regCompanyRes', { 'sessionid' : getParameterByName('sessionid') })
        //                     break;
        //                 case 204:
        //                     isOk = false;
        //                     break;
        //                 case 400:
        //                     // Parametros incorrectos
        //                      isOk = false;
        //                     break;
        //                 case 409:
        //                     // Registro duplicado
        //                     if(entrydata.company.partners[req.number].document === req.doc){
        //                         //console.log('No es registro duplicado')
        //                     }else{
        //                         isOk = false;
        //                         partnerdiv = document.getElementsByClassName('partnerdiv')[req.number]
        //                         partnerdiv.children[0].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv.children[1].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv2.children[0].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv.children[1].children[0].children[2].innerHTML = "Ya existe un socio registrado con esta identificación."
        //                         partnerdiv.children[1].children[0].children[2].style.display = "block"
        //                     }
        //                 case 500:
        //                     if(entrydata.company.partners[req.number].document === req.doc){
        //                         //console.log('No es registro duplicado')
        //                     }else{
        //                         isOk = false;
        //                         partnerdiv = document.getElementsByClassName('partnerdiv')[req.number]
        //                         partnerdiv.children[0].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv.children[1].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv2.children[0].children[0].children[1].style.border ="2px solid #D0021B";
        //                         partnerdiv.children[1].children[0].children[2].innerHTML = "Ya existe un socio registrado con esta identificación."
        //                         partnerdiv.children[1].children[0].children[2].style.display = "block"
        //                     }
        //                     break;
        //                 default:
        //                     isOk = false;
        //                     break;
        //             }
        //         }  
        //       }, i * 1000);
        
        //      }(i));
        
        //     window.setTimeout(function(){
        //         if(isOk){
        //             console.log('fel')
        //             //gotoPage('register','regCompanyRes', { 'sessionid' : getParameterByName('sessionid') })
        //         }
        //     },(document.getElementsByClassName('partnerdiv').length * 1000 + 500));
            
        // }
    }
}
function validLoaded(){
    while(loaded<size){
        if(loaded==last){
            last = last+1;
            var person = data1[loaded];
            savePartner(person);
        }
        else break;
    }
        
}
var size=0;
var loaded = 0;
var last = 0;
function savePartner(person){
    callWS("GET", "partners/update", person, response);
    function response(status, rsp){
        switch(status){
            case 200:
                loaded=loaded+1;
                if(loaded==size)gotoPage('register','regCompanyRes', { 'sessionid' : getParameterByName('sessionid') })
                else validLoaded();
            break;
            case 204:
                isOk = false;
                break;
            case 400:
                console.log(person)
                // Parametros incorrectos
                 isOk = false;
                break;
            case 401:
                expiredSession();
                break;
            case 409:
                loaded=loaded+1;
                //debugger;
                if(loaded==size)gotoPage('register','regCompanyRes', { 'sessionid' : getParameterByName('sessionid') })
                break;
            case 500:
                //if(entrydata.company.partners[person.number].document === person.doc){
                //console.log('No es registro duplicado')
                //}else{
                /*isOk = false;
                partnerdiv = document.getElementsByClassName('partnerdiv')[person.number]
                partnerdiv.children[0].children[0].children[1].style.border ="2px solid #D0021B";
                partnerdiv.children[1].children[0].children[1].style.border ="2px solid #D0021B";
                partnerdiv2.children[0].children[0].children[1].style.border ="2px solid #D0021B";
                partnerdiv.children[1].children[0].children[2].innerHTML = "Ya existe un socio registrado con esta identificación."
                partnerdiv.children[1].children[0].children[2].style.display = "block"*/
                //}
                break;
            default:
                isOk = false;
            break;
        }
    }
}
function updateCompany(req){
    console.log(req)
    //callWS("POST", "users/updatecompany", req, response);
    function response(status, rsp){
        switch(status){
            case 200:
                // Ok
                console.log(req)
                //gotoPage('register','regCompanyRes', { 'sessionid' : getParameterByName('sessionid') })
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
        
                break;
            default:
                break;
        }
    }  
}

function addPolitician(i){
    document.getElementsByClassName('politicianForm')[i].style.display = 'block'
}

function deletePolitician(i){
    document.getElementsByClassName('politicianForm')[i].style.display = 'none'
}

function getCountries(){
    var req = {
        "sessionid": getParameterByName('sessionid')
    }
        
    callWS("GET", "demographics/countries", req, response);
        
    function response(status, rsp){
        console.log(status)
        switch(status){
            case 200:
                countries = JSON.parse(rsp);
                addOptions("polCountry", countries,true)
                //getEntry(getParameterByName('sessionid'))
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
    }    
}
function addOptions(domElement, array, bool) {
    for (var i = 0; i < document.getElementsByName(domElement).length ; i ++){
        var selector = document.getElementsByName(domElement)[i];
        var firstOopcion = document.createElement("option");
        firstOopcion.disabled = true;
        firstOopcion.text = 'Selecciona'
        firstOopcion.value =''
        firstOopcion.selected = true
        selector.add(firstOopcion)
        for (countrie in array.records) {
            if (array.records[countrie].id > 0){
                var opcion = document.createElement("option");
                opcion.text = array.records[countrie].dsc;
                opcion.value = array.records[countrie].id
                selector.add(opcion);   
            }
        }   
        firstOopcion.selected = true
        
    }
    // First Time
    getEntry(getParameterByName('sessionid'))
}

// name A: classIcon
// name B : BD
// nameC: nameInput
function setStatus(nameA,nameB,nameC){
    console.log(nameC)
    document.getElementById(nameC).setAttribute('dataname',nameB.update)
    console.log(nameB.valid)
    if(nameB.valid == -1){
        document.getElementById(nameA).classList.add("iconRed")
        document.getElementById(nameA).classList.add("fas")
        document.getElementById(nameA).classList.add("fa-times-circle")
    }
    else if (nameB.valid == 0){
        document.getElementById(nameA).classList.add("iconYellow")
        document.getElementById(nameA).classList.add("fas")
        document.getElementById(nameA).classList.add("fa-pause-circle")
    }
    else if (nameB.valid == 1){
        document.getElementById(nameA).classList.add("iconGreen")
        document.getElementById(nameA).classList.add("fas")
        document.getElementById(nameA).classList.add("fa-check-circle")
        document.getElementById(nameC).disabled = true;
        document.getElementById(nameC).style.cursor = 'default'
        if(document.getElementById(nameC).tagName != 'SELECT'){
            document.getElementById(nameC).style.backgroundColor = 'white'
        }
    }
}

function setSpecialStatus(ele,rsp,political){
    setColorIcon(rsp.nameValid,ele.children[0].children[0].children[0].children[0].children[0])
    setColorIcon(rsp.documentValid,ele.children[0].children[1].children[0].children[0].children[0])
    setColorIcon(rsp.phoneValid,ele.children[1].children[0].children[0].children[0].children[0])
    setColorIcon(rsp.politicalexpValid,ele.children[1].children[1].children[0].children[0].children[0])
    console.log(rsp)
    if(political == 1){
        //setColorIcon(rsp.affiliationbodyValid,ele.nextElementSibling.children[0].children[0].children[0].children[0].children[0])
        //console.log(ele.nextElementSibling)
        //console.log(ele)
    }/*
    if(rsp.positionheldValid){
        setColorIcon(rsp.positionheldValid,ele.children[0].children[0].children[0].children[0].children[0])
    }
    if(rsp.pepcountryidValid){
        setColorIcon(rsp.pepcountryidValid,ele.children[0].children[0].children[0].children[0].children[0])
    }
    if(rsp.peprelatedidValid){
        setColorIcon(rsp.peprelatedidValid,ele.children[0].children[0].children[0].children[0].children[0])
    }*/
    
}

function setColorIcon(condition,icon){
    if(condition == -1){
        icon.classList.add("iconRed")
        icon.classList.add("fas")
        icon.classList.add("fa-times-circle")
    }
    else if (condition == 0){
        icon.classList.add("iconYellow")
        icon.classList.add("fas")
        icon.classList.add("fa-pause-circle")
    }
    else if (condition == 1){
        icon.classList.add("iconGreen")
        icon.classList.add("fas")
        icon.classList.add("fa-check-circle")
    }
}

function expiredSession(){
    document.getElementsByClassName('expired')[0].style.display = "table"
    WS_waitscreen = false;
    var seconds = 30;
    var countdown = setInterval(countDown, 1000);
    
    function countDown(){
        seconds--;
        if(seconds == 0){
            if(document.getElementsByClassName('expired')[0].style.display == "table"){
                gotoPage('login','main','');
                clearInterval(countdown);
            }
        }
        if(document.getElementsByClassName('expired')[0].style.display == "none"){
            clearInterval(countdown)
        }
    }
}

function sessionUpdate(req){
    callWS('GET', 'session/update', req, response);
    function response(status, rsp){
        console.log('session/update')
        console.log(JSON.parse(rsp));
        console.log(status) 
        switch(status){
            case 200:
                document.getElementsByClassName('expired')[0].style.display = "none"
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 402:
                break;
            case 403:
                break;
            case 500:
                break;
            default:
                break;
        }
    }   
}

function setLevels(levels){
    
    console.log(document.getElementsByTagName('input').length)
    for (var i = 0; document.getElementsByTagName('input').length > i; i++){
        document.getElementsByTagName('input')[i].classList.add("inputElement")
    }
    for (var i = 0; document.getElementsByTagName('select').length > i; i++){
        document.getElementsByTagName('select')[i].classList.add("inputElement")
    }
    console.log(levels)
    levels1 = levels[1].partnersRequired.split(',')
    levels2 = levels[2].partnersRequired.split(',')
    levels3 = levels[3].partnersRequired.split(',')
    console.log(document.getElementsByClassName('inputElement'))
    console.log(document.getElementsByClassName('inputElement').length)
    for(var i = 0; i < document.getElementsByClassName('inputElement').length ; i++){
        if(!document.getElementsByClassName('inputElement')[i].previousElementSibling.children[0]){
            document.getElementsByClassName('inputElement')[i].previousElementSibling.innerHTML += '<span style="font-size: 90%; color: #7D8B9E;" class="roboto-bold"> (1) </span>'   
        }
    }
}
