var m_1 = "Vous devez sélectionner un type de mot de passe";
var m_2 = "Vous devez sélectionner une taille pour le mot de passe";
var m_3 = "Les mot de passes sont incompatibles !";
var m_4 = "Désirez-vous vraiment supprimer cet administrateur ?";
var m_5 = "Désirez-vous vraiment supprimer cette taxe ?";
var m_6 = "Désirez-vous vraiment supprimer cet animal ?";
var m_7 = "Le statut du concessionnaire est invalide.";
var m_8 = "Le coût du transport doit être un nombre sans espace ni virgule.\n Utiliser le point décimal.";
var m_9 = "Désirez-vous vraiment supprimer ce statut ?";
var m_10 = "Impossible de supprimer le dernier statut.";
var m_11 = "Désirez-vous vraiment supprimer le concessionnaire.\nSi oui, tous les clients seront inscrits dans la table t_amibouff";
var m_12 = "Vérifier les prix de concessionnaires.\nLes prix doivent être des nombre sans espace ni virgule.\nUtiliser le point décimal.";
var m_13 = "Sélectionner une catégorie.";
var m_14 = "La date de début est plus grande que la date de fin !";
var m_15 = "Vous devez sélectionner au moins un produit.";
var m_16 = "Vérifier les nombres.\nTous les nombre doivent être des nombre sans espace ni virgule.\nUtiliser le point comme séparateur et au minimum deux décimales.";




MM_reloadPage(true);

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function trim(val) {
  var retour = ""
  for(i=0;i < val.length;i++)
    if(val.charAt(i) != " ") {
      retour += val.charAt(i)
    }
  return retour
} 

function setPointer(theRow, theRowNum, theAction)
{
    var theCells = null;
    var marked_row = new Array();
    var theDefaultColor = '#FDFDFF';
    var thePointerColor = '#F2F2FF';
    var theMarkColor = '#dddddd';
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function
//**********************************
//**********************************
function onlyNumbers(inputString)
{
	if(inputString.charCodeAt(0)==45)
  {
		var len = inputString.length;
		inputString = inputString.substr(1,len);
 	}
	var nombre = inputString.split(".");
 	var verif   = /^[0-9]+$/
   if ((verif.exec(nombre[0]) == null) || (verif.exec(nombre[1]) == null))
     return false;
   return true;

}
function onlyEntier(inputString)
{
   var verif   = /^[0-9]+$/
	if ((verif.exec(inputString) == null))
    return false;
  return true;
}
function isNumberFloat(inputString)//FLOAT ET INTEGER
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}

