var IdList = new Array("fr","com","net","org","biz","info","eu");
var Societe = 'votre-societe';
var NbSoc = 0;

function init2()
{

	for( x in IdList )
	{
		getDomEtatAsync( Societe, IdList[x] );
	}
}

function getHTTPObject()
{
  var xmlhttp = false;

  /* Compilation conditionnelle d'IE */
  /*@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 @*/

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }

  if (xmlhttp)
  {
     /* on définit ce qui doit se passer quand la page répondra */
     xmlhttp.onreadystatechange=function()
     {
        if (xmlhttp.readyState == 4) /* 4 : état "complete" */
        {
           if (xmlhttp.status == 200) /* 200 : code HTTP pour OK */
           {
              /*
              Traitement de la réponse.
              Ici on affiche la réponse dans une boîte de dialogue.
              */
              // alert(xmlhttp.responseText);
			  var res = eval( xmlhttp.responseText );
			  //alert( res.id+' - '+res.etat );
    		  bindEtat( res.id, res.etat );
    		  

              
              
           }
        }
     }
  }
  return xmlhttp;
}

function getDomEtatAsync( soc, id )
{
	var etat = '';
	var dom = soc+'.'+id;
	var etatUrl = "checkajax.php?soc="+encodeURIComponent(soc)+"&id="+id;

	/* Création de l'objet : */
	var xmlhttp = getHTTPObject(); 
	// alert(etatUrl);
	/* Préparation d'une requête asynchrone de type GET : */
	xmlhttp.open("GET", etatUrl,true); 
	/* Effectue la requête : */
	xmlhttp.send(null); 

}

function getDomEtatSync( soc, id )
{
	var etat = '';
	var dom = soc+'.'+id;

	// IE support
	if( window.ActiveXObject && !window.XMLHttpRequest )
	{
		window.XMLHttpRequest = function() {
	    	return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
	  };
	}



		var xmlhttp = new XMLHttpRequest();
		var etatUrl = "http://ploplpopop/test/php/achetez-domaine/index_fichiers/etat.php?soc="+encodeURIComponent(dom)+"&id="+id;
		xmlhttp.open("GET", etatUrl, false);
		xmlhttp.send(null);
		if( xmlhttp.status == 200 )
		{
			etat = xmlhttp.responseText;
			bindEtat( id, etat );
		}
    
}

function bindEtat( id, etat )
{
	// alert(id);
	// alert(id+'='+etat);
	var elt = document.getElementById( 'd'+id );
	
	
	if( etat == 'libre' )
	{
		document.getElementById( 'c'+id ).style.display="block";
		document.getElementById( 'cc'+id ).style.display="block";
		elt.className = etat;
		elt.innerHTML = "<font color=#018b08><b>Disponible</b></font>";
	}
	else if( etat == 'pris' )
	{
		document.getElementById( 'w'+id ).style.display="block";
		document.getElementById( 'c'+id ).name.value="del[]";
		document.getElementById( 'c'+id ).name="del[]";
		document.getElementById( 'c'+id ).checked.value="";
		document.getElementById( 'c'+id ).checked="";
		elt.className = etat;
		elt.innerHTML = "<font color=#CC0000><b>déjà pris</b></font>";
	}
	else
	{
		document.getElementById( 'cc'+id ).style.display="block";
		elt.className = 'libre';
		elt.innerHTML = "<font color=#CC0000><b>erreur re-essayer plustard</b></font>";
	}

	NbSoc++;
    if( NbSoc == 6 )
    {
	// 	document.getElementById( 'ap' ).disabled="";
	}

}

