﻿window.addEvent('domready', function(){
	var el = $('dvCalender'),
	bgcolor = el.getStyle('backgroundColor');
	sUrl = document.getElementById("hidBasePath").value;
	var urlx = encodeURI(sUrl + '/Enta/');
	iTmpToday = "";
    function Calendar(){
        var req = new Request.HTML({url:urlx + 'bpElementProvider.aspx?template=EventCalendarStd', 
            onSuccess: function(html) {
            
                el.set('text', '');
                el.adopt(html);
                document.getElementById("showPlayInfo").style.top = (document.getElementById("dvCalender").offsetHeight + 40) + "px";
                //alert("on " + document.getElementById("dvCalender").offsetHeight);
                //alert(document.getElementById("showPlayInfo").style.top);
                calEventHandler();
                CalendarPerDate2('');
            },
            onFailure: function() {el.set('text', '<p>Cant load: '+ urlx + 'bpElementProvider.aspx?template=EventCalendarStd'+'</p>');}
        });
         req.send();
    }
    function CalendarPerDate(id){
    
        var req = new Request.HTML({url:urlx + 'bpElementProvider.aspx?template=EventCalendarStd&fromdate='+id, 
        
            onSuccess: function(html) {
                el.set('text', '');
                el.adopt(html);
                document.getElementById("calProgress").style.display = "none";
                document.getElementById("showPlayInfo").style.top = (document.getElementById("dvCalender").offsetHeight + 40) + "px";
                //alert("off " + document.getElementById("dvCalender").offsetHeight);
                //alert(document.getElementById("showPlayInfo").style.top);
                document.getElementById("dnn_ctr384_ModuleContent").style.top = "5px";
                calEventHandler();                
            },
            onFailure: function() {el.set('text', '<p>Cant load: '+ urlx + 'bpElementProvider.aspx?template=EventCalendarStd&fromdate='+id+'</p>');}
        });
        //document.getElementById("dvCalender").innerHTML = document.getElementById("dvCalender").innerHTML + "<img id='loadingImg' src='" + sUrl + "/images/loading.gif' alt='Loading'  />";
        document.getElementById("calProgress").style.display = "block";
        document.getElementById("showPlayInfo").innerHTML = "";
        document.getElementById("showPlayInfo").style.visibility="hidden";
         req.send();
    }
    function calEventHandler(){
        el.getElements('td').addEvent('click',function(e){
            e.stop();
            if(this.className == "day_off_month" || this.className == "day_off" || this.className == "day_off_wknd"){ 
                return; 
            }
            
            var id = (this.get('id') == null) ? '' : this.get('id');
            var idlast = '';
            doSomething((this.parentNode).parentNode);
            if(id != ""){
                if (this.className == "day_today"){
                    this.set('class', 'daySelected');
                    iTmpToday = this;
                }
                else{
                    this.set('class', 'daySelected');
                    try{iTmpToday.set('class', 'day_today');}catch(err){}
                }
                
                CalendarPerDate2(id);
                
            }
        });
        el.getElements('th').addEvent('click',function(e){
            e.stop();
            curSpan = this.getElements('span');
            var id = (curSpan.get('id') == null) ? '' : curSpan.get('id');
            var css = (curSpan.get('class') == null) ? '' : curSpan.get('class');
            if (css == 'BF') {
                CalendarPerDate(id);
               
            }
        });
    }
    
    sTempPlay = "";
    function CalendarPerDate2(id){
        var req = new Request.HTML({url:urlx + 'bpElementProvider.aspx?template=dntCalPlayList&fromdate='+id, 
            onSuccess: function(html) { 
                sTempPlay =  this.xhr.responseText;
                AnnaPlays(id);
                document.getElementById("dnn_ctr384_ModuleContent").style.top = document.getElementById("showPlayInfo").offsetHeight + "px";
            },
            onFailure: function() {el.set('text', '<p>Cant load: '+ urlx + 'bpElementProvider.aspx?template=dntCalPlayList&fromdate='+id+'</p>');}
        });
        document.getElementById("showPlayInfo").innerHTML = "<img id='loadingImg' src='" + sUrl + "/images/loading.gif' alt='Loading'  />";
        req.send();
    }
    
    function AnnaPlays(id){
    
        var req = new Request.HTML({url:urlx + 'bpElementProvider.aspx?template=annaPlayCal&fromdate='+id, 
            onSuccess: function(html) { 
                sTempPlay= sTempPlay.replace(/<\/ul>/,"").replace(/<\/UL>/,"");
                document.getElementById("showPlayInfo").innerHTML = sTempPlay.replace(/<\/UL>/,"") + this.xhr.responseText;
                  if(document.getElementById("showPlayInfo").innerHTML !="")
                    {                     
                        document.getElementById("showPlayInfo").style.visibility="visible";
                    }
                document.getElementById("dnn_ctr384_ModuleContent").style.top = document.getElementById("showPlayInfo").offsetHeight + "px";
                    
                
            },
            onFailure: function() 
            {
                document.getElementById("showPlayInfo").innerHTML = sTempPlay;
            }
        });
        document.getElementById("showPlayInfo").innerHTML = "<img id='loadingImg' src='" + sUrl + "/images/loading.gif' alt='Loading'  />";
        req.send();
    }
    
	Calendar();
});

function doSomething(sId) {
    aryClassElements.length = 0;
    getElementsByClassName( 'daySelected', sId );
    for ( var i = 0; i < aryClassElements.length; i++ ) {
        aryClassElements[i].className = 'day';
    }
}

