var hashIndex = 0;
function onFrameLoaded(hash)
{
	//document.getElementById("currentHash").innerHTML = hash;
	location.hash = hash;
}

function makeNewHash(xjrString,geclickt)
{

	var vormals = xjrString;
	var ersatz = '';
	var jetzt = vormals.replace(/\*\*\+\+DO/, ersatz);
	temp_xjrString = jetzt;
	
	if (geclickt == 'true')
	{
		temp_change_hash = 'flase';
		window.location.hash = xjrString;
	}
	else
	{
		temp_change_hash = 'true';
	};
	
	var doc = document.getElementById("historyFrame").contentWindow.document;
	doc.open("javascript:'<html></html>'");
	doc.write("<html><head><scri" + "pt type=\"text/javascript\">parent.onFrameLoaded('"+ temp_xjrString +"');</scri" + "pt></head><body>"+xjrString+"</body></html>");
	doc.close();

}

function HistoryInit()
{
	if (window.location.hash == '')
	{
		if ( - 1 != navigator.userAgent.indexOf("MSIE"))
		{
			makeNewHash('','true');
		};
	};
	
	HashParser();
	
}

var old_Hash = '';
function HashParser() {

	act_Hash = window.location.hash;

	var act_Hashvormals = act_Hash;
	var act_Hashersatz = '';
	var act_Hashjetzt = act_Hashvormals.replace(/#/, act_Hashersatz);
	act_Hash = act_Hashjetzt;
	
	if (old_Hash !=  act_Hash) {
	
		if ( - 1 != navigator.userAgent.indexOf("MSIE"))
		{
		
			if ( - 1 != act_Hash.indexOf("2A2A2B2B444F"))
			{
				makeNewHash(act_Hash,'true');
			};
			
		};
		
		// erstatz f�r XJR request
		
		if ( - 1 == act_Hash.indexOf("**++DO"))
		{				
		
			var xjr_str = build_xjr_str(act_Hash);
			
			if (xjr_str != 'no_function')
			{
				eval(xjr_str);
			};
		
		//	document.getElementById("currentHash").innerHTML = document.getElementById("currentHash").innerHTML + '-' + act_Hash;
			
		}
		else
		{
			if ( - 1 == navigator.userAgent.indexOf("MSIE"))
			{
				var xjr_str = build_xjr_str(act_Hash);
				
				if (xjr_str != 'no_function')
				{
					eval(xjr_str);
				};
			};
		};
		
		
		
		
		if (act_Hash == '')
		{
		
			location.href = 'http://'+window.location.hostname+window.location.pathname+window.location.search
		
		};
	
		old_Hash = act_Hash;
	
	};

	setTimeout('HashParser();',200);

}

function build_xjr_str(anchor_str)
{
	var temp_anchor_str = anchor_str;

	var temp_anchor_str_vormals = temp_anchor_str;
	
	var temp_anchor_str_jetzt = temp_anchor_str_vormals.replace(/xjr/,'');


	temp_anchor_str = 'xjr'+DoAsciiHex(temp_anchor_str_jetzt,'H2A');
	
	if (temp_anchor_str.indexOf('xjr') != -1)
	{
		array_anchor_str = temp_anchor_str.split('**');
		xjr_function_str = "get_it('"+array_anchor_str[1]+"','"+array_anchor_str[2]+"','"+array_anchor_str[3]+"');"
	}
	else
	{
		xjr_function_str = 'no_function';
	};
	
	
	return xjr_function_str
}



function build_xjr_anchor_links()
{
	var tempAlert = '';
	
	//var TempMainContent = $('MAIN_CONTENT');
	
	//var temp_length = TempMainContent.getElementsByTagName('a').length;
	
	$$('a').each(
		function(_item,_item_index)
		{
			temp_ATAG_Href = _item.href;
			if (
					(temp_ATAG_Href.indexOf('#xjr') != -1)
					&&
					(temp_ATAG_Href.indexOf('++DO') != -1)
				)
			{
				var tempArray = temp_ATAG_Href.split('#');
				var vormals = temp_ATAG_Href;
				var jetzt = vormals.replace(/\/#/g, window.location.pathname+window.location.search+'#');
				tempLength 	= jetzt.length;
				HashPos		= jetzt.indexOf('#');
				tempHash = Right(jetzt,tempLength-HashPos+3);
				//_item.href = window.location.pathname+window.location.search+'#xjr'+DoAsciiHex(tempHash,'A2H');
				_item.href = tempArray[0]+'#xjr'+DoAsciiHex(tempHash,'A2H');
				
				
				//console.log(temp_ATAG_Href);
				
				
				
				
				
				
			}
			
		}
	)
	
	/*
	for (var i= 0; i < temp_length; i++)
	{
		temp_ATAG_Href = TempMainContent.getElementsByTagName('a')[i].href;
		
		if (temp_ATAG_Href.indexOf('#xjr') != -1)
		{

//			tempAlert = tempAlert + temp_ATAG_Href + '\n';

			var vormals = temp_ATAG_Href;
			
			var jetzt = vormals.replace(/\/#/g, window.location.pathname+window.location.search+'#');
			
			tempLength 	= jetzt.length;
			HashPos		= jetzt.indexOf('#');
			
			tempHash = Right(jetzt,tempLength-HashPos+3);
			
			//if (window.location.hostname == 'typo-11.ehf-euro.st-innovation.com')
			//{
				TempMainContent.getElementsByTagName('a')[i].href = window.location.pathname+window.location.search+'#xjr'+DoAsciiHex(tempHash,'A2H');
			//}
			//else
			//{
			//	TempMainContent.getElementsByTagName('a')[i].href = jetzt;
			//};
			
			
//			make_anchor_behind_body_tag(temp_ATAG_Href);

		};
	};
	//alert(tempAlert);
	*/
}










// JavaScript Document
var MCarr=new Array(
"*","|",".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",
".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","-----",".----","..---","...--","....-",
".....","-....","--...","---..","----."
);
var ABC012arr="*|ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

function DoMorseDecrypt(x)
{
  mess="";apos=0;bpos=0;
  while(bpos<x.length)
  {
    bpos=x.indexOf(" ",apos);if(bpos<0){bpos=x.length};
    dits=x.substring(apos,bpos);apos=bpos+1;let="";
    for(j=0;j<MCarr.length;j++)
    {
      if(dits==MCarr[j]){let=ABC012arr.charAt(j)}
    };
    if(let==""){let="*"};
    mess+=let;
  };
  return mess;
};

function DoMorseEncrypt(x)
{
  mess="";
  for(i=0;i<x.length;i++)
  {
    let=x.charAt(i).toUpperCase();
    for(j=0;j<MCarr.length;j++)
    {
      if(let==ABC012arr.charAt(j)){mess+=MCarr[j]}
    };
    mess+=" ";
  };
  mess=mess.substring(0,mess.length-1);
  return mess;
};

function DoReverse(x)
{
  y="";
  for(i=0;i<x.length;i++)
  {
    y+=x.charAt(x.length-1-i);
  };
  return y
};

function DoCaeserEncrypt(x,shf)
{
  abc="abcdefghijklmnopqrstuvwxyz";
  ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  r1="";
  r2="";
  shf=eval(shf);
  for(i=0;i<x.length;i++)
  {
    let=x.charAt(i);
    pos=ABC.indexOf(let);
    if(pos>=0)
    {
      r1+=ABC.charAt(  (pos+shf)%26  )
    }
    else
    {
      r1+=let
    };
  };
  for(i=0;i<r1.length;i++)
  {
    let=r1.charAt(i);
    pos=abc.indexOf(let);
    if(pos>=0)
    {
      r2+=abc.charAt(  (pos+shf)%26  )
    }
    else
    {
      r2+=let
    };
  };
  return r2;
};

function DoCaeserDecrypt(x,shf)
{return DoCaeserEncrypt(x,26-shf);};


function MakeCipherABC(abc,key1)
{
abc=abc.toUpperCase();key1=key1.toUpperCase();
cyabc=key1+abc;
for(i=0;i<abc.length;i++){let=cyabc.charAt(i);pos=cyabc.indexOf(let,i+1);
while(pos>-1){cyabc=cyabc.substring(0,pos)+cyabc.substring(pos+1,cyabc.length);pos=cyabc.indexOf(let,i+1);};};
return cyabc;
}


function DoVigenere(et,key1,key2,abc,dir,vigtype,altluabc)
{dt="";et=et.toUpperCase();key1=key1.toUpperCase();key2=key2.toUpperCase();abc=abc.toUpperCase();dir=dir.toUpperCase();
pos=et.indexOf(" ");
while(pos>-1){et=et.substring(0,pos)+et.substring(pos+1,et.length);pos=et.indexOf(" ");};
cyabc=MakeCipherABC(abc,key1);
key1=cyabc;
lu=cyabc;
if(vigtype=="N"){lu=abc};
if(vigtype=="K"){lu=cyabc};
if(vigtype=="A"){lu=altluabc};
for(i=0;i<et.length;i++)
{let=et.charAt(i);letinabc=abc.indexOf(let);
if(letinabc<0){dt+=let;et=et.substring(0,i)+et.substring(i+1,et.length);i--}
else{
if(dir=="E"){dt+=lu.charAt((key1.indexOf(let)+key1.length+key1.indexOf(key2.charAt(i%key2.length)))%key1.length);};
if(dir=="D"){dt+=lu.charAt((key1.indexOf(let)+key1.length-key1.indexOf(key2.charAt(i%key2.length)))%key1.length);};};

};
return dt;};

function DoFreqCnt(x,abc)
{var i,abc,pos,freqs;
 pos=x.indexOf(" ");while(pos>-1){x=x.substring(0,pos)+x.substring(pos+1,x.length);pos=x.indexOf(" ");};
 x=x.toUpperCase();freqs="";
 letarr=new Array("");
 for(i=0;i<abc.length;i++){letarr[i]=0;};
 for(i=0;i<x.length;i++){letarr[abc.indexOf(x.charAt(i))]++};
 for(i=0;i<abc.length;i++){freqs+=abc.charAt(i)+":"+letarr[i]+"/"+x.length+"="+letarr[i]/x.length+"\n";};
 return freqs;
}

function DoRowColumnTranspose(et,rowcol,jump,startrow)
{dt="";if((et=="")||(rowcol=="")||(jump=="")||(startrow=="")){dt="You must supply all values";return dt;}
maxrow=eval(rowcol.substring(0,rowcol.indexOf(",")));
maxcol=eval(rowcol.substring(rowcol.indexOf(",")+1,rowcol.length));
jump=eval(jump);startrow=eval(startrow);
if(startrow>maxrow){dt="Start Row must be <= Max Rows";return dt;}
lin=new Array("");
for(i=0;i<maxrow;i++){lin[i]=et.substring(maxcol*i,maxcol*(i+1))};
row=startrow-1;col=maxcol-1;//starting point
for(i=0;i<(maxrow*maxcol);i++)
{dt+=lin[row].charAt(col);
 row=row+jump;
 while(row>=maxrow){row-=maxrow;col-=1;};
 while(col<=-1){col+=maxcol;row-=1;};
 while(row<=-1){row+=maxrow;col-=1;};
 while(col>=maxcol){col-=maxcol;row-=1;};
};
return dt;};


function DoModTranspose(et,startlet,jumpinc,modulus)
{dt="";if((et=="")||(startlet=="")||(jumpinc=="")||(modulus=="")){dt="You must supply all values";return dt;}
startlet=eval(startlet)-1;jumpinc=eval(jumpinc);modulus=eval(modulus);
if(startlet>modulus){dt="startlet must be <= maxchar";return dt;}
et=escape(et);
pos=et.indexOf("%0D");
while(pos>-1){et=et.substring(0,pos)+et.substring(pos+3,et.length);pos=et.indexOf("%0D");};
pos=et.indexOf("%0A");
while(pos>-1){et=et.substring(0,pos)+et.substring(pos+3,et.length);pos=et.indexOf("%0A");};
et=unescape(et);
for(i=0;i<(modulus);i++){dt+=et.charAt((startlet+jumpinc*i)%modulus);};
return dt;};


function DoAsciiHex(x,dir)
{hex="0123456789ABCDEF";almostAscii=' !"#$%&'+"'"+'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ['+'\\'+']^_`abcdefghijklmnopqrstuvwxyz{|}';r="";
if(dir=="A2H")
{for(i=0;i<x.length;i++){let=x.charAt(i);pos=almostAscii.indexOf(let)+32;h16=Math.floor(pos/16);h1=pos%16;r+=hex.charAt(h16)+hex.charAt(h1);};};
if(dir=="H2A")
{for(i=0;i<x.length;i++){let1=x.charAt(2*i);let2=x.charAt(2*i+1);val=hex.indexOf(let1)*16+hex.indexOf(let2);r+=almostAscii.charAt(val-32);};};
return r;
};


function DoSubstitute(x,orig,sub,dir)
{
x=x.toUpperCase();r="";
if(dir=="e")
{for(i=0;i<x.length;i++){let=x.charAt(i);pos=orig.indexOf(let);if(pos>-1){r+=sub.charAt(pos)}else{r+=let}}};
if(dir=="d")
{for(i=0;i<x.length;i++){let=x.charAt(i);pos=sub.indexOf(let);if(pos>-1){r+=orig.charAt(pos)}else{r+=let}}};
return r;
};

function SwitchEm(x,a,b)
{
posA=x.indexOf(a);
posB=x.indexOf(b);
r1=x.substring(0,posA)+b+x.substring(posA+1,x.length);
r2=r1.substring(0,posB)+a+r1.substring(posB+1,r1.length);
return r2;
};





function MakePlayfairSquare(abc,key1)
{
cyabc=MakeCipherABC(abc,key1);
row = new Array();for(i=0;i<5;i++){row[i]=""};
for(i=0;i<5;i++){for(j=0;j<5;j++)row[i]+=cyabc.charAt(5*i+j);};
sqr="";for(i=0;i<5;i++){sqr+=row[i]+"\n"};
return sqr;
};


function DoPlayfair(et,abc,key1,dir,dup)
{
et=et.toUpperCase();abc=abc.toUpperCase();key1=key1.toUpperCase();
pos=et.indexOf(" ");
while(pos>-1){et=et.substring(0,pos)+et.substring(pos+1,et.length);pos=et.indexOf(" ");};

pos=et.indexOf("?");
while(pos>-1){et=et.substring(0,pos)+et.substring(pos+1,et.length);pos=et.indexOf("?");};

for(i=0;i<et.length;i=i+2)
{let1=et.charAt(i);let2=et.charAt(i+1);if(let1==let2){et=et.substring(0,i+1)+"X"+et.substring(i+1,et.length)};};
if( (et.length%2)==1 ){et+='X'}

if(dup!=""){
pos=et.indexOf(dup);
while(pos>-1){et=et.substring(0,pos)+"I"+et.substring(pos+1,et.length);pos=et.indexOf(dup);};
};

cyabc=MakeCipherABC(abc,key1)
row=new Array();for(i=0;i<5;i++){row[i]=""};
for(i=0;i<5;i++){for(j=0;j<5;j++)row[i]+=cyabc.charAt(5*i+j);};

shf=1;if(dir=="E"){shf=1};if(dir=="D"){shf=4};

dt="";
for(i=0;i<et.length;i=i+2)
{
pos1=cyabc.indexOf(et.charAt(i));pos2=cyabc.indexOf(et.charAt(i+1));
x1=pos1%5;y1=Math.floor(pos1/5);x2=pos2%5;y2=Math.floor(pos2/5);

if(y1==y2){x1=(x1+shf)%5;x2=(x2+shf)%5}
else if(x1==x2){y1=(y1+shf)%5;y2=(y2+shf)%5}
else{temp=x1;x1=x2;x2=temp};

dt+=row[y1].charAt(x1)+row[y2].charAt(x2) ;
};


return dt;
};		
