var ani = false;
var ani2 = false;
var stepb;
var bgCookie;
var bgurl;
var fullBg;
var xLang = lang == 'de' ? 'de' : 'en';

if(lang == 'en' || lang == 'jp'){
	var cLang = 'en';
}else if(lang == 'de'){
	var cLang = 'de'
}else if(lang == 'cn'){
	var cLang = 'cn'
}

tags = JSON.decode(tags);



//IE 6

//lokal testing
if (server == '192.168.128.13') {
    var lokal = true;
    var tmpDir = 'http://192.168.128.13/go4webdesk.ch/httpdocs/users/titlis3/upload/';
    var path = 'http://192.168.128.13/go4webdesk.ch/httpdocs/desk/prevsites/previewSite/';
}else {
    var lokal = false;
    var path = root;
    var tmpDir = root;
    var tmpDir = 'http://www.titlis.ch/upload/';
}


 var monthsA = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
 var daysA = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];

var monthsAe = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var daysAe = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

window.addEvent('domready', function(){
	
	$$('#social a img').each(function(soc){
		
		soc.addEvents({
			'click': function(){
				//console.log(soc.alt);
				
				
				new Request({
				            url: path + 'includes/socialcounter.php',
				            method: 'post',
				            data: 'mode=ajax&request=' + soc.alt,
				            onComplete: function(response){
							//console.log(response);	
					    }
			        }).send();
				        
			    }
				
		});	
		
	});
	

	
    if (lang == 'de') {
        MooTools.lang.set('en-US', 'Date', {
        
            months: ['Januar', 'Februar', 'Maerz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
            days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
            dateOrder: ['month', 'date', 'year', '/'],
            AM: "AM",
            PM: "PM",
            //members can be functions; these will be executed and passed any arguments with .get(member[,args])
            ordinal: function(dayOfMonth){
                return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
            },
            lessThanMinuteAgo: 'less than a minute ago',
            minuteAgo: 'about a minute ago',
            minutesAgo: '{delta} minutes ago',
            hourAgo: 'about an hour ago',
            hoursAgo: 'about {delta} hours ago',
            dayAgo: '1 day ago',
            daysAgo: '{delta} days ago',
            lessThanMinuteUntil: 'less than a minute from now',
            minuteUntil: 'about a minute from now',
            minutesUntil: '{delta} minutes from now',
            hourUntil: 'about an hour from now',
            hoursUntil: 'about {delta} hours from now',
            dayUntil: '1 day from now',
            daysUntil: '{delta} days from now'
        
        });
    }
    else {
        MooTools.lang.set('en-US', 'Date', {
        
            months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
            days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
            dateOrder: ['month', 'date', 'year', '/'],
            AM: "AM",
            PM: "PM",
            //members can be functions; these will be executed and passed any arguments with .get(member[,args])
            ordinal: function(dayOfMonth){
                return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
            },
            lessThanMinuteAgo: 'less than a minute ago',
            minuteAgo: 'about a minute ago',
            minutesAgo: '{delta} minutes ago',
            hourAgo: 'about an hour ago',
            hoursAgo: 'about {delta} hours ago',
            dayAgo: '1 day ago',
            daysAgo: '{delta} days ago',
            lessThanMinuteUntil: 'less than a minute from now',
            minuteUntil: 'about a minute from now',
            minutesUntil: '{delta} minutes from now',
            hourUntil: 'about an hour from now',
            hoursUntil: 'about {delta} hours from now',
            dayUntil: '1 day from now',
            daysUntil: '{delta} days from now'
        
        });
        
    }
    
    
    if (pType == 'main' && theme == 'ti') {
        $('webcam').addEvent('click', function(){
        
            var newani = new boxani();
            newani.tout(-1, 100, 170, 20, 500, 'close');
          
	  
	    if (lang == 'de') {
                setTimeout("followlink('" + path + "index.php?id=22')", 1300);
            }
            else if(lang == 'en') {
                setTimeout("followlink('" + path + "index.php?id=109')", 1300);
            }
	    else if(lang == 'jp') {
                setTimeout("followlink('" + path + "index.php?id=847')", 1300);
            }
	    else if(lang == 'cn') {
                setTimeout("followlink('" + path + "index.php?id=479')", 1300);
            }
            
        });
        
        
        $('snow').addEvent('click', function(){
        
            var newani = new boxani();
            newani.tout(-1, 100, 170, 20, 500, 'close');
            if (lang == 'de') {
                setTimeout("followlink('" + path + "index.php?id=359')", 1300);
            }
            else if(lang == 'en'){
                setTimeout("followlink('" + path + "index.php?id=360')", 1300);
            }
	    else if(lang == 'jp') {
                setTimeout("followlink('" + path + "index.php?id=842')", 1300);
            }
	    else if(lang == 'cn') {
                setTimeout("followlink('" + path + "index.php?id=474')", 1300);
            }
            
        });
        
        $('pas').addEvent('click', function(){
        
            var newani = new boxani();
            newani.tout(-1, 100, 170, 20, 500, 'close');
            if (lang == 'de') {
                setTimeout("followlink('" + path + "index.php?id=341')", 1300);
            }
            else if(lang == 'en'){
                setTimeout("followlink('" + path + "index.php?id=110')", 1300);
            }
	    else if(lang == 'jp') {
                setTimeout("followlink('" + path + "index.php?id=848')", 1300);
            }
	    else if(lang == 'cn') {
                setTimeout("followlink('" + path + "index.php?id=480')", 1300);
            }

            
        });
    }
    
    
    //Hintergrundbild
    rnd = $random(0, 1);
    if (pType != 'main') {
    
        if (lokal == true) {
            bgurl = 'url(' + picpath + ')';
            fullBg = picpath;
        }
        else {
            bgurl = 'url(' + root + picpath + ')';
            fullBg = root + picpath;
        }
        
        //BoxFollow Accordion
        new Accordion($$('dl#unav_boxes dt'), $$('dl#unav_boxes dd'), {
            fixedHeight: 179,
            opacity: 0,
            show: 0
        
        });
        
    }
    else {
        bgurl = 'url(' + root + 'images/mainpics/' + theme + '/home_' + rnd + '.jpg)';
        fullBg = root + 'images/mainpics/' + theme + '/home_' + rnd + '.jpg';
        
    }
    
    createMenu();
    
    //Boxani Startseiten, Aufruf und Init
    if (pType == 'main') {
        var newani = new boxani();
        
        try {
            stepb = $$('#boxes .bani').getElements('div').length;
            
            newani.tout(-1, 1200, 0, 200, 700, 'open');
            
        } 
        catch (err) {
        
        }
    }
    
    $('search').setStyles({
        'background-color': '#fff',
        'padding': '2px',
        'color': '#5F5F5F'
    });
    
    if (imapBtn  == 1) {
	makeMapLink();
    }
    
    if(tags) {
	
	
	
	if (tags.webcam == 1) {
	makeWebcamLinks();
	}
	
	if (tags.weather == 1) {
	showWeather();
	}
	
	if (tags.events == 1) {
	showAllEvents();
	}
	
	if (tags.winteraktD == 1) {
	showActivities('Winteraktivität');
	}
	
	if (tags.winteraktE == 1) {
	showActivities('Winter Activities');
	}
	
	if (tags.sommeraktD == 1) {
	
	showActivities('Sommeraktivität');
	}
	
	if (tags.sommeraktE == 1) {
	showActivities('Summer Activities');
	}
	
	if (tags.erlebnisD == 1) {
	showActivities('Erlebnisangebot');
	}
	
	if (tags.erlebnisE == 1) {
	showActivities('Special Mountain Offers');
	}
	
	
   }
   
   if (map == 'true') {
	gmap();
   }
    
    overlay = new Element('div', {
        'id': 'BoxOverlay',
        'styles': {
            'display': 'block',
            'z-index': '990',
            'position': 'absolute',
            'top': '0',
            'left': '0',
            'background-color': '#000',
            'opacity': 0
        }
    });
    
    overlay.injectInside(document.body);
    
    
    if (theme == 'ti' || pType != 'main') {
        //Events anzeigen
        showEventsBox();
    }
    
    
    //ZebraTables
    var zTables = new ZebraTables('tablemain');
    
    $('backgroundp').setStyle('opacity', 0);
    
    //FontCookie lesen
    if(pType != 'main'){
		 zoomSFont('reload');
	 }
    
    
    var allinps = $('main').getElements('input');
    
    
    allinps.each(function(theInput){
    
        theInput.addEvents({
            'focus': function(e){
                if ((theInput.value == "Suchbegriff" && theInput.id == "search") || (theInput.value == "search" && theInput.id == "search")) {
                    theInput.value = "";
                }
            },
            'blur': function(e){
                if (theInput.value == "" && theInput.id == "search") {
                    if (lang == 'de') {
                        theInput.value = "Suchbegriff";
                    }
                    else {
                        theInput.value = "search";
                    }
                    
                }
            }
        });
    });
    
    
    //Hauptseite Navi Klickverzögerung
    if (pType == 'main') {
    
        var alllink = $$('a');
        
        alllink.each(function(link, item, index){
			
		
			
            var sitelink = link.href;
            
			 if (link.hasClass('externlink') == false && link.get('html').indexOf('snowtubing') == -1) {
			 	link.href = '#';
			 }
			
            if (link.get('html').indexOf('snowtubing') == -1 && link.hasClass('externlink') == false && link.id != "fullscreen" && link.id != 'mediaLink' && link.id != 'homeLink' && link.hasClass('noani') == false) {
					            	
                link.addEvent('click', function(e){
                    if (anistat == 'open') {
                        var newani = new boxani();
                        newani.tout(-1, 100, 170, 20, 500, 'close');
                        setTimeout("followlink('" + sitelink + "')", 1300);
                    }
                    bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
                        duration: 1
                    });
                    
                });
            }
            
        });
        
    }
    else {
        var alllink = $$('a');
        
        alllink.each(function(link, item, index){
        
            if (link.id != "fullscreen" && link.id != 'mediaLink' && link.id != 'homeLink') {
                link.addEvent('click', function(e){
                
                    bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
                        duration: 1
                    });
                    
                });
            }
            
        });
        
        //Specials einlesen auf Folgeseiten
        if (lang == 'de') {
            pid = 1;
        }
        else {
            pid = 2;
        }
        var specials = new Request({
            url: path + 'index.php',
            method: 'post',
            data: 'mode=ajax&id=' + pid + '&reqCol=text, menuname',
            onComplete: function(response){
                txt = JSON.decode(response);
		if(txt.text.indexOf('[advent]')!=-1){
			 txt.text = txt.text.replace('[advent]', '<a href="#" onclick="adventsK()"><img id="advent" style="cursor:pointer" src="'+root+'images/advent.png" border="0" /></a>');
		}
                $$('#bc1 div')[0].set('html', txt.text);
            }
        }).send();
        
    }
    
    //INPUT HIGHLIGHTS
    var allinps = $('main').getElements('input');
    var fadein = function(){
        this.start({
            'background-color': '#ffffff'
        });
    }
    
    var fadeout = function(){
        this.start({
            'background-color': '#DFDFDF'
        });
    };
    
    //wetter
    if (pType == 'main' && theme == 'ti') {
        var reqData = {
            'get': 'ajax'
        };
	

        if (jsH > 12) {
            wicon = 1;
        } else if (jsH > 16) {
                wicon = 2;
        } else {
                wicon = 0;
        }
                
        new Request.JSON({
            url: path + 'includes/weather.php',
            method: 'post',
            data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
            onComplete: function(response){
            
                $('weather').set('html', '');
                //console.log(response[3].children[2].children[0].text);
                //console.log( response[3].children);	console.log("---->");
                try {
                
                
                    weathersymbol = response[4].children[2].children[wicon].text;
                    tmp = response[4].children[1].children[wicon].text;
                    
                    
                    
                    if (weathersymbol != undefined) {
                        $('weather').setStyle('background-image', 'url(' + root + 'images/weather/' + weathersymbol + '.png)');
                    }
                    
                    $('weather').addEvent('click', function(){
                    
                        var newani = new boxani();
                        newani.tout(-1, 100, 170, 20, 500, 'close');
                        if (lang == 'de') {
                            setTimeout("followlink('" + path + "index.php?id=24')", 1300);
                        }
                        else if (lang == 'en'){
                            setTimeout("followlink('" + path + "index.php?id=111')", 1300);
                        }
			else if (lang == 'jp'){
                            setTimeout("followlink('" + path + "index.php?id=849')", 1300);
                        }
			else if (lang == 'cn'){
                            setTimeout("followlink('" + path + "index.php?id=481')", 1300);
                        }
                        
                    });
                    
                    $('panel_val_temp').set('html', tmp + '&deg;C');
                } 
                catch (err) {
                }
            },
            onRequest: function(){
                $('weather').set('html', '<div style="padding:8px 0 0 0"><img src="' + root + 'images/loader.gif" width="16" height="16"></div>');
                $('panel_val_temp').set('html', 'lade');
                
            }
        }).send();
        
    }
    
    
    $('lang_menu').addEvent('mouseenter', function(e){
    
        var blenddown = new Fx.Tween($('lang_menu'), {
            duration: 120
        });
        blenddown.start('height', $('lang_menu').getStyle('height'), "68px");
    });
    
    $('lang_menu').addEvent('mouseleave', function(e){
    
        var blenddown = new Fx.Tween($('lang_menu'), {
            duration: 120
        });
        blenddown.start('height', $('lang_menu').getStyle('height'), "15px");
    });
    
    
    if (Cookie.read("bg") != bgurl) {
    
        $('pic').setStyle('background-image', bgurl);
        
        $('pic').setStyle('opacity', 0);
        var blenddown = new Fx.Tween($('pic'), {
            duration: 300
        });
        blenddown.start('opacity', 0, 1);
        bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
            duration: 1
        });
    }
    else {
        $('pic').setStyle('background-image', bgurl);
    }
    
    
    //BANNER einlesen!
    if(pType == 'main' && theme != 'ti'){
    	
	
	new Request.JSON({ 
			url: 'index.php'  
			,method: 'post'
			,data: 'mode=ajax&id=1&reqCol=text, title'
			,onComplete: function(response){
				
				//console.log(response)
				$$('#box_lastmin .hold')[0].set('html',response.text);
			}
	}).send();
		
	
    }
    
    
    
    //Reservations Button Aktion zuweisen
    
    /*$('btn_reservation').addEvent('click',function(e){
     createWin('Hotelreservation',resContent,'Hotelreservationen auf titlis.ch',358);
     });*/
    //Button Aktion zuweisen
    
    
    
    
    if ((pType == 'main' && theme == 'ti') || pType != 'main') {
        $('btn_erlebnisangebot').addEvent('click', function(e){
            var newani = new boxani();
            newani.tout(-1, 100, 170, 20, 500, 'close');
            if (lang == 'de') {
                setTimeout("followlink('" + path + "index.php?id=40')", 1300);
            }
            else if (lang == 'en'){
                setTimeout("followlink('" + path + "index.php?id=128')", 1300);
            }
	    else if (lang == 'cn'){
                setTimeout("followlink('" + path + "index.php?id=498')", 1300);
            }
	    else if (lang == 'jp'){
                setTimeout("followlink('" + path + "index.php?id=866')", 1300);
            }
			
        });
		
		//Adventskalender
		try{
			$('advent').addEvent('click',function(){
				txt = '<div style="width:100%;height:100%;background-color:#000;text-align:center"><iframe src="'+root+'kalender/index.html" width="800" height=100%" scrolling="auto" frameborder="0"></iframe></div>';
        		createWin('Adventskalender', txt, 'Adventskalender 2009', 600);
			});
		}catch(err){}
        
        $('btn_erlebnisangebot').addEvent('click', function(e){
            if (pType == 'main') {
                var newani = new boxani();
                newani.tout(-1, 100, 170, 20, 500, 'close');
                if (lang == 'de') {
                    setTimeout("followlink('" + path + "index.php?id=40')", 1300);
                }
                 else if (lang == 'en'){
                setTimeout("followlink('" + path + "index.php?id=128')", 1300);
            }
	    else if (lang == 'cn'){
                setTimeout("followlink('" + path + "index.php?id=498')", 1300);
            }
	    else if (lang == 'jp'){
                setTimeout("followlink('" + path + "index.php?id=866')", 1300);
            }
            }
            else {
                if (lang == 'de') {
                    followlink(path + "index.php?id=40");
                }
                else if (lang == 'en') {
                    followlink(path + "index.php?id=128");
                }
		else if (lang == 'cn') {
                    followlink(path + "index.php?id=498");
                }
		else if (lang == 'jp') {
                    followlink(path + "index.php?id=866");
                }
            }
        });
        
        $('btn_tickets').addEvent('click', function(e){
            txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://axess.at/skipass.cx/skipass/oshop.php?locale='+xLang+'&projectId=355&projectName=Engelberg" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
            createWin('tickets', txt, 'Tickets', 600);
            
            //window.open('<a href="https://axess.at/skipass.cx/skipass/oshop.php?locale=de&projectId=355&projectName=Engelberg" target="_blank">','Tickets');
        });
        
        $('btn_shop').addEvent('click', function(e){
            if (pType == 'main') {
                var newani = new boxani();
                newani.tout(-1, 100, 170, 20, 500, 'close');
                if (lang == 'de') {
                    setTimeout("followlink('" + path + "index.php?id=1129')", 1300);
                }
                else if (lang == 'en'){
                    setTimeout("followlink('" + path + "index.php?id=1130')", 1300);
                }
		else if (lang == 'cn'){
                    setTimeout("followlink('" + path + "index.php?id=1132')", 1300);
                }
		else if (lang == 'jp'){
                    setTimeout("followlink('" + path + "index.php?id=1131')", 1300);
                }
            }
            else {
                if (lang == 'de') {
                    followlink(path + "index.php?id=1129");
                }
                else if(lang == 'en') {
                    followlink(path + "index.php?id=1130");
                }
		else if (lang == 'cn'){
                    setTimeout("followlink('" + path + "index.php?id=1132')", 1300);
                }
		else if (lang == 'jp'){
                    setTimeout("followlink('" + path + "index.php?id=1131')", 1300);
                }
            }
        });
	
	$('btn_passes').addEvent('click', function(e){
            if (pType == 'main') {
                var newani = new boxani();
                newani.tout(-1, 100, 170, 20, 500, 'close');
                if (lang == 'de') {
                    setTimeout("followlink('" + path + "index.php?id=301')", 1300);
                }
                else if (lang == 'en'){
                    setTimeout("followlink('" + path + "index.php?id=347')", 1300);
                }
		else if (lang == 'cn'){
                    setTimeout("followlink('" + path + "index.php?id=717')", 1300);
                }
		else if (lang == 'jp'){
                    setTimeout("followlink('" + path + "index.php?id=1085')", 1300);
                }
            }
            else {
                if (lang == 'de') {
                    followlink(path + "index.php?id=301");
                }
                else if(lang == 'en') {
                    followlink(path + "index.php?id=347");
                }
		else if (lang == 'cn'){
                    setTimeout("followlink('" + path + "index.php?id=717')", 1300);
                }
		else if (lang == 'jp'){
                    setTimeout("followlink('" + path + "index.php?id=1085')", 1300);
                }
            }
        });
        
        
   }
    
    $('mediapic').setStyle('cursor', 'pointer');
    
    $('mediapic').addEvent('click', function(e){
        MediaGallery();
    });
    
	
	
	
	if((theme == 'te' || theme == 'tr') && pType == 'main'){
		new DatePicker($('date1'),{days:['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],months:['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],format:'d.m.Y',inputOutputFormat:'Ymd',pickerClass:'datepicker_jqui'});
		new DatePicker($('date2'),{days:['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],months:['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],format:'d.m.Y',inputOutputFormat:'Ymd',pickerClass:'datepicker_jqui'});
	}
	
	
    $('btn_reservation').addEvent('click', function(e){
		
		try{
			if($('date1').value == ''){
		
				aDate = tdy;
			}else{
				aDate = $('date1').value;
			}
		
			if($('date2').value == ''){
			
				dDate = tdy;
			}else{
				dDate = $('date2').value ;
			}	
		}catch(err){
			aDate = tdy;
			dDate = tdy;
		}
		
	
        if (theme == 'ti') {
            txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/Default.aspx?applanguage=' + xLang + '" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
        }
        else 
            if (theme == 'te') {
				
                txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/reserv.aspx?hotelref=3&applanguage=' + xLang + '&arrdate='+aDate+'&Depdate='+dDate+'&number='+$('zimmer').value+'" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
            }
            else 
                if (theme == 'tr') {
                    txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/reserv.aspx?hotelref=2&applanguage=' + xLang + '&arrdate='+aDate+'&Depdate='+dDate+'&number='+$('zimmer').value+'" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
                }

        createWin('reservation', txt, 'Reservation', 600);
    });
    
    //Scroller
    if (pType != 'main' && shop != 'true') {
        $('track').setStyle('display', 'none');
        $('thumb').setStyle('display', 'none');
        
        makeScrollbar($('content_text'), $('track'), $('thumb'));
        
    }
    
    
    getScreen();
    
    if (tags) {
    	
	if (tags.live == 1) {
		new Accordion($$('div.toggler'), $$('div.element'), {
			display: 0,
			opacity: 0,
			onActive: function(toggler, element){
				toggler.getChildren()[0].set('src', root + 'images/minus.gif');
			},
			onBackground: function(toggler, element){
				toggler.getChildren()[0].set('src', root + 'images/plus.gif');
			}
		});
	}
    }
});


