//AUTO LOAD
var docloaded = false;

function getId( id )
{
	if( !document.getElementById && document.all )
		return document.all[id];
	else
		return document.getElementById( id );
}
function get_ajax_object()
{
	var xhr_object = null;
	if(window.XMLHttpRequest)
	{
		xhr_object = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert( tchat_msg1 );
		return false;
	}
	return xhr_object;
}
function fun(value){
	if(value){
		getId('imgdv').src = value;
		getId('imgdv').style.width = '50px';
	}
}
function opacity(obj, value)
{
	obj.style.filter = "Alpha(Opacity = "+value+")";
	obj.style.opacity = value/100;
}
function quit( to )
{
	if( to === true )
	{
		to = window.location.href;
	}
	window.location.href = to;
}
function header(to)
{
	window.location.href = to;
}

/* div survol */
var snow = 0;
var x = 0;
var y = 0;
var offsety = 20;
var offsetx = 0;
var ie4 = (document.getElementById)?true:false;
var ns4 = (document.layers)?true:false;

var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var overDiv = null;

function init_lay()
{
	overDiv = getId('overDiv');
	if( document.layers )
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = mouseMove;
}
function mouseMove(e)
{
	if( snow == 1 )
	{
		if( !e )
		{
			var e = window.event;
		}
		if((document.documentElement && !is_ie) || is_ie)
		{
			x = e.clientX + document.documentElement.scrollLeft;
			y = e.clientY + document.documentElement.scrollTop;
		}
		else if(document.body)
		{
			x = e.x + document.body.scrollLeft;
			y = e.y + document.body.scrollTop;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}
		moveit( x+offsetx, y+offsety );
	}
}
function T(){ nd() }
function O(text){ dcc( text ) }
function nd()
{
	if( overDiv != null )
	{
		snow = 0;
		overDiv.style.display = "none";
	}
}
function dcc(txt)
{
	if( overDiv != null )
	{
		if( docloaded != true )
		{
			return false;
		}
		getId('overDiv').innerHTML = txt;

		if( snow == 0 )
		{
			moveit( x+offsetx, y+offsety );
			overDiv.style.display = "";
			snow = 1;
		}
	}
}
function user_tbl(login, age, pays, region)
{
	userTblHtml =
		'<table style="border:1px solid #000000" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="2">'+
		'<tr><td style="color:#000000"><b>'+login+'</b>, '+age+'</td></tr>';

	if( pays )
		userTblHtml += '<tr><td style="color:#000000">'+pays+'</td></tr><tr><td style="color:#000000">'+region+'</td></tr>';

	userTblHtml += '</table>';

	dcc( userTblHtml );
}
function info(tex)
{
	dcc( tex );
}
function moveit(xL,yL)
{
	overDiv.style.left = xL + 'px';
	overDiv.style.top = yL + 'px';
}

/***/

function ov(obj, cl)
{
	obj.className = cl;
}
function LimitLen(obj, carz, maxLength)
{
	var CharsLeft = 0;
	if (obj.value.length > maxLength)
	{
		obj.value = obj.value.substring(0, maxLength);
	}
	else
	{
		CharsLeft = maxLength - obj.value.length;
	}
	getId(carz).innerHTML = CharsLeft;
}
function CheckLen(obj, carz){
	var maxLength = 500;
	// récupère la valeur optionnelle de maxLength
	if(CheckLen.arguments.length == 3)
		maxLength = parseInt(CheckLen.arguments[2]);
	var cr = getId(carz);
	var CharsLeft = 0;
	if (obj.value.length > maxLength) {
		obj.value = obj.value.substring(0, maxLength);
	} else CharsLeft = maxLength - obj.value.length;
	cr.value = CharsLeft;
}
function CountLen(obj, carz)
{
	var cr = getId (carz);
	if (cr.tagName.toLowerCase () == 'span')
	{
		// ajout par Lou pour un compteur dans un SPAN
		cr.firstChild.nodeValue = obj.value.length;
	}
	else
	{
		cr.value = obj.value.length;
	}
}
// ------------------------------------------------------------------------
function toggle(targetId)
{
	//montre / cache un objet suivant son ID et son etat display
	target = getId( targetId );
	if (target.style.display == "none")
	{
		target.style.display = "";
	}
	else
	{
		target.style.display = "none";
	}
}

function toggle_s(targetId, status)
{
	//montre / cache un objet suivant son ID
	target = getId( targetId );
	if (status)
	{
		target.style.display = "";
	}
	else
	{
		target.style.display = "none";
	}
}

