/*
  cp_media.js
  Copyright (C) 2007, Cinematica Producciones Ltda.
  Author: Andres Melguizo Velez
  Created: 20070221
  Modified: 20070314
*/

// Generate the code to insert a Flash
// Usage:   var s = makeFlash("idMyFlash", "BannerTop.swf", 393, 83, "#FFFFFF", "frase1=Esta es la línea 1 de la Frase+frase2=+time=1+img1=img_title_image_1.jpg+img2=img_title_image_2.jpg+img3=img_title_image_3.jpg");
function makeFlash(szId, szMovie, iWidth, iHeight, szBgColor, szUrlParams) {
  //szUrlParams = szUrlParams.replace("+", "&");
  //szUrlParams = "frase1=" + "Esta es la frase 1" + "+frase2=Esta es la frase 2+time=1+img1=img_title_image_1.jpg+img2=img_title_image_2.jpg+img3=img_title_image_3.jpg";
  var szUrl = szMovie + "?" + szUrlParams; // escape(szUrlParams);
  var s =
    "<object id='" + szId + "' name='" + szId + "' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + iWidth + "' height='" + iHeight + "'>" +
    "  <param name='allowScriptAccess' value='sameDomain' />" +
    "  <param name='movie' value='" + szUrl + "' />" +
    "  <param name='quality' value='high' />" +
    "  <param name='bgcolor' value='" + szBgColor + "' />";
  szUrl = szMovie + "?" + utf8(szUrlParams);
  s += "  <embed id='" + szId + "' name='" + szId + "' src='" + szUrl + "' quality='high' bgcolor='" + szBgColor + "' width='" + iWidth + "' height='" + iHeight + "' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
    "</object>";
  return(s);
}

/*
  utf8 character conversion
  Original code at: http://www.worldtimzone.com/res/encode/, http://www.doxdesk.com/
*/
function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}
