

var agent = navigator.userAgent;
function DOMAvailable(){return(document.getElementById ? true : false);}
function isOpera(){return(agent.toLowerCase().indexOf('opera', 0) != -1);}
function isNetscape(){if(agent.toLowerCase().indexOf('netscape') != -1) return true; else return isGecko();}
function isGecko(){return(agent.toLowerCase().indexOf('gecko') != -1);}
function getDocumentHeight(){
	if(isOpera()) return window.innerHeight; 
	else if (isNetscape()) return window.innerHeight; 
	else 
		if(document.compatMode=='CSS1Compat')
		{
			return document.documentElement.clientHeight;
		}else{
			return document.body.clientHeight;
		}
}
function getDocumentWidth(){
	if (isOpera()) return window.innerWidth; 
	else if (isNetscape()) return window.innerWidth; 
	else 
		if(document.compatMode=='CSS1Compat')
		{
			return document.documentElement.clientWidth;		
		}else{
			return document.body.clientWidth;}	
		}
function onOver(id){filename = document.getElementById(id).src;newfilename = filename.replace(/_r0./gi, '_r1.');document.getElementById(id).src = newfilename;}
function onOut(id){filename = document.getElementById(id).src;newfilename = filename.replace(/_r1./gi, '_r0.');document.getElementById(id).src = newfilename;}
function insertFlash(flashfilename, gfxfilename, width, height, play, loop, menu, flashvars, wmode, elementid)
{
    document.write('<div style="width: '+width+'px; height: '+height+'px;">\n');
    document.write('<object type="application/x-shockwave-flash" data="'+flashfilename+'" width="'+width+'" height="'+height+'" id="'+elementid+'">\n');
    document.write('<param name="movie" value="'+flashfilename+'" />\n');
    document.write('<param name="allowFullScreen" value="true" />\n');
    document.write('<param name="quality" value="High" />\n');
    document.write('<param name="play" value="'+play+'" />\n');
    document.write('<param name="loop" value="'+loop+'" />\n');
    document.write('<param name="menu" value="'+menu+'" />\n');
    document.write('<param name="scale" value="Showall" />\n');
    document.write('<param name="flashvars" value="'+flashvars+'" />\n');
    document.write('<param name="wmode" value="'+wmode+'" />\n');
    document.write('<img src="'+gfxfilename+'" alt="" width="'+width+'" height="'+height+'" />\n');
    document.write('</object>\n');
    document.write('</div>\n');
    if(elementid!='')
	{
	    window[elementid]=document.forms[0][elementid];
	}
}
function setPlayerSize(height, id)
{
    document.getElementById(id).setAttribute("height", Math.round(height));
}

function _defaultSize(strSize){
if(strSize != null){
var objBody = document.getElementById('body');
objBody.style.fontSize = strSize;
}
}

function changeFontSize(strDirection){
var objBody = document.getElementById('body');
if(objBody.currentStyle){
var y = objBody.currentStyle['fontSize'];
y = parseInt(y);
if(strDirection == '+') {
	objBody.style.fontSize = (y + 2) + 'px';
} else if(strDirection == '-') {
	objBody.style.fontSize = (y - 1) + 'px';
}
if(strDirection == '+') {
if(y == 'xx-small')
objBody.style.fontSize = 'x-small';
else if(y == 'x-small')
objBody.style.fontSize = 'small';
} else if(strDirection == '-') {
if(y == 'small')
objBody.style.fontSize = 'x-small';
else if (y == 'x-small')
objBody.style.fontSize = 'xx-small';
}
SetCookie('fontSize', objBody.currentStyle['fontSize']);
} else if (window.getComputedStyle) {
var y = document.defaultView.getComputedStyle(objBody,null).getPropertyValue('font-Size');
y = parseInt(y);
if(strDirection == '+') {
objBody.style.fontSize = (y + 2) + 'px';
} else if(strDirection == '-') {
objBody.style.fontSize = (y - 1) + 'px';
}
SetCookie('fontSize', document.defaultView.getComputedStyle(objBody,null).getPropertyValue('font-Size'));
}
}
	
