function verifSort( titre, ecole, portee, composante, duree, ze, jds, descrip ) {
  // Renvoi faux si un des attributs de sorts sont vides !
  var msg = "";
  var notvalid = false;
  if( notvalid = checkSpace( titre ) || notvalid ) msg += "Veuillez remplir le champ titre\n";
  if( notvalid = checkSpace( ecole ) || notvalid ) msg += "Veuillez remplir le champ école\n";
  if( notvalid = checkSpace( portee ) || notvalid ) msg += "Veuillez remplir le champ portée\n";
  if( notvalid = checkSpace( composante ) || notvalid ) msg += "Veuillez remplir le champ composantes\n";
  if( notvalid = checkSpace( duree ) || notvalid ) msg += "Veuillez remplir le champ durée\n";
  if( notvalid = checkSpace( ze ) || notvalid ) msg += "Veuillez remplir le champ zone d'effet\n";
  if( notvalid = checkSpace( jds ) || notvalid ) msg += "Veuillez remplir le champ jet de sauvegarde\n";
  if( notvalid = checkSpace( descrip ) || notvalid ) msg += "Veuillez remplir le champ description\n";
  if( notvalid )
    alert( msg );
  return !notvalid;
}

function checkSpace( str ) {
  var space = ' ';
  var tab = '\t';
  var nbSpace = 0;
  var nbTab = 0;
  for( i=0; i < str.length; i++ ) {
    switch( str.charAt( i ) ) {
    case space : nbSpace++; break;
    case tab : nbTab++; break;
    default : break;
    }
  }
  if( ( nbSpace + nbTab ) == str.length )
    return true;
  // else
  return false;
}

function checkemail( mail ){
  var filter=/^.+@.+\..{2,3}$/;

  if( !filter.test( mail ) )
    return "L'adresse mail n'est pas valide !\n";
    
  return "";
}

function CheckDate(d) {
	// Cette fonction vérifie le format AAAA/MM/JJ saisi et la validité de la date.
	// Le séparateur est défini dans la variable separateur
	var amin=1900;  // année mini
	var amax=2100;  // année maxi
	var separateur="-"; // separateur entre jour/mois/annee
	var a=(d.substring(0,4));	
	var m=(d.substring(5,7));
	var j=(d.substring(8));
	var ok="";
	if ( ((isNaN(j))||(j<1)||(j>31)) ) {
		ok += "Le jour n'est pas correct.\n";
	}
	if ( ((isNaN(m))||(m<1)||(m>12)) ) {
		ok += "Le mois n'est pas correct.\n";
	}
	if ( ((isNaN(a))||(a<amin)||(a>amax)) ) {
		ok += "L'année n'est pas correcte.\n";
	}
	if ( ((d.substring(4,5)!=separateur)||(d.substring(7,8)!=separateur)) ) {
		ok += "Les séparateurs doivent être des "+separateur+"\n";
	}
	if (ok=="") {
		var d2=new Date(a,m-1,j);
		j2=d2.getDate();
		m2=d2.getMonth()+1;
		a2=d2.getYear(); 
		if (a2<=100) {a2=1900+a2}
		if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
			ok += "La date "+d+" n'existe pas !\n";
		}
	}
	return ok;
}

function fVerifier( genre, surnom, mail, code, codeDeux, neLe, motivation ) {
  var msg = '';
 
  if( neLe )
    msg += CheckDate( neLe );

  if( neLe == '0000-00-00' || checkSpace( neLe ) )
    msg += "La date de naissance est obligatoire !\n";

  if( checkSpace( surnom ) )
    msg += "Le pseudo est obligatoire !\n";

  if( checkSpace( mail ) )
    msg += "Le mail est obligatoire !\n";
  else
    if( checkemail( mail ) )
      msg += "Le mail est incorrect !\n";

  if( genre != 'M' && genre != 'F' && genre != "" )
    msg += "Genre représente votre sexe : M pour homme, F pour femme\n ou rien si vous ne voulez pas le présiser.\n";

  if( code.length > 13 || code.length < 6 )
    msg += "Le code doit faire entre 6 et 13 caractères !\n";

  if( code != codeDeux )
    msg += "Le code et sa confirmation sont différents.\n";

  if( mail.length > 75 )
    msg += "Impossible de mémoriser l'e-mail car trop long.\n";
  
  if( checkSpace( motivation ) )
    msg += "Les motivations sont obligatoires !\n";

  if( msg.length ) {
    alert( msg );
    return false;
  }
  // Else
  return true;
}

function fTestPerso( code, neeEn, mail ) {
  msg = '';
  
  if( code.length > 13 || code.length < 6 )
    msg += "Le code doit faire entre 6 et 13 caractères !\n";
  
  if( neeEn )
    msg += CheckDate( neeEn );

  if( mail )
    msg += checkemail( mail );
  else
    msg += "Le mail est obligatoire !\n";

  if( msg.length ) {
    alert( msg );
    return false;
  }
  return true;
}

