var IMG_URL = "/piscines-et-reves/piscines/images/";


function getHTTPObject()
{
   var xmlhttp;
   /*@cc_on
   @if (@_jscript_version >= 5)
   try
   {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e)
   {
      try
      {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (E)
      {
         xmlhttp = false;
      }
   }
   @else
      xmlhttp = false;
   @end @*/
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
   {
      try
      {
         xmlhttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlhttp = false;
      }
   }
   return xmlhttp;
}


function updatePage(asPage)
{
   var asZoneIdHtml = "";
   if (updatePage.arguments.length > 1)
   {
      asZoneIdHtml = updatePage.arguments[1];
   }
   abLoading = false;
   if (updatePage.arguments.length > 2)
   {
      abLoading = updatePage.arguments[2];
   }
   var http = getHTTPObject();
   http.open("GET", asPage, true);
   /*http.onreadystatechange = handleHttpResponse;*/
   http.onreadystatechange = function()
   {
      if (http.readyState == 4)
      {
         if (http.status == 200)
         {
            var responseText = http.responseText;
            if (asZoneIdHtml == "") // Javascript
            {
               while (responseText.indexOf('<script type=\"text/javascript\">\n') != -1)
               {
                  responseText = responseText.replace('<script type=\"text/javascript\">\n', '');
               }
               while (responseText.indexOf('</script>\n') != -1)
               {
                  responseText = responseText.replace('</script>\n', '');
               }
               eval(responseText);
            }
            else // HTML
            {
               if (responseText.substr(0,9) == '<div id="')
               {
                  responseText = responseText.replace('<div id="' + asZoneIdHtml + '">\n', '');
                  responseText = responseText.substr(0, responseText.length-7);
               }
               if (document.getElementById(asZoneIdHtml))
               {
                  document.getElementById(asZoneIdHtml).innerHTML = responseText;
                  //initForm();
               }
               else if (parent.document.getElementById(asZoneIdHtml))
               {
                  parent.document.getElementById(asZoneIdHtml).innerHTML = responseText;
                  parent.initForm();
               }
               else if (window.opener && window.opener.document.getElementById(asZoneIdHtml))
               {
                  window.opener.document.getElementById(asZoneIdHtml).innerHTML = responseText;
                  window.opener.initForm();
               }
               
               var laJavascript = responseText.split('<script type=\"text/javascript\">\n');
               for (var index=0 ; index < laJavascript.length ; index++)
               {
                  var laJavascriptCode = laJavascript[index].split('</script>\n');
                  if (laJavascriptCode.length > 1)
                  {
                     eval(laJavascriptCode[0]);
                  }
               }
            }
         }
         else
         {
            //alert('Un problème est survenu dans le chargement des données.');
         }
      }
      else if (http.readyState == 1)
      {
         if (asZoneIdHtml != "" || abLoading)
         {
            if (document.getElementById('ajaxLoading'))
            {
               document.getElementById('nbAjaxCall').innerHTML = parseInt(document.getElementById('nbAjaxCall').innerHTML)+1;
               document.getElementById('ajaxLoading').style.display = 'block';
            }
            else if (parent.document.getElementById('ajaxLoading'))
            {
               parent.document.getElementById('nbAjaxCall').innerHTML = parseInt(parent.document.getElementById('nbAjaxCall').innerHTML)+1;
               parent.document.getElementById('ajaxLoading').style.display = 'block';
            }
         }
      }
   }
   http.send(null);
   working = true;
}

function openWindow(asPage, anWidth, anHeight, asName, anPosX, anPosY)
{
   if (!anWidth)
   {
      anWidth = screen.width;
   }
   if (!anHeight)
   {
      anHeight = screen.height;
   }
   if (!anPosX)
   {
      anPosX = (screen.width - anWidth) / 2;
   }
   if (!anPosY)
   {
      anPosY = (screen.height - anHeight) / 2;
   }
   if (!asName)
   {
      asName = 'window1';
   }
   window1 = window.open(asPage,asName,"toolbar=no,location=no,dependent=yes,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,left="+anPosX+",screenX="+anPosX+",top="+anPosY+",screenY="+anPosY+",width="+anWidth+",height="+anHeight);
}

function ctlTextArea(asFieldName, anMaxLength)
{
   var txt = document.principal.elements[asFieldName].value;
   var nb  = document.principal.elements[asFieldName].value.length;
   if (nb > anMaxLength)
   {
      document.principal.elements[asFieldName].value = txt.substring(0, anMaxLength);
      nb = anMaxLength;
   }
   if (document.getElementById(asFieldName + 'NbChar'))
   {
      document.getElementById(asFieldName + 'NbChar').innerHTML = anMaxLength - document.principal.elements[asFieldName].value.length;
   }
}

