// *********
// xml dom
var dateiname, verzeichnis, parameter;
var ShowText;
var Zwischentext;
var globalCounter=0;

var Term=new String();
var Link=new String();
var PosLink=new Array();
var TextUpdate=" ";

var ParseShowTrans=" ";
var ParseLang=" ";
// *********
// globale variablen fuer xml parsen
var xmlHttp;//GetXmlHttpObject();
var xmlDoc;

var http=null;// = createRequestObject();

var ShowTranscription=new String();	// xml einlesen und checken, ob angezeigt werden soll
var ShowTranslation=new String();

var tagTransl=" ", tagTransc=" ";
var Anzeige=null;

var globalDateiname=" ";
var TranscriptionThere=true, TranslationThere=true;

// *********
//
var SwitchLink=true;
var BildName;
var Seite=1;


// *******************************************************
// xml datei: on/off?
// *******************************************************
var bla;
function checkDisplay(str)
{ 
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	globalDateiname=str;
	var url=("http://www.copyrighthistory.org/htdocs/data/bib_record/" + str + ".xml");
	
	//xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=stateChange1;
	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}


// *****************
//
function stateChange1() 
{ 
	if (xmlHttp.readyState==4)
	{ 	
		if(xmlHttp.status == 200) 
		{
		tagTransl = xmlHttp.responseXML.getElementsByTagName("Show_Translation")[0].childNodes[0].nodeValue;
		tagTransc = xmlHttp.responseXML.getElementsByTagName("Show_Transcription")[0].childNodes[0].nodeValue;	
		//var author_transl = "";//xmlHttp.responseXML.getElementsByTagName("Author_Translation")[0].childNodes[0].nodeValue;	

		//var str=",";
		//alert(str.charCodeAt(0));//(author_transl.charCodeAt(author_transl.length-3));
		/*for(var i=author_transl.length;;i--)
			if(author_transl.charCodeAt(i)<48)
				alert(i);*/
		
		var show_author;
		//alert(xmlHttp);
		if (tagTransl.match("on")=="on")
		{
			var author_transl = xmlHttp.responseXML.getElementsByTagName("Author_Translation")[0].childNodes[0].nodeValue;
			if(document.getElementById("myTranslation").innerHTML=="")
				if(Seite>1)
					document.getElementById("myTranslation").innerHTML = "<a href='http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranslation/%22" + BildName + "%22'><span class='p5'>Translation</span></a>";
				else
					document.getElementById("myTranslation").innerHTML = "<a href='http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranslation/%22" + globalDateiname + "%22/start/%22yes%22'><span class='p5'>Translation</span></a>";			
			if(http!=null)	
			{
				if((Anzeige!=null)&&(Anzeige!="solo_translation"))
				{
					if(Anzeige=="transcription")
						show_author="<br><span class='p3'>(Translated by: " + author_transl +")</span>";
					else
						show_author="<br>";

					if(SwitchLink==true)
						document.getElementById('myLink').innerHTML = "<a href='#' onclick='javascript:klick();'><span class='p5'>Show "+ Anzeige + " of this page</span></a>" + show_author + "<br>";
					else
						document.getElementById('myLink').innerHTML = "<br><span class='p3'>(Translated by: " + author_transl +")</span>";
				}				
				if(Anzeige=="solo_translation")
					document.getElementById('myAuthor').innerHTML = "<br><span class='p3'>(Translated by: " + author_transl +")<br><br></span>";
				http.onreadystatechange = updateNewContent;	
			}
		}
		else
		{
			document.getElementById('myTranslation').innerHTML = "";
		}

		if (tagTransc.match("on")=="on")
		{
			if(document.getElementById('myTranscription').innerHTML=="")
				if(Seite>1)				
					document.getElementById('myTranscription').innerHTML = "<a href='http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranscription/%22" + BildName + "%22'><span class='p5'>Transcription</span></a>";
				else
					document.getElementById('myTranscription').innerHTML = "<a href='http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranscription/%22" + globalDateiname + "%22/start/%22yes%22'><span class='p5'>Transcription</span></a>";

			if(http!=null)			
				http.onreadystatechange = updateNewContent;		
		}
		else
		{
			document.getElementById('myTranscription').innerHTML = "";
		}
		}
	}
}



