var flashVersion = [10, 2, 0];

function prepareExterne() {
	$$('.externe').each(function(elem) {
		if(!elem.hasClassName('allreadyCheck')) {
			elem.setAttribute('target', '_blank');
			elem.addClassName('allreadyCheck');
		}
	});
}

function ietruebody() {
	return (document.compatMode && document.compatMode != "BackCompat")
			? document.documentElement
			: document.body;
}

/** *************************** */
/*
function keep_connected(rootConnected) {
	if (rootConnected == null || rootConnected == undefined) {
		rootConnected = '';
	}
	//alert(rootConnected + '/keepConnected.php?keepConnected='+ rootConnected);
	new Ajax.Request(rootConnected + '/keepConnected.php?keepConnected='
					+ rootConnected, {
				method : 'post',
				onSuccess : function(transport) {
					var reponse = transport.responseText;
					// alert(reponse);
					if (reponse == 'undefined' || reponse == null
							|| reponse == undefined) {
						reponse = '';
					}
					// alert('success');
					setTimeout("keep_connected('" + reponse + "')", 600000);
				}
	});
}
*/
function PMA_markRowsInit() {
	// for every table row ...
	var rows = $$('tr');
	for (var i = 0; i < rows.length; i++) {
		// ... with the class 'row0' or 'row1' ...
		if ('row0' != rows[i].className.substr(0, 4)
				&& 'row1' != rows[i].className.substr(0, 4)) {
			continue;
		}
		// ... add event listeners ...
		// ... to highlight the row on mouseover ...
		if (navigator.appName == 'Microsoft Internet Explorer') {
			// but only for IE, other browsers are handled by :hover in css
			rows[i].onmouseover = function() {
				this.addClassName('hover');
			};
			rows[i].onmouseout = function() {
				this.removeClassName('hover');
			};
		}
	}
}

/**
 * Demande une confirmation avant de rediriger sur la page de déconnexion
 */
function deconnexion() {
	if (confirm("Souhaitez-vous vous déconnecter et quitter Netagis MAPS 2011 ?")) {
		urlDeco = 'index.php?action=deconnect_actigis';
		if (pleinEcran) {
			urlDeco += '&mode=plein';
		}
		document.location.href = urlDeco;
	}
}

function forceDeco(force) {
	var mode = '&mode=';

	if (force == null || force == undefined || (parent.document != document)) {
		force = false;
	}
	if ((window.parent != undefined && (parent.document != document))
			|| window.opener != undefined) {
		force = true;
	}
	if (force || valForceDeco) {
		if (window.parent != undefined && (parent.document != document)) {
			if (pleinEcran || window.parent.pleinEcran) {
				mode += 'plein';
			}

			window.parent.document.location.href = "index.php?action=deconnect_actigis&force_deco=true"
					+ mode;
			return false;
		}
		if (window.opener != undefined) {
			if (pleinEcran || window.opener.pleinEcran) {
				mode += 'plein';
			}
			window.opener.document.location.href = "index.php?action=deconnect_actigis&force_deco=true"
					+ mode;
			window.close();
			return false;
		}

		if (pleinEcran) {
			mode += 'plein';
		}
		window.parent.document.location.href = "index.php?action=deconnect_actigis&force_deco=false"
				+ mode;
	}
}

/**
 * Affiche ou cache le contenu d'une catégorie
 * 
 */
function affichePartie(id) {
	var theme = $('partie_content_' + id);
	var exploreTheme = $('explorePartie_' + id);

	exploreTheme.removeClassName('ouvrir');
	exploreTheme.removeClassName('fermer');
	if (theme.style.display == 'none') {
		new Effect.BlindDown(theme, {
					duration : 0.6
				});
		exploreTheme.addClassName('fermer');
	} else {
		new Effect.BlindUp(theme, {
					duration : 0.6
				});
		exploreTheme.addClassName('ouvrir');
	}

	return false;
}

