var surl = window.location.host.split(".");
surl = surl[surl.length-1];
dimension = 100;

if(surl=='')surl='net';

picdir='http://klf-communications.'+surl+'/DATA/s/';

function replaceIt(string,suchen,ersetzen)
{
	ausgabe = "" + string;
	while (ausgabe.indexOf(suchen)>-1)
	{
    	pos= ausgabe.indexOf(suchen);
    	ausgabe = "" + (ausgabe.substring(0, pos) + ersetzen +
		ausgabe.substring((pos + suchen.length), ausgabe.length));
  	}
  	return ausgabe;
}

function enter()
{
	if(window.event && window.event.keyCode == 13) 
	{
 		MakeFile();
  		return false;
	}
}

tempload=replaceIt(replaceIt(document.getElementsByTagName("pre")[0].innerHTML,'\r',''),"&amp;","&").split("\n");

if (typeof document.addEventListener != 'function' && window.XMLHttpRequest)
{
	font='klf,Impact,Arial';
	fontwieght='';
}
else
{
	font='Arial';
	fontwieght='bold';
}

if (top.location != self.location)
{
	piclink='#';
}
else
{
	piclink='http://klf-communications.'+surl;
}

document.write(
'<style>'+
'@font-face {'+
    'font-family: klf;'+
    'font-style:  normal;'+
    'font-weight: normal;'+
    'src: url(\''+picdir+'klf.eot\');'+
'}'+
'*'+
'{'+
	'FONT-FAMILY: '+font+';'+
	'FONT-WEIGHT: '+fontwieght+';'+
'}'+
'INPUT'+
'{'+
	'FONT-SIZE: 14px;'+
	'CURSOR: url(\''+picdir+'klf.ani\')'+
'}'+
'INPUT.b2'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff'+
'}'+
'INPUT.b1'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000'+
'}'+
'A'+
'{'+
	'PADDING: 2px;'+
	'TEXT-DECORATION: none;'+
	'CURSOR: url(\'http://www.klf-communications.'+surl+'/DATA/s/klf.ani\')'+
'}'+
'A:link'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000;'+
'}'+
'A:visited'+
'{'+
	'COLOR: #fff;'+
	'BACKGROUND-COLOR: #000;'+
'}'+
'A:hover'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff;'+
'}'+
'A:active'+
'{'+
	'COLOR: #000;'+
	'BACKGROUND-COLOR: #fff;'+
'}'+
'*.n'+
'{'+
	'display:none;'+
	'FONT-SIZE: 1px;'+
'}'+
'BODY'+
'{'+
	'SCROLLBAR-ARROW-COLOR: #000;'+
	'SCROLLBAR-TRACK-COLOR: #000;'+
	'SCROLLBAR-BASE-COLOR: #000;'+
	'BACKGROUND-COLOR: #000;'+
	'scrollbar-3d-light-color: #000;'+
	'scrollbar-dark-shadow-color: #000;'+
	'CURSOR: url(\'http://www.klf-communications.'+surl+'/DATA/s/klf.cur\')'+
'}'+
'IMG'+
'{'+
	'Border: 0px;'+
'}'+
'*.l1'+
'{'+
	'FONT-SIZE: 14px;'+
	'WIDTH: 20px;'+
	'HEIGHT: 20px;'+
'}'+
'*.l2'+
'{'+
	'FONT-SIZE: 7px;'+
	'WIDTH: 0px;'+
	'HEIGHT: 0px;'+
'}'+
'*.l3'+
'{'+
	'FONT-SIZE: 0px;'+
	'WIDTH: 0px;'+
	'HEIGHT: 0px;'+
'}'+
'A.c'+
'{'+
	'text-align: center;'+
	'DISPLAY: block;'+
'}'+
'*.message'+
'{'+
	'COLOR: #fff;'+
	'FONT-SIZE: 14px;'+
'}'+
'</style>'+
'<table width=100%>'+
	'<tr>'+
		'<td>'+
			'<table WIDTH=100%>'+
				'<tr>'+
					'<td WIDTH=1>'+
						'<a class=c href='+piclink+'>'+
							'<img src='+picdir+'klfcommunications.gif '+
								'alt=www.klf-communications.'+surl+' '+
								'onmouseover="this.src=\''+picdir+'klfcommunications2.gif\';" '+
								'onmouseout="this.src=\''+picdir+'klfcommunications.gif\';" >'+
						'</a>'+
						'</td>'+
					'<td align=center>'+
						'<table>'+
							'<tr>'+
								'<td align=center><nobr>'+
									'<input type=text ID=qxxx name=qxxx size=40 maxlength=255 class=b1 onmouseout="this.className=\'b1\'" '+
										'onmouseover="this.className=\'b2\'" value="" onkeypress="return enter()"> '+
									'<input type=button class=b1 onmouseout="this.className=\'b1\'" '+
										'onmouseover="this.className=\'b2\'" value=search onclick=MakeFile()>'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td align=center class=message id=messsage>'+
								'</td>'+
							'</tr>'+
						'</table>'+
					'</td>'+
					'<td WIDTH=1>'+
						'<a class=c href='+piclink+'>'+
							'<img src='+picdir+'klfcommunications.gif '+
								'alt=www.klf-communications.'+surl+' '+
								'onmouseover="this.src=\''+picdir+'klfcommunications2.gif\';"'+
								'onmouseout="this.src=\''+picdir+'klfcommunications.gif\';">'+
						'</a>'+
					'</td>'+
				'</tr>'+
			'</table>'+
		'</td>'+
	'</tr>'+
	'<tr>'+
		'<td id=q align=center>'+
		'</td>'+
	'</tr>'+
	'<tr>'+
		'<td id=p align=center>'+
		'</td>'+
	'</tr>'+
'</table>');

