function chronologieDate(date1, champ1, date2, champ2) {
	var d1 = new Date(date1.value.substring(6,10), date1.value.substring(3,5) - 1, date1.value.substring(0,2));
	var d2 = new Date(date2.value.substring(6,10), date2.value.substring(3,5) - 1, date2.value.substring(0,2));
	if (d1>d2) {
		alert("Le champ '" + champ1 + "' est superieur au champ '" + champ2 + "'.");
		date2.focus();
		return false;	
	}
	return true;
}
/////
function setNow(obj) {
	var date = new Date();
	obj.value = (date.getDate() < 10) ? '0' + date.getDate() : date.getDate();
	var month = date.getMonth() + 1;
	obj.value += (month < 10) ? '/0' + month: '/' + month;
	var year = date.getYear() % 100;
	obj.value += '/200' + year;//marche jusqu'en 2009  ;-)
}
/////
function setLater(obj) {
	obj.value = '31/12/2035';
}
/////
var isFilterShown;
function showFilter(show) {
	var val = (show) ? 'block' : 'none'
	document.getElementById('filtre').style.display = val;
	if (document.getElementById('filtreInit')) document.getElementById('filtreInit').style.display = val;
	isFilterShown = show;
}
/////
function replaceString(oldS, newS, fullS) {
	for (var i=0; i < fullS.length; i++) {
		if (fullS.substring(i, i+oldS.length) == oldS) {
			fullS = fullS.substring(0,i) + newS + fullS.substring(i+oldS.length, fullS.length);
		}
	}
	return fullS;
}
/////
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/////
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}


/********************/
/*  DEPLACE CRITERE */
/********************/
function DeplaceCritere(elFromSelect, elToSelect) {
	function _fixe_msieIndexOption(elOption) {
		var optionIndex, oNode;
		optionIndex=0;
		if (elOption.parentNode.nodeName.toLowerCase()=='optgroup') {
			oNode = elOption.previousSibling;
			while (oNode && (oNode.nodeName.toLowerCase()!="option")) {
					oNode = oNode.previousSibling;
			}
			if (!oNode) {
				oNode = elOption.parentNode.previousSibling;
			}
		} else {
			oNode = elOption.previousSibling;
		}
		while (oNode) {
			if ( (oNode.nodeName.toLowerCase()!='optgroup')
						&& (oNode.nodeName.toLowerCase()!='option') )
			{
				oNode = oNode.previousSibling;
				continue;
			}
			if (oNode.nodeName.toLowerCase()=='option') {
				optionIndex = oNode.index+1;
				break;
			} else {
				oNode = oNode.lastChild;
				while (oNode) {
					if (oNode.nodeName.toLowerCase()=='option') {
						optionIndex = oNode.index+1;
						break;
					}
					oNode = oNode.previousSibling;
				}
				break;
			}
		}
		return optionIndex;
	}
	var fromIndex, toIndex, elOption, nToParent, nFromParent, oNode;
	fromIndex = toIndex = 0;
	elOption = elFromSelect.options[0];
	fromOptions :
	while (elOption) {
		if (!elOption.selected) {
			elOption = elFromSelect.options[elOption.index+1];
			continue;
		}
		nToParent = elToSelect;
		nFromParent = elOption.parentNode;
		oNode = elToSelect.options[toIndex];
		if (nFromParent.nodeName.toLowerCase()=='optgroup') {
			nToParent = cloneOptgroup(nFromParent, elToSelect,elToSelect.options[toIndex]);
			if (oNode && !isChildNodeOf(oNode,nToParent)) {
				oNode = nToParent.firstChild;
			}
		} else {
			if ( oNode && (oNode.parentNode.nodeName.toLowerCase()=='optgroup') ) {
				oNode = oNode.parentNode;
			}
		}
		var compare;
		while (oNode) {
			if ( (oNode.nodeName.toLowerCase()!='optgroup')
						&& (oNode.nodeName.toLowerCase()!='option') )
			{
				oNode = oNode.nextSibling;
				continue;
			}
			compare=(oNode.nodeName.toLowerCase()=='option')?oNode.text:oNode.label;
			if (elOption.text <= compare) {
				fromIndex = elOption.index;
				nToParent.insertBefore(elOption, oNode);
				toIndex = elOption.index;
				if (toIndex > elToSelect.options.length) {
					toIndex = _fixe_msieIndexOption(elOption);
				}
				elOption = elFromSelect.options[fromIndex];
				continue fromOptions;
			}
			oNode = oNode.nextSibling;
		}
		fromIndex = elOption.index;
		nToParent.appendChild(elOption);
		toIndex = elOption.index;
		if (toIndex > elToSelect.options.length) {
			toIndex = _fixe_msieIndexOption(elOption);
		}
		elOption = elFromSelect.options[fromIndex];
	}
	var cFromOptgroup = elFromSelect.getElementsByTagName('optgroup');
	var aFromOptgroupRemove = new Array();
	for (var k=0;cFromOptgroup[k]; k++) {
		if (cFromOptgroup[k].getElementsByTagName('option').length==0) {
			aFromOptgroupRemove.push(cFromOptgroup[k]);
		}
	}
	for (var l=0; aFromOptgroupRemove[l]; l++) {
		aFromOptgroupRemove[l].parentNode.removeChild(aFromOptgroupRemove[l]);
	}
}
function isChildNodeOf(oNode,other) {
	if (oNode.compareDocumentPosition) {
		return (oNode.compareDocumentPosition(other)==10);
	} else if (other.contains) {
		return other.contains(oNode);
	}
	var bIsChildNodeOf = false;
	function _isChildNodeOf(oNode,other) {
		while (other) {
			if (other==oNode) {
				bIsChildNodeOf = true;
				return;
			} else _isChildNodeOf(oNode,other.firstChild);
			other = other.nextSibling;
		}
	}
	_isChildNodeOf(oNode,other.firstChild);
	return bIsChildNodeOf;
}
function cloneOptgroup(elOptgroup, elSelect, elStart) {
	var oNode, compare, elNewOptgroup;
	if (elStart) {
		oNode = (elStart.parentNode.nodeName.toLowerCase()=='optgroup')?
								elStart.parentNode:elStart;
	} else {
		oNode = elSelect.firstChild;
	}
	while (oNode) {
		if ( (oNode.nodeName.toLowerCase()!='optgroup')
					&& (oNode.nodeName.toLowerCase()!='option') )
		{
			oNode = oNode.nextSibling;
			continue;
		}
		compare=(oNode.nodeName.toLowerCase()=='option')?oNode.text:oNode.label;
		if ( (elOptgroup.label == compare)
					&& (oNode.nodeName.toLowerCase()=='option') )
		{
			elNewOptgroup = oNode;
			break;
		} else if (elOptgroup.label < compare) {
			elNewOptgroup = elOptgroup.cloneNode(false);
			oNode.parentNode.insertBefore(elNewOptgroup,oNode);
			break;
		}
		oNode = oNode.nextSibling;
	}
	if (!elNewOptgroup) {
		elNewOptgroup = elOptgroup.cloneNode(false);
		elSelect.appendChild(elNewOptgroup);
	}
	return elNewOptgroup;
}



