// programa: tutti.js
// tipo: javascript library
// contiene: rutinas de uso comun
// dependencias:
// autor: Faure, Daniel
// email: faure_daniel@yahoo.com.ar
//

function inti(a,b,f,c,advise,wi) {
 if (!advise) {advise=0;}
 if (advise) {
  var adiv=document.getElementById('advise');
  superdic(0);
  adiv.className='advise on';
 }
 xmlhttpPost(a,b,f,c,wi);
}

var doc1='Estrategia_Mensual.pdf';
var doc2='Portafolio_Fondos.pdf';
var doc3='Guia_Fondos.pdf';
var des1='Conozca nuestro<br/>Informe de<br/>Estrategia Mensual';
var des2='Consulte nuestro<br/>Portafolio de<br/>Fondos Sugeridos';
var des3='Vea la Gu&iacute;a<br/>de Fondos<br/>de RJ Delta';

function alegria() {
 var unoj=document.getElementById('longon');
 var doc;
 var des;
 if (unoj.className == 'longon longon1') {
  unoj.className = 'longon longon2';
  doc = doc2;des = des2;
 } else if (unoj.className == 'longon longon2') {
  unoj.className = 'longon longon3';
  doc = doc3;des = des3;
 } else {
  unoj.className = 'longon longon1';
  doc = doc1;des = des1;
 };
 des=des+'<br/><br/>';
 unoj.innerHTML = "<br/>" +
                  des +
                  "<div class='tonbo' ><a href='Resources/mensual/" +
                  doc +
                  "' target='_blank' onclick=javascript:window.open(this.href, 'PopUp' "+
                  "'width=808, height=647, menubar=no, toolbar = no, location= NO, " +
                  "resizable=no, modal=yes');return false;><img "+
                  "src='img/tonbonoti.jpg' alt='click' /></a></div>";
}

function longon() {
 var unoj=document.getElementById('longon');
 unoj.className='longon on';
}
function longon_cancel() {
 var unoj=document.getElementById('longon');
 unoj.className='longon off';
}

function xmlhttpPost(strURL,whatif,xform,xparams,wi) {
    var xmlHttpReq = false;
    var self = '';
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
     self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    // IE
     self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function() {
     if (self.xmlHttpReq.readyState == 4) {
      switch (whatif) {
       case 'docapacitaciones':
       case 'dofamilia':
       case 'doestudio':
        //alert(self.xmlHttpReq.responseText);
        update_popme_div(self.xmlHttpReq.responseText,whatif,wi);
        break;
       case 'dodelivery':
        //alert(self.xmlHttpReq.responseText);
        update_delivery_div(self.xmlHttpReq.responseText,whatif,wi);
        break;
       default:
        alert(whatif);
        break;
      }
     }
    }

    self.xmlHttpReq.send(getquerystring(whatif,xform,xparams));
}

function getquerystring(whatif,xform,xparams) {
    var form=document.getElementById('xform');
    var qstr='author=dfaure';
    switch (whatif) {
     case 'docapacitaciones':
     case 'dofamilia':
     case 'doestudio':
      qstr = qstr + '&pwho=IOI';
      qstr = qstr + '&'+xparams;
      break;
     case 'dodelivery':
      qstr = qstr + '&'+xparams;
      break;
    }
    return qstr;
}

function update_popme_div(str,divid,wi){
    //popme_show(wi); REHABILITAR!
    var unoj=document.getElementById('popme_titulo');
    var isi=str.match(/\<new_titulo\>(.*?)\<\/new_titulo\>/);
    document.getElementById('popme_titulo').innerHTML = isi[1];
    unoj=document.getElementById('popme_contenido');
    isi=str.match(/\<new_content\>(.*?)\<\/new_content\>/);
    document.getElementById('popme_contenido').innerHTML = isi[1];
}

function update_delivery_div(str,divid,wi){
    popme_show(wi);
    var unoj=document.getElementById('dodelivery_here');
    // posibilidad de ir acumulando los resultados;
    //var isi=str.match(/\<new_titulo\>(.*?)\<\/new_titulo\>/);
    //document.getElementById('dodelivery_here').innerHTML = isi[1];
    document.getElementById('dodelivery_here').innerHTML = str;
    unoj=document.getElementById('popme_contenido');
    //isi=str.match(/\<new_content\>(.*?)\<\/new_content\>/);
    //document.getElementById('popme_contenido').innerHTML = isi[1];
}

function popme_close(){
    var unoj=document.getElementById('popme');
    unoj.className='popme_hide';
}

function popme_show(wi){
    var unoj=document.getElementById('dodelivery_here');
    unoj.className='popme_show';
    unoj.style.width=wi+'px';
}