function show(){
if (!document.all&&!document.layers)
  open('index?width=800&height=600', '_parent');
var url = 'index.php?width=' + screen.width + '&height=' + screen.height;
open( url, '_parent', 'scrollbars=no');
}

function send(){

	if (document.UserInfo.NICKNAME.value == null || document.UserInfo.NICKNAME.value == "")   {
		window.alert("Le pseudo est obligatoire !")
		return false
	}

	var USERNICK = document.UserInfo.NICKNAME.value

	win=window.open("","IRC","resizable=no,height=320,width=500")
	win.document.write('<html><head><title>Chat Client</title></head>')
	win.document.write('<body bgcolor="#C0C0C0">')	

//	win.document.write('<applet archive="./chatIRC/jirc_nss.zip" code=Chat.class width=490 height=300 >')

	win.document.write('<applet codebase="./chatIRC/" archive="jirc_nss.zip,resources.cab" code="Chat.class" width=490 height=300 MAYSCRIPT >')         

	win.document.write('<param name="CABBASE" value="chatIRC/jirc_mss.cab">');
	win.document.write('<param name="ServerPort" value="6667">')
	win.document.write('<param name="ServerName1" value="de.quakenet.org">')
	win.document.write('<param name="ServerName2" value="se.quakenet.org">')
	win.document.write('<param name="ServerName3" value="uk.quakenet.org">')
	win.document.write('<param name="Channel1" value="addfan">')
	win.document.write('<param name="AllowURL" value="true">')
	win.document.write('<param name="AllowIdentd" value="true">')
	win.document.write('<param name="WelcomeMessage" value="Bienvenue sur AddFan">')
	win.document.write('<param name="RealName" value="AddFan java client [http://www.addfan.com].">')
	win.document.write('<param name="NickName" value="'+USERNICK+'">')
	win.document.write('<param name="UserName" value="addfan">')
	win.document.write('<param name="isLimitedServers" value="true">')
	win.document.write('<param name="isLimitedChannels" value="true">')
	win.document.write('<param name="MessageCol" value="80">')
	win.document.write('<param name="BackgroundColor" value="100,132,181">')
	win.document.write('<param name="TextColor" value="black">')
	win.document.write('<param name="TextScreenColor" value="white">')    
	win.document.write('<param name="ListTextColor" value="blue">')
	win.document.write('<param name="ListScreenColor" value="white">')
	win.document.write('<param name="TextFontName" value="Helvetica">')
	win.document.write('<param name="TextFontSize" value="12">')
	win.document.write('<param name="DirectStart" value="true"> ')
	win.document.write('<param name="FGColor" value="black">')
	win.document.write('<param name="IgnoreLevel" value="0">') 

	// Attention ! Clef est pseudo relatif au site soit ici : www.addfan.com
	// Username : addfan (a koi y sert???)
	// Clef www.addfan.com / addfan
	win.document.write('<param name="LicenseKey" value="3639872787-822929318204-66888886550909171717148229293182041485239109-01349213340493449293777894566083136688779311198178679346936688888655090931281760831366881485064414043488">')

	win.document.write('</applet>')
	win.document.write('</body>')
	win.document.write('</html>')
	win.document.close()

	//document.location=document.referrer
	//document.location="intro.html"

	return true

}

function fVerifPerso( nom, classe, descriptionP, race, groupe ) {
  var strErr = ""
  if( checkSpace( nom ) )
    strErr += "Le nom de votre personnage est obligatoire\n";

  if( checkSpace( classe ) )
    strErr += "La classe de votre personnage est obligatoire\n";
    
  if( checkSpace( descriptionP ) )
    strErr += "La description de votre personnage est obligatoire\n";

  if( checkSpace( race ) )
    strErr += "La race de votre personnage est obligatoire\n";

  if( checkSpace( groupe ) )
    strErr += "Le groupe de votre personnage est obligatoire\n";
  
  if( strErr.length ) {
    alert( strErr );
    return false;
  }
  
  return true;
}

function MM_findObj(n, d) { //v3.0
  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=MM_findObj(n,d.layers[i].document); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function SetACookie( nom, valeur, heure ) {
  var Expiration = new Date() 
  Expiration.setTime (Expiration.getTime() + heure * (60*60*1000))
  document.cookie = nom + "=" + escape(valeur) + "; " + "expires=" + Expiration.toGMTString()
}

function CheckAll() {
  for (var i=0;i<document.forms['addSpellBook'].elements.length;i++) {
	var e = document.forms['addSpellBook'].elements[i];
	if ((e.name != 'spellAll') && (e.type=='checkbox')) {
	  e.checked = document.forms['addSpellBook'].spellAll.checked;
	}
  }
}

function CheckAll2() {
  for (var i=0;i<document.forms['supprSpellBook'].elements.length;i++) {
	var e = document.forms['supprSpellBook'].elements[i];
	if ((e.name != 'spellAll' && e.name != 'validMemo') && (e.type=='checkbox')) {
	  e.checked = document.forms['supprSpellBook'].spellAll.checked;
	}
  }
}