function GetXmlHttpObject1()
{
//xmlHttp=null;
try
 {
  	xmlHttp=new XMLHttpRequest();
 }
catch (e)
  {
  try
    {
    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
	
return xmlHttp;
}

// *****************
//
function checkTranslationLink(datei)
{
	BildName=datei;
	checkDisplay(datei);
}

function TranscriptionShown(datei)
{
	document.getElementById('myTranscription').innerHTML = "<span class='p6'>Transcription</span>";
}

function TranslationShown(datei)
{
	document.getElementById('myTranslation').innerHTML = "<span class='p3'>Translation</span>";
}

function checkTranscriptionLink(datei)
{	
	BildName=datei;
	checkDisplay(datei);
}

// *******************************************************
// text datei lesen etc.
// *******************************************************

function createRequestObject() 
{

   	var objAjax;

   	var browser = navigator.appName;

   	if(browser == "Microsoft Internet Explorer")
		objAjax = new ActiveXObject("Microsoft.XMLHTTP");
	else

      		objAjax = new XMLHttpRequest();

	

   	return objAjax;

}

// *****************
// der allererste Aufruf von der seite
var firstcall=true;
function getNewContent(parameter,ShowText,NextToImage)
{	
	dateiname=parameter;

	if(dateiname.match("_st")!=null)
	{
		var tmp=dateiname.indexOf("_st");
		dateiname=dateiname.substring(0,tmp);
		dateiname=dateiname+".txt";
	}

	if(ShowText=="transcription")
		Zwischentext="_transl_";
	else	
		Zwischentext="_transcr_";

	http = createRequestObject();

	
	if(NextToImage==false)
		if(ShowText=="translation")
			dateiname=dateiname.replace(/_transc_/, "_transl_");

	var link=("http://www.copyrighthistory.org/htdocs/data/" + ShowText + "/" + dateiname);

	var index=dateiname.indexOf("/",5);
	verzeichnis=dateiname.slice(0,index);

	checkDisplay(verzeichnis); // !!! nach xml parsen wird alles in dieser Fkt. dargestellt
	
	http.open('get',link);

	// *alles* auf utf-8
	//if(dateiname[0]=="i")
	if(navigator.appName != "Microsoft Internet Explorer")
		http.overrideMimeType('text/xml; charset=utf-8'); //charset=ISO-8859-1');	// **************
	//if(dateiname[0]=="d")
	//	http.overrideMimeType('text/xml; charset=x-mac-roman');	
	
	if(NextToImage==true)
	{		
		checkDisplay(verzeichnis);
		FrameImage(link,ShowText);
	}
	else
	{
		checkDisplay(verzeichnis);
		FrameSolo(link,ShowText);
	}

	http.send(null);

   	return false;

}


// *****************
//
function updateNewContent(link,ShowText)
{
	if(http.readyState == 4)
	{	
		if(http.status==404)
		{
			if(Zwischentext=="transc")
			{
				Zwischentext="_transcr_";
				klick();
			}
			else
			{
				SwitchLink=false;
				klick();
				document.getElementById('mySentence').innerHTML = "<span class='p3'>There is no text for this page avaliable.</span>";		
			}	
		}
		if(http.status==200) 
		{
			document.getElementById('mySentence').innerHTML = ("<span class='p3'>" + encode_utf8(http.responseText) + "</span>");
			//ge = document.getElementById('mySentence');
  			//ge.style.display = "block";
  			//ge.innerHTML = ("<span class='p3'>" + encode_utf8(http.responseText) + "</span>");

   		}
	}

}

// *****************
//
function FrameImage(link,ShowText)
{
	if(ShowText=="translation")
		Anzeige="transcription";
	else	
		Anzeige="translation";

	//document.getElementById('myLink').innerHTML = "<a href='#' onclick='javascript:klick();'><span class='p5'>Show " + Anzeige + " of this Page</span></a>";
	//http.onreadystatechange = updateNewContent;
}

function FrameSolo(link,ShowText)
{
	if(ShowText=="translation")
		Anzeige="solo_translation";
	//document.getElementById('myPrinter').innerHTML = "<br><a href='" + link +"' target='blank'><span class='p5'>Printer friendly</span>";
	document.getElementById('myPrinter').innerHTML = "<br><a href=javascript:printText('" + link + "')><span class='p5'>Print view of this page</span> &nbsp;&nbsp;&nbsp; <a href=javascript:printAllText('" + link + "')><span class='p5'>Print view of all pages</span>";	
	http.onreadystatechange = updateNewContent;	
}

// *****************
//
function klick()
{
	if(ShowText=="transcription")
	{
		ShowText="translation";
		Zwischentext="_transl_";
		dateiname=dateiname.replace(/_transc_/, Zwischentext);
	}
	else
	{
		Zwischentext="_transc_";
		ShowText="transcription";
		dateiname=dateiname.replace(/_transl_/, Zwischentext);
	}

	getNewContent(dateiname,ShowText,true);
}

// *****************
//
function ShowSwitchLink(ShowText)
{
	if(ShowText=="translation")
		Anzeige="transcription";
	else	
		Anzeige="translation";
	
	//alert(Transcription);
	if(SwitchLink==true)

   		document.getElementById('myLink').innerHTML = "<a href='#' onclick='javascript:klick();'><span class='p5'>Show " + Anzeige + " of this Page</span></a>";

	//else
	//	document.getElementById('myLink').innerHTML = "";
}
// *****************
//



// *******************************************************
// funktionen fuer kommentare
// *******************************************************

function getNewComContent(parameter)
{
	http = createRequestObject();

   	dateiname=(parameter+"");
	var tempdir=dateiname.substring(0,dateiname.lastIndexOf("_")+1);
	var dir=tempdir.replace(/_com_/, "");

	var link=("http://www.copyrighthistory.org/htdocs/data/commentary/"+dir+"/"+dateiname);
	dateiname=dir;	// unten abgleich
	http.open('get',link);
	//http.overrideMimeType('text/xml; charset=utf-8');
	http.onreadystatechange = updateComNewContent;
	http.send(null);

   	return false;

}



// *********************
//
// *********************
function sanitizeHTML(s) 
{
    var d = document.createElement('div');
    d.appendChild(document.createTextNode(s));
    return d.innerHTML;
}


function updateComNewContent()
{
	if (http.readyState==4)
	{ 
		if(http.status == 200) 
		{
			//document.getElementById('mySentence').innerHTML = encode_utf8(http.responseText);
			var einText = encode_utf8(http.responseText);
			//einText=writeLink();
			//if(navigator.appName == "Microsoft Internet Explorer")
			//	einText = sanitizeHTML(einText);


			einText=comlinks(einText);
			//alert(einText);
			document.getElementById('mySentence').innerHTML = einText;
		}
	}

}



function comlinks(Original)
{
	var faktor=0;
	for(var i=globalCounter-1; i>=0; i--)	// von hinten, da sich position vs. stringlaenge aendert
	{
		var LaengeSuchText = Term[i].length;		
            	var LaengeErsatzText = Link[i].length;

		//alert(i + ": " + Term[i]);
		
		var result=Original.substring(0,PosLink[i]+faktor);
		result += Link[i]+Original.substring(PosLink[i]+LaengeSuchText);
		Original=result;
	}

	return Original;
}

function writeLink(TempTerm,PosTerm)
{		
		//alert(globalCounter + ": " + TempTerm);
		PosLink[globalCounter]=PosTerm;
		Term[globalCounter]=TempTerm;
		Link[globalCounter]=TempTerm.link("http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/ausgabe/%22"+TempTerm+"%22");	
		globalCounter++;
}


// *******************************************************
// menge der seiten checken
// *******************************************************
var which="";
function checkPageNo(str, which)
{
	//alert(str + " "+  which);
	str = str.replace(/.jpg/g,"");
	var rest=str.lastIndexOf("_")+1;
	str = str.slice(rest,str.length)
	rest=0;
	for(var i=0; i<str.length;i++)
	{
		//var no1 = parseInt(str[i]);
		//var no2 = parseInt(str[i+1]);
		if(parseInt(str[i])=='0')
			rest += 1;
		else
			break;
	}
	str = str.slice(rest,str.length);
	if(which=="last")
		document.getElementById('lastpage').innerHTML = parseInt(str,10);
	if(which=="actual")
	{
		document.getElementById('nowpage').innerHTML = parseInt(str,10);
		Seite=str;
	}
}

// **************************************************
// cookie: translation/transcription?
// **************************************************
function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    		{ 
    			c_start=c_start + c_name.length+1; 
    			c_end=document.cookie.indexOf(";",c_start);
    			if (c_end==-1) c_end=document.cookie.length;
    				return unescape(document.cookie.substring(c_start,c_end));
    		} 
  	}
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
	choosen=getCookie('copyright');
	if (choosen!=null && choosen!="")
  	{choosen=Seite;
  		//Seite=choosen;
  	}
  	else 
  	{
  		choosen=Seite;
  		if (choosen!=null && choosen!="")
    		{
    			setCookie('copyright',choosen,365);
    		}
  	}
	alert(choosen);
}

