var langue = "FR";
var tabConsultation = new Array();
var contact_FR = "";
var contact_UK = "";
var start3D = false;
var erreurContact = "";

//recupération des info du navigateur
function getNavigateur()
{
	// Récupération des infos du navigateur
	var N=navigator.appName; var V=navigator.appVersion;
	var version="?"; var nom=N; var os="?"; var langue="?";
	if (N=="Microsoft Internet Explorer") 
	{
		langue=navigator.systemLanguage
		version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf(";",V.indexOf("MSIE",0)));
		if (V.indexOf("Win",0)>0) 
		{
			if ( V.indexOf(";",V.indexOf("Win",0)) > 0 ) 
			{
				os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			} else 
			{
				os=V.substring(V.indexOf("Win",0),V.indexOf(")",V.indexOf("Win",0)));
			}
		}
		if (V.indexOf("Mac",0)>0) 
		{
			os="Macintosh";
			version=V.substring(V.indexOf("MSIE",0)+6,V.indexOf(" ",V.indexOf("MSIE",0)));
		}
	}
	if (N=="Netscape") 
	{
		langue=navigator.systemLanguage
		version=(V.substring(0,V.indexOf("(",0)));
		if (V.indexOf("Mac",0)>0) 
		{
			os="Macintosh";
		}
		if (V.indexOf("Linux",0)>0) 
		{
			os="Linux";
		}
		if (V.indexOf("Win",0)>0) 
		{
			os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
		}
		if (version==5) 
		{
			version="6.0"
		}
	}
	return (nom+"#"+version.substr(0,3)+"#"+os+"#"+langue)
}

/*function popup3D(langue)
{
  largeurFenetre = 941;
  hauteurFenetre = 632;
  largeurEcran = screen.width;
  hauteurEcran = screen.height;
  posLeft = (largeurEcran - largeurFenetre)/2;
  posTop = (hauteurEcran - hauteurFenetre)/2;
  window.open("popup.php?langue="+langue,"OMIA","status=no,scrollbars=no,menubar=no,width="+largeurFenetre+",height="+hauteurFenetre+",left="+posLeft+",top="+posTop);
}*/
function popup3D(langue)
{
  largeurFenetre = 941;
  hauteurFenetre = 632;
  largeurEcran = screen.width;
  hauteurEcran = screen.height;
  posLeft = (largeurEcran - largeurFenetre)/2;
  posTop = (hauteurEcran - hauteurFenetre)/2;
  
  if(langue=='UK'){
	  path = "../";
  }else{
	  path = "";
  }
  window.open( path + "module1/frontoffice/popup.php?langue="+langue,"OMIA","status=no,scrollbars=no,menubar=no,width="+largeurFenetre+",height="+hauteurFenetre+",left="+posLeft+",top="+posTop);
}


function aff3D()
{
  document.getElementById('accueil_FR').style.display = 'none';
  document.getElementById('accueil_UK').style.display = 'none';
  document.getElementById('visu3D').style.display = 'block';
  start3D = true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
 
 // Change la couleur des lignes d'un tableau
 function setPointer(theRow, thePointerColor)
 {
  if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
   return false;
  }
  if (typeof(document.getElementsByTagName) != 'undefined') {
   var theCells = theRow.getElementsByTagName('td');
  }
  else if (typeof(theRow.cells) != 'undefined') {
   var theCells = theRow.cells;
  }
  else {
   return false;
  }
 
  var rowCellsCnt  = theCells.length;
  for (var c = 0; c < rowCellsCnt; c++) {
   theCells[c].style.backgroundColor = thePointerColor;
  }
 
  return true;
 }

 //recupération des info du navigateur
