var waitmessage = '';
var PageColor1 = '';
var PageColor2 = '';
var PageColor3 = '';
var PageId = '';
var RDVAgeId = '';
var RDVOutilId = '';
var planningannuel_refresh = false;
var planningannuel_divday_left = -1;

window.onload = function loadform() {
	if (document.getElementById('javascriptenabled')) {
			document.getElementById('javascriptenabled').value = '1';
	}
	
}
function putwaitmessage(mes) {
	waitmessage = mes;
}
function putpagecolor(c1,c2,c3){
}
function noenter() {
  return !(window.event && window.event.keyCode == 13); 
}

function button_over(buttonid) {
	document.getElementById(buttonid).style.backgroundPosition = '0px -30px';
}
function button_out(buttonid) {
	document.getElementById(buttonid).style.backgroundPosition = '0px 0px';
}
function displayagendacalendar(outilid,FirstDayMonth,DateToDisplay,UserType,AgeId,PageId,RepId) {
	document.getElementById('divcalendar').innerHTML = ajax('ajax.php?outilid=' + outilid + '&action=displayagendacalendar&FirstDayMonth=' + FirstDayMonth + '&DateToDisplay=' + DateToDisplay + '&UserType=' + UserType + '&AgeId=' + AgeId + '&PageId=' + PageId + '&RepId=' + RepId );	
}
function displayfreerdvcalendar(outilid,FirstDayMonth,DateToDisplay,UserType,AgeId,PageId,RepId) {
	document.getElementById('divcalendar').innerHTML = ajax('ajax.php?outilid=' + outilid + '&action=displayfreerdvcalendar&FirstDayMonth=' + FirstDayMonth + '&DateToDisplay=' + DateToDisplay + '&UserType=' + UserType + '&AgeId=' + AgeId + '&PageId=' + PageId + '&RepId=' + RepId );	
}
function quickentrycalendar(outilid,FirstDayMonth,DateToDisplay,UserType,AgeId,PageId,RepId) {
	document.getElementById('divcalendar').innerHTML = ajax('ajax.php?outilid=' + outilid + '&action=quickentrycalendar&FirstDayMonth=' + FirstDayMonth + '&DateToDisplay=' + DateToDisplay + '&UserType=' + UserType + '&AgeId=' + AgeId + '&PageId=' + PageId + '&RepId=' + RepId );	
}
function hideshowadressedetail(RDVId,labelVoir,labelCacher) {
	if (document.getElementById('detail' + RDVId).className == 'agenda_useradresse_show') {
		document.getElementById('detail' + RDVId).className = 'agenda_useradresse_hide';
		document.getElementById('detaillink' + RDVId).innerHTML = labelVoir;
	} else {
		document.getElementById('detail' + RDVId).className = 'agenda_useradresse_show';
		document.getElementById('detaillink' + RDVId).innerHTML = labelCacher;
	}
}
function hideshowrdvdetail(RDVId,labelVoir,labelCacher) {
	if (document.getElementById('rdv' + RDVId).className == 'agendalieushow') {
		document.getElementById('rdv' + RDVId).className = 'agendalieuhide';
		document.getElementById('rdvlink' + RDVId).innerHTML = labelVoir;
	} else {
		document.getElementById('rdv' + RDVId).className = 'agendalieushow';
		document.getElementById('rdvlink' + RDVId).innerHTML = labelCacher;
	}
}

function displayagenda_chkrefresh() {
	
	document.forms[0].submit();
}	

function quickentry_displaywait(nomelement) {
	if (document.getElementById('td' + nomelement)) {
		document.getElementById('td' + nomelement).innerHTML = waitmessage;
	} else if (document.getElementById( nomelement)) {
		document.getElementById(nomelement).innerHTML = waitmessage;
	}
}
function quickentry_displayform(outilid,AgeId,HTId,RDVDate,td,PageId){
	ajax_async('ajax.php?outilid=' + outilid + '&action=quickentry_displayform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&td=' + td + '&PageId=' + PageId, 'quickentry_displayform_ajax(' + outilid + ',xhr,' + HTId + ',\'' + td + '\'' + ',\'' + PageId + '\');', 'quickentry_displaywait(\'' + td + '\');');
}
function quickentry_displayform_ajax(outilid,xhr,HTId,td,PageId){
    if (xhr.readyState==4) { 
		quickentry_catchall(outilid);
		if (xhr.responseText != '') {
			document.getElementById(td).innerHTML = xhr.responseText;
			if (document.getElementById('txtUserNom' + HTId)) {
				document.getElementById('txtUserNom' + HTId).focus();
				setTimeout(function(){document.getElementById('txtUserNom' + HTId).focus();},0);
			}
		} else {
			quickentry_catchall(outilid);
		}
		
	}	
}

