// ========================== ACREAT FRAMEWORK - JAVASCRIPT.JS ===================
var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_regexp = (window.RegExp) ? true : false;

// --------------
addLoadEvent = function ( oFunction ) 
{
	// DOM2
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "load", oFunction, false );
	// IE 
	else if ( typeof window.attachEvent != "undefined" ) 
		window.attachEvent( "onload", oFunction );
	else 
	{
		if ( window.onload != null ) 
		{
			var oldOnload = window.onload;
			window.onload = function ( e ) 
			{
				oldOnload( e );
				oFunction();
			};
		}
		else 
			window.onload = oFunction;
	}
}
// --------------
addUnloadEvent = function ( oFunction ) 
{
	// DOM2
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "unload", oFunction, false );
	// IE 
	else if ( typeof window.attachEvent != "undefined" ) 
		window.attachEvent( "onunload", oFunction );
	else 
	{
		if ( window.onunload != null ) 
		{
			var oldOnunload = window.onunload;
			window.onunload = function ( e ) 
			{
				oldOnunload( e );
				oFunction();
			};
		}
		else 
			window.onunload = oFunction;
	}
}
// --------------
function fetch_cookie(nom)					
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) 
			return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) 
			break;
	}
	return null; 
}
// --------------
function set_cookie(nom, valeur)		// Ecriture de valeur de cookie
{
	var argv=set_cookie.arguments;
	var argc=set_cookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}
// --------------
function delete_cookie(name)
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
// ----------- //
var acreatObjects = new Object();
var acreatDOMtype = '';
if (document.getElementById) { acreatDOMtype = "std"; }
else if (document.all) { acreatDOMtype = "ie4"; }
else if (document.layers) { acreatDOMtype = "ns4"; }
// ----------- //
function fetch_object(idname, forcefetch)
{ 
	if (forcefetch || typeof(acreatObjects[idname]) == "undefined")
	{
		switch (acreatDOMtype)
		{
			case "std":
			{ 
				acreatObjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				acreatObjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				acreatObjects[idname] = document.layers[idname];
			}
			break;
		}
	} 
	return acreatObjects[idname];
}
// --------------
function ArgumentURL() 
{
	this.getArgument = _getArg;
	this.setArgument = _setArg;
	this.removeArgument = _removeArg;
	this.toString    = _toString;	//Allows the object to be printed
									//no need to write toString()
	this.arguments   = new Array();

	// Initiation
	var separator = "&";
	var equalsign = "=";
	
	var str = window.location.search.replace(/%20/g, " ");
	var index = str.indexOf("?");
	var sInfo;
	var infoArray = new Array();

	var tmp;
	
	if (index != -1) {
		sInfo = str.substring(index+1,str.length);
		infoArray = sInfo.split(separator);
	}

	for (var i=0; i<infoArray.length; i++) {
		tmp = infoArray[i].split(equalsign);
		if (tmp[0] != "") {
			var t = tmp[0];
			this.arguments[tmp[0]] = new Object();
			this.arguments[tmp[0]].value = tmp[1];
			this.arguments[tmp[0]].name = tmp[0];
		} 
	} 
	
	function _toString() {
		var s = "";
		var once = true;
		for (i in this.arguments) {
			if (once) {
				s += "?";
				once = false;
			}
			s += this.arguments[i].name;
			s += equalsign;
			s += this.arguments[i].value;
			s += separator;
		}
		return s.replace(/ /g, "%20");
	}
	
	function _getArg(name) {
		if (typeof(this.arguments[name]) != "object" || typeof(this.arguments[name].name) != "string")
			return null;
		else
			return this.arguments[name].value;
	}
	
	function _setArg(name,value) {
		this.arguments[name] = new Object()
		this.arguments[name].name = name;
		this.arguments[name].value = value;
	}
	
	function _removeArg(name) {
		this.arguments[name] = null;
	}
	
	return this;
}
// --------------
function popPage(page,largeur,hauteur,options)
{
	if(options==null) options = "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no";
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var newWin = window.open(page,"POPUP","top="+top+",left="+left+",width="+largeur+",height="+hauteur+"," + options);
}
// --------------
function resizeAndCenter(largeur,hauteur,target)
{
	if(!target) var target = window;
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	target.moveTo(left,top);
	target.resizeTo(largeur,hauteur);
}
// --------------
function zoomPhoto(idPhoto,from)
{
	if(from == null) from = "";
	popPage(from + "popup.php?tpl=zoom&idPhoto=" + idPhoto,450,400);
}
// --------------
function switchLangue(codeLangue)
{
	arguments = new ArgumentURL();
	arguments.removeArgument('lang');
	arguments.setArgument('lang',codeLangue);
	document.location.href="index.php" + arguments.toString();
}
// --------------