



var ie = true;
var ns4 = false;
var ns6 = false;
var stylevisible = "visible";

function Is() 
{  var navName = navigator.appName;
   //alert("appName : " + navName);
   major = parseInt(navigator.appVersion);
   if (navName == "Microsoft Internet Explorer")
      ie = true;
   if (navName == "Netscape")
   {  ie = false;
      if (major < 5)
      {    ns4 = true;
           stylevisible = "show";
	  }
      else ns6 = true;	
   }
   //alert("ie : " + ie + ", ns4 : " + ns4 + ", ns6 : " + ns6 + " - ");
}


// Taille écran et fenêtre
function getClientWidth()
{  if (ie)
	    return parseInt(document.body.clientWidth);
   else return parseInt(window.innerWidth);
}
function getClientHeight()
{  if (ie)
	    return parseInt(document.body.ClientHeight);
   else return parseInt(window.innerHeight);
}
function getClientWidthWindow(_TheWindowId)
{  if (ie)
	    return parseInt(eval(_TheWindowId+"document.body.clientWidth"));
   else return parseInt(eval(_TheWindowId+"window.innerWidth"));
}
function getClientHeightWindow(_TheWindowId)
{  if (ie)
	    return parseInt(eval(_TheWindowId+"document.body.ClientHeight"));
   else return parseInt(eval(_TheWindowId+"window.innerHeight"));
}





function getImg(_theImg, _theparentdiv)
{  if (ie)
      return eval(document.all(_theImg));
   if (ns4)
      if (_theparentdiv)
	       return eval(document.layers[_theparentdiv].document.images[_theImg]);
  	  else return eval(document.images[_theImg]);
   if (ns6)
	  return eval(document.getElementById(_theImg));
}

function getDiv(_theDiv, _theparentdiv)
{  if (ie)
      return eval(document.all(_theDiv));
   if (ns4)
      if (_theparentdiv)
	       return eval(document.layers[_theparentdiv].document.layers[_theDiv]);
  	  else return eval(document.layers[_theDiv]);
   if (ns6)
	  return eval(document.getElementById(_theDiv));
}

function getDivStyle(_theDiv, _theparentdiv)
{  theElement = getDiv(_theDiv, _theparentdiv);
   if (ie || ns6)
      return eval(theElement.style);
   if (ns4)
      return theElement;
}

function saveltwh(_thepage)
{  url = "asp/saveltwh.asp?id="+_thepage;
   window.open(url, "saveltwh", "toolbar=0, location=0, directories=0, status=0, scrollbars=yes, resizable=yes, left=8000, top=8000, height=10, width=10");
}

function setDivInnnerHTML(_theDiv, _theString, _theparentdiv)
{  theElement = getDiv(_theDiv, _theparentdiv);
   if (ie ||ns6)
      theElement.innerHTML = _theString;
   if (ns4)
   {  theElement.document.write(_theString);
      theElement.document.close();
   }
}

function center1Div(_theDiv, _iwidth)
{  theElement = getDivStyle(_theDiv);
   ileft = (getClientWidth() - _iwidth) / 2 ;
   theElement.left = ileft > 0 ? ileft : 0;
   theElement.visibility = stylevisible;
}
function aDroite1Div(_theDiv, _iwidth)
{  theElement = getDivStyle(_theDiv);
   ileft = (getClientWidth() - _iwidth) / 2 ;
   dvActuLeft = (ileft > 0 ? ileft : 0) + _iwidth - 140;
   theElement.left = dvActuLeft - 7;
   theElement.visibility = stylevisible;
}
function agrandir(_theImage)
{  url = "asp/agrandir.asp?id="+_theImage;
   window.open(url, "zoom", "toolbar=0, location=0, directories=0, status=0, scrollbars=yes, resizable=yes, height=600, width=800");
}
function focusField(_theField)
{  _theField.select();
   _theField.focus();
}
function selRequis(_theSelect)
{  if (_theSelect.options[_theSelect.selectedIndex].value.length == 0)
   {  alert("le champ "+ _theSelect.name +" est obligatoire");
      _theSelect.focus();
       return false;
   }
   if (_theSelect.options[_theSelect.selectedIndex].value == "...")
   {  alert("le champ "+ _theSelect.name +" est obligatoire");
      _theSelect.focus();
      return false;
   }
   return true;
}

function chRequis(_champ)
{  if (_champ.value.length == 0)
   {  alert("le champ "+ _champ.name +" est obligatoire");
      _champ.focus();
	  return false;
   }
   else return true;
}
 
