function action(this_, id, lastAction, nodeId, action, img) {
	var direction = document.getElementById('vent' + id).value;
	if(lastAction == 0 || lastAction == 51)	{
		//alert('init');
		direction = 0;
		document.getElementById('vent' + id).value = 0;
		document.getElementById('upVent_' + id).innerHTML = '00:00:00';
	}
	document.getElementById('input_' + id).value = lastAction + '|' + direction;
	var idTmp = document.getElementById('oldId' + id).innerHTML;
	var url = document.getElementById('im_' + id + idTmp).src;
	var urlRem = url.replace("/on/", "/off/");	
	document.getElementById('im_' + id + idTmp).src = urlRem;
	document.getElementById('oldId' + id).innerHTML = lastAction;
	this_.src = "/design/base/images/boutons/on" + img;
	var options = { 
		beforeSubmit:  beforeVal,
		success:       function() { 
        	//alert("ok");
			var node = "id=" + nodeId;
			$.ajax({
						type: "POST",
						url: "/clear-cache.php",
						data: node
					});
			surveyAdm(id);		
		} 
	};
	$('#formPost_' + id).ajaxSubmit(options);
}

function setVent(vent, id, date) {
	//alert(document.getElementById('vent' + id).value + ' - ' + id + ' - ' +  action);
	var direction = document.getElementById('vent' + id).value;
	var idTmp = document.getElementById('oldId' + id).innerHTML;
	//document.getElementById('upVent_' + id).innerHTML = date;
	document.getElementById('input_' + id).value = idTmp + '|' + direction;
	var options = { 
		beforeSubmit:  function() { 
							surveyAdmVent(id)	
						},
		success:       afterVal
	};
	$('#formPost_' + id).ajaxSubmit(options);
}

function beforeVal(formData, jqForm, options) {
	//alert("preload");
	var queryString = $.param(formData); 
	return true;	
}
 
function afterVal(responseText, statusText, xhr, $form) {
	//$.get("/time.php?id=10");
	//location.reload(true);
}


function selectDatePro(date, url) {
	window.location.href= url + '/(date)/' + date; 
}

function selectCoursePro(course, url, date) {
	window.location.href= url + '/(date)/' + date + '/(course)/' + course; 
}

function surveyAdm(id)
{
	 $.ajax({
         type: "POST",
         url: "",
         data: "",
         success: function(msg){
								//MàJ viewInfo
								tag = 'id="viewInfo_' + id + '">';
								tagLength = tag.length;
								extract = msg;
								msgM  = extract.substring(extract.search(tag), extract.length);
								endDiv = msgM.search('</div >');
								msgM  = jQuery.trim(msgM.substring(tagLength, endDiv));
								var setReel = '';
								if (document.getElementById('clockReel_' + id)) {
									if (document.getElementById('oldId' + id).innerHTML == 51) {
										//alert('ini');
										var clockReel = document.getElementById('clockReel_' + id).innerHTML;
										setReel = 'OK';
									}
								}
								document.getElementById('viewInfo_' + id).innerHTML = msgM;
								if (document.getElementById('clockReel_' + id)) {
									if (setReel == 'OK')
										document.getElementById('clockReel_' + id).innerHTML = clockReel;
								}
                			}
 		})
}

function surveyAdmVent(id) {
	 $.ajax({
         type: "POST",
         url: "",
         data: "",
         success: function(msg){
								//MàJ viewInfo
								tag = 'id="upVent_' + id + '">';
								tagLength = tag.length;
								extract = msg;
								msgM  = extract.substring(extract.search(tag), extract.length);
								endDiv = msgM.search('</span >');
								msgM  = jQuery.trim(msgM.substring(tagLength, endDiv));
								document.getElementById('upVent_' + id).innerHTML = msgM;
                			}
 		})
}

function survey(id) {
	 $.ajax({
         type: "POST",
         url: "",
         data: "",
         success: function(msg){
								//alert('start');
								var tag = 'id="lastAction_' + id + '">';
								var tagLength = tag.length;
								var extract = msg;
								var msgM  = extract.substring(extract.search(tag), extract.length);
								var endDiv = msgM.search('</div>');
								msgM  = jQuery.trim(msgM.substring(tagLength, endDiv));
								var idCurrent = msgM;
								if(jQuery.trim($('#lastAction_' + id).html()) == msgM) {
									//alert('No !');
								} else {
									// MàJ viewStatut
									tag = 'id="viewStatut_' + id + '">';
									tagLength = tag.length;
									extract = msg;
									msgM  = extract.substring(extract.search(tag), extract.length);
									endDiv = msgM.search('</div >');
									msgM  = jQuery.trim(msgM.substring(tagLength, endDiv));
									document.getElementById('viewStatut_' + id).innerHTML = msgM;
									//MàJ viewInfo
									tag = 'id="viewInfo_' + id + '">';
									tagLength = tag.length;
									extract = msg;
									msgM  = extract.substring(extract.search(tag), extract.length);
									endDiv = msgM.search('</div >');
									msgM  = jQuery.trim(msgM.substring(tagLength, endDiv));
									document.getElementById('viewInfo_' + id).innerHTML = msgM;
								}
                			}
 		})
}

/*
function decompte()
{
	var myDate = new Date();	
	var time = myDate.getTime(); 
	document.getElementById('decompte_1').innerHTML = myDate;
	timer = setTimeout("decompte()",2000);
}
*/


$(function($) {
      $('.jclock').jclock();
});
