function appearShow(id, opacity, duration)
{
	if (!opacity)
		opacity = 1;
	if (!duration)
		duration = 500;

	appear_fx = new Fx.Style(id, 'opacity', {duration : duration, onStart : function() {$(id).style.display='block';} });
	appear_fx.set(0);
	appear_fx.start(0,opacity);
}
function appearHide(id, opacity, duration)
{
	if (!opacity)
		opacity = 1;
	if (!duration)
		duration = 500;

	appear_fx = new Fx.Style(id, 'opacity', {duration : duration, onComplete : function() {$(id).style.display='none';$(id).setStyle('opacity',1);} });
	appear_fx.start(opacity,0);
}
function appearToggle(id, opacity)
{
	if ($(id).style.display == 'none')
		appearShow(id, opacity);
	else
		appearHide(id, opacity);
}
function offsetPos(element)
{
	var x=0;
	var y=0;

	var temp_element = element;
	x = element.offsetLeft;
	y = element.offsetTop;
	while(temp_element.offsetParent)
	{
		x += temp_element.offsetParent.offsetLeft;
		y += temp_element.offsetParent.offsetTop;
		temp_element = temp_element.offsetParent;
	}

	return new Array(x,y);
}


function voterSondage(pollid, num_option, id_membre, div)
{
	new Ajax('/?action=voter_sondage',
			{
				update : $(div),
				encoding : 'ISO-8859-15',
				method : 'post', 
				data : 'pollid='+pollid+'&option='+num_option+'&id_membre='+id_membre,
				onFailure : function() {alert('Problème de connexion au serveur..');}
			}).request();
}

function loginForums(login_url)
{
	var login = $('vb_login_username').value;
	var vb_login_password = $('vb_login_password');
	var vb_login_md5password = $('vb_login_md5password');
	var vb_login_md5password_utf = $('vb_login_md5password_utf');
	md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf);
	cookieuser = $('login_souvenir').checked;
	
	if ($('login_inscription'))
		$('login_inscription').style.display = 'none';
	if ($('login-loading'))
		$('login-loading').style.display = 'block';
	ajax_login_forum = new Ajax(login_url, 
					{
						 method : 'post', encoding : 'ISO-8859-15',
						 data : 'do=login&vb_login_username='+escape(login)
							 			+'&vb_login_password='+escape(vb_login_password.value)
							 			+'&vb_login_md5password='+escape(vb_login_md5password.value)
							 			+'&vb_login_md5password_utf='+escape(vb_login_md5password_utf.value)
							 			+'&cookieuser='+escape(cookieuser)
							 			+'&ajaxlogin=1',
						 onSuccess : loginForumsResult,
						 onFailure : function()
									{
										if ($('login_inscription'))
											$('login_inscription').style.display = 'block';
									},
						 onComplete : function() 
									{
										if ($('login-loading'))
											$('login-loading').style.display = 'none';
									}
					});
	ajax_login_forum.request();
}
function logoutForums(login_url)
{
	var userid = $('id_membre').value;
	var logouthash = $('logouthash').value;
	if( $('securitytoken') )
		var securitytoken = $('securitytoken').value;
	else
		var securitytoken = $('logouthash').value;

	if ($('login-connecte'))
		$('login-connecte').style.display = 'none';
	if ($('login-loading'))
		$('login-loading').style.display = 'block';
	ajax_login_forum = new Ajax(login_url,
					{
						 method : 'post', encoding : 'ISO-8859-15',
						 data : 'do=logout&logouthash='+logouthash
										+'&securitytoken='+securitytoken
						 				+'&u='+userid
						 				+'&ajaxlogin=1',
						 onSuccess : logoutForumsResult,
						 onComplete : function()
									{
										if ($('login-loading'))
											$('login-loading').style.display = 'none';
									}
					});
	ajax_login_forum.request();
}