function adventsK(){
	
		txt = '<div style="width:100%;height:100%;background-color:#000;text-align:center"><iframe src="'+root+'kalender/index.html" width="800" height=100%" scrolling="auto" frameborder="0"></iframe></div>';
		createWin('Adventskalender', txt, 'Adventskalender 2009', 600);
		
}

function followlink(link){
    window.location.href = link;
}

function showWeather(){
    var reqData = {
        'get': 'ajax'
    };
	
	
	
    hr = jsH;
    
    //console.log(jstime);
    
    new Request.JSON({
        url: path + 'includes/weather.php',
        method: 'post',
        data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
            try {
            
                tab = new Element('table', {
                    'id': 'weatherTable',
                    'cellpadding': '0',
                    'cellspacing': '0',
                    'border': '0',
                    'width': '420',
                    'height': '1%'
                });
                
				
		try{
			 tab.injectBefore($$('div.text')[0]);
		}catch(err){
			tab.injectInside($('content_text'));
		}
               
                
               // tab.injectBefore($('betrieb'));
                
                thead = new Element('thead').inject(tab);
                tbody = new Element('tbody').inject(tab);
                
                headTR = new Element('tr').injectInside(thead);
                
                if (lang == 'de') {
                    dtimes = ['Vormittag', 'Nachmittag', 'Abend'];
                }
                else {
                    dtimes = ['Morning', 'Afternoon', 'Evening'];
                }
                
                for (p = 0; p < 3; p++) {
                    headTD = new Element('td', {
                        'html': '<b>' + dtimes[p] + '</b>',
                        'align': 'center',
                        'styles': {
                            'padding': '5px 0 5px 6px',
                            'background-image': 'url(' + root + 'images/dateheader.png)',
                            'color': '#fff'
                        }
                    
                    }).injectInside(headTR);
                }
                
                
                //console.log(response);
                n = 0;
                p = 0;
                for (x = 0; x < 8; x++) {
                
                    if (x % 2 == false) {
                    
                        trday = new Element('tr').injectInside(tbody);
                        
			wDate = response[4].children[2].children[n].attributes.datetime.split('-');
			
			if(parseInt(pwday)+p > 6){
				p=0;
				pwday=0;
				if(lang=='de'){
					tag = daysA[0];
				}else{
					tag = daysAe[0];
				}
				
			}else{
				if (lang == 'de') {
					tag = daysA[parseInt(pwday) + p];
				}else{
					tag = daysAe[parseInt(pwday) + p];
				}
			}
			
			d = wDate[2].split(' ');
			
			if (lang == 'de') {
						
				wDate = tag + ', ' + d[0] + '.' + monthsA[parseInt(wDate[1]) - 1] + ' ' + wDate[0];
			}else{
				wDate = tag + ', ' + d[0] + '.' + monthsAe[parseInt(wDate[1]) - 1] + ' ' + wDate[0];
			}
					
                        tdday = new Element('td', {
                            'html': wDate,
                            'bgcolor': '#eeeeee',
                            'colspan': 3,
                            'styles': {
                                'padding': '4px 0 4px 4px'
                            }
                        
                        }).injectInside(trday);
			p++;
                    }
                    
                    tr = new Element('tr').injectInside(tbody);
                    
                    for (i = 0; i < 3; i++) {
                    
                        if (x % 2 == false) {
                        
                            weathersymbol = response[4].children[2].children[i + n].text;
                            inhtml = '<img src="' + root + 'images/weather/' + weathersymbol + '.png">';
                            border = '1px #ccc solid';
                        }
                        else {
                            inhtml = response[4].children[1].children[i + n].text + '&deg;C';
                            border = '1px #fff solid';
                        }
                        
                        td = new Element('td', {
                            'html': inhtml,
                            'width': '140',
                            'align': 'center',
                            'styles': {
                                'padding': '5px 0',
                                'border-bottom': border
                            }
                        
                        }).injectInside(tr);
                    }
                    
                    if (x % 2 == true) {
                        n = n + 3;
                    }
                    
                }
                
            } 
            catch (err) {
				
				
            }
        },
        onRequest: function(){
        
        
        }
    }).send();
    
    
}



