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 alert('The typed code saisi is not correct. Please retry');
			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 
	  alert('Please type in the word displayed in the picture');
	  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.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 alert("Please check the fields followed by : *");
result = false;} else {result = true}

	if (result)
		document.formulaire.submit();
		

}

