//For preloading


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_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;
}

//For opening pop up

function popinscription() {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppins=window.open('inscription.do','ppins','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppins.focus();
}

function popmotoublie() {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppmo=window.open('motoublie.do','ppmo','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppmo.focus();
}

function popprofil() {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppprof=window.open('profil.do','ppprof','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppprof.focus();
}

function popnewforum() {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppnf=window.open('newforum.do','ppnf','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppnf.focus();
}

function popmodforum(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppmf=window.open('modforum.do?id='+id,'ppmf','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppmf.focus();
}

function popnewsujet(fid) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppns=window.open('newsujet.do?fid='+fid,'ppns','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppns.focus();
}

function popmodsujet(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppms=window.open('modsujet.do?id='+id,'ppms','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppms.focus();
}

function popnewmessage(tid,mid,fid) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppnm=window.open('newmessage.do?tid='+tid+'&mid='+mid+'&fid='+fid,'ppnm','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppnm.focus();
}

function popmodmessage(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppmm=window.open('modmessage.do?id='+id,'ppmm','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppmm.focus();
}

function popemail(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppem=window.open('email.do?id='+id,'ppem','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppem.focus();
}

function popconditions() {
    var w=290;
    var h=286;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppcon=window.open('conditions.do','ppcon','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppcon.focus();
}

function popnotmail() {
    var w=290;
    var h=286;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppne=window.open('notmail.do','ppne','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppne.focus();
}

function popmailforum() {
    var w=290;
    var h=286;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppmf=window.open('mailforum.do','ppmf','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppmf.focus();
}

function popnotification() {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppnot=window.open('notification.do','ppnot','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppnot.focus();
}

function popsupforum(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppsf=window.open('supforum.do?id='+id,'ppsf','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppsf.focus();
}

function popsupsujet(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppss=window.open('supsujet.do?id='+id,'ppss','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppss.focus();
}

function popsuptxtsujet(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppsts=window.open('suptxtsujet.do?id='+id,'ppsts','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppsts.focus();
}

function popsupmessage(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppsm=window.open('supmessage.do?id='+id,'ppsm','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppsm.focus();
}

function popsuputilisateur(id) {
    var w=576;
    var h=317;
    var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
    var ppsu=window.open('suputilisateur.do?id='+id,'ppsu','width='+w+',height='+h+',top='+topPosition+',left='+leftPosition+',scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no');
    ppsu.focus();
}


function valNumPag(form,max) {
    if(isIntegerInRange(form.n.value,1,max)) {
        return true;
    } else {
        alert("Veuillez introduire le numéro de la page");
        return false;
    }
}

//For validating form

var whitespace = " \t\n\r";

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
    var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}
  
function isEmail(s) {
  if (isWhitespace(s))
    return false;

  // there must be >= 1 character before @, so we start
  // start looking at character position 1 (i.e. second character)
  var i = 1;
  var sLength = s.length;

  // look for @
  while ((i < sLength) && (s.charAt(i) != "@"))
    i++

  if ((i >= sLength) || (s.charAt(i) != "@"))
    return false;
  else
    i += 2;

  // look for .
  while ((i < sLength) && (s.charAt(i) != "."))
    i++

  // there must be at least one character after the .
  if ((i >= sLength - 1) || (s.charAt(i) != "."))
    return false;
  else
    return true;
}

function isDigit(c) {
  return ((c >= "0") && (c <= "9"));
}

function isInteger(s) {
  if (isWhitespace(s))
    return false;

  // skip leading + or -
  if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
    var i = 1;
  else
    var i = 0;

  // Search through string's chars one by one until we find a
  // non-numeric char, then return false; if we don't, return true
  for (i; i<s.length; i++)  {
    // Check that current character is number
    var c = s.charAt(i);
    if (!isDigit(c))
      return false;
  }
  // All characters are numbers
  return true;
}

function isIntegerInRange (s, a, b) {
  if (isWhitespace(s))
    return false;
  if (!isInteger(s))
    return false;
  var num = parseInt(s);
  return ((num >= a) && (num <= b));
}

