//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


function IntroducirReproductorVideo(idDivReproductor, UrlVideo, extencionVideo, ancho, alto)
{
    var objDivContenedor = document.getElementById(idDivReproductor);
    var ContenidoDiv = "";
    
    if(objDivContenedor != null)
    {
        if(UrlVideo.length > 0 && extencionVideo.length > 0 && !isNaN(ancho) && !isNaN(alto))
        {
            if(extencionVideo == 'flv' || extencionVideo == 'swf')
            {
                var s1 = new SWFObject("flash/mediaplayer.swf","mediaplayer",ancho,alto,7);
                s1.addParam("allowfullscreen","true");
                s1.addParam("wmode", "transparent");
                s1.addVariable("width",ancho);
                s1.addVariable("height",alto);
                s1.addVariable("file",UrlVideo);
                s1.write(idDivReproductor);
            }
            else if(extencionVideo == 'wmv' || extencionVideo == 'avi' || extencionVideo == 'mpg' || extencionVideo == 'mpeg')
            {
                var TipoObjeto, Plugin, CodeBase;
                if(extencionVideo == 'mpg' || extencionVideo == 'mpeg')
                {
                    TipoObjeto = "application/x-mplayer2";
                    Plugin = "";
                    CodeBase = "";
                }
                else
                {
                    TipoObjeto = "application/x-mplayer2";
                    Plugin = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0";
                    CodeBase = "http://www.microsoft.com/Windows/MediaPlayer/";
                }
                ContenidoDiv = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="' + ancho + 'px" height="' + alto + 'px" codebase="' + CodeBase + '"> ' +
                               '    <param name="Filename" value="' + UrlVideo + '"/> ' +
                               '    <param name="AutoStart" value="true"> ' +
                               '    <param name="ShowControls" value="true"> ' +
                               '    <param name="BufferingTime" value="2"> ' +
                               '    <param name="ShowStatusBar" value="false"> ' +
                               '    <param name="AutoSize" value="true"> ' +
                               '    <param name="InvokeURLs" value="false"> ' +
                               '    <param name="wmode" value="transparent"> ' +
                               '    <param name="width" value="' + ancho + '"> ' +
                               '    <param name="height" value="' + alto + '"> ' +
                               '    <embed src="' + UrlVideo + '" type="' + TipoObjeto + '" autostart="1" enabled="1" showstatusbar="0" showdisplay="0" showcontrols="1" pluginspage="' + CodeBase + '" CODEBASE="' + Plugin + '" width="' + ancho + 'px" height="' + alto + 'px"></embed> ' +
                               '</object> ' 
            }
            else
            {
                ContenidoDiv = '<img alt="" src="g/img_videos_default.gif" style="height: 269; width: 326" />';
            }
        }
        else
        {
            ContenidoDiv = '<img alt="" src="g/img_videos_default.gif" style="height: 269px; width: 326px;" />';
        }
        //VERIFICA SI DEBE INCLUIR CONTENIDO EN EL DIV
        if(ContenidoDiv.length > 0)
        {
            if(navigator.appName == "Microsoft Internet Explorer")
            {
                var contenidodivaux = '<div id="' + idDivReproductor + '" class="cntr_controlvideo" style="width:' + ancho +'px;height:' + alto + 'px;">' + ContenidoDiv + '</div> ';
                objDivContenedor.outerHTML = contenidodivaux;
            }
            else
            {
                objDivContenedor.innerHTML = ContenidoDiv;
            }
        }
    }
    else
    {
        alert('Error cargando video');
    }
}