﻿// ===========================================
//
// Fonctions communes
//
// ===========================================

var intOffset = 0;

function atx_OutOfFrame() {

	if (top.location != location) {
		top.location.href = document.location.href;
	}

	var btnDelete          = document.getElementById('btnDelete');

	try {
	    if (btnDelete != null) {
	        btnDelete.onclick = atx_AlertDelete;
	    }
	}
	catch (e) {}

//	if (navigator.appName == 'Opera') return;

//	if (screen.availWidth < 982) {
	if (document.body.clientWidth < 982 && blnAdmin == false) {
		if (document.styleSheets[0].href.indexOf('_800') < 0) {
			if (document.location.search == '') {
				document.location = document.location + "?atx=800";
			}
			else if (document.location.search.indexOf('?atx=') < 0 && document.location.search.indexOf('&atx=') < 0) {
				document.location = document.location + "&atx=800";
			}
			else {
				document.location = document.location.toString().replace(/atx=1024/, 'atx=800');
			}
		}
	}
	else {
		if (document.styleSheets[0].href.indexOf('_800') >= 0) {
			if (document.location.search == '') {
				document.location = document.location + "?atx=1024";
			}
			else if (document.location.search.indexOf('?atx=') < 0 && document.location.search.indexOf('&atx=') < 0) {
				document.location = document.location + "&atx=1024";
			}
			else {
				document.location = document.location.toString().replace(/atx=800/, 'atx=1024');
			}
		}
	}

	try {
		var g = document.getElementById('slice_left');
		if (g.offsetHeight < 379) g.style.height = 379 + 'px';
	}
	catch (e) {}
}

function atx_LinkOver(strStatusText) {
	if (strStatusText == null) strStatusText = '';
	window.status = strStatusText;
	return (navigator.appName != 'Opera');
}

function atx_LinkOut(strStatusText) {
	if (strStatusText == null) strStatusText = '';
	window.status = strStatusText;
	return (navigator.appName != 'Opera');
}


// ===========================================
//
// Protection du bouton Supprimer
//
// ===========================================

function atx_AlertDelete() {

	var objElem = window.event;

	if (confirm(strToolNameVersion
	+ '\n\nVous avez demandé la suppression de l\'information sélectionnée.\nCette opération ne peut pas être annulée.\n\n'
	+ 'Vous pouvez choisir de :\n\n'
	+ ' - Cliquer sur ANNULER pour revenir dans l\'outil sans supprimer l\'information.\n'
	+ ' - Cliquer sur OK pour confirmer la suppression de l\'information.') == true) {
		__doPostBack('btnDelete','');
	}
}

/* ================================================= */

function atx_ObjectListProperties(objObject) {
//
// Liste les propriétés d'un objet
// De manière à ne pas occuper trop de place, les valeurs
// trop longues sont tronquées (64 caractères), les fonctions
// ne sont pas listées (<blacklisted>) car consultables en
// mode EDIT...
//
	var strList = 'Properties of object ' + objObject.toString() + '\n\n';
	var i = 0;
	for (prop in objObject) {
		try {
			if (objObject[prop] != null) {
				if ((typeof(objObject[prop]) == 'string') && (objObject[prop].length > 0)) {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + objObject[prop].substr(0,64) + '\n';
				}
				else if (typeof(objObject[prop]) == 'function') {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + '<blacklisted> \n';
				}
				else if ('<'+objObject[prop]+'>' != '<>') {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + objObject[prop] + '\n';
				}
				i += 1;
				if (i == 50) {
					alert(strToolNameVersion + '\n\n'
					+ strList);
					strList = '';
					i = 0;
				}
			}
		}
		catch (e) {
			strList = strList + prop + '\t\t\t  !!! ' + e.message + '\n';
			i += 1;
			if (i == 50) {
				alert(strToolNameVersion + '\n\n'
				+ strList);
				strList = '';
				i = 0;
			}
		}
	}
	alert(strToolNameVersion + '\n\n'
		+ strList);
	return true;
}

// ===========================================
//
// Egalisation de la hauteur des colonnes
//
// ===========================================

