if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

//Limite l'entrée dans ce champ aux nombres uniquement
function NumbersOnly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	{
	   return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1))
	{
   		return true;
	}
	else if (dec && (keychar == "."))
   	{
   		myfield.form.elements[dec].focus();
   		return false;
   	}
	else
	{
   		return false;
	}
}

//Retourne la valeur de la radio box sélectionnée
function GetRadioVal(myField)
{
	var nValue = 0;

	for(i = 0; i < myField.length; i++ )
	{
		if(myField[i].checked == true)
		{
			nValue = myField[i].value;
			break;
		}
	}

	if(myField.length == undefined)
		nValue = myField.value;

	return nValue;
}

//Les champs fournis dans fieldlist doivent être remplis, sinon ils sont marqués en rouge dasn le formulaire
function VerifyFields(sForm, FieldList)
{
	var bValid = true;
	var Fields = FieldList.split(',');
	for(var i=0; i<Fields.length; i++)
	{
		if (type=="MO")
			sForm[Fields[i]].style.borderColor = '';
		if (type=="IE")
			sForm.all[Fields[i]].style.borderColor = '';

		if(sForm[Fields[i]].value.length < 1 || (sForm[Fields[i]].selectedIndex != null && sForm[Fields[i]].selectedIndex == 0))
		{
			bValid = false;
			if (type=="MO")
				sForm[Fields[i]].style.borderColor = 'red';
			if (type=="IE")
				sForm.all[Fields[i]].style.borderColor = 'red';
		}
	}

	if(!bValid)
	{
		alert('Vous avez omis de remplir un ou des champs obligatoires.');
		return false;
	}
	else
		return true;

}

//Sert a débugger les propriétés d'un objet
function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}


//Gestion des layers
function SetLayerContent(LayerID, String)
{
	if (type=="IE")
	{
    	document.all[LayerID].innerHTML = String;
	}

	if (type=="NN")
	{
    	document.layers[LayerID].document.open();
    	document.layers[LayerID].document.write(String);
    	document.layers[LayerID].document.close();
	}

	if (type=="MO" || type=="OP")
	{
    	document.getElementById(LayerID).innerHTML = String;
	}
}

function SetLayerVisibility(LayerID, Action)
{
  	if (type=="IE")
  	{
  		eval("document.all." + LayerID + ".style.visibility='" + Action + "'");
  	}

  	if (type=="NN")
  	{
  		eval("document." + LayerID + ".visibility='" + Action + "'");
  	}

  	if (type=="MO" || type=="OP")
  	{
  		eval("document.getElementById('" + LayerID + "').style.visibility='" + Action + "'");
  	}
}

function SetLayerStyle(LayerID, Name, Value)
{
	if (type=="IE")
  	{
  		eval("document.all." + LayerID + ".style." + Name + "='" + Value + "'");
  	}
  	
  	if (type=="NN")
  	{
  		eval("document." + LayerID + "." + Name + "='" + Value + "'");
  	}

  	if (type=="MO" || type=="OP")
  	{
  		eval("document.getElementById('" + LayerID + "').style." + Name + "='" + Value + "'");
  	}
}

function SetLayerDisplay(LayerID, Action)
{
  	if (type=="IE")
  	{
  		eval("document.all." + LayerID + ".style.display='" + Action + "'");
  	}

  	if (type=="NN")
  	{
  		eval("document." + LayerID + ".display='" + Action + "'");
  	}

  	if (type=="MO" || type=="OP")
  	{
  		eval("document.getElementById('" + LayerID + "').style.display='" + Action + "'");
  	}
}