// *******************************************************
// einzelne pdf
// *******************************************************
function printPdf(tempBildname, pfad)
{
	tempBildname = tempBildname.replace(/.jpg/g,".pdf");
	var pdf=pfad+tempBildname;
	document.getElementById('singlepdf').innerHTML = "<a href='"+pdf+"'><span class='p5'>Open printable pdf of this picture (best resolution)</span></a>";
}
// *******************************************************
// einzelne max. bilddatei / texte drucken
// *******************************************************
function printPicture(tempBildname, pfad)
{
	var http= createRequestObject();
	/*var recordid=tempBildname.substring(0,9);
	rest=recordid.lastIndexOf("_"); 
	recordid=recordid.substring(0,rest);

	var bildname=recordid;
	
	for(var i=bildname.length; i<tempBildname.length;i++)
	{
  		if(tempBildname[i]!='0')
    			bildname=bildname.concat(tempBildname[i]);
	}
	bildname = bildname.replace(/.jpg/g,"_st.jpg");*/

	var bild=pfad+tempBildname;//recordid+"/"+bildname;

	http.open('get',bild);
	http.onreadystatechange = function()
	{
		if (http.readyState==4)
		{ 
			if(http.status == 404) 
			{
				bild = bild.replace(/_st.jpg/g,".jpg");
			}
			if(http.status == 200) 
			{
			
			}
		}
		fenster = window.open(bild, "Image", "width=600,height=500,status=yes,scrollbars=yes,resizable=yes,menubar=yes,status=yes");
		
	}
	
	http.send(null);
	fenster.stop();

	//fenster = window.open(bild, "Image", "width=600,height=500,status=yes,scrollbars=yes,resizable=yes,menubar=no,status=yes");
	//fenster.focus();

	//fenster.print(); 
}

