// $Id$
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}
var utils = new Object();
utils.init = function() {
  //if (!utils.getCookie("flashTaxe20101201")) {
  //  utils.flashSwitch(true);
  //  utils.setCookie("flashTaxe20101201", true);
  //}
}
utils.onload = (window.onload) ? window.onload : function () {};
window.onload = function () {utils.onload(); utils.init()};
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.updateOpener = function(url) {
	if (window.opener) {
		window.opener.location = url;
		window.opener.focus(); 
	} else {
		newWindow = window.open(url,'main');
		newWindow.focus();
	}
}
utils.removeClassName = function(elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}
utils.addClassName = function(elem, className) {
	utils.removeClassName(elem, className);
	elem.className = (elem.className + " " + className).trim();
}
utils.toggle = function(id) {
	var element = document.getElementById(id);
	if (element.className == "display-none") element.className = "display-block";
	else element.className = "display-none";
}
utils.flashSwitch = function(show) {
  var div = document.getElementById("flash-special");
  var lien = document.getElementById("flash-special-lien");
	var flash = document.getElementById("flash-object");
	if (div && lien && flash) {
    if (show) {
      div.className = "display-block";
      flash.className = "display-none";
      lien.className = "display-none";
    } else {
      div.className = "display-none";
      flash.className = "display-block";
      lien.className = "";
    }
  }
}
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.folder = function(object) {
	var depliant = object.parentNode;
	if (depliant) {
		if (depliant.className == "fold-off") {
			object.title = "Cliquez pour masquer le pavé";
			depliant.className = "fold-on";
		} else {
			object.title = "Cliquez pour en savoir plus";
			depliant.className = "fold-off";
		}
	}
}
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;
}
utils.getViewPort = function() {
	// get viewport size
	var width = 0, height = 0;
	if (utils.navigator.isMozilla()) {
		// mozilla
		// _window.innerHeight includes the height taken by the scroll bar
		// clientHeight is ideal but has DTD issues:
		// #4539: FF reverses the roles of body.clientHeight/Width and documentElement.clientHeight/Width based on the DTD!
		// check DTD to see whether body or documentElement returns the viewport dimensions using this algorithm:
		var minw, minh, maxw, maxh;
		var dbw = document.body.clientWidth;
		if (dbw > document.documentElement.clientWidth) {
			minw = document.documentElement.clientWidth;
			maxw = dbw;
		} else {
			maxw = document.documentElement.clientWidth;
			minw = dbw;
		}
		var dbh = document.body.clientHeight;
		if (dbh > document.documentElement.clientHeight) {
			minh = document.documentElement.clientHeight;
			maxh = dbh;
		} else {
			maxh = document.documentElement.clientHeight;
			minh = dbh;
		}
		width = (maxw > window.innerWidth) ? minw : maxw;
		height = (maxh > window.innerHeight) ? minh : maxh;
	} else if (!utils.navigator.isOpera() && window.innerWidth) {
		//in opera9, dojo.body().clientWidth should be used, instead
		//of window.innerWidth/document.documentElement.clientWidth
		//so we have to check whether it is opera
		width = window.innerWidth;
		height = window.innerHeight;
	} else if (utils.navigator.isIE() && document.documentElement && document.documentElement.clientHeight) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} else if (document.body().clientWidth) {
		// IE5, Opera
		width = document.body().clientWidth;
		height = document.body().clientHeight;
	}
	return {width:width, height:height};
}

