//
// pascal thomas - 2004
// copie et distribution interdite
// contactez p.thomas@inlive.info pour un usage eventuel
//

// operation sur chaines
function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() { return this.ltrim().rtrim();}
function strnohtml() {return this.replace(/<(.*)>/g, ""); }
function straddbr() {return this.replace(/\r\n/g, "[br]\r\n");}
function straddtag(att,surl,stext) {	if (surl)return "["+att+" "+surl+"]"+stext+this+"[/"+att+"]";	return "["+att+"]"+this+"[/"+att+"]";}
function strrecodetag(tag) {return this.replace(new RegExp("<"+tag+">","gi"),"["+tag+"]");}
function strrmvemptylines() {return this.replace(/\r\n([\r\n]+)/g,"\r\n").replace(/^\r\n/,'');}
function strhtmltovb(){return this.recodetag("b").recodetag("/b").recodetag("u").recodetag("/u").recodetag("i").recodetag("/i").recodetag("hr").recodetag("br").nohtml();}

// test sur chaines
function strisdate(){var reg=/^(\d{1,2})\/(\d{1,2})\/(\d{4})/;if(!reg.test(this))return false;
	var d = RegExp.$1;if(d<0)return false;
	var m = RegExp.$2;if(m<1||m>12)return false;
	var y = RegExp.$3;if(y<1000)return false;
	if(m==2)return(y%4?d<29:d<30);
	return(m%2?d<31:d<32);
}
function stristime(){var reg=/^(\d{2})\:(\d{2})$/;if(!reg.test(this))return false;
	var m = RegExp.$2;
	var h = RegExp.$1;
	return (h>=0&&h<24&&m>=0&&m<60);
}
function strisdatetimeformat(){var reg=/^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}:\d{2}$/;return reg.test(this);}
function strisemail(){var reg=/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;return(reg.exec(this)!=null);}
function strisinteger(){return(this!='')&&!isNaN(Math.round(this))&&(this.charAt(0)!='#')&&(this==Math.round(this));}
function strisfloat(){return(this!='')&&!isNaN(parseFloat(this))&&(this.charAt(0)!='#')&&(this==parseFloat(this));}
function strisempty(){return(this.trim()=='');}
function strislenok(lmin,lmax){var l=this.trim().length;return (l>=lmin&&l<=lmax);}
function strisvalueok(vmin,vmax){if(!this.isfloat())return false;var v=parseFloat(this);return(v>=vmin&&v<=vmax);}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
String.prototype.nohtml = strnohtml;
String.prototype.addbr = straddbr;
String.prototype.tag = straddtag;
String.prototype.recodetag = strrecodetag;
String.prototype.noemptylines = strrmvemptylines;
String.prototype.htmltovb = strhtmltovb;
String.prototype.islenok = strislenok;
String.prototype.isvalueok = strisvalueok;
String.prototype.isempty = strisempty;
String.prototype.isdate = strisdate;
String.prototype.istime = stristime;
String.prototype.isdatetimeformat = strisdatetimeformat;
String.prototype.isemail = strisemail;
String.prototype.isinteger = strisinteger;
String.prototype.isfloat = strisfloat;


function pageselect(pelt){document.frm.submit();}
function profil(imem){

	var p = document.getElementById('frmInfos');
	if (!p){
		alert('Incompatible');
		return;
	}
	p.src = "?pr=1&cmd=members&subcmd=view&code="+imem;
	movexy ('frmInfos',10,10,580,200,true);
	p.style.visibility = "visible";
}