// **************************************************
// extrafenster texte/bilder
// **************************************************
linkliste = new Array();
queue = new Array(); 
var httpRequestObjectBusy=false;
var http= createRequestObject();
var AllText="";

function printText(link) 
{
	http.open('get',link);
	http.onreadystatechange = function()
	{
		if (http.readyState==4)
		{ 
			if(http.status == 200) 
			{
				var einText = encode_utf8(http.responseText);
				fenster = window.open("http://www.copyrighthistory.org/leer.html", "Text", "width=600,height=500,status=yes,scrollbars=yes,resizable=yes,menubar=yes,status=yes");
				fenster.focus();
				//fenster.document.write("text/html");
				fenster.document.write(einText);
				//fenster.stop();
				//fenster.print();
			}
			if(http.status == 404)
				alert("There is no text available for this page.");
		}
	}
	http.send(null);
}

function printAllText(originallink)
{
	var index=originallink.lastIndexOf("_")
	var basis=originallink.substring(0,index+1);
	
	for(var i=0; i<NumberOfPages; i++)
	{
		var temp=i+1;
		var link=basis + temp + ".txt";
		ladeTexte(link,temp);
	}
}

function ladeTexte(url,pageno) 
{ 
	if(httpRequestObjectBusy==true) 
	{     
		queue.push(new Array(url));
	}
	else
	{
		httpRequestObjectBusy=true;
		http.open('GET',url,true); 		
		http.send(null);	
		http.onreadystatechange = function()
		{
			if(http.readyState == 4)
			{
				httpRequestObjectBusy=false;			
				var text = "Page " + pageno + "<br><br>" + encode_utf8(http.responseText) + "<br><br>";
				
				if(http.status==404)	
					text= "Page " + pageno + "<br><br>(No Text available for this page.)<br><br>";			

				AllText=AllText.concat(text);
				pageno++;				

				if(queue.length!= 0) 
				{
					var element1 = queue[0][0];
					queue.shift();
					ladeTexte(element1,pageno);  
				}
				if((queue.length== 0)&&(http.readyState==4))
				{
					fenster = window.open("http://www.copyrighthistory.org/leer.html", "Text", "width=600,height=500,status=yes,scrollbars=yes,resizable=yes,menubar=yes,status=yes");
					fenster.document.write(AllText);
					document.close();
					fenster.focus();
					//fenster.stop();
					//fenster.print();
				}
			}
		}   
	} 
}


