

/**
* Variables temporaires
*/
var tmp = new Object();
var v = new Object();

/**
* Menu du haut
*/
var selectedOnglet;

/**
* Deuxième système d'onglet
*/
var selectedOnglet2;

/**
* Menu des boutons
*/
var selectedBtn;

/**
* Menu de gauche
*/
var selectedMenu;
var clicableMenu = true;

/**
* Contenu d'un formulaire
*/
var cFormulaires = new Object();

/**
* Champs de recherche
*/
var champRecherche = new Object();


/**
* Pour enregistrer des fonctions
*/
var fct = new Object();



function antiPagePrecedente()
{
	if (!document.getElementById('antiPagePrecedente'))
	{
		tmp.antiPagePrecedente = 1;
		var i = document.createElement('iframe');
		i.style.display = 'none';
		i.id = 'antiPagePrecedente';
		document.getElementsByTagName('body')[0].appendChild(i);
	}

	document.getElementById('antiPagePrecedente').src = '/blank.php?' + (tmp.antiPagePrecedente++);
}



/*
@url = Page demandée
@args= Paramètres de l'url
@meth= POST | GET
@mode= xml | html
@differe = true | false
@fct = fonction de retour
@params = paramètres envoyées à la fonction de retour
*/
function isa_lr(url, args, meth, mode, differe, fct, params)
{
	/*
	L'anti page précédente
	*/
	antiPagePrecedente();
	antiPagePrecedente();
	
	var xmlhttp = false;
	var html = '';

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	
	if (!differe)
	{
		xmlhttp.open(meth, url, false);

		if (meth == 'POST')
		{
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		}
			xmlhttp.send(args);

		if (mode == 'xml')
			return xmlhttp.responseXML.childNodes[0];
		else
			return xmlhttp.responseText;
			
	}
	else
	{
		xmlhttp.open(meth, url, true);
		xmlhttp.onreadystatechange = function()
		{
			if(xmlhttp.readyState == 4)
			{
				if (mode == 'xml')
					fct(xmlhttp.responseXML.childNodes[0], params);
				else
					fct(xmlhttp.responseText, params);
			}
		};
		
		if (meth == 'POST')
		{
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
			xmlhttp.send(args);
	}
	return false;
}


var loadingNum = 0;
var opacityOnLoading = true;
function addLoading(xdiv)
{
	if (document.getElementById(xdiv) && opacityOnLoading)
	{
		if (document.all)
		{
			document.getElementById(xdiv).style['filter'] = 'alpha(opacity=' + 30 + ')';
		}
		else
			document.getElementById(xdiv).style.opacity = 0.3;
	}
	opacityOnLoading = true;
	if (loadingNum == 0)
	{
		var elt = document.createElement('div');
		elt.style.position = 'absolute';

		var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }

		elt.style.top = (document.documentElement.scrollTop + (myHeight / 2) - 20) + 'px';
		elt.style.left =  ((myWidth / 2) - 100) + 'px';
		elt.id = 'loadingDiv';
		elt.innerHTML = '<div style="padding: 10px; padding-left: 50px; padding-right: 50px; background-color: white; opacity: 0.7; border: 1px solid gray; filter:alpha(opacity=70);"><img src="/pics2/xLoading.gif" align="absmiddle"> Chargement...</div>';
		document.getElementsByTagName('body')[0].appendChild(elt);
	}
	loadingNum++;
}



function removeLoading(xdiv)
{
	if (document.getElementById(xdiv))
	{
		if (document.all)
			document.getElementById(xdiv).style['filter'] = 'alpha(opacity=' + 100 + ')';
		else
			document.getElementById(xdiv).style.opacity = 1;
	}
	loadingNum--;
	if (loadingNum == 0)
	{
		var elt = document.getElementById('loadingDiv');
		elt.parentNode.removeChild(elt);
	}
}


function loadPage(url, xdiv, loading)
{
	if (typeof loading == 'undefined')
		loading = true;

	if (loading)	
		addLoading(xdiv);
	isa_lr(url, null, 'GET', 'html', true, loadPageRes, {'xdiv' : xdiv, 'loading' : loading});
}




