<?php
/************************************************************************/
/*                                WEBSHARE                              */
/************************************************************************/
//
// Copyright (c) 2008 by Virginie Vivancos
// http://www.webshare.fr
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// =======================================================================
// Fonction : Identification pour démarrage de la session
// Nom      : ident.php
// Version  : 0.6.5
// Date     : 28/05/08
// =======================================================================
?>
  function getNewXMLHTTP() {
    try {
       return window.XMLHttpRequest?new XMLHttpRequest():
                                    new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
      new ActiveXObject("Msxml2.XMLHTTP");
    }
  }

  function cestparti() {
    url="index.php";
    urlUpdated= window.location.href.substr(window.location.href.lastIndexOf("/")+1,window.location.href.length);
    if (urlUpdated=="") urlUpdated= url;
    xmlhttp = getNewXMLHTTP();
    xmlhttp.onreadystatechange = triggerIdent;
    datas=formData2QueryString(document.ident);
    xmlhttp.open("POST", urlUpdated, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", datas.length);
    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(datas);
    return false;
  }

  function triggerIdent() {
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
      urlLocal= window.location.href.substr(0,window.location.href.lastIndexOf("/")+1);
      if (!xmlhttp.responseText.indexOf("valid")) {
         window.location.href = urlLocal+"start.php"; }
      else { document.getElementById("message").innerHTML = xmlhttp.responseText; }
    }
  }

  function formData2QueryString(docForm) {

    var strSubmit       = '';
    var formElem;
    var strLastElemName = '';

    for (i = 0; i < docForm.elements.length; i++) {
      formElem = docForm.elements[i];
        switch (formElem.type) {
          case 'text':
          case 'hidden':
          case 'password':
          strSubmit += formElem.name +
                '=' + encodeURIComponent(formElem.value) + '&'
          break; }
      }
    return strSubmit;
   }
