//=================================================
// MAS-GalleryBuilder V 1.0.4         19.12.2004
//-------------------------------------------------
// Copyright: M. Schmid, Softwareentwicklung
//            Lucerne, Switzerland
//            mailto:info@maschmid.ch
//=================================================

var i = 0
var j = 0
var Activated = false
var Folders = new Array()
var Galleries = new Array()
var Alias = new Array()
var Names = new Array()
var Texts = new Array()
var Folder = "home"
var Selected = 0
var TitleText = ""
var Anchor = ""
var p = new Array()  // image text for localication

//--- var's for slideshow ---
var ImageLength = -1
var Lock = false
var Show
var FirstImage
var LastImage

//--- var's to config ---
var MAS_Thumb = '_th'
var MAS_Prefix = false
var MAS_ImageExt = 'jpg'
var Thumb
var Prefix
var ImageExt

//--- var's for localication ---
var language = GetCookie("language")

//--- var's for status flasher ---
var delay= 1000;
var flag = 0;

//--- var's for quotes ---
var q = 0;
var Quotes = new Array()

//--- var's for banners ---
var BannerDirectory
var NoUrlText
var NoTitleText
var Bnrs = 0
var BannerImages = new Array()
var BannerUrls = new Array()
var BannerTitles = new Array()

//--- var's for email
var myname = "markus"
var mydomain = "littletramp.ch"
var myemail = myname + "@" + mydomain


//--------------------------------------------------
function DateDiffDays(d,m,y) {
        var start = new Date()
        start.setYear(y)
        start.setMonth(m-1,d)
        return (Date.parse(Date()) - Date.parse(start)) / 1000/60/60/24
}

//--------------------------------------------------
function Banner(image, url, title) {
    Bnrs++
    BannerImages[Bnrs] = BannerDirectory + '/' + image
    if (url) {
            BannerUrls[Bnrs] = url
    } else {
             BannerUrls[Bnrs] = NoUrlText + '?banner=' + BannerImages[Bnrs]
    }
    if (title) {
            BannerTitles[Bnrs] = title
    } else {
             BannerTitles[Bnrs] = NoTitleText
    }
}

function GetBannerNr() {
        var bnr = 0
        if (Bnrs) {
                bnr = Math.round(Bnrs * Math.random()+0.5)
        }
        return(bnr);
}

//--------------------------------------------------
function Quote(text) {
    q++
    Quotes[q] = text
}

function GetQuote() {
        var item = 0
        item = Math.round(q * Math.random()+0.5);
        return(Quotes[item]);
}

function StatusFlasher(text) {
        if (text == '') {
                text = GetQuote()
        }

        if (flag == 0) {
                window.status = text;
                flag = 1;
                setTimeout('StatusFlasher("' + text + '")', delay);
        } else {
                window.status = " ";
                flag = 0;
                setTimeout('StatusFlasher("' + text + '")', delay / 10);
        }
}