//BOXANIMATIONSKLASSE für Startseiten
var anistat = 'closed';

function boxani(){

    this.ani = function(it, marg, h, dur, direction){
    
        if ((anistat == 'closed' && marg == 0) || (anistat == 'open' && marg == 170)) {
        
            it++;
            
            var boxes = $$('#boxes .bani');
            
            if (it < stepb) {
            
                if (direction == 'close') {
                    var dur1 = dur
                    var dur2 = dur / 2
                }
                else {
                    var dur2 = dur
                    var dur1 = dur / 2
                }
                
                var morphElement = boxes[it];
                var morphObject = new Fx.Morph(morphElement, {
                    fps: 60,
                    duration: dur2,
                    onComplete: function(){
                    
                        var morphObject2 = new Fx.Morph(morphElement, {
                            fps: 60,
                            duration: dur1,
                            onComplete: function(){
                            
                                if (marg == 170) {
                                    anistat = 'closed';
                                }
                                else {
                                    anistat = 'open'
                                    
                                }
                            }
                        });
                        
                        if (direction == 'close') {
                            morphObject2.start({
                                'margin-top': marg
                            });
                        }
                        else {
                            morphObject2.start({
                                'height': h
                            });
                        }
                        
                    }
                    
                });
                
                if (direction == 'close') {
                    morphObject.start({
                        'height': h
                    });
                }
                else {
                    morphObject.start({
                        'margin-top': marg
                    });
                }
                
                var t = 10;
                this.tout(it, t, marg, h, dur, direction);
                
            }
        }
    }
    
    this.tout = function(it, t, marg, h, dur, direction){
    
        var newani = new boxani();
        setTimeout(function(){
            newani.ani(it, marg, h, dur, direction);
        }, t);
        
    }
    
}


function collectionToArray(collection)
{
	var ary = [];
	for(var i=0, len = collection.length; i < len; i++)
	{
		ary.push(collection[i]);
	}
	return ary;
}

//Schriftzoom
function zoomSFont(Fsize){

	
	subcont = ['div','td','a','h1'];


	if(Fsize != 'reload'){
		Cookie.write('fontsize',Fsize);
	}
	
	var Fsize = Cookie.read('fontsize') || $('content_text').getStyle('font-size'); 
   	
	
	subcont.each(function(sub){
		
		zSize = sub == 'h1' ? parseInt(Fsize) + 4 : Fsize;
		
		
		
		contArr = $$('#content_text '+sub);
		
		
		
		contArr.each(function(cont){
			
			
			if(cont.id != 'zoom' && cont.id != 'zoomSmall' && cont.id != 'zoomBig'){
				
				
				try{
					cont.setStyle('font-size', zSize + "px")
				}catch(err){

				}
				
			}
			
		});
		
	});

	if (pType != 'main' && shop != 'true') {
		makeScrollbar($('content_text'), $('track'), $('thumb'));
	}
}

function chngScreen(){

    scrsize = Cookie.read("scrsize");
    if (scrsize == 'small') {
        bigScreen();
    }
    else 
        if (scrsize == 'big') {
            smallScreen();
        }
    
}

function getScreen(){

    scrsize = Cookie.read("scrsize");
    
    if (scrsize == 'small') {
        smallScreen();
    }
    else 
        if (scrsize == 'big') {
            bigScreen();
        }
        else {
            smallScreen();
        }
}

//normale Ansicht
function smallScreen(){

    $('img_fullscreen').src = root + 'images/fullscreen.png';
    
    var myCookie = Cookie.write('scrsize', 'small', {
        duration: 999
    });
    
    //$('backgroundp').src = fullBg;
    
    $('main').setStyle('background-color', '#ffffff');
    $('main').setStyle('background-image', 'url(' + root + 'images/mainbg.png)');
    $('pic').setStyle('background-image', bgurl);
    $('backgroundp').setStyle('opacity', 0);
    $('footer').setStyles({
        'width': '987px',
        'background-color': 'transparent',
        'position': 'relative',
        'opacity': 1
    });
    
    $('fr').setStyles({
        'right': '0',
        'padding': '0'
    });
    
    $('fl').setStyles({
        'left': '0'
    });
}

//Zoomansicht mit Vollbild
function bigScreen(){

    $('img_fullscreen').src = root + 'images/fullscreen_off.png';
    
    var myCookie = Cookie.write('scrsize', 'big', {
        duration: 999
    });
    $('backgroundp').src = fullBg;
    $('main').setStyle('background-image', 'none');
    $('main').setStyle('background-color', 'transparent');
    $('pic').setStyle('background-image', 'none');
    $('backgroundp').setStyle('opacity', 1);
    
    //alert($('pic').getStyle('background-image'));
    
    $('footer').setStyles({
        'width': '100%',
        'background-color': '#fff',
        'position': 'fixed',
        'bottom': '0px',
        'height': '18px',
        'opacity': 0.3,
        'padding': '2px 0 3px 0'
    });
    
    $('fr').setStyles({
        'right': '10px',
        'padding': '3px 0 0 0'
    });
    
    $('fl').setStyles({
        'left': '10px'
    });
}

