//Sergei Ganin's Dichotomies Calculator

input=document.location.search.substring(1);

hex= "0123456789ABCDEF";
k=0;

dichtemp1='';
dichtemp2='';
dichotomy1='';
dichotomy2='';
dich='';

known = new Array();

known['AAAA'] = "Extrovert";
known['5555'] = "Introvert";

known['6699'] = "Sensing";
known['9966'] = "Intuitive";

known['9669'] = "Thinking";
known['6996'] = "Feeling";

known['3C3C'] = "Judging";
known['C3C3'] = "Perceiving";

known['9696'] = "Static";
known['6969'] = "Dynamic";

known['A5A5'] = "Positivist";
known['5A5A'] = "Negativist";

known['9999'] = "Questim";
known['6666'] = "Declatim";

known['A55A'] = "Tactical";
known['5AA5'] = "Strategic";

known['AA55'] = "Constuctivist";
known['55AA'] = "Emotivist";

known['CCCC'] = "Right";
known['3333'] = "Left";

known['C33C'] = "Compliant";
known['3CC3'] = "Obstinate";

known['CC33'] = "Careless";
known['33CC'] = "Farsighted";

known['F00F'] = "Reasonable";
known['0FF0'] = "Resolute";

known['FF00'] = "Merry";
known['00FF'] = "Serious";

known['0F0F'] = "Autocratic";
known['F0F0'] = "Democratic";

rev_done = new Array();

bin = new Array();
bin ['0'] = "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['1'] = "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|";
bin ['2'] = "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['3'] = "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|";
bin ['4'] = "&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['5'] = "&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|";
bin ['6'] = "&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['7'] = "&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|";
bin ['8'] = "&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['9'] = "&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|";
bin ['A'] = "&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['B'] = "&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|";
bin ['C'] = "&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['D'] = "&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|&nbsp;*&nbsp;|";
bin ['E'] = "&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;&nbsp;&nbsp;|";
bin ['F'] = "&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|&nbsp;*&nbsp;|";

bin3 = new Array();
bin3 ['0000'] = "0";
bin3 ['0001'] = "1";
bin3 ['0010'] = "2";
bin3 ['0011'] = "3";
bin3 ['0100'] = "4";
bin3 ['0101'] = "5";
bin3 ['0110'] = "6";
bin3 ['0111'] = "7";
bin3 ['1000'] = "8";
bin3 ['1001'] = "9";
bin3 ['1010'] = "A";
bin3 ['1011'] = "B";
bin3 ['1100'] = "C";
bin3 ['1101'] = "D";
bin3 ['1110'] = "E";
bin3 ['1111'] = "F";


bin2 = new Array();
bin2 ['0'] = 0;
bin2 ['1'] = 1;
bin2 ['2'] = 1;
bin2 ['3'] = 2;
bin2 ['4'] = 1;
bin2 ['5'] = 2;
bin2 ['6'] = 2;
bin2 ['7'] = 3;
bin2 ['8'] = 1;
bin2 ['9'] = 2;
bin2 ['A'] = 2;
bin2 ['B'] = 3;
bin2 ['C'] = 2;
bin2 ['D'] = 3;
bin2 ['E'] = 3;
bin2 ['F'] = 4;



temp_known = new Array();

all_temps = "EN,ES,IN,IS.EF,ET,IF,IT.EJ,EP,IJ,IP.NF,NT,SF,ST.NJ,NP,SJ,SP.FJ,FP,TJ,TP.EN,ES,IF,IT.EF,ET,IN,IS.NF,NT,ES,IS.SF,ST,EN,IN.EF,IF,NT,ST.ET,IT,NF,SF.SP,SJ,NT,NF.SF,ST,NJ,NP.FJ,FP,NT,ST.TJ,TP,NF,SF.NJ,SJ,FP,TP.NP,SP,FJ,TJ.FJ,FP,ET,IT.TJ,TP,EF,IF.EJ,IJ,FP,TP.EP,IP,FJ,TJ.EF,ET,IJ,IP.IF,IT,EJ,EP";

temps = all_temps.split(".");


all_types = "ENTP,ISFP,ESFJ,INTJ,ENFJ,ISTJ,ESTP,INFP,ESFP,INTP,ENTJ,ISFJ,ESTJ,INFJ,ENFP,ISTP";

type_str = "|ILE|SEI|ESE|LII|EIE|LSI|SLE|IEI|SEE|ILI|LIE|ESI|LSE|EII|IEE|SLI|";

types = all_types.split(",");

temp_match = new Array();

