function getPageSize() {
	        
	var xScroll, yScroll;
		
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}


function gradient(id, level)
{
	//alert(id);
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	return;
}


function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 500) + 10);
		//setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 100);
		//level += 0.01;
		level += 0.1;
	}
}


// Open the lightbox

/*
function openbox(formtitle, fadin)
{
	var box = document.getElementById('box'); 
  document.getElementById('filter').style.display='block';

	var arrayPageSize = getPageSize();
	//document.getElementById('filter').setStyle({ height: arrayPageSize[1] + 'px' });
	document.getElementById('filter').style.height=arrayPageSize[1]+'px';

  var btitle = document.getElementById('boxtitle');
  btitle.innerHTML = formtitle;
  
  if(fadin)
  {
	 gradient("box", 0);
	 fadein("box");
  }
  else
  { 	
    box.style.display='block';
  }  	
}
*/
function openbox(nameBox, fadin)
{
	/**/
	if (nameBox=="boxVideo"){
		insertFlash('movie/clip_presentation.swf','width="640" height="400"');
	}
	
	
	var box = document.getElementById(nameBox); 
  document.getElementById('filter').style.display='block';

  document.getElementById('boxActive').value=nameBox;

	var arrayPageSize = getPageSize();
	//document.getElementById('filter').setStyle({ height: arrayPageSize[1] + 'px' });
	document.getElementById('filter').style.height=arrayPageSize[1]+'px';

/* 
	var btitle = document.getElementById('boxtitle');
  btitle.innerHTML = formtitle;
*/
  if(fadin)
  {
		//alert(nameBox);
	 gradient(nameBox, 0);
	 fadein(nameBox);
	 //fadein("box");
  }
  else
  { 	
    box.style.display='block';
  } 

	
/* 	
	box.style.display='block';
*/
}


// Close the lightbox

function closebox()
{
   var nameBox = document.getElementById('boxActive').value;
	 //alert(nameBox);
	 //document.getElementById('box').style.display='none';
	 document.getElementById(nameBox).style.display='none';
   document.getElementById('filter').style.display='none';
	document.getElementById("contenuVideoPresentation").innerHTML = "";
}


function arobaceok(EMAIL)
{
var a=document.forms[0].EMAIL.value;
var test="" + a;
for(var k = 0; k < test.length;k++)
{
var c = test.substring(k,k+1);
if(c == "@")
{
return true;
}
}
alert("Votre E-mail, Merci");
return false;
}

function test_email (my_email) {
	var new_string = new String(my_email);
	if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
		return false;
	}
	else {
		return true;
	}
}
		
function trim (myString) { 
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'') 
} 

function traiteChaine (ch) { 
	/*
	ch = ch.replace(/\\/g,"\\\\");
	ch = ch.replace(/\'/g,"\\'");
	ch = ch.replace(/\"/g,"\\\"");
	*/
	//ch = ch.escapeHTML();
	ch = encodeURIComponent(ch);
	return ch;
} 


