//alert("global.js");

/** Ramene un element par son id */

function getUnElementById(whichId){
	var element=null;
	if (document.getElementById){
		// this is the way the standards work
		element = document.getElementById(whichId);
	} else if (document.all) {
		// this is the way old msie versions work
		element = document.all[whichId].style;
	} else if (document.layers) {
		// this is the way nn4 works
		element = document.layers[whichId].style;
	}
	return element;
}


/** Change la propery display d'une layer d'id donnee */
function toggleLayer(whichLayer){
	//alert("toggle layer "+whichLayer);
	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

/** Desactive tous les champs d'un formulaire */
function desactiveForm(whichForm){
	//alert("whichForm="+whichForm);
	var monForm=getUnElementById(whichForm);
	//alert("monForm="+monForm);
			
			var inputsFields= monForm.getElementsByTagName("input");		
			for(i=0;i<inputsFields.length;i++){
				if(inputsFields[i].type=="text" || inputsFields[i].type=="checkbox"  || inputsFields[i].type=="radio" || inputsFields[i].type=="submit" )
					inputsFields[i].disabled="true";
			}
	
			var selectFields=monForm.getElementsByTagName("select");
			for(j=0;j<selectFields.length;j++){
				if(selectFields[j].type=="select-one")
					selectFields[j].disabled="true";
			}
	
			var txtAreaFields=monForm.getElementsByTagName("textarea");
			for(k=0;j<txtAreaFields.length;k++){
					txtAreaFields[k].disabled="true";
			}
	
}

/** Ouvre une pop-up centree */
function popupcentree(page,largeur,hauteur,options){
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


/** Analyse une erreur */
function analyseError(err) {
	var myError = 'error: ' + err.name + '\nmessage: '  + err.message;
	if (err.location) myError += '\nlocation' + err.location; 

	return myError;
}

/** Desactive tous les liens d'une page*/
function disablehref(){
	var input = document.getElementsByTagName("a");
	//alert("input="+input);
	var count = input.length;
	//alert("count="+count);
	for(var i =0; i < count; i++){
		document.getElementsByTagName("a")[i].disabled = true;
		// Does not disable the link it just gives it a grey color, but works with buttons
		document.getElementsByTagName("a")[i].removeAttribute("href"); 
		// OBS this works but also stops the request and the next page does not get loaded, just
		// hangs in the first page
		document.getElementsByTagName("a")[i].style.cursor='wait';// just to give the
		//mousepointer the wait symbol instead of the hand
	}

return true;
}

function popupcentreenommee(page,nom,largeur,hauteur,options){
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var fenetre = window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
	fenetre.focus();
}