for (t=0;t<temps.length;t++){

             temps2 = temps[t].split(",");
             temps2s = temps2.sort();     
 
              combo1 = [temps2s[0]+temps2s[1]+'',temps2s[2]+temps2s[3]+''];
              combo1s = combo1.sort();
              combo2 = [temps2s[0]+temps2s[2]+'',temps2s[1]+temps2s[3]+''];
              combo2s = combo2.sort();
              combo3 = [temps2s[0]+temps2s[3]+'',temps2s[1]+temps2s[2]+''];
              combo3s = combo3.sort();
                 
                      for (t2=0;t2<types.length;t2++){                        

                               if (typeof(temp_match[combo1s[0]])=='undefined'){temp_match[combo1s[0]]="";}
                               if (typeof(temp_match[combo1s[1]])=='undefined'){temp_match[combo1s[1]]="";}
                               temp_match[combo1s[0]]+= ((types[t2].indexOf(temps2s[0].split('')[0])<0 || types[t2].indexOf(temps2s[0].split('')[1])<0) && (types[t2].indexOf(temps2s[1].split('')[0])<0 || types[t2].indexOf(temps2s[1].split('')[1])<0))?"0":"1";
                               temp_match[combo1s[1]]+= ((types[t2].indexOf(temps2s[2].split('')[0])<0 || types[t2].indexOf(temps2s[2].split('')[1])<0) && (types[t2].indexOf(temps2s[3].split('')[0])<0 || types[t2].indexOf(temps2s[3].split('')[1])<0))?"0":"1";


                               if (typeof(temp_match[combo2s[0]])=='undefined'){temp_match[combo2s[0]]="";}
                               if (typeof(temp_match[combo2s[1]])=='undefined'){temp_match[combo2s[1]]="";}
                               temp_match[combo2s[0]]+= ((types[t2].indexOf(temps2s[0].split('')[0])<0 || types[t2].indexOf(temps2s[0].split('')[1])<0) && (types[t2].indexOf(temps2s[2].split('')[0])<0 || types[t2].indexOf(temps2s[2].split('')[1])<0))?"0":"1";
                               temp_match[combo2s[1]]+= ((types[t2].indexOf(temps2s[1].split('')[0])<0 || types[t2].indexOf(temps2s[1].split('')[1])<0) && (types[t2].indexOf(temps2s[3].split('')[0])<0 || types[t2].indexOf(temps2s[3].split('')[1])<0))?"0":"1";


                               if (typeof(temp_match[combo3s[0]])=='undefined'){temp_match[combo3s[0]]="";}
                               if (typeof(temp_match[combo3s[1]])=='undefined'){temp_match[combo3s[1]]="";}
                               temp_match[combo3s[0]]+= ((types[t2].indexOf(temps2s[0].split('')[0])<0 || types[t2].indexOf(temps2s[0].split('')[1])<0) && (types[t2].indexOf(temps2s[3].split('')[0])<0 || types[t2].indexOf(temps2s[3].split('')[1])<0))?"0":"1";
                               temp_match[combo3s[1]]+= ((types[t2].indexOf(temps2s[1].split('')[0])<0 || types[t2].indexOf(temps2s[1].split('')[1])<0) && (types[t2].indexOf(temps2s[2].split('')[0])<0 || types[t2].indexOf(temps2s[2].split('')[1])<0))?"0":"1";

                              
                     

                      }             

}


known_temps = new Array();

for (var a in temp_match){

temp_temp = ''+bin3[temp_match[a].substring(0,4)]+bin3[temp_match[a].substring(4,8)]+bin3[temp_match[a].substring(8,12)]+bin3[temp_match[a].substring(12,16)];

b1 = a.split('')[0]
b2 = a.split('')[1]

b3 = a.split('')[2]
b4 = a.split('')[3]

pr1 = (b1.indexOf('E')<0 && b1.indexOf('I')<0)?((b2.indexOf('E')<0 && b2.indexOf('I')<0)?'x':b2):b1;
pr2 = (b1.indexOf('S')<0 && b1.indexOf('N')<0)?((b2.indexOf('S')<0 && b2.indexOf('N')<0)?'x':b2):b1;
pr3 = (b1.indexOf('F')<0 && b1.indexOf('T')<0)?((b2.indexOf('F')<0 && b2.indexOf('T')<0)?'x':b2):b1;
pr4 = (b1.indexOf('J')<0 && b1.indexOf('P')<0)?((b2.indexOf('J')<0 && b2.indexOf('P')<0)?'x':b2.toLowerCase()):b1.toLowerCase();

pr5 = (b3.indexOf('E')<0 && b3.indexOf('I')<0)?((b4.indexOf('E')<0 && b4.indexOf('I')<0)?'x':b4):b3;
pr6 = (b3.indexOf('S')<0 && b3.indexOf('N')<0)?((b4.indexOf('S')<0 && b4.indexOf('N')<0)?'x':b4):b3;
pr7 = (b3.indexOf('F')<0 && b3.indexOf('T')<0)?((b4.indexOf('F')<0 && b4.indexOf('T')<0)?'x':b4):b3;
pr8 = (b3.indexOf('J')<0 && b3.indexOf('P')<0)?((b4.indexOf('J')<0 && b4.indexOf('P')<0)?'x':b4.toLowerCase()):b3.toLowerCase();

a = pr1+pr2+pr3+pr4+', '+pr5+pr6+pr7+pr8;

if (typeof(known_temps[temp_temp]) == 'undefined'){known_temps[temp_temp] = a;}
else {known_temps[temp_temp] += ', '+a;}

}