function hideinfos(){
	var p = window.parent.document.getElementById('frmInfos');
	p.style.visibility = "hidden";
}
function movexy(k, x,y,w,h,bcenter){
	var sx;
	var sy;
	var p = document.getElementById(k);if(!p)return;
	if(window.innerWidth){
		sx = pageXOffset;sy = pageYOffset;
		if(bcenter){x=(window.innerWidth-w)/2;y=(window.innerHeight-h)/2;}
	}
	else{
		sx=document.body.scrollLeft;sy=document.body.scrollTop;
		if(bcenter){x=(document.body.clientWidth-w)/2;y=(document.body.clientHeight-h)/2;}
	}
	if(x)p.style.left = x+ sx;
	if(y)p.style.top = y+ sy;
	if(w)p.style.width = w+'px';
	if(h)p.style.height = h+'px';
}
//------------------------------------------------------
function gcv(of){
  var es=document.cookie.indexOf(";",of);if (es==-1)es=document.cookie.length;
  return unescape(document.cookie.substring(of, es));
}
function getCookie(k){
	var pm,pl,cl,i,j;
	pm=k+"=";
	pl=pm.length;
	cl=document.cookie.length;
	i=0;
	while(i<cl){
		j=i+pl;
		if(document.cookie.substring(i,j)==pm)return gcv(j);
		i= document.cookie.indexOf(" ",i)+1;
		if(!i)break; 
	}
  return "";
}
function setCookie(k,v){
	var expires = new Date (2010,11,11,1,1,1);
	document.cookie = k+"="+escape(v)+"; expires=" + expires.toGMTString()
}	


function filterCharset(pfld){
var s=pfld.value;
var reg=/[A-Za-z0-9-àéèëêîïöôûüùÿñç]/g;
var s2 = ""+s.match(reg);
	if (s2=="null") {
		pfld.value="";
		return;
	}
	s2=s2.replace(/,/gi,"");
	if (s!=s2) pfld.value=s2;
}
function filterCharsetArm(pfld){
var s=pfld.value;
var reg=/[A-Za-z0-9-àéèëêîïöôûüùÿñç ]/g;
var s2 = ""+s.match(reg);
	if (s2=="null") {
		pfld.value="";
		return;
	}
	s2=s2.replace(/,/gi,"");
	if (s!=s2) pfld.value=s2;
}
function filterCharsetNum(pfld){
var s=pfld.value;
var reg=/[0-9]/g;
var s2 = ""+s.match(reg);
	if (s2=="null") {
		pfld.value="";
		return;
	}
	s2=s2.replace(/,/gi,"");
	if (s!=s2) pfld.value=s2;
}

var checkflag = "false";

function check(obj) 
{
  if (checkflag == "false")
  {
        for (i = 0; i < obj.length; i++) 
        {
if (obj.elements[i].type == "checkbox") obj.elements[i].checked = "checked";
         }
   checkflag = "true";
   return "Tout décocher"; 
   }
  else
 {
     for (i = 0; i < obj.length; i++) 
    {
if (obj.elements[i].type == "checkbox") obj.elements[i].checked = "";
    }
     checkflag = "false";
     return "Tout cocher"; 
 }
}

function MMO(theURL,winName,features) { 
  var w = window.open('info.php?joueur='+theURL,winName,"resizable=yes,dependant=yes,scrollbars=yes,"+features);
  w.opener = window;
  w.focus();
}

function MMO2(theURL,winName,features) { 
  var w = window.open('info.php?joueur='+theURL,'winName',"resizable=yes,dependant=yes,scrollbars=yes,"+features);
  w.opener = window;
  w.focus();
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' doit contenir une adresse valide.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' requis.\n'; }
  } if (errors) alert('Erreur !!\n'+errors);
  document.MM_returnValue = (errors == '');
}

function tremble(nb) {
	var sens=-1;
	var X=0; var Y=0; var dx; var dy
	for (no=nb;no>1;no=no-0.1) {
		dx=-X+sens*Math.round(no*Math.random());
		dy=-Y+sens*Math.round(no*Math.random());
		X=X+dx; Y=Y+dy;
		top.moveBy(dx,dy);
		sens=sens*(-1);
	}
	top.moveBy(-X,-Y);
}

