// KABIKADJ (c) Vlad ATANASIU 2001
// JavaScript handling of catalog files

// Variabeln
NrImages = new Array();
NameImages = new Array();
tempArray = new Array();
var data = "";
var dataBis = "";
var dataRem = "";
var dataRemBis = "";
var descriptor = 0;
var dataOrig = "";
var dataTrans = "";
var end = "";
var i = 0;
var j = 0;
var jour = "";
var k = 0;
var m = "";
var mask = "";
var mois = "";
var n= "";
var nrElements = 0;
var rows = 0;
var start = "";
var strImages = "";
var temp = 0;

// --------------------------------------------------------------
// ecrire les donnees de la fiche descriptive du ms
// --------------------------------------------------------------

function Output(descriptor) {
    data = Catalog[MsNr][descriptor];
    dataRem = "";
    dataRemBis = "";
    if (data.charAt(data.length-1) == ")") {					// Remarks schneiden
        dataRem = data.substring(data.lastIndexOf("(")-1,data.length);
        data = data.substring(0,data.lastIndexOf("(")-1);
        if (dataRem != "" && data !="") { dataRem = "<br>" + dataRem };
    }

    if ( data == "" ) { return };
    with (document)  {

        if (descriptor == NomCollFullOrig || 
            descriptor == CoteMsOrig || 
            descriptor == VilleCollOrig || 
            descriptor == AuteurOrig || 
            descriptor == TitreOrig || 
            descriptor == LieuCopieVilleOrig || 
            descriptor == CopisteOrig || 
            descriptor == DedicataireOrig ) {					// Transliteration owning fields

            if ( data == "*" || data == "?" || data == "-")					// 1. number original items
                write(Dictionary[data] + dataRem)
            else
                write(NumberListData(data) + dataRem);

            dataBis = Catalog[MsNr][descriptor + 1];					// 2. atempt transliteration (write if translation not equal to original)
            if ( dataBis != "-" && dataBis != data) {
                if (dataBis.charAt(dataBis.length-1) == ")") {				// Remarks schneiden
                    dataRemBis = dataBis.substring(dataBis.lastIndexOf("(")-1,dataBis.length);
                    dataBis = dataBis.substring(0,dataBis.lastIndexOf("(")-1);
                        if (dataRemBis != "" && dataBis !="") { dataRemBis = "<br>" + dataRemBis };
                }
                write("<br>" + NumberListData(dataBis) + dataRemBis);
            }

            if (descriptor == NomCollFullOrig || 
                descriptor == TitreOrig ) {						// 3. atempt translation (write if translation not equal to original & if present in dictionary)
                if ( data == "*" || data == "?" || data == "-") {
                }
                else if ( typeof( Dictionary[data] ) != "undefined" && Dictionary[data] != data ) {
                    dataOrig = data + " ; ";
                    dataTrans = "";
                    while(dataOrig.indexOf(" ; ") != -1) {
                        temp = dataOrig.substring(0,dataOrig.indexOf(" ; "));
                        dataOrig = dataOrig.substring(dataOrig.indexOf(" ; ")+3,dataOrig.length);
                        if ( typeof(Dictionary[temp]) != "undefined" )
                            dataTrans = dataTrans + " ; " + Dictionary[temp];
                        else
                            dataTrans = dataTrans + " ; " + Dictionary["*"];
                    }
                    dataTrans = dataTrans.substring(3,dataTrans.length);
                    write("<br>" + NumberListData(dataTrans));
                }
            }
        }

        else if ( descriptor == PaysColl ) {						// ------------ Fields mit fixed-single Eintrage possibility
            write(Dictionary[data] + dataRem);
        }

        else if ( descriptor == LieuVraisembla || 
        descriptor == LieuCopiePays ||
        descriptor == Langue ||
        descriptor == SupportMatiere ||
        descriptor == SupportCouleur ||
        descriptor == SupportEpaiss ||
        descriptor == SupportVergDisp ||
        descriptor == SupportVergDens ||
        descriptor == RelMatiere ||
        descriptor == RelColPlate ||
        descriptor == RelColSpine ||
        descriptor == QualiteScript ||
        descriptor == StyleTitrage ||
        descriptor == StyleTexte ||
        descriptor == ColTexte ||
        descriptor == ColTitrage ||
        descriptor == Descendante ||
        descriptor == NonArabicScripts ) {						// ------------ Fields mit fixed-multiple Eintrage possibility
            k = 1;
            temp = data + " ;";
            // sipmle Data
            if (data.indexOf(" ;") == -1)
                write(Dictionary[data]);
            else {
                // multiple Data
                while (temp.indexOf(" ;") != -1)
                {
                    data = temp.substring(0,temp.indexOf(" ;"));
                    if (data.length+2 == temp.length)
                        del = "";
                    else
                        del = "<br>";                
                    write(k + ". " + Dictionary[data] + del);
                    temp = temp.substring(temp.indexOf(" ;")+3,temp.length);
                    k++;
                }
            }
            write(dataRem);
        }

        else if ( descriptor == Repros ) {						// ------------ Fields with handling of the data
            if ( data.charAt(0) == "[" ) {
                write("النسخة کلها." + dataRem);
                strImages = data.substring(1,data.indexOf("]"));
                NameImgFiles();
            }
            else {
                strImages = data;
                NameImgFiles();
                data = "";
                for ( temp = 0; temp<NameImages.length; temp++ ) {
                    data = data + NameImages[temp] + " ; ";
                    data = data.replace(/<br>/," ");
                }
                data = data.substring(0,data.length-2);
                write(data + dataRem);
            }
        }

        else if (descriptor == DateRecordY || 
            descriptor == DateEquivAdY) {						// ------------ 
            dataRem = "";
            dataArray = new Array();
            for (k=4; k>=0; k--) {
                if (!(k == 0 && descriptor == DateEquivAdY)) {
                    i = 0;
                    data = Catalog[MsNr][descriptor+k-1];
                    if (data.charAt(data.length-1) == ")" && data.indexOf(" (") != -1) {	// Rems ausschneiden
                        if (dataRem =="")
                            del = "";
                        else
                            del = " ; ";
                        dataRem = dataRem + del + data.substring(data.lastIndexOf("(")+1, data.lastIndexOf(")"));
                        data = data.substring(0, data.lastIndexOf("(")-1);
                    }

                    data = data + " ;";							// data in array verteilen
                    while (data.indexOf(" ;") != -1) {
                        del = "";
                        if (!dataArray[i])
                            dataArray[i]="";
                        temp = data;
                        data = data.substring(0,data.indexOf(" ;"));

                        if ( descriptor == DateRecordY && data != "-" ) {			// le nom du jour & mois marquiren
                            if ( k == 4 ) { data = data + "<N>" };
                            if ( k == 2 ) { data = data + "<M>" };
                        }
                        
                        if ( data == "-" && k != 1) { data = "" };				// DICTIONNARY
                            if ( k == 0 && descriptor == DateRecordY && data == "AHq" ) {	// calendar sys AHq

                                if ( dataArray[i].indexOf("<N>") != -1 ) {				// jours de la semaine
		    jour = dataArray[i].substring(0,dataArray[i].indexOf("<N>"));
		    dataArray[i] = dataArray[i].substring(dataArray[i].indexOf("<N>")+3,dataArray[i].length);

		    if ( jour.indexOf("FA") != -1 ) {
                                        jour = jour.charAt(0);
		        while (jour.search(/\d+/) != -1)  {
		            jour = jour.replace(/1/,Dictionary["Day1persian"]);
		            jour = jour.replace(/2/,Dictionary["Day2persian"]);
		            jour = jour.replace(/3/,Dictionary["Day3persian"]);
		            jour = jour.replace(/4/,Dictionary["Day4persian"]);
		            jour = jour.replace(/5/,Dictionary["Day5persian"]);
		            jour = jour.replace(/6/,Dictionary["Day6persian"]);
		            jour = jour.replace(/7/,Dictionary["Day7persian"]);
		        }
                                    }
		    else {
		        while (jour.search(/\d+/) != -1)  {
		            jour = jour.replace(/1/,Dictionary["Day1arabic"]);
		            jour = jour.replace(/2/,Dictionary["Day2arabic"]);
		            jour = jour.replace(/3/,Dictionary["Day3arabic"]);
		            jour = jour.replace(/4/,Dictionary["Day4arabic"]);
		            jour = jour.replace(/5/,Dictionary["Day5arabic"]);
		            jour = jour.replace(/6/,Dictionary["Day6arabic"]);
		            jour = jour.replace(/7/,Dictionary["Day7arabic"]);
		        }
		    }
		    dataArray[i] = jour + dataArray[i];
		}
		                    
                                if ( dataArray[i].indexOf("<M>") != -1 ) {				// mois
		    m = dataArray[i].substring(dataArray[i].indexOf("<M>")+3,dataArray[i].length);
		    dataArray[i] = dataArray[i].substring(0,dataArray[i].indexOf("<M>"));
		    mois = dataArray[i].substring(dataArray[i].lastIndexOf(" ")+1,dataArray[i].length);
		    n = dataArray[i].substring(0,dataArray[i].lastIndexOf(" ")+1);

		    while ( mois.search(/\d+/) != -1 ) {
		        mois = mois.replace(/\b1\b/,Dictionary["Month1arabic"]);
		        mois = mois.replace(/\b2\b/,Dictionary["Month2arabic"]);
		        mois = mois.replace(/3/,Dictionary["Month3arabic"]);
		        mois = mois.replace(/4/,Dictionary["Month4arabic"]);
		        mois = mois.replace(/5/,Dictionary["Month5arabic"]);
		        mois = mois.replace(/6/,Dictionary["Month6arabic"]);
		        mois = mois.replace(/7/,Dictionary["Month7arabic"]);
		        mois = mois.replace(/8/,Dictionary["Month8arabic"]);
		        mois = mois.replace(/9/,Dictionary["Month9arabic"]);
		        mois = mois.replace(/\b10\b/,Dictionary["Month10arabic"]);
		        mois = mois.replace(/\b11\b/,Dictionary["Month11arabic"]);
		        mois = mois.replace(/\b12\b/,Dictionary["Month12arabic"]);
		    }                    
		    dataArray[i] = n + mois + m;
		}
	            }
		                
                            if ( k == 0 && descriptor == DateRecordY && data != "AHq") {		// sys autre que AH qamarî
    	                dataArray[i] = dataArray[i].substring(0,dataArray[i].lastIndexOf(" ")) + "<##>" + dataArray[i].substring(dataArray[i].lastIndexOf(" ")+1,dataArray[i].length);	// zwischen YY & Sys als space merken
		                    
		if (dataArray[i].indexOf("<N>") != -1)				// nom du jour
		    dataArray[i] = dataArray[i].replace(/<N>\s/,"th<##>day<##>of<##>the<##>week<##>");
		                    
		while (dataArray[i].indexOf(" ") != -1)				// spaces durch slash changen
    		    dataArray[i] = dataArray[i].replace(/ /,"<#>");
		while (dataArray[i].indexOf("<#>") != -1)
    		    dataArray[i] = dataArray[i].replace(/<#>/,"/");
    		                
		while (dataArray[i].indexOf("<##>") != -1)			// als space markierte plaetze spacen
    		    dataArray[i] = dataArray[i].replace(/<##>/," ");
    	            }

	            if ( k == 4 && descriptor == DateEquivAdY && data != "" ) {		// jours de la semaine AD
		while (data.search(/\d+/) != -1) {
		    data = data.replace(/1/,Dictionary["Day1arabic"]);
		    data = data.replace(/2/,Dictionary["Day2arabic"]);
		    data = data.replace(/3/,Dictionary["Day3arabic"]);
		    data = data.replace(/4/,Dictionary["Day4arabic"]);
		    data = data.replace(/5/,Dictionary["Day5arabic"]);
		    data = data.replace(/6/,Dictionary["Day6arabic"]);
		    data = data.replace(/7/,Dictionary["Day7arabic"]);
		}
	            }
		
                            if ( k == 2 && descriptor == DateEquivAdY  && data != "" ) {		// mois AD
		while ( data.search(/\d+/) != -1 ) {
		    data = data.replace(/\b1\b/,Dictionary["Month1latinArabic"]);
		    data = data.replace(/\b2\b/,Dictionary["Month2latinArabic"]);
		    data = data.replace(/3/,Dictionary["Month3latinArabic"]);
		    data = data.replace(/4/,Dictionary["Month4latinArabic"]);
		    data = data.replace(/5/,Dictionary["Month5latinArabic"]);
		    data = data.replace(/6/,Dictionary["Month6latinArabic"]);
		    data = data.replace(/7/,Dictionary["Month7latinArabic"]);
		    data = data.replace(/8/,Dictionary["Month8latinArabic"]);
		    data = data.replace(/9/,Dictionary["Month9latinArabic"]);
		    data = data.replace(/\b10\b/,Dictionary["Month10latinArabic"]);
		    data = data.replace(/\b11\b/,Dictionary["Month11latinArabic"]);
		    data = data.replace(/\b12\b/,Dictionary["Month12latinArabic"]);
		}
	            }

                            if ( data == "AHq" || data == "AHsh")				// date system
                                data = Dictionary[data];
                            if ( data != "" )
                                del = " ";
                            dataArray[i] = dataArray[i] + data + del;
                            data = temp.substring(temp.indexOf(" ;")+3, temp.length);
                            i++;
                        }
                    }
                
                    if ( k == 0 && descriptor == DateEquivAdY ) {				// calendrier system schrebien
                        for ( i=0; i<dataArray.length; i++ ) {
                            if ( dataArray[i].charAt(dataArray[i].length-2) == "-" )
                                del = "";
                            else
                                del = " م";
                            dataArray[i] = dataArray[i] + del;
                        }
                    }
                }

            if ( dataArray.length>1 )						// daten ausputten
                del = "<br> ";
            k = 1;
            for ( i = 0; i < dataArray.length; i++ ) {
                if ( dataArray[i].charAt(0) == "*" || dataArray[i].charAt(0) == "?" || dataArray[i].charAt(0) == "-" )
                    dataArray[i] = Dictionary[dataArray[i].charAt(0)];
                if ( i == dataArray.length-1 )
                    del = "";
                if ( dataArray.length == 1 )
                    write(dataArray[i]+del);
                else
                    write(k + ". " + dataArray[i]+del);
                k = k + 1;
            }
            if ( dataRem != "" )
                write("<br>("+dataRem+")");
        }

        else if ( descriptor == DateVraisembla ) {					// ------------ 
            if ( data == "*" || data == "?" || data == "-" )
                data = Dictionary[data];
            else if ( data.charAt(0) == "<" )
                data = data.substring( 1, data.length-1 ) + " ق‌م";
            else if ( data.indexOf("-") != -1 )
                data = data.replace( /-/, "–" );
            write(data + dataRem);
        }

        else if (descriptor == SupportFils) {					// ------------ 
            if ( data != "-" && data != "*" )
            {
	   // here handling of display der data dieses field
	   // replace , > _|_
	   // replace ( > _(_
                data = data + " mm";
            }
            if ( data == "-" || data == "*") { data = Dictionary[data] }
            else
	   data = Dictionary["not visible"];
            write(data + dataRem);
        }

       else if ( descriptor == Cahiers ) {						// ------------ 
            if ( data == "-" || data == "?" || data == "*")
                data = Dictionary[data];
            else if (data.indexOf("; ") != -1) {
                data = NumberListData(data);
                while(data.indexOf("<br>") != -1)
                    data = data.replace(/<br>/," دوبرگی#dummy#");
                while(data.indexOf("#dummy#") != -1)
                    data = data.replace(/#dummy#/,"<br>");
                while(data.indexOf("0 دوبرگی") != -1)
                    data = data.replace(/0 دوبرگی/,"يک⁬برگی");
            }
            write(data + dataRem);
        }

        else if ( descriptor == DimSuppH || 
            descriptor == DimTexteH ) {						// ------------ 
            if ( data == "*" || data == "?" || data == "-" )
                write(Dictionary[data]);
            else {
                if (descriptor == DimSuppH) {k = 3};					// Vorbereiten
                if (descriptor == DimTexteH) {k = 2};
                var inch = (0.03937)*100;
                data = "";
                dataRem = "";
                dataDim = new Array();
                for(i=0;i<k;i++) {
                    dataDim[i] = new Array();
                    dataDim[i][0] = new Array();
                }
            
                dataDim[0][0][0] = Catalog[MsNr][descriptor];				// Aufladen
                if (k == 2 || k == 3)
                    dataDim[1][0][0] = Catalog[MsNr][descriptor+1];
                if (k == 3)
                    dataDim[2][0][0] = Catalog[MsNr][descriptor+2];
            
                for( i = 0; i < k; i++) {						// Remarks ausschneiden
                    if (dataDim[i][0][0].charAt(dataDim[i][0][0].length-1) == ")" && dataDim[i][0][0].indexOf(" (") != -1) {
                         if (dataRem == "")
                             del = "";
                         else
                             del = " ; ";
                         dataRem = dataRem + del + dataDim[i][0][0].substring(dataDim[i][0][0].lastIndexOf("(")+1, dataDim[i][0][0].lastIndexOf(")"));
                         dataDim[i][0][0] = dataDim[i][0][0].substring(0, dataDim[i][0][0].lastIndexOf("(")-1);
                    }
                }

                var i = 0;								// auf Multiple eintraege pruefen
                for( i = 0; i < k; i++) {
                    var j = 0;
                    temp = dataDim[i][0][0];
                    while (temp.indexOf(";") != -1) {
                        dataDim[i][j] = new Array();                        dataDim[i][j][0] = temp.substring(0,temp.indexOf(";")-1);			// cm
                        if (dataDim[i][j][0] != "-" && dataDim[i][j][0] != "*")			// inch
                            dataDim[i][j][1] = (Math.round(dataDim[i][j][0].replace(/,/,".")*inch))/10;
                        else {
                            if (dataDim[i][j][0] == "-")
                                dataDim[i][j][1] = "-";
                            else
                                dataDim[i][j][1] = "*";
                        }
                        temp = temp.substring(temp.indexOf("; ")+2,temp.length);
                        j++;
                        dataDim[i][j] = new Array();
                    }
                    dataDim[i][j][0] = temp;
                    if (dataDim[i][j][0] != "-" && dataDim[i][j][0] != "*")
                        dataDim[i][j][1] = (Math.round(dataDim[i][j][0].replace(/,/,".")*inch))/10;
                    else  {
                        if (dataDim[i][j][0] == "-")
                            dataDim[i][j][1] = "-";
                        else
                            dataDim[i][j][1] = "*";
                    }
                }
            
                len = j;								// Daten ausputten
                i = 0;
                n = 1;

                for( j = 0; j <= len; j++) {						// cm
                    if (k == 3)
        	        data = dataDim[0][j][0] + " × " + dataDim[1][j][0] + " × " + dataDim[2][j][0] + " سم";
                    if (k == 2)
        	        data = dataDim[0][j][0] + " × " + dataDim[1][j][0] + " سم";
                    if (len != 0)
                       write(n + ". " + data + "<br>");
                    else
                       write(data + "<br>");
                    n = n + 1;
                }
    
                n = 1;								// inch
                write("<small>");
                for(j=0;j<=len;j++) {
            	    if (k == 3)
            	        data = dataDim[0][j][1] + " × " + dataDim[1][j][1] + " × " + dataDim[2][j][1] + " انچ";
	    if (k == 2)
            	        data = dataDim[0][j][1] + " × " + dataDim[1][j][1] + " انچ";
            	    if (j != len)
            	        data = data + "<br>";
                    if (len != 0)
                        write(n + ". " + data);
                    else
                        write(data + "<br>");
                    n = n + 1;
                }
                write("</small>");
            }

            if (dataRem != "")
                write("<br>(" + dataRem + ")");
        }

        else if (descriptor == Poids) {						// ------------ 
            var ounces = (0.035274)*100;
            if (data != "-" && data != "?" && data != "*") {
                write(data + " گرام <small>/ ");
    	  data = (Math.round(Catalog[MsNr][descriptor].replace(/,/,".")*ounces))/100;
                write(data + " اونس</small>" + dataRem);
            }
            else
                write(Dictionary[data]);
        }        
        
        else if (descriptor == RemRefs ||
        descriptor == RemId ||
        descriptor == RemCodi ||
        descriptor == RemPaleo) {						// ------------ 
            if (data != "-") {
                write("<tr><td colspan=2 class=\"descriptor-arabic\">&nbsp;ملاخظات : ");
	  write("</td></tr><tr><td></td><td class=\"data\">&nbsp;");
                if ( data == "*" ) { data = Dictionary[data] }
                write(data + dataRem);
	  writeln("</td></tr>");
            }
        }
        
        else {								// ------------ 
            if ( typeof( Dictionary[data] ) != "undefined" )
                data = Dictionary[data];
            else if (data.indexOf("; ") != -1)
                data = NumberListData(data);
            write(data + dataRem);
        }
    }
}

// --------------------------------------------------------------
// multiple Eintrage in data field in numbered List transformieren
// --------------------------------------------------------------

function NumberListData(list) {
    list = " ; " + list;
    k = 0;
    while(list.indexOf(" ; ") != -1) {
        k++;
        temp = "<br>" + k + ". ";
        list = list.replace(/;/,temp);
    }
    list = list.substring(list.indexOf(".")+2,list.length);
    if ( k != 1 ) { list = "1. " + list + "<br>"; }
    return list;
}

// --------------------------------------------------------------
// die Namen der img files extrahieren
// --------------------------------------------------------------

function NameImgFiles() {
    var mem = strImages;
    strImages = strImages + ",";
    i = 0;
    while (strImages) {
        end = strImages.indexOf(",");
        NrImages[i] = strImages.slice(0,end);

        // Img-names human freundlich machen
        n = NrImages[i]

        if ( n.charAt(0) != "_" )
        {
        // binding
        n = n.replace(/b0/," خارج ");
        n = n.replace(/b1/," داخل  ");
        n = n.replace(/fr/," رو ");
        n = n.replace(/bk/," پشت ");
        n = n.replace(/sp/," تيرهپشت ");
        n = n.replace(/fl/," ضربه ");
        n = n.replace(/hd/," سار ");
        n = n.replace(/tl/," ذيل ");
        n = n.replace(/fe/," كنار ");
        n = n.replace(/ad/," اضافي ");

        // paper
        if ( n.search(/^p\d+/) != -1 ) {
            mask = /.(\d+)(\w+)/;
            mask.exec(n);
            n = "ساخت كغاز<BR>" + RegExp.$2 + " جزء " + RegExp.$1;
        }
        if ( n.search(/^p/) != -1 )
            n = n.replace(/^p/,"ساخت كغاز<BR>");

        // color
        n = n.replace(/^c/,"كنترله رنگ<BR>");

        // folio
        n = n.replace(/fx/," ب معلوم غير ");
        n = n.replace(/fi/," ب اگهي ");
        n = n.replace(/f/," ب ");
        n = n.replace(/r/," ر ");
        n = n.replace(/v/," پ ");
        n = n.replace(/999/," اخار ");
        n = n.replace(/000/," اوال ");
        n = n.replace(/_/,"-");
        if ( n.indexOf("ساخت كغاز") == -1 && n.search(/\d+$/) != -1 ) {
            mask = /(\w.+)(\d+$)/;
            mask.exec(n);
            n = RegExp.$1 + "<br>جزء " + RegExp.$2;
        }
        while ( n.indexOf(" 0") != -1 )
            n = n.replace(/ 0/," ");
        }
        NameImages[i] = n.toLowerCase();

        start = end;
        end = strImages.length
        strImages = strImages.substr(start+2,end-1);
        i++;
    }
    strImages = mem;
}

// --------------------------------------------------------------
// das link zum schreiben der Medium Img bande
// --------------------------------------------------------------

function MediImg(look) {
    NameImgFiles();
    var i = 0;
    var j = 0;
    var len = NrImages.length;

    i = screen.availWidth/2 - 312;
    MediWindow =
    window.open("", "MediumImages", "innerHeight=675,innerWidth=600,height=700,width=625,screenX="+i+",screenY=0,left="+i+",top=0,resizable=yes,scrollbars=yes,status=yes");
    MediWindow.focus();
    with (MediWindow.document) {
        writeln("<html><head>");
        writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
        writeln("<meta name=\"Author\" content=\"Vlad ATANASIU\">");
        writeln("<title>eMss:" + Catalog[MsNr][NomCollPart] + " ");

        // in case Cote=ArabicScript, for LatinUser Cote in transliteration displayen
        if (Catalog[MsNr][CoteMsTranslit] != "-")
            write(Catalog[MsNr][CoteMsTranslit]);
        else
            write(Catalog[MsNr][CoteMsOrig]);

        writeln("</title>");
        
        writeln("<script type=\"text/jscript\">");
        writeln("<!--");
        writeln("var loupeOn = 0;");
        writeln("var loupeH = 150;");
        writeln("var loupeW = 200;");
        writeln("var loupeMag = 1600 / 600;");				// Vergrosserungsfaktor (1600 Hohe der Coolpix Fine images; 600 = fixed Hohe des mediImg)
        writeln("// fur Netscape bereiten");

        writeln("function Loupe() {");
            writeln("if (loupeOn == 0) {");
                   writeln("document.getElementsByTagName(\"body\")[0].appendChild(document.createElement(\"img\"));");
                   writeln("var LoupeImg = document.getElementsByTagName(\"body\")[0].lastChild;");
                   writeln("with (LoupeImg) {");
                          writeln("setAttribute(\"src\", \"../IMAGES/MAXI/\"+look.toUpperCase()+\".JPG\");");
                          writeln("style.position = \"absolute\";");
                   writeln("}");
                   writeln("loupeOn = 1;");
                   writeln("LoupeMove();");
            writeln("}");
            writeln("else {");
                   writeln("document.getElementsByTagName(\"body\")[0].removeChild(document.getElementsByTagName(\"body\")[0].lastChild);");
                   writeln("loupeOn = 0;");
            writeln("}");
        writeln("}");

        writeln("function LoupeMove() {");
               writeln("if (loupeOn == 1) {");
                      writeln("var LoupeImg = document.getElementsByTagName(\"body\")[0].lastChild;");
                      writeln("var mediY = window.event.offsetY - loupeH / (loupeMag*2);");
                      writeln("var mediX = window.event.offsetX - loupeW / loupeMag;");
                      writeln("var maxiY = mediY*(1-loupeMag) - loupeH*(1-1/loupeMag)/2;");
                      writeln("var maxiX = mediX*(1-loupeMag) - loupeH*(1-1/loupeMag) - loupeW/2 + document.body.scrollLeft;");
                      writeln("status = Math.floor(mediX*loupeMag + loupeW / loupeMag + 128)+\" x / \"+Math.floor(mediY*loupeMag + loupeH / (loupeMag*2) + 50) + \" y (+-3px)\";");
                      writeln("with (LoupeImg) {");
                          writeln("style.top = maxiY + 25 + \"px\";");
                          writeln("style.left = maxiX + 25 + \"px\";");			// dist to cursor - right margin loupe (a 45 il est a 10px; decrease if you want it further)
                            writeln("style.clip = \"rect(\"+mediY*loupeMag+\"px \"+(mediX*loupeMag+loupeW*1.5)+\"px \"+(mediY*loupeMag+loupeH)+\"px \"+(mediX*loupeMag+loupeW/2)+\"px)\";");
                      writeln("}");
               writeln("}");
        writeln("}");
        writeln("// -->");
        writeln("</script>");

        writeln("<script type=\"text/javascript\">");
        writeln("<!--");

        writeln("function MaxiImg()");
        writeln("{");

            writeln("i = screen.availWidth - 10;");
            writeln("j = screen.availHeight - 25;");
            writeln("temp = \"width=\" + i + \",\" + \"height=\" + j + \",\"+\"screenX=0,screenY=0,left=0,top=0,resizable=yes,scrollbars=yes\";");

            writeln("MaxiWindow = window.open(\"\", \"MaxiImages\", temp);");
            writeln("MaxiWindow.focus();");
            writeln("with (MaxiWindow.document)");
            writeln("{");
                writeln("writeln(\"<html dir=\\\"rtl\\\">\");");
                writeln("writeln(\"<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=utf-8\\\">\");");
                writeln("writeln(\"<title>eMss : \");");
                writeln("write(\""+Catalog[MsNr][NomCollPart]+" \");");
                writeln("write(\""+Catalog[MsNr][CoteMsOrig]+" \");");

                // in case Cote=ArabicScript, for LatinUser Cote in transliteration displayen
                if (Catalog[MsNr][CoteMsTranslit] != "-")
                    writeln("write(\""+Catalog[MsNr][CoteMsTranslit]+" \");");
                else
                    writeln("write(\""+Catalog[MsNr][CoteMsOrig]+" \");");
                
                writeln("write(lookName.replace(/<br>/,\" \"));");

                writeln("writeln(\"</title>\");");
                writeln("writeln(\"</head>\");");
                writeln("writeln(\"<body bgcolor=\\\"#000000\\\">\");");

                writeln("writeln(\"<table heigth=\\\"1600\\\" width=\\\"1600\\\"><tr><td align=right>\");");
                writeln("writeln(\"<img src=\\\"../IMAGES/MAXI/\" + look.toUpperCase() + \".JPG\\\">\");");
                writeln("writeln(\"</td></tr></table>\");");

                writeln("writeln(\"</body>\");");
                writeln("writeln(\"</html>\");");
            writeln("}");
        writeln("}");
        writeln("// -->");
        writeln("</script>");

        writeln("</head>");
        writeln("<body text=\"#EEEEEE\" bgcolor=\"#000000\" link=\"#FF0000\" vlink=\"#FF0000\" alink=\"#FF8080\">");

        write("<table heigth=\"650\" width=\"");
        write(len*600);
        writeln("\"><tr>");
        while(j < len) {
            i = len - j - 1;
            writeln("<td width=600 height=625 align=center>");
            write("<img src=\"../IMAGES/MEDI/");
            write(NrImages[i].toUpperCase() + ".JPG\" border=0 ");
            write("onClick=\"look='"+NrImages[i]+"';Loupe();\" ");
            write("onDblClick=\"look='"+NrImages[i]+"';lookName='"+NameImages[i]+"';MaxiImg();\" ");
            write("onMousemove=\"LoupeMove()\" ");
            writeln("style=\"cursor:w-resize\"><br>");
            writeln("<font style=\"font-size:10pt;\" face=\"Verdana,Arial,Helvetica,sans-serif\">");
            writeln(NameImages[i] + "</font>");
            writeln("</td>");
            j++;
        }
        writeln("</tr>");
        writeln("</table>");
        writeln("</body>");
        writeln("</html>");

        MediWindow.scrollTo((len-look)*600,0);
    }
}

// --------------------------------------------------------------
// das link zum schreiben der Maxi Img pop-up windows
// --------------------------------------------------------------

function MaxiImg() {
    i = screen.availWidth - 10;
    j = screen.availHeight - 25;
    temp = "width=" + i + "," + "height=" + j + ","+"screenX=0,screenY=0,left=0,top=0,resizable=yes,scrollbars=yes";
    MaxiWindow = window.open("", "MaxiImages", temp);
    MaxiWindow.focus();
    with (MaxiWindow.document) {
        writeln("<html dir=\"rtl\">");
        writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
        writeln("<title>eMss : ");
        write(Catalog[MsNr][NomCollPart] + " ");
        // in case Cote=ArabicScript, for LatinUser Cote in transliteration displayen
        if (Catalog[MsNr][CoteMsTranslit] != "-")
            write(Catalog[MsNr][CoteMsTranslit] + " ");
        else
            write(Catalog[MsNr][CoteMsOrig] + " ");

        writeln(lookName.replace(/<br>/," "));

        writeln("</title>");
        writeln("</head>");
        writeln("<body bgcolor=\"#000000\">");

        writeln("<table><tr><td align=right><a onclick=\"javascript:window.close();\">");
        writeln("<img src=\"../IMAGES/MAXI/" + look.toUpperCase() + ".JPG\">");
        writeln("</a></td></tr></table>");

        writeln("</body>");
        writeln("</html>");
    }
}