//Start-und Folgeseite Anzeige Events in Boxen
function showEventsBox(){
	
    //alert(lang);	
    var reqData = {
        'type': 'all',
        'user': 'titlis3',
        'table': {
            'listings_news': 'l',
            'listingrows_news': 'lr',
            'listingdatas_news': 'ld'
        },
        
        'condition': {
            //,' AND lr.rubrikname =': mod
        },
        
        'fields': 'ld.*,lr.id,l.rowID',
        'order': 'ld.datum ASC LIMIT 3',
        'language': xLang
    };
    
    var allEv = new Request({
        url: path + 'index.php',
        method: 'post',
        data: 'mode=verzeichnis&local=0&debug=0&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
        
            if (pType == 'main') {
                $$('#box_event div.hold')[0].set('html', '');
            }
            
            if (lang == 'de') {
                pid = 33;
            }
            else if (lang == 'en'){
                pid = 120;
            }
	    else if (lang == 'cn'){
                pid = 490;
            }
	     else if (lang == 'jp'){
                pid = 858;
            }
            
            response = JSON.decode(response);
            allEvents = response.result;
	    
	    //console.log(allEvents);
            
            dNow = new Date();
            
            allEvents.each(function(e,key){

		   padT = key == 0 ? 0 : 8;
		   
		  // console.log( e.ld.datum);
		   
		    wDate = e.ld.datum.split('-');
		    d = wDate[2].split(' ');
			
			
		   wDate[1] = wDate[1].replace( /^(0+)/g, '' );
		    
		    if(lang == 'de'){
		    	 evDate = d[0]+'. '+monthsA[parseInt(wDate[1]) - 1]+' '+wDate[0];
		    }else{
		    	 evDate = d[0]+'. '+monthsAe[parseInt(wDate[1]) - 1]+' '+wDate[0];
		    }
		    
				    
		  
		  cDate =  evDate = d[0]+'.'+parseInt(wDate[1])+'.'+wDate[0];

                    
                    if (pType == 'main') {
                        tmp = $$('#box_event div.hold')[0].get('html');
                        $$('#box_event div.hold')[0].set('html', tmp+'<div style="padding:'+padT+'px 0 0 0">' + evDate.replace('ae','ä') + '<br/><a href="#" onclick="openEvent(\'index.php?id=' + pid + '\',\'' + cDate + '\',\'' + e.ld.id + '\');return false">' + e.ld.title + '</a></div>');
                    }
                    else {
                        tmp = $$('#bc4 .hold')[0].get('html');
                        $$('#bc4 .hold')[0].set('html', tmp +'<div style="padding:'+padT+'px 0 0 0">'+ evDate.replace('ae','ä')  + '<br/><a href="#" onclick="openEvent(\'index.php?id=' + pid + '\',\'' + cDate + '\',\'' + e.ld.id + '\');return false">' + e.ld.title + '</a></div>');
                    }
                
            });
            
            if (lang == 'de') {
                str = 'alle Events anzeigen';
            }
            else {
                str = 'show all events';
            }
            
            if (pType == 'main') {
                tmp = $$('#box_event div.hold')[0].get('html');
                $$('#box_event div.hold')[0].set('html', tmp + '<br/><button onclick="followlink(\'' + path + 'index.php?id=' + pid + '\')">' + str + '</button>');
            }
            else {
                tmp = $$('#bc4 .hold')[0].get('html');
                
                $$('#bc4 .hold')[0].set('html', tmp + '<br/><button onclick="window.location.href=\'' + path + 'index.php?id=' + pid + '\'">' + str + '</button>');
            }
            
            
        },
        onRequest: function(){
            if (pType == 'main') {
                $$('#box_event div.hold')[0].set('html', 'lade Events...');
            }
        }
    }).send();
}

//Klick auf Event 
function openEvent(page, evDate, evId){

   	eDatum = evDate.split('.');
    	evMonth = eDatum[1]-1;
	evYear = eDatum[2];
    
    if (pType == 'main') {
        var newani = new boxani();
        newani.tout(-1, 100, 170, 20, 500, 'close');
        setTimeout("followlink('" + path + page + "&evMonth=" + evMonth + "&evId=" + evId + "&evYear=" + evYear + "')", 1300);
    }
    else {
    
        followlink(path + page + "&evMonth=" + evMonth + "&evId=" + evId + "&evYear=" + evYear);
    }
    
}

//Events anzeigen, aktueller Monat oder gewählter Event
function showAllEvents(){

    try {
    
        var eurl = window.location.href.split('&evMonth=');
        
        chEv = decodeURI(eurl[1]);
        
        chEv = eurl[1].split('&evId=');
        
        chMonth = chEv[0];
        chId = chEv[1].split('&evYear=')[0];
        chYear = chEv[1].split('&evYear=')[1];
        /*
         console.log(chId);
         console.log(chYear);
         console.log(chMonth);*/
    } 
    catch (err) {
    }
    
    //mod = "Events";
    
    var reqData = {
        'type': 'all',
        'user': 'titlis3',
        'table': {
            'listings_news': 'l',
            'listingrows_news': 'lr',
            'listingdatas_news': 'ld'
        },
        
        'condition': {
            //,' AND lr.rubrikname =': mod
        },
        
        'fields': 'ld.*,lr.id,l.rowID',
        'order': 'ld.datum ASC',
        'language': xLang
    };
    
    
    
    var allEv = new Request({
        url: path + 'index.php',
        method: 'post',
        data: 'mode=verzeichnis&local=0&debug=1&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
            response = JSON.decode(response);
            allEvents = response.result;
            
            var thisMonth = new Date();
            
            //wenn bestimmter event von startseite angeklickt
            try {
                thisMonth.set('month', chMonth);
                thisMonth.set('year', chYear);
            } 
            catch (err) {
            }
	    
	    //Eventsbutton für PDF-Generierung
	    var tmp = parseInt(thisMonth.get('month'))+1;

	    new Element('img', {
	    		'id': 'eBtn'
	        	,'src': root+'images/eBtn.jpg'
			,'width': 150
			,'height': 22
			,'styles':{
				'position': 'absolute'
				,'top': 85
				,'right': 20
				,'cursor': 'pointer'
			},events:{
				'click': function(){
					
					//window.location.href = 'http://www.titlis.ch/pdfgen/events.php?month='+tmp
					n = 'http://www.titlis.ch/pdfgen/events.php?month='+tmp;
					window.open(n, 'titlis', "");
  					
				}
			}
	                
	    }).injectInside($('content'));
            
            thisMonth = thisMonth.format('%B %Y');

            if (lang == 'de') {
                st = 'Events als RSS abonnieren';
            }
            else {
                st = 'RSS';
            }
            
            rss = new Element('div', {
                'html': '<div style="float:left"><img style="margin-bottom:25px;" src="' + root + 'images/rss.png"/></div><div style="float:left;padding:3px 0 0 20px"><a href="http://www.titlis.ch/includes/titlis_events_' + xLang + '.xml" target="_blank">' + st + '</a></div>',
                'styles': {
                    'height': 30
                
                }
            });
	    
	    rss.addEvents({
	    	'click': function(){
			new Request({
			            url: path + 'includes/socialcounter.php',
			            method: 'post',
			            data: 'mode=ajax&request=rss',
			            onComplete: function(response){
														
				    }
		        }).send();
		}
	    });
	    
	    
            rss.injectInside($('content_text'));
            
            cle = new Element('div', {
                'styles': {
                    'clear': 'both'
                }
            });
            
            cle.injectInside($('content_text'));
            
            prv = new Element('div', {
                'styles': {
                    'float': 'left',
                    'height': 21,
                    'width': 30,
                    'background-image': 'url(' + root + 'images/media_prv.png)',
                    'cursor': 'pointer'
                },
                'events': {
                    'click': function(){
                    
                        showMonth('prev', response);
                        
                    }
                }
            });
            
            prv.injectInside($('content_text'));
            
            monthdiv = new Element('div', {
                'id': 'mnthdiv',
                'styles': {
                    'float': 'left',
                    'height': 20,
                    'padding': '1px 0 0 0',
                    'font-size': '12px',
                    'font-weight': 'bold',
                    'width': 360,
                    'background-image': 'url(' + root + 'images/dateheader.png)',
                    'text-align': 'center',
                    'color': '#fff'
                }
            });
            
            monthdiv.injectInside($('content_text'));
            
            monthtxt = new Element('div', {
                'id': 'mnthtxt',
                'styles': {
                    'padding-top': '3px',
                    'color': '#fff'
                },
                'html': thisMonth.replace('ae','ä') 
            });
            
            monthtxt.injectInside(monthdiv);
            
            nxt = new Element('div', {
                'styles': {
                    'float': 'left',
                    'height': 21,
                    'width': 30,
                    'background-image': 'url(' + root + 'images/media_nxt.png)',
                    'cursor': 'pointer'
                },
                'events': {
                    'click': function(){
                    
                        showMonth('nxt', response);
                        
                    }
                }
            });
            
            nxt.injectInside($('content_text'));
            
            cle = new Element('div', {
                'styles': {
                    'clear': 'both'
                }
            });
            
            cle.injectInside($('content_text'));
            
            resDiv = new Element('div', {
                'id': 'resDiv',
                'styles': {
                
                    'position': 'relative',
                    'width': 420
                }
            });
            
            resDiv.injectInside($('content_text'));
            
            
            mainDl = new Element('dl', {
                'id': 'acc'
            });
            
            mainDl.injectInside($('resDiv'));
            
            secDl = new Element('dl', {
                'id': 'secDl',
                'styles': {
                    'margin': 0,
                    'padding': 0
                }
            });
            
            secDl.injectInside(mainDl);
            
            counter = 0;
            chElement = 0;
            
            allEvents.each(function(e,key){

                dToday = new Date();
                
                rToday = new Date();
                
                //wenn bestimmter event von startseite angeklickt
                try {
                    dToday.set('month', chMonth);
                    dToday.set('year', chYear);
                } 
                catch (err) {
                }
                
		eDatum = e.ld.datum.split('-');
		
		d = eDatum[2].split(' ');
		//eMonth = parseInt(eDatum[1]);
		eYear =  eDatum[0];
		eDay = d[0];
		eMonth = eDatum[1].replace( /^(0+)/g, '' );
		
		
		
		
                if (parseInt(dToday.get('month'))+1 == eMonth && dToday.get('year') == eYear) {
                
                
                    try {
                        if (chId == e.ld.id) {
                            chElement = counter;
                        }
                    } 
                    catch (err) {
                    }
                    
                    eventDate = eDay+'.'+eMonth+'.'+eYear;
                    
                    evDiv = new Element('dt', {
                        'html': '<div style="float:left"><b>' + eventDate + '</b></div><div style="float:left;padding:0 0 0 38px">' + e.ld.title + '</div>',
                        'styles': {
                            'height': 14,
                            'width': 400,
                            'margin': '1px 0 0 0',
                            'padding': '3px 10px 3px 10px',
                            'background-color': '#EFEFEF',
                            'cursor': 'pointer'
                        }
                    });
                    
                    evDiv.injectInside(secDl);
                    
                    try {
                        txt = e.ld.text;
                        if (lang == 'de') {
                            infolink = 'mehr Informationen';
                        }else {
                            infolink = 'more information';
                        }
                        
                        if (txt.text[0].length > 180) {
                            shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'events\');return false;">' + infolink + '</a>]<br/><br/>';
                        }else {
                            shortText = txt.text[0];
                        }
                    } 
                    catch (err) {
                        if (lang == 'de') {
                            shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
                        }
                        else {
                            shortText = "information about this event will follow in short time.<br/><br/>";
                        }
                    }
                    
                    if (e.ld.pictures != "") {
                    
                        ASDpic = e.ld.pictures;
                        picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ASDpic.media[0].name + '"/></div>';
                        
                    }
                    else {
                        picKl = '';
                    }
                    
                    evCont = new Element('dd', {
                        'html': '<div style="padding:10px 0 10px 0">' + picKl + '<div style="float:left;width:310px;padding-left:20px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
                        'styles': {
                            'overflow-x': 'hidden',
                            'overflow-y': 'hidden',
                            'height': '15px',
                            'margin': 0
                        }
                    });
                    
                    evCont.injectInside(secDl);
                    
                    counter++;
                }
                
            });
	    
	    if(xLang == 'de'){
	    	noE = 'keine aktuellen Einträge in diesem Monat';
	    }else{
	    	noE = 'no entries found';
	    }
	    
	    if(counter == 0){
	    	 evDiv = new Element('div', {
                        'html': noE
                      
                 }).injectInside(secDl);;

	    }
	    
            new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
                display: chElement,
                opacity: 0
            });
            
        }
        
    }).send();
    
}

