// Funciones para la inserción y manejo de Flashs
// v1.0 - 2008/05/13 - CVI - Primera Versión
// TODO: Validación del Area Flash

// -----------------------------------------------------------------------------
// Función para insertar el Image Fade
//    f: Ruta al archivo del artículo o link asociado
//    w: Ancho del flash (en este caso, de las imágenes)
//    h: Alto del flash (en este caso, de las imágenes)
//    t: Target del link (al hacer click)
//    img1-img4: rutas hacia los archivos de imágenes.
function insert_img_fade(f, w, h, t, img1, img2, img3, img4) {

    var swf = '/prontus_nots/prontus/prontus_imgfade_8.0.swf';
    var ancho = w;
    var alto = h;
    if(ancho && alto) {
        var linkurl = f;
        var urlartic = f;
        var target = t;
        var foto1 = img1;
        var foto2 = img2;
        var foto3 = img3;
        var foto4 = img4;

        var idObj = 'imgFade' + Math.floor(Math.random()*10000);
        var flashvars = 'linkurl='+linkurl+'&urlartic='+urlartic+'&target='+target+'&foto1='+foto1+'&foto2='+foto2+'&foto3='+foto3+'&foto4='+foto4;
        var strSwf = getStringObject(swf, idObj, ancho, alto, flashvars, '', '', '');
        document.write(strSwf);
    };
};

// -----------------------------------------------------------------------------
// Función para insertar un FlashCualquiera
//    s: Ruta completa hacia el flash
//    w: Ancho del flash (en este caso, de las imágenes)
//    h: Alto del flash (en este caso, de las imágenes)
function insert_flash(s, w, h) {

    var swf = s;
    var ancho = w;
    var alto = h;
    var idObj = 'flash' + Math.floor(Math.random()*10000);
    var strSwf = getStringObject(swf, idObj, ancho, alto, '', '', '', '');
    document.write(strSwf);
};


// -----------------------------------------------------------------------------
// Función para insertar el Especial
//      fx:     Path al xml del especial
//      wswf:   Ancho del Especial
//      hswf:   Alto del Especial
//      thisid: Id del Flash
function showEspecial(fx, wswf, hswf, thisid) {

    var swf = '/prontus_nots/flash/_Especiales.swf';
    var ancho = '300';
    var alto = '315';
    var idObj = 'idFlashEspecial';
    if(thisid) idObj = idObj + thisid;
    if(wswf != '') ancho = wswf;
    if(hswf != '') alto = hswf;
    var flashvars = 'xml='+fx;
    var strSwf = getStringObject(swf, idObj, ancho, alto, flashvars, '', '', '');
    document.write(strSwf);
};


// -----------------------------------------------------------------------------
// Función para insertar el Fotorama
//      xml:    XML Con los datos del Fotorama
//      tipo:   Tipo de fotorama: video, foto, multimedia, audio
//      wft:    Ancho del Fotorama
//      hft:    Alto del Fotorama
//      thisid: Id del Flash
function showFotorama(xml,tipo,wft,ratio,thisid) {

    if(xml=='' || tipo=='') {
        return;
    };

    var movieUrl    = "/prontus_nots/flash/_Fotorama.swf";

    var urlFoto         = "/prontus_nots/flash/_PlayerFoto.swf";
    var urlVideo        = "/prontus_nots/flash/_PlayerVideo.swf";
    var urlAudio        = "/prontus_nots/flash/_PlayerAudio.swf";
    var urlMultimedia   = "/prontus_nots/flash/_PlayerMultimedia.swf";

    var idObj = 'idFlashFotorama';
    if(thisid) idObj = idObj + thisid;

    if(wft=='' || wft==null) {
        var ancho = '300';
        var alto = '400';

    } else {

        if(ratio=='' || ratio==null) {
            var ratio = '0.75';
        }

        if(tipo=='video') {
            var ancho = parseInt(wft) + 8;
            var alto = parseInt(parseInt(wft)*parseFloat(ratio) + 179 + 8 + 45);

        } else if(tipo=='audio') {
            var ancho = parseInt(wft) + 8;
            var alto = parseInt(parseInt(wft)*parseFloat(ratio) + 229 + 8);

        } else if(tipo=='multimedia') {
            var ancho = parseInt(wft) + 8;
            var alto = parseInt(parseInt(wft)*parseFloat(ratio) + 179 + 8);

        } else if(tipo=='foto') {
            var ancho = parseInt(wft) + 8;
            var alto = parseInt(parseInt(wft)*parseFloat(ratio) + 179 + 8);

        } else {
            var ancho = '300';
            var alto = '400';
        };
    };

    var flashvars = "xml=" + xml
          + "&tipo=" + tipo
          + "&urlFoto=" + urlFoto
	      + "&urlVideo=" + urlVideo
	      + "&urlAudio=" + urlAudio
	      + "&urlMultimedia=" + urlMultimedia;

    var strSwf = getStringObject(movieUrl, idObj, ancho, alto, flashvars, '', '', '');
    document.write(strSwf);

};