function loadPageRes(html, p)
{
		var a;
		var js = '';
	
		var e = /<script[^>]+src\="(.+)"[^>]*><\/script>/gi;
		var r;
		var h;
		h = html;
		while (r = e.exec(h))
		{
			var elt = document.createElement('script');
			elt.type = 'text/javascript';
			elt.src = r[1];
			document.getElementsByTagName('body')[0].appendChild(elt);
	
			// On enlève de h
			var h = h.substr(0, r.index) + h.substr(r.index + r[0].length);
			if (r = e.exec(h)){} // A laisser... sinon Firefox fait le moisi :|
			var e = /<script[^>]+src\="(.+)"[^>]*><\/script>/gi;
		}
	
		
		while ((a = h.indexOf('<script ')) != -1)
		{
			var b = h.substr(a, h.length - a);
			var fin = h.indexOf('</script>' /**/);
			if (fin > -1)
			{
				var js2 = b.substr(0, fin - a);
				var c = js2.indexOf('>');
				js += js2.substr(c + 1);
				h = h.substr(0, a) + h.substr(fin + /**/ 9);
			}
		}
	
	if (document.getElementById(p.xdiv))
	{
		document.getElementById(p.xdiv).innerHTML = h;
	}
	try
	{
		if (js)
			eval(js);
	}
	catch(e){alert(e);};

	if (p.loading)
	removeLoading(p.xdiv);
}


/*
	Envoie d'un formulaire
*/
    function getFormValues(fobj)

    {

       var str = "";

       var valueArr = null;

       var val = "";

       var cmd = "";

       for(var i = 0;i < fobj.elements.length;i++)
       {
	       if (!fobj.elements[i].disabled)
           switch(fobj.elements[i].type)
           {

               case "text":
               case "hidden":
               case "textarea":
               case "password":

                    str += fobj.elements[i].name +
                     "=" + escape(fobj.elements[i].value).replace(/%u20AC/g, '%A4').replace(/\+/g, '%2B') + "&";
                     break;

               case "select-one":
               			try
               			{
                    str += fobj.elements[i].name +
                    "=" + escape(fobj.elements[i].options[fobj.elements[i].selectedIndex].value).replace(/%u20AC/g, '%A4').replace(/\+/g, '%2B') + "&";
               			}
               			catch(e){};

                    break;
               case "select-multiple":
               			var elt = fobj.elements[i];
               			for (var a in elt.childNodes)
               			{
               				if (elt.childNodes[a].nodeType == 1) if (elt.childNodes[a].selected)
               				{
                    		str += fobj.elements[i].name +
                    		"=" + escape(elt.childNodes[a].value).replace(/%u20AC/g, '%A4').replace(/\+/g, '%2B') + "&";
               				}
               			}
                    break;
               case "checkbox":
               case "radio":
               			if (fobj.elements[i].checked)
               			{
	                    str += fobj.elements[i].name +
	                    "=" + escape(fobj.elements[i].value).replace(/%u20AC/g, '%A4').replace(/\+/g, '%2B') + "&";
               			}
               			break;

           }

       }

       str = str.substr(0,(str.length - 1));

       return str;

    }

    
function iSendForm(f, url, xdiv, loading)
{
	if (typeof loading == 'undefined')
		loading = true;
		
	if (loading)
	addLoading(xdiv);
	
	var args = getFormValues(document.forms[f]);
	var meth = document.forms[f].method;

	if (!meth)
		meth = 'get';
	meth = meth.toUpperCase();
	
	isa_lr(url + (meth == 'GET' ? '?' + args : ''), (meth == 'GET' ? null : args), meth, 'html', true, loadPageRes, {'xdiv' : xdiv, 'loading' : loading});
}









var agt			= navigator.userAgent.toLowerCase();
var appVer		= navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var is_opera	= (agt.indexOf("opera") != -1);
var iePos		= appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);}
var kqPos		= agt.indexOf('konqueror');
var is_safari	= ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml	= (is_safari || (kqPos != -1));
var is_ie		= ((iePos!=-1) && (!is_opera) && (!is_khtml));
var is_ie6up	= (is_ie && is_minor >= 6);






