





































// Loop up a table of hex encoded chars
function CharUtil()
{
    // Only static methods ...
}

CharUtil.HEX_CHARS = "0123456789ABCDEF";

CharUtil.hexTable = function()
{
    var arr = new Array (256);
    for (var i = 0; i < 256; i++)
    {
        arr[i] = "%" + CharUtil.HEX_CHARS.charAt (i>>4) +
            "" + CharUtil.HEX_CHARS.charAt (i%16);
    }
    return arr;
}

CharUtil.HEX_TABLE = CharUtil.hexTable();

CharUtil.charCodeToHex = function
(
    i
)
{
    return CharUtil.HEX_TABLE[i];
}




// Constructor for UTF8 url-encoder (used to insert parameters into the _root timeline).
function URLEncoder()
{
    // Default is to encode all char values
    this.encode_table = new Array (256);
    for (var i = 0; i < 256; i++)
    {
        this.encode_table[i] = true;
    }

    // And then we may want to turn the switch back off for some chars...
    this.dontEncode = function
    (
        c1,
        c2
    )
    {
        var

            i1 = c1.charCodeAt (0),
            i2 = c2.charCodeAt (0);

        for (var i = i1; i < i2; i++)
        {
            this.encode_table[i] = false;
        }
    }


    // I wrote the function below after looking at
    // http://cvs.sourceforge.net/viewcvs.py/lazy-x/src/URLUTF8Encoder.java
    this.encode = function
    (
        str
    )
    {
        var str_buf = "";

        for (var i = 0; i < str.length; i++)
        {
            var c = str.charCodeAt (i);

            // Don't encode the plain ascii ones
            if (!this.encode_table[c])
            {
                str_buf += str.charAt (i);
            }

            else if (c <= 0x007f)
            {
                // other ASCII <= 127
                str_buf += CharUtil.charCodeToHex(c);
            }

            else if (c <= 0x07FF)
            {
                // non-ASCII <= 0x7FF
                str_buf += CharUtil.charCodeToHex(0xc0 | (c >> 6));
                str_buf += CharUtil.charCodeToHex(0x80 | (c & 0x3F));
            }

            // The remainder is left in for a rainy day...
            else
            {
                // 0x7FF < c <= 0xFFFF
                str_buf += CharUtil.charCodeToHex(0xc0 | (c >> 12));
                str_buf += CharUtil.charCodeToHex(0x80 | ((c >> 6) & 0x3F));
                str_buf += CharUtil.charCodeToHex(0x80 | (c & 0x3F));
            }
        }
        return str_buf;
    }
}


// Set up a default encoder
URLEncoder.DEFAULT_ENCODER = new URLEncoder();

URLEncoder.DEFAULT_ENCODER.dontEncode ("A","Z");
URLEncoder.DEFAULT_ENCODER.dontEncode ("a","z");
URLEncoder.DEFAULT_ENCODER.dontEncode ("0","9");

URLEncoder.defaultEncode = function
(
    str
)
{
    return URLEncoder.DEFAULT_ENCODER.encode (str);
}




// Gather some plug-in detection in a separate class
function FlashPlugin ()
{
    // Only static methods ...
}

FlashPlugin.MIMETYPE = "application/x-shockwave-flash";
FlashPlugin.DETECT_OVERRIDE = "hasflash";
FlashPlugin.MX_VERSION = 7;

FlashPlugin.parseTailInt = function
(
    str,
    n1,
    n2
)
{
    var

        res = 0,
        mult = 1;

    if (n2 < 0 || n2 >= str.length)
    {
        n2 = str.length - 1;
    }

    for (var i = n2; i >= n1; i--)
    {
        var p = parseInt (str.charAt (i), 10);
        if (isNaN(p))
        {
            return res;
        }
        else
        {
            res += mult*p;
            mult *= 10;
        }
    }
    return res;
}

FlashPlugin.isRequiredVersion = function
(
    required_version
)
{
    if (isNaN(required_version))
    {
        required_version = FlashPlugin.MX_VERSION;
    }

    // First we look in the MimeTypes array
    if
    (
        navigator.mimeTypes &&
        navigator.mimeTypes[FlashPlugin.MIMETYPE] &&
        navigator.mimeTypes[FlashPlugin.MIMETYPE].enabledPlugin
    )
    {
        var desc = navigator.mimeTypes[FlashPlugin.MIMETYPE].enabledPlugin.description;
        if (required_version <= FlashPlugin.parseTailInt (desc, 0, desc.indexOf (".") - 1))
        {
            return true;
        }
    }

    // Then we try to create an ActiveXObject
    if
    (
        document.all && // Then we are in explorer ...
        navigator.userAgent.indexOf("Mac") < 0 // but not on a mac
    )
    {
        try
        {
            new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + required_version);
            return true;
        }
        catch(e)
        {
        }
    }

    return false;
}




