var navigateur;
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var dom = (document.getElementById)? true:false;
if (ie4)
	navigateur	=	"ie";
else if (ns4)
	navigateur	=	"ns";
else if (dom)
	navigateur	=	"dom";

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function update_checkbox(aCheckboxId)
{
	if (document.getElementById(aCheckboxId).checked)
		document.getElementById(aCheckboxId).checked	=	false;
	else
		document.getElementById(aCheckboxId).checked	=	true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	if (features == "")
	{
		features	=	'center';
		features	+=	',width=500';
		features	+=	',height=600';
		features	+=	',scrollbars=yes';
	}
	
	if (features.substring(0, 7) == "center,")
	{
		features	=	features.substring(7);
		var index_width		=	features.indexOf("width=");
		var index_height	=	features.indexOf("height=");
		var win_width, win_height, win_left, win_top;
		
		if (index_width == -1)
		{
			win_width	=	500;
			alert("pas de 'width'");
		}
		else
		{
			var index_right		=	index_width + 6;
			
			if (features.indexOf(",", index_right) == -1)
				win_width	=	features.substring(index_right);
			else
				win_width	=	features.substring(index_right, features.indexOf(",", index_right));
		}
		
		if (index_height == -1)
		{
			win_height	=	600;
			alert("pas de 'height'");
		}
		else
		{
			var index_right		=	index_height + 7;
			if (features.indexOf(",", index_right) == -1)
				win_height	=	features.substring(index_right);
			else
				win_height	=	features.substring(index_right, features.indexOf(",", index_right));
		}
		
		win_left	=	(screen.width - win_width) / 2;
		win_top		=	(screen.height - win_height) / 2;
		features	+=	',left=' + win_left + ',top=' + win_top;
	}
	
	window.open(theURL,winName,features);
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function goto(page)
{
	var obj_form	=	MM_findObj("frm_naviagation");
	obj_form.action	=	page;
	var args = goto.arguments;
	var target_existe	=	false;
	for (i=1; i < args.length; i+=2)
	{
		if (args[i] == "target")
		{
			obj_form.target	=	args[i+1];
			target_existe	=	true;
		}
		else
			MM_findObj(args[i]).value	=	args[i+1];
	}
	if (!target_existe)
		obj_form.target	=	"";
	obj_form.submit();
}

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments, amin=1500, amax=2050, separateur="/";
	if (args.length == 1)
		if (typeof(args[0]) == "object")
			args	=	args[0];

	for (i=0; i<(args.length-2); i+=3)
	{
		test	=	args[i+2];
		val		=	MM_findObj(args[i]);
		
		if (test == "RSup0")
		{
			if (val.value == 0)
				errors += '- '+args[i+1]+' est obligatoire.\n';
		}
		else if (test == "REnum")
		{
			isSelected	=	false;
			for(j=0; j<2; j++) 
				if (val[j].checked == true)
					isSelected	=	true;
			if (!isSelected)
				errors += '- '+args[i+1]+' est obligatoire.\n';
		}
		else if (test == "RRadio")
		{
			isSelected	=	false;
			for (j=0; j<val.length; j++)
				if (val[j].checked == true)
					isSelected	=	true;
			if (!isSelected)
				errors += '- '+args[i+1]+' est obligatoire.\n';
				
		}
		else
		{
			if (val)
			{
				nm=val.name;
				if ((val=val.value)!="")
				{
					if (test.indexOf('isEmail')!=-1)
					{
						p=val.indexOf('@');
						if (p<1 || p==(val.length-1))
							errors+='- '+args[i+1]+' doit être une adresse EMail.\n';
					}
					else if (test.indexOf('isDate')!=-1)
					{
						//****************
						var d=val;
						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) ) { 
						errors += '- '+args[i+1]+' (Le jour n\'est pas correct).\n'; ok=0; }
						if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) { 
						errors += '- '+args[i+1]+' (Le mois n\'est pas correct).\n'; ok=0;  }
						if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) { 
						errors += '- '+args[i+1]+' (Le année n\'est pas correct).'; ok=0;  }
						if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) 
						&& (ok==1) ) { errors += '- '+args[i+1]+' (Les séparateurs doivent être des \''+separateur+'\').\n'; 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;}
							a2=1900+a2;
							//alert("Jours : "+j+" - "+j2+"\nMois : "+m+" - "+m2+"\nAnnée : "+a+" - "+a2+"\n");
							if ( (j!=j2)||(m!=m2)||(a!=a2) )
							{
								//alert("nono");
								errors += '- '+args[i+1]+' (La date \''+d+'\' n\'existe pas !).\n';
							} 
						} 
						//****************
					}
					else if (test.indexOf('isHeure')!=-1)
					{
						var	heure_complet	=	val.explode(":");
						var heure			=	heure_complet[0];
						if ((isNaN(heure)) || (heure<0)||(heure>23))
							errors += '- '+args[i+1]+' (L\'heure n\'est pas correct).\n';
						if (heure_complet.length == 2)
						{
							var minute			=	heure_complet[1];
							if ((isNaN(minute)) || (minute<0)||(minute>59))
								errors += '- '+args[i+1]+' (Les minutes ne sont pas correct).\n';
						}
						if (heure_complet.length == 3)
						{
							var seconde			=	heure_complet[2];
							if ((isNaN(seconde)) || (seconde<0)||(seconde>59))
								errors += '- '+args[i+1]+' (Les secondes ne sont pas correct).\n';
						}
					}
					else if (test!='R')
					{
						num = parseFloat(val);
						if (isNaN(val))
							errors+='- '+args[i+1]+' doit être un nombre.\n';
						if (test.indexOf('inRange') != -1)
						{
							p=test.indexOf(':');
							min=test.substring(8,p);
							max=test.substring(p+1);
							if (num<min || max<num)
								errors+='- '+args[i+1]+' must contain a number between '+min+' and '+max+'.\n';
						}
					}
				}
				else if (test.charAt(0) == 'R')
					errors += '- '+args[i+1]+' est obligatoire.\n';
			}
		}
	}
  
  if (errors)
  	alert(errors);
  document.MM_returnValue = (errors == '');
}