//================= Functions for Image.html ==========================
function ShowAllImages(title) {
    var allimgtext = "Keine Bilder vorhanden"
    var allimgtitle = title.replace(/ /g,"%20")
    var iimgtxt = " "

    if (ImageLength > 0) {
        if (!title) allimgtitle = ImageLength + " Bilder"
        allimgtext = ""

        for (iimg = 0; iimg < Names.length-1; iimg++) {

            if (Names[iimg]) {
                if (Names[iimg].indexOf("IMAGE=") == 0) {
                    if (Names[iimg].length == 6) {
                        allimgtext += "%%%"   // wenn Bild ohne Namen so nur Zeilenumbruch und Text anzeigen
                    } else {
		                allimgtext += "%%" + Names[iimg].substring(6) 
                    }
	                iimgtxt = StripTags(Texts[iimg])
	                iimgtxt = iimgtxt.replace(/'/g,"%27")    // hier sollte eigentlich ein ' angezeigt werden
	                if (iimgtxt == "") {iimgtxt = " "}
	                allimgtext += "%" + iimgtxt
                }
            }
        }
    }

    window.open("allimages.html?title=" + allimgtitle + "&folder=" + Folder + "/" + "&ext=" + "." + ImageExt + "&images=" + allimgtext , "ImageFrame")
}

function image(img_name, img_txt) {
	img_name = img_name.substring(4)
	img_name = img_name.replace(".JPG.html","")
	img_name = img_name.replace(".jpg.html","")
	img_txt = ReplaceUmlaut(img_txt)

	if (img_txt.indexOf("::")>=0) {
        	img_cmd = img_txt.substring(0,img_txt.indexOf("::"))
		img_txt = img_txt.substring(img_txt.indexOf("::")+2)

		if (img_cmd == "") {
		    Image(img_name,img_txt)
		    Line(img_txt)
		} else {
                    parse_cmd(img_cmd, img_name, img_txt)
		}

	} else {
		Image(img_name,img_txt)
	}
}


function parse_cmd(cmd, name, txt) {

	for (icmd = 0; icmd < cmd.length; icmd++) {

		cmdchar = cmd.substring(icmd,icmd+1)

		switch (cmdchar) {
			case "i": Image(name,txt);
			break;
		   	case "L": Line(txt);
			break;
			case " ": Space();
			break;
			case "-": Line("<br><hr>");
			break;
			case "N": NewLine();
			break;
			case "T": Image("",txt);
			break;
			case "S": Space(); SubTitle(txt);
			break;
			case "t": Text(txt);
			break;
			default: alert("FEHLER bei Bild: " + name + "\nSteuercode-Zeichen >" + cmdchar + "< unbekannt");
			break;
		}
	}

}

function get_region(txt) {
	return(txt.substring(0,txt.indexOf(";")))
}

function get_pagetitle(txt) {
	return(txt.substring(txt.indexOf(";")+1))
}

//================== end functions for image.html ========================

function GetArgValue(argName, arg)
{
    if (!arg) {
        arg = window.location.search
    }

    pos = arg.indexOf(argName + "=")

    if (pos == -1) {
        return("")
    } else {
        arg = arg.substring(pos + argName.length + 1)
        pos = arg.indexOf("&")

        if (pos >= 1) {
            arg = arg.substring(0,pos)
        }

        return(arg.replace(/%20/g," "))
    }
}

//--------------------------------------------------
function StripTags(text)
{
    a = text.indexOf("<")
    b = text.indexOf(">")
    len = text.length
    c = text.substring(0, a)

    if (b == -1) { b = a }

    d = text.substring((b + 1), len)
    text = c + " " + d         // replace tags with space

    tagCheck = text.indexOf("<")

    if (tagCheck != -1) { text = StripTags(text) }  // recursive

    return(text)
}
//--------------------------------------------------
function StripPath(text)
{
    pos = text.indexOf("/")
    if (pos > 0) { text = text.substring(pos + 1) }
    if (text.indexOf("/") > 0) { text = StripPath(text) }  // recursive
    return text
}
//--------------------------------------------------
function ReplaceUmlaut(text)
{
    text = text.replace(/%C4/g,"Ä")
    text = text.replace(/%D6/g,"Ö")
    text = text.replace(/%DC/g,"Ü")
    text = text.replace(/%E4/g,"ä")
    text = text.replace(/%F6/g,"ö")
    text = text.replace(/%FC/g,"ü")

    text = text.replace(/%27/g,"'")

    text = text.replace(/&lt;/g,"<")
    text = text.replace(/&gt;/g,">")
    text = text.replace(/&amp;/g,"&")

    text = text.replace(/&#196;/g,"Ä")
    text = text.replace(/&#214;/g,"Ö")
    text = text.replace(/&#220;/g,"Ü")
    text = text.replace(/&#228;/g,"ä")
    text = text.replace(/&#246;/g,"ö")
    text = text.replace(/&#252;/g,"ü")




    return(text)
}

//=================================================
// functions for language
//=================================================
function PrintLanguageSelectors()
{
//    s = window.document.getElementById('masgalbtn').innerHTML
//    s= s+ '<input type="button" value="' + Text_Language + '" onclick="ChangeLanguage()">'
//    window.document.getElementById('masgalbtn').innerHTML = s
}

function ChangeLanguage(lan)
{
    if (lan == "e" ) {
                if (!navigator.cookieEnabled) {
                        alert("Cookies have to be enabled to use this feature\n\nDu musst Cookies zulassen")
        } else {
                       alert(Text_VolunteerWanted);
        }
    }

    language = lan
    SetCookie("language",language, 1000*60*60*24*180)
    window.location.reload()

}


//=================================================
// functions for cookies
//=================================================
function GetCookie(name) {
    var value = "";
    var c = document.cookie
        if (c) {
            var start = c.indexOf(name + "=")
        if (start != -1) {
                 start += name.length + 1;
                    var end = c.indexOf(";",start);
                    if (end == -1) end = c.length;
                    value = c.substring(start, end);
        }
        }
    if ((name == "language") && (value == "")) {
            value = "d"
            ChangeLanguage(value)
    }
        return value;
}

function SetCookie(name, value, duration) {
    var now = new Date();
    var exp = new Date(now.getTime() + duration);
    document.cookie = name + "=" + value + "; expires=" + exp.toGMTString() + ";";
}


//=================================================
// functions for buttons
//=================================================
function PrintButton()
{
    s = window.document.getElementById('masgalbtn').innerHTML
    s= s+ '<input type="button" value="' + Text_Print + '" onclick="window.print()">'
    window.document.getElementById('masgalbtn').innerHTML = s
}

function MaxButton()
{
    s = window.document.getElementById('masgalbtn').innerHTML
    if (top.location.href != self.location.href) {
        s = s + '<input type="button" value="' + Text_Maximize + '" onclick="window.open(self.location.href,' + "'_blank', 'channelmode=yes,fullscreen=yes,resizable=yes,scrollbars=yes,titlebar=no,status=no,menu=no,location=no'" + ')">'
    } else {
        s = s + '<input type="button" value="' + Text_Close + '" onclick="window.close()">'
    }
    window.document.getElementById('masgalbtn').innerHTML = s
}

function MaxButtonImage()
{
    s = window.document.getElementById('masgalbtn').innerHTML
    if (top.location.href != self.location.href) {
        s = s + '<input type="button" value="' + Text_Maximize + '" onclick="OpenWinMax()">'
    } else {
        s = s + '<input type="button" value="' + Text_Close + '" onclick="window.close()">'
    }
    window.document.getElementById('masgalbtn').innerHTML = s
}

//=================================================
// functions and declarations for navigation.html
//=================================================

function AddFolder(folder, text, alias)
{
    Folders[j] = folder
    if (text) {
        Galleries[j] = text
    } else {
        Galleries[j] = folder
    }

    if (alias) {
        Alias[j] = alias
    } else {
        Alias[j] = folder
    }
    j++
}

//--------------------------------------------------
function CreateFolderList()
{
    menu = GetArgValue("menu")
    if (!menu) {
        menu="menu"
    }
    document.write('<script src=' + menu + '.txt type="text/javascript"></script>')
}

//--------------------------------------------------
function ShowFolderList()
{
    folder = GetArgValue("folder")

    //-------- combobox to select gallery -----------
    document.write('<form><table width="340" border="0" cellspacing="0" cellpadding="0"><tr>')
    if (folder) {
        document.write('<td width="80"><font size="-1"><b>' + Text_Menu + '</b></font></td>')
    } else {    // blink caption Menü if on startpage
        document.write('<td width="80"><font size="-1"><b>' + Text_Menu + '</b></font></td>')
//        document.write('<td width="80"><font size="-1"><b><blink>' + Text_Menu + '</blink></b></font></td>')
    }
    document.write('<td width="260" colspan="6">')

    document.write('<select size="1" name="FolderList" style="width: 260" onchange="OpenGallery()">')

    if (GetArgValue("list")) {
        s = Text_BackHome
    } else {
        s = Text_SelectItem
    }
    if (folder) {
        document.write('<option>' + s + '</option>')
    } else {
        document.write('<option selected>' + s + '</option>')
    }

    for (f = 0; f < Folders.length; f++) {
        if ((Folders[f]) && ((folder.toLowerCase() == Folders[f].toLowerCase()) || (folder.toLowerCase() == Alias[f].toLowerCase()))) {
            document.write('<option selected>' + Galleries[f] + '</option>')
        } else {
            if (!Galleries[f])  {
                document.write('<option>------------------------------------------------------------------------------</option>')
            } else if ((Galleries[f].indexOf("--") == 0) || (Galleries[f].indexOf("==") == 0)) {    // allows to use named delimeter lines like: ---- text ---
                document.write('<option>' + Galleries[f] + '</option>')
                Galleries[f] = ''
                Folders[f] = ''
            } else {
                document.write('<option>' + Galleries[f] + '</option>')
            }
        }
    }

    document.write('</select>')
    document.write('</td></tr>')
    document.write('<tr>')

    ShowSlideShowButtons()

    document.write('</tr>')
    document.write('</table>')

    ShowLanguageSelectors()

    document.write('</form>')
}
//--------------------------------------------------
function ShowLanguageSelectors()
{

var myname = "markus.schmid"
var mydomain = "maschmid.ch"
var myemail = myname + "@" + mydomain
var space = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
        document.write('<h4><div align="center">')
    document.write('<a href="index_start.html" target="_top">[Home]</a>')
    document.write(space)
    document.write('<a href="report.html?folder=start&file=overview.txt" target="ImageFrame">[Sitemap]</a>')
    document.write(space)
    document.write('<a href="index_start.html?list=guestbook&folder=start" target="_top">[' + Text_Guestbook + ']</a>')
    document.write(space)
    document.write("<a href='mailto:" + myemail + "'>[Email]</a>")
//    document.write(space)
//    document.write('<a href="" onclick="ChangeLanguage(\'d\')" title="Sprache Deutsch"><img src="gm-flag.gif"     height="12" hspace="6"></a>')
//    document.write('<a href="" onclick="ChangeLanguage(\'e\')" title="Language english"><img src="uk-flag.gif" height="12"></a>')
    document.write('<hr></div></h4>')
}
//--------------------------------------------------
function ShowSlideShowButtons()
{
    //-------- buttons for slideshow ---------

    if (!window.name) {
        // image control buttons
        s = '<td><input type=button value="I<" style="width: 35" name="firstImg" onClick="' + "javascript:opener.top.frames['GalleryFrame'].window['Gallery'](-2);SetTextAuto()" + '">'
        s = s + '<input type=button value="<" style="width: 35" name="prevImg" onClick="' + "javascript:opener.top.frames['GalleryFrame'].window['Gallery'](-1);SetTextAuto()" + '">'
        s = s + '<input type=button value="Start" style="width: 45" name="autoShow" onClick="' + "javascript:opener.top.frames['GalleryFrame'].window['Gallery']();SetTextAuto()" + '" id=masgalbtnauto>'
        s = s + '<input type=button value=">" style="width: 35" name="nextImg" onClick="' + "javascript:opener.top.frames['GalleryFrame'].window['Gallery'](1);SetTextAuto()" + '">'
        s = s + '<input type=button value=">I" style="width: 35" name="lastImg" onClick="' + "javascript:opener.top.frames['GalleryFrame'].window['Gallery'](2);SetTextAuto()" + '"></td>'
        window.document.getElementById('masgalnavbtn').innerHTML = s
    } else {
        document.write('<td width="80"><font size="-1"><b>' + Text_Controls + '</b></font></td>')
        // Interval selector
        document.write('<td width="75"><select size="1" name="Interval" style="width: 70">')
        document.write('<option>3 ' + Text_Timeunit + '</option>')
        document.write('<option selected>6 ' + Text_Timeunit + '</option>')
        document.write('<option>9 ' + Text_Timeunit + '</option>')
        document.write('<option>12 ' + Text_Timeunit + '</option>')
        document.write('<option>15 ' + Text_Timeunit + '</option>')
        document.write('</select></td>')
        // image control buttons
        document.write('<td width="35"><div align="right"><input type=button value="I<" style="width: 35" name="firstImg" onClick="' + "javascript:top.frames['GalleryFrame'].window['Gallery'](-2)" + '" id=btnStyle></div></td>')
        document.write('<td width="35"><div align="left"><input type=button value="<" style="width: 35" name="prevImg" onClick="' + "javascript:top.frames['GalleryFrame'].window['Gallery'](-1)" + '" id=btnStyle></div></td>')
        document.write('<td width="45"><div align="center"><input type=button value="Start" style="width: 45" name="autoShow" onClick="' + "javascript:top.frames['GalleryFrame'].window['Gallery']()" + '" id=btnStyle></div></td>')
        document.write('<td width="35"><div align="right"><input type=button value=">" style="width: 35" name="nextImg" onClick="' + "javascript:top.frames['GalleryFrame'].window['Gallery'](1)" + '" id=btnStyle></div></td>')
        document.write('<td width="35"><div align="left"><input type=button value=">I" style="width: 35" name="lastImg" onClick="' + "javascript:top.frames['GalleryFrame'].window['Gallery'](2)" + '" id=btnStyle></div></td>')
    }

}

//--------------------------------------------------
function OpenWinGallery(anchor, SelectedText)
{
    if (document.forms[0].FolderList.selectedIndex) {
        folder = Folders[document.forms[0].FolderList.selectedIndex - 1]
    } else {
        folder = "start"
    }

    if (folder=="") {
        document.forms[0].FolderList.selectedIndex = Selected
    } else {
        Selected = document.forms[0].FolderList.selectedIndex

        if ((SelectedText) && (Selected == 0)) {
            folder = "home"
        }

        if (anchor) { anchor = "#" + anchor } else { anchor = "" }

        var repfilereq=GetArgValue("file") //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
		
		if (repfilereq) {
            window.open( "gallery.html?folder=" + folder + anchor + "&file=" + repfilereq, "GalleryFrame")
		} else {
            window.open( "gallery.html?folder=" + folder + anchor, "GalleryFrame")
		}
		

        // Reset buttons for slideshow
        Lock = false
        SetSlideshowControls(Lock)
    }
}

//=================================================
// functions and declarations for gallery.html
//=================================================
function ButtonAction(offset)
{
    if (!offset) {
        SlideShow()
    } else {
        ChangeImage(offset)
        SlideShow(true)     // stop slideshow
    }
}

//--------------------------------------------------
function SlideShow(stop)
{
    // check if images exist
    if (ImageLength == 0) {
        return
    }
    if (stop) { Lock = true }

    if (Lock == true) {
        ChangeImage(0, 0)
    } else {
        delay = top.frames['NavigationFrame'].document.forms[0].Interval.selectedIndex
        delay = (delay * 3 + 3) * 1000        //miliseconds
        ChangeImage(1, delay)
    }

    Lock = !Lock

    SetSlideshowControls(Lock)
}

//--------------------------------------------------
function SetImageControls(img)
{
if (top.frames['NavigationFrame'].document.forms[0].firstImg != null) {
    if (img == "first") {
        top.frames['NavigationFrame'].document.forms[0].firstImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].prevImg.disabled =  true
        top.frames['NavigationFrame'].document.forms[0].nextImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].lastImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].autoShow.disabled = false
    } else if (img == "last") {
        top.frames['NavigationFrame'].document.forms[0].firstImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].prevImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].nextImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].lastImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].autoShow.disabled = false
    } else if (img == "none") {
        top.frames['NavigationFrame'].document.forms[0].firstImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].prevImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].nextImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].lastImg.disabled = true
        top.frames['NavigationFrame'].document.forms[0].autoShow.disabled = true
    } else {
        top.frames['NavigationFrame'].document.forms[0].firstImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].prevImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].nextImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].lastImg.disabled = false
        top.frames['NavigationFrame'].document.forms[0].autoShow.disabled = false
    }
}

}