// *******************************************************
// seite einzeln waehlen
// *******************************************************
var Scriptwahl, NumberOfPages;	//uebergabe image, transl, transc
function selectPageNo(str, tempAnzeige)
{
	str = str.replace(/.jpg/g,"");
	rest=str.lastIndexOf("_")+1; 
	bildname=str;
	str = str.slice(rest,str.length);
	rest=0;
	for(var i=0; i<=str.length;i++)
	{
		if(parseInt(str[i])=='0')
			rest += 1;
		else
			break;
	}  
	Scriptwahl=tempAnzeige;
	str=parseInt(str,10);
	NumberOfPages=str;
	if(str>=2)
		document.getElementById('selectpageno').innerHTML = "<form style='display:inline' name='Formular' action='' onSubmit='return pageinput(bildname)' method='get'><input type='text' size='3' name='inputpageno'><input type='submit' value='Select page'></form>";
}

function pageinput(bildname)
{ 
	// redundant, aber irgendwie uebergabeprobleme
	str=bildname;
	rest=str.lastIndexOf("_")+1; 
	str = str.slice(rest,str.length);
	rest=0;
	for(var i=0; i<str.length;i++)
	{
		if(parseInt(str[i])=='0')
			rest += 1;
		else
			break;
	} 
	str=parseInt(str,10);

	var eingabe=parseInt(document.Formular.inputpageno.value);

	if(document.Formular.inputpageno.value == "")
		alert("You did not enter a page number.");
	else if( eingabe > str)
		alert("There are only " + str + " number of pages.");
	else
	{ 
		var txt=bildname;
		var zahl=document.Formular.inputpageno.value;

		var laenge=zahl.length;
		var index=txt.lastIndexOf("_");
		var bname=txt.slice(0,index+1);
		var rest=txt.slice(index,length);

		temp1="0";temp2="";
		for(i=laenge; i<4; i++)
		{
  			temp2=temp1.concat(temp2);
		}

		zahl=temp2.concat(zahl);
		endung=".jpg";
		bname=bname.concat(zahl);
		bname=bname.concat(endung);
		var ziel = "%22"+bname+"%22";

		if(Scriptwahl=="image")
			document.location="http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showthumb/"+ziel;
		if(Scriptwahl=="translation")
			document.location="http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranslation/"+ziel;
		if(Scriptwahl=="transcription")
			document.location="http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/showTranscription/"+ziel;

		return false;
	}
}