function charcode_keypress(e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }
    return charCode;
}
function quickentry_txtusernom_keypress(outilid,inField, e, AgeId,HTId, RDVDate,td) {
    if(charcode_keypress(e) == 13) {
        quickentry_sendform(outilid,AgeId,HTId,RDVDate,td);
        return false;
    } else {
    	return true;
    }
}
function planningannuel_txtusernom_keypress(outilid,inField, e, AgeId,HTId, RDVDate,td) {
    if(charcode_keypress(e) == 13) {
        planningannuel_sendform(outilid,AgeId,HTId,RDVDate,td);
        return false;
    } else {
    	return true;
    }
}


function quickentry_sendform(outilid,AgeId,HTId,RDVDate,td) {
	url = 'ajax.php?outilid=' + outilid + '&action=quickentry_sendform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&UserNom=' + document.getElementById('txtUserNom' + HTId).value.replace('&','') + '&UserType=' + document.getElementById('cboUserType' + HTId).value + '&RDVTRDVId=' + document.getElementById('cboTRDVTRDVId' + HTId).value + '&td=' + td;
	ajax_async(url,'quickentry_sendform_ajax(' + outilid + ',xhr,' + HTId + ',\'' + td + '\');', 'quickentry_displaywait(\'' + td + '\');'); 	
}
function quickentry_sendform_ajax(outilid,xhr,HTId,td){
    if (xhr.readyState==4) { 
		document.getElementById(td).innerHTML = xhr.responseText;
		quickentry_catchall(outilid);
	}	
}
function planningannuel_sendform(outilid,AgeId,HTId,RDVDate) {
    planningannuel_refresh = true;
	url = 'ajax.php?outilid=' + outilid + '&action=planningannuel_sendform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&UserNom=' + document.getElementById('txtUserNom' + HTId).value.replace('&','') + '&UserType=' + document.getElementById('cboUserType' + HTId).value + '&RDVTRDVId=' + document.getElementById('cboTRDVTRDVId' + HTId).value;
	ajax_async(url,'planningannuel_sendform_ajax(' + outilid + ',xhr,' + HTId + ',' + AgeId + ',' + RDVDate + ');', 'planningannuel_displaywait();'); 	
}
function planningannuel_sendform_ajax(outilid,xhr,HTId,AgeId,RDVDate){
    if (xhr.readyState==4) {
	    planningannuel_refresh = true;
		content = ajax('ajax.php?outilid=' + outilid + '&action=planningannuel_displayday&PageId=' + PageId + '&AgeId=' + AgeId + '&DateToDisplay=' + RDVDate + '&PageColor1=' + PageColor1 + '&PageColor2=' + PageColor2 + '&PageColor3=' + PageColor3);
		document.getElementById('planningannuel_divdayleft').innerHTML = content;
	}	
}
function quickentry_cancelform(outilid,AgeId,HTId,RDVDate,td) {
	url = 'ajax.php?outilid=' + outilid + '&action=quickentry_cancelform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&td=' + td;
	ajax_async(url,'quickentry_cancelform_ajax(' + outilid + ',xhr,' + HTId + ',\'' + td + '\');', 'quickentry_displaywait(\'' + td + '\');'); 	
}
function quickentry_cancelform_ajax(outilid,xhr,HTId,td){
    if (xhr.readyState==4) { 
		document.getElementById(td).innerHTML = xhr.responseText;
		quickentry_catchall(outilid);
	}	
}
function planningannuel_cancelform(outilid,AgeId,HTId,RDVDate,td) {
	url = 'ajax.php?outilid=' + outilid + '&action=planningannuel_cancelform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&td=' + td;
	ajax_async(url,'planningannuel_cancelform_ajax(' + outilid + ',xhr,' + AgeId + ',' + RDVDate + ',' + HTId + ');', 'planningannuel_displaywait();'); 	
}
function planningannuel_cancelform_ajax(outilid,xhr,AgeId,RDVDate,HTId){
    if (xhr.readyState==4) { 
	    planningannuel_refresh = true;
		content = ajax('ajax.php?outilid=' + outilid + '&action=planningannuel_displayday&PageId=' + PageId + '&AgeId=' + AgeId + '&DateToDisplay=' + RDVDate + '&PageColor1=' + PageColor1 + '&PageColor2=' + PageColor2 + '&PageColor3=' + PageColor3);
		document.getElementById('planningannuel_divdayleft').innerHTML = content;
	}	
}
function quickentry_catchall(outilid) {
	var AgeId = document.getElementById('txtAgeId').value;
	var RDVDate = document.getElementById('txtDateToDisplay').value;
	var xml = ajax_xml('ajax.php?outilid=' + outilid + '&action=quickentry_catchall&AgeId=' + AgeId + '&DateToDisplay=' + RDVDate + '&PageId=' + PageId);

	var table = document.getElementById('agendaM');
	var tbody = table.getElementsByTagName('tbody');

	var root = xml.getElementsByTagName('root').item(0);
	var numrow = 1;
	if (root != null) {
	for (i=0;i < root.childNodes.length;i++) {
		rdv = root.childNodes[i];
		if (i<2) {
			//alert(table.rows[numrow].id + ' ' + rdv.getAttribute('key'));
		}
		
		while (table.rows[numrow] && table.rows[numrow].id < rdv.getAttribute('key')) {
			//alert('Delete ' + table.rows[numrow].id);
			table.deleteRow(numrow);
		}
		while (!table.rows[numrow] || table.rows[numrow].id > rdv.getAttribute('key')) {
			//alert (numrow + ' ' + table.rows[numrow].id + ' ' + rdv.getAttribute('key'));
			row = table.insertRow(numrow);
			row.id = rdv.getAttribute('key'); 
			for(td=0;td < rdv.childNodes.length;td++){
				rdv_td = rdv.childNodes[td];
				var insertid = true;
				if (rdv_td.nodeName != 'id') {
					cell = document.createElement('td');
					cell.id = rdv_td.nodeName +  rdv.getAttribute('key');
					row.appendChild(cell);
					if (insertid) document.getElementById(rdv_td.nodeName +  rdv.getAttribute('key')).innerHTML = '<input type="hidden" name="id' + rdv.getAttribute('key') + '" value="">';
					insertid = false;
				}
			}
		}
		numrow++;
	}
	
	while (table.rows[numrow]) {
		//alert('Delete ' + table.rows[numrow].id);
		table.deleteRow(numrow);
		numrow++;
	}
	
	
	
	for (i=0;i < root.childNodes.length;i++) {
	    idnotthesame = false;
		rdv = root.childNodes[i];
		for(td=0;td < rdv.childNodes.length;td++){
			rdv_td = rdv.childNodes[td];
				
			//document.getElementById(rdv_td.nodeName + rdv.getAttribute('key'))) {
			for(typ=0;typ < rdv_td.childNodes.length;typ++){
				rdv_typ = rdv_td.childNodes[typ];
				content = rdv_typ.firstChild.nodeValue
				content = content.replace('[PageColor1]', PageColor1);
				content = content.replace('[PageColor2]', PageColor2);
				content = content.replace('[PageColor3]', PageColor3);
				content = content.replace('[PageId]', PageId);
				if (rdv_td.nodeName == 'id' && document.getElementById('id' + rdv.getAttribute('key')).value != content) {
					//alert(document.getElementById('id' + rdv.getAttribute('key')).value);
					idnotthesame = true;
				}
				if (rdv_typ.nodeName == 'class' && (rdv_td.nodeName != 'td' || (rdv_td.nodeName == 'td' && idnotthesame))) {
					 document.getElementById(rdv_td.nodeName + rdv.getAttribute('key')).className = content;
				}
				if (rdv_typ.nodeName == 'content' && (rdv_td.nodeName != 'td' || (rdv_td.nodeName == 'td' && idnotthesame))) {
					document.getElementById(rdv_td.nodeName + rdv.getAttribute('key')).innerHTML = content;
				}
			}
			
		}
	}	
	}
	
	
}


