// Cookies
function clearCookie(cookieName) {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	document.setCookie(cookieName, '', yesterday);
}
 
function setCookie(cookieName, cookieValue, nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays == null || nDays == 0) nDays = 1;
	expire.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}
 
function getCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) {
			cookieValue = unescape(document.cookie.substring(posValue, endPos));
		} else {
			cookieValue = unescape(document.cookie.substring(posValue));
		}
	}
	return cookieValue;
}
 
/*
function getResolution() {
	var oldwidth = getCookie('screen_width');
	var oldheight = getCookie('screen_height');
	if (window.innerWidth) {
		var width = window.innerWidth;
		var height = window.innerHeight + 32;
	} else {
		var width = document.body.offsetWidth;
		var height = document.body.offsetHeight;
	}
	//alert(height);
	//alert('enregistrement cookie : width => '+width+'; height => '+height+'; oldwidth => '+oldwidth+'; oldheight => '+oldheight);
	width = (width >= 1024?width:1024);
	setCookie('screen_width', width, 30);
	setCookie('screen_height', height, 30);
	if (oldheight && oldwidth) {
		if ((Math.abs(oldheight - height) > 10) || (Math.abs(oldwidth - width) > 30)) {
			if (document.location.href.indexOf('login.php') == -1) {
				document.location.href = document.location.href;
			}
		}
	} else {
		if (document.location.href.indexOf('login.php') == -1) {
			document.location.href = document.location.href;
		}
	}
	 
}
 /**/
// Ajax (basique)
var xmlDoc = new Object();
function populate(obj, dest) {
	if (typeof window.ActiveXObject != 'undefined' ) {
		xmlDoc[dest] = new ActiveXObject("Microsoft.XMLHTTP");
		xmlDoc[dest].onreadystatechange = function() {_populate(dest);};
	} else {
		xmlDoc[dest] = new XMLHttpRequest();
		xmlDoc[dest].onload = function() {_populate(dest);};
	}
	xmlDoc[dest].open("GET", '/index_remote.php?remote=' + dest.toLowerCase() + '&id=' + obj.value, true );
	xmlDoc[dest].send(null);
}
 
function _populate(dest) {
	if (xmlDoc[dest].readyState == 4) {
		// only if "OK"
		if (xmlDoc[dest].status == 200) {
			var result = xmlDoc[dest].responseText;
			document.getElementById(dest).outerHTML = result;
		} else {
			alert("There was a problem retrieving the data:\n" + xmlDoc[dest].statusText);
		}
	}
}
 
function changeEncadre(obj, input1, input2) {
	
	if (!obj.value) {		
		document.getElementById(input1).value = "";
		document.getElementById(input2).value = "";
		var iframeText = eval("window.document.iframeText" + input2);
		iframeText.document.clear();
		iframeText.document.open();
		iframeText.document.write("");
		iframeText.document.close();
	}
}
function MaJEncadre(val,champ) {
	if(val && isNaN(val) == false){
		if(document.getElementById(champ).value == ''){
			document.getElementById(champ).value = TableauJs[val];
		}
	}
}	