function fermCat(id) {
	var theme = $('partie_content_' + id);
	var exploreTheme = $('explorePartie_' + id);

	exploreTheme.removeClassName('ouvrir');
	exploreTheme.removeClassName('fermer');
	if (theme.style.display != 'none') {
		new Effect.BlindUp(theme, {
					duration : 0.6
				});
		exploreTheme.addClassName('ouvrir');
	}

	return false;
}
function OpenCat(id) {
	var theme = $('partie_content_' + id);
	var exploreTheme = $('explorePartie_' + id);

	exploreTheme.removeClassName('ouvrir');
	exploreTheme.removeClassName('fermer');
	if (theme.style.display == 'none') {
		new Effect.BlindDown(theme, {
			duration : 0.6
		});
		
		exploreTheme.addClassName('fermer');
	}

	return false;
}
function getHauteurElem(id) {
	if ($(id) != undefined && $(id) != null) {
		return $(id).getHeight();
	} else {
		alert('Elément introuvable');
		return 0;
	}
}

function getLargeurElem(id) {
	if ($(id) != undefined && $(id) != null) {
		return $(id).getWidth();
	} else {
		alert('Elément introuvable');
		return 0;
	}
}

function getHauteurTotale() {
	// firefox is ok
	var height = document.documentElement.scrollHeight;

	// now IE 7 + Opera with "min window"
	if (document.documentElement.clientHeight > height) {
		height = document.documentElement.clientHeight;
	}
	// last for safari
	if (document.body.scrollHeight > height) {
		height = document.body.scrollHeight;
	}
	return height;
}

function getLargeurTotale() {
	// firefox is ok
	var width = document.documentElement.scrollWidth;

	// now IE 7 + Opera with "min window"
	if (document.documentElement.clientWidth > width) {
		width = document.documentElement.clientWidth;
	}
	// last for safari
	if (document.body.scrollWidth > width) {
		width = document.body.scrollWidth;
	}
	return width;
}

/**
 * Génère l'effet hover sur les boutons du footer
 */
function hoverFooterMenu() {
	if ($('menuFooter') != undefined) {
		$A($('menuFooter').childNodes).each(function(e) {
					Event.observe(e, 'mouseover', function() {
								Element.addClassName(e, 'hover');
							});
					Event.observe(e, 'mouseout', function() {
								Element.removeClassName(e, 'hover');
							});
				});
	}
}

function detecteEspaceDispo() {
	var largUtile = getLargeurElem('corps');
	var hautUtile = getHauteurElem('corps');
	var resolution = new Array();
	resolution['x'] = largUtile;
	resolution['y'] = hautUtile;

	return resolution;
}

function redimModalWindow() {
	var bodyH = $$('body')[0].getHeight();
	var MBTH = $('MB_window').getHeight() + parseInt($('MB_window').style.top);
	if (MBTH > bodyH) {
		var MBH = bodyH - parseInt($('MB_window').style.top)
				- $('MB_header').getHeight();
		$('MB_content').style.height = MBH + 'px';
		$('MB_window').style.height = MBH + 'px';
		$('MB_overlay').style.height = MBH + 'px';
	} else {

	}
}

function is_array(input) {
	return typeof(input) == 'object' && (input instanceof Array);
}

/**
 * Renvoie la position de 'valeur' dans le tableau 'array', ou -1 si 'valeur'
 * n'est pas dans le tableau 'array'.
 */
function in_array(valeur, array) {
	var length = array.length;
	var i = 0;
	while (i < length && array[i] != valeur) {
		i++;
	}
	if (i < length) {
		return i;
	} else {
		return -1;
	}
}

function array_key_exists(key, search) {
	// http://kevin.vanzonneveld.net
	// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)

	// input sanitation
	if (!search
			|| (search.constructor !== Array && search.constructor !== Object)) {
		return false;
	}

	return key in search;
}


function creerBoutonMini(id, icone, titre, path) {
	if(path == null || path == undefined) {
		path = '';
	}
	var div = new Element('div', {
		'class' : 'boutonMini2009',
		title : titre,
		id : id
	});
	div.addClassName('boutonMini2009');
	var img = new Element('img', {
		src : path+'presentation/skin/vide.gif',
		'class' : icone,
		title : titre,
		alt : titre,
		id : 'img__' + id
	});
	img.addClassName(icone);
	div.insert(img);

	return div;
}

function stripslashes (str) {
    // (http://kevin.vanzonneveld.net)

    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

function addslashes (str) {
    // http://kevin.vanzonneveld.net
 
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
}


