function setCSS(){
if(navigator.appName=="Netscape"){
var oStyle = document.styleSheets[0].cssRules[0].style;
oStyle.setProperty('position','fixed','');
oStyle.setProperty('bottom','0px','');
oStyle.setProperty('left','0px','');
}
}

function initialize(){
//setCSS();
initializeElements();
centerOfWindow("logoSPM");
}

function initializeElements()
	{
	setCSS();
	//alert(document.body.clientHeight);
		for(i=1;i<7;i++){
			initializeElement('contenu'+i,'bouton'+i,'idmenu');
		}
		initializeElementSPM('contenu99');
		
	}


function initializeElement(baliseId,button,container)
	{
		/*if(docum	ent.getElementById(baliseId).offsetWidth<document.getElementById(button).offsetWidth)
			{
			document.getElementById(baliseId).style.zIndex=2;
			document.getElementById(button).style.zIndex=1;
			document.getElementById(baliseId).style.borderTop="1px solid #d5deed";
			}*/
		if (document.getElementById && document.getElementById(baliseId) != null) 
			{
			var fullwidth=document.getElementById(baliseId).offsetWidth;
			var posButton=FindPos(button);
			var posContainer=FindPos(container);
			if(fullwidth+posButton['X'] > document.getElementById(container).offsetWidth+posContainer['X'])
				{
				document.getElementById(baliseId).style.left=posButton['X']-(fullwidth-document.getElementById(button).offsetWidth);
				if(fullwidth!=document.getElementById(baliseId).offsetWidth) document.getElementById(baliseId).style.left=posButton['X']-(document.getElementById(baliseId).offsetWidth-document.getElementById(button).offsetWidth);
				}
			else
				{
				document.getElementById(baliseId).style.left=posButton['X']+'px';
				}
			document.getElementById(baliseId).style.top=posButton['Y']+document.getElementById(button).offsetHeight+'px';
			document.getElementById(baliseId).style.visibility='hidden';
			document.getElementById(baliseId).style.display='none';
			}
	}

function initializeElementSPM(baliseId)
	{
		//var offset=70;
		/*if(docum	ent.getElementById(baliseId).offsetWidth<document.getElementById(button).offsetWidth)
			{
			document.getElementById(baliseId).style.zIndex=2;
			document.getElementById(button).style.zIndex=1;
			document.getElementById(baliseId).style.borderTop="1px solid #d5deed";
			}*/
		/*if (document.getElementById && document.getElementById(baliseId) != null) 
			{
			var fullwidth=document.getElementById(baliseId).offsetWidth;
			var posButton=FindPos(button);
			var posContainer=FindPos(container);
			if(fullwidth+posButton['X'] > document.getElementById(container).offsetWidth+posContainer['X'])
				{
				document.getElementById(baliseId).style.left=posButton['X']-(fullwidth-document.getElementById(button).offsetWidth)+offset;
				if(fullwidth!=document.getElementById(baliseId).offsetWidth) document.getElementById(baliseId).style.left=posButton['X']+offset-(document.getElementById(baliseId).offsetWidth-document.getElementById(button).offsetWidth);
				}
			else
				{
				document.getElementById(baliseId).style.left=posButton['X']+offset;
				}
			document.getElementById(baliseId).style.top=posButton['Y']+document.getElementById(button).offsetHeight;
			document.getElementById(baliseId).style.visibility='hidden';
			document.getElementById(baliseId).style.display='none';
			}
			*/
			document.getElementById(baliseId).style.visibility='hidden';
			
	}
	
	
	

function FindPos(IdObject)
{
	AObject=document.getElementById(IdObject);
    var posX = 0, posY = 0;
    
    do
    {
        posX += AObject.offsetLeft;
        posY += AObject.offsetTop;
		AObject = AObject.offsetParent;
    }
    while( AObject != null );
    var pos = [];
    pos['X'] = posX;
    pos['Y'] = posY;
    return pos;
}
	
	
	

function colorBorder(baliseId,button)
	{
		if(document.getElementById(baliseId).offsetWidth>=document.getElementById(button).offsetWidth)
			{
			document.getElementById(button).style.borderBottom="1px solid #d5deed";
			}
	}

function afficheId(baliseId,button) 
  {
  if (document.getElementById && document.getElementById(baliseId) != null) 
    {
	document.getElementById(baliseId).style.zIndex++;
	document.getElementById(baliseId).style.zIndex++;
	document.getElementById(button).style.zIndex++;
	document.getElementById(button).style.zIndex++;
	document.getElementById(baliseId).style.visibility='visible';
    document.getElementById(baliseId).style.display='block';
	//colorBorder(baliseId,button);
    }
  }
  
  function afficheIdSPM(baliseId) 
  {
  if (document.getElementById && document.getElementById(baliseId) != null) 
    {
	document.getElementById(baliseId).style.zIndex++;
	document.getElementById(baliseId).style.zIndex++;
	//document.getElementById(button).style.zIndex++;
	//document.getElementById(button).style.zIndex++;
	document.getElementById(baliseId).style.visibility='visible';
    //colorBorder(baliseId,button);
    }
  }
  
  

 function cacheId(baliseId,button) 
  {
  if (document.getElementById && document.getElementById(baliseId) != null) 
    {
	//document.getElementById(button).style.borderBottom="1px solid #000000";
	document.getElementById(baliseId).style.zIndex--;
	document.getElementById(baliseId).style.zIndex--;
	document.getElementById(button).style.zIndex--;
	document.getElementById(button).style.zIndex--;
    document.getElementById(baliseId).style.visibility='hidden';
    document.getElementById(baliseId).style.display='none';
    }
  }
  
  function cacheIdSPM(baliseId) 
  {
  if (document.getElementById && document.getElementById(baliseId) != null) 
    {
	//document.getElementById(button).style.borderBottom="1px solid #000000";
	document.getElementById(baliseId).style.zIndex--;
	document.getElementById(baliseId).style.zIndex--;
	//document.getElementById(button).style.zIndex--;
	//document.getElementById(button).style.zIndex--;
    document.getElementById(baliseId).style.visibility='hidden';
    }
  }
  
  function magnify(){
	document.getElementById("logo").src="images/spm4tp.png";
  }
  
  function dismagnify(){
	document.getElementById("logo").src="images/spm4tp2.png";
  }
  
  function centerOfWindow(id){
  document.getElementById(id).style.top=(document.documentElement.clientHeight-222)/2+"px";
  document.getElementById(id).style.left=(document.documentElement.clientWidth-365)/2+"px";
  }
  