// -----------------------------------------------------------------------------
// Función para insertar el player de Video con dimensiones variables.
//      xml:    URL al xml del video a reproducir.
//      start:  Partida en play, stop o pausa (stop con precarga del audio). 0:stop, 1:play, 2:pause
//      vol:    Volumen por defecto (posición inicial del control de volumen).
//      wvideo: Ancho del Player
//      hvideo: Alto del Player
//      thisid: Id del Flash
function showPlayerVideo(xml,start,vol,wvideo,hvideo,thisid) {

    if(xml=='') {
        return;
    };

    var movieUrl = "/prontus_nots/flash/_PlayerVideo.swf";
    var ancho = '280';
    var alto = '158';
    var idObj = 'idFlashVideo';
    if(thisid) idObj = idObj + thisid;
    if(wvideo != '') ancho = wvideo;
    if(hvideo != '') alto = hvideo;
    var anchoreal = parseInt(ancho) + 8;
    var altoreal = parseInt(alto) + 8 + 45;

    var flashvars = "xml=" + xml
            + "&start=" + start
            + "&vol=" + vol

    var strSwf = getStringObject(movieUrl, idObj, anchoreal, altoreal, flashvars, '', '', '');
    document.write(strSwf);
};

// -----------------------------------------------------------------------------
// Función para insertar el player de Audio
//      xml:    URL al xml del Audio a reproducir.
//      start:  Partida en play, stop o pausa (stop con precarga del audio). 0:stop, 1:play, 2:pause
//      vol:    Volumen por defecto (posición inicial del control de volumen).
//      waudio: Ancho del Player
//      thisid: Id del Flash
function showPlayerAudio(xml,start,vol,waudio,thisid) {

    if(xml=='') {
        return;
    };

    var movieUrl = "/prontus_nots/flash/_PlayerAudio.swf";
    var ancho = '372';
    var alto = '50';
    var idObj = 'idFlashAudio';
    if(thisid) idObj = idObj + thisid;
    if(waudio != '') ancho = waudio;

    var flashvars = "xml=" + xml
            + "&start=" + start
            + "&vol=" + vol;
    var strSwf = getStringObject(movieUrl, idObj, ancho, alto, flashvars, '', '', '');
    document.write(strSwf);
};


// -----------------------------------------------------------------------------
// Función para insertar el player de Multimedia
//      xml:        URL al xml del multimedia a reproducir.
//      wswf:       Ancho del Player
//      hswf:       Alto del Player
//      thisid:     Id del Flash
function showPlayerMultimedia(xml,wswf,hswf,thisid) {

    if(xml=='') {
        return;
    };

    var movieUrl = "/prontus_nots/flash/_PlayerMultimedia.swf";
    var ancho = '380';
    var alto = '250';
    var idObj = 'idFlashMultimedia';
    if(thisid) idObj = idObj + thisid;
    if(wswf != '') ancho = wswf;
    if(hswf != '') alto = hswf;

    var flashvars = "xml=" + xml
    var strSwf = getStringObject(movieUrl, idObj, ancho, alto, flashvars, '', '', '');
    document.write(strSwf);

};