//Aktivitäten anzeigen
function showActivities(season){

    var reqData = {
        'type': 'all',
        'user': 'titlis3',
        'table': {
            'listings': 'l',
            'listingrows': 'lr',
            'listingdatas': 'ld'
        },
        
        'condition': {
            'ld.status': '1',
            'lr.rubrikname': season
        },
        
        'fields': 'ld.*,lr.id,l.rowID',
        'order': 'ld.position ASC',
        'language': cLang
    };
    
   
    
    var allAct = new Request({
        url: path + 'index.php',
        method: 'post',
        data: 'mode=verzeichnis&local=0&debug=0&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
            response = JSON.decode(response);
            allActivities = response.result;
            
            titleDiv = new Element('div', {
                'id': 'mnthdiv',
                'styles': {
                    'height': 20,
                    'padding': '1px 0 0 0',
                    'font-size': '12px',
                    'font-weight': 'bold',
                    'width': 420,
                    'background-image': 'url(' + root + 'images/dateheader.png)',
                    'text-align': 'center',
                    'color': '#fff'
                }
            });
            
            titleDiv.injectInside($('content_text'));
            
            titletxt = new Element('div', {
                'id': 'mnthtxt',
                'styles': {
                    'padding-top': '3px',
                    'color': '#fff'
                },
                'html': season
            });
            
            titletxt.injectInside(titleDiv);
            
            resDiv = new Element('div', {
                'id': 'resDiv',
                'styles': {
                    'margin': 0,
                    'padding': 0,
                    'position': 'relative',
                    'width': 420
                }
            });
            
            resDiv.injectInside($('content_text'));
            
            
            mainDl = new Element('dl', {
                'id': 'acc',
                'styles': {
                    'margin': 0,
                    'padding': 0
                }
            
            });
            
            mainDl.injectInside($('resDiv'));
            
            secDl = new Element('dl', {
                'id': 'secDl',
                'styles': {
                    'margin': 0,
                    'padding': 0
                }
            });
            
            secDl.injectInside(mainDl);
            
            
            allActivities.each(function(e){
            
                evDiv = new Element('dt', {
                    'html': '<b>' + e.ld.titel + '</b>',
                    'styles': {
                        'height': 14,
                        'width': 400,
                        'margin': '1px 0 0 0',
                        'padding': '3px 10px 3px 10px',
                        'background-color': '#EFEFEF',
                        'cursor': 'pointer'
                    }
                });
                
                evDiv.injectInside(secDl);
                
                
                try {
                    txt = e.ld.text;
                    if (lang == 'de') {
                        infolink = 'mehr Informationen';
                    }
                    else {
                        infolink = 'more information';
                    }
                    
                    if (txt.text[0].length > 180) {
                        shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'activities\');return false;">' + infolink + '</a>]<br/><br/>';
                    }
                    else {
                        shortText = txt.text[0];
                    }
                } 
                catch (err) {
                    if (lang == 'de') {
                        shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
                    }
                    else {
                        shortText = "information about this event will follow in short time.<br/><br/>";
                    }
                }
                
                if (e.ld.bilder != "") {
                    ADpic = e.ld.bilder;
                    picKl = '<div style="float:left;margin-bottom:10px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    
                }
                else {
                    picKl = '';
                    
                }
                
                evCont = new Element('dd', {
                    'html': '<div style="padding:10px 0 10px 0">' + picKl + '<div style="float:left;width:300px;padding-left:20px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
                    'styles': {
                        'overflow-x': 'hidden',
                        'overflow-y': 'hidden',
                        'height': '15px',
                        'margin': 0
                    }
                });
                
                evCont.injectInside(secDl);
                
                
            });
            
            new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
                display: 0,
                opacity: 0
            });
            
        }
        
    }).send();
    
}

var dNext;
var dirC = 0;
var stopper;
//Eventmodul Monat anzeigen -> Direktlink auf Event
function showMonth(dir, response){
	
    allEvents = response.result;
    
    if (dir == 'nxt') {
        dirC++;
    }
    else {
        dirC--;
    }
	
	
    
    dToday = new Date();
	
    dNext = dToday;
    
    dNext.set('hr', 0);
    dNext.set('min', 0);
    dNext.set('date', 1);
	
    dNext = dNext.set('month', dNext.get('month') + dirC);
	

    dToday = new Date();
    
    
    dToday.set('hr', 0);
    dToday.set('min', 0);
    dToday.set('date', 1);
    
    
    
    var tmp = parseInt(dNext.get('month'))+1;
    
    
    $('eBtn').removeEvent('click');
    $('eBtn').addEvents({
    	'click': function(){
		
		window.location.href = 'http://www.titlis.ch/pdfgen/events.php?month='+tmp
	}
    })
    
    
    if (dNext >= dToday) {
    
        $('resDiv').empty();
        
        morphElement = $('mnthtxt');
        morphObject = new Fx.Morph(morphElement, {
            fps: 60,
            duration: 400,
            onComplete: function(){
                $('mnthtxt').set('html', dNext.format('%B %Y').replace('ae','ä') );
                
			
		
                morphElement2 = $('mnthtxt');
                
                morphObject2 = new Fx.Morph(morphElement2, {
                    fps: 60,
                    duration: 400
                });
                
                morphObject2.start({
                    'opacity': 1
                });
                
            }
        });
        
        
        morphObject.start({
            'opacity': 0
        });
        
        
        mainDl = new Element('dl', {
            'id': 'acc',
            'styles': {
                'margin': 0,
                'padding': 0
            }
        
        });
        
        mainDl.injectInside($('resDiv'));
        
        secDl = new Element('dl', {
            'id': 'secDl',
            'styles': {
                'margin': 0,
                'padding': 0
            }
        });
        
        secDl.injectInside(mainDl);
       
       counter = 0;
       
        allEvents.each(function(e){
        	
	    selectedDate = (dNext);
	   
	    
	    	eDatum = e.ld.datum.split('-');
		
	
		
		d = eDatum[2].split(' ');
		//eMonth = parseInt(eDatum[1]);
		eYear =  eDatum[0];
		eDay = d[0];
	    	eMonth = eDatum[1].replace( /^(0+)/g, '' );

            
            dToday = new Date();
            
	    
	   
           //console.log(e.ld.title+'--->'+eDatum+'------------>'+eMonth);
           
	   
            if (parseInt(selectedDate.get('month'))+1 == eMonth && selectedDate.get('year') == eYear) {
              
                eventDate = eDay+'.'+eMonth+'.'+eYear;
		
                evDiv = new Element('dt', {
                    'html': '<div style="float:left"><b>' + eventDate + '</b></div><div style="float:left;padding:0 0 0 38px">' + e.ld.title + '</div>',
                    'styles': {
                        'height': 14,
                        'width': 400,
                        'margin': '1px 0 0 0',
                        'padding': '3px 10px 3px 10px',
                        'background-color': '#EFEFEF',
                        'cursor': 'pointer'
                    }
                });
                
                evDiv.injectInside(secDl);
                
                try {
                    txt = e.ld.text;
                    if (lang == 'de') {
                        infolink = 'mehr Informationen';
                    }
                    else {
                        infolink = 'more information';
                    }
                    
                    
                    if (txt.text[0].length > 180) {
                        shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'events\');return false;">' + infolink + '</a>]<br/><br/>';
                    }
                    else {
                        shortText = txt.text[0];
                    }
                } 
                catch (err) {
                    if (lang == 'de') {
                        shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
                    }
                    else {
                        shortText = "information about this event will follow in short time.<br/><br/>";
                    }
                }
                
                
                if (e.ld.pictures != "") {
                
                    ADpic = e.ld.pictures;
                    picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    
                }
                else {
                
                    picKl = '';
                    ADpic = '';
                    
                }
                
                evCont = new Element('dd', {
                    'html': '<div style="padding:10px 0 10px 0">' + picKl + '<div style="float:left;width:310px;padding-left:20px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
                    'styles': {
                        'overflow-x': 'hidden',
                        'overflow-y': 'hidden',
                        'height': 0,
                        'padding': 0,
                        'margin': 0
                    }
                });
                
                evCont.injectInside(secDl);
                
                new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
                    opacity: 0
                });
               
	        counter ++; 
            }
           
        });
	
	
	 if(xLang == 'de'){
	    	noE = 'keine aktuellen Einträge in diesem Monat';
	    }else{
	    	noE = 'no entries found';
	    }
	    
	    if(counter == 0){
	    	 evDiv = new Element('div', {
	                'html': noE
	              
	         }).injectInside(secDl);;
	
	    }
	
    }
    else {
        dirC++;
        dToday = new Date();
        dNext = dToday;
    }
}



