

var Votac = {

  movieUrl: '/votac.1.1/flash/votac.swf',
  movieUrlAlt: '/votac.1.1/flash/votac_alt.swf',
  userDefault: 'invitado',
  idDivContainer: 'votacObject', // valor por defecto, para uso con jquery

  votShow: function (OBJID,OBJTIPO,PATH_TAX,OBJTIT) {

    if(typeof ConfigVotac == 'undefined') {
        document.write('<!-- No se encontro el objeto de configuracion ConfigVotac -->');
        return;
    };

    var wFlash = ConfigVotac.anchoFlash;
    var hFlash = ConfigVotac.altoFlash;
    var wmode = ConfigVotac.wmodeFlash;
    var flashvars = "&OBJID=" + Votac.votDespulga(OBJID)
                + "&OBJTIPO=" + Votac.votDespulga(OBJTIPO)
                + "&PATH_TAX=" + Votac.votDespulga(Votac.votRePath(PATH_TAX))
                + "&NICK=" + Votac.userDefault
                + "&OBJTIT=" + Votac.votEncode(Votac.desEntities(OBJTIT));

    var tag4Flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
                + '  codebase="http://active.macromedia.com/flash6/cabs/swflash.cab#version=6,0,0,0"'
                + '  width="'+wFlash+'"'
                + '  height="'+hFlash+'">'
                + '  <param name="movie" value="' + Votac.movieUrl + '">'
                + '  <param name="play" value="true">'
                + '  <param name="loop" value="true">'
                + '  <param name="quality" value="high">'
                + '  <param name="wmode" value="' + wmode + '">'
                + '  <param name="flashvars" value="' + flashvars + '" />'
                + '  <embed'
                + '      type="application/x-shockwave-flash"'
                + '      pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"'
                + '      src="' + Votac.movieUrl + '"'
                + '      width="'+wFlash+'"'
                + '      height="'+hFlash+'"'
                + '      play="true"'
                + '      loop="true"'
                + '      quality="high"'
                + '      wmode="' + wmode + '"'
                + '      flashvars="' + flashvars + '" />'
                + '  </embed>'
                + '  </object>';

    if(typeof $ == 'undefined') {
        document.write(tag4Flash);
    } else {
        $('#' + Votac.idDivContainer).html(tag4Flash);
    };

  },

  votShowAlt: function (OBJID,OBJTIPO,PATH_TAX,OBJTIT) {

    if(typeof ConfigVotac == 'undefined') {
        document.write('<!-- No se encontro el objeto de configuracion ConfigVotac -->');
        return;
    };

    var wFlash = ConfigVotac.anchoFlashAlt;
    var hFlash = ConfigVotac.altoFlashAlt;
    var wmode = ConfigVotac.wmodeFlash;
    var flashvars = "&OBJID=" + Votac.votDespulga(OBJID)
                + "&OBJTIPO=" + Votac.votDespulga(OBJTIPO)
                + "&PATH_TAX=" + Votac.votDespulga(Votac.votRePath(PATH_TAX))
                + "&NICK=" + Votac.userDefault
                + "&OBJTIT=" + Votac.votEncode(Votac.desEntities(OBJTIT));

    var tag4Flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
                + '  codebase="http://active.macromedia.com/flash6/cabs/swflash.cab#version=6,0,0,0"'
                + '  width="'+wFlash+'"'
                + '  height="'+hFlash+'">'
                + '  <param name="movie" value="' + Votac.movieUrlAlt + '">'
                + '  <param name="play" value="true">'
                + '  <param name="loop" value="true">'
                + '  <param name="quality" value="high">'
                + '  <param name="wmode" value="' + wmode + '">'
                + '  <param name="flashvars" value="' + flashvars + '" />'
                + '  <embed'
                + '      type="application/x-shockwave-flash"'
                + '      pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"'
                + '      src="' + Votac.movieUrlAlt + '"'
                + '      width="'+wFlash+'"'
                + '      height="'+hFlash+'"'
                + '      play="true"'
                + '      loop="true"'
                + '      quality="high"'
                + '      wmode="' + wmode + '"'
                + '      flashvars="' + flashvars + '" />'
                + '  </embed>'
                + '  </object>';

    if(typeof $ == 'undefined') {
        document.write(tag4Flash);
    } else {
        $('#' + Votac.idDivContainer).html(tag4Flash);
    };

  },

  votRePath: function(txt) {
    txt = txt.replace(/;/g, '/');
    return txt;
  },

  votDespulga: function(txt) {
    txt = txt.toLowerCase();
    txt = txt.replace(/^\s+/g, '');
    txt = txt.replace(/\s+$/g, '');
    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, 'u');
    txt = txt.replace(/ /g, '_');
    txt = txt.replace(/[^0-9a-z\/\_\-]/g, '');
    return txt;
  },

  votEncode: function(txt) {
    txt = txt.replace(/&/g, '|amp;');
    txt = txt.replace(/á/g, '|aacute;');
    txt = txt.replace(/é/g, '|eacute;');
    txt = txt.replace(/í/g, '|iacute;');
    txt = txt.replace(/ó/g, '|oacute;');
    txt = txt.replace(/ú/g, '|uacute;');
    txt = txt.replace(/ñ/g, '|ntilde;');
    txt = txt.replace(/ü/g, '|uuml;');
    txt = txt.replace(/Á/g, '|aacute;');
    txt = txt.replace(/É/g, '|eacute;');
    txt = txt.replace(/Í/g, '|iacute;');
    txt = txt.replace(/Ó/g, '|oacute;');
    txt = txt.replace(/Ú/g, '|uacute;');
    txt = txt.replace(/Ñ/g, '|ntilde;');
    txt = txt.replace(/Ü/g, '|uuml;');
    txt = txt.replace(/\"/g, '|quot;');
    txt = txt.replace(/\'/g, '|quot;');
    txt = txt.replace(/¡/g, '|iexcl;');
    txt = txt.replace(/ /g, '|nbsp;');
    txt = txt.replace(/[^0-9a-zA-Z\/\_\-\|\;]/g, '');
    return txt;
  },

  desEntities: function(txt) {
    txt = txt.replace(/&aacute;/g, 'á');
    txt = txt.replace(/&eacute;/g, 'é');
    txt = txt.replace(/&iacute;/g, 'í');
    txt = txt.replace(/&oacute;/g, 'ó');
    txt = txt.replace(/&uacute;/g, 'ú');
    txt = txt.replace(/&ntilde;/g, 'ñ');
    txt = txt.replace(/&uuml;/g, 'ü');
    txt = txt.replace(/&Aacute;/g, 'Á');
    txt = txt.replace(/&Eacute;/g, 'É');
    txt = txt.replace(/&Iacute;/g, 'Í');
    txt = txt.replace(/&Oacute;/g, 'Ó');
    txt = txt.replace(/&Uacute;/g, 'Ú');
    txt = txt.replace(/&Ntilde;/g, 'Ñ');
    txt = txt.replace(/&Uuml;/g, 'Ü');
    txt = txt.replace(/&quot;/g, '"');
    txt = txt.replace(/&iexcl;/g, '¡');
    txt = txt.replace(/&nbsp;/g, ' ');
    txt = txt.replace(/&amp;/g, '&');
    txt = txt.replace(/&\w+;/g, '');
    return txt;
  }
};