function motdepasse(form)
{
 var type = form.type.selectedIndex;


if (type<4) 
{
    var selectionarray=new Array(62)
    selectionarray[1]="A";
    selectionarray[2]="B";
    selectionarray[3]="C";
    selectionarray[4]="D";
    selectionarray[5]="E";
    selectionarray[6]="F";
    selectionarray[7]="G";
    selectionarray[8]="H";
    selectionarray[9]="I";
    selectionarray[10]="J";
    selectionarray[11]="K";
    selectionarray[12]="L";
    selectionarray[13]="M";
    selectionarray[14]="N";
    selectionarray[15]="O";
    selectionarray[16]="P";
    selectionarray[17]="Q";
    selectionarray[18]="R";
    selectionarray[19]="S";
    selectionarray[20]="T";
    selectionarray[21]="U";
    selectionarray[22]="V";
    selectionarray[23]="W";
    selectionarray[24]="X";
    selectionarray[25]="Y";
    selectionarray[26]="Z";
    selectionarray[27]="0";
    selectionarray[28]="1";
    selectionarray[29]="2";
    selectionarray[30]="3";
    selectionarray[31]="4";
    selectionarray[32]="5";
    selectionarray[33]="6";
    selectionarray[34]="7";
    selectionarray[35]="8";
    selectionarray[36]="9";
    selectionarray[37]="a";
    selectionarray[38]="b";
    selectionarray[39]="c";
    selectionarray[40]="d";
    selectionarray[41]="e";
    selectionarray[42]="f";
    selectionarray[43]="g";
    selectionarray[44]="h";
    selectionarray[45]="i";
    selectionarray[46]="j";
    selectionarray[47]="k";
    selectionarray[48]="l";
    selectionarray[49]="m";
    selectionarray[50]="n";
    selectionarray[51]="o";
    selectionarray[52]="p";
    selectionarray[53]="q";
    selectionarray[54]="r";
    selectionarray[55]="s";
    selectionarray[56]="t";
    selectionarray[57]="u";
    selectionarray[58]="v";
    selectionarray[59]="w";
    selectionarray[60]="x";
    selectionarray[61]="y";
    selectionarray[62]="z";
    var length=62;
    }
    if (type<3) 
    {
    var selectionarray=new Array(36);
    selectionarray[1]="a";
    selectionarray[2]="b";
    selectionarray[3]="c";
    selectionarray[4]="d";
    selectionarray[5]="e";
    selectionarray[6]="f";
    selectionarray[7]="g";
    selectionarray[8]="h";
    selectionarray[9]="i";
    selectionarray[10]="j";
    selectionarray[11]="k";
    selectionarray[12]="l";
    selectionarray[13]="m";
    selectionarray[14]="n";
    selectionarray[15]="o";
    selectionarray[16]="p";
    selectionarray[17]="q";
    selectionarray[18]="r";
    selectionarray[19]="s";
    selectionarray[20]="t";
    selectionarray[21]="u";
    selectionarray[22]="v";
    selectionarray[23]="w";
    selectionarray[24]="x";
    selectionarray[25]="y";
    selectionarray[26]="z";
    selectionarray[27]="0";
    selectionarray[28]="1";
    selectionarray[29]="2";
    selectionarray[30]="3";
    selectionarray[31]="4";
    selectionarray[32]="5";
    selectionarray[33]="6";
    selectionarray[34]="7";
    selectionarray[35]="8";
    selectionarray[36]="9";
    var length=36;
}
if (type<2) 
{
    var selectionarray=new Array(36);
    selectionarray[1]="A";
    selectionarray[2]="B";
    selectionarray[3]="C";
    selectionarray[4]="D";
    selectionarray[5]="E";
    selectionarray[6]="F";
    selectionarray[7]="G";
    selectionarray[8]="H";
    selectionarray[9]="I";
    selectionarray[10]="J";
    selectionarray[11]="K";
    selectionarray[12]="L";
    selectionarray[13]="M";
    selectionarray[14]="N";
    selectionarray[15]="O";
    selectionarray[16]="P";
    selectionarray[17]="Q";
    selectionarray[18]="R";
    selectionarray[19]="S";
    selectionarray[20]="T";
    selectionarray[21]="U";
    selectionarray[22]="V";
    selectionarray[23]="W";
    selectionarray[24]="X";
    selectionarray[25]="Y";
    selectionarray[26]="Z";
    selectionarray[27]="0";
    selectionarray[28]="1";
    selectionarray[29]="2";
    selectionarray[30]="3";
    selectionarray[31]="4";
    selectionarray[32]="5";
    selectionarray[33]="6";
    selectionarray[34]="7";
    selectionarray[35]="8";
    selectionarray[36]="9";
    var length=36;
}
  var lngth=form.length.selectedIndex;
  var i,j;
  var tmpstr;
  tmpstr="";
  i=0;
  do {
  {
  var randscript = -1
  while (randscript < 1 || randscript > length || isNaN(randscript))
  {randscript = parseInt(Math.random()*(length))}
  j=randscript}
  tmpstr=tmpstr+selectionarray[j]
  i=i+1}
  while (i<lngth)
  form.password.value = tmpstr;
}
//*****************************************************
//EXÉCUTE UN FOCUS SUR UN OBJET FORMULAIRE
function set_focus(frm,element)
{
    for(var i = 0; i < frm.elements.length; i++)
    {
      if(frm[i].name == element)
      {
        frm[i].value = "";
        frm[i].focus();
      }
    }
}
//*****************************************************
function add_list(frm,tab_element,list_element)
{
  var s = "";
  var separateur = "**********";
  var saut = "\n";
  for(var i = 0; i < tab_element.length; i++)
  {
   for(var j = 0; j < frm.elements.length; j++)
    {
      if(frm[j].name == tab_element[i])
      {
         if(frm[j].value == "")
           s += "N/A" + saut;
         else
           s += frm[j].value + saut;
      }
    }
  }
  //******************************
  for(var i = 0; i < frm.elements.length; i++)
  {
    if(frm[i].name == list_element)
      frm[i].value += s + separateur + saut;
  }

}
//*****************************************************
function check_field(frm,tab_field)
{
  for(var i = 0; i < tab_field.length; i++)
  {
    for(var j = 0; j < frm.elements.length; j++)
    {
      if(frm[j].name == tab_field[i])
        if(frm[j].value == "")
        {
          alert("Un de vos champs obligatoires a une valeur NULL !");
          set_focus(frm,tab_field[i]);
          return false;
        }
    }
  }
  return true;
}
//*****************************************************
function delete_value(frm,tab_element)
{
  for(var i = 0; i < tab_element.length; i++)
  {
    for(var j = 0; j < frm.elements.length; j++)
    {
      if(frm[j].name == tab_element[i])
      {
        frm[j].value = "";
      }
    }
  }
}
//*****************************************************
function delete_list(frm,element)
{
    for(var i = 0; i < frm.elements.length; i++)
    {
      if(frm[i].name == element)
        frm[i].value = "";
    }
}
//*****************************************************
function set_select(frm,element)
{
    for(var i = 0; i < frm.elements.length; i++)
    {
      if(frm[i].name == element)
      {
        frm[i].focus();
        frm[i].select();
      }
    }
}
//*****************************************************
function fermeture_concess()
{
  if(window != top)
  {
    top.location = "index.php";
  }
}
//*****************************************************
function check_password(frm,first_num,second_num)
{
   if(frm[first_num].value == frm[second_num].value)
   {
     return true;
   }
   else
   {
     alert("Les deux mots de passe, doivent être identiques !");
     return false;
   }
}
//*****************************************************
function check_date(first_date,second_date)
{
 if(first_date > second_date)
 {
   alert("Votre date de début est plus grande de votre date de fin !");
   return false
 }
 return true
}
//*****************************************************
function open_popup(lien)
{
 window.open(lien,"", "width=1000,height=600,scrollbars=1,left=" + ((screen.width - 1000)/2) + ",top=" + ((screen.height - 600)/2) );
}
//*****************************************************
function open_parametre(lien)
{
 window.open(lien,"", "width=1100,height=800,scrollbars=1,left=" + ((screen.width - 1100)/2) + ",top=" + ((screen.height - 800)/2) );
	
}
//*****************************************************
function open_message(lien)
{
 window.open(lien,"", "width=500,height=300,scrollbars=1,left=" + ((screen.width - 500)/2) + ",top=" + ((screen.height - 300)/2) );
	
}

