// $Id$
var utils = new Object();
utils.popup = function (url, name, features) {
	if (!name) name = "_blank";
	if (features) {
		var width = parseInt (features.replace(/.*width=/, ""));
		var height = parseInt (features.replace(/.*height=/, ""));
		var newWindow = window.open(url, name, features);
		if (width && height) try {newWindow.resizeTo (width, height)} catch (e) {};
		try {newWindow.moveTo(0,0)} catch (e) {};
	} else var newWindow = window.open(url, name);
	newWindow.focus();
	return false;
}
utils.deplier = function (object) {
	var depliant = object.parentNode;
	if (depliant) {
		if (depliant.className == "depliant-off") {
			object.title = "Cliquez pour masquer le complément d'information";
			depliant.className = "depliant-on";
		} else {
			object.title = "Cliquez pour afficher le complément d'information";
			depliant.className = "depliant-off";
		}
	}
}
utils.updateOpener = function (url) {
	if (window.opener) {
		window.opener.location = url;
		window.opener.focus(); 
	} else {
		newWindow = window.open(url,'main');
		newWindow.focus();
	}
}
utils.switchTab = function (tab) {
	var index = parseInt (tab.id.replace(/.*-/,""));
	var prefix = tab.id.replace(/-header-\d*$/,"");
	if (document.getElementById) {
		var i = 1;
		var tab_header = true;
		while (tab_header) {
			tab_header = document.getElementById(prefix + "-header-" + i);
			var tab = document.getElementById(prefix + "-" + i);
			if (tab_header) {
				if (i == index) {
					tab_header.className = "tab-current";
					tab.style.display = "block";
				} else {
					tab_header.className = "";
					tab.style.display = "none";
				}
			}
			i++;
		}
	}
}
utils.addBookmark = function (message) {
	if (window.external) window.external.AddFavorite(location.href, document.title);
	else alert (message);
}
utils.sendPage = function (path, name, features) {
	var url = path + "?page=" + escape(location.pathname + location.search);
	utils.popup(url, name, features);
}
utils.getCookie = function (name) {
	var cookies = document.cookie.split(";");
	var pattern = name + "="
	for (var i = 0; i < cookies.length; i++) {
		var index = cookies[i].indexOf(pattern);
		if (index >= 0) return unescape(cookies[i].substr(index + pattern.length));
	}
	return null;
}
utils.setCookie = function (name, value) {
	var arguments = this.setCookie.arguments;
	var cookie = name + "=" + escape(value);
	if (typeof arguments[2] == "object") cookie = cookie + "; expires=" + arguments[2].toGMTString();
	if (typeof arguments[3] == "string") cookie = cookie + "; path=" + arguments[3];
	if (typeof arguments[4] == "string") cookie = cookie + "; domain=" + arguments[4];
	if (arguments[5]) cookie = cookie + "; secure";
	document.cookie = cookie;
}