var iteration = 0;
var MaxIteration = 100;


function photo_check(input_file_name, maxwidth, maxheight)
{    
   var file = document.getElementById(input_file_name).value;
   var file_ext = file.substring(file.lastIndexOf('.') + 1);
   var input_message_name = input_file_name + '[message]';
   var input_status_name = input_file_name + '[status]';
   
   if(file.length == 0)
   {
		document.getElementById(input_message_name).value = 'Fichier inexistant.';
		document.getElementById(input_status_name).value = 'UNCHANGE';
		return;    
   }
      
   file_ext = file_ext.toLowerCase();
   if((file_ext != 'jpeg') && (file_ext != 'jpg') && (file_ext != 'png') && (file_ext != 'gif'))
   {
	   document.getElementById(input_message_name).value = 'Fichier non conforme.';
		document.getElementById(input_status_name).value = 'KO';
		return; 
   }
   /*
   var maxWidth = maxwidth;
   var maxHeight = maxheight;
  // var rapport = maxWidth/maxHeight;
   var delta = 0.01;
   var imgtocheck = new Image();
   
   imgtocheck.src = file;
   var ImgHeight = imgtocheck.height;
   var ImgWidth = imgtocheck.width;
   
   if(((ImgHeight == 0) || (ImgWidth == 0)) && iteration < MaxIteration)
   {
   	imgtocheck.Free;
	  	iteration++;	  
	  	return photo_check(input_file_name, maxwidth, maxheight);
   }
   else if(iteration == MaxIteration)
   {
      iteration = 0;
	  	imgtocheck.Free;
	  	message = 'Le fichier de la photo n\'a pas pu être atteint.';
	   document.getElementById(input_message_name).value = message;
		document.getElementById(input_status_name).value = 'KO';
		return;
   }
   else
      iteration = 0;
   
   if((ImgHeight > maxHeight) || (ImgHeight == 0))
   {
      message = 'Photo trop haute. ' + ImgHeight + ' pour max=' + maxHeight;
	   document.getElementById(input_message_name).value = message;
		document.getElementById(input_status_name).value = 'KO';
		return;
   }
   
   if((ImgWidth > maxWidth) || (ImgWidth == 0))
   {
      message = 'Photo trop large. ' + ImgWidth + ' pour max=' + maxWidth;
	   document.getElementById(input_message_name).value = message;
		document.getElementById(input_status_name).value = 'KO';
		return;
   }
   
   if(((ImgWidth/ImgHeight) > (rapport + delta)) || ((ImgWidth/ImgHeight) < (rapport - delta)))
   {
      message = 'Proportions de la photo non conforme. dim=' + ImgWidth + 'x' + ImgHeight + ' pour max=' + maxWidth + 'x' + maxHeight;
	   document.getElementById(input_message_name).value = message;
		document.getElementById(input_status_name).value = 'KO';
		return;
   }*/
   
   document.getElementById(input_message_name).value = '';
   document.getElementById(input_status_name).value = 'OK';
	return;
}


function isNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if(strString.length == 0) 
      return false;
  
   for(j = 0; j < strString.length; j++)
   {
      strChar = strString.charAt(j);
      if(strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   return blnResult;
}

function isPosInteger(strString)
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if(strString.length == 0) 
      return false;
  
   for(j = 0; j < strString.length; j++)
   {
      strChar = strString.charAt(j);
      if(strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   return blnResult;
}

function isKeyPressedPosInteger()
{
   if(event.keyCode < 45 || event.keyCode > 57) //ie
      return false;
   
   
   if(event.which < 45 || event.which > 57) //others
      return false;
}

//Fonctions synchronisées sur le body.onload
FuncOL = new Array();
function AddWindowOnLoadFunction(Obj) 
{
	FuncOL[FuncOL.length] = Obj;
}
	
// Execution des scripts au chargement de la page
window.onload = function() 
{
	for(i = 0; i < FuncOL.length; i++)
	{
		FuncOL[i]();	
	}
		
}

