//***********************************************
 // AJAX
 //***********************************************

function getHTTPObject(cadre)
{
  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.
              */	

			 if(xmlhttp.getResponseHeader("Content-Type") == "text/html"){
               document.getElementById(cadre).innerHTML = xmlhttp.responseText;
			  }else if(xmlhttp.getResponseHeader("Content-Type") == "application/javascript"){
				eval( xmlhttp.responseText);
			  }else{
				  document.getElementById(cadre).innerHTML = xmlhttp.responseText;
			  }
			  
           }
        }
     }
  }
  return xmlhttp;
}


 function sendData(method, url, data, cadre)
 {
    var xmlhttp = getHTTPObject(cadre);

    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; charset=ISO-8859-1');
		xmlhttp.send(data);
     }
    return true;
 }
 
 function verif_form()
{
//rÃ©cupÃ©ration des infos
	var password 			= document.forms["registration"].password.value;
	var password_confirm	= document.forms["registration"].verif.value
	var name				= document.forms["registration"].name.value;
	var lastname 			= document.forms["registration"].lastname.value;
	var company 			= document.forms["registration"].company.value;
	var email 				= document.forms["registration"].email.value;
	var birth 				= document.forms["registration"].birth.options[document.forms["registration"].birth.selectedIndex].value;
	var categorie 			= document.forms["registration"].categorie.options[document.forms["registration"].categorie.selectedIndex].value;
	
	
	
//mise en place des alertes	
	
	if(name == ''){
		alert('Please enter your First name');
		return false;
	}
	
	if(lastname == ''){
		alert('Please enter your lastname');
		return false;
	}
	
	if(birth == ''){
		alert('Please select a birth date');
		return false;
	}
	
	if(company == ''){
		alert('Please enter your organisation');
		return false;
	}
	
	if(categorie == ''){
		alert('Please select a category');
		return false;
	}
	
	if(null == document.forms["registration"].profession.selectedIndex){
		var profession 	= document.forms["registration"].profession.value;
	}else{
		var profession 	= document.forms["registration"].profession.options[document.forms["registration"].profession.selectedIndex].value;
	}
	
	if(profession == ''){
		alert('Please select a profession');
		return false;
	}
		
	
	var country	= document.forms["registration"].country.options[document.forms["registration"].country.selectedIndex].value;
	
	if(country == ''){
		alert('Please select your country');
		return false;
	}
	
	if(!check_mail(email)){
		alert('Wrong mail');
		return false;
	}
	
	if(password == ''){
		alert('Please enter a password');
		return false;
	}
	
	if (password != password_confirm){
		alert('Passwords does not match');
		return false;
	}	
	
	document.forms["registration"].submit();
	return true;
	
	
}

 function verif_form_inscription()
{
//rÃ©cupÃ©ration des infos
	var password 			= document.forms["registration"].password.value;
	var password_confirm	= document.forms["registration"].verif.value
	var name				= document.forms["registration"].name.value;
	var lastname 			= document.forms["registration"].lastname.value;
	var company 			= document.forms["registration"].company.value;
	var email 				= document.forms["registration"].email.value;
	var birth 				= document.forms["registration"].birth.options[document.forms["registration"].birth.selectedIndex].value;
	var categorie 			= document.forms["registration"].categorie.options[document.forms["registration"].categorie.selectedIndex].value;
	
	
//mise en place des alertes	
	
	if(name == ''){
		alert('Please enter your First name');
		return false;
	}
	
	if(lastname == ''){
		alert('Please enter your lastname');
		return false;
	}
	
	if(birth == ''){
		alert('Please select a birth date');
		return false;
	}
	
	if(company == ''){
		alert('Please enter your organisation');
		return false;
	}
	
	if(categorie == ''){
		alert('Please select a category');
		return false;
	}
	
	if(null == document.forms["registration"].profession.selectedIndex){
		var profession 	= document.forms["registration"].profession.value;
	}else{
		var profession 	= document.forms["registration"].profession.options[document.forms["registration"].profession.selectedIndex].value;
	}
	
	if(profession == ''){
		alert('Please select a profession');
		return false;
	}
		
	
	var country	= document.forms["registration"].country.options[document.forms["registration"].country.selectedIndex].value;
	
	if(country == ''){
		alert('Please select your country');
		return false;
	}
	
	if(!check_mail(email)){
		alert('Wrong mail');
		return false;
	}
	

	
	if(password == ''){
		alert('Please enter a password');
		return false;
	}
	
	if (password != password_confirm){
		alert('Passwords does not match');
		return false;
	}	
	
	document.forms["registration"].submit();
	return true;
	
	
}


 function verif_form_inscription2()
{
//rÃ©cupÃ©ration des infos
	var password 			= document.forms["registration"].password.value;
	var password_confirm	= document.forms["registration"].verif.value
	var name				= document.forms["registration"].name.value;
	var lastname 			= document.forms["registration"].lastname.value;
	var company 			= document.forms["registration"].company.value;
	var email 				= document.forms["registration"].email.value;
	var email2 				= document.forms["registration"].email2.value;
	var birth 				= document.forms["registration"].birth.options[document.forms["registration"].birth.selectedIndex].value;
	var categorie 			= document.forms["registration"].categorie.options[document.forms["registration"].categorie.selectedIndex].value;
	var workshop1 			= document.forms["registration"].workshop1.value;
	var workshop2 			= document.forms["registration"].workshop2.value;
	var workshop3 			= document.forms["registration"].workshop3.value;
	
	
//mise en place des alertes	
	
	if(name == ''){
		alert('Please enter your First name');
		return false;
	}
	
	if(lastname == ''){
		alert('Please enter your lastname');
		return false;
	}
	
	if(birth == ''){
		alert('Please select a birth date');
		return false;
	}
	
	if(company == ''){
		alert('Please enter your organisation');
		return false;
	}
	
	if(categorie == ''){
		alert('Please select a category');
		return false;
	}
	
	if(null == document.forms["registration"].profession.selectedIndex){
		var profession 	= document.forms["registration"].profession.value;
	}else{
		var profession 	= document.forms["registration"].profession.options[document.forms["registration"].profession.selectedIndex].value;
	}
	
	if(profession == ''){
		alert('Please select a profession');
		return false;
	}
		
	
	var country	= document.forms["registration"].country.options[document.forms["registration"].country.selectedIndex].value;
	
	if(country == ''){
		alert('Please select your country');
		return false;
	}
	
	if(!check_mail(email)){
		alert('Wrong mail');
		return false;
	}
	
	if(password == ''){
		alert('Please enter a password');
		return false;
	}
	
	if (password != password_confirm){
		alert('Passwords does not match');
		return false;
	}	
	
	/*
	if(workshop3 == ''){
		alert('Please Select a ')
	}
	*/
	document.forms["registration"].submit();
	return true;
	
	
}