// *******************************************************
// partnerlogos laden
// *******************************************************
function partnerlogos() 
{
	//document.getElementById('partnerlogos').innerHTML = 

	ge = document.getElementById('partnerlogos');
  	ge.style.display = "block";
  	ge.innerHTML = 
	"<center>"+
	"<a href='http://www.bl.uk/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/british_library.jpg' border='0'></a><br><br>"+
	"<a href='http://www.parliament.uk/parliamentary_publications_and_archives/parliamentary_archives.cfm'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/ParliamentArchive.jpg' border='0'></a><br><br>"+
	"<a href='http://www.nationalarchives.gov.uk/ '><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/NationalArchives.jpg' border='0'></a><br><br>"+
	"<a href='http://www.stationers.org/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/StationersComp.jpg' border='0'></a><br><br>"+
	"<a href='http://www.bnf.fr/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/BiblNatdeFrance.jpg' border='0'></a><br><br>"+
	"<a href='http://www.archivesnationales.culture.gouv.fr/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/ArchivesNationalesParis.jpg' border='0'></a><br><br>"+
	"<a href='http://www.archiviodistatovenezia.it/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/VenetianVirtualArchive.jpg' border='0'></a><br><br>"+
	"<a href='http://marciana.venezia.sbn.it/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/BibliotecaMarciana.jpg' border='0'></a><br><br>"+
	"<a href='http://asv.vatican.va/home_en.htm'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/VaticanArchives.jpg' border='0'></a><br><br>"+
	"<a href='http://www.loc.gov/index.html'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/LOC.jpg' border='0'></a><br><br>"+
	"<a href='http://www.copyright.gov/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/USCopyrightOffice.jpg' border='0'></a><br><br>"+
	"<a href='http://www.onb.ac.at/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/ONB.jpg' border='0'></a><br><br>"+
	"<a href='http://www.slub-dresden.de/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/SLUB.jpg' border='0'></a><br><br>"+
	"<a href='http://www.mpier.uni-frankfurt.de/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/MaxPlanckInst.jpg' border='0'></a><br><br>"+
	"<a href='http://www.bsb-muenchen.de/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/BSB.jpg' border='0'></a><br><br>"+
	"<a href='http://www.hab.de/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/HAB.jpg' border='0'></a><br><br>"+
	"<a href='http://www.dla-marbach.de/startseite/index.html'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/DLA.jpg' border='0'></a><br><br>"+
	"<a href='http://staatsbibliothek-berlin.de/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/Berlin.jpg' border='0'></a><br><br>"+
	"<a href='http://www.is.bham.ac.uk/index.shtml'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/Birmingham.jpg' border='0'></a><br><br>"+
	"<a href='http://scd.univ-poitiers.fr/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/Poitiers.jpg' border='0'></a><br><br>"+
	"<a href='http://www.utexas.edu/'><img src='http://www.copyrighthistory.org/database/identityhtml/partnerlogos/Texas.jpg' border='0'></a><br>"+
	"</center>"+
	"<br>";
}

// *******************************************************
// interne links parsen
// *******************************************************

var txt=" ";

function InternalLink(url) 
{
	//alert(url);
        var httpRequest;
	url=("http://www.copyrighthistory.org/htdocs/data/identity/" + url + ".xml");
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');

    }

