function wipAjaxHttpAjaxSuccess (t, statusDiv) {

}
function wipAjaxHttpAjaxError (t) {
  alert('Error ' + t.status + ' -- ' + t.statusText);
  //alert('you can\'t user this pseudo (ndr : test version).');
  //$(imgPseudo).src = '/champNonValide.gif';
}

function wipAjaxHttpAjaxError404 (t) {
  alert('Error ' + t.status + ' -- ' + t.statusText);
  //alert('you can\'t user this pseudo (ndr : test version).');
  //$(imgPseudo).src = '/champNonValide.gif';
}


var toggle_db = new Hash();

function wipAjax (queryString, htmlDiv, page, method, effect, toggle) {
  var url = page;
  var status = $(htmlDiv + 'status');
  if (status) {
    status.style.display = 'inline';
  }

  if (toggle) {
    var div_toggle = $(htmlDiv + toggle);
    if ( toggle_db.get(htmlDiv + toggle) ) {
      toggle_db.unset(htmlDiv + toggle);
      if (div_toggle) div_toggle.removeClassName('active');
      new Effect.SlideUp(htmlDiv, { duration: 0.5 } );
      return;

    } else {
      toggle_db.each( function(pair) {
        if ( $('debug') ) $('debug').insert({ bottom : (pair.key + ' = "' + pair.value + '"') });
	var _div_toggle = $(pair.key);
        if (_div_toggle) {
          _div_toggle.removeClassName('active');
          //new Effect.SlideUp(pair.value, { duration: 0.5 } );
	}
	toggle_db.unset(pair.key);
      });
      toggle_db.set(htmlDiv + toggle, htmlDiv);
      if (div_toggle) div_toggle.addClassName('active');
    }
  }


  if (method == 'post') {
    new Ajax.Updater(
                     htmlDiv, url, {
                                    onComplete:function(){
                                                          if (effect) {
							    if (effect == 'slidedown') {
							      new Effect.SlideDown(htmlDiv, { duration: 0.5 } );
							    } else {
							      htmlDiv.show();
                                                              new Effect.Highlight(htmlDiv, { duration: 0.5 } );
							    }
                                                          }
                                                         },
                                    asynchronous: true,
                                    evalScripts: true,
                                    method: 'post',
                                    parameters: '',
                                    postBody: queryString,
                                    on404: wipAjaxHttpAjaxError404,
                                    onSuccess: wipAjaxHttpAjaxSuccess,
                                    onFailure: wipAjaxHttpAjaxError
                                   }
                       );

  } else {
    new Ajax.Updater(
                     htmlDiv, url + '?' + queryString, {
                                                        onComplete:function(){
                                                                              if (effect) {
							                        if (effect == 'slidedown') {
							                          new Effect.SlideDown(htmlDiv, { duration: 0.5 } );
							                        } else {
										  htmlDiv.show();
                                                                                  new Effect.Highlight(htmlDiv, { duration: 0.5 } );
							                        }
                                                                              }
                                                                             },
                                                        asynchronous: true,
                                                        evalScripts: true,
                                                        method: 'get',
                                                        on404: wipAjaxHttpAjaxError404,
                                                        onSuccess: wipAjaxHttpAjaxSuccess,
                                                        onFailure: wipAjaxHttpAjaxError
                                                       }
                    );
  }

}


function update_user_box(redirect, url) {
  // alert(redirect);
  if (redirect && url) {
    wipAjax('div=' + redirect, redirect, url);
  } else {
    var user_box = document.getElementById("wip_person_fb");
    // add in some XFBML. note that we set useyou=false so it doesn't display "you"
    user_box.innerHTML = "<span>" +
         "<fb:profile-pic uid=loggedinuser facebook-logo=true></fb:profile-pic>" +"<fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account." +
         "</span>";
    // because this is XFBML, we need to tell Facebook to re-process the document
    FB.XFBML.Host.parseDomTree();
  }
}

function init_user_box() {
  // because this is XFBML, we need to tell Facebook to re-process the document
  FB.XFBML.Host.parseDomTree();
}