function post_continent(selected){
	var id = document.getElementById('idcontinent').options[document.getElementById('idcontinent').selectedIndex].value;
	sendData("POST", "country.php", "idcontinent="+id+"&selected="+selected, "country");
	return true;
	
}

function post_categorie(selected, profession){
	if(selected != null){
		selected = selected.replace(/&/gi,"#et#");
	}
	
	if(profession != null){
		profession = profession.replace(/&/gi,"#et#");
	}
	
	var id = selected;
	var value = document.getElementById('categorie').options[document.getElementById('categorie').selectedIndex].value;
	
	sendData("POST", "profession.php", "id="+id+"&value="+value+"&profession="+profession, "profession");
	
	return true;
	
}

function check_mail(mail){

    var re    = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$", "gi");

    if(!re.test(mail)){
	   return false;
	}else{
	   return true;
	}

}

function check_mail_pass(){
	
	// On vÃ©rifie la validitÃ© de l'adresse email
	var mail = document.getElementById('mail_pass').value;

	if(!check_mail(mail)){
		alert('invalid email adress');
		return false;
	}
	
	// si c'est ok on affiche un message prÃ©cisant que le mail a Ã©tÃ© envoyÃ©
	var div_confirm 		= document.getElementById('mail_envoye');
	div_confirm.innerHTML	= '<b>Email sent...</b>';
	return true;
}

