//document.oncontextmenu=new Function ("return false")
//survol image
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 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 popup(page,nom,largeur,hauteur) 
{	var opt="menubar=no,scrollbars=yes,statusbar=no";
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+opt);
}

//modal dialog
function PopupShowModalDialog(path,type,msg)
{	width=300;
	height=150;
	file=path+"inc/popupbox.php?lang="+lang+"&langCSS="+langCSS+"&TypePopup="+type+"&Msg="+msg;
	if (window.showModalDialog) 
	{	window.showModalDialog(file,"Confirmation","center:yes;status:no;resizable:no;help:no;dialogWidth:"+width+"px;dialogHeight:"+height+"px");
	}
	else 
	{	newShowModalDialog(file,'',this.id,'modal=yes,directories=0,menubar=0,titlebar=0,toolbar=0,width='+width+',height='+height);
	}
}

function newShowModalDialog(url,mode,reference,windowParam)
{	var winOpenned=MODAL_alreadyOpen(mode,reference);
	if(winOpenned!=null) { winOpenned.focus(); return; }
	var id=MODAL_DIALOG_LIST.length;
	var newWin=window.open(url,'modal_'+id,windowParam);
	MODAL_DIALOG_LIST.push(Array(newWin,mode,reference,true));  //format win, mode, referecene , isOpen
}

// Variables globales du script
var MODAL_DIALOG_LIST=Array();

//méthode globales du script
function MODAL_alreadyOpen(mode,reference)
{	for(var i=0 ; i<MODAL_DIALOG_LIST.length ; i++)
	{	if(MODAL_DIALOG_LIST[i][1]==mode && MODAL_DIALOG_LIST[i][2]==reference && MODAL_DIALOG_LIST[i][3])
		{	//on test si elle est encore ouverte
		  	if(MODAL_DIALOG_LIST[i][0].document) { return MODAL_DIALOG_LIST[i][0]; }
		  	else   //la fenetre a été fermée sans qu'elle est pu prevenir la fenetre mere, on corrige donc le flag isOpen
			{	MODAL_DIALOG_LIST[i][3]=false;}
		}
	}
	return null;
}

function MODAL_findModalByWinRef(winRef)
{	for(var i=0 ; i<MODAL_DIALOG_LIST.length ; i++)
	{	if(MODAL_DIALOG_LIST[i][0]==winRef && MODAL_DIALOG_LIST[i][3])
		{	//on test si elle est encore ouverte
		  	if(MODAL_DIALOG_LIST[i][0].document) { return MODAL_DIALOG_LIST[i]; }
		  	else   //la fenetre a été fermée sans qu'elle est pu prevenir la fenetre mere, on corrige donc le flag isOpen
		  	{	MODAL_DIALOG_LIST[i][3]=false; 	}
		}
	}
	return null;
}

//force le focus sur les modal encore ouverte (en thoerie il ne peut y en avoir qu'une seule encore d'ouverte)
function MODAL_forceFocusOnModal()
{	for(var i=0 ; i<MODAL_DIALOG_LIST.length ; i++)
	{	if(MODAL_DIALOG_LIST[i][3] && MODAL_DIALOG_LIST[i][0].document) { MODAL_DIALOG_LIST[i][0].focus(); }
	}
	return;
}

//ajout d'un handler sur la reprise du focus, permettant d'imediatement redonner le focus a une eventuelle modal encore ouverte
if (document.addEventListener) 
{	document.addEventListener("focus", MODAL_forceFocusOnModal, true); 
}
else if (document.attachEvent) 
{ document.attachEvent("onfocus", MODAL_forceFocusOnModal); }
//