function wip_ajax_gallery1_lw (w, h, url, title, author, caption) {
     mlw2 = new lightwindow({resizeSpeed : 10});
     mlw2.activateWindow({
   	                  href    : url,
   		          title   : title,
   		          author  : author,
   		          caption : caption,
   		          width   : w,
   		          height  : h
   		         });
   }

   function wipGalleryHttpAjaxSuccess (t, statusDiv) {

   }
   function wipGalleryHttpAjaxError (t) {
     alert('Error ' + t.status + ' -- ' + t.statusText);
     //alert('you can\'t user this pseudo (ndr : test version).');
     //$(imgPseudo).src = '/champNonValide.gif';
   }

   function wipGalleryHttpAjaxError404 (t) {
     alert('Error ' + t.status + ' -- ' + t.statusText);
     //alert('you can\'t user this pseudo (ndr : test version).');
     //$(imgPseudo).src = '/champNonValide.gif';
   }

   function wipGalleryLoad (queryString, htmlDiv) {
     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
  wipGalleryUpdater(queryString, htmlDiv);
  }

   function wipGalleryUpdater (queryString, htmlDiv) {
     var url = '/tools/wip_v4/ajax/gallery1/show_gallery.epl';
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
  },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipGalleryHttpAjaxError404,
                                                     onSuccess: wipGalleryHttpAjaxSuccess,
                                                     onFailure: wipGalleryHttpAjaxError
                                                    });

   }


   function wipGalleryLoadInit (queryString, htmlDiv) {

     Event.observe(window, 'load', function() {
       Event.observe(document, 'keydown', function(event) {
	 var keycode = event.keyCode ? event.keyCode : event.which;
	 if (keycode == Event.KEY_RIGHT) {
	   try { clearTimeout(gallery1_timer); } catch (err) {}
	   wip_gallery_go_right();
	 } else if (keycode == Event.KEY_LEFT) {
	   try { clearTimeout(gallery1_timer); } catch (err) {}
	   wip_gallery_go_left();
	 }
       });
     });

     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
     var url = '/tools/wip_v4/ajax/gallery1/show_gallery.epl';
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
                                                                          },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipGalleryHttpAjaxError404,
                                                     onSuccess: wipGalleryHttpAjaxSuccess,
                                                     onFailure: wipGalleryHttpAjaxError
                                                    });
   }


   function wip_gallery_go_right () {
     wipGalleryLoad(wipgallery_next_url, wipgallery_div);
   }
   function wip_gallery_go_left () {
     wipGalleryLoad(wipgallery_prev_url, wipgallery_div);
   }



function wipPollHttpAjaxSuccess (t, statusDiv) {

   }
   function wipPollHttpAjaxError (t) {
     alert('Error ' + t.status + ' -- ' + t.statusText);
     //alert('you can\'t user this pseudo (ndr : test version).');
     //$(imgPseudo).src = '/champNonValide.gif';
   }

   function wipPollHttpAjaxError404 (t) {
     alert('Error ' + t.status + ' -- ' + t.statusText);
     //alert('you can\'t user this pseudo (ndr : test version).');
     //$(imgPseudo).src = '/champNonValide.gif';
   }

   function wipPollLoadPoll (queryString, htmlDiv) {
     var url = '/tools/wip_v4/ajax/poll/show_poll.epl';
     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
                                                                           new Effect.Highlight(htmlDiv, {
                                                                                                          duration: 0.5
                                                                                                         }
                                                                                               );
                                                                          },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipPollHttpAjaxError404,
                                                     onSuccess: wipPollHttpAjaxSuccess,
                                                     onFailure: wipPollHttpAjaxError
                                                    });
   }

   function wipPollListPoll (queryString, htmlDiv) {
     var url = '/tools/wip_v4/ajax/poll/list_poll.epl';
     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
                                                                           new Effect.Highlight(htmlDiv, {
                                                                                                          duration: 0.5
                                                                                                         }
                                                                                               );
                                                                          },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipPollHttpAjaxError404,
                                                     onSuccess: wipPollHttpAjaxSuccess,
                                                     onFailure: wipPollHttpAjaxError
                                                    });
   }

   function wipPollAddVote (queryString, htmlDiv) {
     var url = '/tools/wip_v4/ajax/poll/add_vote.epl';
     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
                                                                           new Effect.Highlight(htmlDiv, {
                                                                                                          duration: 0.5
                                                                                                         }
                                                                                               );
                                                                          },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipPollHttpAjaxError404,
                                                     onSuccess: wipPollHttpAjaxSuccess,
                                                     onFailure: wipPollHttpAjaxError
                                                    });
   }

   function wipPollShowResult (queryString, htmlDiv) {
     var url = '/tools/wip_v4/ajax/poll/show_result.epl';
     var status = document.getElementById(htmlDiv + 'status');
     if (status) {
       status.style.display = 'inline';
     }
     new Ajax.Updater(htmlDiv, url + '?' + queryString, {
                                                     onComplete:function(){
                                                                           new Effect.Highlight(htmlDiv, {
                                                                                                          duration: 0.5
                                                                                                         }
                                                                                               );
                                                                          },
                                                     asynchronous: true,
                                                     evalScripts: true,
                                                     method: 'get',
                                                     on404: wipPollHttpAjaxError404,
                                                     onSuccess: wipPollHttpAjaxSuccess,
                                                     onFailure: wipPollHttpAjaxError
                                                    });
   }