// COOKIE
function getCookieVal( offset )
{
	var endstr = document.cookie.indexOf( ";", offset );
	if( endstr == -1 )
	{
		endstr = document.cookie.length;
	}
	return unescape( document.cookie.substring( offset, endstr ) );
}
function getCookie( 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 setCookie( nom, valeur )
{
	var argv=setCookie.arguments;
	var argc=setCookie.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 dropCookie( nom )
{
	var date = new Date;
	date.setFullYear( date.getFullYear() - 1 );
	setCookie( nom, null, date );
}

function getTimeStamp()
{
	return Math.floor( new Date().getTime() / 1000 );
}

function addOnLoadEvent( func )
{
	if( typeof func == 'function' )
	{
		if( typeof window.onload != 'function' )
		{
			window.onload = func;
		}
		else
		{
			var oldOnload = window.onload;
			window.onload = function()
			{
				oldOnload();
				func();
			}
		}
	}
}
function load_func()
{
	init_lay();
	docloaded = true;
}

// Retourne un objet de type swf :
function getMovie( movieName )
{
     if ( navigator.appName.indexOf( "Microsoft" ) != -1 )
	 {
          return window[movieName];
     }
     else
	 {
          return document[movieName];
     }
}

function ezIndexOf(array, val)
{
	var length = array.length;
	var qsdf;
	for(qsdf = 0; qsdf < length; qsdf++)
	{
		if(array[qsdf].value == val)
		{
			return qsdf;
		}
	}
	return -1;
}

function shuffle(a, b)
{
	return ( Math.round(Math.random())-0.5 );
}

function printDiv( divId, width, height )
{
	var printWindows = window.open( "","printWindows", "toolbar=0,menubar=0,location=0,directories=0,resizable=1,width="+width+",height="+height+"" );
	printWindows.document.open();
	printWindows.document.write( getId( divId ).innerHTML );
	printWindows.document.close();
	printWindows.print();
}
function myDcc(titre,message)
{
	dcc ( '<div style="width: auto; padding:2px;"><b>'+titre+'</b><br>'+message+'</span>' );
}
function myDcc2(message)
{
	dcc ( '<div style="width: auto;">'+message+'</div>' );
}
function disable_return( e )
{
	if(window.event)
	{
		if (window.event.type == "keypress" && window.event.keyCode == 13 ) return false;
	}
	if( e )
	{
		if( e.type == "keypress" && e.keyCode == 13) return false;
	}
}
function rand( mini, maxi )
{
    return Math.floor( Math.random() * (maxi - mini + 1 ) ) + mini;
}
function getCssStyle( identifier )
{
	for( var sSheet = document.styleSheets.length - 1; sSheet >= 0; sSheet-- )
	{
		try
		{
			var rulesList = document.styleSheets[sSheet].rules ? document.styleSheets[sSheet].rules : document.styleSheets[sSheet].cssRules;
			for( var rule = rulesList.length - 1; rule >= 0 ; rule-- )
			{
				// tag : td, class : .classname, id : #id
				if( rulesList[rule].selectorText == identifier )
				{
					return rulesList[rule].style;
				}
			}
		}
		catch (err)
		{
		}
	}
}
/* ---------------- LEFT MENU & ALERT BLOC ---------------- */
function timeToNow( time )
{
	var myTime = new Date();
	var myTimeNs = ((myTime.getTime()-myTime.getMilliseconds())/1000);
	var seconds = (myTimeNs - time);
	var nb = 0;
	var text = '';
	if( seconds < 60 )
	{
		text = trad_now;
	}
	else if( seconds < 3600 )
	{
		nb = Math.floor( seconds / 60 );
		text = (nb < 2 ? trad_oneminute : trad_minutes);
	}
	else if( seconds < 3600 * 24 )
	{
		nb = Math.floor( seconds / 3600 );
		text = (nb == 1 ? trad_onehour : trad_hours);
	}
	else if( seconds < 3600 * 24 * 7 )
	{
		nb = Math.floor( seconds / ( 3600 * 24 ) );
		text = (nb == 1 ? trad_oneday : trad_days);
	}
	else if( seconds <= 3600 * 24 * 30 )
	{
		nb = Math.floor( seconds / ( 3600 * 24 * 7 ) );
		text = (nb == 1 ? trad_oneweek : trad_weeks);
	}
	else
	{
		nb = Math.floor( seconds / ( 3600 * 24 * 30 ) );
		text = (nb == 1 ? trad_onemonth : trad_month);
	}
	return text.replace('<number>', nb);
}
function leftMenu( id5param )
{
	id5 = id5param;
	if (hasAlerts)
	{
		leftMenuProcess();
	}
	else
	{
		return false;
	}
}
function leftMenuProcess()
{
	dtelement = document.getElementById("leftMenu").getElementsByTagName('dt');
	for( var i = 0; i < dtelement.length; i++ )
	{
		dtelement[i].style.marginTop = '0px';
		if (dtelement[i].firstChild.nodeName == 'DIV')
		{
			if (isOldIE)
			{
				dtelement[i].style.cursor = 'hand';
			}
			else
			{
    			dtelement[i].style.cursor = 'pointer';
			}
			dtelement[i].firstChild.innerHTML = '&raquo;';
			dtelement[i].firstChild.style.float = 'right';
		}
	}
	var countElm = 0;
	delement = document.getElementById("leftMenu").getElementsByTagName('dd');
	for( var i = 0; i < delement.length; i++ )
	{
		delement[i].style.display = 'none';
		if (delement[i].className.indexOf(id5) != -1)
		{
			delement[i].style.display = '';
			countElm++;
		}
	}
	totalHeight = (dispoHeight-((nombTitreMenu*20)+(countElm*oneElmHeight)));
	document.getElementById('alertesMenuList').style.height = totalHeight+'px';
}
function leftMenuExpandAll()
{
	dtelement = document.getElementById("leftMenu").getElementsByTagName('dt');
	for( var i = 0; i < dtelement.length; i++ )
	{
		dtelement[i].style.marginTop = '4px';
		if (dtelement[i].firstChild.nodeName == 'DIV')
		{
			dtelement[i].style.cursor = 'default';
			dtelement[i].firstChild.innerHTML = '';
		}
	}
	delement = document.getElementById("leftMenu").getElementsByTagName('dd');
	for( var i = 0; i < delement.length; i++ )
	{
		delement[i].style.display = '';
	}
}
function getMenuAlerts()
{
	if( typeof(parent.topFrame) != 'undefined' && typeof(parent.topFrame.alertes) != 'undefined' && parent.topFrame.alertes.length > 0 )
	{
		hasAlerts = true;
		document.getElementById('alertesMenuListBloc').style.display = '';
		leftMenuProcess();
		var alerte = '';
		var list = '';
		var imgalert = '';
		var alertTime = new Date();
		var currentTime = new Date();
		var dateExp = 0;
		var heure;
		for( var i = parent.topFrame.alertes.length - 1; i >= 0; i-- )
		{
			alerte = parent.topFrame.alertes[i];
			alertTime.setTime( alerte['time'] );
			dateExp = (parseInt(alerte['time']) + 60);
			if (dateExp > ((currentTime.getTime()-currentTime.getMilliseconds())/1000))
			{
				imgalert = '<img class="AtFh" src="/img/pix55bright.gif"/>';
			}
			else
			{
				imgalert = '';
			}
			heure = timeToNow(alertTime.getTime());
			list +=
				'<div class="bgdark AtP">'+
					'<div class="AML bglight" style="background-image:url(/img/speedflirt/i_'+alerte['type']+'.png)" onmouseover="this.className=\'bgdark AML\'" onmouseout="this.className=\'bglight AML\'" onclick="document.location.href=\'/u_page.php?id='+alerte['user_id']+'\'">'+
						'<div class="border AtUI" style="background-image:url(' + alerte['user_img'] + ')">'+imgalert+'</div>'+
						'<div style="overflow:hidden" title="' + alerte['user_login'] + '"><b>' + alerte['user_login'] + '</b></div>' +
						'<div onmouseout="nd();" onmouseover="myDcc2(\''+alerte['title']+'\');">'+alerte['age'] + '</div>' +
						'<div class="UVL" title="'+alerte['town']+'">'+alerte['town']+'</div>' +
						'<div class="UTTN">'+heure+'</div>'+
					'</div>'+
				'</div>';
		}
		$('alertesMenuList').innerHTML = list;
	}
	else
	{
		leftMenuExpandAll();
	}
}
var isOldIE = 0;
if (navigator.appVersion.indexOf("MSIE")!=-1)
{
	var isOldIEtemp = navigator.appVersion.split("MSIE")
	if (parseFloat(isOldIEtemp[1]) <= 5.5)
	{
		isOldIE = 1;
	}
}
/* ---------------- END - LEFT MENU & ALERT BLOC ---------------- */

/* ---------------- Convertir les couleurs en hexa pour les swf ---------------- */

function rgb2hex( ColorString )
{
	HexDigits = "0123456789abcdef";
	if (ColorString.charAt(0) == '#') return ColorString.substring( 1 );
	else
	{
		ColorString = ColorString.substr(4);
		pos = ColorString.indexOf(',');
		Result = HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
		ColorString = ColorString.substr(pos + 1);
		pos = ColorString.indexOf(',');
		Result = Result + HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
		ColorString = ColorString.substr(pos + 1);
		Result = Result + HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
		return Result;
	}
}



addOnLoadEvent( load_func );