function PersoPopup2(name, url, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	s = screen;
	var left = (s.width-width)/2;
	if(height == "all")
		height = (s.height-40) - 50;
	var top = ((s.height-40)-height)/2;

	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';

	rd = new Date();
	rd = rd.getHours() + 'x' + rd.getMinutes() + 'x' + rd.getSeconds();


	if(is_ie)
	{
		opt = "dialogHeight:" + (height+25) + "px;dialogWidth:" + (width+7) + "px;resizable:" + resizable_str + ";help:no;status:" + statusbar_str + ";scoll:" + scrollbar_str + ";center:yes;";
		val = window.showModalDialog(url + '?&ismd=true&' + rd, 0, opt);
		return val;
	}
	else
	{
		window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
		return false;
	}
}



function popup_couleur2(variable, f)
{
	return PersoPopup2("Popup_couleur", "/aide/popup_couleur.php?variable=" + variable + "&form=" + f, 520, 280, false, false, false, false, false);
}



/**
* Fonction qui mets à jour le script cit et top
*/
var lastScriptCITTOP;
function bclScriptCITTOP()
{
	var f = document.forms['config'];
	if (f)
	{
		var n = getFormValues(document.forms['config']);
		document.getElementById('testcol').style.backgroundColor = '#' + f.elements['color'].value;
		document.getElementById('testcolhover').style.backgroundColor = '#' + f.elements['colorhover'].value;
		
		if (lastScriptCITTOP != n)
		{
			iSendForm('config', '/editeurs/install.cit.script.php', 'xScriptCITTOP');
		}
		setTimeout('bclScriptCITTOP()', 500);
		lastScriptCITTOP = n;
	}
	else
		lastScriptCITTOP = '';
}



/**
* Fonction qui mets à jour le script classic
*/





/**
* Verificateur de modification de formulaire
* @o = Valeur d'origine
*/
var ableSubmitOrigin	= new Object;
var ableSubmitTimeout = new Object;
function ableSubmit(f, btn, t, o)
{
	var a;
	eval("a = ableSubmitTimeout." + t);
	
	if (a)
	{
		eval("clearTimeout(ableSubmitTimeout." + t + ")");
	}

	if (!o)
	{
		resetAbleSubmit(t);
	}
		
	if (document.forms[f])
	{
		eval("a = ableSubmitOrigin." + t);
		if (typeof a == 'undefined' ||
				a == '')
		{
			a = getFormValues(document.forms[f]);
			eval("ableSubmitOrigin." + t + " = a");
		}
			
		else if(a != getFormValues(document.forms[f]))
		{
			if (document.getElementById(btn).disabled)
			document.getElementById(btn).disabled = false;
		}
		else
		{
			if (!document.getElementById(btn).disabled)
			document.getElementById(btn).disabled = true;
		}
		a = setTimeout('ableSubmit("' + f + '", "' + btn + '", "' + t + '", true);', 100);
		eval("ableSubmitTimeout." + t + " = a");
	}
}

function resetAbleSubmit(t)
{
	eval("ableSubmitOrigin." + t + " = ''");
}





var avertMessageTimeOut;
function avertMessage(l, t, icon)
{
	clearTimeout(avertMessageTimeOut);
	
	var a;
	var b;
	a = '<table cellpadding="0" cellspacing="0" align="center"><tr>';
	a += '<td><img src="/pics2/aL.gif"></td>';
		
	b = '</td><td><img src="/pics2/aR.gif"></td>';
	b += '</tr></table>';
	var time = 2000;

	if (typeof icon != 'undefined' &&
			icon != '')
		a+= '<td style="padding-left: 4px; vertical-align: top; background: url(/pics2/aBg.gif);"><div style="padding-top: 3px;"><img src="/pics2/a' + icon + '.gif"></div></td>';
	
	if (l == -1)
	{
		a += '<td style="padding-left: 10px; padding-right: 10px; vertical-align: middle; background: url(/pics2/aBg.gif); color: #D38E0B; font-weight: bold;">';
		time = 3000;
	}
	else
	{
		a += '<td style="padding-left: 10px; padding-right: 10px; vertical-align: middle; background: url(/pics2/aBg.gif); color: #454545">';
	}
		
	document.getElementById('xAlertMessage').innerHTML = a + t + b;
	avertMessageTimeOut = setTimeout("document.getElementById('xAlertMessage').innerHTML = '';", 3000);
}