//--------------------------------------------------
function SetSlideshowControls(lock)
{
    if (lock) {
        textShowBtn = "Stop"
    } else {
        textShowBtn = "Start"
    }
    top.frames['NavigationFrame'].document.forms[0].autoShow.value = textShowBtn
    top.frames['NavigationFrame'].document.forms[0].prevImg.disabled = lock
    top.frames['NavigationFrame'].document.forms[0].nextImg.disabled = lock
    top.frames['NavigationFrame'].document.forms[0].Interval.disabled = lock
}

//--------------------------------------------------
function ChangeImage(offset, delay)
{
if (Show) { window.clearTimeout(Show) }

    if (!offset) {
        return
    }

     if (ImageLength > 0) {
        index = GetImageNumber()
        index = GetNextImage(index, offset)
        OpenWinImage(index)
//        PreloadImage(index)

        if (delay) {
            Show = setTimeout("ChangeImage(1, " + delay + ")", delay)
        }
    }
}


//--------------------------------------------------
function PreloadImage(index)
{
    var preloadedimage = new Image();
    d = new Date()
    time = d.getMilliseconds()
    preloadedimage.src = Folder + "/" + Names[GetNextImage(index)].substring(6) + "." + MAS_ImageExt
//    alert(d.getSeconds())
//alert(Folder + "/" + Names[GetNextImage(index)].substring(6) + "." + MAS_ImageExt)
}