function formulaire()
{
/**/		
	var civilite = "";
	//alert(civilite);
	if(document.getElementById('MME').checked){
		civilite = "MME";
	}else if(document.getElementById('MLLE').checked){
		civilite = "MLLE";
	}else if(document.getElementById('MR').checked){
		civilite = "MR";
	}
	//alert(civilite);

	var email = trim (document.getElementById('email').value);
	var nom = trim (document.getElementById('nom').value);
	var prenom = trim (document.getElementById('prenom').value);
	var telephone = trim (document.getElementById('telephone').value);
	//alert(email);
	
	var formOK = true;
	var messageAlert = "";
	
	if (!nom){
		formOK = false;
		messageAlert += "le nom est un champs obligatoirs,<br>";
	}
	if (!prenom){
		formOK = false;
		messageAlert += "le prenom est un champs obligatoirs,<br>";
	}
	if (!telephone){
		formOK = false;
		messageAlert += "le telephone est un champs obligatoirs,<br>";
	}
	if (!email){
		formOK = false;
		messageAlert += "l'email est un champs obligatoirs,<br>";
	}else{
		if (!test_email (email)){
			//alert(email+" n'est pas une adresse valide");
			formOK = false;
			messageAlert += email+" n'est pas une adresse valide,<br>";
		}
	}
	if (formOK){
		openbox('boxFormulaire', 0);
		//là faudra faire uen bidouille ajax ^^
	/**/
		var OAjax;
		if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
		else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP'); 
		OAjax.open('POST',"include/traitement_SQL.php",true);
		OAjax.onreadystatechange = function()
		{
				if (OAjax.readyState == 4 && OAjax.status==200)
				{
						if (document.getElementById) 
						{    
								
								
								var chaineText = OAjax.responseText;
								// Nous decoupons la reponse selon le caractere choisi
								var tabChaineText = chaineText.split('&');
								// Nous appliquons les valeurs récupérées au element correspondant
								//document.getElementById('revendeur').value = tabChaineText[0];
								//document.getElementById('adresserev').value = tabChaineText[1];
								//document.getElementById('coderev').value = tabChaineText[2];
								//if (OAjax.responseText =='true') { 
//alert(tabChaineText[0])	;						
//alert(tabChaineText[1])	;						
//alert(tabChaineText[2])	;						
								if (tabChaineText[0] =='true') { 
									//OK 
									//document.getElementById('msg').innerHTML='<font color=GREEN>'+OAjax.responseText+'</font>';
									document.getElementById('idInfoBtoC').value=tabChaineText[1];
									//document.getElementById('msg').innerHTML='<font color=GREEN>'+tabChaineText[2]+'</font>';
	
									// et apres on netoye le formulaire...
									/*	*/
									document.getElementById('MME').checked=false;
									document.getElementById('MLLE').checked=false;
									document.getElementById('MR').checked=false;
								
							/*	
									document.getElementById('civilite')[0].checked=false;
									document.getElementById('civilite')[1].checked=false;
									document.getElementById('civilite')[2].checked=false;
							*/
								
									document.getElementById('email').value="";
									document.getElementById('nom').value="";
									document.getElementById('prenom').value="";
									document.getElementById('telephone').value="";
	
								}else{                             
									// PAS OK
									//document.getElementById('msg').innerHTML='<font color=RED>'+OAjax.responseText+'</font>';
									//document.getElementById('msg').innerHTML='<font color=RED>'+tabChaineText[0]+'</font>';
								}
						}     
				}
		}
		OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		OAjax.send('choix=form1&civilite='+civilite+'&nom='+nom+'&prenom='+prenom+'&email='+email+'&telephone='+telephone);           	
			
	
	}else{
		//alert(messageAlert);
		//messageAlert += "Merci.";
		messageAlert = "<br>Merci de compléter les champs obligatoires.";
		openbox('boxAlert', 0);
		document.getElementById("contenuHtmlAlert").innerHTML = "<center>"+messageAlert+"</center>";
	}
}


function formulaireSuite()
{
/**/		
	var idInfoBtoC = document.getElementById('idInfoBtoC').value;
	var pourFormationDIF = 0;
	if(document.getElementById('pourFormationDIF').checked)pourFormationDIF = 1;
	var pourFormationPersonnel = 0;
	if(document.getElementById('pourFormationPersonnel').checked)pourFormationPersonnel = 1;
	var pourFormationSalariesEntreprise = 0;
	if(document.getElementById('pourFormationSalariesEntreprise').checked)pourFormationSalariesEntreprise = 1;
	var pourFormationAutre = 0;
	if(document.getElementById('pourFormationAutre').checked)pourFormationAutre = 1;
	var remarque = traiteChaine(trim (document.getElementById('remarque').value));
	
	var formOK = true;
	
	if (!idInfoBtoC){
		formOK = false;
	}
	if (formOK){
	/**/
		var OAjax;
		if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
		else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP'); 
		OAjax.open('POST',"include/traitement_SQL.php",true);
		OAjax.onreadystatechange = function()
		{
				if (OAjax.readyState == 4 && OAjax.status==200)
				{
						if (document.getElementById) 
						{    
								
								
								var chaineText = OAjax.responseText;
								// Nous decoupons la reponse selon le caractere choisi
								var tabChaineText = chaineText.split('&');
								// Nous appliquons les valeurs récupérées au element correspondant
								//document.getElementById('revendeur').value = tabChaineText[0];
								//document.getElementById('adresserev').value = tabChaineText[1];
								//document.getElementById('coderev').value = tabChaineText[2];
								//if (OAjax.responseText =='true') { 
//alert(tabChaineText[0])	;						
//alert(tabChaineText[1])	;						
//alert(tabChaineText[2])	;						
								if (tabChaineText[0] =='true') { 
									//OK 
									//document.getElementById('msg').innerHTML='<font color=GREEN>'+tabChaineText[1]+'</font>';
									closebox();
									// et apres on netoye le formulaire...
									document.getElementById('idInfoBtoC').value="";
									document.getElementById('pourFormationDIF').checked=false;
									document.getElementById('pourFormationPersonnel').checked=false;
									document.getElementById('pourFormationSalariesEntreprise').checked=false;
									document.getElementById('pourFormationAutre').checked=false;
									document.getElementById('remarque').value="";
								}else{                             
									// PAS OK
									//document.getElementById('msg').innerHTML='<font color=RED>'+tabChaineText[1]+'</font>';
								}
						}     
				}
		}
		OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		OAjax.send('choix=form2&idInfoBtoC='+idInfoBtoC+'&pourFormationDIF='+pourFormationDIF+'&pourFormationPersonnel='+pourFormationPersonnel+'&pourFormationSalariesEntreprise='+pourFormationSalariesEntreprise+'&pourFormationAutre='+pourFormationAutre+'&remarque='+remarque);           	
	}
}