//function explode(aStringSeparateur, aString)
String.prototype.explode = function(aStringSeparateur)
{
	var aString			=	this.trim();
	if (aString == "")
		return -1;
	var	lst_occurence	=	new Array();
	var old_index		=	0;
	var	current_index	=	0;
	
	for(i=0;i<aString.length;i++)
	{
		if (aString.substr(i, aStringSeparateur.length) == aStringSeparateur)
		{
			lst_occurence.push(aString.substring(old_index, i));
			old_index		=	i + aStringSeparateur.length;
		}
	}
	lst_occurence.push(aString.substr(old_index));
	/*
	if (lst_occurence.length == 1)
		return lst_occurence[0];
	else
		return lst_occurence;
	*/
	return lst_occurence;
}

String.prototype.sans_accents = function()
{
	var ch = this.replace(/é|è|ê|ë/g, "e");
	ch = ch.replace(/à|â|ä/g, "a");
	ch = ch.replace(/ç/g, "c");
	ch = ch.replace(/î|ï/g, "i");
	ch = ch.replace(/ô|ö/g, "o");
	ch = ch.replace(/ù|û|ü/g, "u");
	ch = ch.replace(/À|Â|Ä|Å/g, "A");
	ch = ch.replace(/Ç/g, "C");
	ch = ch.replace(/É|È|Ê|Ë/g, "E");
	ch = ch.replace(/Ô|Ö/g, "O");
	ch = ch.replace(/Ù|Û|Ü/g, "U");
	return ch;
}

String.prototype.trim = function()
{
	return this.replace(/ /g, "");
}

function update_div(aName, aId, aFilePath, aColonneName, aColonneIdName, aTableName)
{
	xajax_update_div(aName, aId, aFilePath, aColonneName, aColonneIdName, aTableName);
}

function supprimer_fichier(aName, aId, aFilePath, aColonneName, aColonneIdName, aTableName)
{
	if (confirm("Etes-vous sur de vouloir supprimer ce fichier!"))
	{
		xajax_supprimer_fichier(aName, aId, aFilePath, aColonneName, aColonneIdName, aTableName);
	}
}

function getOffsetPosition(inID, inTYPE)
{
	var iVal	=	0;
	var oObj	=	document.getElementById(inID);
	var sType	=	'oObj.offset' + inTYPE;
	while (oObj && oObj.tagName != 'BODY')
	{
		iVal	+=	eval(sType);
		oObj	=	oObj.offsetParent;
	}
	return iVal;
}

function explorateur(aOperation, aParentId, aType, aTitre, aAuteur, aDatePage)
{
	xajax_explorateur(aOperation, aParentId, aType, aTitre, aAuteur, aDatePage);
}

function contenu_editeur(aContenu)
{
	document.getElementById("td_editeur").innerHTML	=	aContenu;
}

function creer_lien(aPageId, aPageFilleId)
{
	xajax_creer_lien(aPageId, aPageFilleId);
}

function show_div(aId)
{
	if (document.getElementById("div_" + aId).style.display == "none")
	{
		document.getElementById("a_" + aId).innerHTML	=	"<img src=\"../images/b_search.png\" border=\"0\" alt=\"\" />&nbsp;Masquer";
		document.getElementById("div_" + aId).style.display	=	"";
	}
	else
	{
		document.getElementById("a_" + aId).innerHTML	=	"<img src=\"../images/b_search.png\" border=\"0\" alt=\"\" />&nbsp;Voir";
		document.getElementById("div_" + aId).style.display	=	"none";
	}
}