function resetField(theObj,strDefault){
	var curentValue = theObj.value;
	if(curentValue == strDefault){
		theObj.value = '';
	}
	else {
		return;
	}
}

function confirm_supp_avatar(lien) {
	confirmation = confirm('Etes vous sur de vouloir supprimer votre avatar ?');
	if (confirmation) {
		document.location.href = lien;
	}
}

function open_win (id, url, w, h) {
	window.open(url, id, 'toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=' + w + ',height=' + h + ',top=100,left=100');
	return false;
}

function ltrim(str) {
	return str.replace(/^\s*/g,"")
}

var type_login = 'normal';
function switch_login_type () {
	if (type_login == 'normal') {
		type_login = 'openid';

		$('div_login_normal').hide();
		$('div_login_openid').show();

		$('type_login').innerHTML = "Login normal";
	}
	else {
		type_login = 'normal';

		$('div_login_openid').hide();
		$('div_login_normal').show();

		$('type_login').innerHTML = "Login OpenID";
	}
}

function switch_forum(id) {
	var url = $(id).options[$(id).selectedIndex].value;
	document.location.href = url;
}

function refresh_captcha() {
	ndate = new Date();
	nocache = ndate.getTime();

	$('refresh_captha').innerHTML = '<img style="float: left" src="/images/design/loading.gif" alt="Chargement" /><span style="font-weight: bold; display: block; margin-left: 23px">Chargement en cours...</span>';
	$('img_captcha').src = '/images/captcha.php?' + nocache;
	$('refresh_captha').innerHTML = '<a href="javascript:refresh_captcha();">Image illisible ?</a>';
}

var tabHighlight = new Array();

function fetchHighlight(id) {
	$('d' + id).innerHTML = '<div class="loading"><img style="float: left" src="/images/design/loading.gif" alt="Chargement" /><span style="font-weight: bold; display: block; margin-left: 23px">Chargement en cours...</span></div>';

	var content = $('h' + id).innerHTML;
	tabHighlight[id] = content;

	var handlerFunc = function(t) {
		// on récupère le commentaire
		var message = t.responseText;

		if (message.length == 0) {
			return false;
		}

		var textarea = '<textarea style="width: 99%; height: 150px; margin: 10px 0px 10px 5px">' + message + '</textarea>';

		$('h' + id).innerHTML = textarea;
		$('d' + id).innerHTML = '<a href="javascript:undoHighlight(' + id + ')">Annuler</a>';

		document.location = '#h' + id;
	}
	new Ajax.Request('/ajax/fetch_code.php', { method:'post', postBody:'content=' + encodeURIComponent(content), onSuccess:handlerFunc} );
}

function undoHighlight(id) {
	$('d' + id).innerHTML = '<div class="loading"><img style="float: left" src="/images/design/loading.gif" alt="Chargement" /><span style="font-weight: bold; display: block; margin-left: 23px">Chargement en cours...</span></div>';
	$('h' + id).innerHTML = tabHighlight[id];
	$('d' + id).innerHTML = '<a href="javascript:fetchHighlight(' + id + ')">Récupérer le code</a>';

	document.location = '#h' + id;
}