function alertContents(httpRequest) 
{
	try 
	{
		if (httpRequest.readyState == 4) 
		{
                	if (httpRequest.status == 200) 
			{
                    		var tempId=httpRequest.responseXML.getElementsByTagName("Identifier")[0].childNodes[0].nodeValue;
				var tempTitle=httpRequest.responseXML.getElementsByTagName("Short_Title")[0].childNodes[0].nodeValue;
				
				tempTitle = tempTitle.replace(/\r/g,"");
				tempTitle = tempTitle.replace(/\r\n/g,"");
				tempTitle = tempTitle.replace(/\n/g,"");
				tempTitle = tempTitle.replace(/\t/g,"");

				if(tempTitle.charAt(0)=="")
					tempTitle="(no short title available)";

				var tempLink="<a href='http://www.copyrighthistory.org/cgi-bin/kleioc/0010/exec/ausgabe/%22" + tempId + "%22'>"
				tempId=tempId.slice(tempId.indexOf("_")+1, tempId.length-2);

				txt += tempLink + "<span class='p5'>" + tempId + ": " + tempTitle + "</span></a><br>";
				document.getElementById("myInternal").innerHTML=txt;
                	} 
			//else 
			//{
                    		//alert('There was a problem with the request.');
                	//}
            	}
        }
        catch( e ) 
	{
            alert('Caught Exception: ' + e.description);
        }

    }


// *******************************************************
// text encoding fuer sonderzeichen
// *******************************************************
function encode_utf8(rohtext) 
{
	//rohtext=escape(rohtext);
	//rohtext = rohtext.replace(/%uFFFD/g,"\'");

	//rohtext=unescape(rohtext);
	// dient der Normalisierung des Zeilenumbruch
	rohtext = rohtext.replace(/\r/g,"<br>");
	rohtext = rohtext.replace(/\r\n/g,"<br>");
	rohtext = rohtext.replace(/\n/g,"<br>");
	rohtext = rohtext.replace(/<p>/g, "<span class='p3'>");
	rohtext = rohtext.replace(/<\/p>/g, "</span><br>");
	rohtext = rohtext.replace(/<br><br>/g,"<br>");
	rohtext = rohtext.replace(/<tab>/g,"&nbsp;&nbsp;&nbsp;");
	rohtext = rohtext.replace(/<center>/g,"<center><span class='p3'>");
	rohtext = rohtext.replace(/<\/center>/g,"</span></center>");
	rohtext = rohtext.replace(/<italic>/g,"<i><span class='p3'>");
	rohtext = rohtext.replace(/<\/italic>/g,"</span></i>");
	rohtext = rohtext.replace(/amp;/g,"");

	//return rohtext;
	//rohtext=b64t2d(rohtext);
	//rohtext=encode_base64(rohtext);

	var j=0;
	var TempTerm, TempLink;
	var utftext = "";

	for(var i=0; i<rohtext.length; i++)
	{
		// in gleicher schleife: x_ parsen
		if(rohtext.charAt(i)=="_")
		{
			if((rohtext.charAt(i-1)=="i")||(rohtext.charAt(i-1)=="d")||(rohtext.charAt(i-1)=="f"))
			{
				TempTerm=rohtext.substr(i-1,7);
				TempTerm = TempTerm.replace(/\)/,"");
				TempTerm = TempTerm.replace(/ /,"");
				TempTerm = TempTerm.replace(/\,/,"");
				TempTerm = TempTerm.replace(/\;/,"");
				TempTerm = TempTerm.replace(/</,"");
				TempTerm = TempTerm.replace(/\./,"");
				if(TempTerm!=dateiname)
				{
					var Pos=i-1;
					writeLink(TempTerm, Pos)
				}
			}
			if((rohtext.charAt(i-1)=="k")||(rohtext.charAt(i-1)=="s"))
			{
				TempTerm=rohtext.substr(i-2,8);
				TempTerm = TempTerm.replace(/\)/,"");
				TempTerm = TempTerm.replace(/ /,"");
				TempTerm = TempTerm.replace(/\,/,"");
				TempTerm = TempTerm.replace(/\;/,"");
				TempTerm = TempTerm.replace(/</,"");
				TempTerm = TempTerm.replace(/\./,"");
				if(TempTerm!=dateiname)
				{
					var Pos=i-2;
					writeLink(TempTerm, Pos)
				}
			}
		}

		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(i);
		utftext += String.fromCharCode(c);
		//utftext+=" | " + c + " " + rohtext.charAt(i) + " | ";
		// alle Zeichen von 0-127 => 1byte
		/*if (c<128)
			utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)) 
		{
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);
		}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else 
		{
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);
			utftext += "<br>";
		}*/
	}	
	//utftext = rohtext.replace(/\+AJ8\-/g,"&uuml;");
	//utftext=rohtext;
	return utftext;
}



