var xhr_object;

function xmlhttp()
{
	if(window.XMLHttpRequest) // Firefox   
	   xhr_object = new XMLHttpRequest();   
	else if(window.ActiveXObject) // Internet Explorer   
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");   
	else 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	return xhr_object;
}
	
function ChargeFormulaireContact(valeur)
{
	if(valeur=='oui')
	{
		var myAjax = new Ajax.Updater(
		'div_form_contact',
		'form_contact.php',
		{
			method: 'post'
		}
		);
	}
	else
	{
		$('div_form_contact').innerHTML='';
	}
}


function VerifierFormeNum()
{
	if(parseInt(document.getElementById('volet_gauche_eligibilite_nd').value)>20000000 && parseInt(document.getElementById('volet_gauche_eligibilite_nd').value)<40000000)
	{
		VerifierADSLNew();
	}
	else
	{
		$('zone_info').innerHTML="Veuillez entrer un num&eacute;ro de t&eacute;l&eacute;phone valide !";
	}
}

function VerifierADSL()
{
	var url = "verification_ajax_new.php";
	var parametres = "noadsl="+$F('num');
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: parametres,
			onComplete: afficheReponse
		}
	);
}

function AffichePatience()
{
	document.getElementById('zone_info_eligibilite').innerHTML = "Veuillez patienter ..."	
}


function afficheReponse(xhr)
{
	var tst = xhr.responseText;
	var tmp = tst.split('@@@@@')
	
	$("zone_info").innerHTML = tmp[1];
	
	if(tmp[0]!='-1')
	{
		$('div_td_contenu').innerHTML = '<table width="70%" border="0" id="table_select_oui" align="center">'+
			'<tr>'+
			 ' <td width="45%" nowrap="nowrap"><span class="for">Souhaitez-vous &ecirc;tre  contact&eacute; ?</span></td>'+
			 ' <td width="55%"><select name="choix" size="1" class="ch_txt" id="choix" onChange="ChargeFormulaireContact(this.value)">'+
			'	<option selected="selected">[- choix -]</option>'+
			'	<option value="oui">oui</option>'+
			'	<option  value="non">non</option>'+
			 ' </select></td></tr></table>'+
			 '<div id="div_form_contact"></div>';
	}
	else
	{
		$('div_td_contenu').innerHTML='';
	}
	
}

function VerifierADSLNew()
{
    var submit_url = "includes/eligibilite/check_eligibilite.php";
    var parametres = "noadsl="+document.getElementById('volet_gauche_eligibilite_nd').value;
    xhr_object= xmlhttp();
    xhr_object.open('get', submit_url+'?'+parametres);
    xhr_object.onreadystatechange = handleResponse;
    xhr_object.send(null);
  }
function handleResponse()
{
	if (xhr_object.readyState == 4) { 
		afficheReponseNew();
	} else { AffichePatience() }    	
}

function afficheReponseNew()
{
	document.getElementById("zone_info_eligibilite").innerHTML = xhr_object.responseText;
	return false;
}

function EnregistrerContact()
{
	var url = "enregistrer_contact.php";
	var parametres = "noadsl="+$F('num')+"&civilite="+$F('civilite')+"&nom="+$F('nom')+"&numero1"+$F('numero1')+"&numero2="+$F('numero2')+'&datecontact='+$F('datecontact')+"&commentaire="+$F('commentaire');
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: parametres,
			onComplete: afficheReponseEnreg
		}
	);
}

function afficheReponseEnreg(e)
{
	var rep = e.responseText;
	if(rep=='ok')
		$('zone_info_ajoutcontact').innerHTML = "<span class='info_ok'>Vos coordonnées ont été enregistrées!<br> Merci de faire confiance é C&ocirc;te d'Ivoire Telecom!</span>";
	else
		$('zone_info_ajoutcontact').innerHTML = "<span class='info_ko'>Une erreur est survenue lors de l'enregistrement de vos coordonnées!<br/>Veuillez réessayer plus tard !</span>";
}
