rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
}

function rand(number) {
  return Math.ceil(rnd()*number);
}


function popupCentree(width, height, url, nomFenetre) {
 var sw = screen.width;
 var sh = screen.height;
 var x = (sw-width)/2;
 var y = (sh-height)/2;
 var settings = 'toolbar=NO,status=NO,resizable=NO,scrollbars=YES';
 var wh=',width='+width+',height='+height;
 var xy=',left='+x+',top='+y; 
 var fenetre = window.open(url, nomFenetre, settings+wh+xy);
 fenetre.focus();
 return true;
}

//------------------------------------------------
// Fonction permettant de verifier si le champ saisi est un numeric ou non
//------------------------------------------------
function isNumeric(strSaisie) {
	var iNumeric = 1;
	if (strSaisie != "") {
		for (i=0; i < strSaisie.length; i++)
			if (strSaisie.charAt(i) < '0' || strSaisie.charAt(i) > '9')
				iNumeric = 0;
		if (iNumeric == 1)
			return true;
	}
	return false;
}

function isNumerique(champ) {
   return isNumeric(champ.value);
}



function isDecimal(champ){
var iNumeric = 1;
var l_virg=0;
if (champ.value.length > 0) {
   for (i=0; i < champ.value.length; i++){
	if ((champ.value.charAt(i)<'0' || champ.value.charAt(i)>'9') 
             && (champ.value.charAt(i)!='.' && champ.value.charAt(i)!=',') )  iNumeric=0;
        if (champ.value.charAt(i)=='.' || champ.value.charAt(i)==',') l_virg++;        
   }         
   if (iNumeric == 1 && l_virg<=1 ) return true;
}
return false;
}



//---------------------------------------------------------------
// fonction permettant de verifier si des caractères blancs ont été saisis
// attention si retourne false = contient des blancs !!
//---------------------------------------------------------------
function isBlank(strSaisie) {
		var iSaisie = 0;
		var strBlank = "";		
		if (strSaisie != "") {
				for (i=0; i < strSaisie.length; i++){
					if (strSaisie.charAt(i) == ' '){
						iSaisie = 1;
					}
				}
			if (iSaisie == 1){
				return true;
			}else {
				return false;
			}
		}
		return false;
}

//---------------------------------------------------------------
// fonction permettant de verifier si une variable est un entier
//---------------------------------------------------------------
function isEntierPositif(num){
	return (num == parseInt(num, 10) && num > 0);
}


//---------------------------------------------------------------
// fonction qui retourne la chaine si sa longueur est comprise entre min et max
// arguments : chaine de caractères, longueur minimale, longueur maximale
//---------------------------------------------------------------
function verifierLongueurMot(chaine, min, max) {
  /**
   * Retourne la chaine si sa longueur est comprise entre min et max
   */
  if ( (chaine != "") && ((chaine.length < min) || (chaine.length > max)) ) {
    return false;
  }
  return true;
}



function fermer(){
 this.close();       
}



function popup(url){
  var w=300;
  var h=300;
  var top_pos=100;
  var left_pos=100;
      
  var wnd_popup = window.open(url, "", 
         "toolbar=no,location=0,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no" +
         ",width=" + w + ",height=" + h +
         ",top=" + top_pos + ",left=" + left_pos);
         
         
  if (!wnd_popup.opener) wnd_popup.opener=self;     
}

function callPopUp(pg_dest,zcode,zlib){
   url = escape(pg_dest) + "?ZCODE="+escape(zcode)+"&ZLIB="+escape(zlib);
   popup(url);  
}

function recupereCritere(crit){
  var url=this.location.href;

  var pos = url.indexOf(crit,0);

  if ( pos!=-1 ){
     pos+=crit.length+1; //=
     url=url.substring(pos,url.length);
     var posf = url.indexOf("&",0);
     if (posf==-1) posf=url.length;
     return url.substring(0,posf); 
 }else return "Erreur";    

} 

// Affiche les paramètres dans le formulaire
// de la page appelante
function retApp(code,lib){
   var critCode = recupereCritere('ZCODE');
   var crtLib = recupereCritere('ZLIB');     
   this.opener.document.forms[0].elements[critCode].value=code;
   this.opener.document.forms[0].elements[crtLib].value="("+code+") "+lib;  
   this.window.close();   
}

    //-----------------------------------------------
    // Affichage de la pop up identification
    //-----------------------------------------------
    function popupIdentification() {
     return popupCentree(520,150, '/Forum/Forum?controlerCode=CtlConsultation&requestCode=afficherIdentificationDepuisAccueil'+'&nocache='+rand(99999999),'identification');
    }


    //-----------------------------------------------
    // Affichage du formulaire d'inscription (internaute non existant)
    //-----------------------------------------------
    function formulaireInscription(){

 	    location.href="/Forum/Forum?controlerCode=CtlInscription&requestCode=afficherFormulaireInscription";

    }
    //-----------------------------------------------
    // Affichage du formulaire d'inscription (internaute existant)
    //-----------------------------------------------
    function formulaireInscription2(){

 	    location.href="/Forum/Forum?controlerCode=CtlInscription&requestCode=initialiserFormulaireInscription";

    }