function open_max()
{
window.moveTo(0,0);
if (document.all)
	{
	window.resizeTo(screen.availWidth,screen.availHeight);
	}
else if (document.layers)
	{
	if (window.outerHeight<screen.availHeight||window.outerWidth<screen.availWidth)
		{
		window.outerHeight = screen.availHeight;
		window.outerWidth = screen.availWidth;
		}
	}
}
//*****************************************************
function window_size()
{
 self.moveTo(0,0)
 self.resizeTo(screen.availWidth,screen.availHeight)

}
//*****************************************************
function writecookie(name, value, hours)
{
  /*var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;*/
  var argv = writecookie.arguments;
  var argc = writecookie.arguments.length;
  var expires = (argc > 2)?argv[2] : null;
  var path = (argc > 3)?argv[3] : null;
  var domain = (argc > 4)?argv[4] : null;
  var secure = (argc > 5)?argv[5] : false;
  document.cookie = name + "=" + escape(value) +
  ((expires==null) ?"":("; expires="+expires.toGMTString()))+
  ((path==null) ?"":("; path="+path))+
  ((domain==null) ?"":("; domain="+domain))+
  ((secure==true) ?";secure" :"");
}
//*****************************************************
function readcookie(bool)
{
  var cookieValue = "";
  if(bool)
    name = "idconcess";
  else
    name = "idname";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
//*****************************************************
function status_name()
{
	var s = readcookie(true);
	window.defaultStatus = s;
}
//*****************************************************
function CheckDate(d) {
      // Cette fonction vérifie le format JJ-MM-AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
      var amin=1850; // année mini
      var amax=2500; // année maxi
      var separateur="-"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
         alert("Le jour n'est pas correct."); ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
         alert("Le mois n'est pas correct."); ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
         alert("L'année n'est pas correcte."); ok=0;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
         alert("Les séparateurs doivent être des "+separateur); ok=0;
      }
      if (ok==1) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getYear();
         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            alert("La date "+d+" n'existe pas !");
            ok=0;
         }
		 ok=d2;
      }
      return ok;
   }
//*****************************************************
function tjs_age(dt) {
	// Cette fonction retourne une chaîne de type :
	//  "15 ans et 6 mois"
	var d=CheckDate(dt)
	var m=new Date()
	var age=""; var age_a=0;var age_m=0;
	if (d!=0) {
		if (d.getTime()>m.getTime()) {
			age="La date de naissance est invalide !";
			//alert(age);
                        //document.formage.dt_naissance.focus();
		}
		age_a = m.getFullYear()-d.getFullYear();
		m.setYear(d.getYear());
		if ((d.getTime()>m.getTime())&&(d.getMonth()-m.getMonth()!=0)) {age_a--;}
		if (d.getMonth() >= m.getMonth()) {
			age_m = 12 - (d.getMonth()-m.getMonth())
		} else {
			age_m = (m.getMonth()-d.getMonth())
		}
		if (age_m==12) {age_m=0;}
		if (age_a==1) { age=age_a+" an"}
		if (age_a>1) { age=age_a+" ans"}
		if ((age_a>0)&&(age_m>0)) {age+=" et "}
		if (age_m>0) {age+=age_m+" mois"}
		if (age=="") { age="Moins de 1 mois"}
	} else {
		//document.formage.dt_naissance.focus();
	}
	return age;
}
//*****************************************************
function open_dynpopup(lien,w,h)
{
 window.open(lien,"", "width="+w+",height="+h+",scrollbars=1,left=" + ((screen.width - w)/2) + ",top=" + ((screen.height - h)/2) );

}