function str_replace(string,text,by) 
{   var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += str_replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function WriteInnerHTML(toThis,name_div) 
{	if (document.getElementById)
	{	document.getElementById(name_div).innerHTML = toThis;
	}
	else if (document.all) 
	{	document.all[name_div].innerHTML = toThis;
	}
}			

function chgDisplay(bloc) 
{	if (document.getElementById(bloc).style.display=='none') document.getElementById(bloc).style.display='';
	else	document.getElementById(bloc).style.display='none';
}

function get_extension(file)
{	var ext=file.substring(file.lastIndexOf('.'));  //récupérer l'extension de l'image
	ext=str_replace(ext,'.','');
	ext=ext.toLowerCase(); //rendre miniscule
	return ext;
}

function check_extension(nameDoc,tabFormatFile)
{	var error=false;
	extension=get_extension(nameDoc);
	for(var index=0; index < tabFormatFile.length; index++)
	{	if (tabFormatFile[index] == extension)
		{	error=true;
			break;
		}
	}
	return error;
}

function CheckExtFile(nameDoc,tabFormatFile)
{	extension=getExtension(nameDoc);
	for(i = 0 ; i < tabFormatFile.length; i++)
	{	if (tabFormatFile[i] == extension)
		{	return true;					
		}
	}
	return false;
}

function in_array(valeur,vecteur)
{	for(i=0;i<vecteur.length;i++)
	{	if(valeur==vecteur[i])	return true;
	}
	return false;
}

function WriteSwf(file,w,h)
{	swf=''+
'	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">'+
'		  <param name="movie" value="'+file+'">'+
'		  <param name="menu" value="false" />'+
'		  <param name="quality" value="high" />'+
'		  <param name="wmode" value="transparent" />'+
'		  <param name="scale" value="ExactFit" />'+
'		  <embed scale="ExactFit" wmode="transparent" menu="false" src="'+file+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>'+
'	  </object>';		
	document.write(swf);
}

function checkDataQuerystring(data,arg)
{	separateur='@and@';
	if (arg==0)	data=str_replace(data,'&',separateur);
	else		data=str_replace(data,separateur,'&');
	data=str_replace(data,"\\","");
	return data;
}

function detect_browser()
{	var detect = navigator.userAgent.toLowerCase();
	if (detect_browser_checkIt('konqueror',detect))	val=0;//browser = "Konqueror";
	else if (detect_browser_checkIt('safari',detect)) val=1;//browser = "Safari"
	else if (detect_browser_checkIt('omniweb',detect))val=0;// browser = "OmniWeb"
	else if (detect_browser_checkIt('opera',detect)) val=2;//browser = "Opera"
	else if (detect_browser_checkIt('webtv',detect)) val=0;//browser = "WebTV";
	else if (detect_browser_checkIt('icab',detect)) val=0;//browser = "iCab"
	else if (detect_browser_checkIt('msie',detect)) val=0;//browser = "Internet Explorer"
	else if (!detect_browser_checkIt('compatible',detect))	val=1;//browser = "Netscape Navigator"
	else val=0;//browser = "An unknown browser";
	return val;
}


function detect_browser_checkIt(string,detect)
{	place = detect.indexOf(string) + 1;
	return place;
}


function go_back(arg)
{	if (arg==-1)	history.back(); 
	else
	{	if (detect_browser()==1)  //Safari & FF
		{	arg=arg+1;
			history.go(arg);
		}
		else 
		{	history.go(arg);
		}
	}
}

function form_reset(nf)
{	nf.reset();
}

 function affiche_win(bloc,b,l,path) 
{	if (bloc.style.display =='') 
	{	bloc.style.display = 'none';
		if (l== 1) {b.src=path+'plus.gif';}
		else if (l== 2) {b.src=path+'mapsite_plus.gif';}
	}
	else
	{	bloc.style.display='';
		if (l== 1) {b.src=path+'minus.gif';}
		else if (l== 2) {b.src=path+'mapsite_moins.gif';}
	}
} 
//function popup
function open_doc(file)
{	popup(file,'documents',800,800);
}

//scroll-up the scrollbar
function moveToUp() //fct called by all the files to do an action
{	window.scrollTo(0,0); //move the scroll to the top position
}

//heure

function IsHeure(heure)
{	var expReg=new RegExp("(([0|1][0-9])|(2[0-3])):[0-5][0-9]", "gi");
	return expReg.test(heure);
}

function checkFomatTimeBetween(time1,time2)
{	if (str_replace(time1,':','')	>= str_replace(time2,':','') )	return false;
	else return true;
}