function atx_colH() {

	var i;
	var oh;
	var hh;

	var h=0;
	var dA=document.atx_eqc;
	var an=document.atx_eqa;
	
	if (typeof(intOffset) == 'undefined') intOffset = 0;
	
	if (dA && dA.length){

		for ( i = 0; i < dA.length; i++) {
			dA[i].style.height = 'auto';
		}
		
		for ( i = 0; i < dA.length; i++) {
			oh = dA[i].offsetHeight + (i == 1 ? intOffset : 0);
			if (oh == 0) return;
			h = (oh > h) ? oh : h;
		}
		
		for ( i = 0; i < dA.length; i++) {
			if (an) {
				dA[i].style.height = h + 'px';
			}
			else {
				atx_eqA(dA[i].id, dA[i].offsetHeight, h + (i == 0 ? intOffset : 0));
			}
		}
		
		if (an) {
			for ( i = 0; i < dA.length; i++) {
				hh = dA[i].offsetHeight;
				if (hh > h) {
					dA[i].style.height = (h - (hh - h)) + (i == 0 ? intOffset : 0) + 'px';
				}
			}
		}
		else {
			document.atx_eqa = 1;
		}

		document.atx_eqth = document.body.offsetHeight;
		document.atx_eqtw = document.body.offsetWidth;
	}
}

function atx_eqT() {

	if (document.atx_eqth != document.body.offsetHeight || document.atx_eqtw != document.body.offsetWidth) {
		atx_colH();
	}
}

function atx_eqT1() {
	document.atx_eqa = 0;
	atx_colH();
}

function atx_equalCols() {

	if (document.getElementById) {
		document.atx_eqc = new Array;
		if (arguments.length == 0) {
			var i = 0
			while (0 == 0) {
				if (document.getElementById('c' + (i + 1).toString()) == null) break;
				document.atx_eqc[i] = document.getElementById('c' + (i + 1).toString());
				i++;
			}
		}
		else {
			for (i = 0; i < arguments.length; i++) {
				document.atx_eqc[i] = document.getElementById(arguments[i]);
			}
		}
		if (window.addEventListener) window.addEventListener("resize", atx_eqT1, false);
		else if (window.attachEvent) window.attachEvent("onresize", atx_eqT1);
		setInterval("atx_eqT()", 10);
	}
}

function atx_equalColsFast() {

	if (document.getElementById) {
		document.atx_eqc = new Array;
		for (i = 0; i < arguments.length; i++) {
			document.atx_eqc[i] = document.getElementById(arguments[i]);
		}
	}
}

function atx_eqA(el, h, ht) {

	var sp = 10;
	var inc = 10;
	var nh = h;
	var g = document.getElementById(el);
	var oh = g.offsetHeight;
	var ch=parseInt(g.style.height);
	
	if (ht > 2 * h) {
		g.style.height = ht + 'px';
		return;
	}
	//alert(ht + '\n' + h);

	ch = (ch) ? ch : h;
	
	var ad = oh-ch;
	var adT = ht-ad;

	nh += inc;
	nh = (nh > adT) ? adT : nh;
	
	g.style.height = nh + 'px';
	oh = g.offsetHeight;
	
	if (oh > ht) {
		nh = (ht - (oh - ht));
		g.style.height = nh + 'px';
	}

	if (nh < adT) {
		setTimeout("atx_eqA('" + el + "'," + nh + "," + ht + ")", sp);
	}
}

// ===========================================
//
// Décodage d'une adresse de courrier électronique
//
// ===========================================

function atx_LinkToMe(link,seed) {
	var ky = "yJzdeB4CcDnmEFbZtvuHlI1hA8SiLo9MwfN3O6Y5QaRqKTjUpxVk2WgXrP7Gs0";
	if(document.all) { 
		link = document.all[link];
	}
	else {
		link = document.getElementById(link);
	}

	var storeText = link.innerHTML;
	var baseNum = parseInt(seed);
	var atSym = link.href.indexOf("@");

	if(atSym == -1) atSym = 0;
	var dotidx = link.href.indexOf(".",atSym);
	if (dotidx==-1) dotidx = link.href.length;
	var scramble = link.href.substring(7, dotidx);
	var unscramble = "";
	var su = true;
	for (var i = 0; i < scramble.length; i++) {
		var ch = scramble.substring(i,i+1);
		var idx=ky.indexOf(ch);
		if(idx< 0) {
			unscramble = unscramble + ch;
			continue;
		}
		idx -= (su ? -baseNum : baseNum);
		baseNum -= (su ? -i : i);
		while (idx < 0) idx+=ky.length;idx%=ky.length;

		unscramble = unscramble + ky.substring(idx, idx + 1);
		su = !su;
	}

	var emAdd = unscramble + link.href.substring(dotidx, link.href.length + 1);
	link.href = "mailto:" + emAdd;
	var findEm = storeText.indexOf(scramble);
	while (findEm > -1) {
		storeText = storeText.substring(0, findEm) + emAdd + storeText.substring(findEm + emAdd.length, storeText.length);
		findEm = storeText.indexOf(scramble);
	}
	
	link.innerHTML = storeText;
}