function getNavigateur()
{
	// Récupération des infos du navigateur
	var N=navigator.appName; var V=navigator.appVersion;
	var version="?"; var nom=N; var os="?"; var langue="?";
	if (N=="Microsoft Internet Explorer") 
	{
		langue=navigator.systemLanguage
		version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf(";",V.indexOf("MSIE",0)));
		if (V.indexOf("Win",0)>0) 
		{
			if ( V.indexOf(";",V.indexOf("Win",0)) > 0 ) 
			{
				os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			} else 
			{
				os=V.substring(V.indexOf("Win",0),V.indexOf(")",V.indexOf("Win",0)));
			}
		}
		if (V.indexOf("Mac",0)>0) 
		{
			os="Macintosh";
			version=V.substring(V.indexOf("MSIE",0)+6,V.indexOf(" ",V.indexOf("MSIE",0)));
		}
	}
	if (N=="Netscape") 
	{
		langue=navigator.systemLanguage
		version=(V.substring(0,V.indexOf("(",0)));
		if (V.indexOf("Mac",0)>0) 
		{
			os="Macintosh";
		}
		if (V.indexOf("Linux",0)>0) 
		{
			os="Linux";
		}
		if (V.indexOf("Win",0)>0) 
		{
			os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
		}
		if (version==5) 
		{
			version="6.0"
		}
	}
	return (nom+"#"+version.substr(0,3)+"#"+os+"#"+langue)
}

//gestion de l'ecrasement d'un fichier uploader
function confirmationEcrase(listefichier, formu, champPhoto)
{
	var champ = champPhoto.name;
	var lstFichier = listefichier.split("#");
	var champPhoto = champPhoto.value;
	var lspPhoto = champPhoto.split("\\");
	var taille = lspPhoto.length;
	
	photo = lspPhoto[taille -1];
	for (i=0; i<lstFichier.length; i++)
	{
		if (lstFichier[i] == photo)
		{
			rep = confirm('Voulez vous remplacer la photo : ' + photo + ' ?');
			if (rep == true)
			{
				document.forms[formu].elements['ecraseFichier'+champ].value="true";
			}
			else
			{
				document.forms[formu].elements['ecraseFichier'+champ].value="false";
			}
		}
	}
	return true;
}

function confirmSupprBase(file)
// Confirmation de suppression d'un fichier de base de donnée
{
	if (confirm("Etes-vous sûr de vouloir supprimer ce fichier ?"))
	{
		var test = getNavigateur();
		if (test.indexOf("Mac",0)>0)
		{
			document.write("<form name=\"confirmSupprBase\" action=\"gestionsauvegarde.php\" method=\"GET\"");
			document.write("<input type=\"hidden\" name=\"action\" value=\"delete\">");
			document.write("<input type=\"hidden\" name=\"file\" value= \"" + file + "\">");
			document.write("</form>");
			document.confirmSupprBase.submit();
		}
		else
		{
			document.location.href = "gestionsauvegarde.php?action=delete&file="+file;
		}
	}
	else
	{
		alert("Demande de suppression annulée !");
	}
}

