// programa: tutti.js
// tipo: javascript library
// contiene: rutinas de uso comun
// dependencias:
// autor: Faure, Daniel
// email: faure_daniel@yahoo.com.ar
//

function createREQ() {
try {
     req = new XMLHttpRequest(); /* p.e. Firefox */
     } catch(err1) {
       try {
       req = new ActiveXObject('Msxml2.XMLHTTP'); /* algunas versiones IE */
       } catch (err2) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */
         } catch (err3) {
          req = false;
          alert('Ajax no disponible para este entorno, use FIREFOX!');
         }
       }
     }
     return req;
}

function inti(aUrl,bWhat,xform,xparams,unblur,amenu) {
 if (unblur) {
  blurdiv(unblur);
 }
 var fo = document.getElementById('theForm');
 fo.amenu.value=bWhat;
 //alert(xparams);
 xmlhttpPost(createREQ(),aUrl,bWhat,xform,'langa='+fo.langa.value+'&'+xparams,unblur);
}

function intilang(newlang) {
 blurdiv('theMaenu');
 blurdiv('thebox');
 var fo = document.getElementById('theForm');
 fo.langa.value=newlang;
 xmlhttpPost(createREQ(),'redomaenu.php','changelang','theForm','langa='+newlang);
}

function blurdiv(d) {  $opacity(d, 100, 1, 60);}
function unblurdiv(d) { $opacity(d, 1, 100, 200);}

function __blurdiv(d) {
  var adiv=document.getElementById(d);
  if (d) {
   var oldclass = adiv.className;
   adiv.className = 'blurdiv ' + oldclass ;
  }
}

function __unblurdiv(d,quitaclass) {
  var adiv=document.getElementById(d);
  if (!quitaclass) {quitaclass='blurdiv';}
  if (d) {
   var oldclass = adiv.className;
   var re=new RegExp(quitaclass+' ','g');
   adiv.className = oldclass.replace(re,'');
  }
}

function mierdaquote(t) {
  if (t) {
   var re=new RegExp('"','g');
   t = t.replace(re,'qkk13q');
  }
}

function longon() {
 var unoj=document.getElementById('longon');
 unoj.className='longon on';
}
function longon_cancel() {
 var unoj=document.getElementById('longon');
 unoj.className='longon off';
}

function openclose(d) {
 if (d.className == 'namedivdn') d.className = 'namedivup';
 else d.className = 'namedivdn';
}

function xmlhttpPost(reqi,strURL,whatif,xform,xparams,unblur) {
    reqi.open('POST', 'utils/'+strURL, true);
    reqi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    reqi.onreadystatechange = function() {
     if (reqi.readyState == 4) {
      if(reqi.status == 200) {
       switch (whatif) {
        case 'doagenda':
        case 'doalbum':
        case 'domp3':
        case 'donosotros':
        case 'dohistoria':
        case 'doproximo':
        case 'doenlaces':
        case 'docanciones':
        case 'docontacto':
         //alert(self.xmlHttpReq.responseText);
         update_popme_div(reqi.responseText,whatif,unblur);
         break;
        case 'changelang':
         //alert(self.xmlHttpReq.responseText);
         update_varios_langa(reqi.responseText);
         break;
        default:
         alert(whatif);
         break;
       }
      }
     }
    }
    reqi.send(getquerystring(whatif,xform,xparams));
}

function getquerystring(whatif,xform,xparams) {
    var cform=xform;
    if (cform)
      xform=document.getElementById(xform);
    else
      xform=document.getElementById('theForm');

    var myRand=parseInt(Math.random()*99999999);
    var qstr='author=dfaure&ajaxcalled=1&RND='+myRand+'&sentBy='+cform+'&my='+xform.id;
    switch (whatif) {
     case 'doagenda':
     case 'doalbum':
     case 'domp3':
     case 'donosotros':
     case 'dohistoria':
     case 'doproximo':
     case 'doenlaces':
     case 'docanciones':
     case 'docontacto':
     case 'changelang':
      qstr = qstr + '&'+xparams;
      break;
    }
    if (xform) {
      for (var j = 0; j < xform.elements.length; j++) {
       if (xform.elements[j].type=='radio' ) {
        if (xform.elements[j].checked) {
         qstr=qstr+'&'+xform.elements[j].name+'='+escape(xform.elements[j].value);
        }
       } else {
        qstr=qstr+'&'+xform.elements[j].name+'='+escape(xform.elements[j].value);
       }
      }
    }
    //alert(qstr);
    return qstr;
}