function workshop_1(id){
	var div = document.getElementById('workshop1_2');
	var txt = '<p><b>Second choice</b><br /><br />';
	switch(id){
		case 1:
				txt+= '<input type="radio" name="workshop1_2" value=2 />Workshop II: Investment in Innovation - is it Enough to Fuel our Future?<br />';
				txt+= '<input type="radio" name="workshop1_2" value=3 />Workshop III: What is the impact of the new energy equation on tomorrow\'s world ?<br />';
				break;
		case 2:
				txt+='<input type="radio" name="workshop1_2" value=1 />Workshop I: The Energy Mix of 2050 - What Cocktail of Oil and Gas?<br />';
				txt+='<input type="radio" name="workshop1_2" value=3 />Workshop III: What is the impact of the new energy equation on tomorrow\'s world ?<br />';
				break;
		case 3:
				txt+='<input type="radio" name="workshop1_2" value=1 />Workshop I: The Energy Mix of 2050 - What Cocktail of Oil and Gas?<br />';
				txt+='<input type="radio" name="workshop1_2" value=2 />Workshop II: Investment in Innovation - is it Enough to Fuel our Future?<br />';		
				break;
	}
	txt+= "</p>";
	div.innerHTML = txt;
	div.style.display = "block" ;
	return true;
}

function workshop_2(id){
	var div = document.getElementById('workshop2_2');
	var txt = '<p><b>Second choice</b><br /><br />';
	switch(id){
		case 1:
				txt+='<input type="radio" name="workshop2_2" value=5 />Workshop V: The Sustainable Organisation – Walking the Talk…<br />';				
				txt+='<input type="radio" name="workshop2_2" value=6 />Workshop VI: Should Industry Commitments be Self Imposed or do we need more Effective Global Rules ?<br />';
				break;
		case 2:
				txt+='<input type="radio" name="workshop2_2" value=4 />Workshop IV: What is the role of industry, government and NGOs in creating a sustainable society?<br />'; 	
				txt+='<input type="radio" name="workshop2_2" value=6 />Workshop VI: Should Industry Commitments be Self Imposed or do we need more Effective Global Rules ?<br />';
				break;
		case 3:
				txt+='<input type="radio" name="workshop2_2" value=4 />Workshop IV: What is the role of industry, government and NGOs in creating a sustainable society?<br />'; 	
				txt+='<input type="radio" name="workshop2_2" value=5 />Workshop V: The Sustainable Organisation – Walking the Talk…<br />';						
				break;
	}
	
	txt+= "</p>";	
	div.innerHTML = txt;
	div.style.display = "block" ;
	return true;
}

function workshop_3(id){
	var div = document.getElementById('workshop3_2');
	var txt = '<p><b>Second choice</b><br /><br />';
	switch(id){
		case 1:
				txt+='<input type="radio" name="workshop3_2" value=8 />Workshop VIII: What Kind of Image Makeover does the Industry need to Attract and Retain the Best Talent? <br />';
				txt+='<input type="radio" name="workshop3_2" value=9 />Workshop IX: Tomorrow’s Leadership<br />';
				break;
		case 2:
				txt+='<input type="radio" name="workshop3_2" value=7 />Workshop VII: What Kind of Future is there for Young People in the Energy Sector?<br />';
				txt+='<input type="radio" name="workshop3_2" value=9 />Workshop IX: Tomorrow’s Leadership<br />';
				break;
		case 3:
				txt+='<input type="radio" name="workshop3_2" value=7 />Workshop VII: What Kind of Future is there for Young People in the Energy Sector?<br />';
				txt+='<input type="radio" name="workshop3_2" value=8 />Workshop VIII: What Kind of Image Makeover does the Industry need to Attract and Retain the Best Talent? <br />';
				break;
	}

	txt+= "</p>";	
	div.innerHTML = txt;
	div.style.display = "block" ;
	return true;
}