function quickentry_timer(outilid) {
	quickentry_catchall(outilid	);
	//test_xml(outilid);
	t=setTimeout('quickentry_timer(' + outilid + ')',60000);
}

function getInnerHTML(NbreLang) {
  var l;
  for (l=1;l<=NbreLang;l++) {
    //document.getElementById('txtEditeur' + l).value = window.frames[l-1].document.getElementById('elm1').innerHTML;
    document.getElementById('txtEditeur' + l).value = window.frames[l-1].tinyMCE.get('elm1').getContent();
  }
}

function ajax_xml(url)
{
  var ajax_auth_id = ajax('ajax_auth_id.php');
  
  if (window.XMLHttpRequest) {
    objXHR = new XMLHttpRequest();
  } else {
    if (window.ActiveXObject) { 
      objXHR = new ActiveXObject("Microsoft.XMLHTTP");
    } else { 
      return false; 
    }
  }
  objXHR.open("GET",url  + '&ajax_auth_id=' + ajax_auth_id,false);
  objXHR.send(null);
  
  if (objXHR.readyState == 4) {
  		if (objXHR.readyState==4) {
   			if (objXHR.responseText != 'Unauthorized access') {
	    		return objXHR.responseXML;
    		} else {
    			document.location = '404.php';
    		}
    	} 
  } else {
    return false;
  }
}