function update_popme_div(str,divid,unblur){
    //popme_show(wi); REHABILITAR!
    //alert(str);
    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];
    if (unblur) {
     unblurdiv(unblur);
    }
}

function update_varios_langa(str){
    var thediv; var unoj;
    //alert(str);

    var theMaenu=str.match(/\<theMaenu\>(.*?)\<\/theMaenu\>/);
    theMaenu=theMaenu[1];
    if (theMaenu) {
     thediv=theMaenu.match(/\<redodiv\>(.*?)\<\/redodiv\>/);
     unoj=document.getElementById(thediv[1]);
     if (unoj) {
      var isilang=theMaenu.match(/\<new_data\>(.*?)\<\/new_data\>/);
      unoj.innerHTML = isilang[1];
      reinitmenus();
     }
    }
    unoj=null;
    var theAd=str.match(/\<theAd\>(.*?)\<\/theAd\>/);
    theAd=theAd[1];
    if (theAd) {
     thediv=theAd.match(/\<redodiv\>(.*?)\<\/redodiv\>/);
     unoj=document.getElementById(thediv[1]);
     if (unoj) {
      var isilang=theAd.match(/\<new_data\>(.*?)\<\/new_data\>/);
      unoj.innerHTML = isilang[1];
     }
    }
    unoj=null;
    var theContent=str.match(/\<theContent\>(.*?)\<\/theContent\>/);
    theContent=theContent[1];
    if (theContent) {
     //alert(theContent)
     var unoj=document.getElementById('popme_titulo');
     var isi=theContent.match(/\<new_titulo\>(.*?)\<\/new_titulo\>/);
     document.getElementById('popme_titulo').innerHTML = isi[1];
     unoj=document.getElementById('popme_contenido');
     isi=theContent.match(/\<new_content\>(.*?)\<\/new_content\>/);
     document.getElementById('popme_contenido').innerHTML = isi[1];
    }
 unblurdiv('thebox');
 unblurdiv('theMaenu');
}

function esteUpd(){
     thediv=theContent.match(/\<div_target\>(.*?)\<\/div_target\>/);
     unoj=document.getElementById(thediv[1]);
     if (unoj) {
      //noseusara
      alert(unoj.id);
      thetitle=theContent.match(/\<new_titulo\>(.*?)\<\/new_titulo\>/);
      var isilang=theContent.match(/\<new_data\>(.*?)\<\/new_data\>/);
      unoj.innerHTML = isilang[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';
}

function alegria(n,xdiv,elarra,maxi) {
 var unoj=$(xdiv);
 switch(n) {
  case 1:
   if (now_running1 < (maxi-1)) now_running1+=1;
   else now_running1=0;
   $opacity(unoj.id, 30, 100, 500);
   unoj.innerHTML = elarra[now_running1];
   break;
  case 2:
   if (now_running2 < (maxi-1)) now_running2+=1;
   else now_running2=0;
   $opacity(unoj.id, 30, 100, 500);
   unoj.innerHTML = elarra[now_running2];
   break;
  case 3:
   if (now_running3 < (maxi-1)) now_running3+=1;
   else now_running3=0;
   $opacity(unoj.id, 30, 100, 500);
   unoj.innerHTML = elarra[now_running3];
   break;
  case 4:
   if (now_running4 < (maxi-1)) now_running4+=1;
   else now_running4=0;
   $opacity(unoj.id, 30, 100, 500);
   unoj.innerHTML = elarra[now_running4];
   break;
 }
}

function toggleAds() {
 window.clearInterval(idji1);
 // window.clearInterval(idji2);
 // window.clearInterval(idji3);
 window.clearInterval(idji4);
}

// doalbum extras
var slishnum;
var slishid;
var slishtime;
var slishdelay;
var slishmax;
$slish('maphoto',"images/pourlagallerie/P1060065.jpg;images/pourlagallerie/P1060066.jpg;images/pourlagallerie/P1060067.jpg;images/pourlagallerie/P1060068.jpg;images/pourlagallerie/P1060069.jpg;images/pourlagallerie/P1060070.jpg;images/pourlagallerie/P1060071.jpg;images/pourlagallerie/P1060075.jpg;",900);
var nowplaying=0;

function sbPLAYSTOP(delaya) {
 if (nowplaying) {
  nowplaying=0;
  $slishSTOP();
 } else {
  nowplaying=1;
  $slishPLAY(delaya);
 }
 return false;
}


