function prechargerNav()
{
	i1 = new Image;
	i1.src = "images/rub1_bis.gif";
	i2 = new Image;
	i2.src = "images/rub2_bis.gif";
	i3 = new Image;
	i3.src = "images/rub3_bis.gif";
	i4 = new Image;
	i4.src = "images/rub4_bis.gif";
	i5 = new Image;
	i5.src = "images/rub5_bis.gif";
}

function montre_calque(nom_calque)
{
	if(document.all){eval('document.all.'+nom_calque).style.visibility='visible';}                     //Internet Explorer
	else if (document.layers){eval('document.'+nom_calque).visibility='show';}                         //Netscape 4.5 et 4.7
	else if (document.getElementById){document.getElementById(nom_calque).style.visibility='visible';} //Netscape 6
}

function cache_calque(nom_calque)
{
	if(document.all){eval('document.all.'+nom_calque).style.visibility='hidden';}                     //Internet Explorer
	else if (document.layers){eval('document.'+nom_calque).visibility='hidden';}                      //Netscape 4.5 et 4.7
	else if (document.getElementById){document.getElementById(nom_calque).style.visibility='hidden';} //Netscape 6
}

//Ouverture d'une pop up
function ouvreFenetre(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}

function confirmation(URL,MSG)
{
	if(confirm(MSG))
	{
		document.location.href=URL;
	}
}

function verifForm(LayerId)
{
	var msg = "";
	var isImg = "";
	if(document.forms['ajoutActu'].elements['AC_titre'].value == "") msg += "Veuillez fournir un titre S.V.P\n"; else msg += "";
	if(document.forms['ajoutActu'].elements['AC_description'].value == "") msg += "Veuillez fournir une description S.V.P\n"; else msg += "";
	if(document.forms['ajoutActu'].elements['AC_texte'].value == "") msg += "Veuillez fournir un texte S.V.P\n"; else msg += "";
	if(document.forms['ajoutActu'].elements['AC_pdf'].value == "") isImg += ""; else isImg += true;
	if(document.forms['ajoutActu'].elements['AC_img1'].value == "") isImg += ""; else isImg += true;
	if(document.forms['ajoutActu'].elements['AC_img2'].value == "") isImg += ""; else isImg += true;
	if(document.forms['ajoutActu'].elements['AC_img3'].value == "") isImg += ""; else isImg += true;
	if(document.forms['ajoutActu'].elements['AC_img4'].value == "") isImg += ""; else isImg += true;	
		

	if(msg=="") 
	{
		if(isImg!="") {
			montre_calque(LayerId);
		}
		document.forms['ajoutActu'].elements['btValide'].disabled = true;
		document.forms['ajoutActu'].submit();
	}
	else 
	{
		alert(msg);
		msg = "";
	}	
}

function insertion(FormName, InputName, repdeb, repfin) {
  var input = document.forms[FormName].elements[InputName];
  input.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus récents basés sur Gecko*/
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  else
  {
    /* requête de la position d'insertion */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Insertion du code de formatage */
    var insText = prompt("Veuillez entrer le texte à formater:");
    input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  }
}

function confirmate(MSG)
{
	if(confirm(MSG))
	{
		return true;
	}
}

function moveSelected(from, to) {
	from = document.getElementById(from);
	to = document.getElementById(to);
	len = from.options.length - 1;
	for (i = len; i >= 0; i--) {
		if (from.options[i].selected) {
			to.options[to.options.length] = new Option(from.options[i].text,from.options[i].value);
			from.options[i] = null;
		}
	}
	return true;
}

function SelectAll(to)
{
	to = document.getElementById(to);
	len = to.options.length - 1;
	for (i = len; i >= 0; i--) {
		to.options[i].selected = true;
	}
}

function MailBz(adresse,delimiteur)
{
	tabMail = adresse.split(delimiteur)
	adresse_modif = tabMail[0]+tabMail[1];
	document.location.href='mailto:'+adresse_modif;
}


function test_it(entry) {
 if (entry.value && entry.value.length!=0) {
  entry.value=""+ eval(entry.value);
  }
 computeForm(entry.form);
 }
  
function clearRadio(objName) {
	for (var i = 0; i < objName.length; i++) {
	    objName[i].checked = false;
	}
}

function showBloc(objName) {		
	objName.style.position='relative';
	objName.style.visibility='visible';
}

function hideBloc(objName) {		
	objName.style.position='absolute';
	objName.style.visibility='hidden';
}

    
var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;
var regexp = new RegExp("[\r]","gi");

function insertCode(selec,FormName,InputName)
{
	oField = document.forms[FormName].elements[InputName];
	if (isMozilla) 
	{
		objectValue = oField.value;
		deb = oField.selectionStart;
		fin = oField.selectionEnd;
		objectValueDeb = objectValue.substring( 0 , oField.selectionStart );
		objectValueFin = objectValue.substring( oField.selectionEnd , oField.textLength );
		objectSelected = objectValue.substring( oField.selectionStart ,oField.selectionEnd );	
		oField.value = objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]" + objectValueFin;
		oField.selectionStart = strlen(objectValueDeb);
		oField.selectionEnd = strlen(objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]");
		oField.focus();
		oField.setSelectionRange(
			objectValueDeb.length + selec.length + 2,
			objectValueDeb.length + selec.length + 2);
	}
	else
	{
	// Si on est sur IE
		var str = document.selection.createRange().text;
		if (str.length>0)
		{
		// Si on a selectionné du texte
			var sel = document.selection.createRange();
			sel.text = "[" + selec + "]" + str + "[/" + selec + "]";
			sel.collapse();
			sel.select();
		}
		else
		{
			oField.focus(oField.caretPos);
		//	alert(oField.caretPos+"\n"+oField.value.length+"\n")
			oField.focus(oField.value.length);
			oField.caretPos = document.selection.createRange().duplicate();
			var bidon = "%~%";
			var orig = oField.value;
			oField.caretPos.text = bidon;
			var i = oField.value.search(bidon);
			oField.value = orig.substr(0,i) + "[" + selec + "][/" + selec + "]" + orig.substr(i, oField.value.length);
			var r = 0;
			for(n = 0; n < i; n++)
			{if(regexp.test(oField.value.substr(n,2)) == true){r++;}};
			pos = i + 2 + selec.length - r;
			//placer(document.forms['news'].elements['newst'], pos);
			var r = oField.createTextRange();
			r.moveStart('character', pos);
			r.collapse();
			r.select();
		}
	}
}