function getXhr()
{
	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
	{ // Internet Explorer 
	   try
	   {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else 
	{ // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
	return xhr;
}

/**
* Méthode qui sera appelée sur le click du bouton
*/
function validFormContact()
{
	var xhr = getXhr();
	
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function()
	{
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			//var objet = eval('('+xhr.responseText+')');
			var reponse = xhr.responseText;
			//alert(reponse);
			if (reponse != "OK" && reponse != "KO")
			{
        //alert(reponse);
        //validation des entrées
        var tabField = ['nom','prenom','societe','adresse','cp','ville','telephone','email'];
        for (i=0;i<tabField.length;i++)
        {
          if (document.forms['formContact_'+langue].elements[tabField[i]+'_'+langue].value == "")
          {
            document.getElementById('img_'+tabField[i]+'_'+langue).src = "img/asterix_on.jpg";
          } 
          else
          {
            document.getElementById('img_'+tabField[i]+'_'+langue).src = "img/asterix_off.jpg";
          }
        }
        document.getElementById('erreurContact_'+langue).style.display = 'block';
      }
      else
      {
			 erreurContact = "";
       if (reponse == "OK")
			 {
        if (langue == "FR")
        {
          txt = "Votre demande de renseignements a bien été envoyée.<br>Nous vous remercions de l'intérêt que vous portez à notre société.";
        }
        else
        {
          txt = "Your request for information has been sent.<br>We thank you for the interest you have in our society.";
        }
       }
       else
       {
        if (langue == "FR")
  			{
          txt = "Une erreur est survenue";
        }
        else
        {
          txt = "An error occured";
        }
       }
       document.getElementById("contact_"+langue).innerHTML = '<table width="625" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="f9b700"><img id="titre" src="img/contact_'+langue+'.jpg"></td></tr></table><br><table width="625" border="0" align="center" cellpadding="2" cellspacing="0"><tr><td width="60">&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td class="txt">'+txt+'</td></tr></table>';
			}
		}
	}

	// passage parametre
	// Ici on va voir comment faire du post
	xhr.open("POST","validContact.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	// ne pas oublier de poster les arguments
  nom = document.getElementById("formContact_"+langue).elements["nom_"+langue].value;
	prenom = document.getElementById("formContact_"+langue).elements["prenom_"+langue].value;
	societe = document.getElementById("formContact_"+langue).elements["societe_"+langue].value;
	adresse = document.getElementById("formContact_"+langue).elements["adresse_"+langue].value;
	ville = document.getElementById("formContact_"+langue).elements["ville_"+langue].value;
	cp = document.getElementById("formContact_"+langue).elements["cp_"+langue].value;
	pays = document.getElementById("formContact_"+langue).elements["pays_"+langue].value;
	telephone = document.getElementById("formContact_"+langue).elements["telephone_"+langue].value;
	fax = document.getElementById("formContact_"+langue).elements["fax_"+langue].value;
	email = document.getElementById("formContact_"+langue).elements["email_"+langue].value;
	message = document.getElementById("formContact_"+langue).elements["message_"+langue].value;
	
	/*consultation = "";
	diese = "";
	for (i=0; i <tabConsultation.length;i++)
	{
    consultation += diese+tabConsultation[i];
    diese  = "#";
  }
//alert(consultation);
 */
 
	xhr.send("param="+langue+","+nom+","+prenom+","+societe+","+adresse+","+cp+","+ville+","+pays+","+telephone+","+fax+","+email+","+message);
}

function permuteLangue(lng)
{
    var xhr = getXhr();
  	
  	// On défini ce qu'on va faire quand on aura la réponse
  	xhr.onreadystatechange = function()
  	{
  		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
  		if(xhr.readyState == 4 && xhr.status == 200)
  		{
  			//var objet = eval('('+xhr.responseText+')');
  			var objet = xhr.responseText;
  			langue = lng;
  			if (lng == "FR")
  			{
          DoFunction('menuCamera.changeLangue','FR');
          
          lngPermute = "UK";
          //Affichage du menu
          document.getElementById('menu_FR').style.display = 'block';
          document.getElementById('menu_UK').style.display = 'none';
          
          //Affichage si besoin de l'ecran d'accueil
  			  if (document.getElementById('accueil_UK').style.display == 'block')
  			  {
            document.getElementById('accueil_UK').style.display = 'none';
            document.getElementById('accueil_FR').style.display = 'block';
          }
          
          //Affichage si besoin du contact
  			  if (document.getElementById('contact_UK').style.display == 'block')
  			  {
            document.getElementById('contact_UK').style.display = 'none';
            document.getElementById('contact_FR').style.display = 'block';
          }
        }
        else
        {
          DoFunction('menuCamera.changeLangue','UK');
          
          lngPermute = "FR";
          //Affichage du menu
          document.getElementById('menu_FR').style.display = 'none';
          document.getElementById('menu_UK').style.display = 'block';
          
          //Affichage si besoin de l'ecran d'accueil
  			  if (document.getElementById('accueil_FR').style.display == 'block')
  			  {
            document.getElementById('accueil_FR').style.display = 'none';
            document.getElementById('accueil_UK').style.display = 'block';
          }
          
          //Affichage si besoin du contact
  			  if (document.getElementById('contact_FR').style.display == 'block')
  			  {
            document.getElementById('contact_FR').style.display = 'none';
            document.getElementById('contact_UK').style.display = 'block';
          }
        }
  			document.getElementById('barreBleu').innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><img src=\"img/barreBleu1.jpg\"></td><td><a href=\"javascript:affContact('"+lng+"');\"><img src=\"img/barreBleu_contact_"+lng+".jpg\" border=\"0\"></a></td><td><a href=\"javascript:permuteLangue('"+lngPermute+"');\"><img src=\"img/barreBleu_drapeau_"+lng+".jpg\" border=\"0\"></a></td></tr></table>";
  		}
  	}
  	// Ici on va voir comment faire du post
  	xhr.open("POST","permuteLangue.php",true);
  	// ne pas oublier ça pour le post
  	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	xhr.send("langue="+lng);
}


function affContact(lng)
{
	if (start3D == true)
  {
    //masque la 3D
    document.getElementById('visu3D').style.display = 'none';
    document.getElementById('contact_FR').style.display = 'none';
  	document.getElementById('contact_UK').style.display = 'none';
  	document.getElementById('accueil_UK').style.display = 'none';
    document.getElementById('accueil_FR').style.display = 'none';
  	
  	//Reaffichage du formulaire
  	if (lng == "FR")
  	{
      if (contact_FR != "")
      {
        document.getElementById('contact_FR').innerHTML = contact_FR;
      }
    }
    if (lng == "UK")
  	{
      if (contact_UK != "")
      {
        document.getElementById('contact_UK').innerHTML = contact_UK;
      }
    }
    //Affichage du formulaire
  	document.getElementById('contact_'+lng).style.display = 'block';
  	
  	//memorisation du formulaire
    contact_FR = document.getElementById('contact_FR').innerHTML;
    contact_UK = document.getElementById('contact_UK').innerHTML;
    	
    langue = lng;
  }
}

function load(sParam1, sParam2, navigation) 
{
  // sParam1 = 'idObjet3DComplexe#O3D_fichier#famille#libelle'
  // sParam2 = 'machinerie_position' ou sParam2 = 'machinerie_position#portique_irt#central_as'
	if (document.getElementById('visu3D').style.display == 'none')
	{
		document.getElementById('visu3D').style.display = 'block';
	}
	if (document.getElementById('contact_'+langue).style.display == 'block')
	{
		document.getElementById('contact_'+langue).style.display = 'none';
	}
	DoFunction('HUDload.Load',sParam1, sParam2);
	tabConsultation.push(navigation);
}

function destroy() {
	DoFunction('HUDload.destroy');
}

//Affichage de l'aide
function aide(visible, lng) 
{
  if (start3D == true)
  {
    if (visible == 'true')
  	{
  		if (lng == "FR")
  		{
       DoFunction('HUDaide.show_aide');
  		}
      else
      {
  		 DoFunction('HUDaide.show_help');
  		}
  	}
    else
    {		
  		if (lng == "FR")
  		{
  		 DoFunction('HUDaide.hide_aide');
  		}
      else
      {
  		 DoFunction('HUDaide.hide_help');
  	  }	
    }
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var divActif = "";
var img_id= '';
var imageClique = '';

function afficheDiv(div, imgID)
{
	//Affichage si besoin de la 3D
  if (start3D == true)
  {
    if (divActif != '')
  	{
  		masqueDiv(divActif, img_id);
  	}
  	if(divActif != div)
  	{
      document.getElementById(div).style.display = 'block';
 	    document.getElementById('menu_'+div).innerHTML = '<a href="javascript:afficheDiv(\''+div+'\',\''+imgID+'\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\''+imgID+'\',\'\',\'img/'+div+'_on.jpg\',1)"><img src="img/'+div+'_on.jpg" name="'+imgID+'" border="0">';
 	    divActif = div;
  	}
  	else
  	{
      divActif = "";
    }
  	img_id = imgID;
  }
}

function masqueDiv(div, imgID)
{
  document.getElementById(div).style.display = 'none';
  document.getElementById('menu_'+div).innerHTML = '<a href="javascript:afficheDiv(\''+div+'\',\''+imgID+'\');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\''+imgID+'\',\'\',\'img/'+div+'_on.jpg\',1)"><img src="img/'+div+'_off.jpg" name="img1" border="0"></a>';
}

function activeImage(image, bandeau)
{
  if (imageClique != "")
	{
		document.getElementById(imageClique).src = 'img/'+imageClique+'_off.jpg';		
	}
  document.getElementById(image).src = 'img/'+image+'_on.jpg';
  if (bandeau == undefined)
  {
	 document.getElementById('titre').src = 'img/bandeau_'+image+'.jpg';
	}
	else
	{
    document.getElementById('titre').src = 'img/bandeau_'+bandeau+'.jpg';
  }
	imageClique = image;
}

