function AfficherImage(img) { Image1= new Image();  Image1.src=(img);  Control(img); } 
function Control(img) {  if((Image1.width!=0)&&(Image1.height!=0)) {    VoirImage(img);  }  else {    fonction="Control('"+img+"')";    intervalle=setTimeout(fonction,20);  } } 
function VoirImage(img) {  
largeur=Image1.width+20;  hauteur=Image1.height+20;  
var top=(screen.height-hauteur)/2;
var left=(screen.width-largeur)/2;
proprietes="width="+ largeur +",height="+ hauteur+",top="+top+",left="+left;  
win=window.open(img,"",proprietes); }

AlphaChars = "ôéàçèâîïùabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .@,-_";
NumChars = "0123456789";
HexaChars = "ABCDEFabcdef";


function popUp(URLStr, width, height, avecbarres)
{
 var top=(screen.height-height)/2;
var left=(screen.width-width)/2;
sb=(avecbarres)?'yes':'no'
  window.open(URLStr, 'popup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=auto,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function checkValue(champ, typ)
{
 
 erreur=false;
 if (champ.value != '')
 {
	 result = CheckField(champ.value,typ)
	 if (result!=true)
		{	if (typ=='DAT' && result!=false)
				{champ.value = result}
			else {erreur=true
			}
		}
	}
else erreur=true
if (erreur) {
alert("Une erreur est détectée sur le champ "+champ.name+' --- '+champ.value)
champ.focus()
}
else return true

	
}

function IsMail(Data)
{
	alias=Data.split("@")[0] !=null
	domain=Data.split("@")[1] !=null
	if (domain) suffix=Data.split("@")[1].split(".")[1] !=null
	if (!alias || !domain || !suffix) {return false;}
	return true
}

function IsNumeric(Data) {
	var It = true;
	var c;
	for (var x = 0; x < Data.length; x++)
		if (It) {
			c = Data.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}
	return It;
}

function IsDecimal(Data) {
	var It = true;
	var virgule = false;
	var c;
	c = Data.charAt(0);	
	It = (  (AlphaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) || (c == "+") || (c=="-") );
	for (var x = 1; x < Data.length; x++)
		if (It) {
			c = Data.charAt(x);
			if ( (c==".") || (c == ",") )
				if (virgule) 
					It = false;
				else {
					It = true;
					virgule = true;
				}
			else
				It = (  (AlphaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) );
		}
	return It;
}

function IsAlphaNumeric(Data) {
	var It = true;
	var c;
	for (var x = 0; x < Data.length; x++)
		if (It) {
			c = Data.toLowerCase().charAt(x);
			It = (  (AlphaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) );
		}
	return It;
}

function IsHexa(Data) {
	var It = true;
	var c;
	for (var x = 0; x < Data.length; x++)
		if (It) {
			c = Data.charAt(x);
			It = (  (HexaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) );
		}
	return It;
}

function IsSome(Data) {if (Data.length==0) {return false} else {return true};}

function IsAlpha(Data) {
	var It = true;
	if (Data.length==0) It=false;
	var c;
	for (var x = 0; x < Data.length; x++)
		if (It) {
			c = Data.charAt(x);
			It = ( AlphaChars.indexOf(c) != -1);
		}
	return It;
}

function CheckField(Data,Format) {
	var exact = false;
	if (Data.length > 0) {
		if (Format == "NUM")
			exact = IsNumeric(Data);
		if (Format == "TXT")
			exact = IsAlphaNumeric(Data);
		if (Format == "PCT")
			exact = IsDecimal(Data);
		if (Format == "DEC")
			exact = IsDecimal(Data);
		if (Format == "HEXA")
			exact = IsHexa(Data);
		if (Format == "ALPHA")
			exact = IsAlpha(Data);
		if (Format == "DAT")
			exact = IsDate(Data);
		if (Format == "MAIL")
			exact = IsMail(Data);
		if (Format == "SOME")
			exact = IsSome(Data);

	}
	return exact;
}
  
function jsStringReplacejsCheckDate(strOriginal , strFind, strReplace)  {
  var intPos = 0;
  var intLen = strFind.length;
  intPos = strOriginal.indexOf(strFind);
  while (intPos != -1) {
    strOriginal = strOriginal.substring(0, intPos) + strReplace + strOriginal.substring(intPos+intLen, strOriginal.length);
    intPos = strOriginal.indexOf(strFind);
  };
  return strOriginal;
}
function jsTestCeiljsCheckDateFormat(Nbre)  {
 if (Nbre==Math.ceil(Nbre)) {
    return true; 
 } else { 
    return false;
 }
}
function jsStringReplacejsCheckDateFormat(strOriginal , strFind, strReplace)  {
  var intPos = 0;
  var intLen = strFind.length;
  intPos = strOriginal.indexOf(strFind);
  while (intPos != -1) {
    strOriginal = strOriginal.substring(0, intPos) + strReplace + strOriginal.substring(intPos+intLen, strOriginal.length);
    intPos = strOriginal.indexOf(strFind);
  };
  return strOriginal;
}
function jsCheckDateFormat(strDate, strFormat)  {
 var D;
 var M;
 var Y;
 var div4;
 var div100;
 var div400;
 var bTest = false;
  bTest = false;  if ((strFormat=='dd.mm.yyyy') || (strFormat=='dd.mm.yy') || (strFormat=='mm.dd.yyyy') || (strFormat=='mm.dd.yy') || (strFormat=='d.m.yyyy') || (strFormat=='d.m.yy') || (strFormat=='m.d.yyyy') || (strFormat=='m.d.yy'))
  {    bTest = true;    strDate = jsStringReplacejsCheckDateFormat(strDate, '.', '/');
    strFormat = jsStringReplacejsCheckDateFormat(strFormat, '.', '/');
  }  if (!bTest && ((strFormat=='dd-mm-yyyy') || (strFormat=='dd-mm-yy') || (strFormat=='mm-dd-yyyy') || (strFormat=='mm-dd-yy') || (strFormat=='d-m-yyyy') || (strFormat=='d-m-yy') || (strFormat=='m-d-yyyy') || (strFormat=='m-d-yy')))
  {    bTest = true;    strDate = jsStringReplacejsCheckDateFormat(strDate, '-', '/');
    strFormat = jsStringReplacejsCheckDateFormat(strFormat, '-', '/');
  }  if (!bTest && ((strFormat=='ddmmyyyy') || (strFormat=='mmddyyyy') || (strFormat=='ddmmyy') || (strFormat=='mmddyy')))
  {    strDate = strDate.substring(0, 2) + '/' + strDate.substring(2, 4) +  '/' + strDate.substring(4, strDate.length);
    strFormat = strFormat.substring(0, 2) + '/' + strFormat.substring(2, 4) +  '/' + strFormat.substring(4, strFormat.length);
  } p1 = strDate.indexOf('/');
 p2 = strDate.lastIndexOf('/');
 LenY = strDate.length - p2 - 1;
 bTest = false;  if ((strFormat=='dd/mm/yy') || (strFormat=='d/m/yy'))
  {    bTest = true;    D = parseFloat(strDate.substring(0,p1));
    M = parseFloat(strDate.substring(p1+1,p2));
    Y = parseFloat(strDate.substring(p2+1,strDate.length));
    if (LenY!=2) {Y=-1;} 
  }  if (!bTest && ((strFormat=='mm/dd/yy') || (strFormat=='m/d/yy')))
  {    bTest = true;    M = parseFloat(strDate.substring(0,p1));
    D = parseFloat(strDate.substring(p1+1,p2));
    Y = parseFloat(strDate.substring(p2+1,strDate.length));
    if (LenY!=2) {Y=-1;} 
  }  if (!bTest && ((strFormat=='mm/dd/yyyy') || (strFormat=='m/d/yyyy')))
  {    bTest = true;    M = parseFloat(strDate.substring(0,p1));
    D = parseFloat(strDate.substring(p1+1,p2));
    Y = parseFloat(strDate.substring(p2+1,strDate.length));
    if (LenY!=4) {Y=-1;} 
  }  if (!bTest && ((strFormat=='dd/mm/yyyy') || (strFormat=='d/m/yyyy')))
  {    bTest = true;    D = parseFloat(strDate.substring(0,p1));
    M = parseFloat(strDate.substring(p1+1,p2));
    Y = parseFloat(strDate.substring(p2+1,strDate.length));
    if (LenY!=4) {Y=-1;} 
  }  if (!bTest)
  {    D = parseFloat(strDate.substring(0,p1));
    M = parseFloat(strDate.substring(p1+1,p2));
    Y = parseFloat(strDate.substring(p2+1,strDate.length));
    if (LenY!=4) {Y=-1;} 
  }
 if ((D==0)||!jsTestCeiljsCheckDateFormat(D)) {D=-1;}
 if ((M==0)||!jsTestCeiljsCheckDateFormat(M)||(M>=13)) {M=-1;}
 if (!jsTestCeiljsCheckDateFormat(Y)) {Y=-1;}
 if (Y==0) {Y=2000;}
 div4=jsTestCeiljsCheckDateFormat(Y/4);
 div100=jsTestCeiljsCheckDateFormat(Y/100);
 div400=jsTestCeiljsCheckDateFormat(Y/400);
 if ((Y>=0) && (Y<=9999)) { 
   if ((M==1)||(M==3)||(M==5)||(M==7)||(M==8)||(M==10)||(M==12)) {
     if ((D>0)&&(D<=31)) { 
       return true;
     } else { return false; }
   }
   if ((M==4)||(M==6)||(M==9)||(M==11)) {
     if ((D>0)&&(D<=30)) { 
       return true; 
     } else { return false; }
   }
   if (M==02) {1
     if ((div4)&&!(div100)||(div400)) {
       if ((D>0)&&(D<=29)) {
         return true; 
       } else { return false; }
     } else {
       if ((D>0)&&(D<=28)) {
         return true; 
       }else { return false; }
     } 
   } else { return false; }
 } else { return false; }
 return true;
}
function IsDate(strDate)  {
 strDate = jsStringReplacejsCheckDate(strDate, '.', '/');
 strDate = jsStringReplacejsCheckDate(strDate, '-', '/');
 if (strDate.indexOf('/')==-1)
   { 
   if (strDate.length == 6)
     strDate = strDate.substring(0, 2) + '/' + strDate.substring(2, 4) + '/' + strDate.substring(4, 6);
   else if (strDate.length==8)
     strDate = strDate.substring(0, 2) + '/' + strDate.substring(2, 4) + '/' + strDate.substring(4, 8);
   }
 if ((jsCheckDateFormat(strDate, 'dd/mm/yy')) || (jsCheckDateFormat(strDate, 'dd/mm/yyyy')) || (jsCheckDateFormat(strDate, 'mm/dd/yy')) || (jsCheckDateFormat(strDate, 'mm/dd/yyyy')))
   return strDate;
 else {
   return false;
  };
}


