﻿// ** BMI ** //
    window.onload = function() {
        var tb1 = document.getElementById('tb1');
        if (tb1) { tb1.focus(); }
        var ifrm = document.getElementById('ifrm');
        if (ifrm) { InitContest(ifrm); }
    };
    function bmi()
    {
        var tb1 = document.getElementById('tb1');
        var tb2 = document.getElementById('tb2');
        var tb3 = document.getElementById('tb3');
        var tb4 = document.getElementById('tb4');
        if (tb1 && tb2 && tb3 && tb4)
        {
            if(!isNaN(parseInt(tb1.value)) && !isNaN(parseInt(tb3.value)))
            {
                tb1.value = tb1.value.replace(',','.');
                tb3.value = tb3.value.replace(',','.');
                tb4.value = tb3.value;
                var _kg = parseFloat(tb1.value);
                var _m = parseFloat(tb3.value);
                var _bmi = (_kg/(_m*_m)).toString();
                if (_bmi.indexOf('.') != -1)
                {
                    tb2.value = _bmi.substring(0, _bmi.indexOf('.')+2);
                }
            }
            else
            {
                tb2.value = '';
                tb4.value = '';
                if (tb1.value.length>0 && isNaN(parseInt(tb1.value))) { tb1.value = '0'; }
                if (tb3.value.length>0 && isNaN(parseInt(tb3.value))) { tb3.value = '0'; }
            }
        }
    }
    
    
    function o(key)
    {
        var win;
        var keys = {
            sms: { 
                src: 'http://annaottosson.se/sms/tjanst.html',
                name: 'sms',
                height: 500,
                width: 600,
                scroll: 1,
                resize: 1,
                center: 1
            }
        };
        var currentKey = eval('keys.'+key);
        if (typeof currentKey=='object')
        {
            var source = (currentKey.src) ? currentKey.src : '';
            var name = (currentKey.name) ? currentKey.name : key;
            var properties = [];
            
            // Height - pixel value (number)
            if (currentKey.height) { properties[properties.length]='height='+currentKey.height+'px'; }
            // Width - pixel value (number)
            if (currentKey.width) { properties[properties.length]='width='+currentKey.width+'px'; }
            // Scrollbars - 1/0 (number)
            if (currentKey.scroll) { properties[properties.length]='scrollbars='+currentKey.scroll+'px'; }
            // Resize - 1/0 (number)
            if (currentKey.resize) { properties[properties.length]='resizable='+currentKey.resize+'px'; }
            // Possition Center - 1/0 (number)
            if (currentKey.center && 
                currentKey.center==1)
            {
                if (currentKey.height) { properties[properties.length]='top='+ (screen.height-currentKey.height)/2 +'px'; }
                if (currentKey.width) { properties[properties.length]='left='+ (screen.width-currentKey.width)/2 +'px'; }
            }
            
            win = window.open(source, name, properties.join(','));
        }
        if (win) { win.focus(); }
    }

// ** Image slideshow ** //
	// imgTour
	var imgCount, imgPointer, imgs

	function imgTour_init(tourSize) { imgCount = 0; imgPointer = 0; imgs = new Array(tourSize); }

	function imgTour_addImage(imgSRC) 
	{
		imgs[imgCount]= imgSRC; 
		imgCount++;
	}

	function imgTour_nextImage() 
	{ 
		// opdater pointer
		imgPointer++;
		if( imgPointer == imgCount ) { imgPointer=0; }
		// vis billede
		document.TopImage.src = imgs[imgPointer];
	}

// timer:
	var delayInMilliSeconds = 2500;

	// start timer to movenext
	var timerID = 0;

	function UpdateTimer() 
	{
	   clearTimer();
					   
	   // Do stuff
	   imgTour_nextImage();
					   
	   // repeat
	   startTimer();
	}

	function startTimer()
	// Sætter timeout som specificeret i rundtur eller slideshow()
	{
	   timerID  = setTimeout("UpdateTimer()", delayInMilliSeconds );
	}

	function clearTimer()
	{
	   if(timerID) {
		  clearTimeout(timerID);
	   }
	}