// rechargement de la pub..
function rechargerPubs()
{	
	if ($('pub-leaderboard-contenu'))
		new Ajax('/?page=ajax_leaderboard&skin=skin-portail', { update : $('pub-leaderboard-contenu'), evalScripts : true }).request();
//	if ($('pub-rectangle-contenu'))
//		new Ajax('/?page=ajax_rectangle', { update : $('pub-rectangle-contenu'), evalScripts : true }).request();
	if ($('pub-skycrapper-contenu'))
		new Ajax('/?page=ajax_skycrapper', { update : $('pub-skycrapper-contenu'), evalScripts : true }).request();
}
function cacherPubs(display)
{	
	if ($('pub-leaderboard-contenu'))
		$('pub-leaderboard-contenu').style.display = display;
	if ($('pub-rectangle-contenu'))
		$('pub-rectangle-contenu').style.display = display;
	if ($('pub-skycrapper-contenu'))
		$('pub-skycrapper-contenu').style.display = display;
}


// limiter le nombre de caractere d'un champ de saisie
function limiterCaracteres(champ, limite)
{
	if (champ.value.length > limite)
	{
		champ.addClass('erreur_champ');
//		champ.className = champ.className + ' erreur_champ';
		champ.value = champ.value.substring(0,limite);
	}
	else
		champ.removeClass('erreur_champ');
//		champ.className = champ.className.replace(' erreur_champ', '');
}

// limiter la longueur en px d'un champ texte
function limiterLongueur(champ, limite, classe)
{
	test_longueur = $('test_longueur');
	if (classe) test_longueur.className = classe;
	test_longueur.innerHTML = champ.value;
	if (test_longueur.offsetWidth <= limite)
		champ.className = champ.className.replace(' erreur_champ', '');

	class_erreur = champ.className + ' erreur_champ';
	while (test_longueur.offsetWidth > limite)
	{
		champ.className = class_erreur;
		champ.value = champ.value.substring(0,champ.value.length-1);
		test_longueur.innerHTML = champ.value;
	}
}

function modifierTitreNews(id_news)
{
	var champ_titre = '<input type="text" id="champ_titre_news_'+id_news+'" class="champ_texte" style="width : '+$('titre_news_'+id_news).offsetWidth+'px" id="champ_titre_news_'+id_news+'" value="'+$('titre_news_'+id_news).innerHTML+'"/>';
	champ_titre += '&nbsp;<input type="button" id="bouton_titre_news_'+id_news+'" value="Enregistrer" onclick="enregistrerTitreNews('+id_news+')"><span class="erreur" id="erreur_titre_news_'+id_news+'"></span>';
	$('titre_news_'+id_news).innerHTML = champ_titre;
	$('champ_titre_news_'+id_news).focus();
}
function enregistrerTitreNews(id_news)
{
	if (id_news && $('champ_titre_news_'+id_news).value)
	{
		$('details-news-loading_'+id_news).style.display = 'block';
		$('bouton_titre_news_'+id_news).style.display = 'none';
		new Ajax('/ecrire/?exec=news_save', 
						{
							method : 'post',
							encoding : 'ISO-8859-15',
							data : 'id_news='+id_news+'&update=titre&titre='+escape($('champ_titre_news_'+id_news).value),
							onSuccess : function()
										{
											if (this.response['text'] == 'ok')
												$('titre_news_'+id_news).innerHTML = $('champ_titre_news_'+id_news).value;
											else
											{
												$('erreur_titre_news_'+id_news).innerHTML = 'Erreur';
												$('bouton_titre_news_'+id_news).style.display = 'block';
											}
										},
							onFailure : function()
										{
											$('erreur_titre_news_'+id_news).innerHTML = 'Erreur';
											$('bouton_titre_news_'+id_news).style.display = 'block';
										},
							onComplete : function() { $('details-news-loading_'+id_news).style.display = 'none';}
						}).request();
	}
}

