var clientNav = navigator.appName;

//------------------------------------------------------------------------------
// Affichage & masquage de DIV
//------------------------------------------------------------------------------
//Fonction Affiche une DIV :
function MM_affich_Div(id){
document.getElementById(id).style.display='block';
}

//Fonction cache une DIV :
function MM_cache_Div(id){
document.getElementById(id).style.display='none';
}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// Modification de style
//------------------------------------------------------------------------------
function MM_change_Style(id,newStyle){
	
	MM_change_Style_objDiv = document.getElementById(id);

			if (clientNav == "Microsoft Internet Explorer")
			{
			MM_change_Style_objDiv.style.setAttribute("cssText",newStyle);
			}
			if (clientNav == "Netscape")
			{
			MM_change_Style_objDiv.setAttribute("style",newStyle);

		 }
}

//------------------------------------------------------------------------------
// Gestion Click : Espace Connection client
//------------------------------------------------------------------------------
function MM_click_client(idCible,id){	
	MM_click_client_Cible = document.getElementById(idCible);

		if (MM_click_client_Cible.style.display != "block"){
				MM_affich_Div(idCible);
				MM_change_Style(id,'padding-left: 15px; background-image: url(img/center_client.gif);background-repeat: no-repeat;background-position: 0px -12px;');
				}
		else if (MM_click_client_Cible.style.display == "block"){
				MM_cache_Div(idCible);
				MM_change_Style(id,'padding-left: 15px; background-image: url(img/center_client.gif);background-repeat: no-repeat;background-position: 0px 0px;');
				}		
}


//------------------------------------------------------------------------------
// Fonction requette HttpRequest :
//------------------------------------------------------------------------------
function MM_HttpRequest(id,page)
		{
		MM_HttpRequest_objDiv = document.getElementById(id);
		//alert(id);
	if (window.XMLHttpRequest)//  Objet de la fenetre courant
		{ 
   		requeteAJAX = new XMLHttpRequest();//  Firefox, Safari, ...
		} 
	else 
  	if (window.ActiveXObject)//  Version Active
  		{
      	requeteAJAX = new ActiveXObject("Microsoft.XMLHTTP");// Internet Explorer 
  	 	}
	//alert(page);
	requeteAJAX.open('GET', page, false);
	requeteAJAX.send(null);
	MM_HttpRequest_objDiv.innerHTML = requeteAJAX.responseText;
		}