function ajax_async_new(url,function_return,function_wait)
{
    var ajax_auth_id = ajax('ajax_auth_id.php');
    var xhr=null;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() {
    	if (xhr.readyState==4) { 
   			if (xhr.responseText != 'Unauthorized access') {
	    		eval(function_return);
    		} else {
    			document.location = '404.php';
    		}
    	} 
 	};

    
    //on affiche le message d'acceuil
    if (function_wait != '') eval(function_wait);
    
    //on appelle le fichier reponse.txt
    xhr.open("GET", url  + '&ajax_auth_id=' + ajax_auth_id, true);
    xhr.send(null);
}
function vbm_label(e,label) {
	mousex(e)
	document.getElementById('viewbymonth_p_rdv').innerHTML = label;
		
	document.getElementById('viewbymonth_p_rdv').style.top = mousey(e) + document.body.scrollTop ;
	document.getElementById('viewbymonth_p_rdv').style.left = mousex(e) + document.body.scrollLeft + 20;
	
	
	if (getXYpos(document.getElementById('viewbymonth_p_rdv')).y + getHeight(document.getElementById('viewbymonth_p_rdv')) > getXYpos(document.getElementById('viewbymonth')).y + getHeight(document.getElementById('viewbymonth'))) {
		document.getElementById('viewbymonth_p_rdv').style.top = window.event.clientY + document.body.scrollTop - getHeight(document.getElementById('viewbymonth_p_rdv'));
	} else {
		document.getElementById('viewbymonth_p_rdv').style.top = window.event.clientY + document.body.scrollTop ;
	}

	if (getXYpos(document.getElementById('viewbymonth_p_rdv')).x + getWidth(document.getElementById('viewbymonth_p_rdv')) > getXYpos(document.getElementById('viewbymonth')).x + getWidth(document.getElementById('viewbymonth'))) {
		document.getElementById('viewbymonth_p_rdv').style.left = window.event.clientX + document.body.scrollLeft - 20 - getWidth(document.getElementById('viewbymonth_p_rdv'));
	} else {
		document.getElementById('viewbymonth_p_rdv').style.left = window.event.clientX + document.body.scrollLeft + 20;
	}
	 
}



function mousex(e){

 if(document.layers) {return e.x;}
 else {return e.clientX;}
 }

 function mousey(e){
 if(document.layers) {return e.y;}
 else {return e.clientY;}
 } 

function getXYpos(elem) {
   if (!elem) {
      return {"x":0,"y":0};
   }
   var xy={"x":elem.offsetLeft,"y":elem.offsetTop}
   var par=getXYpos(elem.offsetParent);
   for (var key in par) {
      
      xy[key]+=par[key];
   }
   return xy;
}


function getHeight(elem) {
	if (elem.offsetHeight) {
		return elem.offsetHeight;
	} else if (elem.style.pixelHeight) {
		return elem.style.pixelHeight;
	}
}
function getWidth(elem) {
	if (elem.offsetWidth) {
		return elem.offsetWidth;
	} else if (elem.style.pixelWidth) {
		return elem.style.pixelWidth;
	}
}
function test_xml(outilid) {

	url = 'ajax.php?outilid=' + outilid + '&action=test_xml';
	ajax_async(url,'test_xml_ajax(' + outilid + ',xhr);', ''); 	
}
function test_xml_ajax(outilid,xhr){
    if (xhr.readyState==4) { 
		var xml = xhr.responseXML;
		alert(xml)
		var rdvdetail = xml.getElementsByTagName('root').item(0);
		alert(rdvdetail.getAttribute('id'));
		for (i=0;i<rdvdetail.childNodes.length;i++) {
			alert(rdvdetail.childNodes[i].nodeName + ' ' + rdvdetail.childNodes[i].firstChild.nodeValue);
		}
	}	
}
function planningannuel_display(outilid,AgeId) {
	RDVOutilId = outilid;
	RDVAgeId = AgeId;
	blanket_size('popup');
	window_pos('popup');
	toggle('popup_bg');
	toggle('popup');
	document.getElementById('planningannuel_div').innerHTML = ajax('ajax.php?outilid=' + RDVOutilId + '&action=planningannuel_display&AgeId=' + RDVAgeId);
	//document.getElementById('planningannuel_div').style.margin='0px 0px 0px 203px';
}