var aryClassElements = new Array();
function getElementsByClassName( strClassName, obj ) {
    if ( obj.className == strClassName ) {
       aryClassElements[aryClassElements.length] = obj;
       return;
    }
    for ( var i = 0; i < obj.childNodes.length; i++ )
        getElementsByClassName( strClassName, obj.childNodes[i] );
}
window.addEvent('domready', function(){ try { var el = $('dnn_ctr431_ViewSPELEPLAN_tblSpeleplan'), e2 = $('dnn_ctr431_ViewSPELEPLAN_tblAnnayPlays'),	bgcolor = el.getStyle('backgroundColor');	
   sUrl = document.getElementById("hidBasePath").value;
   var urlx = encodeURI(sUrl + '/Enta/');
   function PlaysByShow(id){
        document.getElementById("progressBar").style.display="block";
        document.getElementById("progressMsg").style.visibility="hidden";
        
        sMon = document.getElementById("dnn_ctr431_ViewSPELEPLAN_cmbMonth").value; //dnn$ctr431$ViewSPELEPLAN$cmbMonth
        sShoId = document.getElementById("dnn_ctr431_ViewSPELEPLAN_hidShoId").value; //dnn$ctr431$ViewSPELEPLAN$hidShoId
        if (sShoId == "") sShoId = "0";
        var req = new Request.HTML({url:urlx + 'BPELEMENTPROVIDER.ASPX?mon='+ sMon +'&shId=' + sShoId + '&template=dntPlayList'+id , 
            onSuccess: function(html) {
                /*el.set('text', '');
                el.adopt(html);*/
                document.getElementById("dnn_ctr431_ViewSPELEPLAN_tblSpeleplan").innerHTML = this.xhr.responseText;
                pbsEventHandler();
                document.getElementById("progressBar").style.display="none";
                document.getElementById("progressMsg").style.visibility="visible";
            },
            onFailure: function() {el.set('text', '<p>Cant load: '+ urlx + 'bpElementProvider.aspx?template=dntPlayList&'+id+'</p>');}
        });
        req.send();
        if (sShoId == "0"){
        //alert('BPELEMENTPROVIDER.ASPX?mon='+ sMon +'&shId=' + sShoId + '&template=annaPlayList'+id);
        var req2 = new Request.HTML({url:urlx + 'BPELEMENTPROVIDER.ASPX?mon='+ sMon +'&shId=' + sShoId + '&template=annaPlayList'+id , 
            onSuccess: function(html) {
                /*e2.set('text', '');
                e2.adopt(html);*/
                //alert(this.xhr.responseText);
                document.getElementById("dnn_ctr431_ViewSPELEPLAN_tblAnnayPlays").innerHTML = this.xhr.responseText;
            },
            onFailure: function() {e2.set('text', '<p>Cant load: '+ urlx + 'bpElementProvider.aspx?template=dntPlayList&'+id+'</p>');}
        });
        req2.send();
        }
    }
    var sSortBy; 
    sSortBy = "asc";
    function pbsEventHandler(){
        el.getElements('thead a').addEvent('click', function(e){
            e.stop();
            if(sSortBy == "asc") sSortBy = "desc"; else sSortBy = "asc";
            PlaysByShow(this.title + ' ' +  sSortBy);
        });
        el.getElements('th').addEvent('click',function(e){
            e.stop();
            var id = (this.get('id') == null) ? '' : this.get('id');
            var css = (this.get('class') == null) ? '' : this.get('class');
            if (css == 'BF') {
                CalendarPerDate(id);
            }
        });
    }
    
	PlaysByShow('');
	}
	catch(err){}
	});

window.addEvent('domready', function(){
    try { 
        var el = $('ddlSeasons'), bgcolor = el.getStyle('backgroundColor');
        sUrl = document.getElementById("hidBasePath").value;
	    var urlx = encodeURI(sUrl + '/Enta/');
        function SeasonIndexList()
        {
            var req = new Request.HTML({url:urlx + 'BPELEMENTPROVIDER.ASPX?template=dntSeasonIndexList', 
                onSuccess: function(html) {
                },
                onFailure: function() {}
            });
            req.send();
        }
        SeasonIndexList();
    } catch(err){}
});	



window.addEvent('domready', function(){
    try { 
        var el = $('DvPlayList')
        sUrl = document.getElementById("hidBasePath").value;
        sId = document.getElementById("dnn_ctr381_ViewPlaketenContentDetails_hidShoId").value;
	    var urlx = encodeURI(sUrl + '/Enta/');
        function fnPlayList()
        {
            var req = new Request.HTML({url:urlx + 'BPELEMENTPROVIDER.ASPX?template=EventListTiny&shId=' + sId, 
                onSuccess: function(html) {
                    //alert(this.xhr.responseText);
                    document.getElementById("DvPlayList").innerHTML = this.xhr.responseText;
                },
                onFailure: function() {}
            });
            req.send();
        }
        fnPlayList();
    } catch(err){}
});	


//onload="createPlayer('../../../../js/playlist_chapters.xml')"

/* Function for displaying Video Player on Videoar and Videoarkiv Pages */
window.addEvent('domready', function(){
    try { 
        createPlayer1('http://www.detnorsketeatret.no/Portals/xml/Videoar.xml')
    } catch(err){}
    
    try { 
        createPlayer2('http://www.detnorsketeatret.no/Portals/xml/Videoarkiv.xml')        
    } catch(err){}    
});	


window.addEvent('domready', function() {
  try { 
  Sexy = new SexyAlertBox();
  }catch(err){} 
});