function MM_createAjaxObj(){
        var httprequest;
        if (window.XMLHttpRequest){ //Mozilla,...
                httprequest = new XMLHttpRequest();
                /*if (httprequest.overrideMimeType){
                        httprequest.overrideMimeType('text/xml');
                }*/
        }
        else if (window.ActiveXObject){ // IE
                try {
                        httprequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                        try {
                                httprequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (E){
                        }
                }
        }
        return httprequest;
}
//------------------------------------------------------------------------------
// Objet News :
//------------------------------------------------------------------------------
function CC_News(News_tab)
{
	this.News_tab = News_tab;//Array contenant les pages de news
	
	this.LoadNews = function()//Charge les news se trouvant dans l'Array News_tab
				{
					
					for (i in this.News_tab)
						{
							MM_HttpRequest(this.News_tab[i][0],this.News_tab[i][1]);
						}
					
				}
}

//------------------------------------------------------------------------------
// Fonction de chargement COMMUNICATION PRODUIT :
//------------------------------------------------------------------------------
var ComProduit_tab_count = 0;

function MM_time_affich(ComProduit_tab)
{
	if (ComProduit_tab_count > 1){ComProduit_tab_count = 0;}

		MM_time_affich_Id = ComProduit_tab[ComProduit_tab_count][0];
		MM_time_affich_Page = ComProduit_tab[ComProduit_tab_count][1];
		
		ComProduit_tab_count ++;
	
		MM_HttpRequest(MM_time_affich_Id,MM_time_affich_Page);

		setTimeout('MM_time_affich(ComProduit_tab)',3000);
	
}

//------------------------------------------------------------------------------
// Fonction d'affichage des images
//------------------------------------------------------------------------------
function MM_AfficheLightBox(type){
	if(type){
		var box=document.getElementById("lightbox");
		box.removeChild(document.getElementById('minis'));
		box.removeChild(document.getElementById('imgcontent'));
	}
	document.getElementById('header_haut').style.backgroundColor='#003366';
	document.getElementById('header_fla').style.display='none';
	document.getElementById('darkbox').style.display='block';
}
function MM_closeLightBox(){
	document.getElementById('darkbox').style.display='none';
	document.getElementById('header_fla').style.display='block';
}
function MM_AfficheImage(img){
	document.getElementById('grande').src=img.src;
}
//------------------------------------------------------------------------------
// Fonction d'affichage du formulaire d'oubli de passe
//------------------------------------------------------------------------------
function MM_afficheOubli(){
	var box=document.getElementById("lightbox");
	document.getElementById('header_haut').style.backgroundColor='#003366';
	document.getElementById('header_fla').style.display='none';
	box.parentNode.style.display='block';
	box.removeChild(document.getElementById('minis'));
	box.removeChild(document.getElementById('imgcontent'));
	//reduction de la taille de la lightbox
	box.style.width=400+"px";
	box.style.height=255+"px";
	box.style.marginTop=150+"px";
	box.style.marginLeft=30+'%';
	document.getElementById('closebox').style.margin='0';
	//creation du formulaire
	var h3=document.createElement('h3');
	h3.innerHTML="Mot de passe oublié";
	h3.style.marginTop=65+"px";
	box.appendChild(h3);
	var formul=document.createElement('form');
	formul.setAttribute('action', '');
	formul.setAttribute('method', 'post');
	formul.setAttribute('id', 'form');
	formul.setAttribute('name', 'form1');
	//formul.setAttribute('onsubmit', 'return false;'); //MM_HttpRequest("lightbox", "./oubliPass.php");
	formul.onsubmit=function(){return (false);}
	//traitement
	formul.innerHTML+="Veuillez saisir votre e-mail : <br />";
	var mail=document.createElement('input');
	mail.setAttribute('type', 'text');
	mail.setAttribute('name', 'mail');
	formul.appendChild(mail);
	formul.innerHTML+='<br /><br />';
	formul.innerHTML+='Code de sécurité obligatoire :<br />';
	var img=document.createElement('img');
	img.setAttribute('src', 'image.php');
	img.align='top';
	formul.appendChild(img);
	var secu=document.createElement('input');
	secu.setAttribute('type', 'text');
	secu.setAttribute('size','15');
	secu.setAttribute('name','secu');
	secu.style.width='140px';
	formul.appendChild(secu);
	formul.innerHTML+='<br /><br />';
	var submit=document.createElement('input');
	submit.setAttribute('type', 'button');
	//submit.setAttribute('onclick', 'alert();');
	submit.onclick=function(){MM_traiteOubli(document.getElementById('form'))};
	submit.value="Envoyer";
	formul.appendChild(submit);
	var hide=document.createElement('input');
	hide.setAttribute('type', 'hidden');
	hide.setAttribute('name', 'etape');
	hide.value="1";
	formul.appendChild(hide);
	box.appendChild(formul);
}

function MM_traiteOubli(form){
	//definir le xhr
	var xhr = new MM_createAjaxObj();
	//traitement
	url='oubliPass.php';
	datas='secu='+form.elements[1].value+'&etape=1&mail='+form.elements[0].value;
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xhr.send(datas);
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			var box=document.getElementById('lightbox');
			box.removeChild(document.getElementById('form'));
			box.innerHTML+='<br />';
			var div=document.createElement('div');
			div.setAttribute('id', 'oubli');
			div.innerHTML=xhr.responseText;
			box.appendChild(div);
		}
	}
	//return false;
}

function MM_incrementeSphereUse(motcle){
	var xhr=new MM_createAjaxObj();
	xhr.open("GET", "./incrementeSphere.php?cle="+motcle, true);
	xhr.send(null);
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			//alert(xhr.responseText);
		}
	}
}