//Copyright format tech 2007
var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10	// Lower value = faster

var objectIdToSlideDown = false;
//var activeId = false;
var dhtmlgoodies_slideInProgress = false;

function showHideContent(e,inputId,prefix)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	if(!prefix)prefix = this.id;
	inputId = inputId + '';
	prefix  = prefix.replace(/[0-9]/g,'') + 'a';
	var answerDiv = document.getElementById(prefix + numericId);
	//alert(numericId);
	objectIdToSlideDown = false;
	try{
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		/*if(activeId &&  activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(activeId,(dhtmlgoodies_slideSpeed*-1),prefix);
		}else{*/
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed,prefix);
		//}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1),prefix);
		//activeId = false;
	}
	} catch(e){
	dhtmlgoodies_slideInProgress = false;
	}
	//activeId = false;
}

function slideContent(inputId,direction,prefix)
{
	
	var obj =document.getElementById(prefix + inputId);
	var contentObj = document.getElementById(prefix + 'c' + inputId);
	height = obj.clientHeight;
	//alert('height=' + height);
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	//alert('height=' + height);
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	//alert('height=' + height);	
	var topPos = height - contentObj.offsetHeight;
	//alert('topPos=' + topPos);
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ',\'' + prefix + '\')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById(prefix + objectIdToSlideDown).style.display='block';
				document.getElementById(prefix + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed,prefix);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			//activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs(prefixq)
{
	var divs = document.getElementsByTagName('DIV');
	 divCounter = 1;
	 blnFound = 0;
	prefixa = prefixq + 'a';
	for(var no=0;no<divs.length;no++){
		if(divs[no].className==prefixq){
			 blnFound = 1;
			divs[no].onclick = showHideContent;
			divs[no].id = prefixq+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = prefixa+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className=prefixq+'ac';
			contentDiv.id = prefixa + 'c' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';

			divCounter++;
		}		
	}
	return blnFound;	
}

function initSideBar(){
initShowHideDivs('q');
;
 showHideContent(false,1,'q');	// Automatically expand first item
}

function initacc(pnum){

	if(pnum=='1'){
		strtri='MOA';
	} else {
		strtri='MOE';
	}
	sendData('tri=' + strtri,'listaccmrc.php5','GET','majdata'); 
	//while(blnDone==0){
	//}
	setTimeout('initShowHideDivs(\'qq\')',1000);
	setTimeout('showHideContent(false,1,\'qq\')',1000);
	
}	
function checkmail(EMAIL)
{
var a=EMAIL;
var test="" + a;
for(var k = 0; k < test.length;k++)
{
var c = test.substring(k,k+1);
if(c == "@")
{
return true;
}
}

return false;
}
function trim(aString) {
    return aString.replace(/^\s+/, "").replace(/\s+$/, "");
}
function moncompte(){
sendData('','moncompte.php5','GET','contentbodyacc');
}
function majcompte(){
sendData('','ajax/admin/majcompte.php5','GET','contentbodyacc');
}
function checkAboData(){
abonom = trim(document.getElementById("abonom").value);
aboprenom = trim(document.getElementById("aboprenom").value);
abosociete = trim(document.getElementById("abosociete").value);
aboemail = trim(document.getElementById("aboemail").value);

err_msg = '';
//Test champs obligatoires
if(abonom=='' || aboprenom=='' || aboemail==''){
	err_msg += 'Renseignez les champs obligatoires. Les champs obligatoires sont marqués d\'une étoile (*)<br>';
}
//Test longueur
if(abonom.length > 50 || aboprenom.length > 50 || aboemail.length > 50 || abosociete.length > 50){
	err_msg += 'Les champs ne doivents pas faire plus de 50 caractères de long<br>';
}

//Test validité mail
if(!checkmail(aboemail)){
	err_msg += 'Adresse mail non valide';
}
//Si Ok, validation côté serveur
errElt = document.getElementById("erreur");

if(err_msg!=''){
	err_msg = '<h1>Erreurs sur le formulaire</h1>' + err_msg;
	errElt.innerHTML = err_msg;
	errElt.style.visibility="visible";
	return false;
} else {
	errElt.innerHTML = '';
	errElt.style.visibility="hidden";
return true;
}
}
function checkUserData(){
if(checkAboData()){
	//Vérification Login, Groupe et profil
	abologin = trim(document.getElementById("abologin").value);
	abogroup = trim(document.getElementById("abogroup").value);
	aboprofil = trim(document.getElementById("aboprofil").value);
	abopass1 = trim(document.getElementById("abopass1").value);
	abopass2 = trim(document.getElementById("abopass2").value);
	
	
	if(abologin=='' || abogroup=='' || aboprofil==''){
		err_msg += 'Renseignez les champs obligatoires. Les champs obligatoires sont marqués d\'une étoile (*)<br>';
	}
	//Test longueur
	if(abologin.length > 50 || abogroup.length > 50 || aboprofil.length > 50 ||
	   abopass1.length > 50 || abopass2.length > 50){
		err_msg += 'Les champs ne doivents pas faire plus de 50 caractères de long<br>';
	}
	
	if(abopass1 != abopass2){
		err_msg += 'Les mots de passe ne correspondent pas<br>';
	}
	//Taille mini des mots de passe
	
	//Si Ok, validation côté serveur
	errElt = document.getElementById("erreur");
	
	if(err_msg!=''){
		err_msg = '<h1>Erreurs sur le formulaire</h1>' + err_msg;
		errElt.innerHTML = err_msg;
		errElt.style.visibility="visible";
		return false;
	} else {
		errElt.innerHTML = '';
		errElt.style.visibility="hidden";
	return true;
		}
}
}
function majabo(){
abonom = trim(document.getElementById("abonom").value);
aboprenom = trim(document.getElementById("aboprenom").value);
abosociete = trim(document.getElementById("abosociete").value);
aboemail = trim(document.getElementById("aboemail").value);
abopass1 = trim(document.getElementById("abopass1").value);
abopass2 = trim(document.getElementById("abopass2").value);


sendData('abonom='+abonom+'&aboprenom='+aboprenom+'&abosociete='+abosociete+
         '&aboemail='+aboemail+'&abopass1='+abopass1+'&abopass2='+abopass2,
         'ajax/admin/majabo.php5','POST','contentbodyacc');
}
//
function majuser(p_opt){
abologin   = trim(document.getElementById("abologin").value);
abonom 	   = trim(document.getElementById("abonom").value);
aboprenom  = trim(document.getElementById("aboprenom").value);
abosociete = trim(document.getElementById("abosociete").value);
abopass1   = trim(document.getElementById("abopass1").value);
abopass2   = trim(document.getElementById("abopass2").value);
aboemail   = trim(document.getElementById("aboemail").value);
aboprofil  = trim(document.getElementById("aboprofil").value);
abogroup   = trim(document.getElementById("abogroup").value);
abodatedeb = trim(document.getElementById("abodatedeb").value);
abodatefin = trim(document.getElementById("abodatefin").value);

sendData('opt='+p_opt+ '&abologin='+abologin+'&abonom='+abonom+'&aboprenom='+aboprenom+'&abosociete='+abosociete+
		 '&aboemail='+aboemail+'&abogroup='+abogroup+'&aboprofil='+aboprofil+'&abopass1='+abopass1+'&abopass2l='+abopass2+
		 '&abodatedeb='+abodatedeb+'&abodatefin='+abodatefin,
		 'ajax/admin/majuser.php5','POST','contentbodyacc');
}
function visu(p_abo){

sendData('login='+p_abo,'ajax/admin/visuusr.php5','POST','contentbodyacc');
}
function modif(p_abo){

sendData('login='+p_abo,'ajax/admin/modifusr.php5','POST','contentbodyacc');
}
function supprime(p_abo){
if(confirm('Etes-vous sûr de vouloir supprimer l\'utilisateur ' + p_abo + ' ?\'')){ 
sendData('login='+p_abo,'ajax/admin/suppusr.php5','POST','contentbodyacc');
}
}
function createuser(){

sendData('','ajax/admin/createusr.php5','POST','contentbodyacc');
}
function listusers(p_firstrow){

sendData('firstrow='+p_firstrow,'ajax/admin/manageusers.php5','POST','contentbodyacc');
}
function listmessages(p_firstrow){

sendData('firstrow='+p_firstrow,'ajax/messagerie/listmessages.php5','POST','contentbodyacc');
}
function affichemsg(p_idmsg){
sendData('msgid='+p_idmsg,'ajax/messagerie/readmessage.php5','POST','contentbodyacc');
}
function supprimemsg(p_idmsg){
if(confirm('Etes-vous sûr de vouloir supprimer ce message ?\'')){ 
	sendData('msgid='+p_idmsg,'ajax/messagerie/deletemessage.php5','POST','contentbodyacc');
}
}
function ecrire_a(p_iduser){
repondre_a(p_iduser,0);
}
function repondre_a(p_iduser,p_idmsg){
sendData('logexp=' + p_iduser + '&idm='+p_idmsg,'ajax/messagerie/writemessage.php5','POST','contentbodyacc');
}
function chkmsg(p_idmsg){
return true;
}
function sndmsg(p_idmsg){
aboexp = trim(document.getElementById("r45ml").value);
objet = trim(document.getElementById("r45ob").value);
message = trim(document.getElementById("comment").value);


sendData('r45ml=' + aboexp + '&r45ob=' + objet + '&comment=' + message + '&submit=1','ajax/messagerie/writemessage.php5','POST','contentbodyacc');
}
function addBookmark(title,url) {

if ( document.all ) {

window.external.AddFavorite( url, title);
} else if (window.sidebar) { 

window.sidebar.addPanel(title, url,""); 


} else if( window.opera && window.print ) {

return true;

}
}