var lang;
/*if(window.ActiveXObject){ alert("iic");}else{alert("grdg");}*/
var myArrayFR = {

"SERVER_ERROR" : "D&eacute;sol&eacute;, il a &eacute;t&eacute; impossible de trater votre requ&ecirc;te sur le serveur de licences",
"USER_ALREADY_EXISTS" : "Cette adresse e-mail est d&eacute;j&agrave; utlis&eacute;e.",
"PARAM_INVALID_USER_LOGIN" : "Votre adresse e-mail est mal renseign&eacute;e.",
"PARAM_EMPTY_USER_LOGIN" : "Quel est votre e-mail ?",
"PARAM_EMPTY_FIRST_NAME" : "Quel est votre pr&eacute;nom ?",
"PARAM_EMPTY_LAST_NAME" : "Quel est votre nom de famille ?",
"PARAM_EMPTY_COMPANY" : "Quel est le nom de votre soci&eacute;t&eacute; ?",
"PARAM_EMPTY_COUNTRY" : "Dans quelle pays travaillez-vous ?",
"PARAM_EMPTY_INTEREST" : "Quelle est votre domaine d&apos;int&eacute;r&ecirc;t ?",

"TEXT_EXPLICATION_01": "Merci de tester Living Actor&trade; Vid&eacute;o. Les informations pour t&eacute;l&eacute;charger et utiliser le logiciel vous ont &eacute;t&eacute; envoy&eacute;es &agrave; cette adresse : <b>",
"TEXT_EXPLICATION_02": "</b><br/><br/>Amusez-vous bien !"
}

var myArrayEN = {

"SERVER_ERROR" : "Sorry, the request could not be processed on the server",
"USER_ALREADY_EXISTS" : "This e-mail address is already in use.",
"PARAM_INVALID_USER_LOGIN" : "Please enter a valid email address.",
"PARAM_EMPTY_USER_LOGIN" : "What is your your email address",
"PARAM_EMPTY_FIRST_NAME" : "What is your first name?",
"PARAM_EMPTY_LAST_NAME" : "What is your last name?",
"PARAM_EMPTY_COMPANY" : "What is name of your company?",
"PARAM_EMPTY_COUNTRY" : "What is your country?",
"PARAM_EMPTY_INTEREST" : "What is your area of interest?",
"LOGIN" : "Your access codes have been sent to this email address: ",

"TEXT_EXPLICATION_01": "Thank you for testing Living Actor&trade; Video. Information for downloading and using the software have been sent to this address: <b>",
"TEXT_EXPLICATION_02": "</b><br/><br/>Enjoy!"
}

function get_xml_value(xmldoc, name)
{
	if (!xmldoc) {
		return null
	}
	var elem = xmldoc.getElementsByTagName(name);
	if (elem) {
		return(elem.item(0));
	}
	return null
}

function getHTTPObject()
{
  var xmlhttp = "";

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
 if (window.XMLHttpRequest)
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }else if(window.ActiveXObject){ 

	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	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.
					*/

					var xmldoc = xmlhttp.responseXML;

					var root_node_error_type = get_xml_value(xmldoc, 'error_type');
					var root_node_error_param = get_xml_value(xmldoc, 'error_param');
					var root_node_login = get_xml_value(xmldoc, 'login');
					var root_node_password = get_xml_value(xmldoc, 'password');
					var root_node_download = get_xml_value(xmldoc, 'download');
					if (lang=="fr") {
						text_array = myArrayFR;
					}
					else if (lang=="en") {
						text_array = myArrayEN;
					}
					//alert(root_node.firstChild.data);
					if((root_node_error_type)||(root_node_error_param)){
						//response =error.toUpperCase();
						if (root_node_error_type.firstChild.data=="USER_ALREADY_EXISTS") {	
							idName = "user_login";						
							response = text_array["USER_ALREADY_EXISTS"];		
						}
						else {
							error = root_node_error_type.firstChild.data+"_"+root_node_error_param.firstChild.data;
							idName = root_node_error_param.firstChild.data;	
							response =text_array[error.toUpperCase()];
						}
						myspan = response;
						document.getElementById("user_login_res").innerHTML = "";						
						document.getElementById("first_name_res").innerHTML = "";
						document.getElementById("last_name_res").innerHTML = "";						
						document.getElementById("company_res").innerHTML = "";
						document.getElementById("country_res").innerHTML = "";						
						document.getElementById("interest_res").innerHTML = "";
						document.getElementById(idName+"_res").innerHTML = myspan;
						//document.getElementById(root_node_error_param.firstChild.data+"_res").style.display = "block";
						
					}else if(root_node_login){					
						//alert(root_node.firstChild.data);
						Url= root_node_download.firstChild.data;
						URL_PERSO=Url.replace(/download=1&/, "");
						
						response = text_array["TEXT_EXPLICATION_01"];
						response += root_node_login.firstChild.data;
						response +=text_array["TEXT_EXPLICATION_02"];

						myspan = response;
						document.getElementById("dbtLA_DOWN").innerHTML = "";
						document.getElementById("resultats").innerHTML = "";
						document.getElementById("form_download").innerHTML = myspan;
						document.getElementById("form_download").style.display = "block";
					}
					else {
						response =text_array["SERVER_ERROR"];
						myspan = response;
						document.getElementById("dbtLA_DOWN").innerHTML = "";
						document.getElementById("resultats").innerHTML = "";
						document.getElementById("form_download").innerHTML = myspan;
						document.getElementById("form_download").style.display = "block";
					}
					
				}
			}
		}
	}
	return xmlhttp;
}

window.onload = function()
 {
   //on associe la fonction verifId à
    //l'événénement onsubmit du formulaire
    document.getElementById('downloadLAV').onsubmit = verifId;
 }

function verifId()
 {
 
	var interestID= document.getElementById('interest');
	var numInterest=interestID.selectedIndex;
	var  valueInterest;
	if(numInterest=="0"){
		valueInterest ="";
	}else{
		valueInterest = interestID.options[numInterest].text;
	}
	lang = document.getElementById('langue').value;
    //envoi des données
    return !sendData(
       "POST",
       "tools/ajaxxml.php",
	   //afficher l'ensemble des valeur ICI
       //"user_name="+document.getElementById('user_name').value+
	   "first_name="+document.getElementById('first_name').value+
	   "&last_name="+document.getElementById('last_name').value+
	   "&company="+document.getElementById('company').value+
	   "&address="+document.getElementById('address').value+
	   "&country="+document.getElementById('country').value+
	   "&user_login="+document.getElementById('user_login').value+
	   "&web="+document.getElementById('web').value+
	   "&phone="+document.getElementById('phone').value+
	   "&interest="+valueInterest+
	   "&comment="+document.getElementById('comment').value+
	   "&xmlmode=");
 }


/**
  * Envoie des données à l'aide d'XmlHttpRequest?
  * @param string methode d'envoi ['GET'|'POST']
  * @param string url
  * @param string données à envoyer sous la forme var1=value1&var2=value2...
  */
 function sendData(method, url, data)
 {
    var xmlhttp = getHTTPObject();

    if (!xmlhttp)
    {
        return false;
    }

    if(method == "GET")
     {
     if(data == 'null')
     {
            xmlhttp.open("GET", url, true); //ouverture asynchrone
     }
     else
     {
            xmlhttp.open("GET", url+"?"+data, true);
     }
        xmlhttp.send(null);
     }
     else if(method == "POST")
     {
        xmlhttp.open("POST", url, true); //ouverture asynchrone
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(data);
     }
    return true;
 }