HexIt(input);


function HexIt(filter){


for (i1=0; i1<hex.length; i1++){

d1 = hex.charAt(i1);

          for (i2=0; i2<hex.length; i2++){
          d2 = hex.charAt(i2);
          
                                  for (i3=0; i3<hex.length; i3++){
                                  d3 = hex.charAt(i3);

                                                     
                                                               for (i4=0; i4<hex.length; i4++){
                                                               d4 = hex.charAt(i4);
 
                                                               
                                                               dich = ''+d1+d2+d3+d4;
                                                               rev_dich =''+hex.charAt(15 - hex.indexOf(d1))+hex.charAt(15 - hex.indexOf(d2))+hex.charAt(15 - hex.indexOf(d3))+hex.charAt(15 - hex.indexOf(d4));


                                                               rev_done[rev_dich]=1;
															   
                                                               dichotomy1 = (typeof(known[dich])=='undefined')?'':'<br><br>Reinin/Common Name: '+known[dich];
                                                               dichotomy2 = (typeof(known[rev_dich])=='undefined')?'':' -vs- ' + known[rev_dich];
                                                               
															   dichtemp1 = (typeof(known_temps[dich])=='undefined')?'':'<br><br>Temperament: '+known_temps[dich];
															   dichtemp2 = (typeof(known_temps[rev_dich])=='undefined')?'':' -vs- ' + known_temps[rev_dich];
															   
															    
															                                                         
																
																if (filter == "Quadsymmetrical"){
																		if ((bin2[d1] == 2 && bin2[d2]==2 && bin2[d3]== 2 && bin2[d4] == 2) && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
																
																else if (filter == "Reinin/Common"){
																		if (typeof(known[dich])!='undefined' && typeof(known[rev_dich])!='undefined' && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
																
																else if (filter == "Temperament"){
																		if (typeof(known_temps[dich])!='undefined' && typeof(known_temps[rev_dich])!='undefined' && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
																
																else if (filter == "Reinin/Common/Temperament/AND"){
																		if (typeof(known[dich])!='undefined' && typeof(known[rev_dich])!='undefined' && typeof(known_temps[dich])!='undefined' && typeof(known_temps[rev_dich])!='undefined' && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
															
															    else if (filter == "Reinin/Common/Temperament/OR"){
																		if (((typeof(known[dich])!='undefined' && typeof(known[rev_dich])!='undefined') || (typeof(known_temps[dich])!='undefined' && typeof(known_temps[rev_dich])!='undefined')) && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
																 
															    else if (filter == "Reinin/Common/Temperament/Quadsymmetrical/OR"){
																		if (((bin2[d1] == 2 && bin2[d2]==2 && bin2[d3]== 2 && bin2[d4] == 2) || (typeof(known[dich])!='undefined' && typeof(known[rev_dich])!='undefined') || (typeof(known_temps[dich])!='undefined' && typeof(known_temps[rev_dich])!='undefined')) && bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               	}
																
																else {
																        filter ="None";
																        if (bin2[d1]+bin2[d2]+bin2[d3]+bin2[d4] == 8 && rev_done[dich]!=1) {WriteItBaby(filter);}
                                                               
																}
                                               }


    

                                  }
 

          }




}

document.write('-----------------------<br>Total Dichotomies: '+k);

}

function WriteItBaby(filter) {
k++; document.write ('Dichotomy: '+k+'<br>Filter: '+filter+'<br>Dichotomy ID: '+dich+'/'+rev_dich+dichotomy1+dichotomy2+dichtemp1+dichtemp2+'<br><br>'+type_str+'<br>|'+bin[d1]+bin[d2]+bin[d3]+bin[d4]+'<br>   |'+bin[hex.charAt(15 - hex.indexOf(d1))]+bin[hex.charAt(15 - hex.indexOf(d2))]+bin[hex.charAt(15 - hex.indexOf(d3))]+bin[hex.charAt(15 - hex.indexOf(d4))]+'<br><br><br><br>');
}