// Fenster für Verzeichnismodul
function openDetailVerz(win, id, type){

    if (type == "events") {
        var reqData = {
            'type': 'all',
            'user': 'titlis3',
            'table': {
                'listings_news': 'l',
                'listingrows_news': 'lr',
                'listingdatas_news': 'ld'
            },
            
            'condition': {
                'ld.id =': id
            },
            
            'fields': 'ld.*',
            'order': '',
            'language': xLang
        };
    }
    else {
        var reqData = {
            'type': 'all',
            'user': 'titlis3',
            'table': {
                'listings': 'l',
                'listingrows': 'lr',
                'listingdatas': 'ld'
            },
            
            'condition': {
                'ld.id =': id
            },
            
            'fields': 'ld.*,lr.id,l.rowID',
            'order': 'ld.titel ASC',
            'language': cLang
        };
    }
    
    
    var allEv = new Request({
        url: path + 'index.php',
        method: 'post',
        data: 'mode=verzeichnis&local=0&debug=0&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
            response = JSON.decode(response);
            EvDet = response.result[0];
            
            txt = EvDet.ld.text;
            if (type == 'events') {
                titel = EvDet.ld.title;
                if (EvDet.ld.pictures != "") {
                    ADpic = EvDet.ld.pictures;
                    picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    picGr = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '250_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    winTxt = picGr + '<div style="float:left;width:480px;padding-left:20px;margin-bottom:0px;">' + txt.text[0] + '</div>';
                    
                }
                else {
                    picKl = '';
                    winTxt = txt.text[0];
                }
            }
            else {
                titel = EvDet.ld.titel;
                if (EvDet.ld.bilder != "") {
                    ADpic = EvDet.ld.bilder;
                    picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    picGr = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '250_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    winTxt = picGr + '<div style="float:left;width:480px;padding-left:20px;margin-bottom:0px;">' + txt.text[0] + '</div>';
                    
                }
                else {
                    picKl = '';
                    winTxt = txt.text[0];
                }
            }

            createWin(win, winTxt, titel, 358);
            
        }
    }).send();
    
    
}
var trophy = false;
var fackelabfahrt = false;
var endspurt = false;
var knorrli = false;
var fireride = false;

function createWin(win, winTxt, title, winHeight){

    trophy = false;
    fackelabfahrt = false;
    endspurt = false;
    knorrli = false;
    fireride = false;
    
    if (winHeight > 500) {
        topmargin = '30px';
        winWidth = 900;
        
    }
    else {
        topmargin = '150px';
        winWidth = 768;
        
    }
    
    $('BoxOverlay').setStyles({
        width: window.getScrollWidth() + 'px',
        height: window.getScrollHeight() + 'px'
    });
    
    if (winHeight == 300) 
        winPad = '3px 20px 20px 20px';
    else 
        winPad = '60px 20px 20px 20px';
    
    if (win == 'reservation') {
        winWidth = 940;
    }
    
    
    
    center = winWidth / 2 + 20;
    
    if (win == 'map') {
        winPad = '23px 0 0 0';
        winWidth = 950;
        center = winWidth / 2;
        
        
    }
    
	if (win != 'Adventskalender') {
	
		evDetail = new Element('div', {
			'id': win,
			'styles': {
				'position': 'absolute',
				'width': winWidth,
				'top': topmargin,
				'left': '50%',
				'z-index': '999',
				'height': winHeight + 'px',
				'margin-left': '-' + center + 'px',
				'padding': winPad,
				'text-align': 'left',
				'overflow': 'hidden',
				
				'display': 'block',
				'opacity': 0,
				'background-color': '#fff'
			}
		});
	}else{
		evDetail = new Element('div', {
			'id': win,
			'styles': {
				'position': 'absolute',
				'width': winWidth,
				'top': topmargin,
				'left': '50%',
				'z-index': '999',
				'height': winHeight + 'px',
				'margin-left': '-' + center + 'px',
				'padding': winPad,
				'text-align': 'left',
				'overflow': 'hidden',
				'display': 'block',
				'opacity': 0,
				'background-color': '#000'
			}
		});
	}
    
    evDetail.injectBefore($('subnavcontainer'));
    
    //replace Forms
    
    if (winTxt.indexOf('[Anmeldeformular - trophy]') != -1) {
        winTxt = winTxt.replace('[Anmeldeformular - trophy]', '');
	trophy = true;
        form_trophy = form_trophy();
        
        
    }
	
	 if (winTxt.indexOf('[Anmeldeformular - endspurt]') != -1) {
        winTxt = winTxt.replace('[Anmeldeformular - endspurt]', '');
       form_endspurt = form_endspurt();
       endspurt = true;
        
    }
	    
    if (winTxt.indexOf('[Anmeldeformular - fackel]') != -1) {
        winTxt = winTxt.replace('[Anmeldeformular - fackel]', '');
	fackelabfahrt = true;
        form_fackelabfahrt = form_fackelabfahrt();
        
        
    }
    
    if (winTxt.indexOf('[Anmeldeformular - fireride]') != -1) {
        winTxt = winTxt.replace('[Anmeldeformular - fireride]', '');
         fireride = true;
        form_fireride = form_fireride();
       
        
    }
    
    if (winTxt.indexOf('[Anmeldeformular - knorrli]') != -1) {
        winTxt = winTxt.replace('[Anmeldeformular - knorrli]', '');
	 knorrli = true;
        form_knorrl = form_knorrli();
       
        
    }
    
    cont = new Element('div', {
        'id': 'wincont',
        'html': winTxt,
        'styles': {
            'overflow': 'hidden',
            'width': winWidth,
            'height': winHeight + 'px'
        }
    
    }).injectInside(evDetail);
    
    if (trophy == true) {
        form_trophy.injectInside(cont);
        AjaxSend($('resform'), $('wincont'));
    }
	
	if (endspurt == true) {
        form_endspurt.injectInside(cont);
        AjaxSend($('resform'), $('wincont'));
    }
    
    if (fireride == true) {
    
        form_fireride.injectInside(cont);
        AjaxSend($('resform'), $('wincont'));
    }
    
    if (fackelabfahrt == true) {
        form_fackelabfahrt.injectInside(cont);
        AjaxSend($('resform'), $('wincont'));
    }
    
    if (knorrli == true) {
        form_knorrli.injectInside(cont);
        AjaxSend($('resform'), $('wincont'));
    }
    
    
    
    window_track = new Element('div', {
        'id': 'window_track',
        'styles': {
            'left': winWidth + 30,
            'height': winHeight + 20
        
        }
    }).injectInside(evDetail);
    
    window_thumb = new Element('div', {
        'id': 'window_thumb'
    }).injectInside(window_track);
    
    makeScrollbar($('wincont'), $('window_track'), $('window_thumb'));
    
    var zTables = new ZebraTables('tablemain');
    
    titlebar = new Element('div', {
        'id': 'titlebar',
        'html': title,
        'styles': {
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'height': '18px',
            'padding': '5px 0 0 20px',
            'font-size': '11px',
            'font-weight': 'bold',
            'width': winWidth + 20,
            'background-image': 'url(' + root + 'images/dateheader.png)',
            'color': '#fff'
        }
    });
    
    titlebar.injectInside(evDetail);
    
    closer = new Element('div', {
        'id': 'closer',
        'styles': {
            'position': 'absolute',
            'top': '4px',
            'right': '10px'
        }
    }).injectInside($(win));
    
    closerA = new Element('a', {
        'href': 'javascript:closeOverlay("' + win + '")'
    }).injectInside(closer);
    
    closerImg = new Element('img', {
        'src': root + 'images/close_box.png',
        'border': 0
    }).injectInside(closerA);
    
    var fadein = new Fx.Tween($(win), {
        duration: 800
    });
    fadein.start('opacity', '0', '1');
    
    var fadein2 = new Fx.Tween($('BoxOverlay'), {
        duration: 500
    });
    fadein2.start('opacity', '0', '0.7');
}


function MediaGallery(){

    //xml schreiben
    
    var reqData = {
        'ajax': 'ajax'
    };
    
    var Gallery = new Request({
        url: path + 'mediaGallery/get_xml_content.php',
        method: 'post',
        data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
            //console.log(JSON.decode(response));
            
            txt = '<div style="position:absolute;bottom:0px;left:0;background-color:#F1F4F5;"><iframe src="' + root + 'mediaGallery/mediaGallery.php" width="808" height="415" scrolling="no" frameborder="0"></iframe></div>';
            createWin('gal', txt, 'Media Gallery', 358);
            
        }
    }).send();
    
}


function makeMapLink(){
	

    
    if ($defined($('interaktivekarte'))) {
	$('interaktivekarte').addEvent('click', function(e){
	
		mlang = xLang.substr(0, xLang.length - 1);
		
		mlang = mlang.toUpperCase();

		tmp_link = 'http://www.titlis.ch/karte/karte.php?karte=sommer&lang=' + mlang;
		
		
		var txt = '<iframe src="' + tmp_link + '" width="920" height="647" scrolling="no" frameborder="0"></iframe></div>';
		if (lang == 'de') {
			maptitle = 'Interaktive Karte';
		}
		else {
			maptitle = 'interactive map';
		}
		
		createWin('map', txt, maptitle, 650);
	});
}
    
    if($defined($('blitzkarte'))){
    	  $('blitzkarte').addEvent('click', function(e){
    
        tmp_link = 'http://www.titlis.ch/blitzkarte.jpg';
	
        var txt = '<img src="' + tmp_link + '"height="647"  />';
	
	if(xLang == 'de'){
		maptitle = 'Blitzkarte';
	}else{
		maptitle = 'Flash Map';
	}
        

        createWin('map', txt, maptitle, 650);
	$('wincont').setStyle('width',640);
	
	
	/*console.log("--");
	
	console.log(window.mIframe.document);*/
	
	
	
    });
    }
    
  
    

}

