ie = (navigator.appName == "Microsoft Internet Explorer") ? true:false;
browser = (document.images)? true:false;

function verifRequire(objForm) {
	ERR = "";
	for (i=0; i<objForm.length; i++) {
		if ((objForm.elements[i].getAttribute('REQUIRED') != null) && (!objForm.elements[i].value)) {
			ERR = ERR + "\n" + objForm.elements[i].getAttribute('REQUIRED');
		}
	}
	
	if (ERR) {
		alert("Ce formulaire ne peut être validé car il manque les informations suivantes :\n" + ERR);
		return(false);
	} else {
		return(true);
	}
}

function titrageLabel(objForm,etat,inputSelect) {
	if (etat) {
		objForm.className = "ON";
		eval("document.all['LABEL-" + objForm.name + "'].className = 'ON'");
		
		if (!inputSelect) {
			objForm.select();
		}
	} else {
		if (!objForm.value) {
			objForm.className = "OFF";
		}
		eval("document.all['LABEL-" + objForm.name + "'].className = 'OFF'");
	}
}

function titrageChk(ObjBox) {
	if (ObjBox.checked == true) {
		titrageLabel(ObjBox,1);
	} else {
		titrageLabel(ObjBox,0);
	}
}

function calendrier(appel) {
	nomChamps = appel;
	window.open('/js/calendrier.htm','','width=200,height=220,menubar=no');
}

function afficheChamps(Obj,ID,champs) {
	if (Obj.value) {
		eval("document.all['" + ID + "'].style.visibility = 'visible'");
		if (champs) {
			eval("document.forms[0]." + champs + ".focus()");
		}
	} else {
		eval("document.all['" + ID + "'].style.visibility = 'hidden'");
	}
}

function chkSupprime(champsRetour,msg) {
	var chk = "";
	var utilisateurs = "";
	
	for (i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].checked) {
			if (chk) {
				chk = chk + "," + document.forms[0].elements[i].value;
				utilisateurs = utilisateurs + "\n" + document.forms[0].elements[i].name;
			} else {
				chk = document.forms[0].elements[i].value;
				utilisateurs = document.forms[0].elements[i].name;
			}
		}
	}

	if (chk) {
		eval("document.forms[0]." + champsRetour + ".value = '" + chk + "'");
		
		if (!msg) {
			msg = "choix";
		}
		
		if (confirm("Êtes-vous sûr de vouloir supprimer ces " + msg + " ?\n\n" + utilisateurs)) {
			return(true);
		} else {
			return(false);
		}
	} else {
		alert("Vous n'avez rien choisi à supprimer");
		return(false);
	}
}

var i;
function preloadImage(src, el, elW, elH, new_fenetre) {
	txtErr='';
	
	extension = src.value.substring(src.value.lastIndexOf('.')+1, src.value.length).toLowerCase();
	if ((extension != 'gif') && (extension != 'jpg') && (extension != 'jpeg'))
		txtErr='Votre fichier n\'est pas reconnu comme une image valide.\n\nSeules les extensions .GIF .JPG ou .JPEG sont correctes.';
	else {
		(i = new Image()).src=src.value;
		var compteur=0;
		while ((i.width==0 || i.height==0) && (compteur++<3))
			alert('Veuillez patienter, quelques instants.\nPréchargement en cours.')
		if (compteur>=3)
			txtErr='Veuillez sélectionner une autre image.\nCelle-ci est invalide sur votre poste.';
		else {
			var_img = '<FONT SIZE="1" COLOR="white" FACE="arial"><B>Largeur: ' + i.width + ' - Hauteur: ' + i.height + '</B></FONT><BR><BR><IMG SRC="' + i.src + '" WIDTH="' + i.width + '" HEIGHT="' + i.height + '" onDragStart="return false;" onSelectStart="return false;">';
			
			if (new_fenetre) {
				fenetre = window.open("","","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=250,height=200");
				fenetre.document.open();
				fenetre.document.write("<HTML><HEAD><TITLE></TITLE><BASEFONT FACE='arial' SIZE='2'><LINK REL='STYLESHEET' TYPE='text/css' HREF='/cfme.css'></HEAD><BODY BGCOLOR='#6494DC'>");
					fenetre.document.write("<DIV ALIGN='CENTER'>");
						fenetre.document.write(var_img);
						fenetre.document.write("<BR>");
						fenetre.document.write("<BR>");
						fenetre.document.write("<A HREF='JavaScript: window.close()'>Fermer la fen&ecirc;tre</A>");
					fenetre.document.write("</DIV>");
				fenetre.document.write("</BODY></HTML>");
				fenetre.document.close();
			} else {
				el.innerHTML = var_img
			}
			if (elW) elW.value=i.width;
			if (elH) elH.value=i.height;
		}
	}
	
	if (txtErr) alert(txtErr);
	return (txtErr=='');
}

