 function jsClock() {
    now = new Date();
    hours = now.getHours();
    minutes = now.getMinutes();
    seconds = now.getSeconds();
    //timeStr = "" + hours;
    timeStr = ((hours < 10) ? "0" : "") + hours;
    timeStr += ((minutes < 10) ? ":0" : ":") + minutes;
    timeStr += ((seconds < 10) ? ":0" : ":") + seconds;
    
    dato = new Date();
    month = dato.getMonth();
    month = (month * 1) + 1;
    day = dato.getDate();
    year = dato.getYear();
    if (month==1) {month = "januar"}
    else if (month==2) {month = "februar"}
    else if (month==3) {month = "mars"}
    else if (month==4) {month = "april"}
    else if (month==5) {month = "mai"}
    else if (month==6) {month = "juni"}
    else if (month==7) {month = "juli"}
    else if (month==8) {month = "august"}
    else if (month==9) {month = "september"}
    else if (month==10) {month = "oktober"}
    else if (month==11) {month = "november"}
    else {month = "desember"}
    var grammar="";
    if (day==1 || day==21 || day==31) {grammar="."}
    else if (day==2 || day==22) {grammar="."}
    else if (day==3 || day==23) {grammar="."}
    else {grammar=". "}
    
    var dag = dato.getDay();
    if (dag==1) {dag = "mandag"}
    else if (dag==2) {dag = "tirsdag"}
    else if (dag==3) {dag = "onsdag"}
    else if (dag==4) {dag = "torsdag"}
    else if (dag==5) {dag = "fredag"}
    else if (dag==6) {dag = "lørdag"}
    else {dag = "søndag"}

    var clockDiv = document.getElementById("jsclock");
    if (clockDiv != null) {
        clockDiv.innerHTML = timeStr + " " + dag + " " + day + grammar + "" + month + "";
        setTimeout("jsClock()", 1000);
    }
} 

// written by Dean Edwards, 2005
// http://dean.edwards.name/

function addEvent(element, type, handler) {
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	if (!element.events) element.events = {};
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	handlers[handler.$$guid] = handler;
	element["on" + type] = handleEvent;
};

// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};

function TipsEnVenn() {
    
}

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(window.event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};


addEvent(window, "load", function() {
    var elemAnn = document.getElementById("announcement-container");
    if (elemAnn != null) {
        addEvent(elemAnn, "mouseover", function() {
            accordionRunning = false;
        });
    }

    setTimeout("jsClock()", 1000);
});