function makeWebcamLinks(){
    $$('#content_text button').each(function(btn, item){
    
        var cam = btn.id.split('_');
        //console.log(cam[1]);
        
        switch (cam[1]) {
            case 'titlis':
                var camtitle = 'Titlis';
                break;
                
            case 'jochstock':
                var camtitle = 'Jochstock';
                break;
                
            case 'stationstand':
                var camtitle = 'Station Stand';
                break;
			
			case 'funpark':
	          	var camtitle = 'Funpark';
	            break;
                
            case 'skihuettestand':
                var camtitle = 'Skihütte Stand';
                break;
                
            case 'berghausjochpass':
                var camtitle = 'Jochpass';
                break;
                
            case 'berghoteltruebsee':
                var camtitle = 'Trübsee';
                break;
                
            case 'gerschnialp':
                var camtitle = 'Gerschnialp';
                break;
                
            case 'talstationengelberg':
                var camtitle = 'Engelberg Talstation';
                break;
                
        }
        
        var txt = '<div style="position:absolute;bottom:0px;left:0;background-color:#F1F4F5;"><iframe src="' + root + 'camSlide/slider.php?name=' + cam[1] + '" width="808" height="300" scrolling="no" frameborder="0"></iframe></div>';
        
        btn.addEvent('click', function(e){
            createWin('camslide' + item, txt, 'Webcam Timeline - ' + camtitle, 300);
        });
        
        
    });
}


function closeOverlay(win){

    var fadeout = new Fx.Tween(win, {
        duration: 500,
        onComplete: function(){ 
            $(win).destroy();
        }
    });
    fadeout.start('opacity', '1', '0');
    
    var fadeout2 = new Fx.Tween('BoxOverlay', {
        duration: 500,
        onComplete: function(){
            $('BoxOverlay').setStyle('opacity', 0);
        }
    });
    fadeout2.start('opacity', '0.7', '0');
    
}

var tmp = false;
function makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse){

    if (tmp != true) {
        tmp = true;
        var f = function(){
            makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse);
        };
        
        setTimeout(f, 900);
    }
    
    var steps = (horizontal ? (content.getScrollSize().x - content.getSize().x) : (content.scrollHeight - content.getSize().y -2))
    
    if (steps > 0) {
        Xscrollbar.setStyle('display', 'block');
        handle.setStyle('display', 'block');
    }
    else {
        Xscrollbar.setStyle('display', 'none');
        handle.setStyle('display', 'none');
        return;
    }
    
    var slider = new Slider(Xscrollbar, handle, {
        steps: steps,
        mode: (horizontal ? 'horizontal' : 'vertical'),
        onChange: function(step){
            var x = (horizontal ? step : 0);
            var y = (horizontal ? 0 : step);
            content.scrollTo(x, y);
        }
    }).set(0);
    
    if (!(ignoreMouse)) {
        $$(content, Xscrollbar).addEvent('mousewheel', function(e){
        
            e = new Event(e).stop();
            var step = slider.step - (e.wheel / 2) * 30;
            
            slider.set(step);
        });
    }
    
    $(document.body).addEvent('mouseleave', function(){
        slider.drag.stop();
    });
}

function gmap(){
    if (GBrowserIsCompatible()) {
        var map = new GMap2($('map'));
        map.addControl(new GSmallZoomControl());
        map.addControl(new GMapTypeControl());
        
        map.setCenter(new GLatLng(46.81678148234219, 8.397116661071777), 15);
        var point = new GLatLng(46.81678148234219, 8.397116661071777);
        
        //online -> ABQIAAAAQO7vjAZDK3KEoA9w4ZoZyxTexs7A9H3Vm8wZ_Mn5AzXDa7S3sRQzL5sW4lnzlmEnwnJaQju0Pw2inw
        //local -> ABQIAAAAQO7vjAZDK3KEoA9w4ZoZyxQViYNHs_A5WglK8K_BKzzK06MAkRTwfhfMkbLQCc5eDuXBH28bWxn9jA
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        
        blueIcon.image = "http://www.titlis.ch/images/gmap.gif";
        blueIcon.iconSize = new GSize(50, 29);
        markerOptions = {
            icon: blueIcon
        };
        
        if (lang == 'de') {
            langst = "Route berechnen";
            langlink = "de";
        }
        else {
            langst = "get directions";
            langlink = "en";
        }
        
        
        marker = new GMarker(point, markerOptions);
        map.addOverlay(marker);
        var html = '<b>Titlis Rotair</b><br>Gerschnistrasse 1<br>CH-6390 Engelberg<br>Tel. ++41 (0)41 639 50 50<br><br><a href="http://maps.google.com/maps?f=d&source=s_d&saddr=Gerschniweg+1,+6390+Engelberg,+Schweiz&daddr=&hl='+langlink+'&geocode=&mra=ls&sll=47.110366,8.447905&sspn=0.010223,0.01929&ie=UTF8&z=16" target="_blank">' + langst + '</a>';
        
        marker.openInfoWindowHtml(html);
    }
}

function form_endspurt(){

    var fld = [{
        'feld0': {
            'str': 'Vorname Name',
            'bez': 'Name',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld1': {
            'str': 'Jahrgang',
            'bez': 'Jahrgang',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld2': {
            'str': 'Mail',
            'bez': 'Mail',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld3': {
            'str': 'Telefonnummer',
            'bez': 'Telefonnummer',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld4': {
            'str': 'Disziplin: Ski',
            'bez': 'Disziplin',
            'cls': 'nochk',
            'ftype': 'radio',
            'params': 'value="Ski" checked'
        }
    }, {
        'feld5': {
            'str': 'Disziplin: Snowboard',
            'bez': 'Disziplin',
            'cls': 'nochk',
            'ftype': 'radio',
            'params': 'value="Snowboard"'
        }
    }, {
        'feld6': {
            'str': 'Disziplin: Fun',
            'bez': 'Disziplin',
            'cls': 'nochk',
            'ftype': 'radio',
            'params': 'value="Fun"'
        }
    }, {
        'feld7': {
            'str': 'Bei Disziplin Fun -> Anzahl Personen:',
            'bez': 'Personen',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld8': {
            'str': 'Bei Disziplin Fun -> Teamname:',
            'bez': 'Teamname',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld9': {
            'str': 'An folgendem Verschiebedatum wäre ich auch dabei: 23. Mai',
            'bez': 'Verschiebedatum',
            'cls': 'nochk',
			'ftype': 'checkbox',
            'params': 'value="ja"'
        }
    }, {
        'feld10': {
            'str': '24. Mai',
            'bez': 'Verschiebedatum2',
            'cls': 'nochk',
			'ftype': 'checkbox',
            'params': 'value="ja"'
        }
      },{  'feld11': {
            'str': '',
            'bez': 'reservieren',
            'cls': 'sbmt',
            'ftype': 'submit',
            'params': 'value="reservieren"'
        }
    }, {
        'feld12': {
            'str': '',
            'bez': 'logfile',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="logEndspurt_' + xLang + '"'
        }
    }, {
        'feld13': {
            'str': '',
            'bez': 'title',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="Anmeldung Endspurt ' + xLang + '"'
        }
    }]
    
    return createForm(fld, $('eventInfo'));
}

function form_knorrli(){

    var fld = [{
        'feld0': {
            'str': 'Name',
            'bez': 'Name',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld1': {
            'str': 'Vorname',
            'bez': 'Vorname',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld2': {
            'str': 'Adresse',
            'bez': 'Adresse',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld3': {
            'str': 'PLZ',
            'bez': 'PLZ',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld4': {
            'str': 'Ort',
            'bez': 'Ort',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld5': {
            'str': 'Mail',
            'bez': 'Mail',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld6': {
            'str': 'Telefon',
            'bez': 'Telefon',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld7': {
            'str': 'Anzahl Erwachsene (ab 16 Jahren):',
            'bez': 'Erwachsene',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld8': {
            'str': 'Anzahl Kinder (bis&mit 15 Jahren):',
            'bez': 'Kinder',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld9': {
            'str': 'Bemerkungen',
            'bez': 'Bemerkungen',
            'cls': 'nochk',
            'ftype': 'area',
            'params': ''
        }
    }, {
        'feld10': {
            'str': '',
            'bez': 'reservieren',
            'cls': 'sbmt',
            'ftype': 'submit',
            'params': 'value="reservieren"'
        }
    }, {
        'feld11': {
            'str': '',
            'bez': 'logfile',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="logKnorrli_' + xLang + '"'
        }
    }, {
        'feld12': {
            'str': '',
            'bez': 'title',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="Anmeldung Knorrli ' + xLang + '"'
        }
    }]
    
    return createForm(fld, $('eventInfo'));
}

function form_fireride(){

    if (lang == 'de') {
        bezArr = new Array('Name', 'Vorname', 'Adresse', 'PLZ', 'Ort', 'Land', 'Mail', 'Telefon', 'Anzahl Personen', 'Bemerkungen');
    }
    else {
        bezArr = new Array('Last Name', 'First Name', 'Adress', 'ZIP Code', 'City', 'Country', 'Mail', 'Phone', 'How many people', 'Message');
    }
    
    
    var fld = [{
        'feld0': {
            'str': bezArr[0],
            'bez': 'Name',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld1': {
            'str': bezArr[1],
            'bez': 'Vorname',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld2': {
            'str': bezArr[2],
            'bez': 'Adresse',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld3': {
            'str': bezArr[3],
            'bez': 'PLZ',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld4': {
            'str': bezArr[4],
            'bez': 'Ort',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld5': {
            'str': bezArr[5],
            'bez': 'Land',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld6': {
            'str': bezArr[6],
            'bez': 'Mail',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld7': {
            'str': bezArr[7],
            'bez': 'Telefon',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld8': {
            'str': bezArr[8],
            'bez': 'Personen',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld9': {
            'str': bezArr[9],
            'bez': 'Bemerkungen',
            'cls': 'nochk',
            'ftype': 'area',
            'params': ''
        }
    }, {
        'feld10': {
            'str': '',
            'bez': 'reservieren',
            'cls': 'sbmt',
            'ftype': 'submit',
            'params': 'value="reservieren"'
        }
    }, {
        'feld11': {
            'str': '',
            'bez': 'logfile',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="logFireride_' + xLang + '"'
        }
    }, {
        'feld12': {
            'str': '',
            'bez': 'title',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="Anmeldung Fireride ' + xLang + '"'
        }
    }]
    
    return createForm(fld, $('eventInfo'));
}