function modifierPitchNews(id_news)
{
	var champ_pitch = '<input type="text" id="champ_pitch_news_'+id_news+'" class="champ_texte" style="width : '+$('pitch_news_'+id_news).offsetWidth+'px" id="champ_pitch_news_'+id_news+'" value="'+$('pitch_news_'+id_news).innerHTML+'"/>';
	champ_pitch += '<input type="button" id="bouton_pitch_news_'+id_news+'" value="Enregistrer" onclick="enregistrerPitchNews('+id_news+')"><span class="erreur" id="erreur_pitch_news_'+id_news+'"></span>';
	$('pitch_news_'+id_news).innerHTML = champ_pitch;
	$('champ_pitch_news_'+id_news).focus();
}
function enregistrerPitchNews(id_news)
{
	if (id_news && $('champ_pitch_news_'+id_news).value)
	{
		$('details-news-loading_'+id_news).style.display = 'block';
		$('bouton_pitch_news_'+id_news).style.display = 'none';
		new Ajax('/ecrire/?exec=news_save', 
						{
							method : 'post',
							encoding : 'ISO-8859-15',
							data : 'id_news='+id_news+'&update=pitch&pitch='+escape($('champ_pitch_news_'+id_news).value),
							onSuccess : function()
										{
											if (this.response['text'] == 'ok')
												$('pitch_news_'+id_news).innerHTML = $('champ_pitch_news_'+id_news).value;
											else
											{
												$('erreur_pitch_news_'+id_news).innerHTML = 'Erreur';
												$('bouton_pitch_news_'+id_news).style.display = 'block';
											}
										},
							onFailure : function()
										{
											$('erreur_pitch_news_'+id_news).innerHTML = 'Erreur';
											$('bouton_pitch_news_'+id_news).style.display = 'block';
										},
							onComplete : function(transport) { $('details-news-loading_'+id_news).style.display = 'none';}
						}).request();
	}
}

function proposerNews()
{
	if ($('proposer-news-loading'))
		$('proposer-news-loading').style.display = 'block';
	$('formulaire_proposer_news').set('send',
									{
										encoding : 'ISO-8859-15',
										onSuccess : function(transport)
										{
											finirProposerNews(); // a définir dans la skin
										},
										onComplete : function() {if ($('proposer-news-loading')) $('proposer-news-loading').style.display = 'none';}
									});
	$('formulaire_proposer_news').send();
}

function proposerFeedback()
{
	var id_membre = $('champ_id_membre_feedback') ? $('champ_id_membre_feedback').value : '';
	var email = $('champ_email_feedback') ? $('champ_email_feedback').value : '';
	var url = window.location.href; //$('champ_url_feedback').value;
	var titre = $('champ_titre_feedback').value;
	var texte = $('champ_texte_feedback').value;
	var id_site = $('champ_id_site_feedback').value;

	$('proposer-feedback-loading').style.display = 'block';
	new Ajax('?action=feedback',
					{
						method : 'post',
						encoding : 'ISO-8859-15',
						data : 'id_membre='+id_membre+'&email='+email+'&url='+url+'&titre='+escape(titre)+'&description='+escape(texte)+'&id_site='+id_site,
						onSuccess : function()
									{
										$('proposer-feedback-loading').style.display = 'none';
										finirProposerFeedback(); // a définir dans la skin
									}
					}
	).request();
}


pop_up = '';

function popUp(url)
{
//	if (pop_up != url)
//	{ // on charge la page
		$('pop-up').innerHTML = '';

		showPopUp();

		$('pop-up-loading').style.display = 'block';

		new Request.HTML(
			{
				url : url,
				update : $('pop-up'),
				evalScripts : true,
				onSuccess : function()
							{
								pop_up = url;
							},
				onFailure : function()
							{
								hidePopUp();
							},
				onComplete : function()
							{
								$('pop-up-loading').style.display = 'none';
							}
			}	
		).send();
//	}
//	else // pas besoin de recharger la page
//		showPopUp();
}