function showAnnouncement(color1,color2, color3, color4,index){
    var containerElem = document.getElementById("announcement-container");
    var button1 = document.getElementById("announce-button-1");
    var button2 = document.getElementById("announce-button-2");
    var button3 = document.getElementById("announce-button-3");
    var button4 = document.getElementById("announce-button-4");    
    var elem1 = document.getElementById("box-1");
    var elem2 = document.getElementById("box-2");
    var elem3 = document.getElementById("box-3");
    var elem4 = document.getElementById("box-4");
   // alert("index: " + index);
    if(index == "1"){
        containerElem.style.backgroundColor = "#" + color1; 
        var elem = document.getElementById("box-1");
        elem.style.display = "block";
        if (elem2 != null) { elem2.style.display = "none"; }
        if (elem3 != null) { elem3.style.display = "none"; }
        if (elem4 != null) { elem4.style.display = "none"; }

        if (button1 != null) { button1.style.backgroundImage = "url('KAN/accordion/" + color1 + "_3.gif')"; }
        if (button2 != null) { button2.style.backgroundImage = "url('KAN/accordion/" + color2 + "_1.gif')"; }
        if (button3 != null) { button3.style.backgroundImage = "url('KAN/accordion/" + color3 + "_1.gif')"; }
        if (button4 != null) { button4.style.backgroundImage = "url('KAN/accordion/" + color4 + "_1.gif')"; }


    } else if (index == "2") {
        containerElem.style.backgroundColor = "#" + color2;
        var elem = document.getElementById("box-2");
        elem.style.display = "block";
        if (elem1 != null) { elem1.style.display = "none"; }
        if (elem3 != null) { elem3.style.display = "none"; }
        if (elem4 != null) { elem4.style.display = "none"; }
        if (button1 != null) { button1.style.backgroundImage = "url('KAN/accordion/" + color1 + "_0.gif')"; }
        if (button2 != null) { button2.style.backgroundImage = "url('KAN/accordion/" + color2 + "_2.gif')"; }
        if (button3 != null) { button3.style.backgroundImage = "url('KAN/accordion/" + color3 + "_1.gif')"; }
        if (button4 != null) { button4.style.backgroundImage = "url('KAN/accordion/" + color4 + "_1.gif')"; }
    }else if(index== "3"){
        containerElem.style.backgroundColor = "#" + color3;
        var elem = document.getElementById("box-3");
        elem.style.display = "block";
        if (elem1 != null) { elem1.style.display = "none"; }
        if (elem2 != null) { elem2.style.display = "none"; }
        if (elem4 != null) { elem4.style.display = "none"; }
        if (button1 != null) { button1.style.backgroundImage = "url('KAN/accordion/" + color1 + "_0.gif')"; }
        if (button2 != null) { button2.style.backgroundImage = "url('KAN/accordion/" + color2 + "_1.gif')"; }
        if (button3 != null) { button3.style.backgroundImage = "url('KAN/accordion/" + color3 + "_2.gif')"; }
        if (button4 != null) { button4.style.backgroundImage = "url('KAN/accordion/" + color4 + "_1.gif')"; }
    }else{
        containerElem.style.backgroundColor = "#" + color4;
        var elem = document.getElementById("box-4");
        elem.style.display = "block";
        if (elem1 != null) { elem1.style.display = "none"; }
        if (elem2 != null) { elem2.style.display = "none"; }
        if (elem3 != null) { elem3.style.display = "none"; }
        if (button1 != null) {
            //alert("button1: KAN/images/accordion/" + color1 + "_3.gif")
            button1.style.backgroundImage = "url(KAN/accordion/" + color1 + "_0.gif)"; 
        }
        if (button2 != null) { button2.style.backgroundImage = "url('KAN/accordion/" + color2 + "_1.gif')"; }
        if (button3 != null) { button3.style.backgroundImage = "url('KAN/accordion/" + color3 + "_1.gif')"; }
        if (button4 != null) { button4.style.backgroundImage = "url('KAN/accordion/" + color4 + "_2.gif')"; }
    }
}

function hideAnnouncement(id){
    var elem = document.getElementById(id);
    elem.style.display = "none";
}
function showVenueInformation(id) {
    GB_show("Informasjon om lokalet", "kanvenuepage.aspx?vid=" + id, 480, 580);
}
function showVenueInfo() {
    var div = document.getElementById("kurslokale-info");
    if (div != null) { 
        div.style.display ="block";
    }
}
function hideVenueInfo() {
    var div = document.getElementById("kurslokale-info");
    if (div != null) {
        div.style.display = "none";
    }
}

function showCourseProgram() {
    var infoElem = document.getElementById("kursinfo");
    var programElem = document.getElementById("kursprogram");
    infoElem.style.display = "none";
    programElem.style.display = "block";
}

function showCourseInfo() {
    var infoElem = document.getElementById("kursinfo");
    var programElem = document.getElementById("kursprogram");
    infoElem.style.display = "block";
    programElem.style.display = "none";

}

function showCoursePartProgram(id) {
    var elem = document.getElementById("part" + id);
    course-part-heading
}

//addEvent(window, "load", function(){  
//        setTimeout("jsClock()",1000);        
//});


function showPamelding(id, numParaSections, partCoursesPossible, numPartCourses) {
    var parExtraHeight = numParaSections * 30;
    var partCoursesExtraHeight = 0;
    
    if (partCoursesPossible) {
        partCoursesExtraHeight = numPartCourses * 30;
    }
    var height = 650 + parExtraHeight + partCoursesExtraHeight;
    GB_show("P&aring;melding", "KANRegCoursePage.aspx?courseid=" + id, height, 435, true);
}





function switchAccordionTab(color1, color2, color3, color4) {
    if (accordionRunning == true) {
        var tabsArray = [];
        var tabsArray = $(".accordiontab");
       // alert("index: " + accordionIndex);
        showAnnouncement(color1, color2, color3, color4, accordionIndex);
        if (accordionIndex >= tabsArray.length) {
            accordionIndex = 1;
        } else {
            accordionIndex = accordionIndex + 1;
        }
                
    }
}