function makeVisible(id){
	document.getElementById(id).style.visibility='visible';
    document.getElementById(id).style.display='block';
} 
function hideElement(id){
    document.getElementById(id).style.visibility='hidden';
    document.getElementById(id).style.display='none';
}
  
  
function traiterChamps(listeChampsObligatoires){
var champsVide="Champs vides:\n";
var result=true;
//for (champs in listeChampsObligatoires){
for(var champs=0;champs<listeChampsObligatoires.length;champs++){
	if((typeof listeChampsObligatoires[champs])=='string')	{
		if(document.getElementById(listeChampsObligatoires[champs]).innerHTML){
			pointeurChamps=document.getElementById(listeChampsObligatoires[champs]);
			if(pointeurChamps.createTextRange){
				var range = pointeurChamps.createTextRange();
				var text = range.text;
			}else if(document.createRange){
				var range = document.createRange();
				range.setStartBefore(pointeurChamps);
				range.setEndAfter(pointeurChamps);
				var text = range.toString();
			}else{
				var text = remSp(pointeurChamps.innerHTML);
			}
			var text=remSp(text);
			if(!text){
					champsVide+=listeChampsObligatoires[champs]+"\n";
					result=false;
			}
			
			
		}else{
			if(!remSp(document.getElementById(listeChampsObligatoires[champs]).value)){
				champsVide+=listeChampsObligatoires[champs]+"\n";
				result=false;
			}
		}
	}else{
		if(listeChampsObligatoires[champs].innerHTML){
			if(listeChampsObligatoires[champs].createTextRange){
				var range = listeChampsObligatoires[champs].createTextRange();
				var text = range.text;
			}else if(document.createRange){
				var range = document.createRange();
				range.setStartBefore(listeChampsObligatoires[champs]);
				range.setEndAfter(listeChampsObligatoires[champs]);
				var text = range.toString();
			}else{
				var text = remSp(listeChampsObligatoires[champs].innerHTML);
			}
			var text=remSp(text);
			if(!text){
					champsVide+=listeChampsObligatoires[champs].id+"\n";
					result=false;
			}
		}else{
			if(!remSp(listeChampsObligatoires[champs].value)){
				champsVide+=listeChampsObligatoires[champs].id+"\n";
				result=false;
			}
		}
	}
}
if (!result)alert(champsVide);
return result;
}

function remBR(arg){
if(arg)return arg.replace(/<br>/,'');
else return false;
}

function remSp(arg){
if(arg)return arg.replace(/\s+/,'');
else return false
} 
// si JavaScript est disponible, cache le contenu dès le 
// chargement de la page. Sans JavaScript, le contenu sera 
// affiché.

function displayRow(rowId){
navigateur = navigator.appName;
	if ( navigateur == "Microsoft Internet Explorer" )
	{
		document.getElementById(rowId).style.display="block";
	}else{
		document.getElementById(rowId).style.display="table-row";
	}
}
function hideRow(rowId){
	document.getElementById(rowId).style.display="none";
}

var mail_regExp=(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/g);

function verifyPassToPage(protectedPage){
if (traiterChamps(new Array("password","username"))){
	new Ajax.Request('include/verifyPass.php', 
					{
						parameters: $('passwordForm').serialize(true),
						method: 'post',
						onComplete: function(transport) {
									if (transport.responseText.indexOf('true')!=-1){
										document.location="index.php?page="+protectedPage;
									}else{
										document.location="index.php?page="+protectedPage+"&err="+transport.responseText;
									}
									}
					}
					); 
	}
}


function changePass(){
if (traiterChamps(new Array("password0"))){
	new Ajax.Request('agora/applyNewPass.php', 
					{
						parameters: {user:$('user').value,password0:$('password0').value},
						method: 'post',
						onComplete: function(transport) {
									if (transport.responseText.indexOf('mis')!=-1){
										confirm2(transport.responseText);
									}else{
										requestBack2(transport.responseText);
									}
									}
					}
					); 
	}
}

function confirm2(message){
/* document.getElementById('passForm10').innerHTML='';
document.getElementById('passForm20').innerHTML='';
document.getElementById('passForm11').innerHTML='';
document.getElementById('passForm21').innerHTML='';
document.getElementById('passForm31').innerHTML=''; */
document.getElementById('errorMessage').innerHTML=message;
}

function clearForm(){
document.getElementById('errorMessage').innerHTML='';
document.getElementById('password0').value='';
}

function requestBack2(message){

document.getElementById('password0').value='';
document.getElementById('errorMessage').innerHTML=message;
}
