///////////////////////////////////////////////
// spamCle@ner.net JS - (c)2005-2006 Jerome Bruandet
// http://spamcleaner.net
///////////////////////////////////////////////
// Affiche les erreurs sur page index lors du login:

var sc_version = '1.30 - 15-05-2009';

function get_error() {
	var error= document.location.href.split('?')[1];
	if ((!error)|| (error == 'sp')){ return;}
	var code = new RegExp(/^LOGIN_ERROR\d{2}/);
	var session = new RegExp(/^\d{1,2}$/);
	if (error == 'NO_COOKIE') {
		document.write('<span style="background-color:red ;color:white;font-size: 10px;">Vous devez activer les cookies<br>pour vous connecter !</span>');
	} else if (error.match(session)) {
		document.write('<span style="background-color:red ;color:white;font-size: 10px;">Votre session a expiré car votre compte est resté inactif pendant plus de '+error+'mn.</span>');
	} else if (error.match(/LOGIN_ERROR\d{2}/)) {
		num=error.slice(11,13);
		document.write('<span style="background-color:red ;color:white;font-size: 10px;">Erreur d\'itentification ('+num+') !');
		document.write('<br>Mot de passe perdu ? <a style="color:white;" class=links href="https://spamcleaner.net/password.html">[cliquez ici]</a></span>');
	}else if (error.match(/^[a-zA-Z][a-zA-Z0-9_]{5,11}$/)){
		document.write('<input type=hidden name=un value='+error+'>');
	} else {
		document.write('<span style="background-color:red ;color:white;font-size: 10px;">Erreur d\'itentification !');
		document.write('<br>Mot de passe perdu ? <a style="color:white;" href="https://spamcleaner.net/password.html">[cliquez ici]</a></span>');
	}
}