function showPopUp()
{
	// on masque la pub :
	afficherPub('off');

	// on affiche le masque
	$('masque').style.display = 'block';


	// et enfin, le pop-up
	$('pop-up').style.display = 'block';

	window.location.replace('#pop-up');
}
function hidePopUp()
{

	$('pop-up-loading').style.display = 'none';
	
	$('pop-up').style.display = 'none';

	$('masque').style.display = 'none';

	// on remet la pub :
	afficherPub('on');
}


function afficherPub(on)
{
	if (on=='on')
		display = 'visible';
	else
		display = 'hidden';

	if ($('leaderboard'))
		$('leaderboard').setStyle('visibility', display);
	if ($('pub-rectangle'))
		$('pub-rectangle').setStyle('visibility', display);
	if ($('skycrapper'))
		$('skycrapper').setStyle('visibility', display);

}

function popUpScreen(e)
{
	// caca : on ne fait le popup que si le lien pointe vers une image
	if (!(e.target.getParent().href.contains('.jpg')
        || e.target.getParent().href.contains('.jpeg')
        || e.target.getParent().href.contains('.png')
        || e.target.getParent().href.contains('.gif')
		))
		return;

	e = new Event(e);
	e.stop();


	var position = e.target.getPosition();

	var div;

	var div = new Element('div');
	div.addClass('loading_popup_screen');
	div.setStyle('top', position.y);
	div.setStyle('left', position.x);
	div.setStyle('width', e.target.offsetWidth);
	div.setStyle('height', e.target.offsetHeight);
		
	$$('body').adopt(div);


	var container_div = new Element('div');
	container_div.addClass('popup_screen');
	container_div.setStyle('top', position.y);
	container_div.setStyle('left', position.x);
	container_div.setStyle('opacity', 0);
	var close_button = new Element('div');
	close_button.title=':: Fermer l\'image';
	new Tips(close_button, {className : 'tooltip'});
	close_button.addClass('popup_screen_fermer');
	close_button.addEvent('click', closeScreenPopUp);
	container_div.adopt(close_button);

	var fullscreen_button = new Element('div');
	fullscreen_button.title=':: Voir l\'image en taille réelle';
	new Tips(fullscreen_button, {className : 'tooltip'});
	fullscreen_button.addClass('popup_screen_fullscreen');
	fullscreen_button.addEvent('click', function(e) { e=new Event(e); e.stop(); window.open(url_image); closeScreenPopUp(e)} );
	container_div.adopt(fullscreen_button);

	var resize_button = new Element('div');
	resize_button.title=':: Redimensionner l\'image';
	new Tips(resize_button, {className : 'tooltip'});
	resize_button.addClass('popup_screen_resize');
	container_div.adopt(resize_button);

	container_div.makeResizable({handle : resize_button});
		
	$$('body').adopt(container_div);
	
	var data = {position : 'center', moyenature : e.target.getParent().href};

	if (e.target.getParent().rel)
		data = JSON.decode(e.target.getParent().rel);

	if (!data.position)
		data.position = 'center';

	var image = new Element('img');

	var url_image = e.target.getParent().href; 
	image.addClass('screen_preview');
	if(e.target.title)
	{
		image.title = e.target.title + ' :: ';
		new Tips(image, {maxTitleChars : 200, className : 'tooltip'});
	}

	image.addEvent('load', function()
				{
					div.dispose();

					var max_width = 700;

					var to_width = this.width <= max_width ? this.width : max_width;
					var to_height = this.width <= max_width ? this.height : this.height*max_width/this.width;

					var from_x = position.x;
					var from_y = position.y;
					var center_x = from_x - to_width/2 +  e.target.offsetWidth/2;
					var center_y = from_y - to_height/2 +  e.target.offsetHeight/2;

					switch(data.position)
					{
						case 'nw' :
							to_x = from_x;
							to_y = from_y;
						break;
						case 'n' :
							to_x = center_x;
							to_y = from_y;
						break;
						case 'ne' :
							to_x = from_x - to_width + e.target.offsetWidth;
							to_y = from_y;
						break;
						case 'e' :
							to_x = from_x - to_width + e.target.offsetWidth;
							to_y = center_y;
						break;
						case 'se' :
							to_x = from_x - to_width + e.target.offsetWidth;
							to_y = from_y - to_height + e.target.offsetHeight;
						break;
						case 's' :
							to_x = center_x;
							to_y = from_y - to_height + e.target.offsetHeight;
						break;
						case 'sw' :
							to_x = from_x;
							to_y = from_y - to_height + e.target.offsetHeight;
						break;
						case 'w' :
							to_x = from_x;
							to_y = center_y;
						break;
						case 'center' :
						default :
							to_x = center_x;
							to_y = center_y;
						break;
					}
					
					container_div.adopt(this);

					var pos = this.getCoordinates()
					this.setStyle('width', e.target.offsetWidth);
					this.setStyle('height', e.target.offsetHeight);

					new Fx.Morph(container_div, {duration : 400, transition : Fx.Transitions.Quad.easeOut}).start(
						{
							'left' : to_x, 
							'top' : to_y,
							'opacity' : 1});
					new Fx.Morph(this, {duration : 400, transition : Fx.Transitions.Quad.easeOut}).start(
						{
							'width' : to_width, 
							'height' : to_height
							});
				});
	image.src = data.moyenature;
	image.makeResizable({handle : resize_button});
	new Drag(container_div, {handle : image});
			
}
function closeScreenPopUp(e)
{
	e = new Event(e);
	e.stop();
		
	new Fx.Tween(e.target.getParent(), 'opacity', {onComplete : function() {e.target.getParent().dispose();e.target.dispose()} }).start(0);
	$$('.tooltip-tip').dispose();
	
	cacherPubs('block');
}