//--------------------------------------------------
function GetImageNumber()
{
    var index = 0
    if (top.frames['ImageFrame'].document.getElementById('masgalimg'))  {
        index = top.frames['ImageFrame'].document.getElementById('masgalimg').alt
    }
    if (index <= 0) {
        index = 0
    }
    return index
}

//--------------------------------------------------
//function ShowImage(index, offset)
function GetNextImage(index, offset)
{
    var ok = false

    if (offset == -2) {                // first image
        index = -1
        offset = 1
    } else if (offset == 2) {         // last image
        index = -1
        offset = -1
    }

    if (Names) {
        do {

            if (offset > 0) {
                index++
            } else {
                index--
              }

            if (index >= Names.length) {
                index = 0
            } else if (index < 0) {
                index = Names.length - 1
            }

            if (!Names[index]) {
            } else if (Names[index].indexOf("REPORT=") == 0) {
//                OpenWinReport(index)
            } else if (Names[index].indexOf("FILE=") == 0) {
            } else if (Names[index].indexOf("VIDEO=") == 0) {
            } else if (Names[index].indexOf("IMAGE=") == 0) {
                ok = true
            }

        } while (!ok)

        if (index == FirstImage) {
            SetImageControls("first")
        } else if (index == LastImage) {
            SetImageControls("last")
        } else {
            SetImageControls("all")
        }

        return index
//        OpenWinImage(index)
    }
}

//--------------------------------------------------
function CreateImageList()
{
    // reset config values
    Thumb = MAS_Thumb
    Prefix = MAS_Prefix
    ImageExt = MAS_ImageExt

    // load gallery index file
    folder=GetArgValue("folder")
    Folder = folder
    document.write('<script src=' + Folder + '/index.txt type="text/javascript"></script>')
}

//--------------------------------------------------
function SoundLink(soundsrc,displaytext)
{
    ie = (navigator.appName == "Microsoft Internet Explorer")
    // make sure the function doesen't already exist
    if (!document.getElementById("mas_soundonoff")) {

        document.write('<script language="JavaScript" id="mas_soundonoff" tag="">')

        document.write('function SoundOnOff(src,text){')

        document.write('if (document.getElementById("mas_sound").src=="") {')
        document.write('document.getElementById("mas_sound").src= src;')
        document.write('document.getElementById("mas_soundonoff").tag= text;')
        document.write('document.getElementById(src).innerHTML= text + Text_Stop;')
        if (!ie) { document.write('document.getElementById("mas_sound").play();') }

        document.write('} else if (document.getElementById("mas_sound").src==src) {')

        document.write('document.getElementById("mas_sound").src="";')
        document.write('document.getElementById(src).innerHTML= text + Text_Play;')
        if (!ie) { document.write('document.getElementById("mas_sound").stop();') }

        document.write('} else {')

        document.write('textold=document.getElementById("mas_soundonoff").tag;')
        document.write('srcold=document.getElementById("mas_sound").src;')
        document.write('document.getElementById(srcold).innerHTML= textold + Text_Play;')
        document.write('document.getElementById("mas_sound").src=src;')
        document.write('document.getElementById("mas_soundonoff").tag= text;')
        document.write('document.getElementById(src).innerHTML= text + Text_Stop;')
        if (!ie) { document.write('document.getElementById("mas_sound").play();') }

        document.write('}')
        document.write('}')
        document.write('</script>')
        if (ie) {
            document.write('<bgsound id="mas_sound" loop="-1">')        //LOOP: -1 = infinitely ; 0 = once ; nn = number of times
        } else {
            document.write('<embed id="mas_sound" type="audio/x-midi" src="" hidden="true" autostart="true" loop="true">')
        }
    }

    if (!displaytext) { displaytext = Text_Sound }
       document.write('<h4><a href="javascript:SoundOnOff(' + "'" + soundsrc + "','" + displaytext + "'" + ')" id="' + soundsrc + '">' + displaytext + Text_Play + '</a></h4>')
}