function _getCookieVal(offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
	
function GetCookie(name){
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return _getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
	
function SetCookie(name, value){
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + " = " + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
	
function DeleteCookie(name){
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// Eventlistcalendar functions
var eventlistCalendar = null;
var eventlistCalendarHead = null;

function getLanguage() 
{
    if (navigator.userLanguage == "da") 
    {
	    return(navigator.userLanguage);
    }
    else if (navigator.language == "da")
    {
	    return(navigator.language);
    }
    else
    {
	    return("andetSprog");
    }
}

function eventlistCalendarFill(calId, year, month, cssPrefix, DBCalId)
{
    var month_names
    if (getLanguage() == "da")
    {
        var month_names = new Array("Januar", "Februar", "Marts", "April", "Maj", "Juni",
        "Juli", "August", "September", "Oktober", "November", "December");
    }
    else
    {
        var month_names = new Array("January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December");
    }
    if(eventlistCalendar == null) eventlistCalendar = document.getElementById(calId);
    else if(eventlistCalendar.id != calId) eventlistCalendar = document.getElementById(calId);
    
    if(eventlistCalendarHead == null) eventlistCalendarHead = document.getElementById(calId + '_month');
    else if(eventlistCalendarHead.id != calId+'_month') eventlistCalendarHead = document.getElementById(calId + '_month');
    eventlistCalendarHead.innerHTML = month_names[month-1] + '  - ' + year;

    ClientsideAjax.getEventlistCalendarMonth(year, month, DBCalId, function(response){ eventlistCalendarFill_callback(response, calId, cssPrefix); });
    
}

function eventlistCalendarFill_callback(response, calId, cssPrefix)
{    
    if(response.value != null)
    {
        var tmp;
        var tmpLink;
        var eventdate;
        for(var i = 0; i < response.value.calendar.Rows.length; i++)
        {
            tmp = document.getElementById(calId + '_' + response.value.calendar.Rows[i].square);
            while(tmp.childNodes.length > 0)
            {
                tmp.removeChild(tmp.childNodes[0]);
            }
            if(!response.value.calendar.Rows[i].square.match(/_0$/))
            {
                eventdate = (response.value.calendar.Rows[i].day<10 ? '0' + response.value.calendar.Rows[i].day : response.value.calendar.Rows[i].day) + '-' + (response.value.calendar.Rows[i].month<10 ? '0' + response.value.calendar.Rows[i].month : response.value.calendar.Rows[i].month) + '-' + response.value.calendar.Rows[i].year;
                tmpLink = document.createElement('a');
                tmpLink.href = document[calId + '_page'] +'?eventdate=' + eventdate;
                tmpLink.innerHTML = response.value.calendar.Rows[i].day;
                tmp.appendChild(tmpLink);
                
                if(response.value.calendar.Rows[i].month == response.value.month)
                {
                    tmp.className = (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarInThisMonth';
                    tmpLink.className = (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarInThisMonthLink';
                    
                    if(eventdate == '05-02-2012')
                    {
                        tmp.className = tmp.className + ' ' + (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarToDay';
                        tmpLink.className = tmpLink.className + ' ' + (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarToDayLink';
                    }
                    
                    if(document['eventdate'] == eventdate)
                    {
                        tmp.className = tmp.className + ' ' + (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarEventDate';
                        tmpLink.className = tmpLink.className + ' ' + (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarEventDateLink';
                    }
                }
                else
                {
                   tmp.className = (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarNotInThisMonth';
                   tmpLink.className = (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarNotInThisMonthLink';
                }
                if (response.value.calendar.Rows[i].notempty==true)
                {
                    tmp.className += ' EventlistCalendarDateContainsEvent';
                    tmpLink.className += ' EventlistCalendarDateContainsEvent';
                }                
            }
            else
            {
                tmp.innerHTML = response.value.calendar.Rows[i].day;
                tmp.className = (cssPrefix != null ? cssPrefix : '') + 'EventlistCalendarWeekNumber';
            }
        }
    }
}

function _onLoad(){
	_defaultSize(GetCookie('fontSize'));
}
function _onResize(){
}
function _onUnload(){
}


window.onload = _onLoad;
window.onresize = _onResize;
window.onunload = _onUnload;

var form2submit = null;
var formEnctyped = false;
function preSubmit(formid){
    if(form2submit == null){
        form2submit = document.createElement('input');
        form2submit.type='hidden';
        form2submit.name='skybrudedit_formid';
        form2submit.id='skybrudedit_formid';
        var f = document.forms[0]; 
        if(f != null){
            f.appendChild(form2submit);
        }
    }
    form2submit.value = formid;
}