// Constructor for the query string parser
function QueryParams
(
    query_str
)
{
    this.params = new Array ();
    this.vals = new Array ();

    if
    (
        query_str != undefined &&
        (
            query_str.indexOf ('?') == 0 ||
            query_str.indexOf ('#') == 0
        )
    )
    {
        query_str = query_str.substring (1);
        var pairs = query_str.split ("&");
        for (var i = 0; i < pairs.length; i++)
        {
            var pair = pairs[i].split ("=");
            this.params[i] = pair[0];
            this.vals[i] = pair.length > 1 ? pair[1] : pair[0]; // NB!
        }
    }

    this.findQueryParam = function
    (
        param
    )
    {
        for (var i = 0; i < this.params.length; i++)
        {
            if (this.params[i] == param)
            {
                return unescape(this.vals[i]);
            }
        }
        return undefined;
    }
}




// Constructor for a collection of flash parameters.
function FlashParams
(
    query_str
)
{
    // Call the superclass
    QueryParams.call (this, query_str);

    // For storing the parameters
    this.encoded = "";

    // Add a parameter/value pair
    this.addParam = function
    (
        param,
        val
    )
    {
        if (val != undefined)
        {
            this.encoded += (this.encoded.length > 0 ? "&" : "?") +
                URLEncoder.defaultEncode ("" + param) +
                "=" + URLEncoder.defaultEncode ("" + val);
        }
    }

    // Look for parameter/value pairs in the query string
    this.addQueryParam = function
    (
        param
    )
    {
        this.addParam (param, this.findQueryParam (param));
    }
}


// Build the inheritance chain
var proto_flash_params = new FlashParams();

// Delete the instance variables of the QueryParams constructor
delete proto_flash_params.params;
delete proto_flash_params.vals;
delete proto_flash_params.findQueryParam;

proto_flash_params.constructor = FlashParams;
FlashParams.prototype = proto_flash_params;


// Set a common parameter for FlashParams living in a browser.
FlashParams.IN_BROWSER = "in_browser";
FlashParams.inBrowser = function ()
{
    var flash_params = new FlashParams
    (
        window.location.search ||
        window.location.hash
    );
    flash_params.addParam (FlashParams.IN_BROWSER, true);
    return flash_params;
}




// Constructor for the HTML writing object
function FlashEmbed()
{
    // Wrap some code around the significant objects
    this.flash_params = FlashParams.inBrowser();
    this.addParam = function
    (
        param,
        val
    )
    {
        this.flash_params.addParam (param, val);
    }

    this.addQueryParam = function
    (
        param
    )
    {
        this.flash_params.addQueryParam (param);
    }

    // Default is to just write the code
    this.flash_detected = true;
    this.detect_override = true;

    // Unless this method is called
    this.initDetect = function
    (
        required_version,
        alternate_url,
        alternate_html
    )
    {
        this.flash_detected = FlashPlugin.isRequiredVersion
        (
            required_version
        );

        this.detect_override = FlashPlugin.DETECT_OVERRIDE ==
            this.flash_params.findQueryParam (FlashPlugin.DETECT_OVERRIDE);

        this.alternate_url = alternate_url;
        this.alternate_html = alternate_html == undefined ?

            FlashEmbed.noFlashMessage (required_version) :
            alternate_html;
    }


    // The actual embedding
    this.doEmbed = function
    (
        src,
        wdt,
        hgt,
        col
    )
    {
        if (this.flash_detected || this.detect_override)
        {
            src = src + this.flash_params.encoded;

            var code = '<object \n' +
                '    classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \n' +
                '    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" \n' +
                '    width="' + wdt + '" height="' + hgt + '">\n' +
                '    <param name="allowScriptAccess" value="sameDomain" />\n' +
                '    <param name="movie" value="' + src + '" />\n' +
                '    <param name="quality" value="best" />\n' +
                '    <param name="menu" value="false" />\n' +
                '    <param name="align" value="lt" />\n' +
                '    <param name="scale" value="exactfit" />\n' +
                '    <param name="bgcolor" value="' + col + '" />\n' +
                '<embed \n' +
                '    src="' + src + '" \n' +
                '    quality="best" scale="exactfit" salign="lt" menu="false" \n' +
                '    bgcolor="' + col + '" \n' +
                '    width="' + wdt + '" \n' +
                '    height="' + hgt + '" \n' +
                '    type="application/x-shockwave-flash" \n' +
                '    allowScriptAccess="sameDomain" \n' +
                '    pluginspage="http://www.macromedia.com/go/getflashplayer">\n' +
                '</embed></object>';

            document.writeln (code);
        }

        else if
        (
            this.alternate_url != undefined &&
            this.alternate_url.length > 0
        )
        {
            window.location.replace (this.alternate_url);
        }

        else
        {
            document.writeln (this.alternate_html);
        }
    }
}