//--------------------------------------------------
function NewRow(c,nospace) {
    if (c != 1) {
        document.write('</tr></table>')
    }
    if (nospace) {
        document.write('<table border="0" class=""  cellpadding="0" cellspacing="0" width="100%"><tr>')
    } else {
        document.write('<table border="0" class="" width="100%"><tr>')
    }
    return 3
}
//--------------------------------------------------
function StartCell() {
    document.write('<td align="center" valign="middle">')
}

//--------------------------------------------------
function EndCell() {
    document.write('</td>')
}

//--------------------------------------------------
function InsertSpace(c) {
    c = NewRow(c)
    document.write('<td height="1"></td>')
    return 3
}

//--------------------------------------------------
function BuildTable()
{
    var activated = false
    var c = 0
    ImageLength = 0
    FirstImage = -1
    LastImage = -1

    // set top-anchor
    if (Names[0] == "PAGETITLE") {               // show pagetitel
            if (Texts[0] == "")  {
                 TitleText = "Homepage Markus Schmid"
        } else {

               document.write('<a name="_top_"></a>' + '<h1>' + Texts[0] + '</h1>')
               TitleText = Texts[0]
        }
        p0 = 1
    } else {
        TitleText = ""
        p0 = 0
    }

    // show content

    for (p = p0; p < Names.length; p++) {

        // start new row
        if (c == 0) {
            document.write('<table border="0" class="" width="100%"><tr>')
        }

        c++            // increment column

        // show item
        if (!Names[p]) {

            if (c > 1) {
                c = 3        // is linebreak
            } else {
                c--            // ignore
            }

        } else {

            if ((Names[p].indexOf("TITLE=") == 0) || (Names[p].indexOf("SUBTITLE=") == 0)) {   // show titel with space before

                c = NewRow(c)
                StartCell()

                // get name of anchor
                if (Names[p].indexOf("TITLE=") == 0) {
                        if (TitleText=="") {
                        TitleText="Homepage Markus Schmid"
                            s = '_top_'
                    } else {
                        s = Names[p].substr(6)
                    }
                } else if (Names[p].indexOf("SUBTITLE=") == 0) {
                    s = Names[p].substr(9)
                } else {
                    s = Names[p].substr(1)
                }

                // set text
                if (!Texts[p]) { Texts[p] = s }

                // write line and set anchor
                if (Names[p].indexOf("SUBTITLE=") == 0) {
                    s1 = "<h3>"
                    s2 = "</h3>"
                } else {
                    s1 = "<h2>"
                    s2 = "</h2>"
                }
                if (s=="_top_") {
                    document.write('<a name="' + s + '"</a>' + s1 + Texts[p] + s2)
                } else if (s) {
                        if (s.indexOf(">") > 0) {         // Führende Tags wegschneiden
                            s = s.substr(s.indexOf(">") + 1)
                    }
                    document.write('<br><a name="' + s + '"</a>' + s1 + Texts[p] + s2)
                } else {
                    document.write('<br>' + s1 + Texts[p] + s2)
                }

                c = InsertSpace(c)

            } else if (Names[p] == "SPACE") {            // insert space

                c = InsertSpace(c)

            } else if (Names[p].indexOf("TEXT=") == 0) {            // Text in cell (does not insert space after!!!)

                StartCell()
                document.write('<h5>' + Names[p].substr(5) + '</h5>')
                EndCell()

            } else if (Names[p].indexOf("LINE=") == 0) {            // Text in new line (inserts space after!!!)

                c = NewRow(c)
                StartCell()
                document.write('<h5>' + Names[p].substr(5) + '</h5>')
                EndCell()
                c = InsertSpace(c)

            } else if (Names[p].indexOf("OPEN=") == 0) {            // show new content in window

                c = NewRow(c)
                StartCell()
                if (!Texts[p]) { Texts[p] = Names[p].substr(5) }
                s = '<h4><a href="JavaScript:window.open(' + "'" + Names[p].substr(5) + "','_top'" + ')">' + Texts[p] + '</a></h4>'
                document.write(s)

                EndCell()

            } else if (Names[p].indexOf("REPORT=") == 0) {            // show link to report

                if (Texts[p]) {                           // do not print empty line if first item has no text
                    c = NewRow(c)
                    StartCell()
                    if (Texts[p].indexOf("&") > 0) {
                        s = Texts[p].replace(/&/g,'</a></div></h4></td><td><h5><div align="right">') + '</div></h5></td></tr>'
                        document.write('<h4><div align="left"><a href="JavaScript:OpenWinReport(' + "'" + p + "'" + ')">' + s + '</a>')
                    } else {
                        document.write('<h4><a href="JavaScript:OpenWinReport(' + "'" + p + "'" + ')">' + Texts[p] + '</a></h4>')
                    }
                    EndCell()
                }
                if (!activated) {      // activate first item
                    activated = true

					var repfilereq=(GetArgValue("file"))

					if (repfilereq) {
                    	OpenWinReportFile(repfilereq)   // if file requested open requestet file ---- ergänzt 24.04.11
					} else {
                    	OpenWinReport(p)
					}

                }

            } else if (Names[p].indexOf("NEWS=") == 0) {       // show link to report or section in other chapter

                c = NewRow(c,true)
                StartCell()
                if (Texts[p].indexOf("&") > 0) {
                    s1 = '<h4 style="text-align:left">'
                } else {
                    s1 = '<h4>'
                }
                s2 = Texts[p].replace(/&/g,'</a></h4></td><td><h5 style="text-align:right">') + '</h5></td></tr>'
                if (Names[p].indexOf("list=") >= 5) {
                    document.write(s1 + '<a href="index_start.html?' + Names[p].substr(5) + '", target="_top">' + s2 + '</a>')
                } else {
                    s = Names[p].substr(5)
                    file = StripPath(s)
                    folder = s.substr(0, s.length - file.length)
                    document.write(s1 + '<a href="report.html?folder=' + folder + '&file=' + file + '", target="ImageFrame">' + s2 + '</a>')
                }
                EndCell()

            } else if (Names[p].indexOf("LINK=") == 0) {            // show link to url

                // show link only if linktext exists
                s = Texts[p]
                if (s) {
                    document.write('<h4><a href="' + Names[p].substr(5) + '" target="ImageFrame">' + s + '</a></h4>')
                    EndCell()
                    c = NewRow(c)
                    StartCell()
                }

                if (!activated) {      // activate link if first item
                    activated = true
                    OpenLink(p)
                }

            } else if (Names[p].indexOf("MAPS=") == 0) {            // show link to url

                // show map only if linktext exists
                s = Texts[p]
                if (s) {
                    document.write('<h4><a href="' + Names[p].substr(5) + '" target="_new">' + s + '</a></h4>')
                    EndCell()
                    c = NewRow(c)
                    StartCell()
                }

                // Note: do not activate map if first item


            } else if (Names[p].indexOf("GOTO=") == 0) {            // show link to anchor

                c = NewRow(c)
                StartCell()
                s = Texts[p]
                if (!s) { s = Names[p].substr(5) }
                document.write('<h4><a href="#' + Names[p].substr(5) + '">' + s + '</a></h4>')
                EndCell()

            } else if (Names[p] == "GOTOTOP") {                        // show link to top of frame

                c = NewRow(c)
                StartCell()
                document.write('<h5><br><a href="#_top_">' + Text_GoToTop + '</a></h5>')
                EndCell()

            } else if (Names[p] == "HOME") {                        //

                c = NewRow(c)
                StartCell()
                document.write('<h5><br><a href="JavaScript:window.open(' + "'index_start.html','_top')" + '">' + Texts[p] + '</a></h5>')
                EndCell()

            } else if (Names[p].indexOf("EMAIL=") == 0) {            // show link to create email

                c = NewRow(c)
                StartCell()
                document.write('<h5><a href="mailto:' + Names[p].substring(6) + '">' + Texts[p] + '</a></h5>')
                EndCell()

            } else if (Names[p].indexOf("FILE=") == 0) {            // show file

                c = NewRow(c)
                StartCell()
                document.write('<h4><a href="JavaScript:OpenWinFile(' + "'" + p + "'" + ')">' + Texts[p] + '</a></h4>')
                EndCell()

                if (!activated) {      // activate first item
                    activated = true
                    OpenWinFile(p)
                }

            } else if (Names[p].indexOf("SOUND=") == 0) {            // show link to start sound in cell

                StartCell()
                SoundLink(Names[p].substring(6),Texts[p])
                EndCell()

            } else if (Names[p].indexOf("VIDEO=") == 0) {            // show video

                StartCell()
                document.write('<a href="JavaScript:OpenWinVideo(' + "'" + p + "'" + ')">' + Texts[p] + '</a>')
                EndCell()

                if (!activated) {      // activate first item
                    activated = true
                    OpenWinVideo(p)
                }


            } else if (Names[p].indexOf("IMAGE=") == 0) {           // show image

                ImageLength++
if (Names[p].substring(6)) {   // ergänzt 16.04.08

                StartCell()
                reftext = '"JavaScript:OpenWinImage(' + "'" + p + "'" + ')"'
                document.write('<a href=' + reftext + ' onfocus=' + reftext + '>')

                if (Prefix) {
                    imageName = Thumb + Names[p].substring(6)
                } else {
                    imageName = Names[p].substring(6) + Thumb
                }
                document.write('<img src="' + Folder + '/' + imageName + '.' + ImageExt + '" alt="' + StripTags(Texts[p]) + '"></a>')
                EndCell()

}
                if (!activated) {      // activate first item
                    activated = true
                    OpenWinImage(p)
                }
                if (ImageLength == 1) { FirstImage = p }
                LastImage = p

            } else if ((Names[p] == "-") || (Names[p].indexOf("=") == 0)) {

                alert("Diese Syntax wird nicht mehr unterstützt:" + Names[p])

            }


        }        // end item

        if (c == 3) {        // finish row
            c = 0
            document.write('</tr>')
        }

    }           // end for



    if (c != 0) {        // finish actual row
           document.write('</tr>')
    }

    InsertSpace(c)
    InsertSpace(c)

    document.write('</table>')

    parent.document.title = StripTags(TitleText)

    if (!activated) {        // if no image/file shown then reset image frame
        window.open("blank.html", "ImageFrame")
    }

    if (ImageLength > 0) {
        SetImageControls("first")
    } else {
        SetImageControls("none")
    }
}