function editIllustration(ci, ai, checkChangePage)
{
	window.open('camp.annonce.illustration.php?ci=' + ci + '&ai=' + ai + '&checkChangePage=' + checkChangePage, 'illustration', 'width=400,height=250,status=no,location=no,menubar=no,resizable=no,scrollbars=no,titlebar=no,toolbar=no');
}



function editedIllustration(mi, ci, ai, param)
{
	document.forms['addAnnonce'].elements['image'].value = param;
	document.getElementById('xIllustrationNew').innerHTML =
		param ?
		'<img src="http://fr.data.clickintext.net/pics/' + mi + '/' + ci + '-' + ai + '.' + param + '?' + grain() + '">' :
		'Aucune';
	checkIllustrationButtons();
}


function checkIllustrationButtons()
{
	var e = document.forms['addAnnonce'].elements;
	
	// le bouton supprimer
	if (e['btnSupprimer'])
	e['btnSupprimer'].disabled = (e['image'].value == '');

	// le bouton annuler modif
	if (typeof(e['btnAnnulModif']) != 'undefined'
			&& typeof(e['imageActuelle']) != 'undefined')
	e['btnAnnulModif'].disabled = (e['image'].value == e['imageActuelle'].value);
}



function grain()
{
	var v = new Date();
	return '&' + v.getHours() + 'x' + v.getMinutes() + 'x' + v.getSeconds()
}


function drawFlash(url, id1, id2)
{
	return	'<object width="250" height="250" ' + (id1 ? 'id="' + id1 + '"' : '') + '>' +
					'<param name="movie" value="' + url + '">' +
					'<embed src="' + url + '" width="250" height="250"' + (id2 ? 'id="' + id2 + '"' : '') + '>' +
					'</embed>' +
					'</object>';
}




/*
---------------------
*/

var infoBulle = new Object();
infoBulle.show = function(texte)
{
	infoBulle.prevent = 1;
	tmp.infoBulleText = texte;
	setTimeout('infoBulle._show()');
}

 /* Le CSS pour le positionnement */
	document.write("<style type=\"text/css\">#infoBulleContainer{z-index: 1000; right: 5px; top: 0px; position: fixed; *position: absolute;};</style>");

	/* Pour IE, comme il n'y a pas de "position: fixed" on combine le js au css tout en bidouillant ! oui, IE est très tordu :) */
	if (document.all)
		document.write("<style type=\"text/css\">#infoBulleContainer{top: expression( ( ignoreMe = (5 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 150 )/2) + 'px' );};</style>");


		