buffer='';

lasttempstring=Array('','','','','');

for(x=0;x<tempload.length;x++)
{
	tempstring=tempload[x];

	for(cx=tempload[x].split('/').length;cx<5;cx++)
	{
		tempstring='*/'+tempstring;
	}

	tempstring=tempstring.split('/');

	if(tempstring[0]=='*')tempstring[0]=lasttempstring[0];
	if(tempstring[1]=='*')tempstring[1]=lasttempstring[1];
	if(tempstring[2]=='*')tempstring[2]=lasttempstring[2];
	if(tempstring[3]=='*')tempstring[3]=lasttempstring[3];

	lasttempstring=tempstring;

	tempload[x]=tempstring;
}

filearray=Array();
filearraypointer=0;
bigarray=Array();
alparray=Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

function trim (zeichenkette)
{
 	return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

function MakeFile()
{
	filearray=Array();
	filearraypointer=0;
//	bigarray=Array();
		
	searchvalue=trim(document.getElementById('qxxx').value.toLowerCase());
	
	insearch=false;

	for(sx=0;sx<searchvalue.length;sx++)
	{
		if(searchvalue.charAt(sx)=='"')
		{
			insearch=!insearch;
		}
		if(insearch)
		{
			if(searchvalue.charAt(sx)==' ')
			{
				searchvalue=searchvalue.substring(0,sx)+'¿'+searchvalue.substring(sx+1,searchvalue.length);
			}
		}
	}

	searchvalue=searchvalue.split(' ');
	
	for(sx=0;sx<searchvalue.length;sx++)
	{
		searchvalue[sx]=replaceIt(replaceIt(searchvalue[sx],'"',''),'¿',' ');
	}
	
	for(x=0;x<tempload.length;x++)
	{
		tempstring=tempload[x];

		add=true;

		if(searchvalue[0]!='')
		{
			refstring=replaceIt(replaceIt(tempstring[0]+' '+tempstring[1]+' '+tempstring[2]+' '+tempstring[3],'.',' '),'_',' ');

			for(sx=0;sx<searchvalue.length;sx++)
			{
				if(refstring.indexOf(searchvalue[sx])==-1)
				{
					add=false;
				}
			}
		}
		
		if(add)
		{
			for(cx=0;cx<=tempstring[4];cx++)
			{
				filepartname=alparray[(cx%26)];

				if(cx>25)filepartname=alparray[(((cx)-(cx%26))/26)-1]+filepartname;

				filearray[filearraypointer++]=tempstring[0]+'.'+tempstring[1]+'.'+tempstring[2]+'.'+tempstring[3]+'.'+filepartname;
			}
		}
	}

	changeset(0);
}

topdom='http://pics.klf-communications.'+surl+'/';
ext='';

//topdom='';
//ext='.jpg';

function changeset(start)
{
	defineDimension();

	buffer='';

	ende=start+dimension;

	if(ende>filearray.length)
	{
	ende=filearray.length;
	}

	for(x=start;x<ende;x++)
	{
		if(bigarray[filearray[x]])
		{
			dir='';
	 	}
		else
		{
			dir='t/';
	 	}
		
		buffer=buffer+
		'<table style="display:inline;">'+
			'<tr>'+
				'<td ID=img'+x+' onclick=y('+x+')>'+
					'<a class=c href=#>'+
						'<IMG title="'+filearray[x]+'" src='+topdom+dir+filearray[x]+ext+'>'+
					'</a>'+
				'</td>'+
			'</tr>'+
		'</table> <b class=n>.</b> ';
	}
	document.getElementById('p').innerHTML=buffer;
	
	buffer='';

	for(x=0;x<filearray.length/dimension;x++)
	{
		en=(x*dimension)+dimension;
		if(en>filearray.length) en=filearray.length;

		buffer=buffer+'<a ';
		
		if((x==0)||(x>filearray.length/dimension-1)||(x==start/dimension))
		{
			buffer=buffer+'class=l1 ';
		}
		else
		{
			buffer=buffer+'class=l2 onmouseout="this.className=\'l2\'" onmouseover="this.className=\'l1\'" ';
		}

		buffer=buffer+'href=# title="'+ ((x*dimension)+1) +' ('+filearray[x*dimension]+') - '+en+' ('+filearray[(en-1)]+')" '+
		'onclick=changeset('+(x*dimension)+')>'+(x+1)+'.</a><font class=l3> </font>';
	}
	
	document.getElementById('q').innerHTML=buffer;

	if (filearray.length!=0) 
	{
		document.getElementById('messsage').innerHTML='<nobr>search result ('+(start+1)+' - '+(ende)+')';
	}
	else
	{
		document.getElementById('messsage').innerHTML='<nobr>no search result';
	}
}

function y(x)
{
	line = document.getElementById('img'+x);

	if(bigarray[filearray[x]])
	{
		bigarray[filearray[x]] = false;
		dir='t/';
 	}
	else
	{
		bigarray[filearray[x]] = true;
		dir='';
 	}

	line.innerHTML ='<a class=c href=#>'+
		'<IMG title="'+filearray[x]+'" src='+topdom+dir+filearray[x]+ext+'>'+
	'</a>';
}

function defineDimension()
{

	Width1=document.body.clientWidth;
	Width2=Width1-18-6;
	Width3=Width2/63;
	Width4=Math.ceil(Width3);
	Width5=Width4-1;
	
	Height1=document.body.clientHeight;
	Height2=Height1-170;
	Height3=Height2/63;
	Height4=Math.ceil(Height3);
	Height5=Height4;

	dimension = Width5*Height5;
}

MakeFile();