function form_trophy(){

    var fld = [{
        'feld0': {
            'str': 'Name',
            'bez': 'Name',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld1': {
            'str': 'Vorname',
            'bez': 'Vorname',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld2': {
            'str': 'Adresse',
            'bez': 'Adresse',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld3': {
            'str': 'PLZ',
            'bez': 'PLZ',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld4': {
            'str': 'Ort',
            'bez': 'Ort',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld5': {
            'str': 'Mail',
            'bez': 'Mail',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld6': {
            'str': 'Telefon',
            'bez': 'Telefon',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld7': {
            'str': 'Anzahl Erwachsene (ab 16 Jahren):',
            'bez': 'Erwachsene',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld8': {
            'str': 'Anzahl Kinder (bis&mit 15 Jahren):',
            'bez': 'Kinder',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld9': {
            'str': 'Bemerkungen',
            'bez': 'Bemerkungen',
            'cls': 'nochk',
            'ftype': 'area',
            'params': ''
        }
    }, {
        'feld10': {
            'str': 'Start ab 6 Uhr (Profis) ',
            'bez': 'Startzeit',
            'cls': 'nochk',
            'ftype': 'radio',
            'params': 'value="Profi" checked'
        }
    }, {
        'feld11': {
            'str': 'Start ab 6:30 - 8:30 Uhr (Pläuschler)',
            'bez': 'Startzeit',
            'cls': 'nochk',
            'ftype': 'radio',
            'params': 'value="Plaeuschler"'
        }
    }, {
        'feld12': {
            'str': '',
            'bez': 'reservieren',
            'cls': 'sbmt',
            'ftype': 'submit',
            'params': 'value="reservieren"'
        }
    }, {
        'feld13': {
            'str': '',
            'bez': 'logfile',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="logBergtrophy_' + xLang + '"'
        }
    }, {
        'feld14': {
            'str': '',
            'bez': 'title',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="Anmeldung Bergtrophy ' + xLang + '"'
        }
    }]
    
    return createForm(fld, $('eventInfo'));
}

function form_fackelabfahrt(){

    if (lang == 'de') {
        bezArr = new Array('Name', 'Vorname', 'Adresse', 'PLZ', 'Ort', 'Land', 'Mail', 'Telefon', 'Anzahl Skifahrer (Zahl eingeben)', 'Anzahl Snowboarder (Zahl eingeben)', 'Bemerkungen', '<b>Voraussetzung</b>: Gute Ski- oder Snowboardkenntnisse,<br>Versicherung ist Sache des Teilnehmers,<br> Schneesportler dürfen die Piste nicht verlassen.', '<b>Haftung</b>: Bergbahnen Titlis Rotair AG haftet nicht für Unfälle und  Beschädigungen jeglicher Art<br> an Kleidern und Ausrüstung.');
    }
    else {
        bezArr = new Array('Last Name', 'First Name', 'Adress', 'ZIP Code', 'City', 'Country', 'Mail', 'Phone', 'How many skiers', 'How many snowboarders', 'Message', '<b>Requirement</b>: Good skiing or snowboarding knowledge. Insurance is the responsibility of the participant, do not leave the piste.', '<b>Haftung</b>: Titlis Rotair Cableways is not liable for accidents and damages of any kind of clothing and equipment');
    }
    
    var fld = [{
        'feld0': {
            'str': bezArr[0],
            'bez': 'Name',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld1': {
            'str': bezArr[1],
            'bez': 'Vorname',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld2': {
            'str': bezArr[2],
            'bez': 'Adresse',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld3': {
            'str': bezArr[3],
            'bez': 'PLZ',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld4': {
            'str': bezArr[4],
            'bez': 'Ort',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld5': {
            'str': bezArr[5],
            'bez': 'Land',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld6': {
            'str': bezArr[6],
            'bez': 'Mail',
            'cls': 'chk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld7': {
            'str': bezArr[7],
            'bez': 'Telefon',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld8': {
            'str': bezArr[8],
            'bez': 'Skifahrer',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld9': {
            'str': bezArr[9],
            'bez': 'Snowboarder',
            'cls': 'nochk',
            'ftype': 'text',
            'params': ''
        }
    }, {
        'feld10': {
            'str': bezArr[10],
            'bez': 'Bemerkungen',
            'cls': 'nochk',
            'ftype': 'area',
            'params': ''
        }
    }, {
        'feld11': {
            'str': bezArr[11],
            'bez': 'Voraussetzug',
            'cls': 'chk',
            'ftype': 'checkbox',
            'params': 'value="akzeptiert"'
        }
    }, {
        'feld12': {
            'str': bezArr[12],
            'bez': 'Haftung',
            'cls': 'chk',
            'ftype': 'checkbox',
            'params': 'value="akzeptiert"'
        }
    }, {
        'feld13': {
            'str': '',
            'bez': 'reservieren',
            'cls': 'sbmt',
            'ftype': 'submit',
            'params': 'value="reservieren"'
        }
    }, {
        'feld14': {
            'str': '',
            'bez': 'logfile',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="logFackel_' + xLang + '"'
        }
    }, {
        'feld15': {
            'str': '',
            'bez': 'title',
            'cls': 'nochk',
            'ftype': 'hidden',
            'params': 'value="Anmeldung Fackelabfahrt ' + xLang + '"'
        }
    }]
    
    return createForm(fld, $('eventInfo'));
}


function createForm(fld, target){

    frm = new Element('form', {
        'method': 'post',
        'class': 'ajaxsend',
        'id': 'resform',
        'styles': {
            'clear': 'both',
            'margin-left': '275px'
        }
    });
    
    
    //frm.injectInside(target);
    
    tab = new Element('table', {
        'cellpadding': '2',
        'cellspacing': '0',
        'border': '0',
        'width': '400',
        'height': '100%'
    });
    
    tab.injectInside(frm);
    
    thead = new Element('thead').inject(tab);
    tbody = new Element('tbody').inject(tab);
    
    fld.each(function(f, item){
    
        tr = new Element('tr');
        tr.injectInside(tbody);
        
        td = new Element('td', {
            'html': f['feld' + item].str,
            'valign': 'top'
        });
        
        td.injectInside(tr);
        
        
        if (f['feld' + item].ftype != 'area') {
            td = new Element('td', {
                'align': 'left',
                'valign': 'top',
                'html': '<input type="' + f['feld' + item].ftype + '" name="' + f['feld' + item].bez + '" class="' + f['feld' + item].cls + '" ' + f['feld' + item].params + '>'
            });
        }
        else {
            td = new Element('td', {
                'html': '<textarea name="' + f['feld' + item].bez + '" class="' + f['feld' + item].cls + '" />'
            });
        }
        td.injectInside(tr);
        
    });
    
    return frm;
    
}


function AjaxSend(form, target){

    $$('.sbmt').addEvent('click', function(){
        return chk(form);
    });
    
    
    form.addEvent('submit', function(e){
    
        e.stop();
        
        this.set('send', {
            method: 'post',
            url: path + 'includes/sendmail.php',
            
            onRequest: function(){
                target.empty();
                target.innerHTML = '<div style="position:absolute;top:60px;">LOADING: Reservation wird verarbeitet...</div>';
                
            },
            onComplete: function(response){
            
                target.empty();
                
                makeScrollbar($('wincont'), $('window_track'), $('window_thumb'));
		
		
		
		if (lang == 'de') {
			
			if(fackelabfahrt == true){
				target.innerHTML = '<div style="position:absolute;top:60px;">Herzlichen Dank für Ihre Anmeldung zum Titlis Fire Ride vom Samstag, 27. März 2010. Infos zur Durchführung erhalten Sie unter der Nummer 041 639 50 68 ab Freitag, 26. März ab 17 Uhr.<br/><br/>Bis bald am Titlis<br/><br/><a href="http://titlis.ch/de/titlis/service/unternehmen/teams" />Das Titlis-Team</a></div>';
			}else if(trophy == true){
				target.innerHTML = '<div style="position:absolute;top:60px;">Herzlichen Dank für Ihre Anmeldung zur Titlis Bergtrophy vom 28. August 2010. Infos zur Durchführung erhalten Sie unter der Nummer 041 639 50 68 ab Freitag, 27. August ab 17 Uhr.<br/><br/><a href="http://titlis.ch/de/titlis/service/unternehmen/teams" />Das Titlis-Team</a></div>';
			}else if(endspurt == true){
				target.innerHTML = '<div style="position:absolute;top:60px;">Herzlichen Dank für die Anmeldung zum Titlis Endspurt-Event vom 22. Mai (Verschiebedatum 23. oder 24. Mai). Wir freuen uns, dass Sie mit uns den Winterabschluss feiern werden. AUSKUNFT DURCHFÜHRUNG: 041 639 50 68 ab Freitag 21. Mai, ab 17 Uhr<br/><br/>Bis bald am Titlis<br/><br/><a href="http://titlis.ch/de/titlis/service/unternehmen/teams" />Das Titlis-Team</a></div>';
			}else{
				target.innerHTML = '<div style="position:absolute;top:60px;">Formular erfolgreich verschickt. Besten Dank für Ihre Anmeldung.</div>';
			}

			
		}else{
			target.innerHTML = '<div style="position:absolute;top:60px;">Thanks a lot for your reservation! See you on Mount Titlis!</div>';
		}
                
            }
        });
        
        this.send();
        
    });
    
    
}


function chk(frm){

    $$('input').each(function(inp){
        inp.addEvent('keydown', function(){
            inp.setStyle('background-color', '#ffffff');
        })
    });
    
    msg = new Array();
    err = false;
    allinp = frm.getElementsByTagName("input").length;
    inp = frm.getElementsByTagName("input");
    x = 0;
    for (i = 0; i < allinp; i++) {
        if (inp[i].value == "" && inp[i].className == "chk") {
            err = true;
            inp[i].setStyle('background-color', '#FFEFEF');
            msg[x] = inp[i].name;
            x++;
        }
        
        try {
            if (inp[i].type == 'checkbox' && inp[i].checked == false && inp[i].className == "chk") {
                err = true;
                msg[x] = inp[i].name;
                x++;
            }
        } 
        catch (err) {
        }
        
    }
    if (err == true) {
        ausgabe = msg.join(", ");
        alert("Bitte ergaenzen Sie die Felder: " + ausgabe);
        return false;
    }
    
}