infoBulle._show = function()
{
	infoBulle.prevent = 0;
	var ib = document.getElementById('infoBulleContainer');

	if (!ib)
	{
		infoBulle.infoBullePlace = 0;
		ib = document.createElement('div');
		ib.id = 'infoBulleContainer';
		ib.style.display = 'none';
		
		//ib.style.top = infoBulle.infoBullePlace + 'px';
		
		var b = document.getElementsByTagName("body")[0];
		if (b.firstChild != null) b.insertBefore(ib, b.firstChild);
		else b.appendChild(ib);
		ib = document.getElementById('infoBulleContainer');
		ib.innerHTML =	'<table cellpadding="0" cellspacing="0" onmouseover="infoBulle.preventClose();" onmouseout="infoBulle.acceptClose()" id="infoBulleContainer">' +
										'	<tr>' +
										'		<td style="height: 15px; width: 178px;"></td><td rowspan="4" style="padding-left: 0px;">' + png('/pics2/ibGuy.png', 36, 55) + '</td>' +
										'	</tr>' +
										'	<tr>' +
										'		<td style="' + pngBg('/pics2/ibTop.png') + '; width: 178px; height: 19px;"></td>' +
										'	</tr>' +
										'	<tr>' +
										'		<td style=" width: 178px;">' +
										'			<table style="width: 178px;" cellpadding="0" cellspacing="0">' +
										'				<tr>' +
										'					<td style="' + pngBg('/pics2/ibLeft.png') + ' width: 4px;"></td>' +
										'					<td style="' + pngBg('/pics2/ibBg.png') + ' font-size: 10px; font-family: Verdana; color: #3D3D3D; width: 161px"><div id="infoBulleTexte"></div></td>' +
										'					<td style="' + pngBg('/pics2/ibRight.png') + ' width: 9px;"></td>' +
										'					<td style="width: 4px;"></td>' +
										'				</tr>' +
										'			</table>' +
										'		</td>' +
										'	</tr>' +
										'	<tr>' +
										'		<td style=" width: 178px;">' +
										'			<table style="width: 174px;" cellpadding="0" cellspacing="0">' +
										'				<tr>' +
										'					<td style="' + pngBg('/pics2/ibBottom.png') + ' width: 4px; height: 15px;"></td>' +
										'				</tr>' +
										'			</table>' +
										'		</td>' +
										'	</tr>' +
										'</table>';
	}
	ib.style.display = '';
	clearTimeout(infoBulle.infoBulleTimeout2);
	document.getElementById('infoBulleTexte').innerHTML = '<div style="text-align: center; color: gray; padding-top: 15px; padding-bottom: 15px;">Chargement...</div>';
	
	infoBulle.infoBulleTimeout2 = setTimeout('infoBulle.text();', 200);
	ib.style.display = '';
	clearTimeout(infoBulle.infoBulleTimeout);
	infoBulle.open();
}


infoBulle.text = function()
{
	document.getElementById('infoBulleTexte').innerHTML = tmp.infoBulleText;
}


infoBulle.open = function()
{
	clearTimeout(infoBulle.infoBulleTimeout);
	var ib = document.getElementById('infoBulleContainer');
	infoBulle.infoBullePlace += 7;
	if (infoBulle.infoBullePlace < 150)
		infoBulle.infoBulleTimeout = setTimeout("infoBulle.open();", 20);
	else
		infoBulle.infoBullePlace = 150;
	/*
	if (document.all)
		ib.style.top = ((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + infoBulle.infoBullePlace) + 'px';
	else
	*/
		ib.style.marginTop = infoBulle.infoBullePlace + 'px';
}

infoBulle.preventClose = function()
{
	infoBulle.prevent = 1;
}

infoBulle.acceptClose = function()
{
	/*infoBulle.prevent = 0;*/
	this.remove();
}

infoBulle.close = function()
{
	clearTimeout(infoBulle.infoBulleTimeout);
	var ib = document.getElementById('infoBulleContainer');
	infoBulle.infoBullePlace -= 7;
	if (infoBulle.infoBullePlace > 0)
		infoBulle.infoBulleTimeout = setTimeout("infoBulle.close();", 20);
	else
	{
		ib.style.display = 'none';
		infoBulle.infoBullePlace = 0;
	}
	ib.style.marginTop = infoBulle.infoBullePlace + 'px';
}

infoBulle.remove = function()
{
	setTimeout('infoBulle._remove()');
}


infoBulle._remove = function()
{
	if (infoBulle.prevent != 1)
	{
		clearTimeout(infoBulle.infoBulleTimeout);
		infoBulle.close();
	}
	infoBulle.prevent = 0;
}










function png(src, w, h)
{
	if (document.all)
	{
		return '<span style="padding: 0; margin: 0; border: 0; display: inline-block; width: ' + w + 'px; height:' + h + 'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\');"></span>';
	}
	else
	{
		return '<img src="' + src + '" style="border: 0; padding: 0; margin: 0;">';
	}
}




function pngBg(src)
{
	if (document.all)
	{
		/*return 'background: url(' + src + ')';*/
		return 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=scale);';
	}
	else
	{
		return 'background: url(' + src + ');';
	}
}