function planningannuel_hide(){
	toggle('popup_bg');
	toggle('popup');
}

function planningannuel_displayday(outilid,AgeId,DateToDisplay,row,col) {
	var top = 104 + (row-1) * 30;
	var left = planningannuel_divday_left + 4 + (col-1) * 26;
	document.getElementById('popup_bg').style.zIndex =  1003;
	document.getElementById('planningannuel_divdayleft').style.top =  top + 'px';
	document.getElementById('planningannuel_divdayleft').style.left = left + 'px';
	document.getElementById('planningannuel_divdayleft').style.height = '270px';
	toggle('planningannuel_divdayleft');
	content = ajax('ajax.php?outilid=' + outilid + '&action=planningannuel_displayday&PageId=' + PageId + '&AgeId=' + AgeId + '&DateToDisplay=' + DateToDisplay + '&PageColor1=' + PageColor1 + '&PageColor2=' + PageColor2 + '&PageColor3=' + PageColor3);
	document.getElementById('planningannuel_divdayleft').innerHTML = content;
}

function planningannuel_hideday() {
	if (planningannuel_refresh) setTimeout(function(){planningannuel_refresh=false;document.getElementById('planningannuel_div').innerHTML = ajax('ajax.php?outilid=' + RDVOutilId + '&action=planningannuel_display&AgeId=' + RDVAgeId);},0);
	document.getElementById('popup_bg').style.zIndex =  1001;
	toggle('planningannuel_divdayleft');
}
function planningannuel_displaywait() {
	document.getElementById("planningannuel_allrdv").innerHTML = waitmessage;
}
function planningannuel_displayform(outilid,AgeId,HTId,RDVDate,PageId){
	ajax_async('ajax.php?outilid=' + outilid + '&action=planningannuel_displayform&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate + '&PageId=' + PageId, 'planningannuel_displayform_ajax(' + outilid + ',xhr,' + HTId + ',\'' + PageId + '\');', 'planningannuel_displaywait();');
}
function planningannuel_displayform_ajax(outilid,xhr,HTId,PageId){
    if (xhr.readyState==4) {
    		content = xhr.responseText.replace('[PageColor1]', PageColor1);
			content = content.replace('[PageColor2]', PageColor2);
			content = content.replace('[PageColor3]', PageColor3);
     
			document.getElementById("planningannuel_allrdv").innerHTML = content;
			if (document.getElementById('txtUserNom' + HTId)) {
				document.getElementById('txtUserNom' + HTId).focus();
				setTimeout(function(){document.getElementById('txtUserNom' + HTId).focus();},0);
			}
	
	}	
}
function planningannuel_refreshday_ajax(outilid,xhr,AgeId,RDVDate) {
    if (xhr.readyState==4) {
		content = ajax('ajax.php?outilid=' + outilid + '&action=planningannuel_displayday&PageId=' + PageId + '&AgeId=' + AgeId + '&DateToDisplay=' + RDVDate + '&PageColor1=' + PageColor1 + '&PageColor2=' + PageColor2 + '&PageColor3=' + PageColor3);
		document.getElementById('planningannuel_divdayleft').innerHTML = content;
    }
}
function planningannuel_cancelplage(outilid,AgeId,HTId,RDVDate) {
    planningannuel_refresh = true;
	ajax_async('ajax.php?outilid=' + outilid + '&action=planningannuel_cancelplage&AgeId=' + AgeId + '&HTId=' + HTId + '&RDVDate=' + RDVDate, 'planningannuel_refreshday_ajax(' + outilid + ',xhr,' + AgeId + ',' + RDVDate + ');', 'planningannuel_displaywait();');
}
function planningannuel_cancelrdv(outilid,AgeId,RDVId,RDVDate) {
 
	if (confirm(ajax('ajax.php?outilid=' + outilid + '&action=planningannuel_cancelrdv_message'))) {
	    planningannuel_refresh = true;
		ajax_async('ajax.php?outilid=' + outilid + '&action=planningannuel_cancelrdv&AgeId=' + AgeId + '&RDVId=' + RDVId , 'planningannuel_refreshday_ajax(' + outilid + ',xhr,' + AgeId + ',' + RDVDate + ');', 'planningannuel_displaywait();');		
	}
}
function planningannuel_undoplage(outilid,AgeId,RDVId,RDVDate) {
    planningannuel_refresh = true;
	ajax_async('ajax.php?outilid=' + outilid + '&action=planningannuel_undoplage&AgeId=' + AgeId + '&RDVId=' + RDVId , 'planningannuel_refreshday_ajax(' + outilid + ',xhr,' + AgeId + ',' + RDVDate + ');', 'planningannuel_displaywait();');
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display != 'block' ) {el.style.display = 'block';}
	else {el.style.display = 'none';}
}

