var url = 'naltis_captcheck.php?code=';
var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed
var lg = 'fr';  // 2 - not yet checked, 1 - correct, 0 - failed

function getHTTPObject()
{
	try
	{
		req = new XMLHttpRequest();
	}
	catch (err1)
	{
		try
		{
			req = new ActiveXObject("Msxml12.XMLHTTP");
		}
		catch (err2)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (err3)
			{
				req = false;
			}
		}
	}

	return req;
}

var http = getHTTPObject(); // We create the HTTP Object        

function handleHttpResponse()
{
	if (http.readyState == 4)
	{
		captchaOK = http.responseText;
		if (captchaOK != 1)
		{if (lg == 'fr')
			alert('Le code saisi est incorrect. Veuillez rÃ©essayer');
		 else if (lg == 'en') alert('The typed code is not correct. Please retry');
		 else if (lg == 'ar') alert('????? ???? ??? ?????. ???? ??? ????');
		 else if (lg == 'es') alert('El codigo introducido es incorrecto. Por favor, inttÃ©ntalo de nuevo');
			document.getElementById("naltis_captcha").value='';
			document.getElementById("naltis_captcha").focus();
			return false;
		}
//		alert('ok')
		check_fields(lg);

	}
}

function checkcode(thecode)
{
//	alert(thecode)
	http.open("GET", url + escape(thecode), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function go_valider_form_from_captcha(lg)
{
	if (document.getElementById("naltis_captcha").value == "")
	{
	  if (lg == 'fr')
	  alert('Veuillez saisir le mot présent sur l\'image');
	  else if (lg == 'en')
	  alert('Please type in the word displayed in the picture');
	  else if (lg == 'ar')
	  alert('ãä ÝÖáß ÇäÞá ÇáßáãÉ ÇáãßÊæÈÉ Ýí ÇáÕæÑÉ');
	  else if (lg =='es')
	  alert('Por favor, introduzca la palabra en esta imagen');
	  
	  document.getElementById("naltis_captcha").value='';
	  document.getElementById("naltis_captcha").focus();
	  return false;
	}
	else
	{
	  checkcode(document.getElementById("naltis_captcha").value);
	  return false;
	}
}

function check_fields(lg) 
{
	var test=""+document.formulaire.mail.value ;
	a=true;
	if (document.formulaire.message.value.length == 0){ a= false;} 
	else if (document.formulaire.ville.value.length == 0){ a= false;} 
	else if (document.formulaire.pays.value.length == 0){ a= false;} 
	else if (document.formulaire.mail.value.length == 0){ a= false;} 
	else if (document.formulaire.mail.value.length > 0)
	{
		isthere = false;
		for (var k = 0; k < test.length;k++) 
		{ 
			var c = test.substring(k,k+1); if(c == "@") { isthere = true;} 
		}
		if (isthere != true) {if (lg == 'fr') alert("Veuillez vérifier votre e-mail !"); 
		else alert("Please check your e-mail !"); a= false; result = false;}
	}
				
	if (a==false)
	{
		if (lg == 'fr')
		alert("Vous devez remplir tous les champs suivis par : *"); 
			else if (lg == 'en') alert("Please check the fields followed by : *");
				else if (lg == 'ar') alert("*: ÈÌÈ ãáÆ ßá ÇáÎÇäÇÊ ÇáãÊÈæÚÉ È ");
					else if (lg == 'es') alert("Usted debe llenar todos los campos seguidos por: *");
		result = false;
	} 
		else {result = true}

	if (result)
		document.formulaire.submit();
}