/**********/
/*  COVER */
/**********/
var popupCover = null;
var timeoutCover = null;
function ownWindowOpen(url, name, feature) {
	showCover();
	if (feature) {
		feature += ",resizable,scrollbars,modal=yes";
	} else {
		feature = "resizable,scrollbars,modal=yes";
	}
	if (!name) name = 'POPUP';
	popupCover = window.open(url, name, feature);
	timeoutCover = window.setInterval('intervalCover()', 500);
	return false;
}
function intervalCover() {
	if (!popupCover || popupCover.closed) {
		window.clearInterval(timeoutCover);
		hideCover();
	}
}
function showCover() {
	var oTemplatecover = document.getElementById("bo_cover");
	if (oTemplatecover) {
		oTemplatecover.style.display = "block";
		minHeight = window.innerHeight
		if (isNaN(minHeight)) minHeight = window.document.body.offsetHeight
		oHeight = document.getElementById('document').offsetHeight;
		if (minHeight > oHeight) oHeight = minHeight;
		oTemplatecover.style.height = oHeight + 'px';
	}
}
function hideCover() {
	var oTemplatecover = document.getElementById("bo_cover");
	if (oTemplatecover) oTemplatecover.style.display = "none";
}
/**
	SPECIFIQUE CG05
*/
function setAddFavorite() {
	if (navigator.appName.indexOf("Explorer") != -1) { 
		document.write("<a href=\"javascript:void(0)\" onclick=\"window.external.AddFavorite(location.href,document.title)\" onkeypress=\"window.external.AddFavorite(location.href,document.title)\">Ajouter aux favoris</a>");
	} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
		document.write("<a href=\"javascript:void(0)\" onclick=\"window.sidebar.addPanel(document.title, location.href, '')\" onkeypress=\"window.sidebar.addPanel(document.title, location.href, '')\">Ajouter aux favoris</a>");
	} else {
		document.write("Pour ajouter le site du <cite>Conseil G&eacute;n&eacute;ral des Hautes Alpes</cite> &agrave; vos favoris : Cliquez sur la rubrique correspondante de votre navigateur.");
 	}
}