// -----------------------------------------------------------------------------
// Función encargada de insertar el Marcador en Portada
function showMarcadorPortada(tipo,thisid,prontusid,wmarc,hmarc,sst_aid,sst_path,sst_tit,sst_tipo) {

    var idFlash = "portada_"+tipo+"_"+thisid;
    var movieUrl = "/"+ prontusid +"/flash/marcador_"+ tipo +"_port.swf";
    var flashvars = "TS="+thisid+"&aid="+encodetext(sst_aid)+"&path=;"+encodetext(sst_path)
                  +"&tit="+encodetext(sst_tit)+"&tipo="+sst_tipo;

    var ancho = '285';
    var alto = '85';
    if(wmarc != '') ancho = wmarc;
    if(hmarc != '') alto = hmarc;

    var params1 = ' align="middle"';
    var params2 = ' <param name="scale" value="exactfit" />';
    params2 = params2 + ' <param name="bgcolor" value="#ffffff" />';
    params2 = params2 + ' <param name="allowScriptAccess" value="always" />';
    var params3 = ' align="middle" scale="exactfit" bgcolor="#ffffff" allowScriptAccess="always" ';
    var strSwf = getStringObject(movieUrl, idFlash, ancho, alto, flashvars, params1, params2, params3);
    document.write(strSwf);

};

// -----------------------------------------------------------------------------
// Función encargada de insertar el Marcador en Marquesina
function showMarcadorMarquesina(tipo,thisid,prontusid,wmarc,hmarc,sst_aid,sst_path,sst_tit,sst_tipo) {

    var idFlash = "portada_"+tipo+"_"+thisid;
    var movieUrl = "/"+ prontusid +"/flash/marcador_"+ tipo +"_marquesina.swf";
    var flashvars = "TS="+thisid+"&aid="+encodetext(sst_aid)+"&path=;"+encodetext(sst_path)
                  +"&tit="+encodetext(sst_tit)+"&tipo="+sst_tipo;

    var ancho = '285';
    var alto = '85';
    if(wmarc != '') ancho = wmarc;
    if(hmarc != '') alto = hmarc;

    var params1 = ' align="middle"';
    var params2 = ' <param name="scale" value="exactfit" />';
    params2 = params2 + ' <param name="bgcolor" value="#ffffff" />';
    params2 = params2 + ' <param name="allowScriptAccess" value="always" />';
    var params3 = ' align="middle" scale="exactfit" bgcolor="#ffffff" allowScriptAccess="always" ';
    var strSwf = getStringObject(movieUrl, idFlash, ancho, alto, flashvars, params1, params2, params3);
    document.write(strSwf);

};

// -----------------------------------------------------------------------------
// Función encargada de insertar el Marcador en Artículo
function showMarcadorArticulo(tipo,thisid,prontusid,wmarc,hmarc,popup,sst_aid,sst_path,sst_tit,sst_tipo) {

    var idFlash = "articulo_"+tipo+"_"+thisid;
    var movieUrl = "/"+ prontusid +"/flash/marcador_"+ tipo +"_art.swf";

    var ancho = '494';
    var alto = '655';
    if(wmarc != '') ancho = wmarc;
    if(hmarc != '') alto = hmarc;

    var flashvars = "TS="+thisid;
    if(popup) {
      flashvars = flashvars + "&POP=javascript%3AsubWin2%28%27/"+ prontusid +"/stat/marcadores/popflash_"+tipo+".html%3Fts%3D"+ thisid +"%26prontus_id%3D"+ prontusid +"%27%2C%27pop"+tipo+"%27%2C494%2C655%2C50%2C50%29";
      flashvars += "&aid="+encodetext(sst_aid)+"&path=;"+encodetext(sst_path)
                 +"&tit="+encodetext(sst_tit)+"&tipo="+sst_tipo;
    };

    var params1 = ' align="middle"';
    var params2 = ' <param name="scale" value="exactfit" />';
    params2 = params2 + ' <param name="bgcolor" value="#ffffff" />';
    var params3 = ' align="middle" scale="exactfit" bgcolor="#ffffff"';
    var strSwf = getStringObject(movieUrl, idFlash, ancho, alto, flashvars, params1, params2, params3);

    document.write(strSwf);
};