function VerifDate(LaDate) 
{    dateStr = LaDate.value;
     var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
     var matchArray = dateStr.match(datePat);
	   if (matchArray == null) 
	   {  alert("La date n'est pas au bon format (jj/mm/aaaa) ou (jj/mm/aa)");
		  focusField(LaDate);
		  return 0;
	   }
	   day = matchArray[1];
	   month = matchArray[3];
	   year = matchArray[4];
	   if (month < 1 || month > 12) 
	   {  alert("Le mois doit être compris entre 1 et 12");
		  focusField(LaDate);
		  return 0;
	   }
	   if (day < 1 || day > 31) 
	   {  alert("Le jour doit être compris entre 1 et 31");
		  focusField(LaDate);
		  return 0;
	   }
	   if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	   {  alert("Le mois "+month+" n'a pas 31 jours!")
		  focusField(LaDate);
		  return 0
	   }
	   if (month == 2) 
	   {  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		  if (day>29 || (day==29 && !isleap)) 
		  {  alert("Février " + year + " n'a pas " + day + " jours!");
		  focusField(LaDate);
			 return 0;
		  }
	   }
	   return 1;
}
   
 
function VerifHeure(Lheure) 
{      heureStr = Lheure.value;
       var heurePat = /^(\d{1,2})(\:)(\d{1,2})\2(\d{2})$/;
       var matchArray = heureStr.match(heurePat);
	   if (matchArray == null) 
	   {  alert("L'heure n'est pas au bon format (hh:mm:ss)");
		  focusField(Lheure);
		  return 0;
	   }
	   hh = matchArray[1];
	   mm = matchArray[3];
	   ss = matchArray[4];
	   if (hh < 0 || hh > 23) 
	   {  alert("Les heures doivent être comprises entre 1 et 23");
		  focusField(Lheure);
		  return 0;
	   }
	   if (mm < 0 || mm > 59) 
	   {  alert("Les minutes doivent être comprises entre 1 et 59");
		  focusField(Lheure);
		  return 0;
	   }
	   if (ss < 0 || ss > 59) 
	   {  alert("Les secondes doivent être comprises entre 1 et 59");
		  focusField(Lheure);
		  return 0;
	   }
	   return 1;
}
   
    
function Date1InferieureADate2(LaDate1, LaDate2) 
{      dateStr1 = LaDate1.value;
       dateStr2 = LaDate2.value;
       var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
       var matchArray = dateStr1.match(datePat);
       var date1 = new Date(matchArray[3] + "/" + matchArray[1] + "/" + matchArray[4]);
       matchArray = dateStr2.match(datePat);
       var date2 = new Date(matchArray[3] + "/" + matchArray[1] + "/" + matchArray[4]);
       if (date2 < date1)
       {  alert("Fourchette de date incorrecte...");
          LaDate2.focus(); 
          return 0;
       }
       return 1;
}

function truncate(_theTextArea, _limite)
{  _theTextArea.value = _theTextArea.value.substr(0, _limite);
}

function verifLength(_theTextArea, _limite)
{  if (_theTextArea.value.length > _limite)
	   {  alert("Vous avez atteint la limite du nombre de caractères ("+_limite+") de cette zone");
	      window.event.cancelBubble = true;
		  window.event.returnValue = false;
	      truncate(_theTextArea, _limite);
	   }
}

function checkFormFieldsAndValues(_form)
{	str = "";
	for(i=0;i<_form.length;i++)
	  str+= "nom champ : "+_form.elements[i].name+"  valeur champ : "+_form.elements[i].value+"\n";
	alert(str);
}	


function docElem(_theElement)
{  if (eval(document.all(_theElement)))
        return eval(document.all(_theElement));
   else return eval(document.getElementById(_theElement));
}

function MySQL_DateFormatClient(strdateheure)
{
    /*--------------------------------------------------
	'-- formater une date en ayant 2 carac. 
	'-- pour les jours et les mois
   	'--------------------------------------------------*/
		//isoler les valeurs constituant la date
		TabDate = strdateheure.split("/");
		
		//'--le jour et le mois
	    DD = parseInt(TabDate[0]);
	    MM = parseInt(TabDate[1]);

		if (DD < 10) sDD = "0"+DD;
		else sDD = DD;

		if (MM < 10) sMM = "0"+MM;
		else sMM = MM;

		//'--l'annee
		YYYY = parseInt(TabDate[2]);
		if (YYYY < 100) sYYYY = "2000"+YYYY;
		else sYYYY = YYYY;
		
		//'--date complète
		str = sDD + "/" + sMM + "/" + sYYYY;
	return(str);
}

function reloadTopFrame(_nomPage){
    top.location.href= "frm_aide.asp?nompage="+_nomPage;
}

function callOnglet(_val){
    parent.entete.Onglet(_val);    
}
