
    /**
    * Ce fichier contient les fonctions utiles Javascript pour AJAX
    **/
	
	function pop_it(idForm,idphoto) 
	{
	   my_form = document.forms[idForm]
	   window.open("./wait.php?photo_id="+idphoto, "popup", "height=440,width=640,menubar='no',toolbar='no',location='no',status='no',scrollbars='no'");
	   //my_form.target = "popup";
	   //my_form.submit();
	}

var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var req;
var g_ElementToChange= '';

function include(fileName)
{ 
   document.write("<script type='text/javascript' src='"+fileName+"'></script>" );
} 

function getXMLHTTPRequest()
{
    var xRequest=null;
    if (window.XMLHttpRequest)
    {
        xRequest=new XMLHttpRequest();
    }
    else if (typeof ActiveXObject != "undefined")
    {
        xRequest=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else      // XMLHttpRequest non supporté par le navigateur 
    { 
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
        xRequest = false; 
    } 
    return xRequest;
}

String.prototype.extractTags=function(tag) {
    var matchAll = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'img');
    var matchOne = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'im');
    return (this.match(matchAll) || []).map(function(scriptTag) {
      return (scriptTag.match(matchOne) || ['', ''])[1];
    });
  }
 
Object.prototype.forEach=function(delegate, ownpropertiesonly)
{
    if (typeof(delegate)=="function")
    {
        if (this instanceof Array && typeof(ownpropertiesonly)=="undefined")
        {
            ownpropertiesonly=true;
        }
           
        for (key in this)
        {
            var ok = (!ownpropertiesonly);
            if (!ok)
            {
                try
                {
                    ok=this.hasOwnProperty(key)
                } catch (ex) {}
                }
                if (ok)
                {
                    try { delegate(this[key], key, this) } catch(e) { // ...}
                }
            }
        }
        return false;
    }
}

Object.prototype.map=function(iterator) {
    var results = [];
    this.forEach(function(value, index) {
      results.push(iterator(value, index));
    });
    return results;
  }
 
function onReadyStateChange()
{
    var ready=req.readyState;
    var data=null;
    if (ready==READY_STATE_COMPLETE)
    {
        
        data=req.responseText;
        if (g_ElementToChange != '')
        {
            //alert(data);
            document.getElementById(g_ElementToChange).innerHTML = data;
            
            try
            {
                var All=divContent.getElementsByTagName("*");
                for (var i=0; i<All.length; i++) {
                  All[i].id=All[i].getAttribute("id")
                  All[i].name=All[i].getAttribute("name")
                  All[i].className=All[i].getAttribute("class")
                }
            } catch (ex) {}

            try
            {
                var AllScripts=data.extractTags("script");
                AllScripts.forEach(function (v)
                {
                  //alert(v);
                  eval(v);
                }
                )
            }
            catch (ex) {}
            
            try
            {
                var AllStyles=HTML.extractTags("style");
                AllStyles.forEach(function (v)
                {
                    var s=document.createStyleSheet()
                    s.cssText=v;
                    s.enabled=true;
                }, true)
            } catch (ex) {}

        }
    }
    else
    {
        data="loading...["+ready+"]";
    }
    //... do something with the data...
}

function sendRequest(url,params,HttpMethod,myElementToChange,newTitle)
{
   if (!HttpMethod)
   {
      HttpMethod="GET";
   }
   req=getXMLHTTPRequest();
   g_ElementToChange = myElementToChange;
   if (newTitle != '')
   {
      document.title = newTitle;
   }
   if (req)
   {
      req.onreadystatechange=onReadyStateChange;
      req.open(HttpMethod,url,true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      req.send(params);
   }
}