// -----------------------------------------------------------------------------
// Función encargada de encontrar el objeto Flash
function getFlashMovieObject(movieName) {

    if (window.document[movieName]) {
        return window.document[movieName];
    };
    if (navigator.appName.indexOf("Microsoft Internet")==-1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    } else {
        return document.getElementById(movieName);
    };
};


// -----------------------------------------------------------------------------
// Devuelve un String con el objeto a insertar en el sitio web
//    swf:        Path al swf
//    idObj:      ID del objeto
//    ancho:      ancho del Flash
//    alto:       alto del flash
//    flashvars:  flashvars que irán hacia el flash
//    params1:    atributos adicionales del tag object
//    params2:    tags "param" adicionales
//    params3:    atributos adicionales del tag embed
function getStringObject(swf, idObj, ancho, alto, flashvars, params1, params2, params3) {

    var str = '';

    // Esta es la sentencia recomendada por la W3C para pasar la validacion sin
    // tener que recurrir a escribir el objeto con Javascript.
    // Aún ahí se utiliza Javascript para mayor seguridad.
    str = str + '<object name="'+idObj+'" id="'+idObj+'"';
    str = str + '  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
    str = str + '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"';
    if(params1) { str = str + ' ' + params1; }
    str = str + '  width="'+ancho+'"';
    str = str + '  height="'+alto+'">' + "\n";
    str = str + ' <param name="movie" value="'+swf+'">' + "\n";
    str = str + ' <param name="play" value="true">' + "\n";
    str = str + ' <param name="loop" value="true">' + "\n";
    str = str + ' <param name="quality" value="high">' + "\n";
    str = str + ' <param name="wmode" value="transparent">' + "\n";
    if(flashvars) { str = str + ' <param name="flashvars" value="'+flashvars+'">' + "\n"; };
    if(params2) { str = str + ' ' + params2 + "\n"; };
    str = str + ' <embed src="'+swf+'"';
    str = str + ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"';
    str = str + ' type="application/x-shockwave-flash"';
    str = str + ' width="'+ancho+'"';
    str = str + ' height="'+alto+'"';
    str = str + ' play="true"';
    str = str + ' loop="true"';
    str = str + ' quality="high"';
    if(flashvars) { str = str + ' flashvars="'+flashvars+'"'; };
    if(params3) { str = str + ' ' + params3; };
    str = str + ' wmode="transparent"> </embed>'+"\n";
    str = str + '</object>' + "\n";
    return str;
};

// -----------------------------------------------------------------------------
// Usado por Alfredo para codificar los datos pasados a los marcadores
function encodetext(texto) {
    var txt = texto;
    if(txt=='' || txt==null) return '';
    txt = txt.replace(/Á/g,'A');
    txt = txt.replace(/É/g,'E');
    txt = txt.replace(/Í/g,'I');
    txt = txt.replace(/Ó/g,'O');
    txt = txt.replace(/Ú/g,'U');
    txt = txt.replace(/á/g,'a');
    txt = txt.replace(/é/g,'e');
    txt = txt.replace(/í/g,'i');
    txt = txt.replace(/ó/g,'o');
    txt = txt.replace(/ú/g,'u');
    txt = txt.replace(/Ñ/g,'N');
    txt = txt.replace(/ñ/g,'n');
    txt = txt.replace(/Ü/g,'U');
    txt = txt.replace(/ü/g,'u');
    txt = txt.replace(/á/g,'a');
    txt = txt.replace(/[^0-9a-zA-Z;\_\- ]/g,'');
    txt = txt.replace(/ /g,'%20');
    return txt;
}; // encodetext