//--------------------------------------------------
function OpenWinVideo(index)
{
    file = Folder + "/" + Names[index].substring(6)
    text = Texts[index]
    if (!text) { text = "." }

    if (!top.frames['ImageFrame'].document['masgalvideo']) {
        window.open("video.html?file=" + file + "&text=" + text + "&index=" + index , "ImageFrame")
    } else {
        GetVideo(text, file)
    }
}

//--------------------------------------------------
function OpenLink(index)
{
    url = Names[index].substring(5)
    window.open(url, "ImageFrame")
    window.status = url        // show filename in statusbar
}

//--------------------------------------------------
function OpenWinFile(index)
{
    file = Names[index].substring(5)
    window.open(Folder + "/" + file, "ImageFrame")
    window.status = file        // show filename in statusbar
}

//--------------------------------------------------
function _add(image, text)
{
    Names[i] = image
    if (text) {
        Texts[i] = text
    } else {
        Texts[i] = ''
    }
    i++
}


//=================================================
// functions for image.html
//=================================================

function OpenWinImage(index)
{
if (Names[index].substring(6)) {
    file = Folder + "/" + Names[index].substring(6) + "." + ImageExt
    text = StripTags(Texts[index])
} else {
        file = ""
    text = Texts[index]
}
    if (!text) { text = "." }

    if (!top.frames['ImageFrame'].document.getElementById('masgalimg')) {
        window.open("image.html?file=" + file + "&text=" + text + "&index=" + index , "ImageFrame")
    } else {
        SetImage(text, file, index)
    }
}
//--------------------------------------------------
function SetImage(text, file, index)
{
//    alert(file)
    if (file) {
        top.frames['ImageFrame'].document.getElementById('masgalimg').src = file
    } else {
        top.frames['ImageFrame'].document.getElementById('masgalimg').src = "i.jpg"
    }
    top.frames['ImageFrame'].document.getElementById('masgalimg').alt = index
    SetImageText(text, file)
}
//=================================================
function SetImageText(text, file)
{
    file = StripPath(file)
    if (file) {
            if (text== ' ') {
                window.status = file
                text = "&nbsp;"
            } else {
                text = StripTags(text)
                window.status = file + " - " + text
            }

            top.frames['ImageFrame'].document.getElementById('masgaltxt').innerHTML = ReplaceUmlaut(text)
        top.frames['ImageFrame'].document.getElementById('imageframe').style.visibility ="visible"
    } else {
        top.frames['ImageFrame'].document.getElementById('masgaltxt').innerHTML = text
        top.frames['ImageFrame'].document.getElementById('imageframe').style.visibility ="hidden"
        window.status = ""
    }
}