// ***********************
function b64arrays() 
{
	var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789öäüßÖÄÜ +/';
	b64 = [];f64 =[];
	for (var i=0; i<b64s.length ;i++) 
	{
		b64[i] = b64s.charAt(i);
		f64[b64s.charAt(i)] = i;
	}
}

function encode_base64(d) 
{
	var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789öäüßÖÄÜ +/';
	b64 = [];f64 =[];
	for (var i=0; i<b64s.length ;i++) 
	{
		b64[i] = b64s.charAt(i);
		f64[b64s.charAt(i)] = i;
	}


	var r=[]; var i=0; var dl=d.length;
	// Padding vorbereiten
	if ((dl%3) == 1) {
		d[d.length] = 0; d[d.length] = 0;}
	if ((dl%3) == 2)
		d[d.length] = 0;
	// Konvertieren
	while (i<d.length)
	{
		r[r.length] = b64[d[i]>>2];
		r[r.length] = b64[((d[i]&3)<<4) | (d[i+1]>>4)];
		r[r.length] = b64[((d[i+1]&15)<<2) | (d[i+2]>>6)];
		r[r.length] = b64[d[i+2]&63];
		if ((i%57)==54)
		r[r.length] = "\n";
		i+=3;
	}
	// padding abschließen
	if ((dl%3) == 1)
		r[r.length-1] = r[r.length-2] = "=";
	if ((dl%3) == 2)
		r[r.length-1] = "=";
	// Array in text zusammenführen
	var t=r.join("");
	return t;
}

function b64t2d(t) 
{
	var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789öäüßÖÄÜ +/';
	b64 = [];f64 =[];
	for (var i=0; i<b64s.length ;i++) 
	{
		b64[i] = b64s.charAt(i);
		f64[b64s.charAt(i)] = i;
	}

	var d=[]; var i=0;
	// zur decodierung die Umbrueche killen
	t=t.replace(/\n|\r/g,""); t=t.replace(/=/g,"");
	while (i<t.length)
	{
		d[d.length] = (f64[t.charAt(i)]<<2) | (f64[t.charAt(i+1)]>>4);
		d[d.length] = (((f64[t.charAt(i+1)]&15)<<4) | (f64[t.charAt(i+2)]>>2));
		d[d.length] = (((f64[t.charAt(i+2)]&3)<<6) | (f64[t.charAt(i+3)]));
		i+=4;
	}
	if (t.length%4 == 2)
		d = d.slice(0, d.length-2);
	if (t.length%4 == 3)
		d = d.slice(0, d.length-1);
	return d;
}


// *******************************************************
// eingebetteter html Code fuer Google Suche
// *******************************************************
function includeGoogleAnalytics()
{
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		 
		 try {
		 var pageTracker = _gat._getTracker("UA-9807136-1");
		 pageTracker._trackPageview();
		 } catch(err) {}	
}

