function changeClass(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function doLogin(){
	Dialog.confirm($('login').innerHTML, {
		className:"alphacube",
		width:400,
		okLabel: "Go",
		cancelLabel: "Annuler",
		onOk:function(win){
			var login_login		= document.getElementById('login_login').value;
			var login_password	= document.getElementById('login_password').value;
			var login_form		= document.getElementById('login_form');
			if(login_login=='' || login_password==''){
				$('login_error_msg').innerHTML='Login ou mot de passe manquant';
				$('login_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				return false;
			}
			login_form.submit();
			return true;
		}
		}
	);
}

function doRegistration(){
	Dialog.confirm($('registration').innerHTML, {
		className:"alphacube",
		width:400,
		okLabel: "Suite",
		cancelLabel: "Annuler",
		onOk:function(win){
			var reg_login 		= document.getElementById('reg_login').value;
			var reg_email 		= document.getElementById('reg_email').value;
			var reg_password 	= document.getElementById('reg_password').value;
			var reg_password2 	= document.getElementById('reg_password2').value;
			var reg_form		= document.getElementById('registration_form');
		
			if(reg_login=='' || reg_password=='' || reg_email==''){
				$('password_error_msg').innerHTML='Erreur : informations manquantes';
				$('password_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				return false;
			}
			
			if(!alphanumeric(reg_login)){
				$('password_error_msg').innerHTML='Erreur : le login ne peut contenir que des chiffres et des lettres';
				$('password_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				document.getElementById('reg_login').value = '';
				return false;
			}
			
			if(!verificationEmail(reg_email)){
				$('password_error_msg').innerHTML='Erreur : adresse email non valide';
				$('password_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				document.getElementById('reg_email').value = '';
				return false;
			}
			

			if(reg_password != reg_password2){
				$('password_error_msg').innerHTML='Erreur : les 2 mots de passes sont diff&eacute;rents';
				$('password_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				return false;
			}
			
			reg_form.submit();
			return true;
		}
		}
	);
}

function doPassword(){
	Dialog.confirm($('password').innerHTML, {
		className:"alphacube",
		width:400,
		okLabel: "Go",
		cancelLabel: "Annuler",
		onOk:function(win){
			var password_email	= document.getElementById('password_email').value;
			var password_login	= document.getElementById('password_login');
			var password_form	= document.getElementById('password_form');
			if(password_email=='' || password_login==''){
				$('password_error_msg').innerHTML='Login ou adresse email manquant';
				$('password_error_msg').show();
				Windows.focusedWindow.updateHeight();
				new Effect.Shake(Windows.focusedWindow.getId());
				return false;
			}
			password_form.submit();
			return true;
		}
		}
	);
}


function doSendMessage(sendTo){
	var send_msg = new Window(
		{
		className: "alphacube",
		width:500,
		height:470,
		minimizable:false,
		maximizable:false,
		resizable: false,
		url: "http://shakelist.com/envoyer-message.php?sendTo=" + sendTo/*,
		showEffectOptions: {duration:1.5;};*/
		}
	);
	send_msg.showCenter();
}

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function verificationEmail(email){
	if (email.indexOf("@") != "-1" &&
		email.indexOf(".") != "-1" &&
		email != "")
		return true;
	
	return false;
}

function swapImgRestore() { 
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { 
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { 
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function resetVote(){
	swapImage('vote1','','/images/vote_off.jpg',1);
	swapImage('vote2','','/images/vote_off.jpg',2);
	swapImage('vote3','','/images/vote_off.jpg',3);
	swapImage('vote4','','/images/vote_off.jpg',4);
	swapImage('vote5','','/images/vote_off.jpg',5);
}