function blanket_size(popUpDivVar) {

	if (typeof window.innerHeight != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.scrollHeight;
		}
	}
	var blanket = document.getElementById('popup_bg');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = '100px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-500;//500 is half popup's width
	popUpDiv.style.left = window_width + 'px';
	if (planningannuel_divday_left == -1) planningannuel_divday_left = window_width;
}
function popup_bg_click() {
	if (document.getElementById('popup_bg').style.zIndex ==  1001) {
		planningannuel_hide();
	} else {
		planningannuel_hideday();
	}
}
function displayagenda_changeagenda(url) {
	document.location=url;
}
function planningannuel_changeagenda(AgeId) {
	document.getElementById('planningannuel_div').innerHTML = waitmessage; 
	setTimeout(function(){document.getElementById('planningannuel_div').innerHTML = ajax('ajax.php?outilid=' + RDVOutilId + '&action=planningannuel_display&AgeId=' + AgeId)},0);
}
function mrdv_validemail(rdvoutilid,userid) {
	var p = document.getElementById('pUserId' + userid);
	p.innerHTML = 'Connection au serveur ...';
	ajax_async('ajax.php?outilid=' + rdvoutilid + '&action=mrdv_validemail&userid=' + userid + '&useremail=' + document.getElementById('txtUserId' + userid).value,'mrdv_validemail_ajax(xhr,\'pUserId' + userid + '\')','') ;	

}
function mrdv_validemail_ajax(xhr,p){
    if (xhr.readyState==4) {
		document.getElementById(p).innerHTML = xhr.responseText;
	}
}
function messages_timer(outilid) {
	c = ajax('ajax.php?outilid=' + outilid + '&action=cache_count_messages');
	if (c == 0) {
		document.getElementById('messagesnew').style.display = 'none';
	} else {
		document.getElementById('messagesnew').style.display = 'inline';
		document.getElementById('messagesnew').innerHTML = c;
	}
	t=setTimeout('messages_timer(' + outilid + ')',6000);
}
function sviusernom_displayhideform(rdvid) {
	if (document.getElementById('sviusernom_divchange_' + rdvid).style.display == 'none') {
		document.getElementById('sviusernom_text_' + rdvid).style.display = 'none';
		document.getElementById('sviusernom_divchange_' + rdvid).style.display = 'block';
		document.getElementById('sviusernom_input_' + rdvid).focus(); 
	} else {
		document.getElementById('sviusernom_text_' + rdvid).style.display = 'block';
		document.getElementById('sviusernom_divchange_' + rdvid).style.display = 'none'; 
	}
}
function sviusernom_keypress(outilid,e,ageid,rdvid) {
    if(charcode_keypress(e) == 13) {
        sviusernom_sendform(outilid,ageid,rdvid);
        return false;
    } else {
    	return true;
    }
}
function sviusernom_sendform(outilid,ageid,rdvid) {
	ajax_async('ajax.php?outilid=' + outilid + '&action=sviusernom_sendform&AgeId=' + ageid + '&RDVId=' + rdvid + '&UserNom=' + document.getElementById('sviusernom_input_' + rdvid).value.replace('&','') , 'sviusernom_sendform_ajax(' + outilid + ',xhr,' + rdvid + ');','');
}
function sviusernom_sendform_ajax(outilid,xhr,rdvid){
    if (xhr.readyState==4) {
    	//var str = location + '';
    	//if (str.search('displayrdv')!=-1) {
    	//	alert (str.search('displayrdv'));
    		document.getElementById('sviusernom_divchange_' + rdvid).innerHTML = '';
    		location.reload(true);
    	//} else {
    	//	document.getElementById('sviusernom_divchange_' + rdvid).innerHTML = '';
    	//	quickentry_catchall(outilid);
    	//}
		
	}	
}
