// ************************************************************
// Funktioner til brug for omgåelse af IE flash problematik
// ************************************************************
// Version 1.00 (c) Datagraf Auning AS
// ************************************************************
// I Internet Explorer er det nødvendigt at klikke på hvert
// flash element for at aktivere dette.
// Javascript funktionerne i denne fil omgår dette, så det ikke
// er nødvendigt at klikke for at aktivere flash elementer.
//
// WriteFlash2 utf-8 encoder tekster så de vises rigtigt i flash versioner over 5.
//
// ************************************************************

function WriteFlash(url,width,height,bgcolor,wmode,version,scriptaccess,name,align) {
	var out        = '';
	var embedParam = '';
	out += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" width="'+width+'" height="'+height+'" id="'+name+'" align="'+align+'">';
	out += '<param name="movie" value="'+url+'">';
	out += '<param name="menu" value="false">';
	out += '<param name="bgcolor" value="'+bgcolor+'">';
	out += '<param name="allowScriptAccess" value="'+scriptaccess+'">';

	embedParam += 'bgcolor="'+bgcolor+'" ';
	embedParam += 'allowScriptAccess="'+scriptaccess+'" ';
	
	if (wmode==true) {
		out += '<param name="WMODE" value="Transparent">';
		embedParam += 'WMODE="Transparent" ';
	}
	
	out += '<param name="quality" value="high">';
	out += '<embed menu="false" src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" name="'+name+'" align="'+align+'" '+embedParam+'></embed></object>';
	document.write(out);
}


function RandomFlash(htmlarray) {
	var arraylength = html_array.length;
	var arrayindex  = Math.floor( Math.random() * arraylength );
	document.write(htmlarray[arrayindex]);
}


// According to RFC 3986, only characters from a set of reserved and a set
// of unreserved characters are allowed in a URL:
var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var reserved = "!*'();:@&=+$,/?%#[]";
var allowed = unreserved + reserved;
var hexchars = "0123456789ABCDEFabcdef";

// --------------------------------- Encoding -------------------------------

// This function returns a percent sign followed by two hexadecimal digits.
// Input is a decimal value not greater than 255.
function gethex(decimal) {
  return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
  }




function WriteFlash2(url,width,height,bgcolor,wmode,version,scriptaccess,name,align,txt) {
 

  // Some variables:
  var decoded = txt;
  var encoded = "";


  
  // ---------------- If UTF-8 character encoding was chosen: ----------------

    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {

        // The position in the Unicode table tells us how many bytes are needed.
        // Note that if we talk about first, second, etc. in the following, we are
        // counting from left to right:
        //
        //   Position in   |  Bytes needed   | Binary representation
        //  Unicode table  |   for UTF-8     |       of UTF-8
        // ----------------------------------------------------------
        //     0 -     127 |    1 byte       | 0XXX.XXXX
        //   128 -    2047 |    2 bytes      | 110X.XXXX 10XX.XXXX
        //  2048 -   65535 |    3 bytes      | 1110.XXXX 10XX.XXXX 10XX.XXXX
        // 65536 - 2097151 |    4 bytes      | 1111.0XXX 10XX.XXXX 10XX.XXXX 10XX.XXXX

        var charcode = decoded.charCodeAt(i);

        // Position 0 - 127 is equal to percent-encoding with an ASCII character encoding:
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        }

        // Position 128 - 2047: two bytes for UTF-8 character encoding.
        if (charcode > 127 && charcode < 2048) {
          // First UTF byte: Mask the first five bits of charcode with binary 110X.XXXX:
          encoded = encoded + gethex((charcode >> 6) | 0xC0);
          // Second UTF byte: Get last six bits of charcode and mask them with binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 2048 - 65535: three bytes for UTF-8 character encoding.
        if (charcode > 2047 && charcode < 65536) {
          // First UTF byte: Mask the first four bits of charcode with binary 1110.XXXX:
          encoded = encoded + gethex((charcode >> 12) | 0xE0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 65536 - : four bytes for UTF-8 character encoding.
        if (charcode > 65535) {
          // First UTF byte: Mask the first three bits of charcode with binary 1111.0XXX:
          encoded = encoded + gethex((charcode >> 18) | 0xF0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Fourth UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

      }

    }  // end of for ...


	var out        = '';
	var embedParam = '';
	out += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" width="'+width+'" height="'+height+'" id="'+name+'" align="'+align+'">';
	out += '<param name="movie" value="'+url+'&txt='+encoded+'">';
	out += '<param name="menu" value="false">';
	out += '<param name="bgcolor" value="'+bgcolor+'">';
	out += '<param name="allowScriptAccess" value="'+scriptaccess+'">';

	embedParam += 'bgcolor="'+bgcolor+'" ';
	embedParam += 'allowScriptAccess="'+scriptaccess+'" ';
	
	if (wmode==true) {
		out += '<param name="WMODE" value="Transparent">';
		embedParam += 'WMODE="Transparent" ';
	}
	
	out += '<param name="quality" value="high">';
	out += '<embed menu="false" src="'+url+'&txt='+encoded+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" name="'+name+'" align="'+align+'" '+embedParam+'></embed></object>';
	document.write(out);
}