///////////////////////////////////////////////
// Affiche une table blanche et/ou le petit logo et/ou le copyright:
function version(table,image,copyright) {
	var ct = new Date();
	var cy = ct.getFullYear();
	var path = "http://spamcleaner.net/fr/";
//	var path = 'http://'+self.location.host+'/';
	if (table) {
		document.write('<table style="border: 1px solid #666666;" bgcolor="white" cellpadding=3 cellspacing=0 width="100%">');
		document.write('<tr><td>');
	}
	if (image) {
		document.write('<center><img src="'+path+'gif/sclogosmall.gif" width="210" height="35"></center>');
	}
	if (copyright) {
		document.write('<center><font class="tinyblack">')
		document.write('&copy;2006-'+cy+' spamCle@ner - Jérôme Bruandet');
		document.write(' - <a class=links href="https://spamcleaner.net/contact.html">[contact]</a><br>');
		document.write('<a class=links href="javascript:popup(\''+path+'update.html\',640,480)">[version: '+sc_version+']</a></font></center>');
	}
	if (table) {
		if ((!image) & (!copyright)) {
			document.write('&nbsp;');
		}
		document.write('</td></tr></table>');
	}
}
//////////////////////////////////////////////////////////////
// Verifie que les noms et passwd ont ete entres correctement:
function check_login() {
	var invalid = new RegExp (/^[a-zA-Z][a-zA-Z0-9_]{5,11}$/);
	var space = new RegExp (/\x20/);
	if ((!document.login.username.value) && (!document.login.password.value)) {
		alert("Vous devez entrer vos nom d'utilisateur et mot de passe !");
		document.login.username.focus();
		return false;
	} else if (!document.login.username.value) {
		alert("Vous devez entrer votre nom d'utilisateur !");
		document.login.username.focus();
		return false;
	}else if (! document.login.username.value.match(invalid)){
		alert("Le nom d'utilisateur ["+document.login.username.value+"] est invalide !");
		document.login.username.focus();
		return false;
	} else if (!document.login.password.value) {
		alert("Vous devez entrer votre mot de passe !");
		document.login.password.focus();
		return false;
	}else if ( (document.login.password.value.match(space)) ||
		(document.login.password.value.length<6) || (document.login.password.value.length>12)){
		alert("Le mot de passe est invalide !")
		document.login.password.focus();
		return false;
	} else {
		document.getElementById('01').innerHTML="&nbsp;&nbsp;<img src='"+pic1.src+"' border=0>";
		document.cookie='spamcleaner=check_cookie; path=/; domain=.spamcleaner.net';
		return true;
	}
}
///////////////////////////////////////////////
// Affiche une fenetre pop-up
// scroll_bar: 0=oui, 1=non ;P
function popup(url,width,height,scroll_bar) {
	height=height+20;
	width=width+20;
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		if (scroll_bar) {
			str += ",scrollbars=no";
		}else {
			str += ",scrollbars=yes";
		}
		str += ",status=no,location=no,resizable=yes";
	}
	win = open(url, 'SpamScleaner', str);
	// delais de 1.3 secondes avant deffectuer un focus sur la fenêtre popup:
	setTimeout("win.window.focus()",1300);

}
///////////////////////////////////////////////
// Affiche la formulaire de connexion uniquement si JavaScript est active:
function login_form(){
	document.write("<table width=100% border=0 cellpadding=1 cellspacing=1>");
	document.write("<tr>");
	document.write("<td style='text-align:left;' class=tiny2black>Utilisateur</td><td>:</td>");
	document.write("<td class=tiny2black><input class=input size=16 type=text name=username maxlength=12></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td style='text-align: left;' class=tiny2black>Mot de passe</td><td>:</td>");
	document.write("<td class=tiny2black><input class=input size=16 type=password name=password maxlength=12></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td class=left>");
	document.write("<font class=tiny2black>");
//	document.write("<a class=links href='https://spamcleaner.net' target=_top>[Accès sécurisé]</a>");
document.write("<a href='https://spamcleaner.net/' target=_top><img border=0 src='gif/ssl.png' align=absbottom title='Accès sécurisé SSL'></a>");
	document.write("</font>");
	document.write("</td>");
	document.write("<td>&nbsp;</td>");
	document.write("<td align='left'>");
	document.write("<div id=01><input style='width:91px;font-size: 10px' class=button type=submit value='Entrer'></div>");
	document.write("</td>");
	document.write("</tr>");
	document.write("</table>");
	if (document.login.un){
		document.login.username.value=document.login.un.value;document.login.password.focus();
	}else{
		// rien de pire que les sites qui font un focus sur le champ du nom
		// alors que l'utilisateur est deja en train de taper son pass :p
		if (!document.login.username.value) {document.login.username.focus()}
	}
}
//////////////////////////////////////////////////
// Share :
var URL = location.href;
if (location.href.search("\\?") != -1) {
	URL = location.href.split("?")[0];
}

function Delicious() {
	var Title=document.getElementById('titre').innerHTML;
	popup('http://del.icio.us/post?url='+encodeURIComponent(URL)+'&title='+encodeURIComponent(Title), 650, 500, 0);
}
function Furl() {
	var Title=document.getElementById('titre').innerHTML;
	popup('http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(URL)+'&t='+encodeURIComponent(Title), 650, 500, 0);
}
//function Digg() {
//	popup('http://digg.com/remote-submit?phase=2&url='+encodeURIComponent(URL)+'&title='+encodeURIComponent(Title), 650, 500, 0);
//}
function Google(){
	var Title=document.getElementById('titre').innerHTML;
	popup('http://google.com/bookmarks/mark?op=edit&bkmk='+encodeURIComponent(URL)+'&title='+encodeURIComponent(Title), 650, 500, 0);
}
function Yahoo() {
	var Title=document.getElementById('titre').innerHTML;
	popup('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(Title)+'&u='+encodeURIComponent(URL)+'&ei=UTF-8', 650, 500, 0);
}
function Facebook() {
	var Title=document.getElementById('titre').innerHTML;
	popup('http://www.facebook.com/sharer.php?u='+encodeURIComponent(URL)+'&t='+encodeURIComponent(Title), 650, 500, 0);
}
function Myspace(){
	var Title=document.getElementById('titre').innerHTML;
	popup('http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+encodeURIComponent(URL)+'&t='+encodeURIComponent(Title), 650, 500, 0);
}
function Twitter(){
	var Title=document.getElementById('titre').innerHTML;
	popup('http://twitter.com/home?status=Je+suis+sur+'+encodeURIComponent(URL), 650, 500, 0);
}