function thisIsNew(element)
{
	var sign = new Element('div');
	sign.setStyle('position', 'absolute');
	var size = element.getPosition();
	sign.setStyle('left', size.x-25); 
	sign.setStyle('top', size.y-42);
	sign.setStyle('opacity', '0');
	sign.addClass('new_sign');
	sign.addEvent('click', function(e) {this.setStyle('display', 'none');});
	$$('body').adopt(sign);
			
	var blink = new Fx.Tween(sign, 'opacity');
	blink.set('duration', 'short');
	blink.start(0,1).chain(
	function(){ this.start(1,0); },
	function(){ this.start(0,1); },
	function()
	{
		var fadeout = function() { sign.fade('out'); };
		fadeout.delay(5*1000);
	}
	);			
}


// GROSSSSSSSE Bidouille pour activer les activeX sous IE....
// Get all objects from the page as an array
var aTechsourceObjects = document.getElementsByTagName('object');
var iObjectsCounter;

// This function waits until the document is ready and then activates the objects
function TechsourceWaitReadyStateIsComplete() {
  // Is the document loaded, parsed and ready?
  if( document.readyState != 'complete' ) {
    // No, wait a bit more
    self.setTimeout( "TechsourceWaitReadyStateIsComplete()", 100 );
  } else if( iTechsource != 1 ) {
    iTechsource = 1;
    // Loop on objects
    for( iObjectsCounter = 0; iObjectsCounter < aTechsourceObjects.length; iObjectsCounter++ ) {
      // Check if it's a techsource generated object
//      if( aTechsourceObjects[iObjectsCounter].id.substring(0,11) == 'techsource_' ) {
        // Reassign the outerHTML code to itself
        aTechsourceObjects[iObjectsCounter].outerHTML=aTechsourceObjects[iObjectsCounter].outerHTML;
//      }
    }
  }
}
//if( navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 ) {
//  TechsourceWaitReadyStateIsComplete();
//}

var iTechsource = 0;