//=================================================
// functions for video.html
//=================================================
function GetVideo(text, file)
{
    if (navigator.appName == "Microsoft Internet Explorer") {
        top.frames['ImageFrame'].document['masgalvideo'].dynsrc =  file
    } else {
        text = "Sorry, your browser does not support videos!"
    }
    SetImageText(text, file)
}

//========================================================================================================================
// functions for report.html
//========================================================================================================================

function OpenWinReport(index)
{
    file = Names[index].substring(7)
    title = StripTags(Texts[index])
    window.open("report.html?folder=" + Folder + "&file=" + file + "&title=" + title, "ImageFrame")
}

function OpenWinReportFile(file)
{
    window.open("report.html?folder=" + Folder + "&file=" + file, "ImageFrame")
}

function PageTitle(arg1)
{
    if (window.name == "GalleryFrame") {
        _add("PAGETITLE", arg1)
    } else {
        if (!arg1) {
            arg1 = '<h1>' + GetArgValue("title") + '</h1>'
        }
        if (arg1) {
            window.document.getElementById('masgaltitle').innerHTML = arg1
        }

    }
}

function Title(arg1, arg2)
{
    if (!arg2) {
        tag = arg1.replace(/ /g,"_")
    } else {
        tag = arg2
    }

    if (window.name == "GalleryFrame") {
        _add("TITLE=" + tag, arg1)
    } else {
        window.document.write('<br><a name="' + tag + '"></a><h2>' + arg1 + "</h2>")
    }
}

function SubTitle(arg1, arg2)        // smaler and without leading space
{
    if (!arg2) {
        tag = arg1.replace(/ /g,"_")
    } else {
        tag = arg2
    }

    if (window.name == "GalleryFrame") {
        _add("SUBTITLE=" + tag, arg1)
    } else {
        window.document.write('<a name="' + tag + '"></a><h3>' + arg1 + "</h3>")
    }
}

function Text(arg1)
{
    if (window.name == "GalleryFrame") {
        _add("TEXT=" + arg1)
    } else {
        window.document.write("<p><h4>" + arg1 + "</h4></p>")
    }
}

function TextLeft(text)
{
    Text("<div align='left'>" + text + "</div>")
}

function NewLine()
{
    if (window.name == "GalleryFrame") {
        _add()
    } else {
        Text("</td></tr><tr><td>")
    }
}

function Space()
{
    if (window.name == "GalleryFrame") {
        _add("SPACE")
    } else {
        window.document.write("<p><small>&nbsp;</small></p>")
    }
}

function CenterStart()
{
    window.document.write("<div align=centre>")
}

function CenterEnd()
{
    window.document.write("</div>")
}

function ImageLeft(text)
{
    src = GetArgValue("folder") + '/' + text
    window.document.write('<p><div align="left"><img src="' + src + '"></div></p>')
}

function Image(arg1, arg2)
{
     if (window.name == "GalleryFrame") {
        _add("IMAGE=" + arg1, arg2)
    } else {
        src = GetArgValue("folder") + '/' + arg1
        window.document.write('<p><center><img src="' + src + '"></center></p>')
    }
}

//--------------- Links ---------------------
function Link(url,text,comment)
{
    if (window.name == "GalleryFrame") {
        _add("LINK=" + url,text)
    } else {
        if (!text) { text = url }
        if (!comment) { comment = "" }
        Text("<a href='" + url + "'>" + text + "</a> " + comment)
    }
}

function LinkLeft(url,text,comment)
{
    if (!text) { text = url }
    if (!comment) { comment = "" }
    TextLeft("<a href='" + url + "'>" + text + "</a> " + comment)
}

function LinkItem(url,text,comment)
{
    if (!text) { text = url }
    if (!comment) { comment = "" }
    ListStart()
    Text("<li><a href='" + url + "'>" + text + "</a><br><div align='left'>" + comment + "</div></li>")
    ListEnd()
}

function News(arg1,arg2)
{
    if (window.name == "GalleryFrame") {
        _add("NEWS=" + arg1, arg2)
    }
}

function Report(arg1, arg2)
{
    if (window.name == "GalleryFrame") {
        _add("REPORT=" + arg1, arg2)
    }
}

function Line(arg1)
{
    if (window.name == "GalleryFrame") {
        _add("LINE=" + arg1)
    }
}

function Goto(arg1, arg2)
{
    if (!arg2) { arg2 = arg1 }
    anchor = arg1.replace(/ /g,"_")

    if (window.name == "GalleryFrame") {
        _add("GOTO=" + anchor, arg2)
    } else {
        document.write('<a href="#' + anchor + '"><small><b>' + arg2 + '</b></small></a><br>')
    }
}

function GotoNextReport(file,text) {
    Space()
    SubTitle("Weiter mit <a href='report.html?folder=" + GetArgValue("folder") + "&file=" + file + "'>" + text + "</a> ")
}