// Statics / default values
FlashEmbed.DOWNLOAD_FLASH_URL = "http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
FlashEmbed.FORCE_EMBED_URL = window.location.href + (window.location.search.length > 0 ? "&" : "?") + FlashPlugin.DETECT_OVERRIDE;

FlashEmbed.NO_FLASH_1 = '<p>We could not detect Flash ';
FlashEmbed.NO_FLASH_2 = ' on your system. Please visit <a href="' +
    FlashEmbed.DOWNLOAD_FLASH_URL + '">Adobe.com</a> to download the free Flash player. ' +
    '(Expert mode: If you <em>know</em> you have the latest version installed, ' +
    'click <a href="' + FlashEmbed.FORCE_EMBED_URL + '">here</a> to ' +
    'deactivate Flash detection on this page.)</p>';


FlashEmbed.noFlashMessage = function
(
    required_version
)
{
    return FlashEmbed.NO_FLASH_1 + required_version + FlashEmbed.NO_FLASH_2;
}




ssi_aid   = "2324";
ssi_title = "Karmøy kommune";
ssi_cyear = "2003";
ssi_lang  = "";
ssi_epid  = "";


ssi_tick_text_color   = "0x000000";
ssi_tick_back_color_1 = "0xe6ebeb";
ssi_tick_back_color_2 = "0xe6ebeb";


var

    TICKER_SRC = "ticker_src",
    IMAGE_PATH = "image_prepend",

    TEXT_COLOR = "text_color",
    BACK_COLOR_1 = "back_color_1",
    BACK_COLOR_2 = "back_color_2";




// Configure the swf
var flash_embed = new FlashEmbed ();




var ticker_src = "/ksysekstern/servlet/ksysex?aid=" + ssi_aid + "&lang=" + ssi_lang + "&epid=" + ssi_epid + "&action=date&det=0&shw=1&fla=1";



//ticker_src = "/ksys/ticker/data.txt";
//prompt ("", ticker_src);



// Source files
flash_embed.addParam
(
    TICKER_SRC,
    ticker_src
);

flash_embed.addParam
(
    IMAGE_PATH,
    "/images/"
);





// Visual appearance
flash_embed.addParam
(
    TEXT_COLOR,
    ssi_tick_text_color
);

flash_embed.addParam
(
    BACK_COLOR_1,
    ssi_tick_back_color_1
);

flash_embed.addParam
(
    BACK_COLOR_2,
    ssi_tick_back_color_2
);




// Generate alternate HTML
var gig_header = "Hva skjer i dag? Klikk her for å se...";
if (ssi_lang == "NN")
{
    gig_header = "Kva skjer i dag? Klikk her for å sjå...";
}
var today = new Date();
var y = today.getFullYear();
var m = today.getMonth();
var d = today.getDate();

var bg_color = "#" + ssi_tick_back_color_2.substring(2);
var fg_color = "#" + ssi_tick_text_color.substring(2);


var alternate_html = '<div class="ticker-div" style="background-color:' + bg_color + '"><a class="ticker-a" style="color:' + fg_color + '" href="/ksys/find.shtml?year=' + y + '&mon=' + m + '&day=' + d + '&vie=prg">' + gig_header + '</a></div>';




// Plugin detection
flash_embed.initDetect
(
    7,
    null,
    alternate_html
);




// Embed the swf
flash_embed.doEmbed
(
    "/ksys/common/flash/ticker/KsysTicker.swf",
    193,
    270,
    "#ffffff"
);