function GotoTop()
{
    if (window.name == "GalleryFrame") {
        _add("GOTOTOP")
    } else {
        document.write('<h5><br><a href="#_top_">' + Text_GoToTop + '</a></h5>')
    }
}

function File(arg1,arg2)
{
    _add("FILE=" + arg1, arg2)
}

function Sound(src,text)
{
    _add("SOUND=" + src, text)
}

//---------- Item lists --------------
function ListStart()
{
    window.document.write("<ul>")
}

function Item(itemtext, text)
{
    if (text) {
         Text("<li>" + itemtext + "</li><p align='left' style='margin-top:3px'>" + text + "</p>")
    } else {
         Text("<li>" + itemtext + "</li>")
    }
}

function ListEnd()
{
    window.document.write("</ul>")
}

//----------- Tabled lists -------------
function TableStart(hr)
{
    if (hr) { Text("<HR>") }
    Text('<center><table width="90%">')
}

function Row(text1,text2,space)
{
    s1 = "<tr><td width='33%' valign='top'><h4><div align='left'>"
    s2 = "</div></h4></td><td><h4><div align='left'>"
    s3 = "</div></h4></td></tr>"
    if (space) { Text(s1 + s2) }
    Text(s1 + text1 + s2 + text2 + s3)
}

function CellStart(top)
{
    if (top) {
        Text("<td valign='top'>")
    } else {
        Text("<td>")
    }
}

function CellEnd()
{
    Text("</td>")
}

function Cell(text,top)
{
    if (top) {
        Text("<td valign='top'>" + text + "</td>")
    } else {
        Text("<td>" + text + "</td>")
    }
}

function TableEnd(hr)
{
    Text("</table></center>")
    if (hr) { Text("<HR>") }
}
//---------------------------------------
function CheckPassword(pwd,text1,text2,repeat)
{
    if (!text1) { text1 = Text_Pwd }
    if (!text2) { text2 = Text_Protected }
    s = prompt(text1,"")
    if (pwd != s) {
        if (s != null) {
            alert(text2)
        }
        if (!repeat) {
            window.open("index_start.html","_top")
        }
        die     // creates error to stop execution
    }
}

function LinkMap(region,image)
{
    if (image) {
        Text("<a href='map.html?region=" + region + "' target='_new' onmouseover='return overlib(\"<h3>Interaktive Karte</h3><center>Hier kannst du auf einer zoomfähigen Karte meine Reiseroute verfolgen</center>&nbsp;<br>\");' onmouseout='return nd();'><b><img src='" + rpath + "/route.gif'></b></a>")
    } else {
        Text("<a href='map.html?region=" + region + "' target='_new' onmouseover='return overlib(\"<h3>Interaktive Karte</h3><center>Hier kannst du auf einer zoomfähigen Karte meine Reiseroute verfolgen</center>&nbsp;<br>\");' onmouseout='return nd();'><b>" + Text_Map + "</b></a>")
    }
}

function LinkShowAllImages(title)
{
        Line('<a href="javascript:ShowAllImages(' + "'" + Text_Photos + " " + title + "'" + ')" title="" onmouseover="return overlib(\'<h3>Alle Fotos anzeigen</h3><center>Hier kannst du auf der rechten Seite alle Fotos gleichzeitig in voller Grösse anzeigen lassen.<br>(Dies ist nur für schnelle Internetverbindungen empfohlen)</center>&nbsp;<br>\');" onmouseout="return nd();">' + Text_ShowAllPhotos + '</a>')
}

function NextPart(search)
{
var folder=GetArgValue("folder",search)
var partnr=StripPath(folder)
partnr=partnr.replace("part","")
var nextnr=partnr;
nextnr++;
list=folder.replace("worldtrip/","")
list=list.replace("/part" + partnr,"")
next="list=" + list + "&folder=part" + nextnr 
return next
}

function PrevPart(search)
{
var folder=GetArgValue("folder",search)
var partnr=StripPath(folder)
partnr=partnr.replace("part","")
var prevnr=partnr - 1;
list=folder.replace("worldtrip/","")
list=list.replace("/part" + partnr,"")
prev="list=" + list + "&folder=part" + prevnr     
return prev
}

function GotoHome(text)
{
    if (!text) {
        text = "Home"
    }
    _add("HOME=" + text)
}

//------------- maps ---------------------
function Map(text,lat,lon,scale,icon)
{
    if (!icon) { icon = "" } else { icon = "&icon=x" }
    url = "http://www.multimap.com/map/browse.cgi?mapsize=big&lat=" + lat + "&lon=" + lon + icon + "&scale=" + scale

    if (window.name == "GalleryFrame") {
        _add("MAPS=" + url,text)
    } else {
        Text("<a href='"+ url + "' target='_new'>" + text + "</a>")
//        ListStart()
//        Text("<li><a href='"+ url + "'>" + text + "</a><br><div align='left'></div></li>")
//        ListEnd()
    }
}

//---------------------------------------
function PopImage(bild,txt) {
    if (!txt) { txt = ""  }
    window.document.write("<a href='popimage.html?file=" + bild + ".jpg&title=" + txt +  "' target='_blank' onclick='return popup(this.href);'><img src=" + bild + "_th.jpg title='" + txt + "' style='vertical-align:middle' hspace='6px'></a>")
}


//--------- inline popup-image ----------
//Verwendung: Text(popimg("la1_001","Anzeigetext 1") + popimg("la1_002","Anzeigetext 2"))
//Text(popimg("","") + popimg("","") + popimg("","") + popimg("","") +  "<br>")
function popimg(imgname,imgtext) {
if (imgname == "") {
    pi = ""
} else {
    pi = '&nbsp;<a onclick="return popup(this.href);" target="_blank" title="' + imgtext + '" href="popimage.html?title=' + imgtext + '&file=' + rpath + "/" + imgname + '.jpg"><img src="' + rpath + "/" + imgname+ '_th.jpg"/></a>&nbsp;'
}
return pi
}

function popup(url) {
    popwin=window.open(url, "Popupfenster", "width=640,height=720,resizable=yes,dependent=yes");
    popwin.focus();
    return false;
}
//---------------------------------------

